1138321fabb993e4542cf62251ade1ec3d0d45c1
[reactos.git] / boot / freeldr / freeldr / arch / i386 / i386vid.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <freeldr.h>
21
22 #include <debug.h>
23
24 DBG_DEFAULT_CHANNEL(HWDETECT);
25
26 #include <pshpack2.h>
27 typedef struct
28 {
29 UCHAR Signature[4]; // (ret) signature ("VESA")
30 // (call) VESA 2.0 request signature ("VBE2"), required to receive
31 // version 2.0 info
32 USHORT VesaVersion; // VESA version number (one-digit minor version -- 0102h = v1.2)
33 ULONG OemNamePtr; // pointer to OEM name
34 // "761295520" for ATI
35 ULONG Capabilities; // capabilities flags (see #00078)
36 ULONG SupportedModeListPtr; // pointer to list of supported VESA and OEM video modes
37 // (list of words terminated with FFFFh)
38 USHORT TotalVideoMemory; // total amount of video memory in 64K blocks
39
40 // ---VBE v1.x ---
41 //UCHAR Reserved[236];
42
43 // ---VBE v2.0 ---
44 USHORT OemSoftwareVersion; // OEM software version (BCD, high byte = major, low byte = minor)
45 ULONG VendorNamePtr; // pointer to vendor name
46 ULONG ProductNamePtr; // pointer to product name
47 ULONG ProductRevisionStringPtr; // pointer to product revision string
48 USHORT VBE_AF_Version; // (if capabilities bit 3 set) VBE/AF version (BCD)
49 // 0100h for v1.0P
50 ULONG AcceleratedModeListPtr; // (if capabilities bit 3 set) pointer to list of supported
51 // accelerated video modes (list of words terminated with FFFFh)
52 UCHAR Reserved[216]; // reserved for VBE implementation
53 UCHAR ScratchPad[256]; // OEM scratchpad (for OEM strings, etc.)
54 } VESA_SVGA_INFO, *PVESA_SVGA_INFO;
55 #include <poppack.h>
56
57 // Bitfields for VESA capabilities:
58 //
59 // Bit(s) Description (Table 00078)
60 // 0 DAC can be switched into 8-bit mode
61 // 1 non-VGA controller
62 // 2 programmed DAC with blank bit (i.e. only during blanking interval)
63 // 3 (VBE v3.0) controller supports hardware stereoscopic signalling
64 // 3 controller supports VBE/AF v1.0P extensions
65 // 4 (VBE v3.0) if bit 3 set:
66 // =0 stereo signalling via external VESA stereo connector
67 // =1 stereo signalling via VESA EVC connector
68 // 4 (VBE/AF v1.0P) must call EnableDirectAccess to access framebuffer
69 // 5 (VBE/AF v1.0P) controller supports hardware mouse cursor
70 // 6 (VBE/AF v1.0P) controller supports hardware clipping
71 // 7 (VBE/AF v1.0P) controller supports transparent BitBLT
72 // 8-31 reserved (0)
73
74 // Notes: The list of supported video modes is stored in the reserved
75 // portion of the SuperVGA information record by some implementations,
76 // and it may thus be necessary to either copy the mode list or use a
77 // different buffer for all subsequent VESA calls. Not all of the video
78 // modes in the list of mode numbers may be supported, e.g. if they require
79 // more memory than currently installed or are not supported by the
80 // attached monitor. Check any mode you intend to use through AX=4F01h first..
81 // The 1.1 VESA document specifies 242 reserved bytes at the end, so the
82 // buffer should be 262 bytes to ensure that it is not overrun; for v2.0,
83 // the buffer should be 512 bytes. The S3 specific video modes will most
84 // likely follow the FFFFh terminator at the end of the standard modes.
85 // A search must then be made to find them, FFFFh will also terminate this
86 // second list. In some cases, only a "stub" VBE may be present, supporting
87 // only AX=4F00h; this case may be assumed if the list of supported video modes
88 // is empty (consisting of a single word of FFFFh)
89 #if 0
90 static VOID BiosSetVideoFont8x16(VOID)
91 {
92 REGS Regs;
93
94 // Int 10h AX=1114h
95 // VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x16 CHARACTER SET (VGA)
96 //
97 // AX = 1114h
98 // BL = block to load
99 // Return:
100 // Nothing
101 Regs.w.ax = 0x1114;
102 Regs.b.bl = 0;
103 Int386(0x10, &Regs, &Regs);
104 }
105
106 static VOID VideoSetTextCursorPosition(ULONG X, ULONG Y)
107 {
108 }
109
110 static ULONG VideoGetTextCursorPositionX(VOID)
111 {
112 REGS Regs;
113
114 // Int 10h AH=03h
115 // VIDEO - GET CURSOR POSITION AND SIZE
116 //
117 // AH = 03h
118 // BH = page number
119 // 0-3 in modes 2&3
120 // 0-7 in modes 0&1
121 // 0 in graphics modes
122 // Return:
123 // AX = 0000h (Phoenix BIOS)
124 // CH = start scan line
125 // CL = end scan line
126 // DH = row (00h is top)
127 // DL = column (00h is left)
128 Regs.b.ah = 0x03;
129 Regs.b.bh = 0x00;
130 Int386(0x10, &Regs, &Regs);
131
132 return Regs.b.dl;
133 }
134
135 static ULONG VideoGetTextCursorPositionY(VOID)
136 {
137 REGS Regs;
138
139 // Int 10h AH=03h
140 // VIDEO - GET CURSOR POSITION AND SIZE
141 //
142 // AH = 03h
143 // BH = page number
144 // 0-3 in modes 2&3
145 // 0-7 in modes 0&1
146 // 0 in graphics modes
147 // Return:
148 // AX = 0000h (Phoenix BIOS)
149 // CH = start scan line
150 // CL = end scan line
151 // DH = row (00h is top)
152 // DL = column (00h is left)
153 Regs.b.ah = 0x03;
154 Regs.b.bh = 0x00;
155 Int386(0x10, &Regs, &Regs);
156
157 return Regs.b.dh;
158 }
159 #endif
160
161 USHORT BiosIsVesaSupported(VOID)
162 {
163 REGS Regs;
164 PVESA_SVGA_INFO SvgaInfo = (PVESA_SVGA_INFO)BIOSCALLBUFFER;
165 //USHORT* VideoModes;
166 //USHORT Index;
167
168 TRACE("BiosIsVesaSupported()\n");
169
170 RtlZeroMemory(SvgaInfo, sizeof(VESA_SVGA_INFO));
171
172 // Make sure we receive version 2.0 info
173 SvgaInfo->Signature[0] = 'V';
174 SvgaInfo->Signature[1] = 'B';
175 SvgaInfo->Signature[2] = 'E';
176 SvgaInfo->Signature[3] = '2';
177
178 // Int 10h AX=4F00h
179 // VESA SuperVGA BIOS (VBE) - GET SuperVGA INFORMATION
180 //
181 // AX = 4F00h
182 // ES:DI -> buffer for SuperVGA information (see #00077)
183 // Return:
184 // AL = 4Fh if function supported
185 // AH = status
186 // 00h successful
187 // ES:DI buffer filled
188 // 01h failed
189 // ---VBE v2.0---
190 // 02h function not supported by current hardware configuration
191 // 03h function invalid in current video mode
192 //
193 // Determine whether VESA BIOS extensions are present and the
194 // capabilities supported by the display adapter
195 //
196 // Installation check;VESA SuperVGA
197 Regs.w.ax = 0x4F00;
198 Regs.w.es = BIOSCALLBUFSEGMENT;
199 Regs.w.di = BIOSCALLBUFOFFSET;
200 Int386(0x10, &Regs, &Regs);
201
202 TRACE("AL = 0x%x\n", Regs.b.al);
203 TRACE("AH = 0x%x\n", Regs.b.ah);
204
205 if (Regs.w.ax != 0x004F)
206 {
207 WARN("VBE Get SuperVGA information function not supported (AL=0x%x) or failed (AH=0x%x)\n",
208 Regs.b.al, Regs.b.ah);
209 return 0x0000;
210 }
211
212 TRACE("Supported.\n");
213 TRACE("SvgaInfo->Signature[4] = %c%c%c%c\n", SvgaInfo->Signature[0], SvgaInfo->Signature[1], SvgaInfo->Signature[2], SvgaInfo->Signature[3]);
214 TRACE("SvgaInfo->VesaVersion = v%d.%d\n", ((SvgaInfo->VesaVersion >> 8) & 0xFF), (SvgaInfo->VesaVersion & 0xFF));
215 TRACE("SvgaInfo->OemNamePtr = 0x%x\n", SvgaInfo->OemNamePtr);
216 TRACE("SvgaInfo->Capabilities = 0x%x\n", SvgaInfo->Capabilities);
217 TRACE("SvgaInfo->VideoMemory = %dK\n", SvgaInfo->TotalVideoMemory * 64);
218 TRACE("---VBE v2.0 ---\n");
219 TRACE("SvgaInfo->OemSoftwareVersion = v%d.%d\n", ((SvgaInfo->OemSoftwareVersion >> 8) & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 12) & 0x0F) * 10), (SvgaInfo->OemSoftwareVersion & 0x0F) + (((SvgaInfo->OemSoftwareVersion >> 4) & 0x0F) * 10));
220 TRACE("SvgaInfo->VendorNamePtr = 0x%x\n", SvgaInfo->VendorNamePtr);
221 TRACE("SvgaInfo->ProductNamePtr = 0x%x\n", SvgaInfo->ProductNamePtr);
222 TRACE("SvgaInfo->ProductRevisionStringPtr = 0x%x\n", SvgaInfo->ProductRevisionStringPtr);
223 TRACE("SvgaInfo->VBE/AF Version = 0x%x (BCD WORD)\n", SvgaInfo->VBE_AF_Version);
224
225 if (SvgaInfo->Signature[0] != 'V' ||
226 SvgaInfo->Signature[1] != 'E' ||
227 SvgaInfo->Signature[2] != 'S' ||
228 SvgaInfo->Signature[3] != 'A')
229 {
230 ERR("Bad signature in VESA information (%c%c%c%c)\n",
231 SvgaInfo->Signature[0],
232 SvgaInfo->Signature[1],
233 SvgaInfo->Signature[2],
234 SvgaInfo->Signature[3]);
235 return 0x0000;
236 }
237
238 return SvgaInfo->VesaVersion;
239 }
240
241
242 BOOLEAN
243 BiosIsVesaDdcSupported(VOID)
244 {
245 REGS Regs;
246
247 TRACE("BiosIsVesaDdcSupported()\n");
248
249 Regs.w.ax = 0x4F15;
250 Regs.b.bl = 0;
251 Regs.w.cx = 0;
252 Regs.w.es = 0;
253 Regs.w.di = 0;
254 Int386(0x10, &Regs, &Regs);
255
256 TRACE("AL = 0x%x\n", Regs.b.al);
257 TRACE("AH = 0x%x\n", Regs.b.ah);
258
259 TRACE("BL = 0x%x\n", Regs.b.bl);
260
261 if (Regs.w.ax != 0x004F)
262 {
263 WARN("VBE/DDC Installation check function not supported (AL=0x%x) or failed (AH=0x%x)\n",
264 Regs.b.al, Regs.b.ah);
265 return FALSE;
266 }
267
268 return (Regs.b.ah == 0);
269 }
270
271
272 BOOLEAN
273 BiosVesaReadEdid(VOID)
274 {
275 REGS Regs;
276
277 TRACE("BiosVesaReadEdid()\n");
278
279 RtlZeroMemory((PVOID)BIOSCALLBUFFER, 128);
280
281 Regs.w.ax = 0x4F15;
282 Regs.b.bl = 1;
283 Regs.w.cx = 0;
284 Regs.w.dx = 0;
285 Regs.w.es = BIOSCALLBUFSEGMENT;
286 Regs.w.di = BIOSCALLBUFOFFSET;
287 Int386(0x10, &Regs, &Regs);
288
289 TRACE("AL = 0x%x\n", Regs.b.al);
290 TRACE("AH = 0x%x\n", Regs.b.ah);
291
292 if (Regs.w.ax != 0x004F)
293 {
294 WARN("VBE/DDC Read EDID function not supported (AL=0x%x) or failed (AH=0x%x)\n",
295 Regs.b.al, Regs.b.ah);
296 return FALSE;
297 }
298
299 return (Regs.b.ah == 0);
300 }
301
302 /* EOF */