bcb70d0ce1083c2cda2d917b556e1d0ad43454ee
[reactos.git] / boot / freeldr / freeldr / arch / i386 / xboxvideo.c
1 /*
2 * FreeLoader
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Note: much of this code was based on knowledge and/or code developed
19 * by the Xbox Linux group: http://www.xbox-linux.org
20 */
21
22 #include <freeldr.h>
23 #include <debug.h>
24
25 DBG_DEFAULT_CHANNEL(UI);
26
27 static PVOID FrameBuffer;
28 static ULONG ScreenWidth;
29 static ULONG ScreenHeight;
30 static ULONG BytesPerPixel;
31 static ULONG Delta;
32
33 #define CHAR_WIDTH 8
34 #define CHAR_HEIGHT 16
35
36 #define TOP_BOTTOM_LINES 0
37
38 #define FB_SIZE_MB 4
39
40 #define MAKE_COLOR(Red, Green, Blue) (0xff000000 | (((Red) & 0xff) << 16) | (((Green) & 0xff) << 8) | ((Blue) & 0xff))
41
42 BOOLEAN I2CTransmitByteGetReturn(UCHAR bPicAddressI2cFormat, UCHAR bDataToWrite, ULONG *Return);
43
44 static VOID
45 XboxVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
46 {
47 PUCHAR FontPtr;
48 PULONG Pixel;
49 UCHAR Mask;
50 unsigned Line;
51 unsigned Col;
52
53 FontPtr = XboxFont8x16 + Char * 16;
54 Pixel = (PULONG) ((char *) FrameBuffer + (Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta
55 + X * CHAR_WIDTH * BytesPerPixel);
56 for (Line = 0; Line < CHAR_HEIGHT; Line++)
57 {
58 Mask = 0x80;
59 for (Col = 0; Col < CHAR_WIDTH; Col++)
60 {
61 Pixel[Col] = (0 != (FontPtr[Line] & Mask) ? FgColor : BgColor);
62 Mask = Mask >> 1;
63 }
64 Pixel = (PULONG) ((char *) Pixel + Delta);
65 }
66 }
67
68 static ULONG
69 XboxVideoAttrToSingleColor(UCHAR Attr)
70 {
71 UCHAR Intensity;
72
73 Intensity = (0 == (Attr & 0x08) ? 127 : 255);
74
75 return 0xff000000 |
76 (0 == (Attr & 0x04) ? 0 : (Intensity << 16)) |
77 (0 == (Attr & 0x02) ? 0 : (Intensity << 8)) |
78 (0 == (Attr & 0x01) ? 0 : Intensity);
79 }
80
81 static VOID
82 XboxVideoAttrToColors(UCHAR Attr, ULONG *FgColor, ULONG *BgColor)
83 {
84 *FgColor = XboxVideoAttrToSingleColor(Attr & 0xf);
85 *BgColor = XboxVideoAttrToSingleColor((Attr >> 4) & 0xf);
86 }
87
88 static VOID
89 XboxVideoClearScreenColor(ULONG Color, BOOLEAN FullScreen)
90 {
91 ULONG Line, Col;
92 PULONG p;
93
94 for (Line = 0; Line < ScreenHeight - (FullScreen ? 0 : 2 * TOP_BOTTOM_LINES); Line++)
95 {
96 p = (PULONG) ((char *) FrameBuffer + (Line + (FullScreen ? 0 : TOP_BOTTOM_LINES)) * Delta);
97 for (Col = 0; Col < ScreenWidth; Col++)
98 {
99 *p++ = Color;
100 }
101 }
102 }
103
104 VOID
105 XboxVideoClearScreen(UCHAR Attr)
106 {
107 ULONG FgColor, BgColor;
108
109 XboxVideoAttrToColors(Attr, &FgColor, &BgColor);
110
111 XboxVideoClearScreenColor(BgColor, FALSE);
112 }
113
114 VOID
115 XboxVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
116 {
117 ULONG FgColor, BgColor;
118
119 XboxVideoAttrToColors(Attr, &FgColor, &BgColor);
120
121 XboxVideoOutputChar(Ch, X, Y, FgColor, BgColor);
122 }
123
124 VOID
125 XboxVideoInit(VOID)
126 {
127 ULONG AvMode;
128
129 FrameBuffer = (PVOID)((ULONG) XboxMemReserveMemory(FB_SIZE_MB) | 0xf0000000);
130
131 if (I2CTransmitByteGetReturn(0x10, 0x04, &AvMode))
132 {
133 if (1 == AvMode) /* HDTV */
134 {
135 ScreenWidth = 720;
136 }
137 else
138 {
139 /* FIXME Other possible values of AvMode:
140 * 0 - AV_SCART_RGB
141 * 2 - AV_VGA_SOG
142 * 4 - AV_SVIDEO
143 * 6 - AV_COMPOSITE
144 * 7 - AV_VGA
145 * other AV_COMPOSITE
146 */
147 ScreenWidth = 640;
148 }
149 }
150 else
151 {
152 ScreenWidth = 640;
153 }
154
155 ScreenHeight = 480;
156 BytesPerPixel = 4;
157 Delta = (ScreenWidth * BytesPerPixel + 3) & ~ 0x3;
158
159 XboxVideoClearScreenColor(MAKE_COLOR(0, 0, 0), TRUE);
160
161 /* Tell the nVidia controller about the framebuffer */
162 *((PULONG) 0xfd600800) = (ULONG) FrameBuffer;
163 }
164
165 VIDEODISPLAYMODE
166 XboxVideoSetDisplayMode(char *DisplayMode, BOOLEAN Init)
167 {
168 /* We only have one mode, semi-text */
169 return VideoTextMode;
170 }
171
172 VOID
173 XboxVideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth)
174 {
175 *Width = ScreenWidth / CHAR_WIDTH;
176 *Height = (ScreenHeight - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT;
177 *Depth = 0;
178 }
179
180 ULONG
181 XboxVideoGetBufferSize(VOID)
182 {
183 return (ScreenHeight - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT * (ScreenWidth / CHAR_WIDTH) * 2;
184 }
185
186 VOID
187 XboxVideoGetFontsFromFirmware(PULONG RomFontPointers)
188 {
189 TRACE("XboxVideoGetFontsFromFirmware(): UNIMPLEMENTED\n");
190 }
191
192 VOID
193 XboxVideoSetTextCursorPosition(UCHAR X, UCHAR Y)
194 {
195 /* We don't have a cursor yet */
196 }
197
198 VOID
199 XboxVideoHideShowTextCursor(BOOLEAN Show)
200 {
201 /* We don't have a cursor yet */
202 }
203
204 VOID
205 XboxVideoCopyOffScreenBufferToVRAM(PVOID Buffer)
206 {
207 PUCHAR OffScreenBuffer = (PUCHAR) Buffer;
208 ULONG Col, Line;
209
210 for (Line = 0; Line < (ScreenHeight - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT; Line++)
211 {
212 for (Col = 0; Col < ScreenWidth / CHAR_WIDTH; Col++)
213 {
214 XboxVideoPutChar(OffScreenBuffer[0], OffScreenBuffer[1], Col, Line);
215 OffScreenBuffer += 2;
216 }
217 }
218 }
219
220 BOOLEAN
221 XboxVideoIsPaletteFixed(VOID)
222 {
223 return FALSE;
224 }
225
226 VOID
227 XboxVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue)
228 {
229 /* Not supported */
230 }
231
232 VOID
233 XboxVideoGetPaletteColor(UCHAR Color, UCHAR* Red, UCHAR* Green, UCHAR* Blue)
234 {
235 /* Not supported */
236 }
237
238 VOID
239 XboxVideoSync(VOID)
240 {
241 /* Not supported */
242 }
243
244 VOID
245 XboxBeep(VOID)
246 {
247 /* Call PC version */
248 PcBeep();
249 }
250
251 VOID
252 XboxVideoPrepareForReactOS(VOID)
253 {
254 XboxVideoClearScreenColor(MAKE_COLOR(0, 0, 0), TRUE);
255 XboxVideoHideShowTextCursor(FALSE);
256 }
257
258 /* EOF */