annotate linux/vbelib.c @ 4706:a4400910be9f

yv12 slices fix by Robert Kesterson <robertk@robertk.com>
author arpi
date Thu, 14 Feb 2002 22:31:21 +0000
parents 7eda15bbb3f9
children 6c45b8bf9a3e
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;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
115 int vbeInit( void )
f4b588dba08a vbelib import
nick
parents:
diff changeset
116 {
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
117 unsigned short iopl_port;
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
118 size_t i;
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
119 int retval;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
120 if(!LRMI_init()) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
121 /*
f4b588dba08a vbelib import
nick
parents:
diff changeset
122 Allow read/write to ALL io ports
f4b588dba08a vbelib import
nick
parents:
diff changeset
123 */
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
124 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
125 /* Video BIOS should be at C000:0000 and above */
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
126 hh_int_10_seg >>= 12;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
127 if(hh_int_10_seg < 0xC) return VBE_BROKEN_BIOS;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
128 ioperm(0, 1024, 1);
f4b588dba08a vbelib import
nick
parents:
diff changeset
129 iopl(3);
f4b588dba08a vbelib import
nick
parents:
diff changeset
130 memset(&vbe_pm_info,0,sizeof(struct VesaProtModeInterface));
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
131 retval = vbeGetProtModeInfo(&vbe_pm_info);
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
132 if(retval != VBE_OK) return retval;
2359
ee6ef0b10655 More iopl'ed ports and test for brken BIOS
nick
parents: 2294
diff changeset
133 i = 0;
2913
74731185c5c9 Fixed iopl ports detection
nick
parents: 2693
diff changeset
134 if(vbe_pm_info.iopl_ports) /* Can be NULL !!!*/
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
135 while((iopl_port=vbe_pm_info.iopl_ports[i]) != 0xFFFF
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
136 && 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
137 iopl(3);
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
138 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
139 hide_terminal_output();
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
140 return VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
141 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
142
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
143 int vbeDestroy( void )
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
144 {
3016
ea414257856f Hide terminal's output and text-mode cursor for LCD and DFP
nick
parents: 2913
diff changeset
145 __set_cursor_type(my_stdout,1);
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
146 close(fd_mem);
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
147 return VBE_OK;
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
148 }
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
149
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
150 /* Fixme!!! This code is compatible only with mplayer's version of lrmi*/
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
151 static inline int is_addr_valid(const void *p)
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
152 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
153 return (p < (const void *)0x502) ||
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
154 (p >= (const void *)0x10000 && p < (const void *)0x20000) ||
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
155 (p >= (const void *)0xa0000 && p < (const void *)0x100000);
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
156 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
157
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
158 static int check_str(const unsigned char *str)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
159 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
160 size_t i;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
161 int null_found = 0;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
162 for(i = 0;i < 256;i++)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
163 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
164 if(is_addr_valid(&str[i]))
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
165 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
166 if(VERR(&str[i]))
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
167 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
168 if(!str[i]) { null_found = 1; break; }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
169 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
170 else break;
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
171 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
172 else break;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
173 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
174 return null_found;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
175 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
176
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
177 static int check_wrd(const unsigned short *str)
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
178 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
179 size_t i;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
180 int ffff_found = 0;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
181 for(i = 0;i < 1024;i++)
622cd80caaba memory verification
nick
parents: 2460
diff changeset
182 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
183 if(is_addr_valid(&str[i]))
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
184 {
2536
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
185 if(VERR(&str[i]))
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
186 {
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
187 if(str[i] == 0xffff) { ffff_found = 1; break; }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
188 }
6426007cad63 Fixed broken BIOS workaround
nick
parents: 2518
diff changeset
189 else break;
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
190 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
191 else break;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
192 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
193 return ffff_found;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
194 }
622cd80caaba memory verification
nick
parents: 2460
diff changeset
195
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
196 static void print_str(unsigned char *str)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
197 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
198 size_t i;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
199 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
200 printf("vbelib: ");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
201 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
202 printf("\n");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
203 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
204 }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
205
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
206 static void print_wrd(unsigned short *str)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
207 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
208 size_t i;
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
209 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
210 printf("vbelib: ");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
211 for(i = 0;i < 256;i++) { printf("%04X ",str[i]); if(str[i] == 0xffff) break; }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
212 printf("\n");
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
213 fflush(stdout);
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
214 }
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
215
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
216 int vbeGetControllerInfo(struct VbeInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
217 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
218 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
219 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
220 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
221 if(!(rm_space = LRMI_alloc_real(sizeof(struct VbeInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
222 memcpy(rm_space,data,sizeof(struct VbeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
223 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
224 r.eax = 0x4f00;
f4b588dba08a vbelib import
nick
parents:
diff changeset
225 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
226 r.edi = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
227 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
228 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
229 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
230 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
231 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
232 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
233 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
234 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
235 FarPtr fpdata;
f4b588dba08a vbelib import
nick
parents:
diff changeset
236 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
237 memcpy(data,rm_space,sizeof(struct VbeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
238 fpdata.seg = (unsigned long)(data->OemStringPtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
239 fpdata.off = (unsigned long)(data->OemStringPtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
240 data->OemStringPtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
241 if(!check_str(data->OemStringPtr)) data->OemStringPtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
242 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
243 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
244 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
245 printf("vbelib: OemStringPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemStringPtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
246 if(data->OemStringPtr) print_str(data->OemStringPtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
247 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
248 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
249 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
250 fpdata.seg = (unsigned long)(data->VideoModePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
251 fpdata.off = (unsigned long)(data->VideoModePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
252 data->VideoModePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
253 if(!check_wrd(data->VideoModePtr))
622cd80caaba memory verification
nick
parents: 2460
diff changeset
254 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
255 data->VideoModePtr = NULL;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
256 retval = VBE_BROKEN_BIOS;
622cd80caaba memory verification
nick
parents: 2460
diff changeset
257 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
258 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
259 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
260 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
261 printf("vbelib: VideoModePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->VideoModePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
262 if(data->VideoModePtr) print_wrd(data->VideoModePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
263 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
264 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
265 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
266 fpdata.seg = (unsigned long)(data->OemVendorNamePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
267 fpdata.off = (unsigned long)(data->OemVendorNamePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
268 data->OemVendorNamePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
269 if(!check_str(data->OemVendorNamePtr)) data->OemVendorNamePtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
270 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
271 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
272 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
273 printf("vbelib: OemVendorNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemVendorNamePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
274 if(data->OemVendorNamePtr) print_str(data->OemVendorNamePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
275 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
276 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
277 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
278 fpdata.seg = (unsigned long)(data->OemProductNamePtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
279 fpdata.off = (unsigned long)(data->OemProductNamePtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
280 data->OemProductNamePtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
281 if(!check_str(data->OemProductNamePtr)) data->OemProductNamePtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
282 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
283 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
284 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
285 printf("vbelib: OemProductNamePtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductNamePtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
286 if(data->OemVendorNamePtr) print_str(data->OemProductNamePtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
287 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
288 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
289 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
290 fpdata.seg = (unsigned long)(data->OemProductRevPtr) >> 16;
f4b588dba08a vbelib import
nick
parents:
diff changeset
291 fpdata.off = (unsigned long)(data->OemProductRevPtr) & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
292 data->OemProductRevPtr = PhysToVirt(fpdata);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
293 if(!check_str(data->OemProductRevPtr)) data->OemProductRevPtr = NULL;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
294 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
295 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
296 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
297 printf("vbelib: OemProductRevPtr=%04X:%04X => %p\n",fpdata.seg,fpdata.off,data->OemProductRevPtr);
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
298 if(data->OemProductRevPtr) print_str(data->OemProductRevPtr);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
299 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
300 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
301 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
302 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
303 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
304 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
305
f4b588dba08a vbelib import
nick
parents:
diff changeset
306 int vbeGetModeInfo(unsigned mode,struct VesaModeInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
307 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
308 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
309 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
310 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
311 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaModeInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
312 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
313 r.eax = 0x4f01;
f4b588dba08a vbelib import
nick
parents:
diff changeset
314 r.ecx = mode;
f4b588dba08a vbelib import
nick
parents:
diff changeset
315 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
316 r.edi = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
317 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
318 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
319 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
320 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
321 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
322 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
323 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
324 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
325 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
326 memcpy(data,rm_space,sizeof(struct VesaModeInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
327 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
328 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
329 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
330
f4b588dba08a vbelib import
nick
parents:
diff changeset
331 int vbeSetMode(unsigned mode,struct VesaCRTCInfoBlock *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
332 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
333 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
334 void *rm_space = NULL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
335 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
336 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
337 if(data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
338 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
339 if(!(rm_space = LRMI_alloc_real(sizeof(struct VesaCRTCInfoBlock)))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
340 r.es = VirtToPhysSeg(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
341 r.edi = VirtToPhysOff(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
342 memcpy(rm_space,data,sizeof(struct VesaCRTCInfoBlock));
f4b588dba08a vbelib import
nick
parents:
diff changeset
343 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
344 r.eax = 0x4f02;
f4b588dba08a vbelib import
nick
parents:
diff changeset
345 r.ebx = mode;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
346 retval = VBE_LRMI_int(0x10,&r);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
347 if(rm_space) LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
348 if(!retval) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
349 retval = r.eax & 0xffff;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
350 if(retval == 0x4f)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
351 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
352 /* Just info for internal use (currently in SetDiplayStart func). */
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
353 vbeGetModeInfo(mode&0x1f,&curr_mode_info);
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
354 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
355 }
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
356 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
357 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
358
f4b588dba08a vbelib import
nick
parents:
diff changeset
359 int vbeGetMode(unsigned *mode)
f4b588dba08a vbelib import
nick
parents:
diff changeset
360 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
361 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
362 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
363 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
364 r.eax = 0x4f03;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
365 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
366 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
367 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
368 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
369 *mode = r.ebx;
f4b588dba08a vbelib import
nick
parents:
diff changeset
370 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
371 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
372 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
373 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
374
f4b588dba08a vbelib import
nick
parents:
diff changeset
375 int vbeSaveState(void **data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
376 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
377 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
378 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
379 void *rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
380 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
381 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
382 r.edx = 0x00;
f4b588dba08a vbelib import
nick
parents:
diff changeset
383 r.ecx = 0x0f;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
384 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
385 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
386 if(retval != 0x4f) return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
387 if(!(rm_space = LRMI_alloc_real((r.ebx & 0xffff)*64))) return VBE_OUT_OF_DOS_MEM;
f4b588dba08a vbelib import
nick
parents:
diff changeset
388 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
389 r.edx = 0x01;
f4b588dba08a vbelib import
nick
parents:
diff changeset
390 r.ecx = 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
391 r.es = VirtToPhysSeg(rm_space);
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
392 r.ebx = VirtToPhysOff(rm_space);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
393 if(!VBE_LRMI_int(0x10,&r))
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
394 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
395 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
396 return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
397 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
398 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
399 if(retval != 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
400 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
401 LRMI_free_real(rm_space);
f4b588dba08a vbelib import
nick
parents:
diff changeset
402 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
403 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
404 *data = rm_space;
f4b588dba08a vbelib import
nick
parents:
diff changeset
405 return VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
406 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
407
f4b588dba08a vbelib import
nick
parents:
diff changeset
408 int vbeRestoreState(void *data)
f4b588dba08a vbelib import
nick
parents:
diff changeset
409 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
410 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
411 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
412 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
413 r.eax = 0x4f04;
f4b588dba08a vbelib import
nick
parents:
diff changeset
414 r.edx = 0x02;
f4b588dba08a vbelib import
nick
parents:
diff changeset
415 r.ecx = 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
416 r.es = VirtToPhysSeg(data);
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
417 r.ebx = VirtToPhysOff(data);
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
418 retval = VBE_LRMI_int(0x10,&r);
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
419 LRMI_free_real(data);
f4b588dba08a vbelib import
nick
parents:
diff changeset
420 if(!retval) return VBE_VM86_FAIL;
f4b588dba08a vbelib import
nick
parents:
diff changeset
421 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
422 if(retval == 0x4f) retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
423 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
424 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
425
f4b588dba08a vbelib import
nick
parents:
diff changeset
426 int vbeGetWindow(unsigned *win_num)
f4b588dba08a vbelib import
nick
parents:
diff changeset
427 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
428 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
429 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
430 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
431 r.eax = 0x4f05;
f4b588dba08a vbelib import
nick
parents:
diff changeset
432 r.ebx = (*win_num & 0x0f) | 0x0100;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
433 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
434 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
435 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
436 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
437 *win_num = r.edx & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
438 retval = VBE_OK;
f4b588dba08a vbelib import
nick
parents:
diff changeset
439 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
440 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
441 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
442
f4b588dba08a vbelib import
nick
parents:
diff changeset
443 int vbeSetWindow(unsigned win_num,unsigned win_gran)
f4b588dba08a vbelib import
nick
parents:
diff changeset
444 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
445 int retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
446 if(vbe_pm_info.SetWindowCall)
f4b588dba08a vbelib import
nick
parents:
diff changeset
447 {
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
448 /* Don't verbose this stuff from performance reasons */
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
449 /* 32-bit function call is much better of int 10h */
f4b588dba08a vbelib import
nick
parents:
diff changeset
450 __asm __volatile(
f4b588dba08a vbelib import
nick
parents:
diff changeset
451 "pushl %%ebx\n"
f4b588dba08a vbelib import
nick
parents:
diff changeset
452 "movl %1, %%ebx\n"
f4b588dba08a vbelib import
nick
parents:
diff changeset
453 ::"a"(0x4f05),"S"(win_num & 0x0f),"d"(win_gran):"memory");
f4b588dba08a vbelib import
nick
parents:
diff changeset
454 (*vbe_pm_info.SetWindowCall)();
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
455 __asm __volatile("popl %%ebx":::"memory");
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
456 retval = VBE_OK;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
457 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
458 else
f4b588dba08a vbelib import
nick
parents:
diff changeset
459 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
460 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
461 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
462 r.eax = 0x4f05;
f4b588dba08a vbelib import
nick
parents:
diff changeset
463 r.ebx = win_num & 0x0f;
f4b588dba08a vbelib import
nick
parents:
diff changeset
464 r.edx = win_gran;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
465 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
466 retval = r.eax & 0xffff;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
467 if(retval == 0x4f) retval = VBE_OK;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
468 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
469 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
470 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
471
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
472 int vbeGetScanLineLength(unsigned *num_pixels,unsigned *num_bytes)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
473 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
474 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
475 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
476 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
477 r.eax = 0x4f06;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
478 r.ebx = 1;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
479 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
480 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
481 if(retval == 0x4f)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
482 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
483 if(num_bytes) *num_bytes = r.ebx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
484 if(num_pixels) *num_pixels= r.ecx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
485 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
486 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
487 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
488 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
489
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
490 int vbeGetMaxScanLines(unsigned *num_pixels,unsigned *num_bytes, unsigned *num_lines)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
491 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
492 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
493 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
494 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
495 r.eax = 0x4f06;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
496 r.ebx = 3;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
497 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
498 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
499 if(retval == 0x4f)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
500 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
501 if(num_bytes) *num_bytes = r.ebx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
502 if(num_pixels) *num_pixels= r.ecx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
503 if(num_lines) *num_lines = r.edx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
504 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
505 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
506 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
507 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
508
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
509 int vbeSetScanLineLength(unsigned num_pixels)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
510 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
511 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
512 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
513 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
514 r.eax = 0x4f06;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
515 r.ebx = 0;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
516 r.ecx = num_pixels;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
517 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
518 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
519 if(retval == 0x4f) retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
520 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
521 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
522
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
523 int vbeSetScanLineLengthB(unsigned num_bytes)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
524 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
525 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
526 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
527 memset(&r,0,sizeof(struct LRMI_regs));
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
528 r.eax = 0x4f06;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
529 r.ebx = 2;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
530 r.ecx = num_bytes;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
531 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
532 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
533 if(retval == 0x4f) retval = VBE_OK;
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 vbeGetDisplayStart(unsigned *pixel_num,unsigned *scan_line)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
538 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
539 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
540 int retval;
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 = 0x4f07;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
543 r.ebx = 1;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
544 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
545 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
546 if(retval == 0x4f)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
547 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
548 if(pixel_num) *pixel_num = r.ecx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
549 if(scan_line) *scan_line = r.edx & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
550 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
551 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
552 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
553 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
554
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
555 int vbeSetDisplayStart(unsigned long offset, int vsync)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
556 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
557 int retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
558 if(vbe_pm_info.SetDisplayStart)
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
559 {
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
560 /* Don't verbose this stuff from performance reasons */
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
561 /* 32-bit function call is much better of int 10h */
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
562 __asm __volatile(
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
563 "pushl %%ebx\n"
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
564 "movl %1, %%ebx\n"
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
565 ::"a"(0x4f07),"S"(vsync ? 0x80 : 0),
2686
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
566 "c"((offset>>2) & 0xffff),"d"((offset>>18)&0xffff):"memory");
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
567 (*vbe_pm_info.SetDisplayStart)();
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
568 __asm __volatile("popl %%ebx":::"memory");
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
569 retval = VBE_OK;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
570 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
571 else
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
572 {
2686
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
573 #if 0
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
574 /* Something wrong here */
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
575 struct LRMI_regs r;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
576 unsigned long pixel_num;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
577 memset(&r,0,sizeof(struct LRMI_regs));
2686
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
578 pixel_num = offset%(unsigned long)curr_mode_info.BytesPerScanLine;
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
579 if(pixel_num*(unsigned long)curr_mode_info.BytesPerScanLine!=offset) pixel_num++;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
580 r.eax = 0x4f07;
2693
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
581 r.ebx = vsync ? 0x82 : 2;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
582 r.ecx = pixel_num;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
583 r.edx = offset/(unsigned long)curr_mode_info.BytesPerScanLine;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
584 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
585 retval = r.eax & 0xffff;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
586 if(retval == 0x4f) retval = VBE_OK;
2686
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
587 #endif
44ff6b5c7cea Double buffering support
nick
parents: 2632
diff changeset
588 retval = VBE_BROKEN_BIOS;
2632
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
589 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
590 return retval;
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
591 }
6e3cee9e07ef Double buffering interface
nick
parents: 2610
diff changeset
592
2693
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
593 int vbeSetScheduledDisplayStart(unsigned long offset, int vsync)
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
594 {
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
595 int retval;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
596 struct LRMI_regs r;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
597 unsigned long pixel_num;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
598 memset(&r,0,sizeof(struct LRMI_regs));
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
599 pixel_num = offset%(unsigned long)curr_mode_info.BytesPerScanLine;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
600 if(pixel_num*(unsigned long)curr_mode_info.BytesPerScanLine!=offset) pixel_num++;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
601 r.eax = 0x4f07;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
602 r.ebx = vsync ? 0x82 : 2;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
603 r.ecx = offset;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
604 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
605 retval = r.eax & 0xffff;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
606 if(retval == 0x4f) retval = VBE_OK;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
607 return retval;
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
608 }
1a8e5e017b1d triple buffering interface
nick
parents: 2686
diff changeset
609
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
610 struct realVesaProtModeInterface
f4b588dba08a vbelib import
nick
parents:
diff changeset
611 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
612 unsigned short SetWindowCall;
f4b588dba08a vbelib import
nick
parents:
diff changeset
613 unsigned short SetDisplayStart;
f4b588dba08a vbelib import
nick
parents:
diff changeset
614 unsigned short SetPaletteData;
f4b588dba08a vbelib import
nick
parents:
diff changeset
615 unsigned short iopl_ports;
f4b588dba08a vbelib import
nick
parents:
diff changeset
616 }__attribute__((packed));
f4b588dba08a vbelib import
nick
parents:
diff changeset
617
f4b588dba08a vbelib import
nick
parents:
diff changeset
618 int vbeGetProtModeInfo(struct VesaProtModeInterface *pm_info)
f4b588dba08a vbelib import
nick
parents:
diff changeset
619 {
f4b588dba08a vbelib import
nick
parents:
diff changeset
620 struct LRMI_regs r;
f4b588dba08a vbelib import
nick
parents:
diff changeset
621 int retval;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
622 unsigned info_offset;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
623 struct realVesaProtModeInterface *rm_info;
f4b588dba08a vbelib import
nick
parents:
diff changeset
624 memset(&r,0,sizeof(struct LRMI_regs));
f4b588dba08a vbelib import
nick
parents:
diff changeset
625 r.eax = 0x4f0a;
f4b588dba08a vbelib import
nick
parents:
diff changeset
626 r.ebx = 0;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
627 if(!VBE_LRMI_int(0x10,&r)) return VBE_VM86_FAIL;
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
628 retval = r.eax & 0xffff;
f4b588dba08a vbelib import
nick
parents:
diff changeset
629 if(retval == 0x4f)
f4b588dba08a vbelib import
nick
parents:
diff changeset
630 {
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
631 retval = VBE_OK;
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
632 info_offset = r.edi&0xffff;
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
633 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
634 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
635 pm_info->SetWindowCall = PhysToVirtSO(r.es,info_offset+rm_info->SetWindowCall);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
636 if(!is_addr_valid(pm_info->SetWindowCall)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
637 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
638 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
639 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
640 pm_info->SetDisplayStart = PhysToVirtSO(r.es,info_offset+rm_info->SetDisplayStart);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
641 if(!is_addr_valid(pm_info->SetDisplayStart)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
642 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
643 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
644 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
645 pm_info->SetPaletteData = PhysToVirtSO(r.es,info_offset+rm_info->SetPaletteData);
2552
bd734d41a407 Misc: more checks
nick
parents: 2536
diff changeset
646 if(!is_addr_valid(pm_info->SetPaletteData)) retval = VBE_BROKEN_BIOS;
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
647 #ifdef HAVE_VERBOSE_VAR
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
648 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
649 #endif
2254
6e5b548790c9 Fixed bug of 32-bit mode interface detection and save-restore mechanism
nick
parents: 2243
diff changeset
650 pm_info->iopl_ports = PhysToVirtSO(r.es,info_offset+rm_info->iopl_ports);
2913
74731185c5c9 Fixed iopl ports detection
nick
parents: 2693
diff changeset
651 if(!rm_info->iopl_ports) pm_info->iopl_ports = NULL;
74731185c5c9 Fixed iopl ports detection
nick
parents: 2693
diff changeset
652 else
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
653 if(!check_wrd(pm_info->iopl_ports))
622cd80caaba memory verification
nick
parents: 2460
diff changeset
654 {
622cd80caaba memory verification
nick
parents: 2460
diff changeset
655 pm_info->iopl_ports = NULL;
2913
74731185c5c9 Fixed iopl ports detection
nick
parents: 2693
diff changeset
656 /* retval = VBE_BROKEN_BIOS; <- It's for broken BIOSes only */
2515
622cd80caaba memory verification
nick
parents: 2460
diff changeset
657 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
658 #ifdef HAVE_VERBOSE_VAR
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
659 if(verbose > 1)
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
660 {
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
661 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
662 if(pm_info->iopl_ports) print_wrd(pm_info->iopl_ports);
2518
a3f658d3c98c More flushing
nick
parents: 2515
diff changeset
663 fflush(stdout);
2407
2e4c17f4a744 More verbosing
nick
parents: 2359
diff changeset
664 }
2294
9475a75dde9c More verbosing
nick
parents: 2254
diff changeset
665 #endif
2243
f4b588dba08a vbelib import
nick
parents:
diff changeset
666 }
f4b588dba08a vbelib import
nick
parents:
diff changeset
667 return retval;
f4b588dba08a vbelib import
nick
parents:
diff changeset
668 }
2410
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
669 /* --------- Standard VGA stuff -------------- */
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
670 int vbeWriteString(int x, int y, int attr, char *str)
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
671 {
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
672 struct LRMI_regs r;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
673 void *rm_space = NULL;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
674 int retval;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
675 memset(&r,0,sizeof(struct LRMI_regs));
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
676 r.ecx = strlen(str);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
677 r.edx = ((y<<8)&0xff00)|(x&0xff);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
678 r.ebx = attr;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
679 if(!(rm_space = LRMI_alloc_real(r.ecx))) return VBE_OUT_OF_DOS_MEM;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
680 r.es = VirtToPhysSeg(rm_space);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
681 r.ebp = VirtToPhysOff(rm_space);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
682 memcpy(rm_space,str,r.ecx);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
683 r.eax = 0x1300;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
684 retval = VBE_LRMI_int(0x10,&r);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
685 if(rm_space) LRMI_free_real(rm_space);
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
686 if(!retval) return VBE_VM86_FAIL;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
687 retval = r.eax & 0xffff;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
688 if(retval == 0x4f) retval = VBE_OK;
27ca5ad3c7e9 Title support
nick
parents: 2407
diff changeset
689 return retval;
2460
7925f241765b Suppress trivial warnings
nick
parents: 2445
diff changeset
690 }
2610
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
691
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
692 void * vbeMapVideoBuffer(unsigned long phys_addr,unsigned long size)
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
693 {
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
694 void *lfb;
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
695 if(fd_mem == -1) return NULL;
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
696 if(verbose > 1) printf("vbelib: vbeMapVideoBuffer(%08lX,%08lX)\n",phys_addr,size);
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
697 /* Here we don't need with MAP_FIXED and prefered address (first argument) */
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
698 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
699 return lfb == (void *)-1 ? 0 : lfb;
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
700 }
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
701
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
702 void vbeUnmapVideoBuffer(unsigned long linear_addr,unsigned long size)
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
703 {
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
704 if(verbose > 1) printf("vbelib: vbeUnmapVideoBuffer(%08lX,%08lX)\n",linear_addr,size);
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
705 munmap((void *)linear_addr,size);
65cb69a90a9f vo_vesa: DGA support
nick
parents: 2552
diff changeset
706 }