annotate osdep/vbelib.c @ 12108:06c4780332bc

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