annotate osdep/vbelib.c @ 10417:008ff00f4223

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