Subversion Repositories shark

Rev

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