Mercurial > mplayer.hg
annotate linux/vbelib.c @ 6659:715d93d492c3
interlacing support - Klaus Stengel <ks1@inter-ject.de>
author | arpi |
---|---|
date | Sat, 06 Jul 2002 15:20:34 +0000 |
parents | 6c45b8bf9a3e |
children | 21e1ab99cb21 |
rev | line source |
---|---|
2243 | 1 /* |
2 This file contains implementation of VESA library which is based on | |
3 LRMI (Linux real-mode interface). | |
4 So it's not an emulator - it calls real int 10h handler under Linux. | |
5 Note: VESA is available only on x86 systems. | |
6 You can redistribute this file under terms and conditions | |
2632 | 7 of GNU General Public licence v2. |
2243 | 8 Written by Nick Kurshev <nickols_k@mail.ru> |
9 */ | |
10 #include "vbelib.h" | |
11 #include "lrmi.h" | |
12 #include <stdlib.h> | |
13 #include <string.h> | |
14 #include <stdio.h> | |
15 #include <sys/io.h> | |
2610 | 16 #include <sys/mman.h> |
17 #include <sys/types.h> | |
18 #include <sys/stat.h> | |
2407 | 19 #include <ctype.h> |
2610 | 20 #include <unistd.h> |
21 #include <fcntl.h> | |
2243 | 22 |
23 static struct VesaProtModeInterface vbe_pm_info; | |
2632 | 24 static struct VesaModeInfoBlock curr_mode_info; |
2243 | 25 |
2536 | 26 static inline int VERR(const void *p) |
2515 | 27 { |
28 register int retval; | |
29 __asm __volatile( | |
30 "xorl %0, %0\n\t" | |
31 "verr %1\n\t" | |
32 "setnz %b0" | |
4405
7eda15bbb3f9
fixing assembly bug. By Thierry Vignaud <tvignaud@mandrakesoft.com>
nick
parents:
3016
diff
changeset
|
33 :"=q"(retval) |
2515 | 34 :"m"(*(unsigned char *)p) |
4405
7eda15bbb3f9
fixing assembly bug. By Thierry Vignaud <tvignaud@mandrakesoft.com>
nick
parents:
3016
diff
changeset
|
35 :"memory","cc"); |
2515 | 36 return retval; |
37 } | |
38 | |
39 #if 0 | |
2536 | 40 static inline int VERW(const void *p) |
2515 | 41 { |
42 register int retval; | |
43 __asm __volatile( | |
44 "xorl %0, %0\n\t" | |
45 "verw %1\n\t" | |
46 "setnz %b0" | |
4405
7eda15bbb3f9
fixing assembly bug. By Thierry Vignaud <tvignaud@mandrakesoft.com>
nick
parents:
3016
diff
changeset
|
47 :"=q"(retval) |
2515 | 48 :"m"(*(unsigned char *)p) |
4405
7eda15bbb3f9
fixing assembly bug. By Thierry Vignaud <tvignaud@mandrakesoft.com>
nick
parents:
3016
diff
changeset
|
49 :"memory","cc"); |
2515 | 50 return retval; |
51 } | |
52 #endif | |
53 | |
2294 | 54 #define HAVE_VERBOSE_VAR 1 |
55 | |
56 #ifdef HAVE_VERBOSE_VAR | |
57 extern int verbose; | |
58 | |
59 static void __dump_regs(struct LRMI_regs *r) | |
60 { | |
61 printf("vbelib: eax=%08lXh ebx=%08lXh ecx=%08lXh edx=%08lXh\n" | |
62 "vbelib: edi=%08lXh esi=%08lXh ebp=%08lXh esp=%08lXh\n" | |
2445 | 63 "vbelib: ds=%04Xh es=%04Xh ss=%04Xh cs:ip=%04X:%04X\n" |
64 "vbelib: fs=%04Xh gs=%04Xh ss:sp=%04X:%04X flags=%04X\n" | |
65 ,(unsigned long)r->eax,(unsigned long)r->ebx,(unsigned long)r->ecx,(unsigned long)r->edx | |
66 ,(unsigned long)r->edi,(unsigned long)r->esi,(unsigned long)r->ebp,(unsigned long)r->reserved | |
2294 | 67 ,r->ds,r->es,r->ss,r->cs,r->ip |
68 ,r->fs,r->gs,r->ss,r->sp,r->flags); | |
69 } | |
70 | |
71 static inline int VBE_LRMI_int(int int_no, struct LRMI_regs *r) | |
72 { | |
73 int retval; | |
74 if(verbose > 1) | |
75 { | |
76 printf("vbelib: registers before int %02X\n",int_no); | |
77 __dump_regs(r); | |
78 } | |
79 retval = LRMI_int(int_no,r); | |
80 if(verbose > 1) | |
81 { | |
2445 | 82 printf("vbelib: Interrupt handler returns: %X\n",retval); |
2294 | 83 printf("vbelib: registers after int %02X\n",int_no); |
84 __dump_regs(r); | |
85 } | |
86 return retval; | |
87 } | |
88 #else | |
89 #define VBE_LRMI_int(int_no,regs) (VBE_LRMI_int(int_no,regs)) | |
90 #endif | |
91 | |
3016
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
92 static FILE *my_stdin; |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
93 static FILE *my_stdout; |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
94 static FILE *my_stderr; |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
95 |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
96 static void __set_cursor_type(FILE *stdout_fd,int cursor_on) |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
97 { |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
98 fprintf(stdout_fd,"\033[?25%c",cursor_on?'h':'l'); |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
99 } |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
100 |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
101 /* TODO: do it only on LCD or DFP. We should extract such info from DDC */ |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
102 static void hide_terminal_output( void ) |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
103 { |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
104 my_stdin = fopen(ttyname(fileno(stdin )),"r"); |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
105 my_stdout = fopen(ttyname(fileno(stdout)),"w"); |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
106 my_stderr = fopen(ttyname(fileno(stderr)),"w"); |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
107 __set_cursor_type(stdout,0); |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
108 /*if(isatty(fileno(stdin ))) stdin =freopen("/dev/null","r",stdin );*/ |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
109 if(isatty(fileno(stdout))) stdout=freopen("/dev/null","w",stdout); |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
110 if(isatty(fileno(stderr))) stderr=freopen("/dev/null","w",stderr); |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
111 } |
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
112 |
2407 | 113 static unsigned hh_int_10_seg; |
2610 | 114 static int fd_mem; |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
115 /* |
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
116 the list of supported video modes is stored in the reserved portion of |
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
117 the SuperVGA information record by some implementations, and it may |
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
118 thus be necessary to either copy the mode list or use a different |
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
119 buffer for all subsequent VESA calls |
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
120 */ |
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
121 static void *controller_info; |
2243 | 122 int vbeInit( void ) |
123 { | |
2407 | 124 unsigned short iopl_port; |
2359 | 125 size_t i; |
2552 | 126 int retval; |
2243 | 127 if(!LRMI_init()) return VBE_VM86_FAIL; |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
128 if(!(controller_info = LRMI_alloc_real(sizeof(struct VbeInfoBlock)))) return VBE_OUT_OF_DOS_MEM; |
2243 | 129 /* |
130 Allow read/write to ALL io ports | |
131 */ | |
2407 | 132 hh_int_10_seg = *(unsigned short *)PhysToVirtSO(0x0000,0x0042); |
2359 | 133 /* Video BIOS should be at C000:0000 and above */ |
2407 | 134 hh_int_10_seg >>= 12; |
135 if(hh_int_10_seg < 0xC) return VBE_BROKEN_BIOS; | |
2243 | 136 ioperm(0, 1024, 1); |
137 iopl(3); | |
138 memset(&vbe_pm_info,0,sizeof(struct VesaProtModeInterface)); | |
2552 | 139 retval = vbeGetProtModeInfo(&vbe_pm_info); |
140 if(retval != VBE_OK) return retval; | |
2359 | 141 i = 0; |
2913 | 142 if(vbe_pm_info.iopl_ports) /* Can be NULL !!!*/ |
2552 | 143 while((iopl_port=vbe_pm_info.iopl_ports[i]) != 0xFFFF |
144 && vbe_pm_info.iopl_ports[i++] > 1023) ioperm(iopl_port,1,1); | |
2359 | 145 iopl(3); |
2610 | 146 fd_mem = open("/dev/mem",O_RDWR); |
3016
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
147 hide_terminal_output(); |
2243 | 148 return VBE_OK; |
149 } | |
150 | |
2610 | 151 int vbeDestroy( void ) |
152 { | |
3016
ea414257856f
Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents:
2913
diff
changeset
|
153 __set_cursor_type(my_stdout,1); |
2610 | 154 close(fd_mem); |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
155 LRMI_free_real(controller_info); |
2610 | 156 return VBE_OK; |
157 } | |
2243 | 158 |
2536 | 159 /* Fixme!!! This code is compatible only with mplayer's version of lrmi*/ |
160 static inline int is_addr_valid(const void *p) | |
161 { | |
162 return (p < (const void *)0x502) || | |
163 (p >= (const void *)0x10000 && p < (const void *)0x20000) || | |
164 (p >= (const void *)0xa0000 && p < (const void *)0x100000); | |
165 } | |
166 | |
167 static int check_str(const unsigned char *str) | |
2515 | 168 { |
169 size_t i; | |
170 int null_found = 0; | |
171 for(i = 0;i < 256;i++) | |
172 { | |
2536 | 173 if(is_addr_valid(&str[i])) |
2515 | 174 { |
2536 | 175 if(VERR(&str[i])) |
176 { | |
177 if(!str[i]) { null_found = 1; break; } | |
178 } | |
179 else break; | |
2515 | 180 } |
181 else break; | |
182 } | |
183 return null_found; | |
184 } | |
185 | |
2536 | 186 static int check_wrd(const unsigned short *str) |
2515 | 187 { |
188 size_t i; | |
189 int ffff_found = 0; | |
190 for(i = 0;i < 1024;i++) | |
191 { | |
2536 | 192 if(is_addr_valid(&str[i])) |
2515 | 193 { |
2536 | 194 if(VERR(&str[i])) |
195 { | |
196 if(str[i] == 0xffff) { ffff_found = 1; break; } | |
197 } | |
198 else break; | |
2515 | 199 } |
200 else break; | |
201 } | |
202 return ffff_found; | |
203 } | |
204 | |
2407 | 205 static void print_str(unsigned char *str) |
206 { | |
207 size_t i; | |
208 fflush(stdout); | |
209 printf("vbelib: "); | |
210 for(i = 0;i < 256;i++) { printf("%02X(%c) ",str[i],isprint(str[i])?str[i]:'.'); if(!str[i]) break; } | |
211 printf("\n"); | |
212 fflush(stdout); | |
213 } | |
214 | |
215 static void print_wrd(unsigned short *str) | |
216 { | |
217 size_t i; | |
218 fflush(stdout); | |
219 printf("vbelib: "); | |
220 for(i = 0;i < 256;i++) { printf("%04X ",str[i]); if(str[i] == 0xffff) break; } | |
221 printf("\n"); | |
222 fflush(stdout); | |
223 } | |
224 | |
2243 | 225 int vbeGetControllerInfo(struct VbeInfoBlock *data) |
226 { | |
227 struct LRMI_regs r; | |
228 int retval; | |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
229 memcpy(controller_info,data,sizeof(struct VbeInfoBlock)); |
2243 | 230 memset(&r,0,sizeof(struct LRMI_regs)); |
231 r.eax = 0x4f00; | |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
232 r.es = VirtToPhysSeg(controller_info); |
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
233 r.edi = VirtToPhysOff(controller_info); |
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
234 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 235 retval = r.eax & 0xffff; |
236 if(retval == 0x4f) | |
237 { | |
238 FarPtr fpdata; | |
239 retval = VBE_OK; | |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
240 memcpy(data,controller_info,sizeof(struct VbeInfoBlock)); |
2243 | 241 fpdata.seg = (unsigned long)(data->OemStringPtr) >> 16; |
242 fpdata.off = (unsigned long)(data->OemStringPtr) & 0xffff; | |
243 data->OemStringPtr = PhysToVirt(fpdata); | |
2515 | 244 if(!check_str(data->OemStringPtr)) data->OemStringPtr = NULL; |
2294 | 245 #ifdef HAVE_VERBOSE_VAR |
2407 | 246 if(verbose > 1) |
247 { | |
248 printf("vbelib: OemStringPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemStringPtr); | |
2515 | 249 if(data->OemStringPtr) print_str(data->OemStringPtr); |
2518 | 250 fflush(stdout); |
2407 | 251 } |
2294 | 252 #endif |
2243 | 253 fpdata.seg = (unsigned long)(data->VideoModePtr) >> 16; |
254 fpdata.off = (unsigned long)(data->VideoModePtr) & 0xffff; | |
255 data->VideoModePtr = PhysToVirt(fpdata); | |
2515 | 256 if(!check_wrd(data->VideoModePtr)) |
257 { | |
258 data->VideoModePtr = NULL; | |
259 retval = VBE_BROKEN_BIOS; | |
260 } | |
2294 | 261 #ifdef HAVE_VERBOSE_VAR |
2407 | 262 if(verbose > 1) |
263 { | |
264 printf("vbelib: VideoModePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->VideoModePtr); | |
2515 | 265 if(data->VideoModePtr) print_wrd(data->VideoModePtr); |
2518 | 266 fflush(stdout); |
2407 | 267 } |
2294 | 268 #endif |
2243 | 269 fpdata.seg = (unsigned long)(data->OemVendorNamePtr) >> 16; |
270 fpdata.off = (unsigned long)(data->OemVendorNamePtr) & 0xffff; | |
271 data->OemVendorNamePtr = PhysToVirt(fpdata); | |
2515 | 272 if(!check_str(data->OemVendorNamePtr)) data->OemVendorNamePtr = NULL; |
2294 | 273 #ifdef HAVE_VERBOSE_VAR |
2407 | 274 if(verbose > 1) |
275 { | |
276 printf("vbelib: OemVendorNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemVendorNamePtr); | |
2515 | 277 if(data->OemVendorNamePtr) print_str(data->OemVendorNamePtr); |
2518 | 278 fflush(stdout); |
2407 | 279 } |
2294 | 280 #endif |
2243 | 281 fpdata.seg = (unsigned long)(data->OemProductNamePtr) >> 16; |
282 fpdata.off = (unsigned long)(data->OemProductNamePtr) & 0xffff; | |
283 data->OemProductNamePtr = PhysToVirt(fpdata); | |
2515 | 284 if(!check_str(data->OemProductNamePtr)) data->OemProductNamePtr = NULL; |
2294 | 285 #ifdef HAVE_VERBOSE_VAR |
2407 | 286 if(verbose > 1) |
287 { | |
288 printf("vbelib: OemProductNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductNamePtr); | |
2515 | 289 if(data->OemVendorNamePtr) print_str(data->OemProductNamePtr); |
2518 | 290 fflush(stdout); |
2407 | 291 } |
2294 | 292 #endif |
2243 | 293 fpdata.seg = (unsigned long)(data->OemProductRevPtr) >> 16; |
294 fpdata.off = (unsigned long)(data->OemProductRevPtr) & 0xffff; | |
295 data->OemProductRevPtr = PhysToVirt(fpdata); | |
2515 | 296 if(!check_str(data->OemProductRevPtr)) data->OemProductRevPtr = NULL; |
2294 | 297 #ifdef HAVE_VERBOSE_VAR |
2407 | 298 if(verbose > 1) |
299 { | |
300 printf("vbelib: OemProductRevPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductRevPtr); | |
2515 | 301 if(data->OemProductRevPtr) print_str(data->OemProductRevPtr); |
2518 | 302 fflush(stdout); |
2407 | 303 } |
2294 | 304 #endif |
2243 | 305 } |
306 return retval; | |
307 } | |
308 | |
309 int vbeGetModeInfo(unsigned mode,struct VesaModeInfoBlock *data) | |
310 { | |
311 struct LRMI_regs r; | |
312 void *rm_space; | |
313 int retval; | |
314 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaModeInfoBlock)))) return VBE_OUT_OF_DOS_MEM; | |
315 memset(&r,0,sizeof(struct LRMI_regs)); | |
316 r.eax = 0x4f01; | |
317 r.ecx = mode; | |
318 r.es = VirtToPhysSeg(rm_space); | |
319 r.edi = VirtToPhysOff(rm_space); | |
2294 | 320 if(!VBE_LRMI_int(0x10,&r)) |
2243 | 321 { |
322 LRMI_free_real(rm_space); | |
323 return VBE_VM86_FAIL; | |
324 } | |
325 retval = r.eax & 0xffff; | |
326 if(retval == 0x4f) | |
327 { | |
328 retval = VBE_OK; | |
329 memcpy(data,rm_space,sizeof(struct VesaModeInfoBlock)); | |
330 } | |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
331 LRMI_free_real(rm_space); |
2243 | 332 return retval; |
333 } | |
334 | |
335 int vbeSetMode(unsigned mode,struct VesaCRTCInfoBlock *data) | |
336 { | |
337 struct LRMI_regs r; | |
338 void *rm_space = NULL; | |
339 int retval; | |
340 memset(&r,0,sizeof(struct LRMI_regs)); | |
341 if(data) | |
342 { | |
343 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaCRTCInfoBlock)))) return VBE_OUT_OF_DOS_MEM; | |
344 r.es = VirtToPhysSeg(rm_space); | |
345 r.edi = VirtToPhysOff(rm_space); | |
346 memcpy(rm_space,data,sizeof(struct VesaCRTCInfoBlock)); | |
347 } | |
348 r.eax = 0x4f02; | |
349 r.ebx = mode; | |
2294 | 350 retval = VBE_LRMI_int(0x10,&r); |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
351 LRMI_free_real(rm_space); |
2243 | 352 if(!retval) return VBE_VM86_FAIL; |
353 retval = r.eax & 0xffff; | |
2632 | 354 if(retval == 0x4f) |
355 { | |
356 /* Just info for internal use (currently in SetDiplayStart func). */ | |
357 vbeGetModeInfo(mode&0x1f,&curr_mode_info); | |
358 retval = VBE_OK; | |
359 } | |
2243 | 360 return retval; |
361 } | |
362 | |
363 int vbeGetMode(unsigned *mode) | |
364 { | |
365 struct LRMI_regs r; | |
366 int retval; | |
367 memset(&r,0,sizeof(struct LRMI_regs)); | |
368 r.eax = 0x4f03; | |
2294 | 369 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 370 retval = r.eax & 0xffff; |
371 if(retval == 0x4f) | |
372 { | |
373 *mode = r.ebx; | |
374 retval = VBE_OK; | |
375 } | |
376 return retval; | |
377 } | |
378 | |
379 int vbeSaveState(void **data) | |
380 { | |
381 struct LRMI_regs r; | |
382 int retval; | |
383 void *rm_space; | |
384 memset(&r,0,sizeof(struct LRMI_regs)); | |
385 r.eax = 0x4f04; | |
386 r.edx = 0x00; | |
387 r.ecx = 0x0f; | |
2294 | 388 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 389 retval = r.eax & 0xffff; |
390 if(retval != 0x4f) return retval; | |
391 if(!(rm_space = LRMI_alloc_real((r.ebx & 0xffff)*64))) return VBE_OUT_OF_DOS_MEM; | |
392 r.eax = 0x4f04; | |
393 r.edx = 0x01; | |
394 r.ecx = 0x0f; | |
395 r.es = VirtToPhysSeg(rm_space); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
396 r.ebx = VirtToPhysOff(rm_space); |
2294 | 397 if(!VBE_LRMI_int(0x10,&r)) |
2243 | 398 { |
399 LRMI_free_real(rm_space); | |
400 return VBE_VM86_FAIL; | |
401 } | |
402 retval = r.eax & 0xffff; | |
403 if(retval != 0x4f) | |
404 { | |
405 LRMI_free_real(rm_space); | |
406 return retval; | |
407 } | |
408 *data = rm_space; | |
409 return VBE_OK; | |
410 } | |
411 | |
412 int vbeRestoreState(void *data) | |
413 { | |
414 struct LRMI_regs r; | |
415 int retval; | |
416 memset(&r,0,sizeof(struct LRMI_regs)); | |
417 r.eax = 0x4f04; | |
418 r.edx = 0x02; | |
419 r.ecx = 0x0f; | |
420 r.es = VirtToPhysSeg(data); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
421 r.ebx = VirtToPhysOff(data); |
2294 | 422 retval = VBE_LRMI_int(0x10,&r); |
2243 | 423 LRMI_free_real(data); |
424 if(!retval) return VBE_VM86_FAIL; | |
425 retval = r.eax & 0xffff; | |
426 if(retval == 0x4f) retval = VBE_OK; | |
427 return retval; | |
428 } | |
429 | |
430 int vbeGetWindow(unsigned *win_num) | |
431 { | |
432 struct LRMI_regs r; | |
433 int retval; | |
434 memset(&r,0,sizeof(struct LRMI_regs)); | |
435 r.eax = 0x4f05; | |
436 r.ebx = (*win_num & 0x0f) | 0x0100; | |
2294 | 437 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 438 retval = r.eax & 0xffff; |
439 if(retval == 0x4f) | |
440 { | |
441 *win_num = r.edx & 0xffff; | |
442 retval = VBE_OK; | |
443 } | |
444 return retval; | |
445 } | |
446 | |
447 int vbeSetWindow(unsigned win_num,unsigned win_gran) | |
448 { | |
449 int retval; | |
450 if(vbe_pm_info.SetWindowCall) | |
451 { | |
2294 | 452 /* Don't verbose this stuff from performance reasons */ |
2243 | 453 /* 32-bit function call is much better of int 10h */ |
454 __asm __volatile( | |
455 "pushl %%ebx\n" | |
456 "movl %1, %%ebx\n" | |
457 ::"a"(0x4f05),"S"(win_num & 0x0f),"d"(win_gran):"memory"); | |
458 (*vbe_pm_info.SetWindowCall)(); | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
459 __asm __volatile("popl %%ebx":::"memory"); |
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
460 retval = VBE_OK; |
2243 | 461 } |
462 else | |
463 { | |
464 struct LRMI_regs r; | |
465 memset(&r,0,sizeof(struct LRMI_regs)); | |
466 r.eax = 0x4f05; | |
467 r.ebx = win_num & 0x0f; | |
468 r.edx = win_gran; | |
2294 | 469 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 470 retval = r.eax & 0xffff; |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
471 if(retval == 0x4f) retval = VBE_OK; |
2243 | 472 } |
473 return retval; | |
474 } | |
475 | |
2632 | 476 int vbeGetScanLineLength(unsigned *num_pixels,unsigned *num_bytes) |
477 { | |
478 struct LRMI_regs r; | |
479 int retval; | |
480 memset(&r,0,sizeof(struct LRMI_regs)); | |
481 r.eax = 0x4f06; | |
482 r.ebx = 1; | |
483 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
484 retval = r.eax & 0xffff; | |
485 if(retval == 0x4f) | |
486 { | |
487 if(num_bytes) *num_bytes = r.ebx & 0xffff; | |
488 if(num_pixels) *num_pixels= r.ecx & 0xffff; | |
489 retval = VBE_OK; | |
490 } | |
491 return retval; | |
492 } | |
493 | |
494 int vbeGetMaxScanLines(unsigned *num_pixels,unsigned *num_bytes, unsigned *num_lines) | |
495 { | |
496 struct LRMI_regs r; | |
497 int retval; | |
498 memset(&r,0,sizeof(struct LRMI_regs)); | |
499 r.eax = 0x4f06; | |
500 r.ebx = 3; | |
501 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
502 retval = r.eax & 0xffff; | |
503 if(retval == 0x4f) | |
504 { | |
505 if(num_bytes) *num_bytes = r.ebx & 0xffff; | |
506 if(num_pixels) *num_pixels= r.ecx & 0xffff; | |
507 if(num_lines) *num_lines = r.edx & 0xffff; | |
508 retval = VBE_OK; | |
509 } | |
510 return retval; | |
511 } | |
512 | |
513 int vbeSetScanLineLength(unsigned num_pixels) | |
514 { | |
515 int retval; | |
516 struct LRMI_regs r; | |
517 memset(&r,0,sizeof(struct LRMI_regs)); | |
518 r.eax = 0x4f06; | |
519 r.ebx = 0; | |
520 r.ecx = num_pixels; | |
521 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
522 retval = r.eax & 0xffff; | |
523 if(retval == 0x4f) retval = VBE_OK; | |
524 return retval; | |
525 } | |
526 | |
527 int vbeSetScanLineLengthB(unsigned num_bytes) | |
528 { | |
529 int retval; | |
530 struct LRMI_regs r; | |
531 memset(&r,0,sizeof(struct LRMI_regs)); | |
532 r.eax = 0x4f06; | |
533 r.ebx = 2; | |
534 r.ecx = num_bytes; | |
535 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
536 retval = r.eax & 0xffff; | |
537 if(retval == 0x4f) retval = VBE_OK; | |
538 return retval; | |
539 } | |
540 | |
541 int vbeGetDisplayStart(unsigned *pixel_num,unsigned *scan_line) | |
542 { | |
543 struct LRMI_regs r; | |
544 int retval; | |
545 memset(&r,0,sizeof(struct LRMI_regs)); | |
546 r.eax = 0x4f07; | |
547 r.ebx = 1; | |
548 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
549 retval = r.eax & 0xffff; | |
550 if(retval == 0x4f) | |
551 { | |
552 if(pixel_num) *pixel_num = r.ecx & 0xffff; | |
553 if(scan_line) *scan_line = r.edx & 0xffff; | |
554 retval = VBE_OK; | |
555 } | |
556 return retval; | |
557 } | |
558 | |
559 int vbeSetDisplayStart(unsigned long offset, int vsync) | |
560 { | |
561 int retval; | |
562 if(vbe_pm_info.SetDisplayStart) | |
563 { | |
564 /* Don't verbose this stuff from performance reasons */ | |
565 /* 32-bit function call is much better of int 10h */ | |
566 __asm __volatile( | |
567 "pushl %%ebx\n" | |
568 "movl %1, %%ebx\n" | |
569 ::"a"(0x4f07),"S"(vsync ? 0x80 : 0), | |
2686 | 570 "c"((offset>>2) & 0xffff),"d"((offset>>18)&0xffff):"memory"); |
2632 | 571 (*vbe_pm_info.SetDisplayStart)(); |
572 __asm __volatile("popl %%ebx":::"memory"); | |
573 retval = VBE_OK; | |
574 } | |
575 else | |
576 { | |
2686 | 577 #if 0 |
578 /* Something wrong here */ | |
2632 | 579 struct LRMI_regs r; |
580 unsigned long pixel_num; | |
581 memset(&r,0,sizeof(struct LRMI_regs)); | |
2686 | 582 pixel_num = offset%(unsigned long)curr_mode_info.BytesPerScanLine; |
583 if(pixel_num*(unsigned long)curr_mode_info.BytesPerScanLine!=offset) pixel_num++; | |
2632 | 584 r.eax = 0x4f07; |
2693 | 585 r.ebx = vsync ? 0x82 : 2; |
2632 | 586 r.ecx = pixel_num; |
587 r.edx = offset/(unsigned long)curr_mode_info.BytesPerScanLine; | |
588 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
589 retval = r.eax & 0xffff; | |
590 if(retval == 0x4f) retval = VBE_OK; | |
2686 | 591 #endif |
592 retval = VBE_BROKEN_BIOS; | |
2632 | 593 } |
594 return retval; | |
595 } | |
596 | |
2693 | 597 int vbeSetScheduledDisplayStart(unsigned long offset, int vsync) |
598 { | |
599 int retval; | |
600 struct LRMI_regs r; | |
601 unsigned long pixel_num; | |
602 memset(&r,0,sizeof(struct LRMI_regs)); | |
603 pixel_num = offset%(unsigned long)curr_mode_info.BytesPerScanLine; | |
604 if(pixel_num*(unsigned long)curr_mode_info.BytesPerScanLine!=offset) pixel_num++; | |
605 r.eax = 0x4f07; | |
606 r.ebx = vsync ? 0x82 : 2; | |
607 r.ecx = offset; | |
608 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; | |
609 retval = r.eax & 0xffff; | |
610 if(retval == 0x4f) retval = VBE_OK; | |
611 return retval; | |
612 } | |
613 | |
2243 | 614 struct realVesaProtModeInterface |
615 { | |
616 unsigned short SetWindowCall; | |
617 unsigned short SetDisplayStart; | |
618 unsigned short SetPaletteData; | |
619 unsigned short iopl_ports; | |
620 }__attribute__((packed)); | |
621 | |
622 int vbeGetProtModeInfo(struct VesaProtModeInterface *pm_info) | |
623 { | |
624 struct LRMI_regs r; | |
625 int retval; | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
626 unsigned info_offset; |
2243 | 627 struct realVesaProtModeInterface *rm_info; |
628 memset(&r,0,sizeof(struct LRMI_regs)); | |
629 r.eax = 0x4f0a; | |
630 r.ebx = 0; | |
2294 | 631 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL; |
2243 | 632 retval = r.eax & 0xffff; |
633 if(retval == 0x4f) | |
634 { | |
2407 | 635 retval = VBE_OK; |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
636 info_offset = r.edi&0xffff; |
2407 | 637 if((r.es >> 12) != hh_int_10_seg) retval = VBE_BROKEN_BIOS; |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
638 rm_info = PhysToVirtSO(r.es,info_offset); |
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
639 pm_info->SetWindowCall = PhysToVirtSO(r.es,info_offset+rm_info->SetWindowCall); |
2552 | 640 if(!is_addr_valid(pm_info->SetWindowCall)) retval = VBE_BROKEN_BIOS; |
2294 | 641 #ifdef HAVE_VERBOSE_VAR |
642 if(verbose > 1) printf("vbelib: SetWindowCall=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetWindowCall,pm_info->SetWindowCall); | |
643 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
644 pm_info->SetDisplayStart = PhysToVirtSO(r.es,info_offset+rm_info->SetDisplayStart); |
2552 | 645 if(!is_addr_valid(pm_info->SetDisplayStart)) retval = VBE_BROKEN_BIOS; |
2294 | 646 #ifdef HAVE_VERBOSE_VAR |
647 if(verbose > 1) printf("vbelib: SetDisplayStart=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetDisplayStart,pm_info->SetDisplayStart); | |
648 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
649 pm_info->SetPaletteData = PhysToVirtSO(r.es,info_offset+rm_info->SetPaletteData); |
2552 | 650 if(!is_addr_valid(pm_info->SetPaletteData)) retval = VBE_BROKEN_BIOS; |
2294 | 651 #ifdef HAVE_VERBOSE_VAR |
652 if(verbose > 1) printf("vbelib: SetPaletteData=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetPaletteData,pm_info->SetPaletteData); | |
653 #endif | |
2254
6e5b548790c9
Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents:
2243
diff
changeset
|
654 pm_info->iopl_ports = PhysToVirtSO(r.es,info_offset+rm_info->iopl_ports); |
2913 | 655 if(!rm_info->iopl_ports) pm_info->iopl_ports = NULL; |
656 else | |
2515 | 657 if(!check_wrd(pm_info->iopl_ports)) |
658 { | |
659 pm_info->iopl_ports = NULL; | |
2913 | 660 /* retval = VBE_BROKEN_BIOS; <- It's for broken BIOSes only */ |
2515 | 661 } |
2294 | 662 #ifdef HAVE_VERBOSE_VAR |
2407 | 663 if(verbose > 1) |
664 { | |
665 printf("vbelib: iopl_ports=%04X:%04X => %p\n",r.es,info_offset+rm_info->iopl_ports,pm_info->iopl_ports); | |
2515 | 666 if(pm_info->iopl_ports) print_wrd(pm_info->iopl_ports); |
2518 | 667 fflush(stdout); |
2407 | 668 } |
2294 | 669 #endif |
2243 | 670 } |
671 return retval; | |
672 } | |
2410 | 673 /* --------- Standard VGA stuff -------------- */ |
674 int vbeWriteString(int x, int y, int attr, char *str) | |
675 { | |
676 struct LRMI_regs r; | |
677 void *rm_space = NULL; | |
678 int retval; | |
679 memset(&r,0,sizeof(struct LRMI_regs)); | |
680 r.ecx = strlen(str); | |
681 r.edx = ((y<<8)&0xff00)|(x&0xff); | |
682 r.ebx = attr; | |
683 if(!(rm_space = LRMI_alloc_real(r.ecx))) return VBE_OUT_OF_DOS_MEM; | |
684 r.es = VirtToPhysSeg(rm_space); | |
685 r.ebp = VirtToPhysOff(rm_space); | |
686 memcpy(rm_space,str,r.ecx); | |
687 r.eax = 0x1300; | |
688 retval = VBE_LRMI_int(0x10,&r); | |
6473
6c45b8bf9a3e
date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents:
4405
diff
changeset
|
689 LRMI_free_real(rm_space); |
2410 | 690 if(!retval) return VBE_VM86_FAIL; |
691 retval = r.eax & 0xffff; | |
692 if(retval == 0x4f) retval = VBE_OK; | |
693 return retval; | |
2460 | 694 } |
2610 | 695 |
696 void * vbeMapVideoBuffer(unsigned long phys_addr,unsigned long size) | |
697 { | |
698 void *lfb; | |
699 if(fd_mem == -1) return NULL; | |
700 if(verbose > 1) printf("vbelib: vbeMapVideoBuffer(%08lX,%08lX)\n",phys_addr,size); | |
701 /* Here we don't need with MAP_FIXED and prefered address (first argument) */ | |
702 lfb = mmap((void *)0,size,PROT_READ | PROT_WRITE,MAP_SHARED,fd_mem,phys_addr); | |
703 return lfb == (void *)-1 ? 0 : lfb; | |
704 } | |
705 | |
706 void vbeUnmapVideoBuffer(unsigned long linear_addr,unsigned long size) | |
707 { | |
708 if(verbose > 1) printf("vbelib: vbeUnmapVideoBuffer(%08lX,%08lX)\n",linear_addr,size); | |
709 munmap((void *)linear_addr,size); | |
710 } |