annotate osdep/vbelib.c @ 13939:25db6ab99ff3

More detailed Debian package building instructions, based on a patch by Guillaume Poirier <guillaume dot poirier at ifsic dot univ-rennes1 dot fr>
author diego
date Sun, 14 Nov 2004 14:24:18 +0000
parents 1cb0e1833515
children 85fd2ee1c094
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
1 /*
f4b588dba08a vbelib import
nick
parents:
diff changeset
2 This file contains implementation of VESA library which is based on
f4b588dba08a vbelib import
nick
parents:
diff changeset
3 LRMI (Linux real-mode interface).
f4b588dba08a vbelib import
nick
parents:
diff changeset
4 So it's not an emulator - it calls real int 10h handler under Linux.
f4b588dba08a vbelib import
nick
parents:
diff changeset
5 Note: VESA is available only on x86 systems.
f4b588dba08a vbelib import
nick
parents:
diff changeset
6 You can redistribute this file under terms and conditions
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
7 of GNU General Public licence v2.
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
8 Written by Nick Kurshev <nickols_k@mail.ru>
12660
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
9 Neomagic TV out support by Rudolf Marek <r.marek et sh.cvut.cz>
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
10 */
11455
22f8732b5d97 cumulative libc5 compatibility patch ;)
gabucino
parents: 10114
diff changeset
11
22f8732b5d97 cumulative libc5 compatibility patch ;)
gabucino
parents: 10114
diff changeset
12 #include <../config.h>
22f8732b5d97 cumulative libc5 compatibility patch ;)
gabucino
parents: 10114
diff changeset
13 #ifdef HAVE_VESA
22f8732b5d97 cumulative libc5 compatibility patch ;)
gabucino
parents: 10114
diff changeset
14
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
15 #include "vbelib.h"
f4b588dba08a vbelib import
nick
parents:
diff changeset
16 #include "lrmi.h"
f4b588dba08a vbelib import
nick
parents:
diff changeset
17 #include <stdlib.h>
f4b588dba08a vbelib import
nick
parents:
diff changeset
18 #include <string.h>
f4b588dba08a vbelib import
nick
parents:
diff changeset
19 #include <stdio.h>
f4b588dba08a vbelib import
nick
parents:
diff changeset
20 #include <sys/io.h>
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
21 #include <sys/mman.h>
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
22 #include <sys/types.h>
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
23 #include <sys/stat.h>
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
24 #include <ctype.h>
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
25 #include <unistd.h>
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
26 #include <fcntl.h>
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
27
f4b588dba08a vbelib import
nick
parents:
diff changeset
28 static struct VesaProtModeInterface vbe_pm_info;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
29 static struct VesaModeInfoBlock curr_mode_info;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
30
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
31 static inline int VERR(const void *p)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
32 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
33 register int retval;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
34 __asm __volatile(
622cd80caaba memory verification
nick
parents: 2460
diff changeset
35 "xorl %0, %0\n\t"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
36 "verr %1\n\t"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
37 "setnz %b0"
4405
7eda15bbb3f9 fixing assembly bug. By Thierry Vignaud <tvignaud@mandrakesoft.com>
nick
parents: 3016
diff changeset
38 :"=q"(retval)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
39 :"m"(*(unsigned char *)p)
4405
7eda15bbb3f9 fixing assembly bug. By Thierry Vignaud <tvignaud@mandrakesoft.com>
nick
parents: 3016
diff changeset
40 :"memory","cc");
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
41 return retval;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
42 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
43
622cd80caaba memory verification
nick
parents: 2460
diff changeset
44 #if 0
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
45 static inline int VERW(const void *p)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
46 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
47 register int retval;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
48 __asm __volatile(
622cd80caaba memory verification
nick
parents: 2460
diff changeset
49 "xorl %0, %0\n\t"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
50 "verw %1\n\t"
622cd80caaba memory verification
nick
parents: 2460
diff changeset
51 "setnz %b0"
4405
7eda15bbb3f9 fixing assembly bug. By Thierry Vignaud <tvignaud@mandrakesoft.com>
nick
parents: 3016
diff changeset
52 :"=q"(retval)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
53 :"m"(*(unsigned char *)p)
4405
7eda15bbb3f9 fixing assembly bug. By Thierry Vignaud <tvignaud@mandrakesoft.com>
nick
parents: 3016
diff changeset
54 :"memory","cc");
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
55 return retval;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
56 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
57 #endif
622cd80caaba memory verification
nick
parents: 2460
diff changeset
58
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
59 #define HAVE_VERBOSE_VAR 1
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
60
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
61 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
62 extern int verbose;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
63
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
64 static void __dump_regs(struct LRMI_regs *r)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
65 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
66 printf("vbelib: eax=%08lXh ebx=%08lXh ecx=%08lXh edx=%08lXh\n"
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
67 "vbelib: edi=%08lXh esi=%08lXh ebp=%08lXh esp=%08lXh\n"
2445
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
68 "vbelib: ds=%04Xh es=%04Xh ss=%04Xh cs:ip=%04X:%04X\n"
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
69 "vbelib: fs=%04Xh gs=%04Xh ss:sp=%04X:%04X flags=%04X\n"
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
70 ,(unsigned long)r->eax,(unsigned long)r->ebx,(unsigned long)r->ecx,(unsigned long)r->edx
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
71 ,(unsigned long)r->edi,(unsigned long)r->esi,(unsigned long)r->ebp,(unsigned long)r->reserved
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
72 ,r->ds,r->es,r->ss,r->cs,r->ip
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
73 ,r->fs,r->gs,r->ss,r->sp,r->flags);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
74 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
75
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
76 static inline int VBE_LRMI_int(int int_no, struct LRMI_regs *r)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
77 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
78 int retval;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
79 if(verbose > 1)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
80 {
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
81 printf("vbelib: registers before int %02X\n",int_no);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
82 __dump_regs(r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
83 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
84 retval = LRMI_int(int_no,r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
85 if(verbose > 1)
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
86 {
2445
c570836dd567 Suppressing warnings
nick
parents: 2410
diff changeset
87 printf("vbelib: Interrupt handler returns: %X\n",retval);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
88 printf("vbelib: registers after int %02X\n",int_no);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
89 __dump_regs(r);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
90 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
91 return retval;
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
92 }
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
93 #else
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
94 #define VBE_LRMI_int(int_no,regs) (VBE_LRMI_int(int_no,regs))
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
95 #endif
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
96
3016
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
97 static FILE *my_stdin;
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
98 static FILE *my_stdout;
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
99 static FILE *my_stderr;
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 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
102 {
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
103 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
104 }
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
105
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
106 /* 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
107 static void hide_terminal_output( void )
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
108 {
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
109 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
110 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
111 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
112 __set_cursor_type(stdout,0);
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
113 /*if(isatty(fileno(stdin ))) stdin =freopen("/dev/null","r",stdin );*/
13352
166a12bd5470 stdout and stderr are macros --- you can't assign to them. Assignment doesn't make sense anyway, because freopen will always return the same FILE * structure that it got in parameter. patch by Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
faust3
parents: 12660
diff changeset
114 if(isatty(fileno(stdout))) freopen("/dev/null","w",stdout);
166a12bd5470 stdout and stderr are macros --- you can't assign to them. Assignment doesn't make sense anyway, because freopen will always return the same FILE * structure that it got in parameter. patch by Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>
faust3
parents: 12660
diff changeset
115 if(isatty(fileno(stderr))) freopen("/dev/null","w",stderr);
3016
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
116 }
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
117
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
118 static unsigned hh_int_10_seg;
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
119 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
120 /*
6c45b8bf9a3e date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents: 4405
diff changeset
121 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
122 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
123 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
124 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
125 */
6c45b8bf9a3e date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents: 4405
diff changeset
126 static void *controller_info;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
127 int vbeInit( void )
f4b588dba08a vbelib import
nick
parents:
diff changeset
128 {
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
129 unsigned short iopl_port;
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
130 size_t i;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
131 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
132 if(!(controller_info = LRMI_alloc_real(sizeof(struct VbeInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
133 /*
f4b588dba08a vbelib import
nick
parents:
diff changeset
134 Allow read/write to ALL io ports
f4b588dba08a vbelib import
nick
parents:
diff changeset
135 */
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
136 hh_int_10_seg = *(unsigned short *)PhysToVirtSO(0x0000,0x0042);
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
137 /* Video BIOS should be at C000:0000 and above */
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
138 hh_int_10_seg >>= 12;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
139 if(hh_int_10_seg < 0xC) return VBE_BROKEN_BIOS;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
140 ioperm(0, 1024, 1);
f4b588dba08a vbelib import
nick
parents:
diff changeset
141 iopl(3);
f4b588dba08a vbelib import
nick
parents:
diff changeset
142 memset(&vbe_pm_info,0,sizeof(struct VesaProtModeInterface));
13568
1cb0e1833515 Currently vbeGetProtModeInfo call the 0x4f0a function of int 10h the get
faust3
parents: 13352
diff changeset
143 vbeGetProtModeInfo(&vbe_pm_info);
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
144 i = 0;
2913
74731185c5c9 Fixed iopl ports detection
nick
parents: 2693
diff changeset
145 if(vbe_pm_info.iopl_ports) /* Can be NULL !!!*/
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
146 while((iopl_port=vbe_pm_info.iopl_ports[i]) != 0xFFFF
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
147 && vbe_pm_info.iopl_ports[i++] > 1023) ioperm(iopl_port,1,1);
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
148 iopl(3);
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
149 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
150 hide_terminal_output();
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
151 return VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
152 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
153
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
154 int vbeDestroy( void )
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
155 {
10114
f6a788f113a8 uninit fix by Aurelien JACOBS <aurel at gnuage.org>
faust3
parents: 9380
diff changeset
156 if (my_stdout) __set_cursor_type(my_stdout,1);
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
157 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
158 LRMI_free_real(controller_info);
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
159 return VBE_OK;
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
160 }
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
161
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
162 /* Fixme!!! This code is compatible only with mplayer's version of lrmi*/
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
163 static inline int is_addr_valid(const void *p)
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
164 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
165 return (p < (const void *)0x502) ||
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
166 (p >= (const void *)0x10000 && p < (const void *)0x20000) ||
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
167 (p >= (const void *)0xa0000 && p < (const void *)0x100000);
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
168 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
169
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
170 static int check_str(const unsigned char *str)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
171 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
172 size_t i;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
173 int null_found = 0;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
174 for(i = 0;i < 256;i++)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
175 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
176 if(is_addr_valid(&str[i]))
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
177 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
178 if(VERR(&str[i]))
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
179 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
180 if(!str[i]) { null_found = 1; break; }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
181 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
182 else break;
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
183 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
184 else break;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
185 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
186 return null_found;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
187 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
188
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
189 static int check_wrd(const unsigned short *str)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
190 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
191 size_t i;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
192 int ffff_found = 0;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
193 for(i = 0;i < 1024;i++)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
194 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
195 if(is_addr_valid(&str[i]))
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
196 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
197 if(VERR(&str[i]))
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
198 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
199 if(str[i] == 0xffff) { ffff_found = 1; break; }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
200 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
201 else break;
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
202 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
203 else break;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
204 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
205 return ffff_found;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
206 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
207
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
208 static void print_str(unsigned char *str)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
209 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
210 size_t i;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
211 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
212 printf("vbelib: ");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
213 for(i = 0;i < 256;i++) { printf("%02X(%c) ",str[i],isprint(str[i])?str[i]:'.'); if(!str[i]) break; }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
214 printf("\n");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
215 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
216 }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
217
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
218 static void print_wrd(unsigned short *str)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
219 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
220 size_t i;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
221 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
222 printf("vbelib: ");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
223 for(i = 0;i < 256;i++) { printf("%04X ",str[i]); if(str[i] == 0xffff) break; }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
224 printf("\n");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
225 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
226 }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
227
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
228 int vbeGetControllerInfo(struct VbeInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
229 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
230 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
231 int retval;
6473
6c45b8bf9a3e date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents: 4405
diff changeset
232 memcpy(controller_info,data,sizeof(struct VbeInfoBlock));
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
233 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
234 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
235 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
236 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
237 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
238 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
239 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
240 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
241 FarPtr fpdata;
f4b588dba08a vbelib import
nick
parents:
diff changeset
242 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
243 memcpy(data,controller_info,sizeof(struct VbeInfoBlock));
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
244 fpdata.seg = (unsigned long)(data->OemStringPtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
245 fpdata.off = (unsigned long)(data->OemStringPtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
246 data->OemStringPtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
247 if(!check_str(data->OemStringPtr)) data->OemStringPtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
248 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
249 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
250 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
251 printf("vbelib: OemStringPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemStringPtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
252 if(data->OemStringPtr) print_str(data->OemStringPtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
253 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
254 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
255 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
256 fpdata.seg = (unsigned long)(data->VideoModePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
257 fpdata.off = (unsigned long)(data->VideoModePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
258 data->VideoModePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
259 if(!check_wrd(data->VideoModePtr))
622cd80caaba memory verification
nick
parents: 2460
diff changeset
260 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
261 data->VideoModePtr = NULL;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
262 retval = VBE_BROKEN_BIOS;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
263 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
264 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
265 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
266 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
267 printf("vbelib: VideoModePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->VideoModePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
268 if(data->VideoModePtr) print_wrd(data->VideoModePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
269 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
270 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
271 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
272 fpdata.seg = (unsigned long)(data->OemVendorNamePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
273 fpdata.off = (unsigned long)(data->OemVendorNamePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
274 data->OemVendorNamePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
275 if(!check_str(data->OemVendorNamePtr)) data->OemVendorNamePtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
276 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
277 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
278 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
279 printf("vbelib: OemVendorNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemVendorNamePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
280 if(data->OemVendorNamePtr) print_str(data->OemVendorNamePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
281 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
282 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
283 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
284 fpdata.seg = (unsigned long)(data->OemProductNamePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
285 fpdata.off = (unsigned long)(data->OemProductNamePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
286 data->OemProductNamePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
287 if(!check_str(data->OemProductNamePtr)) data->OemProductNamePtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
288 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
289 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
290 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
291 printf("vbelib: OemProductNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductNamePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
292 if(data->OemVendorNamePtr) print_str(data->OemProductNamePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
293 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
294 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
295 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
296 fpdata.seg = (unsigned long)(data->OemProductRevPtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
297 fpdata.off = (unsigned long)(data->OemProductRevPtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
298 data->OemProductRevPtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
299 if(!check_str(data->OemProductRevPtr)) data->OemProductRevPtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
300 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
301 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
302 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
303 printf("vbelib: OemProductRevPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductRevPtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
304 if(data->OemProductRevPtr) print_str(data->OemProductRevPtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
305 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
306 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
307 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
308 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
309 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
310 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
311
f4b588dba08a vbelib import
nick
parents:
diff changeset
312 int vbeGetModeInfo(unsigned mode,struct VesaModeInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
313 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
314 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
315 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
316 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
317 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaModeInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
318 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
319 r.eax = 0x4f01;
f4b588dba08a vbelib import
nick
parents:
diff changeset
320 r.ecx = mode;
f4b588dba08a vbelib import
nick
parents:
diff changeset
321 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
322 r.edi = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
323 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
324 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
325 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
326 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
327 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
328 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
329 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
330 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
331 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
332 memcpy(data,rm_space,sizeof(struct VesaModeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
333 }
6473
6c45b8bf9a3e date: 2002/06/16 09:10:00; author: nickols_k; state: Exp; lines: +17 -13
atmos4
parents: 4405
diff changeset
334 LRMI_free_real(rm_space);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
335 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
336 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
337
12660
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
338
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
339 int vbeSetTV(unsigned int vesa_mode,unsigned int TV_mode) {
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
340
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
341 #define NR_MODES 8
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
342
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
343 unsigned int mode_table[NR_MODES] =
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
344 {0x101,0x103,0x111,0x114,0x120,0x121,0x122,0x123};
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
345 unsigned int tv_table[][NR_MODES] = {
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
346 {0x201,0x202,0x211,0x212,0x221,0x231,0x222,0x232},
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
347 {0x200,0x203,0x210,0x213,0x220,0x230,0xFFFF,0xFFFF}};
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
348
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
349 /*
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
350
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
351 Alternate mode map. If modes like 320x240 and 400x300 does not work, but
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
352 640x480 and 800x600 work, then try to replace above two lines with this
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
353 lines and write email to me if it works.
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
354 r.marek et sh.cvut.cz
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
355
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
356 {0x201,0x202,0x211,0x212,0x222,0x223,0x224,0x225},
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
357 {0x200,0x203,0x210,0x213,0x220,0x221,0xFFFF,0xFFFF}};
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
358
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
359 */
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
360 int i,retval;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
361 struct LRMI_regs r;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
362
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
363 memset(&r,0,sizeof(struct LRMI_regs));
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
364 for (i=0;((mode_table[i]!=(vesa_mode&0x3FF))&&(i<NR_MODES));i++) ;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
365
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
366 if (i==NR_MODES) return 0;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
367 if(verbose > 1) printf("vbelib: Trying to set TV mode %x\n",tv_table[TV_mode][i]);
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
368 r.eax = 0x4f14;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
369 r.ebx = 0x20;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
370 r.edx = 0;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
371 r.edi = 0;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
372 r.ecx = tv_table[TV_mode][i];
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
373 retval = VBE_LRMI_int(0x10,&r);
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
374 if(!retval) return VBE_VM86_FAIL;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
375 return r.eax & 0xffff;
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
376
430a71a762b4 neomagic tv out support throught vesa vbe, patch by Rudolf Marek
alex
parents: 11455
diff changeset
377 }
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
378 int vbeSetMode(unsigned mode,struct VesaCRTCInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
379 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
380 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
381 void *rm_space = NULL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
382 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
383 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
384 if(data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
385 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
386 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaCRTCInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
387 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
388 r.edi = VirtToPhysOff(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
389 memcpy(rm_space,data,sizeof(struct VesaCRTCInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
390 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
391 r.eax = 0x4f02;
f4b588dba08a vbelib import
nick
parents:
diff changeset
392 r.ebx = mode;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
393 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
394 LRMI_free_real(rm_space);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
395 if(!retval) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
396 retval = r.eax & 0xffff;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
397 if(retval == 0x4f)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
398 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
399 /* Just info for internal use (currently in SetDiplayStart func). */
13568
1cb0e1833515 Currently vbeGetProtModeInfo call the 0x4f0a function of int 10h the get
faust3
parents: 13352
diff changeset
400 vbeGetModeInfo(mode,&curr_mode_info);
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
401 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
402 }
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
403 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
404 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
405
f4b588dba08a vbelib import
nick
parents:
diff changeset
406 int vbeGetMode(unsigned *mode)
f4b588dba08a vbelib import
nick
parents:
diff changeset
407 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
408 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
409 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
410 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
411 r.eax = 0x4f03;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
412 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
413 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
414 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
415 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
416 *mode = r.ebx;
f4b588dba08a vbelib import
nick
parents:
diff changeset
417 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
418 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
419 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
420 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
421
7069
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
422 int vbeGetPixelClock(unsigned *mode,unsigned *pixel_clock) // in Hz
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
423 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
424 struct LRMI_regs r;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
425 int retval;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
426 memset(&r,0,sizeof(struct LRMI_regs));
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
427 r.eax = 0x4f0b;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
428 r.ebx = 0;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
429 r.edx = *mode;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
430 r.ecx = *pixel_clock;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
431 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
432 retval = r.eax & 0xffff;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
433 if(retval == 0x4f)
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
434 {
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
435 *pixel_clock = r.ecx;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
436 retval = VBE_OK;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
437 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
438 return retval;
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
439 }
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
440
21e1ab99cb21 General Timing Formula algorithm from a scratch.
arpi
parents: 6473
diff changeset
441
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
442 int vbeSaveState(void **data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
443 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
444 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
445 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
446 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
447 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
448 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
449 r.edx = 0x00;
f4b588dba08a vbelib import
nick
parents:
diff changeset
450 r.ecx = 0x0f;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
451 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
452 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
453 if(retval != 0x4f) return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
454 if(!(rm_space = LRMI_alloc_real((r.ebx & 0xffff)*64))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
455 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
456 r.edx = 0x01;
f4b588dba08a vbelib import
nick
parents:
diff changeset
457 r.ecx = 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
458 r.es = VirtToPhysSeg(rm_space);
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
459 r.ebx = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
460 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
461 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
462 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
463 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
464 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
465 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
466 if(retval != 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
467 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
468 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
469 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
470 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
471 *data = rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
472 return VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
473 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
474
f4b588dba08a vbelib import
nick
parents:
diff changeset
475 int vbeRestoreState(void *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
476 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
477 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
478 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
479 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
480 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
481 r.edx = 0x02;
f4b588dba08a vbelib import
nick
parents:
diff changeset
482 r.ecx = 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
483 r.es = VirtToPhysSeg(data);
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
484 r.ebx = VirtToPhysOff(data);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
485 retval = VBE_LRMI_int(0x10,&r);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
486 LRMI_free_real(data);
f4b588dba08a vbelib import
nick
parents:
diff changeset
487 if(!retval) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
488 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
489 if(retval == 0x4f) retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
490 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
491 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
492
f4b588dba08a vbelib import
nick
parents:
diff changeset
493 int vbeGetWindow(unsigned *win_num)
f4b588dba08a vbelib import
nick
parents:
diff changeset
494 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
495 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
496 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
497 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
498 r.eax = 0x4f05;
f4b588dba08a vbelib import
nick
parents:
diff changeset
499 r.ebx = (*win_num & 0x0f) | 0x0100;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
500 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
501 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
502 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
503 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
504 *win_num = r.edx & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
505 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
506 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
507 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
508 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
509
f4b588dba08a vbelib import
nick
parents:
diff changeset
510 int vbeSetWindow(unsigned win_num,unsigned win_gran)
f4b588dba08a vbelib import
nick
parents:
diff changeset
511 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
512 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
513 if(vbe_pm_info.SetWindowCall)
f4b588dba08a vbelib import
nick
parents:
diff changeset
514 {
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
515 /* Don't verbose this stuff from performance reasons */
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
516 /* 32-bit function call is much better of int 10h */
f4b588dba08a vbelib import
nick
parents:
diff changeset
517 __asm __volatile(
f4b588dba08a vbelib import
nick
parents:
diff changeset
518 "pushl %%ebx\n"
f4b588dba08a vbelib import
nick
parents:
diff changeset
519 "movl %1, %%ebx\n"
f4b588dba08a vbelib import
nick
parents:
diff changeset
520 ::"a"(0x4f05),"S"(win_num & 0x0f),"d"(win_gran):"memory");
f4b588dba08a vbelib import
nick
parents:
diff changeset
521 (*vbe_pm_info.SetWindowCall)();
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
522 __asm __volatile("popl %%ebx":::"memory");
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
523 retval = VBE_OK;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
524 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
525 else
f4b588dba08a vbelib import
nick
parents:
diff changeset
526 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
527 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
528 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
529 r.eax = 0x4f05;
f4b588dba08a vbelib import
nick
parents:
diff changeset
530 r.ebx = win_num & 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
531 r.edx = win_gran;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
532 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
533 retval = r.eax & 0xffff;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
534 if(retval == 0x4f) retval = VBE_OK;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
535 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
536 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
537 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
538
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
539 int vbeGetScanLineLength(unsigned *num_pixels,unsigned *num_bytes)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
540 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
541 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
542 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
543 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
544 r.eax = 0x4f06;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
545 r.ebx = 1;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
546 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
547 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
548 if(retval == 0x4f)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
549 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
550 if(num_bytes) *num_bytes = r.ebx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
551 if(num_pixels) *num_pixels= r.ecx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
552 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
553 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
554 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
555 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
556
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
557 int vbeGetMaxScanLines(unsigned *num_pixels,unsigned *num_bytes, unsigned *num_lines)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
558 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
559 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
560 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
561 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
562 r.eax = 0x4f06;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
563 r.ebx = 3;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
564 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
565 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
566 if(retval == 0x4f)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
567 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
568 if(num_bytes) *num_bytes = r.ebx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
569 if(num_pixels) *num_pixels= r.ecx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
570 if(num_lines) *num_lines = r.edx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
571 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
572 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
573 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
574 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
575
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
576 int vbeSetScanLineLength(unsigned num_pixels)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
577 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
578 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
579 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
580 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
581 r.eax = 0x4f06;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
582 r.ebx = 0;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
583 r.ecx = num_pixels;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
584 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
585 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
586 if(retval == 0x4f) retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
587 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
588 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
589
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
590 int vbeSetScanLineLengthB(unsigned num_bytes)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
591 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
592 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
593 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
594 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
595 r.eax = 0x4f06;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
596 r.ebx = 2;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
597 r.ecx = num_bytes;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
598 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
599 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
600 if(retval == 0x4f) retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
601 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
602 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
603
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
604 int vbeGetDisplayStart(unsigned *pixel_num,unsigned *scan_line)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
605 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
606 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
607 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
608 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
609 r.eax = 0x4f07;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
610 r.ebx = 1;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
611 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
612 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
613 if(retval == 0x4f)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
614 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
615 if(pixel_num) *pixel_num = r.ecx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
616 if(scan_line) *scan_line = r.edx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
617 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
618 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
619 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
620 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
621
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
622 int vbeSetDisplayStart(unsigned long offset, int vsync)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
623 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
624 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
625 if(vbe_pm_info.SetDisplayStart)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
626 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
627 /* Don't verbose this stuff from performance reasons */
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
628 /* 32-bit function call is much better of int 10h */
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
629 __asm __volatile(
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
630 "pushl %%ebx\n"
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
631 "movl %1, %%ebx\n"
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
632 ::"a"(0x4f07),"S"(vsync ? 0x80 : 0),
2686
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
633 "c"((offset>>2) & 0xffff),"d"((offset>>18)&0xffff):"memory");
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
634 (*vbe_pm_info.SetDisplayStart)();
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
635 __asm __volatile("popl %%ebx":::"memory");
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
636 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
637 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
638 else
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
639 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
640 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
641 unsigned long pixel_num;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
642 memset(&r,0,sizeof(struct LRMI_regs));
2686
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
643 pixel_num = offset%(unsigned long)curr_mode_info.BytesPerScanLine;
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
644 if(pixel_num*(unsigned long)curr_mode_info.BytesPerScanLine!=offset) pixel_num++;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
645 r.eax = 0x4f07;
2693
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
646 r.ebx = vsync ? 0x82 : 2;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
647 r.ecx = pixel_num;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
648 r.edx = offset/(unsigned long)curr_mode_info.BytesPerScanLine;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
649 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
650 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
651 if(retval == 0x4f) retval = VBE_OK;
13568
1cb0e1833515 Currently vbeGetProtModeInfo call the 0x4f0a function of int 10h the get
faust3
parents: 13352
diff changeset
652 else retval = VBE_BROKEN_BIOS;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
653 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
654 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
655 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
656
2693
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
657 int vbeSetScheduledDisplayStart(unsigned long offset, int vsync)
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
658 {
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
659 int retval;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
660 struct LRMI_regs r;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
661 unsigned long pixel_num;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
662 memset(&r,0,sizeof(struct LRMI_regs));
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
663 pixel_num = offset%(unsigned long)curr_mode_info.BytesPerScanLine;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
664 if(pixel_num*(unsigned long)curr_mode_info.BytesPerScanLine!=offset) pixel_num++;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
665 r.eax = 0x4f07;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
666 r.ebx = vsync ? 0x82 : 2;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
667 r.ecx = offset;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
668 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
669 retval = r.eax & 0xffff;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
670 if(retval == 0x4f) retval = VBE_OK;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
671 return retval;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
672 }
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
673
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
674 struct realVesaProtModeInterface
f4b588dba08a vbelib import
nick
parents:
diff changeset
675 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
676 unsigned short SetWindowCall;
f4b588dba08a vbelib import
nick
parents:
diff changeset
677 unsigned short SetDisplayStart;
f4b588dba08a vbelib import
nick
parents:
diff changeset
678 unsigned short SetPaletteData;
f4b588dba08a vbelib import
nick
parents:
diff changeset
679 unsigned short iopl_ports;
f4b588dba08a vbelib import
nick
parents:
diff changeset
680 }__attribute__((packed));
f4b588dba08a vbelib import
nick
parents:
diff changeset
681
f4b588dba08a vbelib import
nick
parents:
diff changeset
682 int vbeGetProtModeInfo(struct VesaProtModeInterface *pm_info)
f4b588dba08a vbelib import
nick
parents:
diff changeset
683 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
684 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
685 int retval;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
686 unsigned info_offset;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
687 struct realVesaProtModeInterface *rm_info;
f4b588dba08a vbelib import
nick
parents:
diff changeset
688 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
689 r.eax = 0x4f0a;
f4b588dba08a vbelib import
nick
parents:
diff changeset
690 r.ebx = 0;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
691 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
692 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
693 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
694 {
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
695 retval = VBE_OK;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
696 info_offset = r.edi&0xffff;
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
697 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
698 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
699 pm_info->SetWindowCall = PhysToVirtSO(r.es,info_offset+rm_info->SetWindowCall);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
700 if(!is_addr_valid(pm_info->SetWindowCall)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
701 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
702 if(verbose > 1) printf("vbelib: SetWindowCall=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetWindowCall,pm_info->SetWindowCall);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
703 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
704 pm_info->SetDisplayStart = PhysToVirtSO(r.es,info_offset+rm_info->SetDisplayStart);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
705 if(!is_addr_valid(pm_info->SetDisplayStart)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
706 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
707 if(verbose > 1) printf("vbelib: SetDisplayStart=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetDisplayStart,pm_info->SetDisplayStart);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
708 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
709 pm_info->SetPaletteData = PhysToVirtSO(r.es,info_offset+rm_info->SetPaletteData);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
710 if(!is_addr_valid(pm_info->SetPaletteData)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
711 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
712 if(verbose > 1) printf("vbelib: SetPaletteData=%04X:%04X => %p\n",r.es,info_offset+rm_info->SetPaletteData,pm_info->SetPaletteData);
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
713 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
714 pm_info->iopl_ports = PhysToVirtSO(r.es,info_offset+rm_info->iopl_ports);
2913
74731185c5c9 Fixed iopl ports detection
nick
parents: 2693
diff changeset
715 if(!rm_info->iopl_ports) pm_info->iopl_ports = NULL;
74731185c5c9 Fixed iopl ports detection
nick
parents: 2693
diff changeset
716 else
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
717 if(!check_wrd(pm_info->iopl_ports))
622cd80caaba memory verification
nick
parents: 2460
diff changeset
718 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
719 pm_info->iopl_ports = NULL;
2913
74731185c5c9 Fixed iopl ports detection
nick
parents: 2693
diff changeset
720 /* retval = VBE_BROKEN_BIOS; <- It's for broken BIOSes only */
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
721 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
722 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
723 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
724 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
725 printf("vbelib: iopl_ports=%04X:%04X => %p\n",r.es,info_offset+rm_info->iopl_ports,pm_info->iopl_ports);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
726 if(pm_info->iopl_ports) print_wrd(pm_info->iopl_ports);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
727 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
728 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
729 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
730 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
731 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
732 }
2410
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
733 /* --------- Standard VGA stuff -------------- */
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
734 int vbeWriteString(int x, int y, int attr, char *str)
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
735 {
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
736 struct LRMI_regs r;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
737 void *rm_space = NULL;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
738 int retval;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
739 memset(&r,0,sizeof(struct LRMI_regs));
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
740 r.ecx = strlen(str);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
741 r.edx = ((y<<8)&0xff00)|(x&0xff);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
742 r.ebx = attr;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
743 if(!(rm_space = LRMI_alloc_real(r.ecx))) return VBE_OUT_OF_DOS_MEM;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
744 r.es = VirtToPhysSeg(rm_space);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
745 r.ebp = VirtToPhysOff(rm_space);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
746 memcpy(rm_space,str,r.ecx);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
747 r.eax = 0x1300;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
748 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
749 LRMI_free_real(rm_space);
2410
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
750 if(!retval) return VBE_VM86_FAIL;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
751 retval = r.eax & 0xffff;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
752 if(retval == 0x4f) retval = VBE_OK;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
753 return retval;
2460
7925f241765b Suppress trivial warnings
nick
parents: 2445
diff changeset
754 }
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
755
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
756 void * vbeMapVideoBuffer(unsigned long phys_addr,unsigned long size)
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
757 {
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
758 void *lfb;
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
759 if(fd_mem == -1) return NULL;
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
760 if(verbose > 1) printf("vbelib: vbeMapVideoBuffer(%08lX,%08lX)\n",phys_addr,size);
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
761 /* Here we don't need with MAP_FIXED and prefered address (first argument) */
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
762 lfb = mmap((void *)0,size,PROT_READ | PROT_WRITE,MAP_SHARED,fd_mem,phys_addr);
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
763 return lfb == (void *)-1 ? 0 : lfb;
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
764 }
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
765
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
766 void vbeUnmapVideoBuffer(unsigned long linear_addr,unsigned long size)
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
767 {
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
768 if(verbose > 1) printf("vbelib: vbeUnmapVideoBuffer(%08lX,%08lX)\n",linear_addr,size);
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
769 munmap((void *)linear_addr,size);
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
770 }
11455
22f8732b5d97 cumulative libc5 compatibility patch ;)
gabucino
parents: 10114
diff changeset
771
22f8732b5d97 cumulative libc5 compatibility patch ;)
gabucino
parents: 10114
diff changeset
772 #endif