Subversion Repositories shark

Rev

Rev 478 | Rev 1022 | Go to most recent revision | Details | Compare with Previous | 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
 
479 giacomo 49
#define NMODES 13
50
static struct gmode allmodes[NMODES] = {
51
        {640, 400, 640, 8, 0x4100},
52
        {640, 480, 640, 8, 0x4101},
53
        {800, 600, 800, 8, 0x4103},
54
        {1024, 768, 1024, 8, 0x4105},
55
        {640, 480, 1280, 15, 0x4110},
56
        {800, 600, 1600, 15, 0x4113},
57
        {1024, 768, 2048, 15, 0x4116},
58
        {640, 480, 1280, 16, 0x4111},
59
        {800, 600, 1600, 16, 0x4114},
60
        {1024, 768, 2048, 16, 0x4117},
61
        {640, 480, 1920, 24, 0x4112},
62
        {800, 600, 2400, 24, 0x4115},
63
        {1024, 768, 3072, 24, 0x4118}
64
};
65
 
477 giacomo 66
int vbe_check_status (WORD vbe_function_result)
67
{
68
    if (vbe_function_result != 0x004f) {
69
        switch (vbe_function_result) {
70
            case 0x014f : return -1;    /* VBE Generic error */
71
            case 0x024f : return -2;    /* Hardware incompatibility error */
72
            case 0x034f : return -3;    /* Unvalid function requested */
73
            default     : return -4;    /* Unknown error */
74
        }
75
    }
76
    return 1;
77
}
78
 
479 giacomo 79
int vbe_modenum(WORD x, WORD y, BYTE depth)
80
{
81
        int  mode, i;
82
 
83
        mode = -1;
84
 
85
        for (i = 0; i < NMODES; i++) {
86
          if ((depth == allmodes[i].bpp) && (x == allmodes[i].xdim) && (y == allmodes[i].ydim)) {
87
                mode = allmodes[i].modenum;
88
          }
89
        }
90
 
91
        return mode;
92
}
93
 
478 giacomo 94
void vbe_restore_vga(void) {
95
 
96
  X_REGS16 inregs, outregs;
97
  X_SREGS16 sregs;
98
 
99
#ifndef VM86
100
  BYTE p1,p2;
101
#endif
102
 
103
  inregs.x.ax = 0x03;
104
#ifndef VM86
105
  p1 = inp(0x21);
106
  p2 = inp(0xA1);
107
  outp(0x21,0xFF);
108
  outp(0xA1,0xFF);
109
  X_callBIOS(0x10, &inregs, &outregs, &sregs);
110
  outp(0x21,p1);
111
  outp(0xA1,p2);
112
#else
113
  vm86_callBIOS(0x10, &inregs, &outregs, &sregs);
114
#endif
115
 
116
}
117
 
477 giacomo 118
int vbe_getinfo(void)
119
{
120
    X_REGS16  inregs, outregs;              /* registri normali */
121
    X_SREGS16 sregs;             /* registri estesi */
122
    LIN_ADDR DOSaddr;
123
    DWORD linearaddr;
124
#ifndef VM86
125
    BYTE p1, p2;
126
#endif
127
 
128
    /* Allochiamo mem per il nostro blocco */
129
    if ((DOSaddr = DOS_alloc(sizeof(VbeInfoBlock))) == 0) {
130
        /*    set_text_mode ();*/
131
        return -1;
132
    } else {
133
/*      linearaddr = appl2linear(DOSaddr);*/
134
        linearaddr = (DWORD) DOSaddr;
135
 
136
        /* 0x00 = Get Vbe2.0 Info */
137
        inregs.x.ax = 0x4f00;
138
        /* Indirizzo reale del nostro blocco */
139
        inregs.x.di = linearaddr & 0x000F;
140
        sregs.es = ((linearaddr & 0xFFFF0) >> 4);
141
        sregs.ds = ((linearaddr & 0xFFFF0) >> 4);
142
 
143
        /* Settiamo il VbeSignature correttamente */
144
        VbeInfo.VbeSignature[0] = 'V';
145
        VbeInfo.VbeSignature[1] = 'B';
146
        VbeInfo.VbeSignature[2] = 'E';
147
        VbeInfo.VbeSignature[3] = '2';
148
 
149
        memcpy((void *)linearaddr, &VbeInfo, sizeof(VbeInfo));
150
#ifndef VM86
151
        p1 = inp(0x21);
152
        p2 = inp(0xA1);
153
        outp(0x21,0xFF);
154
        outp(0xA1,0xFF);
155
        X_callBIOS(0x10, &inregs, &outregs, &sregs);
156
        outp(0x21,p1);
157
        outp(0xA1,p2);
158
#else
159
        vm86_callBIOS(0x10, &inregs, &outregs, &sregs);
160
#endif
161
        if (vbe_check_status(outregs.x.ax) < 0)
162
            return -1;
163
        memcpy(&VbeInfo, (void *)linearaddr, sizeof(VbeInfo));
164
        return 0;
165
    }
166
}
167
 
