ReactOS 0.4.15-dev-8127-g6338913
hardware.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS framebuffer driver for NEC PC-98 series
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Hardware support code
5 * COPYRIGHT: Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include "pc98vid.h"
11
12/* GLOBALS ********************************************************************/
13
14#define PEGC_MAX_COLORS 256
15
16/* FUNCTIONS ******************************************************************/
17
18static BOOLEAN
21{
23
26
27 return (Result & GRAPH_STATUS_SET) && (Result != 0xFF);
28}
29
30static BOOLEAN
32 _In_ PHW_DEVICE_EXTENSION DeviceExtension)
33{
34 USHORT OldValue, NewValue;
35
36 OldValue = VideoPortReadRegisterUshort((PUSHORT)(DeviceExtension->PegcControlVa +
38
39 /* Bits [15:1] are not writable */
40 VideoPortWriteRegisterUshort((PUSHORT)(DeviceExtension->PegcControlVa +
41 PEGC_MMIO_MODE), 0x80);
42 NewValue = VideoPortReadRegisterUshort((PUSHORT)(DeviceExtension->PegcControlVa +
44
45 VideoPortWriteRegisterUshort((PUSHORT)(DeviceExtension->PegcControlVa +
46 PEGC_MMIO_MODE), OldValue);
47
48 return !(NewValue & 0x80);
49}
50
51static VOID
53{
55 NOTHING;
56
58 NOTHING;
59}
60
64 _In_ PHW_DEVICE_EXTENSION DeviceExtension)
65{
67
69 return TestMmio(DeviceExtension);
70
76
77 return Success;
78}
79
80CODE_SEG("PAGE")
84 _In_ PHW_DEVICE_EXTENSION DeviceExtension,
85 _In_ PVIDEO_MODE RequestedMode)
86{
87 SYNCPARAM SyncParameters;
88 CSRFORMPARAM CursorParameters;
90 PITCHPARAM PitchParameters;
91 PRAMPARAM RamParameters;
92 ZOOMPARAM ZoomParameters;
93 UCHAR RelayState;
94
95 PAGED_CODE();
96
97 VideoDebugPrint((Trace, "%s() Mode %d\n",
98 __FUNCTION__, RequestedMode->RequestedMode));
99
100 if (RequestedMode->RequestedMode > DeviceExtension->ModeCount)
102
103 /* Blank screen */
105
106 /* RESET, without FIFO check */
109
110 /* Configure chipset */
118 VideoModes[RequestedMode->RequestedMode].Clock1);
120 VideoModes[RequestedMode->RequestedMode].Clock2);
122 VideoModes[RequestedMode->RequestedMode].HorizontalScanRate);
125
126 /* =========================== MASTER ============================ */
127
128 /* MASTER */
130
131 /* SYNC */
132 SyncParameters = VideoModes[RequestedMode->RequestedMode].TextSyncParameters;
136 WRITE_GDC_SYNC((PUCHAR)GDC1_IO_o_PARAM, &SyncParameters);
137
138 /* CSRFORM */
139 CursorParameters.Show = FALSE;
140 CursorParameters.Blink = FALSE;
141 CursorParameters.BlinkRate = 12;
142 CursorParameters.LinesPerRow = 16;
143 CursorParameters.StartScanLine = 0;
144 CursorParameters.EndScanLine = 15;
146 WRITE_GDC_CSRFORM((PUCHAR)GDC1_IO_o_PARAM, &CursorParameters);
147
148 /* PITCH */
149 PitchParameters.WordsPerScanline = 80;
151 WRITE_GDC_PITCH((PUCHAR)GDC1_IO_o_PARAM, &PitchParameters);
152
153 /* PRAM */
154 RamParameters.StartingAddress = 0;
155 RamParameters.Length = 1023;
156 RamParameters.ImageBit = FALSE;
157 RamParameters.WideDisplay = FALSE;
159 WRITE_GDC_PRAM((PUCHAR)GDC1_IO_o_PARAM, &RamParameters);
160
161 /* ZOOM */
162 ZoomParameters.DisplayZoomFactor = 0;
163 ZoomParameters.WritingZoomFactor = 0;
165 WRITE_GDC_ZOOM((PUCHAR)GDC1_IO_o_PARAM, &ZoomParameters);
166
167 /* CSRW */
168 CursorPosition.CursorAddress = 0;
169 CursorPosition.DotAddress = 0;
172
173 /* START */
175
176 /* ============================ SLAVE ============================ */
177
178 /* SLAVE */
180
181 /* SYNC */
182 SyncParameters = VideoModes[RequestedMode->RequestedMode].VideoSyncParameters;
187 WRITE_GDC_SYNC((PUCHAR)GDC2_IO_o_PARAM, &SyncParameters);
188
189 /* CSRFORM */
190 CursorParameters.Show = FALSE;
191 CursorParameters.Blink = FALSE;
192 CursorParameters.BlinkRate = 0;
193 CursorParameters.LinesPerRow = 1;
194 CursorParameters.StartScanLine = 0;
195 CursorParameters.EndScanLine = 0;
197 WRITE_GDC_CSRFORM((PUCHAR)GDC2_IO_o_PARAM, &CursorParameters);
198
199 /* PITCH */
200 PitchParameters.WordsPerScanline = 80;
202 WRITE_GDC_PITCH((PUCHAR)GDC2_IO_o_PARAM, &PitchParameters);
203
204 /* PRAM */
205 RamParameters.StartingAddress = 0;
206 RamParameters.Length = 1023;
207 RamParameters.ImageBit = TRUE;
208 RamParameters.WideDisplay = FALSE;
210 WRITE_GDC_PRAM((PUCHAR)GDC2_IO_o_PARAM, &RamParameters);
211
212 /* ZOOM */
213 ZoomParameters.DisplayZoomFactor = 0;
214 ZoomParameters.WritingZoomFactor = 0;
216 WRITE_GDC_ZOOM((PUCHAR)GDC2_IO_o_PARAM, &ZoomParameters);
217
218 /* CSRW */
219 CursorPosition.CursorAddress = 0;
220 CursorPosition.DotAddress = 0;
223
224 /* Synchronize the master sync source */
225 TextSync();
226 TextSync();
227 TextSync();
228 TextSync();
229
230 /* START */
232
233 /* 256 colors, packed pixel */
237 VideoModes[RequestedMode->RequestedMode].Mem);
239 VideoPortWriteRegisterUshort((PUSHORT)(DeviceExtension->PegcControlVa +
241 VideoPortWriteRegisterUshort((PUSHORT)(DeviceExtension->PegcControlVa +
243
244 /* Select the video source */
249
250 /* Unblank screen */
252
253 DeviceExtension->CurrentMode = RequestedMode->RequestedMode;
254
255 return NO_ERROR;
256}
257
258CODE_SEG("PAGE")
262 _In_ PVIDEO_CLUT ColorLookUpTable)
263{
265
266 PAGED_CODE();
267
268 VideoDebugPrint((Trace, "%s()\n", __FUNCTION__));
269
270 if (ColorLookUpTable->NumEntries > PEGC_MAX_COLORS)
272
273 for (Entry = ColorLookUpTable->FirstEntry;
274 Entry < ColorLookUpTable->FirstEntry + ColorLookUpTable->NumEntries;
275 ++Entry)
276 {
279 ColorLookUpTable->LookupTable[Entry].RgbArray.Red);
281 ColorLookUpTable->LookupTable[Entry].RgbArray.Green);
283 ColorLookUpTable->LookupTable[Entry].RgbArray.Blue);
284 }
285
286 return NO_ERROR;
287}
288
289CODE_SEG("PAGE")
291NTAPI
293 _In_ PVOID HwDeviceExtension,
294 _In_ ULONG HwId,
295 _In_ PVIDEO_POWER_MANAGEMENT VideoPowerControl)
296{
297 PAGED_CODE();
298
299 VideoDebugPrint((Trace, "%s() Id %lX, State %x\n",
300 __FUNCTION__, HwId, VideoPowerControl->PowerState));
301
302 if (HwId == MONITOR_HW_ID || HwId == DISPLAY_ADAPTER_HW_ID)
303 {
304 switch (VideoPowerControl->PowerState)
305 {
306 case VideoPowerOn:
309 case VideoPowerOff:
311 return NO_ERROR;
312 }
313 }
314
316}
317
318CODE_SEG("PAGE")
320NTAPI
322 _In_ PVOID HwDeviceExtension,
323 _In_ ULONG HwId,
324 _In_ PVIDEO_POWER_MANAGEMENT VideoPowerControl)
325{
326 UCHAR Dpms;
327
328 PAGED_CODE();
329
330 VideoDebugPrint((Trace, "%s() Id %lX, State %x\n",
331 __FUNCTION__, HwId, VideoPowerControl->PowerState));
332
333 if (HwId == MONITOR_HW_ID)
334 {
336
337 switch (VideoPowerControl->PowerState)
338 {
339 case VideoPowerOn:
340 /* Turn on HS/VS signals */
343
344 /* Unblank screen */
347 break;
348
350 /* Disable HS signal */
353 break;
354
356 /* Disable VS signal */
359 break;
360
361 case VideoPowerOff:
363 /* Turn off HS/VS signals */
366
367 /* Blank screen */
370 break;
371 }
372 }
373
374 return NO_ERROR;
375}
#define PAGED_CODE()
#define CODE_SEG(...)
unsigned char BOOLEAN
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_DEVICE_REINITIALIZATION_NEEDED
Definition: dderror.h:16
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define Trace(x)
Definition: inflate.c:42
#define __FUNCTION__
Definition: types.h:116
@ Success
Definition: eventcreate.c:712
Status
Definition: gdiplustypes.h:25
#define NOTHING
Definition: input_list.c:10
#define _In_
Definition: ms_sal.h:308
#define FASTCALL
Definition: nt_native.h:50
@ VideoPowerOn
Definition: ntddvdeo.h:403
@ VideoPowerSuspend
Definition: ntddvdeo.h:405
@ VideoPowerOff
Definition: ntddvdeo.h:406
@ VideoPowerShutdown
Definition: ntddvdeo.h:408
@ VideoPowerStandBy
Definition: ntddvdeo.h:404
static USHORT CursorPosition
Definition: pc98cons.c:20
#define MONITOR_HW_ID
Definition: pc98vid.h:29
unsigned short USHORT
Definition: pedump.c:61
VPAPI USHORT NTAPI VideoPortReadRegisterUshort(IN PUSHORT Register)
VPAPI VOID NTAPI VideoPortWriteRegisterUshort(IN PUSHORT Register, IN USHORT Value)
LONG VP_STATUS
Definition: video.h:153
VPAPI UCHAR NTAPI VideoPortReadPortUchar(IN PUCHAR Port)
#define DISPLAY_ADAPTER_HW_ID
Definition: video.h:115
VPAPI VOID NTAPI VideoPortWritePortUchar(IN PUCHAR Port, IN UCHAR Value)
#define VideoDebugPrint(x)
Definition: video.h:75
#define GDC_COMMAND_PITCH
Definition: video.h:138
#define GDC2_IO_o_RED
Definition: video.h:277
#define PEGC_MODE_PACKED
Definition: video.h:421
#define GDC1_IO_o_MODE_FLIPFLOP1
Definition: video.h:238
#define GDC2_IO_o_MODE_FLIPFLOP2
Definition: video.h:280
#define GDC1_IO_i_STATUS
Definition: video.h:230
#define GDC_COMMAND_MASTER
Definition: video.h:200
#define GRAPH_IO_i_STATUS
Definition: video.h:346
#define GDC2_EGC_FF_PROTECT
Definition: video.h:285
#define SYNC_VIDEO_FRAMING_NONINTERLACED
Definition: video.h:83
#define GRAPH_STATUS_PEGC
Definition: video.h:352
FORCEINLINE VOID WRITE_GDC_CSRFORM(PUCHAR Port, PCSRFORMPARAM CursorParameters)
Definition: video.h:186
#define GDC2_IO_o_COMMAND
Definition: video.h:272
#define GRAPH_MODE_DISPLAY_ENABLE
Definition: video.h:254
#define SYNC_DISPLAY_MODE_GRAPHICS
Definition: video.h:80
#define GDC2_MODE_ODD_RLINE_SHOW
Definition: video.h:247
#define PEGC_MMIO_MODE
Definition: video.h:420
#define GDC2_MODE_LINES_400
Definition: video.h:301
#define GDC_COMMAND_BCTRL_START
Definition: video.h:73
#define GDC2_IO_o_VIDEO_PAGE_ACCESS
Definition: video.h:274
#define GDC_STATUS_VSYNC
Definition: video.h:41
#define GDC2_MODE_LCD
Definition: video.h:298
#define GRAPH_IO_o_STATUS_SELECT
Definition: video.h:350
#define GDC1_IO_o_COMMAND
Definition: video.h:235
#define PEGC_FB_MAP
Definition: video.h:426
#define PEGC_MMIO_FRAMEBUFFER
Definition: video.h:424
#define GRAPH_VID_SRC_INTERNAL
Definition: video.h:370
#define GRAPH_DPMS_HSYNC_MASK
Definition: video.h:356
FORCEINLINE VOID WRITE_GDC_CSRW(PUCHAR Port, PCSRWPARAM CursorParameters)
Definition: video.h:160
#define GDC2_MODE_GRCG
Definition: video.h:283
#define GDC2_IO_o_GREEN
Definition: video.h:276
#define GDC2_IO_o_VIDEO_PAGE
Definition: video.h:273
#define GRAPH_IO_i_RELAY
Definition: video.h:364
#define GRAPH_IO_o_RELAY
Definition: video.h:368
#define GRAPH_IO_o_DPMS
Definition: video.h:355
#define GDC_COMMAND_SLAVE
Definition: video.h:199
FORCEINLINE VOID WRITE_GDC_ZOOM(PUCHAR Port, PZOOMPARAM ZoomParameters)
Definition: video.h:133
#define GDC2_IO_o_PALETTE_INDEX
Definition: video.h:275
#define GDC2_MODE_COLORS_16
Definition: video.h:282
#define GDC_COMMAND_PRAM
Definition: video.h:202
#define GRAPH_SRC_GDC
Definition: video.h:373
FORCEINLINE VOID WRITE_GDC2_COMMAND(UCHAR Command)
Definition: video.h:336
FORCEINLINE VOID WRITE_GDC_PITCH(PUCHAR Port, PPITCHPARAM PitchParameters)
Definition: video.h:146
FORCEINLINE VOID WRITE_GDC_PRAM(PUCHAR Port, PPRAMPARAM RamParameters)
Definition: video.h:213
#define GRAPH_MODE_COLORED
Definition: video.h:241
#define SYNC_DRAW_ONLY_DURING_RETRACE_BLANKING
Definition: video.h:88
#define GDC_COMMAND_ZOOM
Definition: video.h:124
#define GDC2_EGC_FF_UNPROTECT
Definition: video.h:286
#define GRAPH_STATUS_SET
Definition: video.h:347
#define SYNC_STATIC_RAM_NO_REFRESH
Definition: video.h:90
#define GRAPH_IO_o_HORIZONTAL_SCAN_RATE
Definition: video.h:360
#define GDC_COMMAND_RESET1
Definition: video.h:68
#define SYNC_DISPLAY_MODE_GRAPHICS_AND_CHARACTERS
Definition: video.h:79
#define GDC1_IO_o_PARAM
Definition: video.h:234
#define GRAPH_MODE_DISPLAY_DISABLE
Definition: video.h:253
#define GRAPH_DPMS_VSYNC_MASK
Definition: video.h:357
#define GDC_COMMAND_CSRW
Definition: video.h:151
#define SYNC_DRAW_DURING_ACTIVE_DISPLAY_TIME_AND_RETRACE_BLANKING
Definition: video.h:87
FORCEINLINE VOID WRITE_GDC1_COMMAND(UCHAR Command)
Definition: video.h:326
#define GRAPH_RELAY_1
Definition: video.h:366
#define GDC2_IO_o_BLUE
Definition: video.h:278
#define GRAPH_IO_i_DPMS
Definition: video.h:354
#define GDC2_MODE_PEGC_ENABLE
Definition: video.h:288
#define GDC2_IO_o_PARAM
Definition: video.h:271
FORCEINLINE VOID WRITE_GDC_SYNC(PUCHAR Port, PSYNCPARAM SyncParameters)
Definition: video.h:105
#define GDC_COMMAND_SYNC_ON
Definition: video.h:75
#define GRAPH_RELAY_0
Definition: video.h:365
#define GDC_COMMAND_CSRFORM
Definition: video.h:173
#define GDC2_MODE_PEGC_DISABLE
Definition: video.h:287
base of all file and directory entries
Definition: entries.h:83
UCHAR StartScanLine
Definition: video.h:180
UCHAR LinesPerRow
Definition: video.h:179
BOOLEAN Show
Definition: video.h:176
UCHAR EndScanLine
Definition: video.h:181
BOOLEAN Blink
Definition: video.h:177
UCHAR BlinkRate
Definition: video.h:178
ULONG WordsPerScanline
Definition: video.h:141
ULONG StartingAddress
Definition: video.h:205
USHORT Length
Definition: video.h:206
BOOLEAN ImageBit
Definition: video.h:207
BOOLEAN WideDisplay
Definition: video.h:208
UCHAR Flags
Definition: video.h:78
UCHAR WritingZoomFactor
Definition: video.h:128
UCHAR DisplayZoomFactor
Definition: video.h:127
#define NTAPI
Definition: typedefs.h:36
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
static CONST VGA_MODE VideoModes[BIOS_MAX_VIDEO_MODE+1]
Definition: vidbios.c:1941
VP_STATUS FASTCALL Pc98VidSetColorRegisters(_In_ PVIDEO_CLUT ColorLookUpTable)
Definition: hardware.c:261
VP_STATUS FASTCALL Pc98VidSetCurrentMode(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_MODE RequestedMode)
Definition: hardware.c:83
BOOLEAN NTAPI HasPegcController(_In_ PHW_DEVICE_EXTENSION DeviceExtension)
Definition: hardware.c:63
VP_STATUS NTAPI Pc98VidGetPowerState(_In_ PVOID HwDeviceExtension, _In_ ULONG HwId, _In_ PVIDEO_POWER_MANAGEMENT VideoPowerControl)
Definition: hardware.c:292
VP_STATUS NTAPI Pc98VidSetPowerState(_In_ PVOID HwDeviceExtension, _In_ ULONG HwId, _In_ PVIDEO_POWER_MANAGEMENT VideoPowerControl)
Definition: hardware.c:321
static VOID TextSync(VOID)
Definition: hardware.c:52
#define PEGC_MAX_COLORS
Definition: hardware.c:14
static BOOLEAN TestMmio(_In_ PHW_DEVICE_EXTENSION DeviceExtension)
Definition: hardware.c:31
static BOOLEAN GraphGetStatus(_In_ UCHAR Status)
Definition: hardware.c:19
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
unsigned char UCHAR
Definition: xmlstorage.h:181