Subversion Repositories shark

Rev

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