168
void vbe_showmodes(void)
169
{
170
    short int modec;
171
    WORD list;
172
    LIN_ADDR VideoModeaddr;
173
 
174
    list=0;
175
    VideoModeaddr = (LIN_ADDR)((VbeInfo.SupportedModesSegment<<4) + VbeInfo.SupportedModesOffset);
176
 
177
    cprintf ("\nList of modes supported:\n");
178
    do {
179
        memcpy(&modec, VideoModeaddr, 2);
180
        VideoModeaddr += 2;
181
        if (modec != -1) cprintf ("    %s   ", VideoModeNames[modec - 0x100]);
182
        list++;
183
        if (list % 2 == 0) cprintf ("\n");
184
    } while ((modec != -1) && (list < 40));
185
 
186
    cprintf ("\nToal modes supported: %d", list);
187
}
188
 
189
DWORD vbe_getmodeinfo(ModeInfoBlock *ModeInfo, WORD Vbe_Mode)
190
{
191
    X_REGS16  inregs, outregs;
192
    X_SREGS16 sregs;
193
    LIN_ADDR dosaddr;
194
#ifndef VM86
195
    BYTE p1, p2;
196
#endif
197
 
198
    if ((dosaddr = DOS_alloc(sizeof(ModeInfoBlock))) == 0) {
199
        return(-1);
200
    }
201
 
202
    /* 0x01 = Get Vbe Mode Info */
203
    inregs.x.ax = 0x4f01;
204
    inregs.x.cx  = Vbe_Mode;
205
 
206
    inregs.x.di = (DWORD)dosaddr & 0x000F;
207
    sregs.es = (((DWORD)dosaddr & 0xFFFF0) >> 4);
208
    sregs.ds = (((DWORD)dosaddr & 0xFFFF0) >> 4);
209
 
210
#ifndef VM86
211
        p1 = inp(0x21);
212
        p2 = inp(0xA1);
213
        outp(0x21,0xFF);
214
        outp(0xA1,0xFF);
215
        X_callBIOS(0x10, &inregs, &outregs, &sregs);
216
        outp(0x21,p1);
217
        outp(0xA1,p2);
218
#else
219
        vm86_callBIOS(0x10, &inregs, &outregs, &sregs);
220
#endif
221
    if (vbe_check_status (outregs.x.ax) < 0) {
222
        return -1;
223
    }
224
 
225
    memcpy(ModeInfo, dosaddr, sizeof(ModeInfoBlock));
226
 
227
    vbe_screen = ModeInfo->PhysBasePtr;
228
    if(vbe_screen == -1) {
229
        return -1;
230
    }
231
    return vbe_screen;
232
}
233
 
234
DWORD vbe_getflb(void)
235
{
236
    return vbe_screen;
237
}
238
 
239
int vbe_setmode (WORD Vbe_Mode)
240
{
241
    X_REGS16 inregs, outregs;
242
    X_SREGS16 sregs;
243
#ifndef VM86
244
    BYTE p1, p2;
245
#endif
246
 
247
    memset (&inregs, 0, sizeof(inregs));
248
    /* Set Vesa Vbe mode */
249
    inregs.x.ax = 0x4f02;
250
    inregs.x.bx = Vbe_Mode;
251
#ifndef VM86
252
        p1 = inp(0x21);
253
        p2 = inp(0xA1);
254
        outp(0x21,0xFF);
255
        outp(0xA1,0xFF);
256
        X_callBIOS(0x10, &inregs, &outregs, &sregs);
257
        outp(0x21,p1);
258
        outp(0xA1,p2);
259
#else
260
        vm86_callBIOS(0x10, &inregs, &outregs, &sregs);
261
#endif
262
 
263
    return 1; //vbe_check_status (outregs.x.ax);
264
 
265
}
266
 
267
WORD vbe_getbpr(ModeInfoBlock *ModeInfo)
268
{
269
    return ModeInfo->BytesPerScanLine;
270
}
271
 
272
int vbe_setbank(ModeInfoBlock *ModeInfo, BYTE bank)
273
{
274
    X_REGS16 inregs, outregs;
275
    X_SREGS16 sregs;
276
#ifndef VM86
277
    BYTE p1, p2;
278
#endif
279
 
280
    memset (&inregs, 0, sizeof(inregs));
281
    memset (&sregs, 0, sizeof(sregs));
282
    /* Set Window */
283
    inregs.x.ax = 0x4f05;
284
    inregs.h.bh = 0x00;
285
    inregs.h.bl = 0x00;
286
    inregs.x.dx = (64 / ModeInfo->WinGranularity) * bank;
287
#ifndef VM86
288
        p1 = inp(0x21);
289
        p2 = inp(0xA1);
290
        outp(0x21,0xFF);
291
        outp(0xA1,0xFF);
292
        X_callBIOS(0x10, &inregs, &outregs, &sregs);
293
        outp(0x21,p1);
294
        outp(0xA1,p2);
295
#else
296
        vm86_callBIOS(0x10, &inregs, &outregs, &sregs);
297
#endif
298
    return vbe_check_status (outregs.x.ax);
299
}
300
 
301
DWORD vbe_getmem(void)
302
{
303
    return (VbeInfo.TotalMemory<<6) * 1024;
304
}