ReactOS 0.4.15-dev-8344-g0574987
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
24#include <debug.h>
26
27ULONG NvBase = 0xFD000000;
33static ULONG Delta;
35
37
38#define CHAR_WIDTH 8
39#define CHAR_HEIGHT 16
40
41#define TOP_BOTTOM_LINES 0
42
43#define FB_SIZE_MB 4
44
45#define MAKE_COLOR(Red, Green, Blue) (0xff000000 | (((Red) & 0xff) << 16) | (((Green) & 0xff) << 8) | ((Blue) & 0xff))
46
47static VOID
48XboxVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
49{
50 PUCHAR FontPtr;
51 PULONG Pixel;
52 UCHAR Mask;
53 unsigned Line;
54 unsigned Col;
55
56 FontPtr = BitmapFont8x16 + Char * 16;
57 Pixel = (PULONG) ((char *) FrameBuffer + (Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta
59 for (Line = 0; Line < CHAR_HEIGHT; Line++)
60 {
61 Mask = 0x80;
62 for (Col = 0; Col < CHAR_WIDTH; Col++)
63 {
64 Pixel[Col] = (0 != (FontPtr[Line] & Mask) ? FgColor : BgColor);
65 Mask = Mask >> 1;
66 }
67 Pixel = (PULONG) ((char *) Pixel + Delta);
68 }
69}
70
71static ULONG
73{
75
76 Intensity = (0 == (Attr & 0x08) ? 127 : 255);
77
78 return 0xff000000 |
79 (0 == (Attr & 0x04) ? 0 : (Intensity << 16)) |
80 (0 == (Attr & 0x02) ? 0 : (Intensity << 8)) |
81 (0 == (Attr & 0x01) ? 0 : Intensity);
82}
83
84static VOID
85XboxVideoAttrToColors(UCHAR Attr, ULONG *FgColor, ULONG *BgColor)
86{
87 *FgColor = XboxVideoAttrToSingleColor(Attr & 0xf);
88 *BgColor = XboxVideoAttrToSingleColor((Attr >> 4) & 0xf);
89}
90
91static VOID
93{
94 ULONG Line, Col;
95 PULONG p;
96
97 for (Line = 0; Line < ScreenHeight - (FullScreen ? 0 : 2 * TOP_BOTTOM_LINES); Line++)
98 {
99 p = (PULONG) ((char *) FrameBuffer + (Line + (FullScreen ? 0 : TOP_BOTTOM_LINES)) * Delta);
100 for (Col = 0; Col < ScreenWidth; Col++)
101 {
102 *p++ = Color;
103 }
104 }
105}
106
107VOID
109{
110 ULONG BgColor, Dummy;
111 ULONG PixelCount = ScreenWidth * CHAR_HEIGHT *
112 (((ScreenHeight - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT) - 1);
115
117
118 while (PixelCount--)
119 *Dst++ = *Src++;
120
121 for (PixelCount = 0; PixelCount < ScreenWidth * CHAR_HEIGHT; PixelCount++)
122 *Dst++ = BgColor;
123}
124
125VOID
127{
128 ULONG FgColor, BgColor;
129
130 XboxVideoAttrToColors(Attr, &FgColor, &BgColor);
131
133}
134
135VOID
136XboxVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
137{
138 ULONG FgColor, BgColor;
139
140 XboxVideoAttrToColors(Attr, &FgColor, &BgColor);
141
142 XboxVideoOutputChar(Ch, X, Y, FgColor, BgColor);
143}
144
145UCHAR
147{
150}
151
152ULONG
154{
156 INT Count, i;
157
158 if (!MultibootInfoPtr)
159 {
160 return 0;
161 }
162
164 {
165 return 0;
166 }
167
169
170 if (!MemoryMap ||
173 {
174 return 0;
175 }
176
178 for (i = 0; i < Count; i++, MemoryMap++)
179 {
180 TRACE("i = %d, base_addr_low = 0x%p, MemoryMap->length_low = 0x%p\n", i, MemoryMap->base_addr_low, MemoryMap->length_low);
181
182 /* Framebuffer address offset value is coming from the GPU within
183 * memory mapped I/O address space, so we're comparing only low
184 * 28 bits of the address within actual RAM address space */
185 if (MemoryMap->base_addr_low == ((ULONG)Offset & 0x0FFFFFFF) && MemoryMap->base_addr_high == 0)
186 {
187 TRACE("Video memory found\n");
188 return MemoryMap->length_low;
189 }
190 }
191 ERR("Video memory not found!\n");
192 return 0;
193}
194
195VOID
197{
198 /* Reuse framebuffer that was set up by firmware */
200 /* Verify that framebuffer address is page-aligned */
202
203 /* Obtain framebuffer memory size from multiboot memory map */
205 {
206 /* Fallback to Cromwell standard which reserves high 4 MB of RAM */
207 FrameBufferSize = 4 * 1024 * 1024;
208 WARN("Could not detect framebuffer memory size, fallback to 4 MB\n");
209 }
210
213 /* Get BPP directly from NV2A CRTC (magic constants are from Cromwell) */
214 BytesPerPixel = 8 * (((NvGetCrtc(0x19) & 0xE0) << 3) | (NvGetCrtc(0x13) & 0xFF)) / ScreenWidth;
215 if (BytesPerPixel == 4)
216 {
217 ASSERT((NvGetCrtc(0x28) & 0xF) == BytesPerPixel - 1);
218 }
219 else
220 {
221 ASSERT((NvGetCrtc(0x28) & 0xF) == BytesPerPixel);
222 }
223 Delta = (ScreenWidth * BytesPerPixel + 3) & ~ 0x3;
224
225 /* Verify screen resolution */
226 ASSERT(ScreenWidth > 1);
227 ASSERT(ScreenHeight > 1);
228 ASSERT(BytesPerPixel >= 1 && BytesPerPixel <= 4);
229 /* Verify that screen fits framebuffer size */
231
233}
234
237{
238 /* We only have one mode, semi-text */
239 return VideoTextMode;
240}
241
242VOID
244{
247 *Depth = 0;
248}
249
250ULONG
252{
254}
255
256VOID
258{
259 TRACE("XboxVideoGetFontsFromFirmware(): UNIMPLEMENTED\n");
260}
261
262VOID
264{
265 /* We don't have a cursor yet */
266}
267
268VOID
270{
271 /* We don't have a cursor yet */
272}
273
274VOID
276{
277 PUCHAR OffScreenBuffer = (PUCHAR) Buffer;
278 ULONG Col, Line;
279
280 for (Line = 0; Line < (ScreenHeight - 2 * TOP_BOTTOM_LINES) / CHAR_HEIGHT; Line++)
281 {
282 for (Col = 0; Col < ScreenWidth / CHAR_WIDTH; Col++)
283 {
284 XboxVideoPutChar(OffScreenBuffer[0], OffScreenBuffer[1], Col, Line);
285 OffScreenBuffer += 2;
286 }
287 }
288}
289
292{
293 return FALSE;
294}
295
296VOID
298{
299 /* Not supported */
300}
301
302VOID
304{
305 /* Not supported */
306}
307
308VOID
310{
311 /* Not supported */
312}
313
314VOID
316{
319}
320
321/* EOF */
unsigned char BOOLEAN
#define RomFontPointers
Definition: winldr.c:348
#define READ_REGISTER_ULONG(r)
Definition: arm.h:26
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
@ Green
Definition: bl.h:199
@ Red
Definition: bl.h:201
@ Blue
Definition: bl.h:198
BIOS_MEMORY_MAP MemoryMap[32]
Definition: loader.c:11
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
@ VideoTextMode
Definition: machine.h:35
enum tagVIDEODISPLAYMODE VIDEODISPLAYMODE
#define COLOR_GRAY
Definition: ui.h:329
#define ATTR(cFore, cBack)
Definition: ui.h:317
#define COLOR_WHITE
Definition: ui.h:338
#define COLOR_BLACK
Definition: ui.h:322
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define Y(I)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
unsigned int Mask
Definition: fpcontrol.c:82
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
if(dx< 0)
Definition: linetemp.h:194
#define Dst
Definition: mesh.h:153
#define ASSERT(a)
Definition: mode.c:44
static WORD Intensity(RGBQUAD clr)
Definition: msrle32.c:44
#define MB_INFO_FLAG_MEMORY_MAP
Definition: multiboot.h:50
struct memory_map memory_map_t
int Count
Definition: noreturn.cpp:7
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
UCHAR BitmapFont8x16[]
Definition: vgafont.c:12
static VIDEODISPLAYMODE DisplayMode
Definition: pcvideo.c:117
#define Ch(x, y, z)
Definition: sha2.c:141
#define TRACE(s)
Definition: solgame.cpp:4
Definition: ncftp.h:79
Definition: ui.h:200
unsigned long mmap_addr
Definition: multiboot.h:109
unsigned long mmap_length
Definition: multiboot.h:108
unsigned long flags
Definition: multiboot.h:96
uint32_t * PULONG
Definition: typedefs.h:59
void * PVOID
Definition: typedefs.h:50
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
_In_ WDFCOLLECTION _In_ ULONG Index
VOID XboxVideoGetPaletteColor(UCHAR Color, UCHAR *Red, UCHAR *Green, UCHAR *Blue)
Definition: xboxvideo.c:303
VOID XboxVideoInit(VOID)
Definition: xboxvideo.c:196
ULONG FrameBufferSize
Definition: xboxvideo.c:29
static VOID XboxVideoClearScreenColor(ULONG Color, BOOLEAN FullScreen)
Definition: xboxvideo.c:92
static ULONG ScreenWidth
Definition: xboxvideo.c:30
static ULONG Delta
Definition: xboxvideo.c:33
#define TOP_BOTTOM_LINES
Definition: xboxvideo.c:41
VOID XboxVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
Definition: xboxvideo.c:136
static ULONG ScreenHeight
Definition: xboxvideo.c:31
VOID XboxVideoPrepareForReactOS(VOID)
Definition: xboxvideo.c:315
multiboot_info_t * MultibootInfoPtr
VOID XboxVideoSetTextCursorPosition(UCHAR X, UCHAR Y)
Definition: xboxvideo.c:263
VOID XboxVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue)
Definition: xboxvideo.c:297
VOID XboxVideoCopyOffScreenBufferToVRAM(PVOID Buffer)
Definition: xboxvideo.c:275
PVOID FrameBuffer
Definition: xboxvideo.c:28
#define CHAR_WIDTH
Definition: xboxvideo.c:38
VOID XboxVideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth)
Definition: xboxvideo.c:243
ULONG XboxGetFramebufferSize(PVOID Offset)
Definition: xboxvideo.c:153
ULONG XboxVideoGetBufferSize(VOID)
Definition: xboxvideo.c:251
VOID XboxVideoScrollUp(VOID)
Definition: xboxvideo.c:108
ULONG NvBase
Definition: xboxvideo.c:27
VOID XboxVideoSync(VOID)
Definition: xboxvideo.c:309
static VOID XboxVideoAttrToColors(UCHAR Attr, ULONG *FgColor, ULONG *BgColor)
Definition: xboxvideo.c:85
VIDEODISPLAYMODE XboxVideoSetDisplayMode(char *DisplayMode, BOOLEAN Init)
Definition: xboxvideo.c:236
VOID XboxVideoHideShowTextCursor(BOOLEAN Show)
Definition: xboxvideo.c:269
UCHAR MachDefaultTextColor
Definition: xboxvideo.c:36
BOOLEAN XboxVideoIsPaletteFixed(VOID)
Definition: xboxvideo.c:291
#define MAKE_COLOR(Red, Green, Blue)
Definition: xboxvideo.c:45
static ULONG BytesPerPixel
Definition: xboxvideo.c:32
VOID XboxVideoClearScreen(UCHAR Attr)
Definition: xboxvideo.c:126
static ULONG XboxVideoAttrToSingleColor(UCHAR Attr)
Definition: xboxvideo.c:72
#define CHAR_HEIGHT
Definition: xboxvideo.c:39
VOID XboxVideoGetFontsFromFirmware(PULONG RomFontPointers)
Definition: xboxvideo.c:257
UCHAR NvGetCrtc(UCHAR Index)
Definition: xboxvideo.c:146
static VOID XboxVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
Definition: xboxvideo.c:48
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION _In_ ULONG _In_ SIZE_T _In_ ULONG _In_ USHORT Depth
Definition: exfuncs.h:819
NTKERNELAPI VOID NTAPI WRITE_REGISTER_UCHAR(IN PUCHAR Register, IN UCHAR Value)
NTKERNELAPI UCHAR NTAPI READ_REGISTER_UCHAR(IN PUCHAR Register)
#define NV2A_CRTC_FRAMEBUFFER_START
Definition: xgpu.h:21
#define NV2A_RAMDAC_FP_VVALID_END
Definition: xgpu.h:26
#define NV2A_CRTC_REGISTER_INDEX
Definition: xgpu.h:22
#define NV2A_CRTC_REGISTER_VALUE
Definition: xgpu.h:23
#define NV2A_RAMDAC_FP_HVALID_END
Definition: xgpu.h:25
unsigned char UCHAR
Definition: xmlstorage.h:181