Subversion Repositories shark

Rev

Rev 1063 | Details | Compare with Previous | Last modification | View Log | RSS feed

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