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