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