ReactOS  0.4.15-dev-1070-ge1a01de
pc98video.c
Go to the documentation of this file.
1 /*
2  * PROJECT: FreeLoader
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Video support for NEC PC-98 series
5  * COPYRIGHT: Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include <freeldr.h>
11 #include <drivers/pc98/video.h>
12 
13 extern UCHAR BitmapFont8x16[];
14 extern BOOLEAN HiResoMachine;
15 
16 /* GLOBALS ********************************************************************/
17 
18 #define VGA_CHAR_SIZE 2
19 
20 #define TEXT_CHAR_SIZE 2
23 
24 #define CHAR_WIDTH 8
25 #define CHAR_HEIGHT 16
26 
27 #define SCREEN_WIDTH 640
28 #define SCREEN_HEIGHT 400
29 #define BYTES_PER_SCANLINE (SCREEN_WIDTH / 8)
30 
36 
37 static const PALETTE_ENTRY CgaPalette[] =
38 {
39  {0x00, 0x00, 0x00},
40  {0x00, 0x00, 0x0A},
41  {0x00, 0x0A, 0x00},
42  {0x00, 0x0A, 0x0A},
43  {0x0A, 0x00, 0x00},
44  {0x0A, 0x00, 0x0A},
45  {0x0A, 0x05, 0x00},
46  {0x0A, 0x0A, 0x0A},
47  {0x05, 0x05, 0x05},
48  {0x05, 0x05, 0x0F},
49  {0x05, 0x0F, 0x05},
50  {0x05, 0x0F, 0x0F},
51  {0x0F, 0x05, 0x05},
52  {0x0F, 0x05, 0x0F},
53  {0x0F, 0x0F, 0x05},
54  {0x0F, 0x0F, 0x0F}
55 };
56 
57 /* FUNCTIONS ******************************************************************/
58 
59 VOID
61 {
62  REGS Regs;
63  USHORT i;
64 
65  if (HiResoMachine)
66  {
72  TextCols = 80;
73  TextLines = 31;
74  }
75  else
76  {
82  TextCols = 80;
83  TextLines = 25;
84  }
85 
86  for (i = 0; i < VRAM_ATTR_SIZE; i += TEXT_CHAR_SIZE)
88 
89  /* Int 18h AH=41h
90  * CRT BIOS - Stop displaying graphics
91  */
92  Regs.b.ah = 0x41;
93  Int386(0x18, &Regs, &Regs);
94 
95  /* Int 18h AH=42h
96  * CRT BIOS - Set display area
97  *
98  * CH0-CH3 - always zero
99  * CH4 - video page
100  * CH5 - CRT display mode
101  * 0 - color
102  * 1 - monochrome
103  * CH6-CH7 - VRAM area
104  * 01 - Upper-half (16-32 kB), 640x200
105  * 10 - Lower-half (0-16 kB), 640x200
106  * 11 - All (0-32 kB), 640x400
107  */
108  Regs.b.ah = 0x42;
109  Regs.b.ch = 0xC0;
110  Int386(0x18, &Regs, &Regs); /* 640x400 */
111 
115 
116  Pc98VideoSync();
117  for (i = 0; i < RTL_NUMBER_OF(CgaPalette); i++)
119 
120  /* Int 18h AH=0Ah
121  * CRT BIOS - Set text screen mode
122  *
123  * AL0 - text rows
124  * 0 - 25
125  * 1 - 20
126  * AL1 - text cols
127  * 0 - 80
128  * 1 - 40
129  * AL2 - text attribute
130  * 0 - with vertical line
131  * 1 - normal
132  * AL3 - KCG access mode
133  * 0 - code
134  * 1 - bitmap
135  * AL4-AL7 - always zero
136  *
137  * High-resolution machine:
138  * AL4 - text rows, AL3 - KCG access mode
139  */
140  Regs.b.ah = 0x0A;
141  Regs.b.al = HiResoMachine ? 0x10 : 0x00;
142  Int386(0x18, &Regs, &Regs); /* 80x25(31) */
143 
144  /* Int 18h AH=0Ch
145  * CRT BIOS - Start displaying text
146  */
147  Regs.b.ah = 0x0C;
148  Int386(0x18, &Regs, &Regs);
149 
150  /* Int 18h AH=40h
151  * CRT BIOS - Start displaying graphics
152  */
153  Regs.b.ah = 0x40;
154  Int386(0x18, &Regs, &Regs);
155 }
156 
157 VOID
159 {
160  USHORT i;
161  USHORT B = (Attr & 0x10) ? 0xFFFF : 0;
162  USHORT G = (Attr & 0x20) ? 0xFFFF : 0;
163  USHORT R = (Attr & 0x40) ? 0xFFFF : 0;
164  USHORT I = (Attr & 0x80) ? 0xFFFF : 0;
165 
166  for (i = 0; i < VRAM_TEXT_SIZE; i += TEXT_CHAR_SIZE)
167  *(PUSHORT)(VramText + i) = ' ';
168 
169  for (i = 0; i < BYTES_PER_SCANLINE * SCREEN_HEIGHT; i += sizeof(USHORT))
170  {
171  *(PUSHORT)(VramPlaneB + i) = B;
172  *(PUSHORT)(VramPlaneG + i) = G;
173  *(PUSHORT)(VramPlaneR + i) = R;
174  *(PUSHORT)(VramPlaneI + i) = I;
175  }
176 }
177 
179 Pc98VideoSetDisplayMode(char *DisplayModeName, BOOLEAN Init)
180 {
181  /* Not supported by hardware */
182  return VideoTextMode;
183 }
184 
185 VOID
187 {
188  *Width = SCREEN_WIDTH / CHAR_WIDTH;
189  *Height = SCREEN_HEIGHT / CHAR_HEIGHT;
190  *Depth = 0;
191 }
192 
193 ULONG
195 {
197 }
198 
199 VOID
201 {
202  *RomFontPointers = VramText + 0x4000;
203 }
204 
205 VOID
207 {
208  CSRWPARAM CursorParameters;
209 
210  RtlZeroMemory(&CursorParameters, sizeof(CSRWPARAM));
211  CursorParameters.CursorAddress = X + Y * TextCols;
212  CursorParameters.DotAddress = 0;
213 
215  WRITE_GDC_CSRW((PUCHAR)GDC1_IO_o_PARAM, &CursorParameters);
216 }
217 
218 VOID
220 {
221  CSRFORMPARAM CursorParameters;
222 
223  RtlZeroMemory(&CursorParameters, sizeof(CSRFORMPARAM));
224  CursorParameters.Show = Show;
225  CursorParameters.Blink = TRUE;
226  CursorParameters.BlinkRate = 12;
227  CursorParameters.LinesPerRow = 16;
228  CursorParameters.StartScanLine = 12;
229  CursorParameters.EndScanLine = 15;
230 
232  WRITE_GDC_CSRFORM((PUCHAR)GDC1_IO_o_PARAM, &CursorParameters);
233 }
234 
235 VOID
236 Pc98VideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
237 {
238  UCHAR Line;
239  UCHAR B = (Attr & 0x10) ? 0xFF : 0;
240  UCHAR G = (Attr & 0x20) ? 0xFF : 0;
241  UCHAR R = (Attr & 0x40) ? 0xFF : 0;
242  UCHAR I = (Attr & 0x80) ? 0xFF : 0;
243  ULONG VramOffset = X + (Y * CHAR_HEIGHT) * BYTES_PER_SCANLINE;
244  PUCHAR FontPtr = BitmapFont8x16 + Ch * 16;
245 
246  for (Line = 0; Line < CHAR_HEIGHT; Line++)
247  {
248  if (Attr & 0x0F)
249  {
250  *(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B | ((Attr & 0x01) ? FontPtr[Line] : 0);
251  *(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G | ((Attr & 0x02) ? FontPtr[Line] : 0);
252  *(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R | ((Attr & 0x04) ? FontPtr[Line] : 0);
253  *(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I | ((Attr & 0x08) ? FontPtr[Line] : 0);
254  }
255  else
256  {
257  *(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B & ~FontPtr[Line];
258  *(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G & ~FontPtr[Line];
259  *(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R & ~FontPtr[Line];
260  *(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I & ~FontPtr[Line];
261  }
262  }
263 }
264 
265 VOID
267 {
268  PUCHAR OffScreenBuffer = (PUCHAR)Buffer;
269  USHORT X, Y;
270 
271  for (Y = 0; Y < SCREEN_HEIGHT / CHAR_HEIGHT; Y++)
272  {
273  for (X = 0; X < SCREEN_WIDTH / CHAR_WIDTH; X++)
274  {
275  Pc98VideoPutChar(OffScreenBuffer[0], OffScreenBuffer[1], X, Y);
276  OffScreenBuffer += VGA_CHAR_SIZE;
277  }
278  }
279 }
280 
281 BOOLEAN
283 {
284  return FALSE;
285 }
286 
287 VOID
289 {
290  if (Color < 16)
291  {
296  }
297 }
298 
299 VOID
301 {
302  if (Color < 16)
303  {
308  }
309  else
310  {
311  *Red = 0;
312  *Green = 0;
313  *Blue = 0;
314  }
315 }
316 
317 VOID
319 {
321  NOTHING;
322 
324  NOTHING;
325 }
326 
327 VOID
329 {
330  REGS Regs;
331 
332  /* Int 18h AH=41h
333  * CRT BIOS - Stop displaying graphics
334  */
335  Regs.b.ah = 0x41;
336  Int386(0x18, &Regs, &Regs);
337 
339 }
VOID Pc98VideoCopyOffScreenBufferToVRAM(PVOID Buffer)
Definition: pc98video.c:266
#define GDC_COMMAND_CSRFORM
Definition: video.h:173
#define G(r, i, a, b, c, d)
Definition: blake2b-ref.c:117
VOID Pc98VideoSync(VOID)
Definition: pc98video.c:318
UCHAR TextCols
Definition: pc98video.c:21
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:814
#define R(b, x)
Definition: sha2.c:134
VOID Pc98VideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth)
Definition: pc98video.c:186
#define GDC2_IO_o_RED
Definition: video.h:277
#define VRAM_HI_RESO_PLANE_G
Definition: video.h:29
#define Y(I)
#define VRAM_NORMAL_PLANE_G
Definition: video.h:13
UCHAR StartScanLine
Definition: video.h:180
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:21
#define VRAM_ATTR_SIZE
Definition: video.h:20
#define GDC2_IO_i_BLUE
Definition: video.h:267
#define TRUE
Definition: types.h:120
static ULONG VramPlaneB
Definition: pc98video.c:32
#define GDC2_IO_o_BLUE
Definition: video.h:278
#define VRAM_HI_RESO_TEXT
Definition: video.h:32
unsigned char * PUCHAR
Definition: retypes.h:3
BOOLEAN Pc98VideoIsPaletteFixed(VOID)
Definition: pc98video.c:282
UCHAR BitmapFont8x16[]
Definition: vgafont.c:12
#define SCREEN_WIDTH
Definition: pc98video.c:27
static ULONG VramPlaneR
Definition: pc98video.c:34
unsigned char ah
Definition: pcbios.h:126
VOID Pc98VideoSetTextCursorPosition(UCHAR X, UCHAR Y)
Definition: pc98video.c:206
VOID Pc98VideoInit(VOID)
Definition: pc98video.c:60
Definition: bl.h:199
#define GDC2_IO_o_VIDEO_PAGE_ACCESS
Definition: video.h:274
#define Ch(x, y, z)
Definition: sha2.c:141
#define GDC2_IO_o_VIDEO_PAGE
Definition: video.h:273
VOID Pc98VideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue)
Definition: pc98video.c:288
#define VRAM_NORMAL_PLANE_R
Definition: video.h:14
#define GDC2_IO_o_MODE_FLIPFLOP2
Definition: video.h:280
int __cdecl Int386(int ivec, REGS *in, REGS *out)
#define TEXT_CHAR_SIZE
Definition: pc98video.c:20
ULONG VramText
Definition: pc98video.c:31
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
VOID Pc98VideoHideShowTextCursor(BOOLEAN Show)
Definition: pc98video.c:219
#define VRAM_TEXT_ATTR_OFFSET
Definition: video.h:18
#define FALSE
Definition: types.h:117
VOID Pc98VideoGetFontsFromFirmware(PULONG RomFontPointers)
Definition: pc98video.c:200
#define VRAM_HI_RESO_PLANE_B
Definition: video.h:28
FORCEINLINE VOID WRITE_GDC_CSRFORM(PUCHAR Port, PCSRFORMPARAM CursorParameters)
Definition: video.h:186
VOID Pc98VideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
Definition: pc98video.c:236
#define CHAR_HEIGHT
Definition: pc98video.c:25
unsigned char BOOLEAN
Definition: video.h:11
Definition: bufpool.h:45
UCHAR EndScanLine
Definition: video.h:181
VOID Pc98VideoGetPaletteColor(UCHAR Color, UCHAR *Red, UCHAR *Green, UCHAR *Blue)
Definition: pc98video.c:300
#define BYTES_PER_SCANLINE
Definition: pc98video.c:29
#define GDC2_IO_i_RED
Definition: video.h:266
#define SCREEN_HEIGHT
Definition: pc98video.c:28
#define VGA_CHAR_SIZE
Definition: pc98video.c:18
ULONG CursorAddress
Definition: video.h:154
#define VRAM_TEXT_SIZE
Definition: video.h:19
#define VRAM_NORMAL_PLANE_I
Definition: video.h:15
unsigned char ch
Definition: pcbios.h:132
Definition: ncftp.h:79
#define GDC2_IO_o_PALETTE_INDEX
Definition: video.h:275
BOOLEAN HiResoMachine
Definition: machpc98.c:17
Definition: bl.h:200
unsigned char UCHAR
Definition: xmlstorage.h:181
#define VRAM_NORMAL_PLANE_B
Definition: video.h:12
BYTEREGS b
Definition: pcbios.h:157
#define GDC2_IO_o_GREEN
Definition: video.h:276
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:20
enum tagVIDEODISPLAYMODE VIDEODISPLAYMODE
#define I(s)
#define VRAM_NORMAL_TEXT
Definition: video.h:17
#define GDC_ATTR_WHITE
Definition: video.h:58
#define NOTHING
Definition: env_spec_w32.h:461
unsigned char al
Definition: pcbios.h:125
static ULONG VramPlaneI
Definition: pc98video.c:35
#define GDC_COMMAND_CSRW
Definition: video.h:151
BOOLEAN Show
Definition: video.h:176
FORCEINLINE VOID WRITE_GDC_CSRW(PUCHAR Port, PCSRWPARAM CursorParameters)
Definition: video.h:160
#define RomFontPointers
Definition: winldr.c:422
#define CHAR_WIDTH
Definition: pc98video.c:24
#define VRAM_HI_RESO_PLANE_I
Definition: video.h:31
#define VRAM_HI_RESO_PLANE_R
Definition: video.h:30
unsigned short USHORT
Definition: pedump.c:61
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define GDC_STATUS_VSYNC
Definition: video.h:41
unsigned int * PULONG
Definition: retypes.h:1
#define B(row, col)
VOID Pc98VideoPrepareForReactOS(VOID)
Definition: pc98video.c:328
#define GDC2_IO_i_GREEN
Definition: video.h:265
UCHAR DotAddress
Definition: video.h:155
unsigned int ULONG
Definition: retypes.h:1
ULONG Pc98VideoGetBufferSize(VOID)
Definition: pc98video.c:194
Definition: pcbios.h:152
UCHAR BlinkRate
Definition: video.h:178
BOOLEAN Blink
Definition: video.h:177
#define GDC1_IO_o_PARAM
Definition: video.h:234
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
VIDEODISPLAYMODE Pc98VideoSetDisplayMode(char *DisplayModeName, BOOLEAN Init)
Definition: pc98video.c:179
static const PALETTE_ENTRY CgaPalette[]
Definition: pc98video.c:37
#define GDC_ATTR_VISIBLE
Definition: video.h:45
#define GDC1_IO_o_COMMAND
Definition: video.h:235
static ULONG VramPlaneG
Definition: pc98video.c:33
unsigned short * PUSHORT
Definition: retypes.h:2
struct Line Line
UCHAR TextLines
Definition: pc98video.c:22
#define X(b, s)
#define GDC2_IO_i_STATUS
Definition: video.h:260
UCHAR LinesPerRow
Definition: video.h:179
#define GDC2_MODE_COLORS_16
Definition: video.h:282
VOID Pc98VideoClearScreen(UCHAR Attr)
Definition: pc98video.c:158