Rev 478 | Go to most recent revision | Details | 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 | |||
49 | int vbe_check_status (WORD vbe_function_result) |
||
50 | { |
||
51 | if (vbe_function_result != 0x004f) { |
||
52 | switch (vbe_function_result) { |
||
53 | case 0x014f : return -1; /* VBE Generic error */ |
||
54 | case 0x024f : return -2; /* Hardware incompatibility error */ |
||
55 | case 0x034f : return -3; /* Unvalid function requested */ |
||
56 | default : return -4; /* Unknown error */ |
||
57 | } |
||
58 | } |
||
59 | return 1; |
||
60 | } |
||
61 | |||
62 | int vbe_getinfo(void) |
||
63 | { |
||
64 | X_REGS16 inregs, outregs; /* registri normali */ |
||
65 | X_SREGS16 sregs; /* registri estesi */ |
||
66 | LIN_ADDR DOSaddr; |
||
67 | DWORD linearaddr; |
||
68 | #ifndef VM86 |
||
69 | BYTE p1, p2; |
||
70 | #endif |
||
71 | |||
72 | /* Allochiamo mem per il nostro blocco */ |
||
73 | if ((DOSaddr = DOS_alloc(sizeof(VbeInfoBlock))) == 0) { |
||
74 | /* set_text_mode ();*/ |
||
75 | return -1; |
||
76 | } else { |
||
77 | /* linearaddr = appl2linear(DOSaddr);*/ |
||
78 | linearaddr = (DWORD) DOSaddr; |
||
79 | |||
80 | /* 0x00 = Get Vbe2.0 Info */ |
||
81 | inregs.x.ax = 0x4f00; |
||
82 | /* Indirizzo reale del nostro blocco */ |
||
83 | inregs.x.di = linearaddr & 0x000F; |
||
84 | sregs.es = ((linearaddr & 0xFFFF0) >> 4); |
||
85 | sregs.ds = ((linearaddr & 0xFFFF0) >> 4); |
||
86 | |||
87 | /* Settiamo il VbeSignature correttamente */ |
||
88 | VbeInfo.VbeSignature[0] = 'V'; |
||
89 | VbeInfo.VbeSignature[1] = 'B'; |
||
90 | VbeInfo.VbeSignature[2] = 'E'; |
||
91 | VbeInfo.VbeSignature[3] = '2'; |
||
92 | |||
93 | memcpy((void *)linearaddr, &VbeInfo, sizeof(VbeInfo)); |
||
94 | #ifndef VM86 |
||
95 | p1 = inp(0x21); |
||
96 | p2 = inp(0xA1); |
||
97 | outp(0x21,0xFF); |
||
98 | outp(0xA1,0xFF); |
||
99 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
100 | outp(0x21,p1); |
||
101 | outp(0xA1,p2); |
||
102 | #else |
||
103 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
104 | #endif |
||
105 | if (vbe_check_status(outregs.x.ax) < 0) |
||
106 | return -1; |
||
107 | memcpy(&VbeInfo, (void *)linearaddr, sizeof(VbeInfo)); |
||
108 | return 0; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | void vbe_showmodes(void) |
||
113 | { |
||
114 | short int modec; |
||
115 | WORD list; |
||
116 | LIN_ADDR VideoModeaddr; |
||
117 | |||
118 | list=0; |
||
119 | VideoModeaddr = (LIN_ADDR)((VbeInfo.SupportedModesSegment<<4) + VbeInfo.SupportedModesOffset); |
||
120 | |||
121 | cprintf ("\nList of modes supported:\n"); |
||
122 | do { |
||
123 | memcpy(&modec, VideoModeaddr, 2); |
||
124 | VideoModeaddr += 2; |
||
125 | if (modec != -1) cprintf (" %s ", VideoModeNames[modec - 0x100]); |
||
126 | list++; |
||
127 | if (list % 2 == 0) cprintf ("\n"); |
||
128 | } while ((modec != -1) && (list < 40)); |
||
129 | |||
130 | cprintf ("\nToal modes supported: %d", list); |
||
131 | } |
||
132 | |||
133 | DWORD vbe_getmodeinfo(ModeInfoBlock *ModeInfo, WORD Vbe_Mode) |
||
134 | { |
||
135 | X_REGS16 inregs, outregs; |
||
136 | X_SREGS16 sregs; |
||
137 | LIN_ADDR dosaddr; |
||
138 | #ifndef VM86 |
||
139 | BYTE p1, p2; |
||
140 | #endif |
||
141 | |||
142 | if ((dosaddr = DOS_alloc(sizeof(ModeInfoBlock))) == 0) { |
||
143 | return(-1); |
||
144 | } |
||
145 | |||
146 | /* 0x01 = Get Vbe Mode Info */ |
||
147 | inregs.x.ax = 0x4f01; |
||
148 | inregs.x.cx = Vbe_Mode; |
||
149 | |||
150 | inregs.x.di = (DWORD)dosaddr & 0x000F; |
||
151 | sregs.es = (((DWORD)dosaddr & 0xFFFF0) >> 4); |
||
152 | sregs.ds = (((DWORD)dosaddr & 0xFFFF0) >> 4); |
||
153 | |||
154 | #ifndef VM86 |
||
155 | p1 = inp(0x21); |
||
156 | p2 = inp(0xA1); |
||
157 | outp(0x21,0xFF); |
||
158 | outp(0xA1,0xFF); |
||
159 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
160 | outp(0x21,p1); |
||
161 | outp(0xA1,p2); |
||
162 | #else |
||
163 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
164 | #endif |
||
165 | if (vbe_check_status (outregs.x.ax) < 0) { |
||
166 | return -1; |
||
167 | } |
||
168 | |||
169 | memcpy(ModeInfo, dosaddr, sizeof(ModeInfoBlock)); |
||
170 | |||
171 | vbe_screen = ModeInfo->PhysBasePtr; |
||
172 | if(vbe_screen == -1) { |
||
173 | return -1; |
||
174 | } |
||
175 | return vbe_screen; |
||
176 | } |
||
177 | |||
178 | DWORD vbe_getflb(void) |
||
179 | { |
||
180 | return vbe_screen; |
||
181 | } |
||
182 | |||
183 | int vbe_setmode (WORD Vbe_Mode) |
||
184 | { |
||
185 | X_REGS16 inregs, outregs; |
||
186 | X_SREGS16 sregs; |
||
187 | #ifndef VM86 |
||
188 | BYTE p1, p2; |
||
189 | #endif |
||
190 | |||
191 | memset (&inregs, 0, sizeof(inregs)); |
||
192 | /* Set Vesa Vbe mode */ |
||
193 | inregs.x.ax = 0x4f02; |
||
194 | inregs.x.bx = Vbe_Mode; |
||
195 | #ifndef VM86 |
||
196 | p1 = inp(0x21); |
||
197 | p2 = inp(0xA1); |
||
198 | outp(0x21,0xFF); |
||
199 | outp(0xA1,0xFF); |
||
200 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
201 | outp(0x21,p1); |
||
202 | outp(0xA1,p2); |
||
203 | #else |
||
204 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
205 | #endif |
||
206 | |||
207 | return 1; //vbe_check_status (outregs.x.ax); |
||
208 | |||
209 | } |
||
210 | |||
211 | WORD vbe_getbpr(ModeInfoBlock *ModeInfo) |
||
212 | { |
||
213 | return ModeInfo->BytesPerScanLine; |
||
214 | } |
||
215 | |||
216 | int vbe_setbank(ModeInfoBlock *ModeInfo, BYTE bank) |
||
217 | { |
||
218 | X_REGS16 inregs, outregs; |
||
219 | X_SREGS16 sregs; |
||
220 | #ifndef VM86 |
||
221 | BYTE p1, p2; |
||
222 | #endif |
||
223 | |||
224 | memset (&inregs, 0, sizeof(inregs)); |
||
225 | memset (&sregs, 0, sizeof(sregs)); |
||
226 | /* Set Window */ |
||
227 | inregs.x.ax = 0x4f05; |
||
228 | inregs.h.bh = 0x00; |
||
229 | inregs.h.bl = 0x00; |
||
230 | inregs.x.dx = (64 / ModeInfo->WinGranularity) * bank; |
||
231 | #ifndef VM86 |
||
232 | p1 = inp(0x21); |
||
233 | p2 = inp(0xA1); |
||
234 | outp(0x21,0xFF); |
||
235 | outp(0xA1,0xFF); |
||
236 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
237 | outp(0x21,p1); |
||
238 | outp(0xA1,p2); |
||
239 | #else |
||
240 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
241 | #endif |
||
242 | return vbe_check_status (outregs.x.ax); |
||
243 | } |
||
244 | |||
245 | DWORD vbe_getmem(void) |
||
246 | { |
||
247 | return (VbeInfo.TotalMemory<<6) * 1024; |
||
248 | } |