Rev 448 | Go to most recent revision | Details | Compare with Previous | 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/cons.h> |
||
4 | #include <ll/sys/ll/ll-func.h> |
||
5 | |||
635 | giacomo | 6 | #include "drivers/gd.h" |
2 | pj | 7 | |
8 | #include "drivers/s3.h" |
||
9 | #include "drivers/trident.h" |
||
10 | #include "drivers/vesa.h" |
||
11 | #include "drivers/chips.h" |
||
12 | |||
13 | BYTE bus, dev; |
||
14 | ModeInfoBlock vbemi; |
||
15 | BYTE actbank; |
||
16 | BYTE type; |
||
17 | |||
18 | DWORD flb=0; |
||
19 | int linear; |
||
20 | BYTE trylinear; |
||
21 | /*BYTE gmode = FALSE;*/ |
||
22 | |||
23 | #define NMODES 13 |
||
24 | static struct gmode allmodes[NMODES] = { |
||
25 | {640, 400, 640, 8, 0x100}, |
||
26 | {640, 480, 640, 8, 0x101}, |
||
27 | {800, 600, 800, 8, 0x103}, |
||
28 | {1024, 768, 1024, 8, 0x105}, |
||
29 | {640, 480, 1280, 15, 0x110}, |
||
30 | {800, 600, 1600, 15, 0x113}, |
||
31 | {1024, 768, 2048, 15, 0x116}, |
||
32 | {640, 480, 1280, 16, 0x111}, |
||
33 | {800, 600, 1600, 16, 0x114}, |
||
34 | {1024, 768, 2048, 16, 0x117}, |
||
35 | {640, 480, 1920, 24, 0x112}, |
||
36 | {800, 600, 2400, 24, 0x115}, |
||
37 | {1024, 768, 3072, 24, 0x118} |
||
38 | }; |
||
39 | static struct gmode actualmode; |
||
40 | |||
41 | |||
42 | static int myceil(float f) |
||
43 | { |
||
44 | int i = (int) f; |
||
45 | float f1 = f - i; |
||
46 | |||
47 | if (f1 != 0) { |
||
48 | return i + 1; |
||
49 | } else { |
||
50 | return i; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | /************************************************************************/ |
||
55 | /* GD Common Interface */ |
||
56 | /************************************************************************/ |
||
57 | int gd_init(WORD flags) |
||
58 | { |
||
59 | memset(&actualmode, 0, sizeof(struct gmode)); |
||
60 | type = UNKNOWN; |
||
61 | |||
62 | /* VESA driver needs the V86 Mode... */ |
||
444 | giacomo | 63 | vm86_init(); |
2 | pj | 64 | |
65 | /* First, check VESA... */ |
||
66 | if (vbe_getinfo() == 1) { |
||
67 | type = VESA; |
||
68 | if (flags & NOLINEAR) { |
||
69 | trylinear = 0; |
||
70 | } else { |
||
71 | trylinear = 1; |
||
72 | } |
||
444 | giacomo | 73 | return 1; |
2 | pj | 74 | } |
75 | |||
76 | /* Then, the other graph cards... Override VESA!!! */ |
||
77 | if (trident_test() == 1) { |
||
78 | type = TRIDENT; |
||
79 | trylinear = 0; |
||
80 | } |
||
81 | |||
82 | if (s3_test() == 1) { |
||
83 | type = S3; |
||
84 | if (flags & NOLINEAR) { |
||
85 | trylinear = 0; |
||
86 | } else { |
||
87 | trylinear = 1; |
||
88 | } |
||
89 | return 1; |
||
90 | } |
||
91 | |||
92 | if (type == UNKNOWN) { |
||
93 | return -1; |
||
94 | } |
||
444 | giacomo | 95 | |
2 | pj | 96 | return -2; |
97 | } |
||
98 | |||
99 | void gd_showmodeinfo(void) |
||
100 | { |
||
101 | cprintf("Mode number %x\n", actualmode.modenum); |
||
102 | cprintf("MaxX: %u\n", actualmode.xdim); |
||
103 | cprintf("MaxY: %u\n", actualmode.ydim); |
||
104 | cprintf("BPR: %u\n", actualmode.bpr); |
||
105 | } |
||
106 | |||
107 | void gd_showinfo(void) |
||
108 | { |
||
109 | DWORD addr; |
||
110 | |||
111 | addr = gd_getflb(); |
||
112 | |||
113 | if (addr != 0) { |
||
114 | cprintf ("\t gd: Frame Linear Buffer @ %lx (%luM)\n", |
||
115 | addr, (addr / 0x1000000)); |
||
116 | } |
||
117 | |||
118 | if (type == VESA) { |
||
119 | cprintf("Vesa SVGA card\n"); |
||
120 | vbe_showinfo(); |
||
121 | } |
||
122 | if (type == TRIDENT) { |
||
123 | cprintf("Trident graphic card\n"); |
||
124 | trident_showinfo(); |
||
125 | } |
||
126 | |||
127 | if (type == S3) { |
||
128 | cprintf("S3 graphic card\n"); |
||
129 | s3_showinfo(); |
||
130 | } |
||
131 | } |
||
132 | |||
133 | int gd_setmode(WORD mode) |
||
134 | { |
||
135 | WORD app; |
||
136 | int i; |
||
137 | #ifndef VM86 |
||
138 | BYTE p1, p2; |
||
139 | #endif |
||
140 | |||
141 | if (mode == 0) { |
||
142 | X_REGS16 inregs, outregs; |
||
143 | X_SREGS16 sregs; |
||
144 | |||
145 | if (actualmode.modenum != 0) { |
||
146 | inregs.x.ax = 0x03; |
||
147 | #ifndef VM86 |
||
148 | p1 = inp(0x21); |
||
149 | p2 = inp(0xA1); |
||
150 | outp(0x21,0xFF); |
||
151 | outp(0xA1,0xFF); |
||
152 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
153 | outp(0x21,p1); |
||
154 | outp(0xA1,p2); |
||
155 | #else |
||
156 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
157 | #endif |
||
158 | } |
||
159 | return 1; |
||
160 | } |
||
161 | |||
162 | for (i = 0; i < NMODES; i++) { |
||
163 | if ((mode == allmodes[i].modenum)) { |
||
164 | memcpy(&actualmode, &(allmodes[i]), sizeof(struct gmode)); |
||
165 | } |
||
166 | } |
||
167 | |||
168 | if (type == VESA) { |
||
444 | giacomo | 169 | |
2 | pj | 170 | if (vbe_getmodeinfo(&vbemi, mode) < 0) { |
444 | giacomo | 171 | return -1; |
172 | } |
||
2 | pj | 173 | |
174 | app = mode; |
||
175 | if (trylinear) { |
||
176 | /* try linear... */ |
||
177 | mode = mode | 0x4000; |
||
178 | linear = TRUE; |
||
179 | if (vbe_setmode(mode) == 1) { |
||
180 | return linear; |
||
181 | } |
||
182 | } |
||
183 | actbank = 0; |
||
184 | Load_Write_Bank_256(0); |
||
185 | linear = FALSE; |
||
186 | mode = app; |
||
187 | if (vbe_setmode(mode) < 0) { |
||
188 | return -1; |
||
189 | } |
||
190 | return linear; |
||
191 | } |
||
192 | |||
193 | if (type == S3) { |
||
194 | /* Still use VESA to open graph... */ |
||
195 | if (vbe_getmodeinfo(&vbemi, mode) < 0) { |
||
196 | return -1; |
||
197 | } |
||
198 | if (vbe_setmode(mode) < 0) { |
||
199 | return -1; |
||
200 | } |
||
201 | if ((flb != 0) && trylinear) { |
||
202 | linear = TRUE; |
||
203 | s3_linear(flb); |
||
204 | return TRUE; |
||
205 | } |
||
206 | linear = FALSE; |
||
207 | actbank = 0; |
||
208 | Load_Write_Bank_256(0); |
||
209 | return FALSE; |
||
210 | } |
||
211 | |||
212 | if (type == TRIDENT) { |
||
213 | /* Still use VESA to open graph... */ |
||
214 | if (vbe_getmodeinfo(&vbemi, mode) < 0) { |
||
215 | return -1; |
||
216 | } |
||
217 | if (vbe_setmode(mode) < 0) { |
||
218 | return -1; |
||
219 | } |
||
220 | |||
221 | actbank = 0; |
||
222 | Load_Write_Bank_256(0); |
||
223 | return FALSE; |
||
224 | } |
||
225 | |||
226 | return -2; |
||
227 | } |
||
228 | |||
229 | DWORD gd_getflb(void) |
||
230 | { |
||
231 | if (type == VESA) { |
||
232 | return vbe_getflb(); |
||
233 | } |
||
234 | if (type == S3) { |
||
235 | return flb; |
||
236 | } |
||
237 | return 0; |
||
238 | } |
||
239 | |||
240 | DWORD gd_getmem(void) |
||
241 | { |
||
242 | if (type == VESA) { |
||
243 | return vbe_getmem(); |
||
244 | } |
||
245 | if (type == S3) { |
||
246 | return s3_getmem(); |
||
247 | } |
||
248 | if (type == TRIDENT) { |
||
249 | return trident_getmem(); |
||
250 | } |
||
251 | |||
252 | return 0; |
||
253 | } |
||
254 | |||
255 | WORD gd_getbpr(void) |
||
256 | { |
||
257 | if (actualmode.bpr) return actualmode.bpr; |
||
258 | return -2; |
||
259 | } |
||
260 | |||
51 | pj | 261 | int gd_getmodeinfo(grx_vga_modeinfo *m) |
2 | pj | 262 | { |
263 | if (actualmode.modenum == 0) { |
||
264 | return -1; |
||
265 | } |
||
266 | |||
267 | m->width = actualmode.xdim; |
||
268 | m->height = actualmode.ydim; |
||
269 | m->bytesperpixel = (myceil((float)actualmode.bpp / 8)); |
||
270 | /* m->colors = myexp(2, actualmode.bpp); */ |
||
271 | m->colors = 1 << actualmode.bpp; |
||
272 | m->linewidth = gd_getbpr(); |
||
273 | m->maxlogicalwidth = gd_getbpr(); /* 4 the moment... */ |
||
274 | m->startaddressrange = 0; /* don't know :( */ |
||
275 | m->maxpixels = gd_getmem() / m->bytesperpixel; |
||
276 | m->haveblit = 0; |
||
277 | m->flags = 0; |
||
278 | |||
279 | /* Extended fields: */ |
||
280 | m->chiptype = type; /* Chiptype detected */ |
||
281 | m->memory = gd_getmem(); |
||
282 | m->linewidth_unit = 0; /* don't know :( */ |
||
283 | if (linear) { |
||
284 | m->linear_aperture = (LIN_ADDR)gd_getflb(); |
||
285 | m->aperture_size = gd_getmem(); |
||
286 | } else { |
||
287 | m->linear_aperture = 0; |
||
288 | m->aperture_size = 0xFFFF; |
||
289 | } |
||
290 | m->set_aperture_page = NULL; |
||
291 | m->extensions = NULL; |
||
292 | return 1; |
||
293 | } |
||
294 | |||
295 | void Load_Write_Bank_256(BYTE bank) |
||
296 | { |
||
297 | if (bank != actbank) { |
||
298 | actbank = bank; |
||
299 | if (type == VESA) { |
||
300 | if (vbe_setbank(&vbemi, bank) < 0) |
||
301 | ll_abort(259); |
||
302 | } |
||
303 | if (type == S3) { |
||
304 | s3_setpage(bank); |
||
305 | } |
||
306 | if (type == TRIDENT) { |
||
307 | trident_setpage(bank); |
||
308 | } |
||
309 | } |
||
310 | } |
||
311 | |||
312 | /************************************************************************/ |
||
313 | /* BANK HANDLING FUNCS */ |
||
314 | /************************************************************************/ |
||
315 | |||
316 | LIN_ADDR start_address(WORD bpr, WORD x, WORD y) |
||
317 | { |
||
318 | LIN_ADDR a; |
||
319 | |||
320 | a = (LIN_ADDR)(y * bpr +x); |
||
321 | return a; |
||
322 | } |
||
323 | |||
324 | void Seg_Off_256(WORD x, WORD y, WORD pitch, WORD *offs, WORD *seg) |
||
325 | { |
||
326 | DWORD a; |
||
327 | |||
328 | a = y * pitch + x; |
||
329 | *offs = a & 0x0000FFFF; |
||
330 | *seg = a >> 16; |
||
331 | } |
||
332 | |||
333 | void Seg_Off_Hi(WORD x, WORD y, WORD pitch, WORD *offs, WORD *seg) |
||
334 | { |
||
335 | DWORD a; |
||
336 | |||
337 | a = y * pitch + x * 2; |
||
338 | *offs = a & 0x0000FFFF; |
||
339 | *seg = a >> 16; |
||
340 | } |
||
341 | |||
342 | int gd_modenum(WORD x, WORD y, BYTE depth) |
||
343 | { |
||
344 | int mode, i; |
||
345 | |||
346 | mode = -1; |
||
347 | |||
348 | for (i = 0; i < NMODES; i++) { |
||
349 | if ((depth == allmodes[i].bpp) && (x == allmodes[i].xdim) && (y == allmodes[i].ydim)) { |
||
350 | mode = allmodes[i].modenum; |
||
351 | } else { |
||
352 | } |
||
353 | } |
||
354 | |||
355 | if ((mode != -1) && (vbe_checkmode(mode) != -1)) |
||
356 | return mode; |
||
357 | return -1; |
||
358 | } |