ReactOS  0.4.15-dev-3303-g1ade494
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 
18 static BOOLEAN
21 {
22  UCHAR Result;
23 
26 
27  return (Result & GRAPH_STATUS_SET) && (Result != 0xFF);
28 }
29 
30 static 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 
51 static VOID
53 {
55  NOTHING;
56 
58  NOTHING;
59 }
60 
61 BOOLEAN
62 NTAPI
64  _In_ PHW_DEVICE_EXTENSION DeviceExtension)
65 {
67 
69  return TestMmio(DeviceExtension);
70 
73  Success = GraphGetStatus(GRAPH_STATUS_PEGC) ? TestMmio(DeviceExtension) : FALSE;
76 
77  return Success;
78 }
79 
80 CODE_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 */
247  RelayState |= GRAPH_VID_SRC_INTERNAL | GRAPH_SRC_GDC;
249 
250  /* Unblank screen */
252 
253  DeviceExtension->CurrentMode = RequestedMode->RequestedMode;
254 
255  return NO_ERROR;
256 }
257 
258 CODE_SEG("PAGE")
259 VP_STATUS
260 FASTCALL
262  _In_ PVIDEO_CLUT ColorLookUpTable)
263 {
264  USHORT Entry;
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 
289 CODE_SEG("PAGE")
290 VP_STATUS
291 NTAPI
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:
307  case VideoPowerStandBy:
308  case VideoPowerSuspend:
309  case VideoPowerOff:
310  case VideoPowerShutdown:
311  return NO_ERROR;
312  }
313  }
314 
316 }
317 
318 CODE_SEG("PAGE")
319 VP_STATUS
320 NTAPI
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 
349  case VideoPowerStandBy:
350  /* Disable HS signal */
351  Dpms = (Dpms | GRAPH_DPMS_HSYNC_MASK) & ~GRAPH_DPMS_VSYNC_MASK;
353  break;
354 
355  case VideoPowerSuspend:
356  /* Disable VS signal */
357  Dpms = (Dpms | GRAPH_DPMS_VSYNC_MASK) & ~GRAPH_DPMS_HSYNC_MASK;
359  break;
360 
361  case VideoPowerOff:
362  case VideoPowerShutdown:
363  /* Turn off HS/VS signals */
366 
367  /* Blank screen */
370  break;
371  }
372  }
373 
374  return NO_ERROR;
375 }
#define GRAPH_RELAY_0
Definition: video.h:365
#define GDC_COMMAND_CSRFORM
Definition: video.h:173
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define PEGC_FB_MAP
Definition: video.h:426
#define DISPLAY_ADAPTER_HW_ID
Definition: video.h:115
#define GDC2_MODE_LINES_400
Definition: video.h:301
#define GDC2_IO_o_RED
Definition: video.h:277
#define GRAPH_MODE_DISPLAY_DISABLE
Definition: video.h:253
#define GRAPH_VID_SRC_INTERNAL
Definition: video.h:370
BOOLEAN ImageBit
Definition: video.h:207
struct _Entry Entry
Definition: kefuncs.h:627
USHORT Length
Definition: video.h:206
#define GRAPH_IO_o_DPMS
Definition: video.h:355
ULONG StartingAddress
Definition: video.h:205
UCHAR StartScanLine
Definition: video.h:180
#define TRUE
Definition: types.h:120
#define MONITOR_HW_ID
Definition: pc98vid.h:29
#define GDC1_IO_o_MODE_FLIPFLOP1
Definition: video.h:238
#define GDC2_IO_o_BLUE
Definition: video.h:278
#define GDC_COMMAND_MASTER
Definition: video.h:200
unsigned char * PUCHAR
Definition: retypes.h:3
BOOLEAN NTAPI HasPegcController(_In_ PHW_DEVICE_EXTENSION DeviceExtension)
Definition: hardware.c:63
#define GRAPH_SRC_GDC
Definition: video.h:373
#define PEGC_MAX_COLORS
Definition: hardware.c:14
#define GRAPH_IO_i_RELAY
Definition: video.h:364
#define GRAPH_STATUS_PEGC
Definition: video.h:352
#define GDC2_IO_o_VIDEO_PAGE_ACCESS
Definition: video.h:274
#define GDC2_IO_o_VIDEO_PAGE
Definition: video.h:273
#define GRAPH_DPMS_HSYNC_MASK
Definition: video.h:356
#define NO_ERROR
Definition: dderror.h:5
#define FASTCALL
Definition: nt_native.h:50
VP_STATUS FASTCALL Pc98VidSetColorRegisters(_In_ PVIDEO_CLUT ColorLookUpTable)
Definition: hardware.c:261
#define GDC_COMMAND_BCTRL_START
Definition: video.h:73
FORCEINLINE VOID WRITE_GDC1_COMMAND(UCHAR Command)
Definition: video.h:326
#define GDC2_IO_o_MODE_FLIPFLOP2
Definition: video.h:280
FORCEINLINE VOID WRITE_GDC_ZOOM(PUCHAR Port, PZOOMPARAM ZoomParameters)
Definition: video.h:133
#define GDC2_MODE_LCD
Definition: video.h:298
#define SYNC_DRAW_DURING_ACTIVE_DISPLAY_TIME_AND_RETRACE_BLANKING
Definition: video.h:87
BOOLEAN WideDisplay
Definition: video.h:208
VPAPI UCHAR NTAPI VideoPortReadPortUchar(IN PUCHAR Port)
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define GDC2_EGC_FF_PROTECT
Definition: video.h:285
static VOID TextSync(VOID)
Definition: hardware.c:52
#define FALSE
Definition: types.h:117
FORCEINLINE VOID WRITE_GDC_PITCH(PUCHAR Port, PPITCHPARAM PitchParameters)
Definition: video.h:146
#define ERROR_DEVICE_REINITIALIZATION_NEEDED
Definition: dderror.h:16
UCHAR WritingZoomFactor
Definition: video.h:128
VP_STATUS NTAPI Pc98VidSetPowerState(_In_ PVOID HwDeviceExtension, _In_ ULONG HwId, _In_ PVIDEO_POWER_MANAGEMENT VideoPowerControl)
Definition: hardware.c:321
#define GDC_COMMAND_PITCH
Definition: video.h:138
FORCEINLINE VOID WRITE_GDC_CSRFORM(PUCHAR Port, PCSRFORMPARAM CursorParameters)
Definition: video.h:186
VP_STATUS FASTCALL Pc98VidSetCurrentMode(_In_ PHW_DEVICE_EXTENSION DeviceExtension, _In_ PVIDEO_MODE RequestedMode)
Definition: hardware.c:83
#define GRAPH_STATUS_SET
Definition: video.h:347
unsigned char BOOLEAN
_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:426
#define _In_
Definition: ms_sal.h:308
#define GDC2_MODE_GRCG
Definition: video.h:283
UCHAR DisplayZoomFactor
Definition: video.h:127
UCHAR EndScanLine
Definition: video.h:181
#define SYNC_DISPLAY_MODE_GRAPHICS_AND_CHARACTERS
Definition: video.h:79
#define GRAPH_IO_o_STATUS_SELECT
Definition: video.h:350
static CONST VGA_MODE VideoModes[BIOS_MAX_VIDEO_MODE+1]
Definition: vidbios.c:1941
Status
Definition: gdiplustypes.h:24
FORCEINLINE VOID WRITE_GDC2_COMMAND(UCHAR Command)
Definition: video.h:336
#define GRAPH_DPMS_VSYNC_MASK
Definition: video.h:357
#define GDC1_IO_i_STATUS
Definition: video.h:230
VP_STATUS NTAPI Pc98VidGetPowerState(_In_ PVOID HwDeviceExtension, _In_ ULONG HwId, _In_ PVIDEO_POWER_MANAGEMENT VideoPowerControl)
Definition: hardware.c:292
#define PEGC_MMIO_MODE
Definition: video.h:420
#define SYNC_DISPLAY_MODE_GRAPHICS
Definition: video.h:80
#define GDC_COMMAND_RESET1
Definition: video.h:68
#define GDC2_IO_o_PALETTE_INDEX
Definition: video.h:275
unsigned char UCHAR
Definition: xmlstorage.h:181
#define GDC2_IO_o_COMMAND
Definition: video.h:272
#define GDC_COMMAND_SLAVE
Definition: video.h:199
VPAPI VOID NTAPI VideoPortWriteRegisterUshort(IN PUSHORT Register, IN USHORT Value)
#define GDC2_EGC_FF_UNPROTECT
Definition: video.h:286
#define GRAPH_MODE_COLORED
Definition: video.h:241
#define GDC2_IO_o_GREEN
Definition: video.h:276
#define GRAPH_IO_i_DPMS
Definition: video.h:354
FORCEINLINE VOID WRITE_GDC_SYNC(PUCHAR Port, PSYNCPARAM SyncParameters)
Definition: video.h:105
#define PEGC_MMIO_FRAMEBUFFER
Definition: video.h:424
#define Trace(x)
Definition: inflate.c:42
#define NOTHING
Definition: env_spec_w32.h:461
#define GDC2_MODE_PEGC_ENABLE
Definition: video.h:288
#define GRAPH_IO_i_STATUS
Definition: video.h:346
#define SYNC_DRAW_ONLY_DURING_RETRACE_BLANKING
Definition: video.h:88
UCHAR Flags
Definition: video.h:78
#define GDC_COMMAND_SYNC_ON
Definition: video.h:75
VPAPI USHORT NTAPI VideoPortReadRegisterUshort(IN PUSHORT Register)
#define GRAPH_IO_o_HORIZONTAL_SCAN_RATE
Definition: video.h:360
#define GDC_COMMAND_CSRW
Definition: video.h:151
#define SYNC_VIDEO_FRAMING_NONINTERLACED
Definition: video.h:83
BOOLEAN Show
Definition: video.h:176
FORCEINLINE VOID WRITE_GDC_CSRW(PUCHAR Port, PCSRWPARAM CursorParameters)
Definition: video.h:160
#define VideoDebugPrint(x)
Definition: video.h:75
ULONG WordsPerScanline
Definition: video.h:141
#define GDC2_MODE_PEGC_DISABLE
Definition: video.h:287
unsigned short USHORT
Definition: pedump.c:61
#define GDC_STATUS_VSYNC
Definition: video.h:41
#define PEGC_MODE_PACKED
Definition: video.h:421
unsigned int ULONG
Definition: retypes.h:1
UCHAR BlinkRate
Definition: video.h:178
BOOLEAN Blink
Definition: video.h:177
#define GDC1_IO_o_PARAM
Definition: video.h:234
#define GRAPH_RELAY_1
Definition: video.h:366
FORCEINLINE VOID WRITE_GDC_PRAM(PUCHAR Port, PPRAMPARAM RamParameters)
Definition: video.h:213
static BOOLEAN TestMmio(_In_ PHW_DEVICE_EXTENSION DeviceExtension)
Definition: hardware.c:31
LONG VP_STATUS
Definition: video.h:153
#define GDC_COMMAND_PRAM
Definition: video.h:202
static BOOLEAN GraphGetStatus(_In_ UCHAR Status)
Definition: hardware.c:19
#define SYNC_STATIC_RAM_NO_REFRESH
Definition: video.h:90
#define GDC2_IO_o_PARAM
Definition: video.h:271
#define __FUNCTION__
Definition: types.h:112
VPAPI VOID NTAPI VideoPortWritePortUchar(IN PUCHAR Port, IN UCHAR Value)
static USHORT CursorPosition
Definition: pc98cons.c:20
static CODE_SEG("PAGE")
Definition: isapnp.c:1482
#define GDC1_IO_o_COMMAND
Definition: video.h:235
unsigned short * PUSHORT
Definition: retypes.h:2
base of all file and directory entries
Definition: entries.h:82
#define GDC_COMMAND_ZOOM
Definition: video.h:124
#define GRAPH_MODE_DISPLAY_ENABLE
Definition: video.h:254
#define GRAPH_IO_o_RELAY
Definition: video.h:368
#define PAGED_CODE()
UCHAR LinesPerRow
Definition: video.h:179
#define GDC2_MODE_ODD_RLINE_SHOW
Definition: video.h:247
#define GDC2_MODE_COLORS_16
Definition: video.h:282