2 * ReactOS Boot video driver
4 * Copyright (C) 2005 Filip Navara
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 /* INCLUDES ******************************************************************/
27 /* TYPES AND DEFINITIONS *****************************************************/
30 #define MISC (PUCHAR)0x3c2
31 #define SEQ (PUCHAR)0x3c4
32 #define SEQDATA (PUCHAR)0x3c5
33 #define CRTC (PUCHAR)0x3d4
34 #define CRTCDATA (PUCHAR)0x3d5
35 #define GRAPHICS (PUCHAR)0x3ce
36 #define GRAPHICSDATA (PUCHAR)0x3cf
37 #define ATTRIB (PUCHAR)0x3c0
38 #define STATUS (PUCHAR)0x3da
39 #define PELMASK (PUCHAR)0x3c6
40 #define PELINDEX (PUCHAR)0x3c8
41 #define PELDATA (PUCHAR)0x3c9
43 #define CRTC_COLUMNS 0x01
44 #define CRTC_OVERFLOW 0x07
45 #define CRTC_ROWS 0x12
46 #define CRTC_SCANLINES 0x09
47 #define CRTC_CURHI 0x0e
48 #define CRTC_CURLO 0x0f
50 #define CHAR_ATTRIBUTE_BLACK 0x00 /* black on black */
51 #define CHAR_ATTRIBUTE 0x1F /* grey on blue */
53 /* GLOBALS *******************************************************************/
55 static BOOLEAN VidpInitialized
= FALSE
;
56 static PUCHAR VidpMemory
;
57 static ULONG SizeX
, SizeY
;
59 /* FUNCTIONS *****************************************************************/
62 VidpVgaTextClearDisplay(VOID
)
64 volatile WORD
*ptr
= (volatile WORD
*)VidpMemory
;
67 for (i
= 0; i
< SizeX
* SizeY
; i
++, ptr
++)
68 *ptr
= (0x1700 + ' ');
76 PHYSICAL_ADDRESS PhysicalAddress
;
81 PhysicalAddress
.QuadPart
= 0xB8000;
82 VidpMemory
= MmMapIoSpace(PhysicalAddress
, 0x2000, MmNonCached
);
83 if (VidpMemory
== NULL
)
85 VidpInitialized
= TRUE
;
87 WRITE_PORT_UCHAR(CRTC
, CRTC_COLUMNS
);
88 SizeX
= READ_PORT_UCHAR(CRTCDATA
) + 1;
89 WRITE_PORT_UCHAR(CRTC
, CRTC_ROWS
);
90 SizeY
= READ_PORT_UCHAR(CRTCDATA
);
91 WRITE_PORT_UCHAR(CRTC
, CRTC_OVERFLOW
);
92 Data
= READ_PORT_UCHAR(CRTCDATA
);
93 SizeY
|= (((Data
& 0x02) << 7) | ((Data
& 0x40) << 3));
95 WRITE_PORT_UCHAR(CRTC
, CRTC_SCANLINES
);
96 ScanLines
= (READ_PORT_UCHAR(CRTCDATA
) & 0x1F) + 1;
97 SizeY
= SizeY
/ ScanLines
;
99 VidpVgaTextClearDisplay();
101 WRITE_PORT_UCHAR(CRTC
, CRTC_CURLO
);
102 WRITE_PORT_UCHAR(CRTCDATA
, 0);
103 WRITE_PORT_UCHAR(CRTC
, CRTC_CURHI
);
104 WRITE_PORT_UCHAR(CRTCDATA
, 0);
111 VidVgaTextResetDisplay(VOID
)
113 VidVgaTextInitialize(TRUE
);
117 VidVgaTextCleanUp(VOID
)
121 MmUnmapIoSpace(VidpMemory
, 0x10000);
122 VidpInitialized
= FALSE
;
127 VidVgaTextBufferToScreenBlt(
138 VidVgaTextScreenToBufferBlt(
157 VidVgaTextSolidColorFill(
167 VidpVgaTextScrollDisplay(VOID
)
169 volatile USHORT
*ptr
;
172 RtlMoveMemory(VidpMemory
, (PUSHORT
)VidpMemory
+ SizeX
, SizeX
* (SizeY
- 1) * 2);
174 ptr
= (volatile USHORT
*)VidpMemory
+ (SizeX
* (SizeY
- 1));
175 for (i
= 0; i
< (int)SizeX
; i
++, ptr
++)
176 *ptr
= (CHAR_ATTRIBUTE
<< 8) + ' ';
180 VidVgaTextDisplayString(
190 WRITE_PORT_UCHAR(CRTC
, CRTC_CURHI
);
191 offset
= READ_PORT_UCHAR(CRTCDATA
) << 8;
192 WRITE_PORT_UCHAR(CRTC
, CRTC_CURLO
);
193 offset
+= READ_PORT_UCHAR(CRTCDATA
);
195 CursorY
= offset
/ SizeX
;
196 CursorX
= offset
% SizeX
;
205 else if (*pch
== '\b')
210 else if (*pch
!= '\r')
212 volatile USHORT
*ptr
;
214 ptr
= (volatile USHORT
*)VidpMemory
+ ((CursorY
* SizeX
) + CursorX
);
215 *ptr
= (CHAR_ATTRIBUTE
<< 8) + *pch
;
218 if (CursorX
>= SizeX
)
225 if (CursorY
>= SizeY
)
227 VidpVgaTextScrollDisplay();
234 offset
= (CursorY
* SizeX
) + CursorX
;
235 WRITE_PORT_UCHAR(CRTC
, CRTC_CURLO
);
236 WRITE_PORT_UCHAR(CRTCDATA
, (UCHAR
)(offset
& 0xff));
237 WRITE_PORT_UCHAR(CRTC
, CRTC_CURHI
);
238 WRITE_PORT_UCHAR(CRTCDATA
, (UCHAR
)((offset
>> 8) & 0xff));
241 VID_FUNCTION_TABLE VidVgaTextTable
= {
242 VidVgaTextInitialize
,
244 VidVgaTextResetDisplay
,
245 VidVgaTextBufferToScreenBlt
,
246 VidVgaTextScreenToBufferBlt
,
248 VidVgaTextSolidColorFill
,
249 VidVgaTextDisplayString