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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Note: much of this code was based on knowledge and/or code developed
20 * by the Xbox Linux group: http://www.xbox-linux.org
30 #define I2C_IO_BASE 0xc000
32 static PVOID FrameBuffer
;
33 static ULONG ScreenWidth
;
34 static ULONG ScreenHeight
;
35 static ULONG BytesPerPixel
;
39 #define CHAR_HEIGHT 16
41 #define TOP_BOTTOM_LINES 0
45 #define MAKE_COLOR(Red, Green, Blue) (0xff000000 | (((Red) & 0xff) << 16) | (((Green) & 0xff) << 8) | ((Blue) & 0xff))
48 XboxVideoOutputChar(UCHAR Char
, unsigned X
, unsigned Y
, ULONG FgColor
, ULONG BgColor
)
56 FontPtr
= XboxFont8x16
+ Char
* 16;
57 Pixel
= (PULONG
) ((char *) FrameBuffer
+ (Y
* CHAR_HEIGHT
+ TOP_BOTTOM_LINES
) * Delta
58 + X
* CHAR_WIDTH
* BytesPerPixel
);
59 for (Line
= 0; Line
< CHAR_HEIGHT
; Line
++)
62 for (Col
= 0; Col
< CHAR_WIDTH
; Col
++)
64 Pixel
[Col
] = (0 != (FontPtr
[Line
] & Mask
) ? FgColor
: BgColor
);
67 Pixel
= (PULONG
) ((char *) Pixel
+ Delta
);
72 XboxVideoAttrToSingleColor(UCHAR Attr
)
76 Intensity
= (0 == (Attr
& 0x08) ? 127 : 255);
79 (0 == (Attr
& 0x04) ? 0 : (Intensity
<< 16)) |
80 (0 == (Attr
& 0x02) ? 0 : (Intensity
<< 8)) |
81 (0 == (Attr
& 0x01) ? 0 : Intensity
);
85 XboxVideoAttrToColors(UCHAR Attr
, ULONG
*FgColor
, ULONG
*BgColor
)
87 *FgColor
= XboxVideoAttrToSingleColor(Attr
& 0xf);
88 *BgColor
= XboxVideoAttrToSingleColor((Attr
>> 4) & 0xf);
92 XboxVideoClearScreenColor(ULONG Color
, BOOL FullScreen
)
97 for (Line
= 0; Line
< ScreenHeight
- (FullScreen
? 0 : 2 * TOP_BOTTOM_LINES
); Line
++)
99 p
= (PULONG
) ((char *) FrameBuffer
+ (Line
+ (FullScreen
? 0 : TOP_BOTTOM_LINES
)) * Delta
);
100 for (Col
= 0; Col
< ScreenWidth
; Col
++)
108 XboxVideoClearScreen(UCHAR Attr
)
110 ULONG FgColor
, BgColor
;
112 XboxVideoAttrToColors(Attr
, &FgColor
, &BgColor
);
114 XboxVideoClearScreenColor(BgColor
, FALSE
);
118 XboxVideoPutChar(int Ch
, UCHAR Attr
, unsigned X
, unsigned Y
)
120 ULONG FgColor
, BgColor
;
122 XboxVideoAttrToColors(Attr
, &FgColor
, &BgColor
);
124 XboxVideoOutputChar(Ch
, X
, Y
, FgColor
, BgColor
);
128 ReadfromSMBus(UCHAR Address
, UCHAR bRegister
, UCHAR Size
, ULONG
*Data_to_smbus
)
130 int nRetriesToLive
=50;
132 while (0 != (READ_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 0)) & 0x0800))
134 ; /* Franz's spin while bus busy with any master traffic */
137 while (0 != nRetriesToLive
--)
142 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 4), (Address
<< 1) | 1);
143 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 8), bRegister
);
145 temp
= READ_PORT_USHORT((USHORT
*) (I2C_IO_BASE
+ 0));
146 WRITE_PORT_USHORT((PUSHORT
) (I2C_IO_BASE
+ 0), temp
); /* clear down all preexisting errors */
151 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x0d); /* DWORD modus ? */
154 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x0b); /* WORD modus */
157 WRITE_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 2), 0x0a); // BYTE
163 while (0 == (b
& 0x36))
165 b
= READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 0));
170 /* printf("I2CTransmitByteGetReturn error %x\n", b); */
175 /* printf("I2CTransmitByteGetReturn no complete, retry\n"); */
182 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 6));
183 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9));
184 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9));
185 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9));
186 READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 9));
189 *Data_to_smbus
= READ_PORT_USHORT((USHORT
*) (I2C_IO_BASE
+ 6));
192 *Data_to_smbus
= READ_PORT_UCHAR((PUCHAR
) (I2C_IO_BASE
+ 6));
206 I2CTransmitByteGetReturn(UCHAR bPicAddressI2cFormat
, UCHAR bDataToWrite
, ULONG
*Return
)
208 return ReadfromSMBus(bPicAddressI2cFormat
, bDataToWrite
, 1, Return
);
217 FrameBuffer
= (PVOID
)((ULONG
) XboxMemReserveMemory(FB_SIZE_MB
) | 0xf0000000);
219 if (I2CTransmitByteGetReturn(0x10, 0x04, &AvMode
))
221 if (1 == AvMode
) /* HDTV */
227 /* FIXME Other possible values of AvMode:
245 Delta
= (ScreenWidth
* BytesPerPixel
+ 3) & ~ 0x3;
247 XboxVideoClearScreenColor(MAKE_COLOR(0, 0, 0), TRUE
);
249 /* Tell the nVidia controller about the framebuffer */
250 *((PULONG
) 0xfd600800) = (ULONG
) FrameBuffer
;
254 XboxVideoSetDisplayMode(char *DisplayMode
, BOOL Init
)
256 /* We only have one mode, semi-text */
257 return VideoTextMode
;
261 XboxVideoGetDisplaySize(PULONG Width
, PULONG Height
, PULONG Depth
)
263 *Width
= ScreenWidth
/ CHAR_WIDTH
;
264 *Height
= (ScreenHeight
- 2 * TOP_BOTTOM_LINES
) / CHAR_HEIGHT
;
269 XboxVideoGetBufferSize(VOID
)
271 return (ScreenHeight
- 2 * TOP_BOTTOM_LINES
) / CHAR_HEIGHT
* (ScreenWidth
/ CHAR_WIDTH
) * 2;
275 XboxVideoSetTextCursorPosition(ULONG X
, ULONG Y
)
277 /* We don't have a cursor yet */
281 XboxVideoHideShowTextCursor(BOOL Show
)
283 /* We don't have a cursor yet */
287 XboxVideoCopyOffScreenBufferToVRAM(PVOID Buffer
)
289 PUCHAR OffScreenBuffer
= (PUCHAR
) Buffer
;
292 for (Line
= 0; Line
< (ScreenHeight
- 2 * TOP_BOTTOM_LINES
) / CHAR_HEIGHT
; Line
++)
294 for (Col
= 0; Col
< ScreenWidth
/ CHAR_WIDTH
; Col
++)
296 XboxVideoPutChar(OffScreenBuffer
[0], OffScreenBuffer
[1], Col
, Line
);
297 OffScreenBuffer
+= 2;
303 XboxVideoIsPaletteFixed(VOID
)
309 XboxVideoSetPaletteColor(UCHAR Color
, UCHAR Red
, UCHAR Green
, UCHAR Blue
)
315 XboxVideoGetPaletteColor(UCHAR Color
, UCHAR
* Red
, UCHAR
* Green
, UCHAR
* Blue
)
327 XboxVideoPrepareForReactOS(VOID
)
329 XboxVideoClearScreenColor(MAKE_COLOR(0, 0, 0), TRUE
);