Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 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 | #include "chips.h" |
||
11 | |||
12 | |||
13 | VbeInfoBlock VbeInfo; /* VBE 2.0 Informations */ |
||
14 | DWORD vbe_screen; /* Frame Linear Buffer Address */ |
||
15 | |||
16 | char VideoModeNames [96][40] = { |
||
17 | "100 - 640x400 256 colors", "101 - 640x480 256 colors", "102 - 800x600 16 colors", |
||
18 | "103 - 800x600 256 colors", "104 - 1024x768 16 colors", "105 - 1024x768 256 colors", |
||
19 | "106 - 1280x1024 16 colors", "107 - 1280x1024 256 colors", "108 - 80x60 Text Mode", |
||
20 | "109 - 132x25 Text Mode", "10A - 132x43 Text Mode", "10B - 132x50 Text Mode", |
||
21 | "10C - 132x60 Text Mode", "10D - 320x200 32,768 colors", "10E - 320x200 65,536 colors", |
||
22 | "10F - 320x200 16m colors", "110 - 640x480 32,768 colors", "111 - 640x480 65,536 colors", |
||
23 | "112 - 640x480 16m colors", "113 - 800x600 32,768 colors", "114 - 800x600 65,536 colors", |
||
24 | "115 - 800x600 16m colors", "116 - 1024x768 32,768 colors", "117 - 1024x768 65,536 colors", |
||
25 | "118 - 1024x768 16m colors", "119 - 1280x1024 32,768 colors", "11A - 1280x1024 65,536 colors", |
||
26 | "11B - 1280x1024 16m colors", "11C - 640x350 256 colors", "11D - 640x350 32,768 colors", |
||
27 | "11E - 640x400 32,768 colors", "11F - 640x350 65,536 colors", "120 - 640x400 65,536 colors", |
||
28 | "121 - 640x350 16m colors", "122 - 640x400 16m colors", "123 - 1600x1200 16 colors", |
||
29 | "124 - 1600x1200 256 colors", "125 - 1600x1200 32,768 colors", "126 - 1600x1200 65,536 colors", |
||
30 | "127 - 1600x1200 16m colors", "128 - 640x480 16m colors(*)", "129 - 800x600 16m colors(*)", |
||
31 | "12A - 1024x768 16m colors(*)", "12B - 1280x1024 16m colors(*)", "12C - 1600x1200 16m colors(*)", |
||
32 | "12D - 320x240 32,768 colors", "12E - 320x400 32,768 colors", "12F - 360x200 32,768 colors", |
||
33 | "130 - 360x240 32,768 colors", "131 - 360x400 32,768 colors", "132 - 320x240 65,536 colors", |
||
34 | "133 - 320x400 65,536 colors", "134 - 360x200 65,536 colors", "135 - 360x240 65,536 colors", |
||
35 | "136 - 360x400 65,536 colors", "137 - 320x240 16m colors", "138 - 320x400 16m colors", |
||
36 | "139 - name n/a", "13A - name n/a", "13B - name n/a", |
||
37 | "13C - name n/a", "13D - name n/a", "13E - name n/a", |
||
38 | "13F - name n/a", "140 - name n/a", "141 - name n/a", |
||
39 | "142 - 640x350 16m colors(*)", "143 - 640x400 16m colors(*)", "144 - name n/a", |
||
40 | "145 - name n/a", "146 - name n/a", "147 - name n/a", |
||
41 | "148 - name n/a", "149 - name n/a", "14A - name n/a", |
||
42 | "14B - name n/a", "14C - name n/a", "14D - name n/a", |
||
43 | "14E - name n/a", "14F - name n/a", "150 - 640x350 16 colors", |
||
44 | "151 - 640x400 16 colors", "152 - 640x480 16 colors", "153 - 320x200 256 colors", |
||
45 | "154 - 320x240 256 colors", "155 - 320x400 256 colors", "156 - 360x200 256 colors", |
||
46 | "157 - 360x240 256 colors", "158 - 360x400 256 colors", "159 - name n/a", |
||
47 | "15A - name n/a", "15B - name n/a", "15C - name n/a", |
||
48 | "15D - name n/a", "15E - name n/a", "15F - name n/a" |
||
49 | }; |
||
50 | |||
51 | int vbe_check_status (WORD vbe_function_result) |
||
52 | { |
||
53 | /* |
||
54 | if (vbe_function_result != 0x004f) { |
||
55 | cprintf("\nWarning! There was an error: (%x) ", vbe_function_result); |
||
56 | switch (vbe_function_result) { |
||
57 | case 0x014f : cprintf("generic."); break; |
||
58 | case 0x024f : cprintf("hardware incompatibility."); break; |
||
59 | case 0x034f : cprintf("unvalid function."); break; |
||
60 | default : cprintf("unknown error %x.\n", vbe_function_result); |
||
61 | } |
||
62 | */ |
||
63 | if (vbe_function_result != 0x004f) { |
||
64 | switch (vbe_function_result) { |
||
65 | case 0x014f : return -1; /* VBE Generic error */ |
||
66 | case 0x024f : return -2; /* Hardware incompatibility error */ |
||
67 | case 0x034f : return -3; /* Unvalid function requested */ |
||
68 | default : return -4; /* Unknown error */ |
||
69 | } |
||
70 | } |
||
71 | return 1; |
||
72 | } |
||
73 | |||
74 | int vbe_getinfo(void) |
||
75 | { |
||
76 | BYTE p1,p2; |
||
77 | X_REGS16 inregs, outregs; /* registri normali */ |
||
78 | X_SREGS16 sregs; /* registri estesi */ |
||
79 | LIN_ADDR DOSaddr; |
||
80 | DWORD linearaddr; |
||
81 | |||
82 | /* Allochiamo mem per il nostro blocco */ |
||
83 | if ((DOSaddr = DOS_alloc(sizeof(VbeInfoBlock))) == 0) { |
||
84 | /* set_text_mode ();*/ |
||
85 | return -1; |
||
86 | } else { |
||
87 | /* linearaddr = appl2linear(DOSaddr);*/ |
||
88 | linearaddr = (DWORD) DOSaddr; |
||
89 | |||
90 | /* 0x00 = Get Vbe2.0 Info */ |
||
91 | inregs.x.ax = 0x4f00; |
||
92 | /* Indirizzo reale del nostro blocco */ |
||
93 | inregs.x.di = linearaddr & 0x000F; |
||
94 | sregs.es = ((linearaddr & 0xFFFF0) >> 4); |
||
95 | sregs.ds = ((linearaddr & 0xFFFF0) >> 4); |
||
96 | |||
97 | /* Settiamo il VbeSignature correttamente */ |
||
98 | VbeInfo.VbeSignature[0] = 'V'; |
||
99 | VbeInfo.VbeSignature[1] = 'B'; |
||
100 | VbeInfo.VbeSignature[2] = 'E'; |
||
101 | VbeInfo.VbeSignature[3] = '2'; |
||
102 | |||
103 | memcpy((void *)linearaddr, &VbeInfo, sizeof(VbeInfo)); |
||
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); |
||
111 | if (vbe_check_status(outregs.x.ax) < 0) |
||
112 | return -1; |
||
113 | memcpy(&VbeInfo, (void *)linearaddr, sizeof(VbeInfo)); |
||
114 | return 1; |
||
115 | } |
||
116 | } |
||
117 | |||
118 | int vbe_check(char *key) |
||
119 | { |
||
120 | LIN_ADDR VendorNameaddr; |
||
121 | char VendorName[256]; |
||
122 | int i, k, len, found; |
||
123 | |||
124 | found = CHIP_NOT_FOUND; |
||
125 | VendorNameaddr = (void *)((VbeInfo.OemNameSegment<<4) + VbeInfo.OemNameOffset); |
||
126 | memcpy(VendorName, VendorNameaddr, 256); |
||
127 | |||
128 | len = strlen(key); |
||
129 | for (i = 0; i <= 512 - len; i++) { |
||
130 | if (VendorName[i] == key[0]) { |
||
131 | found = CHIP_FOUND; |
||
132 | for (k = 1; k < len; k++) { |
||
133 | if (VendorName[i + k] != key[k]) found = CHIP_NOT_FOUND; |
||
134 | } |
||
135 | if (found == CHIP_FOUND) return found; |
||
136 | } |
||
137 | } |
||
138 | return found; |
||
139 | } |
||
140 | |||
141 | int vbe_check_id(void) |
||
142 | { |
||
143 | if (vbe_check("Chips") == CHIP_FOUND) return CHIPS; |
||
144 | if (vbe_check("Cirrus") == CHIP_FOUND) return CIRRUS; |
||
145 | if (vbe_check("Diamond") == CHIP_FOUND) return DIAMOND; |
||
146 | if (vbe_check("ITT") == CHIP_FOUND) return ITT; |
||
147 | if (vbe_check("Western Digital") == CHIP_FOUND) return WD; |
||
148 | if (vbe_check("S3") == CHIP_FOUND) return S3; |
||
149 | if (vbe_check("Trident") == CHIP_FOUND) return TRIDENT; |
||
150 | if (vbe_check("Tseng") == CHIP_FOUND) return TSENG; |
||
151 | return UNKNOWN; |
||
152 | } |
||
153 | |||
154 | void vbe_showinfo(void) |
||
155 | { |
||
156 | char Name[256], VendorName[256], ProductName[256], ProductRev[256]; |
||
157 | LIN_ADDR Nameaddr, VendorNameaddr, ProductNameaddr, ProductRevaddr; |
||
158 | |||
159 | Nameaddr = (LIN_ADDR)((VbeInfo.OemNameSegment<<4) + VbeInfo.OemNameOffset); |
||
160 | memcpy(Name, Nameaddr, 256); |
||
161 | |||
162 | VendorNameaddr = (LIN_ADDR)((VbeInfo.OemVendorNameSegment<<4) + VbeInfo.OemVendorNameOffset); |
||
163 | memcpy(VendorName, VendorNameaddr, 256); |
||
164 | |||
165 | ProductNameaddr = (LIN_ADDR)((VbeInfo.OemProductNameSegment<<4) + VbeInfo.OemProductNameOffset); |
||
166 | memcpy(ProductName, ProductNameaddr, 256); |
||
167 | |||
168 | ProductRevaddr = (LIN_ADDR)((VbeInfo.OemProductRevSegment<<4) + VbeInfo.OemProductRevOffset); |
||
169 | memcpy(ProductRev, ProductRevaddr, 256); |
||
170 | |||
171 | cprintf ("\n"); |
||
172 | |||
173 | cprintf ("Software ................. %s\n", Name); |
||
174 | |||
175 | if (VendorNameaddr == 0) cprintf ("Vendor Name .............. n/a\n"); |
||
176 | else cprintf ("Vendor Name .............. %s\n", VendorName); |
||
177 | |||
178 | if (ProductNameaddr == 0) cprintf ("Product Name ............. n/a\n"); |
||
179 | else cprintf ("Product Name ............. %s\n", ProductName); |
||
180 | |||
181 | if (ProductRevaddr == 0) cprintf ("Product Revision ......... n/a\n"); |
||
182 | else cprintf ("Product Revision ......... %s\n", ProductRev); |
||
183 | |||
184 | cprintf ("--------------------------------------------------------\n"); |
||
185 | |||
186 | cprintf ("Driver Version............ %d.%d\n", VbeInfo.VbeVersion/100, |
||
187 | VbeInfo.VbeVersion%100); |
||
188 | |||
189 | cprintf ("Total Memory OnBoard...... %d Kb\n", VbeInfo.TotalMemory<<6); |
||
190 | |||
191 | cprintf ("Capabilities:\n"); |
||
192 | |||
193 | (VbeInfo.Capabilities[0]&1) ? cprintf (" - DAC is fixed width, with 6 bits per primary color\n") |
||
194 | : cprintf (" - DAC width is switchable to 8 bits per primary color\n"); |
||
195 | (VbeInfo.Capabilities[0]&2) ? cprintf (" - Controller is VGA compatible\n") |
||
196 | : cprintf (" - Controller is not VGA compatible\n"); |
||
197 | (VbeInfo.Capabilities[0]&3) ? cprintf (" - Normal RAMDAC operation\n") |
||
198 | : cprintf (" - RAMDAC recommends programming during blank period only\n"); |
||
199 | } |
||
200 | |||
201 | void vbe_showmodes(void) |
||
202 | { |
||
203 | short int modec; |
||
204 | WORD list; |
||
205 | LIN_ADDR VideoModeaddr; |
||
206 | |||
207 | list=0; |
||
208 | VideoModeaddr = (LIN_ADDR)((VbeInfo.SupportedModesSegment<<4) + VbeInfo.SupportedModesOffset); |
||
209 | |||
210 | cprintf ("\nList of modes supported:\n"); |
||
211 | do { |
||
212 | /*modec = (unsigned char) DOSPeek(VideoModePtr);*/ |
||
213 | memcpy(&modec, VideoModeaddr, 2); |
||
214 | VideoModeaddr += 2; |
||
215 | if (modec != -1) cprintf (" %s ", VideoModeNames[modec - 0x100]); |
||
216 | /* cprintf("%x/%d ", modec, (modec & 0xFF));*/ |
||
217 | list++; |
||
218 | if (list % 2 == 0) cprintf ("\n"); |
||
219 | } while ((modec != -1) && (list < 40)); |
||
220 | |||
221 | cprintf ("\nToal modes supported: %d", list); |
||
222 | } |
||
223 | |||
224 | DWORD vbe_getmodeinfo(ModeInfoBlock *ModeInfo, WORD Vbe_Mode) |
||
225 | { |
||
226 | BYTE p1,p2; |
||
227 | X_REGS16 inregs, outregs; |
||
228 | X_SREGS16 sregs; |
||
229 | LIN_ADDR dosaddr; |
||
230 | |||
231 | if ((dosaddr = DOS_alloc(sizeof(ModeInfoBlock))) == 0) { |
||
232 | /* set_text_mode ();*/ |
||
233 | return(-1); |
||
234 | } |
||
235 | /* linearaddr = far2linear(DOSaddr); */ |
||
236 | |||
237 | /* 0x01 = Get Vbe Mode Info */ |
||
238 | inregs.x.ax = 0x4f01; |
||
239 | inregs.x.cx = Vbe_Mode; |
||
240 | |||
241 | inregs.x.di = (DWORD)dosaddr & 0x000F; |
||
242 | sregs.es = (((DWORD)dosaddr & 0xFFFF0) >> 4); |
||
243 | sregs.ds = (((DWORD)dosaddr & 0xFFFF0) >> 4); |
||
244 | |||
245 | p1 = inp(0x21); |
||
246 | p2 = inp(0xA1); |
||
247 | outp(0x21,0xFF); |
||
248 | outp(0xA1,0xFF); |
||
249 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
250 | outp(0x21,p1); |
||
251 | outp(0xA1,p2); |
||
252 | if (vbe_check_status (outregs.x.ax) < 0) { |
||
253 | return -1; |
||
254 | } |
||
255 | |||
256 | memcpy(ModeInfo, dosaddr, sizeof(ModeInfoBlock)); |
||
257 | |||
258 | vbe_screen = ModeInfo->PhysBasePtr; |
||
259 | if(vbe_screen == -1) { |
||
260 | return -1; |
||
261 | } |
||
262 | return vbe_screen; |
||
263 | } |
||
264 | |||
265 | DWORD vbe_getflb(void) |
||
266 | { |
||
267 | return vbe_screen; |
||
268 | } |
||
269 | |||
270 | int vbe_setmode (WORD Vbe_Mode) |
||
271 | { |
||
272 | BYTE p1,p2; |
||
273 | X_REGS16 inregs, outregs; |
||
274 | X_SREGS16 sregs; |
||
275 | |||
276 | /* Se volessimo il Linear Frame Buffer, dovremmo fare |
||
277 | Vbe_Mode = Vbe_Mode | 0x4000; |
||
278 | */ |
||
279 | memset (&inregs, 0, sizeof(inregs)); |
||
280 | /* Set Vesa Vbe mode */ |
||
281 | inregs.x.ax = 0x4f02; |
||
282 | inregs.x.bx = Vbe_Mode; |
||
283 | p1 = inp(0x21); |
||
284 | p2 = inp(0xA1); |
||
285 | outp(0x21,0xFF); |
||
286 | outp(0xA1,0xFF); |
||
287 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
288 | outp(0x21,p1); |
||
289 | outp(0xA1,p2); |
||
290 | |||
291 | return vbe_check_status (outregs.x.ax); |
||
292 | } |
||
293 | |||
294 | WORD vbe_getbpr(ModeInfoBlock *ModeInfo) |
||
295 | { |
||
296 | return ModeInfo->BytesPerScanLine; |
||
297 | } |
||
298 | |||
299 | int vbe_setbank(ModeInfoBlock *ModeInfo, BYTE bank) |
||
300 | { |
||
301 | BYTE p1,p2; |
||
302 | X_REGS16 inregs, outregs; |
||
303 | X_SREGS16 sregs; |
||
304 | |||
305 | memset (&inregs, 0, sizeof(inregs)); |
||
306 | memset (&sregs, 0, sizeof(sregs)); |
||
307 | /* Set Window */ |
||
308 | inregs.x.ax = 0x4f05; |
||
309 | inregs.h.bh = 0x00; |
||
310 | inregs.h.bl = 0x00; |
||
311 | inregs.x.dx = (64 / ModeInfo->WinGranularity) * bank; |
||
312 | p1 = inp(0x21); |
||
313 | p2 = inp(0xA1); |
||
314 | outp(0x21,0xFF); |
||
315 | outp(0xA1,0xFF); |
||
316 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
317 | outp(0x21,p1); |
||
318 | outp(0xA1,p2); |
||
319 | return vbe_check_status (outregs.x.ax); |
||
320 | } |
||
321 | |||
322 | void vbe_showmodeinfo (ModeInfoBlock *ModeInfo) |
||
323 | { |
||
324 | cprintf ("\n Mode: %dx%dx%d (%d bits)", ModeInfo->XResolution, |
||
325 | ModeInfo->YResolution, |
||
326 | ModeInfo->BitsPerPixel<<5, |
||
327 | ModeInfo->BitsPerPixel); |
||
328 | |||
329 | (ModeInfo->ModeAttributes&1)? cprintf ("\n - Mode SUPPORTED in hardware configuration") |
||
330 | : cprintf ("\n - Mode NOT supported in hardware configuration"); |
||
331 | (ModeInfo->ModeAttributes&5)? cprintf ("\n - Color Mode") |
||
332 | : cprintf ("\n - Text Mode"); |
||
333 | (ModeInfo->ModeAttributes&6)? cprintf ("\n - Not VGA compatible") |
||
334 | : cprintf ("\n - VGA compatible"); |
||
335 | (ModeInfo->ModeAttributes&7)? cprintf ("\n - Windowed memory mode available") |
||
336 | : cprintf ("\n - Windowed memory NOT mode available"); |
||
337 | (ModeInfo->ModeAttributes&8)? cprintf ("\n - Linear Frame Buffer available :-)") |
||
338 | : cprintf ("\n - Linear Frame Buffer NOT available :-("); |
||
339 | |||
340 | cprintf ("\n\n Bytes Per ScanLine %d", ModeInfo->BytesPerScanLine); |
||
341 | |||
342 | cprintf ("\n\n Window A Attributes:"); |
||
343 | (ModeInfo->WinAAttributes&1)? cprintf ("\n - Window is relocatable") |
||
344 | : cprintf ("\n - Window is not relocatable"); |
||
345 | (ModeInfo->WinAAttributes&2)? cprintf ("\n - Window is readable") |
||
346 | : cprintf ("\n - Window is not readable"); |
||
347 | (ModeInfo->WinAAttributes&3)? cprintf ("\n - Window is writeable") |
||
348 | : cprintf ("\n - Window is not writeable"); |
||
349 | |||
350 | /* Tolgo x leggere... |
||
351 | cprintf ("\n\n Window B Attributes:"); |
||
352 | (ModeInfo->WinBAttributes&1)? cprintf ("\n - Window is relocatable") |
||
353 | : cprintf ("\n - Window is not relocatable"); |
||
354 | (ModeInfo->WinBAttributes&2)? cprintf ("\n - Window is readable") |
||
355 | : cprintf ("\n - Window is not readable"); |
||
356 | (ModeInfo->WinBAttributes&3)? cprintf ("\n - Window is writeable") |
||
357 | : cprintf ("\n - Window is not writeable"); |
||
358 | */ |
||
359 | cprintf ("\n\n Window granularity %u Kb", ModeInfo->WinGranularity); |
||
360 | cprintf ("\n Window size %u Kb", ModeInfo->WinSize); |
||
361 | cprintf ("\n Segment: %x", ModeInfo->WinBSegment); |
||
362 | cprintf ("\n\n Memory Model is "); |
||
363 | switch (ModeInfo->MemoryModel) |
||
364 | { |
||
365 | case 0x00: cprintf ("Text Mode"); break; |
||
366 | case 0x01: cprintf ("CGA Graphics"); break; |
||
367 | case 0x02: cprintf ("Hercules Graphics"); break; |
||
368 | case 0x03: cprintf ("Planar"); break; |
||
369 | case 0x04: cprintf ("Packed Pixel"); break; |
||
370 | case 0x05: cprintf ("Non-chain 4, 256 color"); break; |
||
371 | case 0x06: cprintf ("Direct Color"); break; |
||
372 | case 0x07: cprintf ("YUV Color"); break; |
||
373 | default: cprintf ("to be defined by OEM"); |
||
374 | } |
||
375 | |||
376 | cprintf ("\n Number of Banks %u", ModeInfo->NumberOfBanks); |
||
377 | cprintf ("\n Bank Size %u Kb\n", ModeInfo->BankSize); |
||
378 | |||
379 | /* cprintf ("\n Red Mask Size %d (%d)", ModeInfo->RedMaskSize, ModeInfo->RedFieldPosition); |
||
380 | cprintf ("\n Green Mask Size %d (%d)", ModeInfo->GreenMaskSize, ModeInfo->GreenFieldPosition); |
||
381 | cprintf ("\n Blue Mask Size %d (%d)", ModeInfo->BlueMaskSize, ModeInfo->BlueFieldPosition); |
||
382 | |||
383 | cprintf ("\n\nColor Mode Info:"); |
||
384 | (ModeInfo->DirectColorModeInfo&1)? cprintf ("\n - Color ramp is programmable") |
||
385 | : cprintf ("\n - Color ramp is fixed"); |
||
386 | (ModeInfo->DirectColorModeInfo&2)? cprintf ("\n - Bits in Rsvd are usable") |
||
387 | : cprintf ("\n - Bits in Rsvd are reserved");*/ |
||
388 | } |
||
389 | |||
390 | int vbe_checkmode(WORD mode) |
||
391 | { |
||
392 | LIN_ADDR VideoModeaddr; |
||
393 | short int modec; |
||
394 | BYTE done; |
||
395 | |||
396 | done = 0; |
||
397 | VideoModeaddr = (LIN_ADDR)((VbeInfo.SupportedModesSegment<<4) + VbeInfo.SupportedModesOffset); |
||
398 | do { |
||
399 | memcpy(&modec, VideoModeaddr, 2); |
||
400 | VideoModeaddr += 2; |
||
401 | if ((modec != -1) && (modec == mode)) { |
||
402 | done = 1; |
||
403 | } |
||
404 | } while ((modec != -1) && (!done)); |
||
405 | if (done == 1) return 1; |
||
406 | return -1; |
||
407 | } |
||
408 | |||
409 | DWORD vbe_getmem(void) |
||
410 | { |
||
411 | return (VbeInfo.TotalMemory<<6) * 1024; |
||
412 | } |