Rev 479 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
477 | giacomo | 1 | #include <ll/i386/hw-data.h> |
2 | #include <ll/i386/mem.h> |
||
3 | #include <ll/i386/string.h> |
||
4 | #include <ll/i386/x-dos.h> |
||
5 | #include <ll/i386/x-dosmem.h> |
||
6 | #include <ll/i386/cons.h> |
||
7 | #include <ll/sys/ll/ll-func.h> |
||
8 | |||
9 | #include "vesa.h" |
||
10 | |||
11 | VbeInfoBlock VbeInfo; /* VBE 2.0 Informations */ |
||
12 | DWORD vbe_screen; /* Frame Linear Buffer Address */ |
||
13 | |||
14 | char VideoModeNames [96][40] = { |
||
15 | "100 - 640x400 256 colors", "101 - 640x480 256 colors", "102 - 800x600 16 colors", |
||
16 | "103 - 800x600 256 colors", "104 - 1024x768 16 colors", "105 - 1024x768 256 colors", |
||
17 | "106 - 1280x1024 16 colors", "107 - 1280x1024 256 colors", "108 - 80x60 Text Mode", |
||
18 | "109 - 132x25 Text Mode", "10A - 132x43 Text Mode", "10B - 132x50 Text Mode", |
||
19 | "10C - 132x60 Text Mode", "10D - 320x200 32,768 colors", "10E - 320x200 65,536 colors", |
||
20 | "10F - 320x200 16m colors", "110 - 640x480 32,768 colors", "111 - 640x480 65,536 colors", |
||
21 | "112 - 640x480 16m colors", "113 - 800x600 32,768 colors", "114 - 800x600 65,536 colors", |
||
22 | "115 - 800x600 16m colors", "116 - 1024x768 32,768 colors", "117 - 1024x768 65,536 colors", |
||
23 | "118 - 1024x768 16m colors", "119 - 1280x1024 32,768 colors", "11A - 1280x1024 65,536 colors", |
||
24 | "11B - 1280x1024 16m colors", "11C - 640x350 256 colors", "11D - 640x350 32,768 colors", |
||
25 | "11E - 640x400 32,768 colors", "11F - 640x350 65,536 colors", "120 - 640x400 65,536 colors", |
||
26 | "121 - 640x350 16m colors", "122 - 640x400 16m colors", "123 - 1600x1200 16 colors", |
||
27 | "124 - 1600x1200 256 colors", "125 - 1600x1200 32,768 colors", "126 - 1600x1200 65,536 colors", |
||
28 | "127 - 1600x1200 16m colors", "128 - 640x480 16m colors(*)", "129 - 800x600 16m colors(*)", |
||
29 | "12A - 1024x768 16m colors(*)", "12B - 1280x1024 16m colors(*)", "12C - 1600x1200 16m colors(*)", |
||
30 | "12D - 320x240 32,768 colors", "12E - 320x400 32,768 colors", "12F - 360x200 32,768 colors", |
||
31 | "130 - 360x240 32,768 colors", "131 - 360x400 32,768 colors", "132 - 320x240 65,536 colors", |
||
32 | "133 - 320x400 65,536 colors", "134 - 360x200 65,536 colors", "135 - 360x240 65,536 colors", |
||
33 | "136 - 360x400 65,536 colors", "137 - 320x240 16m colors", "138 - 320x400 16m colors", |
||
34 | "139 - name n/a", "13A - name n/a", "13B - name n/a", |
||
35 | "13C - name n/a", "13D - name n/a", "13E - name n/a", |
||
36 | "13F - name n/a", "140 - name n/a", "141 - name n/a", |
||
37 | "142 - 640x350 16m colors(*)", "143 - 640x400 16m colors(*)", "144 - name n/a", |
||
38 | "145 - name n/a", "146 - name n/a", "147 - name n/a", |
||
39 | "148 - name n/a", "149 - name n/a", "14A - name n/a", |
||
40 | "14B - name n/a", "14C - name n/a", "14D - name n/a", |
||
41 | "14E - name n/a", "14F - name n/a", "150 - 640x350 16 colors", |
||
42 | "151 - 640x400 16 colors", "152 - 640x480 16 colors", "153 - 320x200 256 colors", |
||
43 | "154 - 320x240 256 colors", "155 - 320x400 256 colors", "156 - 360x200 256 colors", |
||
44 | "157 - 360x240 256 colors", "158 - 360x400 256 colors", "159 - name n/a", |
||
45 | "15A - name n/a", "15B - name n/a", "15C - name n/a", |
||
46 | "15D - name n/a", "15E - name n/a", "15F - name n/a" |
||
47 | }; |
||
48 | |||
479 | giacomo | 49 | #define NMODES 13 |
50 | static struct gmode allmodes[NMODES] = { |
||
1022 | mauro | 51 | {640, 400, 640, 8, 0x4100}, |
52 | {640, 480, 640, 8, 0x4101}, |
||
53 | {800, 600, 800, 8, 0x4103}, |
||
54 | {1024, 768, 1024, 8, 0x4105}, |
||
55 | {640, 480, 1280, 15, 0x4110}, |
||
56 | {800, 600, 1600, 15, 0x4113}, |
||
57 | {1024, 768, 2048, 15, 0x4116}, |
||
58 | {640, 480, 1280, 16, 0x4111}, |
||
59 | {800, 600, 1600, 16, 0x4114}, |
||
60 | {1024, 768, 2048, 16, 0x4117}, |
||
61 | {640, 480, 1920, 24, 0x4112}, |
||
62 | {800, 600, 2400, 24, 0x4115}, |
||
63 | {1024, 768, 3072, 24, 0x4118} |
||
479 | giacomo | 64 | }; |
65 | |||
477 | giacomo | 66 | int vbe_check_status (WORD vbe_function_result) |
67 | { |
||
1022 | mauro | 68 | if (vbe_function_result != 0x004f) { |
69 | switch (vbe_function_result) { |
||
70 | case 0x014f : return -1; /* VBE Generic error */ |
||
71 | case 0x024f : return -2; /* Hardware incompatibility error */ |
||
72 | case 0x034f : return -3; /* Unvalid function requested */ |
||
73 | default : return -4; /* Unknown error */ |
||
74 | } |
||
477 | giacomo | 75 | } |
1022 | mauro | 76 | return 1; |
477 | giacomo | 77 | } |
78 | |||
479 | giacomo | 79 | int vbe_modenum(WORD x, WORD y, BYTE depth) |
80 | { |
||
1022 | mauro | 81 | int mode, i; |
479 | giacomo | 82 | |
1022 | mauro | 83 | mode = -1; |
478 | giacomo | 84 | |
1022 | mauro | 85 | for (i = 0; i < NMODES; i++) { |
86 | if ((depth == allmodes[i].bpp) && (x == allmodes[i].xdim) && (y == allmodes[i].ydim)) { |
||
87 | mode = allmodes[i].modenum; |
||
88 | } |
||
89 | } |
||
478 | giacomo | 90 | |
1022 | mauro | 91 | return mode; |
92 | } |
||
93 | |||
94 | void vbe_restore_vga(void) |
||
95 | { |
||
96 | X_REGS16 inregs, outregs; |
||
97 | X_SREGS16 sregs; |
||
478 | giacomo | 98 | #ifndef VM86 |
1022 | mauro | 99 | BYTE p1,p2; |
478 | giacomo | 100 | #endif |
1022 | mauro | 101 | |
102 | inregs.x.ax = 0x03; |
||
478 | giacomo | 103 | #ifndef VM86 |
1022 | mauro | 104 | p1 = inp(0x21); |
105 | p2 = inp(0xA1); |
||
106 | outp(0x21,0xFF); |
||
107 | outp(0xA1,0xFF); |
||
108 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
109 | outp(0x21,p1); |
||
110 | outp(0xA1,p2); |
||
478 | giacomo | 111 | #else |
1022 | mauro | 112 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
478 | giacomo | 113 | #endif |
114 | } |
||
115 | |||
477 | giacomo | 116 | int vbe_getinfo(void) |
117 | { |
||
1022 | mauro | 118 | X_REGS16 inregs, outregs; /* registri normali */ |
119 | X_SREGS16 sregs; /* registri estesi */ |
||
120 | LIN_ADDR DOSaddr; |
||
121 | DWORD linearaddr; |
||
477 | giacomo | 122 | #ifndef VM86 |
1022 | mauro | 123 | BYTE p1, p2; |
477 | giacomo | 124 | #endif |
125 | |||
1022 | mauro | 126 | /* Allochiamo mem per il nostro blocco */ |
127 | if ((DOSaddr = DOS_alloc(sizeof(VbeInfoBlock))) == 0) { |
||
128 | /* set_text_mode ();*/ |
||
129 | return -1; |
||
130 | } else { |
||
131 | /*linearaddr = appl2linear(DOSaddr);*/ |
||
132 | linearaddr = (DWORD) DOSaddr; |
||
477 | giacomo | 133 | |
1022 | mauro | 134 | /* 0x00 = Get Vbe2.0 Info */ |
135 | inregs.x.ax = 0x4f00; |
||
136 | /* Indirizzo reale del nostro blocco */ |
||
137 | inregs.x.di = linearaddr & 0x000F; |
||
138 | sregs.es = ((linearaddr & 0xFFFF0) >> 4); |
||
139 | sregs.ds = ((linearaddr & 0xFFFF0) >> 4); |
||
477 | giacomo | 140 | |
1022 | mauro | 141 | /* Settiamo il VbeSignature correttamente */ |
142 | VbeInfo.VbeSignature[0] = 'V'; |
||
143 | VbeInfo.VbeSignature[1] = 'B'; |
||
144 | VbeInfo.VbeSignature[2] = 'E'; |
||
145 | VbeInfo.VbeSignature[3] = '2'; |
||
477 | giacomo | 146 | |
1022 | mauro | 147 | memcpy((void *)linearaddr, &VbeInfo, sizeof(VbeInfo)); |
148 | |||
477 | giacomo | 149 | #ifndef VM86 |
1022 | mauro | 150 | p1 = inp(0x21); |
151 | p2 = inp(0xA1); |
||
152 | outp(0x21,0xFF); |
||
153 | outp(0xA1,0xFF); |
||
154 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
155 | outp(0x21,p1); |
||
156 | outp(0xA1,p2); |
||
477 | giacomo | 157 | #else |
1022 | mauro | 158 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
477 | giacomo | 159 | #endif |
1022 | mauro | 160 | if (vbe_check_status(outregs.x.ax) < 0) |
161 | return -1; |
||
162 | memcpy(&VbeInfo, (void *)linearaddr, sizeof(VbeInfo)); |
||
163 | |||
164 | return 0; |
||
165 | } |
||
477 | giacomo | 166 | } |
167 | |||
168 | void vbe_showmodes(void) |
||
169 | { |
||
1022 | mauro | 170 | short int modec; |
171 | WORD list; |
||
172 | LIN_ADDR VideoModeaddr; |
||
477 | giacomo | 173 | |
1022 | mauro | 174 | list=0; |
175 | VideoModeaddr = (LIN_ADDR)((VbeInfo.SupportedModesSegment<<4) + VbeInfo.SupportedModesOffset); |
||
477 | giacomo | 176 | |
1022 | mauro | 177 | cprintf ("\nList of modes supported:\n"); |
178 | do { |
||
179 | memcpy(&modec, VideoModeaddr, 2); |
||
180 | VideoModeaddr += 2; |
||
181 | if (modec != -1) cprintf (" %s ", VideoModeNames[modec - 0x100]); |
||
182 | list++; |
||
183 | if (list % 2 == 0) cprintf ("\n"); |
||
184 | } while ((modec != -1) && (list < 40)); |
||
477 | giacomo | 185 | |
1022 | mauro | 186 | cprintf ("\nToal modes supported: %d", list); |
477 | giacomo | 187 | } |
188 | |||
189 | DWORD vbe_getmodeinfo(ModeInfoBlock *ModeInfo, WORD Vbe_Mode) |
||
190 | { |
||
1022 | mauro | 191 | X_REGS16 inregs, outregs; |
192 | X_SREGS16 sregs; |
||
193 | LIN_ADDR dosaddr; |
||
477 | giacomo | 194 | #ifndef VM86 |
1022 | mauro | 195 | BYTE p1, p2; |
477 | giacomo | 196 | #endif |
197 | |||
1022 | mauro | 198 | if ((dosaddr = DOS_alloc(sizeof(ModeInfoBlock))) == 0) { |
199 | return(-1); |
||
200 | } |
||
477 | giacomo | 201 | |
1022 | mauro | 202 | /* 0x01 = Get Vbe Mode Info */ |
203 | inregs.x.ax = 0x4f01; |
||
204 | inregs.x.cx = Vbe_Mode; |
||
477 | giacomo | 205 | |
1022 | mauro | 206 | inregs.x.di = (DWORD)dosaddr & 0x000F; |
207 | sregs.es = (((DWORD)dosaddr & 0xFFFF0) >> 4); |
||
208 | sregs.ds = (((DWORD)dosaddr & 0xFFFF0) >> 4); |
||
477 | giacomo | 209 | |
210 | #ifndef VM86 |
||
211 | p1 = inp(0x21); |
||
212 | p2 = inp(0xA1); |
||
213 | outp(0x21,0xFF); |
||
214 | outp(0xA1,0xFF); |
||
215 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
216 | outp(0x21,p1); |
||
217 | outp(0xA1,p2); |
||
218 | #else |
||
219 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
220 | #endif |
||
1022 | mauro | 221 | if (vbe_check_status (outregs.x.ax) < 0) { |
222 | return -1; |
||
223 | } |
||
477 | giacomo | 224 | |
1022 | mauro | 225 | memcpy(ModeInfo, dosaddr, sizeof(ModeInfoBlock)); |
477 | giacomo | 226 | |
1022 | mauro | 227 | vbe_screen = ModeInfo->PhysBasePtr; |
228 | if(vbe_screen == -1) { |
||
229 | return -1; |
||
230 | } |
||
231 | return vbe_screen; |
||
477 | giacomo | 232 | } |
233 | |||
234 | DWORD vbe_getflb(void) |
||
235 | { |
||
1022 | mauro | 236 | return vbe_screen; |
477 | giacomo | 237 | } |
238 | |||
239 | int vbe_setmode (WORD Vbe_Mode) |
||
240 | { |
||
1022 | mauro | 241 | X_REGS16 inregs, outregs; |
242 | X_SREGS16 sregs; |
||
477 | giacomo | 243 | #ifndef VM86 |
1022 | mauro | 244 | BYTE p1, p2; |
477 | giacomo | 245 | #endif |
246 | |||
1022 | mauro | 247 | memset (&inregs, 0, sizeof(inregs)); |
248 | /* Set Vesa Vbe mode */ |
||
249 | inregs.x.ax = 0x4f02; |
||
250 | inregs.x.bx = Vbe_Mode; |
||
477 | giacomo | 251 | #ifndef VM86 |
252 | p1 = inp(0x21); |
||
253 | p2 = inp(0xA1); |
||
254 | outp(0x21,0xFF); |
||
255 | outp(0xA1,0xFF); |
||
256 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
257 | outp(0x21,p1); |
||
258 | outp(0xA1,p2); |
||
259 | #else |
||
260 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
261 | #endif |
||
1022 | mauro | 262 | return 1; //vbe_check_status (outregs.x.ax); |
477 | giacomo | 263 | } |
264 | |||
265 | WORD vbe_getbpr(ModeInfoBlock *ModeInfo) |
||
266 | { |
||
1022 | mauro | 267 | return ModeInfo->BytesPerScanLine; |
477 | giacomo | 268 | } |
269 | |||
270 | int vbe_setbank(ModeInfoBlock *ModeInfo, BYTE bank) |
||
271 | { |
||
1022 | mauro | 272 | X_REGS16 inregs, outregs; |
273 | X_SREGS16 sregs; |
||
477 | giacomo | 274 | #ifndef VM86 |
1022 | mauro | 275 | BYTE p1, p2; |
477 | giacomo | 276 | #endif |
277 | |||
1022 | mauro | 278 | memset (&inregs, 0, sizeof(inregs)); |
279 | memset (&sregs, 0, sizeof(sregs)); |
||
280 | /* Set Window */ |
||
281 | inregs.x.ax = 0x4f05; |
||
282 | inregs.h.bh = 0x00; |
||
283 | inregs.h.bl = 0x00; |
||
284 | inregs.x.dx = (64 / ModeInfo->WinGranularity) * bank; |
||
477 | giacomo | 285 | #ifndef VM86 |
286 | p1 = inp(0x21); |
||
287 | p2 = inp(0xA1); |
||
288 | outp(0x21,0xFF); |
||
289 | outp(0xA1,0xFF); |
||
290 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
291 | outp(0x21,p1); |
||
292 | outp(0xA1,p2); |
||
293 | #else |
||
294 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
295 | #endif |
||
1022 | mauro | 296 | return vbe_check_status (outregs.x.ax); |
477 | giacomo | 297 | } |
298 | |||
299 | DWORD vbe_getmem(void) |
||
300 | { |
||
1022 | mauro | 301 | return (VbeInfo.TotalMemory<<6) * 1024; |
477 | giacomo | 302 | } |