ReactOS  0.4.14-dev-593-g1793dcc
xboxvideo.c
Go to the documentation of this file.
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 
26 
32 static ULONG Delta;
33 
34 #define CHAR_WIDTH 8
35 #define CHAR_HEIGHT 16
36 
37 #define TOP_BOTTOM_LINES 0
38 
39 #define FB_SIZE_MB 4
40 
41 #define MAKE_COLOR(Red, Green, Blue) (0xff000000 | (((Red) & 0xff) << 16) | (((Green) & 0xff) << 8) | ((Blue) & 0xff))
42 
43 static VOID
44 XboxVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
45 {
46  PUCHAR FontPtr;
47  PULONG Pixel;
48  UCHAR Mask;
49  unsigned Line;
50  unsigned Col;
51 
52  FontPtr = XboxFont8x16 + Char * 16;
53  Pixel = (PULONG) ((char *) FrameBuffer + (Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta
54  + X * CHAR_WIDTH * BytesPerPixel);
55  for (Line = 0; Line < CHAR_HEIGHT; Line++)
56  {
57  Mask = 0x80;
58  for (Col = 0; Col < CHAR_WIDTH; Col++)
59  {
60  Pixel[Col] = (0 != (FontPtr[Line] & Mask) ? FgColor : BgColor);
61  Mask = Mask >> 1;
62  }
63  Pixel = (PULONG) ((char *) Pixel + Delta);
64  }
65 }
66 
67 static ULONG
69 {
71 
72  Intensity = (0 == (Attr & 0x08) ? 127 : 255);
73 
74  return 0xff000000 |
75  (0 == (Attr & 0x04) ? 0 : (Intensity << 16)) |
76  (0 == (Attr & 0x02) ? 0 : (Intensity << 8)) |
77  (0 == (Attr & 0x01) ? 0 : Intensity);
78 }
79 
80 static VOID
81 XboxVideoAttrToColors(UCHAR Attr, ULONG *FgColor, ULONG *BgColor)
82 {
83  *FgColor = XboxVideoAttrToSingleColor(Attr & 0xf);
84  *BgColor = XboxVideoAttrToSingleColor((Attr >> 4) & 0xf);
85 }
86 
87 static VOID
89 {
90  ULONG Line, Col;
91  PULONG p;
92 
93  for (Line = 0; Line < ScreenHeight - (FullScreen ? 0 : 2 * TOP_BOTTOM_LINES); Line++)
94  {
95  p = (PULONG) ((char *) FrameBuffer + (Line + (FullScreen ? 0 : TOP_BOTTOM_LINES)) * Delta);
96  for (Col = 0; Col < ScreenWidth; Col++)
97  {
98  *p++ = Color;
99  }
100  }
101 }
102 
103 VOID
105 {
106  ULONG FgColor, BgColor;
107 
108  XboxVideoAttrToColors(Attr, &FgColor, &BgColor);
109 
111 }
112 
113 VOID
114 XboxVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
115 {
116  ULONG FgColor, BgColor;
117 
118  XboxVideoAttrToColors(Attr, &FgColor, &BgColor);
119 
120  XboxVideoOutputChar(Ch, X, Y, FgColor, BgColor);
121 }
122 
123 UCHAR
125 {
127  return *((PUCHAR) NV2A_CRTC_REGISTER_VALUE);
128 }
129 
130 VOID
132 {
133  /* Reuse framebuffer that was set up by firmware */
135  /* Verify that framebuffer address is page-aligned */
137 
138  /* FIXME: obtain fb size from firmware somehow (Cromwell reserves high 4 MB of RAM) */
139  FrameBufferSize = 4 * 1024 * 1024;
140 
143  /* Get BPP directly from NV2A CRTC (magic constants are from Cromwell) */
144  BytesPerPixel = 8 * (((NvGetCrtc(0x19) & 0xE0) << 3) | (NvGetCrtc(0x13) & 0xFF)) / ScreenWidth;
145  if (BytesPerPixel == 4)
146  {
147  ASSERT((NvGetCrtc(0x28) & 0xF) == BytesPerPixel - 1);
148  }
149  else
150  {
151  ASSERT((NvGetCrtc(0x28) & 0xF) == BytesPerPixel);
152  }
153  Delta = (ScreenWidth * BytesPerPixel + 3) & ~ 0x3;
154 
155  /* Verify screen resolution */
156  ASSERT(ScreenWidth > 1);
157  ASSERT(ScreenHeight > 1);
158  ASSERT(BytesPerPixel >= 1 && BytesPerPixel <= 4);
159  /* Verify that screen fits framebuffer size */
161 
163 }
164 
167 {
168  /* We only have one mode, semi-text */
169  return VideoTextMode;
170 }
171 
172 VOID
174 {
175  *Width = ScreenWidth / CHAR_WIDTH;
176  *Height = (ScreenHeight - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT;
177  *Depth = 0;
178 }
179 
180 ULONG
182 {
184 }
185 
186 VOID
188 {
189  TRACE("XboxVideoGetFontsFromFirmware(): UNIMPLEMENTED\n");
190 }
191 
192 VOID
194 {
195  /* We don't have a cursor yet */
196 }
197 
198 VOID
200 {
201  /* We don't have a cursor yet */
202 }
203 
204 VOID
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
222 {
223  return FALSE;
224 }
225 
226 VOID
228 {
229  /* Not supported */
230 }
231 
232 VOID
234 {
235  /* Not supported */
236 }
237 
238 VOID
240 {
241  /* Not supported */
242 }
243 
244 VOID
246 {
247  /* Call PC version */
248  PcBeep();
249 }
250 
251 VOID
253 {
256 }
257 
258 /* EOF */
Definition: bl.h:202
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION _In_ ULONG _In_ SIZE_T _In_ ULONG _In_ USHORT Depth
Definition: exfuncs.h:656
#define TRUE
Definition: types.h:120
static VOID XboxVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
Definition: xboxvideo.c:44
#define Y(I)
static VOID XboxVideoClearScreenColor(ULONG Color, BOOLEAN FullScreen)
Definition: xboxvideo.c:88
static ULONG BytesPerPixel
Definition: xboxvideo.c:31
unsigned char * PUCHAR
Definition: retypes.h:3
VOID XboxVideoCopyOffScreenBufferToVRAM(PVOID Buffer)
Definition: xboxvideo.c:205
#define TOP_BOTTOM_LINES
Definition: xboxvideo.c:37
static ULONG ScreenWidth
Definition: xboxvideo.c:29
VOID XboxVideoClearScreen(UCHAR Attr)
Definition: xboxvideo.c:104
Definition: bl.h:199
#define Ch(x, y, z)
Definition: sha2.c:141
struct Color Color
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID XboxVideoSetTextCursorPosition(UCHAR X, UCHAR Y)
Definition: xboxvideo.c:193
#define NV2A_CRTC_REGISTER_VALUE
Definition: machxbox.h:44
#define NV2A_RAMDAC_FP_VVALID_END
Definition: machxbox.h:47
ULONG FrameBufferSize
Definition: xboxvideo.c:28
unsigned char BOOLEAN
#define NV2A_CRTC_REGISTER_INDEX
Definition: machxbox.h:43
ULONG XboxVideoGetBufferSize(VOID)
Definition: xboxvideo.c:181
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
#define NV2A_CRTC_FRAMEBUFFER_START
Definition: machxbox.h:42
VOID XboxVideoGetFontsFromFirmware(PULONG RomFontPointers)
Definition: xboxvideo.c:187
static VOID XboxVideoAttrToColors(UCHAR Attr, ULONG *FgColor, ULONG *BgColor)
Definition: xboxvideo.c:81
static ULONG ScreenHeight
Definition: xboxvideo.c:30
#define TRACE(s)
Definition: solgame.cpp:4
VOID XboxBeep(VOID)
Definition: xboxvideo.c:245
BOOLEAN XboxVideoIsPaletteFixed(VOID)
Definition: xboxvideo.c:221
UCHAR NvGetCrtc(UCHAR Index)
Definition: xboxvideo.c:124
VOID XboxVideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth)
Definition: xboxvideo.c:173
static const UCHAR Index[8]
Definition: usbohci.c:18
UCHAR XboxFont8x16[256 *16]
Definition: xboxfont.c:23
DBG_DEFAULT_CHANNEL(UI)
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: ncftp.h:79
static VIDEODISPLAYMODE DisplayMode
Definition: pcvideo.c:115
VOID XboxVideoSync(VOID)
Definition: xboxvideo.c:239
#define CHAR_WIDTH
Definition: xboxvideo.c:34
Definition: bl.h:200
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID XboxVideoInit(VOID)
Definition: xboxvideo.c:131
static WORD Intensity(RGBQUAD clr)
Definition: msrle32.c:44
enum tagVIDEODISPLAYMODE VIDEODISPLAYMODE
VOID XboxVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
Definition: xboxvideo.c:114
#define PAGE_SIZE
Definition: env_spec_w32.h:49
static ULONG XboxVideoAttrToSingleColor(UCHAR Attr)
Definition: xboxvideo.c:68
VOID XboxVideoPrepareForReactOS(VOID)
Definition: xboxvideo.c:252
#define CHAR_HEIGHT
Definition: xboxvideo.c:35
VOID PcBeep(VOID)
Definition: i386rtl.c:25
VOID XboxVideoHideShowTextCursor(BOOLEAN Show)
Definition: xboxvideo.c:199
PVOID FrameBuffer
Definition: xboxvideo.c:27
#define RomFontPointers
Definition: winldr.c:422
static ULONG Delta
Definition: xboxvideo.c:32
unsigned int * PULONG
Definition: retypes.h:1
#define MAKE_COLOR(Red, Green, Blue)
Definition: xboxvideo.c:41
VOID XboxVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue)
Definition: xboxvideo.c:227
unsigned int ULONG
Definition: retypes.h:1
VOID XboxVideoGetPaletteColor(UCHAR Color, UCHAR *Red, UCHAR *Green, UCHAR *Blue)
Definition: xboxvideo.c:233
VIDEODISPLAYMODE XboxVideoSetDisplayMode(char *DisplayMode, BOOLEAN Init)
Definition: xboxvideo.c:166
GLfloat GLfloat p
Definition: glext.h:8902
#define NV2A_RAMDAC_FP_HVALID_END
Definition: machxbox.h:46
struct Line Line