ReactOS  0.4.15-dev-1377-ga59cecd
blue.c File Reference
#include "blue.h"
#include <ndk/inbvfuncs.h>
#include <debug.h>
Include dependency graph for blue.c:

Go to the source code of this file.

Classes

struct  _DEVICE_EXTENSION
 
struct  _VGA_REGISTERS
 

Macros

#define NDEBUG
 
#define FOREGROUND_LIGHTGRAY   (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
 

Typedefs

typedef struct _DEVICE_EXTENSION DEVICE_EXTENSION
 
typedef struct _DEVICE_EXTENSIONPDEVICE_EXTENSION
 
typedef struct _VGA_REGISTERS VGA_REGISTERS
 
typedef struct _VGA_REGISTERSPVGA_REGISTERS
 

Functions

static BOOLEAN ScrResetScreen (_In_ PDEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FullReset, _In_ BOOLEAN Enable)
 
static BOOLEAN NTAPI ScrResetDisplayParametersEx (_In_ ULONG Columns, _In_ ULONG Rows, _In_ BOOLEAN CalledByInbv)
 
static BOOLEAN NTAPI ScrResetDisplayParameters (_In_ ULONG Columns, _In_ ULONG Rows)
 
static VOID NTAPI InbvMonitorThread (_In_ PVOID Context)
 
static NTSTATUS ScrInbvInitialize (VOID)
 
static NTSTATUS ScrInbvCleanup (VOID)
 
static VOID FASTCALL ScrSetRegisters (const VGA_REGISTERS *Registers)
 
static VOID FASTCALL ScrSetCursor (_In_ PDEVICE_EXTENSION DeviceExtension)
 
static VOID FASTCALL ScrSetCursorShape (_In_ PDEVICE_EXTENSION DeviceExtension)
 
static VOID FASTCALL ScrAcquireOwnership (_In_ PDEVICE_EXTENSION DeviceExtension)
 
static NTSTATUS NTAPI ScrCreateClose (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
static NTSTATUS NTAPI ScrWrite (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
static NTSTATUS NTAPI ScrIoControl (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
static NTSTATUS NTAPI ScrDispatch (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
NTSTATUS NTAPI DriverEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
 

Variables

static const VGA_REGISTERS VidpMode3Regs
 
static const UCHAR DefaultPalette []
 
static PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension = NULL
 
static HANDLE InbvThreadHandle = NULL
 
static BOOLEAN InbvMonitoring = FALSE
 
static DRIVER_DISPATCH ScrCreateClose
 
static DRIVER_DISPATCH ScrWrite
 
static DRIVER_DISPATCH ScrIoControl
 
static DRIVER_DISPATCH ScrDispatch
 

Macro Definition Documentation

◆ FOREGROUND_LIGHTGRAY

#define FOREGROUND_LIGHTGRAY   (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file blue.c.

Typedef Documentation

◆ DEVICE_EXTENSION

◆ PDEVICE_EXTENSION

◆ PVGA_REGISTERS

◆ VGA_REGISTERS

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PUNICODE_STRING  RegistryPath 
)

Definition at line 1593 of file blue.c.

1596 {
1597  NTSTATUS Status;
1599  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\BlueScreen");
1600  UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\??\\BlueScreen");
1601 
1602  DPRINT("Screen Driver 0.0.6\n");
1603 
1604  DriverObject->MajorFunction[IRP_MJ_CREATE] = ScrCreateClose;
1605  DriverObject->MajorFunction[IRP_MJ_CLOSE] = ScrCreateClose;
1606  DriverObject->MajorFunction[IRP_MJ_READ] = ScrDispatch;
1607  DriverObject->MajorFunction[IRP_MJ_WRITE] = ScrWrite;
1609 
1611  sizeof(DEVICE_EXTENSION),
1612  &DeviceName,
1615  TRUE,
1616  &DeviceObject);
1617  if (!NT_SUCCESS(Status))
1618  {
1619  return Status;
1620  }
1621 
1622  Status = IoCreateSymbolicLink(&SymlinkName, &DeviceName);
1623  if (NT_SUCCESS(Status))
1624  {
1625  /* By default disable the screen (but don't touch INBV: ResetDisplayParametersDeviceExtension is still NULL) */
1626  ScrResetScreen(DeviceObject->DeviceExtension, TRUE, FALSE);
1627  /* Now set ResetDisplayParametersDeviceExtension to enable synchronizing with INBV */
1630  }
1631  else
1632  {
1634  }
1635  return Status;
1636 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define FILE_DEVICE_SCREEN
Definition: winioctl.h:133
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
static DRIVER_DISPATCH ScrDispatch
Definition: blue.c:1569
static BOOLEAN ScrResetScreen(_In_ PDEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FullReset, _In_ BOOLEAN Enable)
Definition: blue.c:504
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
static DRIVER_DISPATCH ScrCreateClose
Definition: blue.c:675
#define FALSE
Definition: types.h:117
static DRIVER_DISPATCH ScrWrite
Definition: blue.c:695
void DPRINT(...)
Definition: polytest.cpp:61
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
static DRIVER_DISPATCH ScrIoControl
Definition: blue.c:853
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IRP_MJ_READ
Definition: rdpdr.c:46
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
static PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension
Definition: blue.c:98
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ InbvMonitorThread()

static VOID NTAPI InbvMonitorThread ( _In_ PVOID  Context)
static

Definition at line 189 of file blue.c.

191 {
192  LARGE_INTEGER Delay;
193  USHORT i;
194 
196 
197  while (TRUE)
198  {
199  /*
200  * During one second, check the INBV status each 100 milliseconds,
201  * then revert to 1 second delay.
202  */
203  i = 10;
204  Delay.QuadPart = (LONGLONG)-100*1000*10; // 100 millisecond delay
205  while (!InbvMonitoring)
206  {
208 
209  if ((i > 0) && (--i == 0))
210  Delay.QuadPart = (LONGLONG)-1*1000*1000*10; // 1 second delay
211  }
212 
213  /*
214  * Loop while the display is owned by INBV. We cannot do anything else
215  * than polling since INBV does not offer a proper notification system.
216  *
217  * During one second, check the INBV status each 100 milliseconds,
218  * then revert to 1 second delay.
219  */
220  i = 10;
221  Delay.QuadPart = (LONGLONG)-100*1000*10; // 100 millisecond delay
222  while (InbvCheckDisplayOwnership())
223  {
225 
226  if ((i > 0) && (--i == 0))
227  Delay.QuadPart = (LONGLONG)-1*1000*1000*10; // 1 second delay
228  }
229 
230  /* Reset the monitoring */
232 
233  /*
234  * Somebody released INBV display ownership, usually by invoking
235  * InbvNotifyDisplayOwnershipLost(). However the caller of this
236  * function certainly specified a different callback than ours.
237  * As we are going to be the only owner of the active display,
238  * we need to re-register our own display reset callback.
239  */
241 
242  /* Re-enable the screen, keeping the original screen settings */
245  }
246 
247  // FIXME: See ScrInbvCleanup().
248  // PsTerminateSystemThread(STATUS_SUCCESS);
249 }
VOID NTAPI InbvNotifyDisplayOwnershipLost(IN INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:638
#define TRUE
Definition: types.h:120
static BOOLEAN InbvMonitoring
Definition: blue.c:100
#define LOW_REALTIME_PRIORITY
static BOOLEAN ScrResetScreen(_In_ PDEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FullReset, _In_ BOOLEAN Enable)
Definition: blue.c:504
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
int64_t LONGLONG
Definition: typedefs.h:68
static BOOLEAN NTAPI ScrResetDisplayParameters(_In_ ULONG Columns, _In_ ULONG Rows)
Definition: blue.c:147
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
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1327
unsigned short USHORT
Definition: pedump.c:61
BOOLEAN NTAPI InbvCheckDisplayOwnership(VOID)
Definition: inbv.c:553
#define KeGetCurrentThread
Definition: hal.h:44
static PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension
Definition: blue.c:98
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by ScrInbvInitialize().

◆ ScrAcquireOwnership()

static VOID FASTCALL ScrAcquireOwnership ( _In_ PDEVICE_EXTENSION  DeviceExtension)
static

Definition at line 412 of file blue.c.

414 {
415  UCHAR data, value;
416  ULONG offset;
417  ULONG Index;
418 
419  _disable();
420 
422 
423  /* Disable screen and enable palette access */
425  WRITE_PORT_UCHAR(ATTRIB, 0x00);
426 
427  for (Index = 0; Index < sizeof(DefaultPalette) / 3; Index++)
428  {
433  }
434 
435  /* Enable screen and disable palette access */
437  WRITE_PORT_UCHAR(ATTRIB, 0x20);
438 
439  /* Switch blinking characters off */
444  data = data & ~0x08;
448 
449  /* Read screen information from CRT controller */
451  DeviceExtension->Columns = READ_PORT_UCHAR(CRTC_DATA) + 1;
453  DeviceExtension->Rows = READ_PORT_UCHAR(CRTC_DATA);
456  DeviceExtension->Rows |= (((data & 0x02) << 7) | ((data & 0x40) << 3));
457  DeviceExtension->Rows++;
459  DeviceExtension->ScanLines = (READ_PORT_UCHAR(CRTC_DATA) & 0x1F) + 1;
460 
461  /* Retrieve the current output cursor position */
465  offset += (READ_PORT_UCHAR(CRTC_DATA) << 8);
466 
467  /* Show blinking cursor */
468  // FIXME: cursor block? Call ScrSetCursorShape() instead?
470  WRITE_PORT_UCHAR(CRTC_DATA, (DeviceExtension->ScanLines - 1) & 0x1F);
472  data = READ_PORT_UCHAR(CRTC_DATA) & 0xE0;
474  data | ((DeviceExtension->ScanLines - 1) & 0x1F));
475 
476  _enable();
477 
478  /* Calculate number of text rows */
479  DeviceExtension->Rows = DeviceExtension->Rows / DeviceExtension->ScanLines;
480 
481  /* Set the cursor position, clipping it to the screen */
482  DeviceExtension->CursorX = (USHORT)(offset % DeviceExtension->Columns);
483  DeviceExtension->CursorY = (USHORT)(offset / DeviceExtension->Columns);
484  // DeviceExtension->CursorX = min(max(DeviceExtension->CursorX, 0), DeviceExtension->Columns - 1);
485  DeviceExtension->CursorY = min(max(DeviceExtension->CursorY, 0), DeviceExtension->Rows - 1);
486 
487  if (DeviceExtension->FontBitfield)
488  {
489  ScrSetFont(DeviceExtension->FontBitfield);
490  }
491  else
492  {
493  /* Upload a default font for the current codepage */
494  ScrLoadFontTable(DeviceExtension->CodePage);
495  }
496 
497  DPRINT("%d Columns %d Rows %d Scanlines\n",
498  DeviceExtension->Columns,
499  DeviceExtension->Rows,
500  DeviceExtension->ScanLines);
501 }
#define CRTC_SCANLINES
Definition: blue.h:108
#define max(a, b)
Definition: svc.c:63
static const VGA_REGISTERS VidpMode3Regs
Definition: blue.c:54
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define CRTC_CURSORPOSHI
Definition: blue.h:111
#define ATTRIB
Definition: blue.h:141
#define CRTC_ROWS
Definition: blue.h:107
static const UCHAR DefaultPalette[]
Definition: blue.c:70
#define CRTC_COLUMNS
Definition: blue.h:105
#define CRTC_DATA
Definition: blue.h:103
#define ATTRC_INPST1
Definition: blue.h:132
void DPRINT(...)
Definition: polytest.cpp:61
#define ATTRC_WRITEREG
Definition: blue.h:130
#define PELINDEX
Definition: blue.h:144
GLintptr offset
Definition: glext.h:5920
_In_ WDFCOLLECTION _In_ ULONG Index
#define STATUS
Definition: blue.h:142
#define CRTC_CURSOREND
Definition: blue.h:110
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned char UCHAR
Definition: xmlstorage.h:181
#define CRTC_CURSORPOSLO
Definition: blue.h:112
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
GLsizei const GLfloat * value
Definition: glext.h:6069
#define CRTC_OVERFLOW
Definition: blue.h:106
unsigned short USHORT
Definition: pedump.c:61
#define min(a, b)
Definition: monoChain.cc:55
#define CRTC_COMMAND
Definition: blue.h:102
#define PELDATA
Definition: blue.h:145
void __cdecl _disable(void)
Definition: intrin_arm.h:365
VOID ScrSetFont(_In_ PUCHAR FontBitfield)
Definition: font.c:66
unsigned int ULONG
Definition: retypes.h:1
static VOID FASTCALL ScrSetRegisters(const VGA_REGISTERS *Registers)
Definition: blue.c:309
#define ATTRC_READREG
Definition: blue.h:131
#define CRTC_CURSORSTART
Definition: blue.h:109
VOID ScrLoadFontTable(_In_ ULONG CodePage)
Definition: font.c:26

Referenced by ScrResetScreen().

◆ ScrCreateClose()

static NTSTATUS NTAPI ScrCreateClose ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)
static

Definition at line 678 of file blue.c.

681 {
683 
685 
686  if (stk->MajorFunction == IRP_MJ_CREATE)
687  Irp->IoStatus.Information = FILE_OPENED;
688  // else: IRP_MJ_CLOSE
689 
690  Irp->IoStatus.Status = STATUS_SUCCESS;
692  return STATUS_SUCCESS;
693 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define FILE_OPENED
Definition: nt_native.h:769
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ ScrDispatch()

static NTSTATUS NTAPI ScrDispatch ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)
static

Definition at line 1572 of file blue.c.

1575 {
1577 
1579 
1580  DPRINT1("ScrDispatch(0x%p): stk->MajorFunction = %lu UNIMPLEMENTED\n",
1581  DeviceObject, stk->MajorFunction);
1582 
1583  Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
1585  return STATUS_NOT_IMPLEMENTED;
1586 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:581

◆ ScrInbvCleanup()

static NTSTATUS ScrInbvCleanup ( VOID  )
static

Definition at line 278 of file blue.c.

279 {
280  // HANDLE ThreadHandle;
281 
282  // ResetDisplayParametersDeviceExtension = NULL;
284  {
287  // or InbvAcquireDisplayOwnership(); ?
288  }
289 
290 #if 0
291  // TODO: Find the best way to communicate the request.
292  /* Signal the INBV monitoring thread and wait for it to terminate */
294  if (ThreadHandle)
295  {
296  ZwWaitForSingleObject(ThreadHandle, Executive, KernelMode, FALSE, NULL);
297  /* Close its handle */
298  ObCloseHandle(ThreadHandle, KernelMode);
299  }
300 #endif
301 
302  return STATUS_SUCCESS;
303 }
VOID NTAPI InbvNotifyDisplayOwnershipLost(IN INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:638
#define FALSE
Definition: types.h:117
static BOOLEAN NTAPI ScrResetDisplayParametersEx(_In_ ULONG Columns, _In_ ULONG Rows, _In_ BOOLEAN CalledByInbv)
Definition: blue.c:119
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
static HANDLE InbvThreadHandle
Definition: blue.c:99
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
static PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension
Definition: blue.c:98

Referenced by ScrResetScreen().

◆ ScrInbvInitialize()

static NTSTATUS ScrInbvInitialize ( VOID  )
static

Definition at line 252 of file blue.c.

253 {
254  /* Create the INBV monitoring thread if needed */
255  if (!InbvThreadHandle)
256  {
259 
261  0,
263  NULL,
264  NULL,
266  NULL);
267  if (!NT_SUCCESS(Status))
269  }
270 
271  /* Re-register the display reset callback with INBV */
273 
274  return STATUS_SUCCESS;
275 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
VOID NTAPI InbvNotifyDisplayOwnershipLost(IN INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:638
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static BOOLEAN NTAPI ScrResetDisplayParameters(_In_ ULONG Columns, _In_ ULONG Rows)
Definition: blue.c:147
static VOID NTAPI InbvMonitorThread(_In_ PVOID Context)
Definition: blue.c:189
static HANDLE InbvThreadHandle
Definition: blue.c:99
#define RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by ScrResetScreen().

◆ ScrIoControl()

static NTSTATUS NTAPI ScrIoControl ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)
static

Definition at line 856 of file blue.c.

859 {
862  PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
863 
864  switch (stk->Parameters.DeviceIoControl.IoControlCode)
865  {
867  {
868  BOOLEAN Enable;
869 
870  /* Validate input buffer */
871  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG))
872  {
874  break;
875  }
876  ASSERT(Irp->AssociatedIrp.SystemBuffer);
877 
878  Enable = !!*(PULONG)Irp->AssociatedIrp.SystemBuffer;
879 
880  /* Fully enable or disable the screen */
881  Status = (ScrResetScreen(DeviceExtension, TRUE, Enable)
883  Irp->IoStatus.Information = 0;
884  break;
885  }
886 
888  {
890  USHORT rows = DeviceExtension->Rows;
891  USHORT columns = DeviceExtension->Columns;
892 
893  /* Validate output buffer */
894  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_SCREEN_BUFFER_INFO))
895  {
897  break;
898  }
899  ASSERT(Irp->AssociatedIrp.SystemBuffer);
900 
901  pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
903 
904  pcsbi->dwSize.X = columns;
905  pcsbi->dwSize.Y = rows;
906 
907  pcsbi->dwCursorPosition.X = DeviceExtension->CursorX;
908  pcsbi->dwCursorPosition.Y = DeviceExtension->CursorY;
909 
910  pcsbi->wAttributes = DeviceExtension->CharAttribute;
911 
912  pcsbi->srWindow.Left = 0;
913  pcsbi->srWindow.Right = columns - 1;
914  pcsbi->srWindow.Top = 0;
915  pcsbi->srWindow.Bottom = rows - 1;
916 
917  pcsbi->dwMaximumWindowSize.X = columns;
918  pcsbi->dwMaximumWindowSize.Y = rows;
919 
920  Irp->IoStatus.Information = sizeof(CONSOLE_SCREEN_BUFFER_INFO);
922  break;
923  }
924 
926  {
928 
929  /* Validate input buffer */
930  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(CONSOLE_SCREEN_BUFFER_INFO))
931  {
933  break;
934  }
935  ASSERT(Irp->AssociatedIrp.SystemBuffer);
936 
937  pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
938 
939  if ( pcsbi->dwCursorPosition.X < 0 || pcsbi->dwCursorPosition.X >= DeviceExtension->Columns ||
940  pcsbi->dwCursorPosition.Y < 0 || pcsbi->dwCursorPosition.Y >= DeviceExtension->Rows )
941  {
942  Irp->IoStatus.Information = 0;
944  break;
945  }
946 
947  DeviceExtension->CharAttribute = pcsbi->wAttributes;
948 
949  /* Set the cursor position */
950  ASSERT((0 <= pcsbi->dwCursorPosition.X) && (pcsbi->dwCursorPosition.X < DeviceExtension->Columns));
951  ASSERT((0 <= pcsbi->dwCursorPosition.Y) && (pcsbi->dwCursorPosition.Y < DeviceExtension->Rows));
952  DeviceExtension->CursorX = pcsbi->dwCursorPosition.X;
953  DeviceExtension->CursorY = pcsbi->dwCursorPosition.Y;
954  if (DeviceExtension->Enabled)
955  ScrSetCursor(DeviceExtension);
956 
957  Irp->IoStatus.Information = 0;
959  break;
960  }
961 
963  {
965 
966  /* Validate output buffer */
967  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_CURSOR_INFO))
968  {
970  break;
971  }
972  ASSERT(Irp->AssociatedIrp.SystemBuffer);
973 
974  pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
975  RtlZeroMemory(pcci, sizeof(CONSOLE_CURSOR_INFO));
976 
977  pcci->dwSize = DeviceExtension->CursorSize;
978  pcci->bVisible = DeviceExtension->CursorVisible;
979 
980  Irp->IoStatus.Information = sizeof(CONSOLE_CURSOR_INFO);
982  break;
983  }
984 
986  {
988 
989  /* Validate input buffer */
990  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(CONSOLE_CURSOR_INFO))
991  {
993  break;
994  }
995  ASSERT(Irp->AssociatedIrp.SystemBuffer);
996 
997  pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
998 
999  DeviceExtension->CursorSize = pcci->dwSize;
1000  DeviceExtension->CursorVisible = pcci->bVisible;
1001  if (DeviceExtension->Enabled)
1002  ScrSetCursorShape(DeviceExtension);
1003 
1004  Irp->IoStatus.Information = 0;
1006  break;
1007  }
1008 
1010  {
1011  PCONSOLE_MODE pcm;
1012 
1013  /* Validate output buffer */
1014  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_MODE))
1015  {
1017  break;
1018  }
1019  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1020 
1021  pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
1022  RtlZeroMemory(pcm, sizeof(CONSOLE_MODE));
1023 
1024  pcm->dwMode = DeviceExtension->Mode;
1025 
1026  Irp->IoStatus.Information = sizeof(CONSOLE_MODE);
1028  break;
1029  }
1030 
1032  {
1033  PCONSOLE_MODE pcm;
1034 
1035  /* Validate input buffer */
1036  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(CONSOLE_MODE))
1037  {
1039  break;
1040  }
1041  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1042 
1043  pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
1044  DeviceExtension->Mode = pcm->dwMode;
1045 
1046  Irp->IoStatus.Information = 0;
1048  break;
1049  }
1050 
1052  {
1053  POUTPUT_ATTRIBUTE Buf;
1054  PUCHAR vidmem;
1055  ULONG offset;
1056  ULONG dwCount;
1057  ULONG nMaxLength;
1058 
1059  /* Validate input and output buffers */
1060  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(OUTPUT_ATTRIBUTE) ||
1061  stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(OUTPUT_ATTRIBUTE))
1062  {
1064  break;
1065  }
1066  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1067 
1068  Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
1069  nMaxLength = Buf->nLength;
1070 
1071  Buf->dwTransfered = 0;
1072  Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
1073 
1074  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
1075  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows ||
1076  nMaxLength == 0 )
1077  {
1079  break;
1080  }
1081 
1082  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1083  {
1084  vidmem = DeviceExtension->VideoMemory;
1085  offset = (Buf->dwCoord.X + Buf->dwCoord.Y * DeviceExtension->Columns) * 2 + 1;
1086 
1087  nMaxLength = min(nMaxLength,
1088  (DeviceExtension->Rows - Buf->dwCoord.Y)
1089  * DeviceExtension->Columns - Buf->dwCoord.X);
1090 
1091  for (dwCount = 0; dwCount < nMaxLength; dwCount++)
1092  {
1093  vidmem[offset + (dwCount * 2)] = (char)Buf->wAttribute;
1094  }
1095  Buf->dwTransfered = dwCount;
1096  }
1097 
1099  break;
1100  }
1101 
1103  {
1104  POUTPUT_ATTRIBUTE Buf;
1105  PUSHORT pAttr;
1106  PUCHAR vidmem;
1107  ULONG offset;
1108  ULONG dwCount;
1109  ULONG nMaxLength;
1110 
1111  /* Validate input buffer */
1112  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(OUTPUT_ATTRIBUTE))
1113  {
1115  break;
1116  }
1117  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1118 
1119  Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
1120  Irp->IoStatus.Information = 0;
1121 
1122  /* Validate output buffer */
1123  if (stk->Parameters.DeviceIoControl.OutputBufferLength == 0)
1124  {
1126  break;
1127  }
1128  ASSERT(Irp->MdlAddress);
1129  pAttr = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1130  if (pAttr == NULL)
1131  {
1133  break;
1134  }
1135 
1136  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
1137  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
1138  {
1140  break;
1141  }
1142 
1143  nMaxLength = stk->Parameters.DeviceIoControl.OutputBufferLength;
1144  nMaxLength /= sizeof(USHORT);
1145 
1146  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1147  {
1148  vidmem = DeviceExtension->VideoMemory;
1149  offset = (Buf->dwCoord.X + Buf->dwCoord.Y * DeviceExtension->Columns) * 2 + 1;
1150 
1151  nMaxLength = min(nMaxLength,
1152  (DeviceExtension->Rows - Buf->dwCoord.Y)
1153  * DeviceExtension->Columns - Buf->dwCoord.X);
1154 
1155  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pAttr++)
1156  {
1157  *((PCHAR)pAttr) = vidmem[offset + (dwCount * 2)];
1158  }
1159  Irp->IoStatus.Information = dwCount * sizeof(USHORT);
1160  }
1161 
1163  break;
1164  }
1165 
1167  {
1168  COORD dwCoord;
1169  PCOORD pCoord;
1170  PUSHORT pAttr;
1171  PUCHAR vidmem;
1172  ULONG offset;
1173  ULONG dwCount;
1174  ULONG nMaxLength;
1175 
1176  //
1177  // NOTE: For whatever reason no OUTPUT_ATTRIBUTE structure
1178  // is used for this IOCTL.
1179  //
1180 
1181  /* Validate output buffer */
1182  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(COORD))
1183  {
1185  break;
1186  }
1187  ASSERT(Irp->MdlAddress);
1188  pCoord = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1189  if (pCoord == NULL)
1190  {
1192  break;
1193  }
1194  /* Capture the input info data */
1195  dwCoord = *pCoord;
1196 
1197  nMaxLength = stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(COORD);
1198  nMaxLength /= sizeof(USHORT);
1199 
1200  Irp->IoStatus.Information = 0;
1201 
1202  if ( dwCoord.X < 0 || dwCoord.X >= DeviceExtension->Columns ||
1203  dwCoord.Y < 0 || dwCoord.Y >= DeviceExtension->Rows ||
1204  nMaxLength == 0 )
1205  {
1207  break;
1208  }
1209 
1210  pAttr = (PUSHORT)(pCoord + 1);
1211 
1212  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1213  {
1214  vidmem = DeviceExtension->VideoMemory;
1215  offset = (dwCoord.X + dwCoord.Y * DeviceExtension->Columns) * 2 + 1;
1216 
1217  nMaxLength = min(nMaxLength,
1218  (DeviceExtension->Rows - dwCoord.Y)
1219  * DeviceExtension->Columns - dwCoord.X);
1220 
1221  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pAttr++)
1222  {
1223  vidmem[offset + (dwCount * 2)] = *((PCHAR)pAttr);
1224  }
1225  Irp->IoStatus.Information = dwCount * sizeof(USHORT);
1226  }
1227 
1229  break;
1230  }
1231 
1233  {
1234  /* Validate input buffer */
1235  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(USHORT))
1236  {
1238  break;
1239  }
1240  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1241 
1242  DeviceExtension->CharAttribute = *(PUSHORT)Irp->AssociatedIrp.SystemBuffer;
1243 
1244  Irp->IoStatus.Information = 0;
1246  break;
1247  }
1248 
1250  {
1251  POUTPUT_CHARACTER Buf;
1252  PUCHAR vidmem;
1253  ULONG offset;
1254  ULONG dwCount;
1255  ULONG nMaxLength;
1256 
1257  /* Validate input and output buffers */
1258  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(OUTPUT_CHARACTER) ||
1259  stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(OUTPUT_CHARACTER))
1260  {
1262  break;
1263  }
1264  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1265 
1266  Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
1267  nMaxLength = Buf->nLength;
1268 
1269  Buf->dwTransfered = 0;
1270  Irp->IoStatus.Information = sizeof(OUTPUT_CHARACTER);
1271 
1272  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
1273  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows ||
1274  nMaxLength == 0 )
1275  {
1277  break;
1278  }
1279 
1280  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1281  {
1282  vidmem = DeviceExtension->VideoMemory;
1283  offset = (Buf->dwCoord.X + Buf->dwCoord.Y * DeviceExtension->Columns) * 2;
1284 
1285  nMaxLength = min(nMaxLength,
1286  (DeviceExtension->Rows - Buf->dwCoord.Y)
1287  * DeviceExtension->Columns - Buf->dwCoord.X);
1288 
1289  for (dwCount = 0; dwCount < nMaxLength; dwCount++)
1290  {
1291  vidmem[offset + (dwCount * 2)] = (char)Buf->cCharacter;
1292  }
1293  Buf->dwTransfered = dwCount;
1294  }
1295 
1297  break;
1298  }
1299 
1301  {
1302  POUTPUT_CHARACTER Buf;
1303  PCHAR pChar;
1304  PUCHAR vidmem;
1305  ULONG offset;
1306  ULONG dwCount;
1307  ULONG nMaxLength;
1308 
1309  /* Validate input buffer */
1310  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(OUTPUT_CHARACTER))
1311  {
1313  break;
1314  }
1315  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1316 
1317  Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
1318  Irp->IoStatus.Information = 0;
1319 
1320  /* Validate output buffer */
1321  if (stk->Parameters.DeviceIoControl.OutputBufferLength == 0)
1322  {
1324  break;
1325  }
1326  ASSERT(Irp->MdlAddress);
1327  pChar = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1328  if (pChar == NULL)
1329  {
1331  break;
1332  }
1333 
1334  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
1335  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
1336  {
1338  break;
1339  }
1340 
1341  nMaxLength = stk->Parameters.DeviceIoControl.OutputBufferLength;
1342 
1343  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1344  {
1345  vidmem = DeviceExtension->VideoMemory;
1346  offset = (Buf->dwCoord.X + Buf->dwCoord.Y * DeviceExtension->Columns) * 2;
1347 
1348  nMaxLength = min(nMaxLength,
1349  (DeviceExtension->Rows - Buf->dwCoord.Y)
1350  * DeviceExtension->Columns - Buf->dwCoord.X);
1351 
1352  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pChar++)
1353  {
1354  *pChar = vidmem[offset + (dwCount * 2)];
1355  }
1356  Irp->IoStatus.Information = dwCount * sizeof(CHAR);
1357  }
1358 
1360  break;
1361  }
1362 
1364  {
1365  COORD dwCoord;
1366  PCOORD pCoord;
1367  PCHAR pChar;
1368  PUCHAR vidmem;
1369  ULONG offset;
1370  ULONG dwCount;
1371  ULONG nMaxLength;
1372 
1373  //
1374  // NOTE: For whatever reason no OUTPUT_CHARACTER structure
1375  // is used for this IOCTL.
1376  //
1377 
1378  /* Validate output buffer */
1379  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(COORD))
1380  {
1382  break;
1383  }
1384  ASSERT(Irp->MdlAddress);
1385  pCoord = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1386  if (pCoord == NULL)
1387  {
1389  break;
1390  }
1391  /* Capture the input info data */
1392  dwCoord = *pCoord;
1393 
1394  nMaxLength = stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(COORD);
1395  Irp->IoStatus.Information = 0;
1396 
1397  if ( dwCoord.X < 0 || dwCoord.X >= DeviceExtension->Columns ||
1398  dwCoord.Y < 0 || dwCoord.Y >= DeviceExtension->Rows ||
1399  nMaxLength == 0 )
1400  {
1402  break;
1403  }
1404 
1405  pChar = (PCHAR)(pCoord + 1);
1406 
1407  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1408  {
1409  vidmem = DeviceExtension->VideoMemory;
1410  offset = (dwCoord.X + dwCoord.Y * DeviceExtension->Columns) * 2;
1411 
1412  nMaxLength = min(nMaxLength,
1413  (DeviceExtension->Rows - dwCoord.Y)
1414  * DeviceExtension->Columns - dwCoord.X);
1415 
1416  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pChar++)
1417  {
1418  vidmem[offset + (dwCount * 2)] = *pChar;
1419  }
1420  Irp->IoStatus.Information = dwCount * sizeof(CHAR);
1421  }
1422 
1424  break;
1425  }
1426 
1427  case IOCTL_CONSOLE_DRAW:
1428  {
1429  CONSOLE_DRAW ConsoleDraw;
1430  PCONSOLE_DRAW pConsoleDraw;
1431  PUCHAR Src, Dest;
1432  UINT32 SrcDelta, DestDelta, i;
1433 
1434  /* Validate output buffer */
1435  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_DRAW))
1436  {
1438  break;
1439  }
1440  ASSERT(Irp->MdlAddress);
1441  pConsoleDraw = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1442  if (pConsoleDraw == NULL)
1443  {
1445  break;
1446  }
1447  /* Capture the input info data */
1448  ConsoleDraw = *pConsoleDraw;
1449 
1450  /* Check whether we have the size for the header plus the data area */
1451  if ((stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(CONSOLE_DRAW)) / 2
1452  < ((ULONG)ConsoleDraw.SizeX * (ULONG)ConsoleDraw.SizeY))
1453  {
1455  break;
1456  }
1457 
1458  // TODO: For the moment if the ConsoleDraw rectangle has borders
1459  // out of the screen-buffer we just bail out. Would it be better
1460  // to actually clip the rectangle within its borders instead?
1461  if ( ConsoleDraw.X < 0 || ConsoleDraw.X >= DeviceExtension->Columns ||
1462  ConsoleDraw.Y < 0 || ConsoleDraw.Y >= DeviceExtension->Rows )
1463  {
1465  break;
1466  }
1467  if ( ConsoleDraw.SizeX >= DeviceExtension->Columns - ConsoleDraw.X ||
1468  ConsoleDraw.SizeY >= DeviceExtension->Rows - ConsoleDraw.Y )
1469  {
1471  break;
1472  }
1473 
1474  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1475  {
1476  Src = (PUCHAR)(pConsoleDraw + 1);
1477  SrcDelta = ConsoleDraw.SizeX * 2;
1478  Dest = DeviceExtension->VideoMemory +
1479  (ConsoleDraw.X + ConsoleDraw.Y * DeviceExtension->Columns) * 2;
1480  DestDelta = DeviceExtension->Columns * 2;
1481  /* 2 == sizeof(CHAR) + sizeof(BYTE) */
1482 
1483  /* Copy each line */
1484  for (i = 0; i < ConsoleDraw.SizeY; i++)
1485  {
1486  RtlCopyMemory(Dest, Src, SrcDelta);
1487  Src += SrcDelta;
1488  Dest += DestDelta;
1489  }
1490  }
1491 
1492  /* Set the cursor position, clipping it to the screen */
1493  DeviceExtension->CursorX = min(max(ConsoleDraw.CursorX, 0), DeviceExtension->Columns - 1);
1494  DeviceExtension->CursorY = min(max(ConsoleDraw.CursorY, 0), DeviceExtension->Rows - 1);
1495  if (DeviceExtension->Enabled)
1496  ScrSetCursor(DeviceExtension);
1497 
1498  Irp->IoStatus.Information = 0;
1500  break;
1501  }
1502 
1504  {
1505  /* Validate input buffer */
1506  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG))
1507  {
1509  break;
1510  }
1511  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1512 
1513  if (DeviceExtension->FontBitfield)
1514  {
1515  ExFreePoolWithTag(DeviceExtension->FontBitfield, TAG_BLUE);
1516  DeviceExtension->FontBitfield = NULL;
1517  }
1518  DeviceExtension->CodePage = *(PULONG)Irp->AssociatedIrp.SystemBuffer;
1519 
1520  /* Upload a font for the codepage if needed */
1521  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1522  ScrLoadFontTable(DeviceExtension->CodePage);
1523 
1524  Irp->IoStatus.Information = 0;
1526  break;
1527  }
1528 
1529  case IOCTL_CONSOLE_SETFONT:
1530  {
1531  /* Validate input buffer */
1532  if (stk->Parameters.DeviceIoControl.InputBufferLength < 256 * 8)
1533  {
1535  break;
1536  }
1537  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1538 
1539  DeviceExtension->CodePage = 0;
1540  if (DeviceExtension->FontBitfield)
1541  ExFreePoolWithTag(DeviceExtension->FontBitfield, TAG_BLUE);
1542  DeviceExtension->FontBitfield = ExAllocatePoolWithTag(NonPagedPool, 256 * 8, TAG_BLUE);
1543  if (!DeviceExtension->FontBitfield)
1544  {
1546  break;
1547  }
1548  RtlCopyMemory(DeviceExtension->FontBitfield, Irp->AssociatedIrp.SystemBuffer, 256 * 8);
1549 
1550  /* Upload the font if needed */
1551  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1552  ScrSetFont(DeviceExtension->FontBitfield);
1553 
1554  Irp->IoStatus.Information = 0;
1556  break;
1557  }
1558 
1559  default:
1561  }
1562 
1563  Irp->IoStatus.Status = Status;
1565 
1566  return Status;
1567 }
struct tagCONSOLE_CURSOR_INFO * PCONSOLE_CURSOR_INFO
signed char * PCHAR
Definition: retypes.h:7
#define max(a, b)
Definition: svc.c:63
PBYTE vidmem
Definition: vgavideo.c:18
static VOID FASTCALL ScrSetCursorShape(_In_ PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:383
#define IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:15
#define IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:7
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USHORT SizeX
Definition: ntddblue.h:54
#define IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE
Definition: ntddblue.h:16
static VOID FASTCALL ScrSetCursor(_In_ PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:363
#define IOCTL_CONSOLE_SETFONT
Definition: ntddblue.h:25
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct tagOUTPUT_CHARACTER OUTPUT_CHARACTER
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
struct tagCONSOLE_SCREEN_BUFFER_INFO CONSOLE_SCREEN_BUFFER_INFO
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
struct tagCONSOLE_MODE * PCONSOLE_MODE
#define IOCTL_CONSOLE_SET_CURSOR_INFO
Definition: ntddblue.h:9
static BOOLEAN ScrResetScreen(_In_ PDEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FullReset, _In_ BOOLEAN Enable)
Definition: blue.c:504
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
#define IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER
Definition: ntddblue.h:18
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
_In_ PIRP Irp
Definition: csq.h:116
unsigned int UINT32
#define IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:13
unsigned char BOOLEAN
#define IoCompleteRequest
Definition: irp.c:1240
#define IOCTL_CONSOLE_GET_CURSOR_INFO
Definition: ntddblue.h:8
#define IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:14
#define PCHAR
Definition: match.c:90
SHORT Left
Definition: blue.h:32
ULONG X
Definition: bl.h:1340
Status
Definition: gdiplustypes.h:24
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:650
#define TAG_BLUE
Definition: blue.h:14
struct _COORD COORD
USHORT CursorX
Definition: ntddblue.h:56
SHORT Bottom
Definition: blue.h:35
#define ASSERT(a)
Definition: mode.c:45
if(!(yy_init))
Definition: macro.lex.yy.c:714
GLintptr offset
Definition: glext.h:5920
#define IOCTL_CONSOLE_GET_MODE
Definition: ntddblue.h:10
SHORT Top
Definition: blue.h:33
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IO_VIDEO_INCREMENT
Definition: iotypes.h:592
USHORT CursorY
Definition: ntddblue.h:57
#define IOCTL_CONSOLE_RESET_SCREEN
Definition: ntddblue.h:4
Definition: bl.h:1338
#define IOCTL_CONSOLE_DRAW
Definition: ntddblue.h:22
ULONG dwMode
Definition: ntddblue.h:31
struct tagOUTPUT_CHARACTER * POUTPUT_CHARACTER
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
USHORT SizeY
Definition: ntddblue.h:55
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
unsigned short USHORT
Definition: pedump.c:61
#define IOCTL_CONSOLE_SET_MODE
Definition: ntddblue.h:11
struct tagCONSOLE_MODE CONSOLE_MODE
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define IOCTL_CONSOLE_READ_OUTPUT_CHARACTER
Definition: ntddblue.h:19
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
struct tagOUTPUT_ATTRIBUTE * POUTPUT_ATTRIBUTE
#define NULL
Definition: types.h:112
#define IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:6
#define IOCTL_CONSOLE_LOADFONT
Definition: ntddblue.h:24
VOID ScrSetFont(_In_ PUCHAR FontBitfield)
Definition: font.c:66
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER
Definition: ntddblue.h:20
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
SHORT Right
Definition: blue.h:34
struct tagCONSOLE_SCREEN_BUFFER_INFO * PCONSOLE_SCREEN_BUFFER_INFO
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
ULONG Y
Definition: bl.h:1341
#define CHAR(Char)
struct tagCONSOLE_CURSOR_INFO CONSOLE_CURSOR_INFO
struct tagOUTPUT_ATTRIBUTE OUTPUT_ATTRIBUTE
unsigned short * PUSHORT
Definition: retypes.h:2
VOID ScrLoadFontTable(_In_ ULONG CodePage)
Definition: font.c:26

◆ ScrResetDisplayParameters()

static BOOLEAN NTAPI ScrResetDisplayParameters ( _In_ ULONG  Columns,
_In_ ULONG  Rows 
)
static

Definition at line 147 of file blue.c.

150 {
151  /* Call the extended function, specifying we were called by INBV */
153 }
#define TRUE
Definition: types.h:120
_In_ ULONG Rows
Definition: haltypes.h:7
static BOOLEAN NTAPI ScrResetDisplayParametersEx(_In_ ULONG Columns, _In_ ULONG Rows, _In_ BOOLEAN CalledByInbv)
Definition: blue.c:119
static const COLUMN_LIST Columns[]
Definition: listview.c:19

Referenced by InbvMonitorThread(), and ScrInbvInitialize().

◆ ScrResetDisplayParametersEx()

static BOOLEAN NTAPI ScrResetDisplayParametersEx ( _In_ ULONG  Columns,
_In_ ULONG  Rows,
_In_ BOOLEAN  CalledByInbv 
)
static

Definition at line 119 of file blue.c.

123 {
124  PDEVICE_EXTENSION DeviceExtension;
125 
126  /* Bail out early if we don't have any resettable adapter */
128  return FALSE; // No adapter found: request HAL to perform a full reset.
129 
130  /*
131  * If we have been unexpectedly called via a callback from
132  * InbvAcquireDisplayOwnership(), start monitoring INBV.
133  */
134  if (CalledByInbv)
136 
137  DeviceExtension = ResetDisplayParametersDeviceExtension;
138  ASSERT(DeviceExtension);
139 
140  /* Disable the screen but don't reset all screen settings (OK at high IRQL) */
141  return ScrResetScreen(DeviceExtension, FALSE, FALSE);
142 }
#define TRUE
Definition: types.h:120
static BOOLEAN InbvMonitoring
Definition: blue.c:100
static BOOLEAN ScrResetScreen(_In_ PDEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FullReset, _In_ BOOLEAN Enable)
Definition: blue.c:504
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:45
static PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension
Definition: blue.c:98

Referenced by ScrInbvCleanup(), and ScrResetDisplayParameters().

◆ ScrResetScreen()

static BOOLEAN ScrResetScreen ( _In_ PDEVICE_EXTENSION  DeviceExtension,
_In_ BOOLEAN  FullReset,
_In_ BOOLEAN  Enable 
)
static

Definition at line 504 of file blue.c.

508 {
509 #define FOREGROUND_LIGHTGRAY (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
510 
512 
513  /* Allow resets to the same state only for full resets */
514  if (!FullReset && (Enable == DeviceExtension->Enabled))
515  return FALSE; // STATUS_INVALID_PARAMETER; STATUS_INVALID_DEVICE_REQUEST;
516 
517  if (FullReset)
518  {
519  DeviceExtension->CursorSize = 5; /* FIXME: value correct?? */
520  DeviceExtension->CursorVisible = TRUE;
521 
522  if (DeviceExtension->FontBitfield)
523  {
524  ExFreePoolWithTag(DeviceExtension->FontBitfield, TAG_BLUE);
525  DeviceExtension->FontBitfield = NULL;
526  }
527 
528  /* More initialization */
529  DeviceExtension->CharAttribute = BACKGROUND_BLUE | FOREGROUND_LIGHTGRAY;
530  DeviceExtension->Mode = ENABLE_PROCESSED_OUTPUT |
532  DeviceExtension->CodePage = 437; /* Use default codepage */
533  }
534 
535  if (Enable)
536  {
537  ScrAcquireOwnership(DeviceExtension);
538 
539  if (FullReset)
540  {
541  /*
542  * Fully reset the screen and all its settings.
543  */
544 
545  /* Unmap any previously mapped video memory */
546  if (DeviceExtension->VideoMemory)
547  {
548  ASSERT(DeviceExtension->VideoMemorySize != 0);
549  MmUnmapIoSpace(DeviceExtension->VideoMemory, DeviceExtension->VideoMemorySize);
550  }
551  DeviceExtension->VideoMemory = NULL;
552  DeviceExtension->VideoMemorySize = 0;
553 
554  /* Free any previously allocated backup screenbuffer */
555  if (DeviceExtension->ScreenBuffer)
556  {
557  ASSERT(DeviceExtension->ScreenBufferSize != 0);
558  ExFreePoolWithTag(DeviceExtension->ScreenBuffer, TAG_BLUE);
559  }
560  DeviceExtension->ScreenBuffer = NULL;
561  DeviceExtension->ScreenBufferSize = 0;
562 
563  /* Get a pointer to the video memory */
564  DeviceExtension->VideoMemorySize = DeviceExtension->Rows * DeviceExtension->Columns * 2;
565  if (DeviceExtension->VideoMemorySize == 0)
566  return FALSE; // STATUS_INVALID_VIEW_SIZE; STATUS_MAPPED_FILE_SIZE_ZERO;
567 
568  /* Map the video memory */
569  BaseAddress.QuadPart = VIDMEM_BASE;
570  DeviceExtension->VideoMemory =
571  (PUCHAR)MmMapIoSpace(BaseAddress, DeviceExtension->VideoMemorySize, MmNonCached);
572  if (!DeviceExtension->VideoMemory)
573  {
574  DeviceExtension->VideoMemorySize = 0;
575  return FALSE; // STATUS_NONE_MAPPED; STATUS_NOT_MAPPED_VIEW; STATUS_CONFLICTING_ADDRESSES;
576  }
577 
578  /* Initialize the backup screenbuffer in non-paged pool (must be accessible at high IRQL) */
579  DeviceExtension->ScreenBufferSize = DeviceExtension->VideoMemorySize;
580  DeviceExtension->ScreenBuffer =
581  (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, DeviceExtension->ScreenBufferSize, TAG_BLUE);
582  if (!DeviceExtension->ScreenBuffer)
583  {
584  DPRINT1("Could not allocate screenbuffer, ignore...\n");
585  DeviceExtension->ScreenBufferSize = 0;
586  }
587 
588  /* (Re-)initialize INBV */
590  }
591  else
592  {
593  /*
594  * Restore the previously disabled screen.
595  */
596 
597  /* Restore the snapshot of the video memory from the backup screenbuffer */
598  if (DeviceExtension->ScreenBuffer)
599  {
600  ASSERT(DeviceExtension->VideoMemory);
601  ASSERT(DeviceExtension->ScreenBuffer);
602  ASSERT(DeviceExtension->ScreenBufferSize != 0);
603  ASSERT(DeviceExtension->VideoMemorySize == DeviceExtension->ScreenBufferSize);
604 
605  RtlCopyMemory(DeviceExtension->VideoMemory,
606  DeviceExtension->ScreenBuffer,
607  DeviceExtension->VideoMemorySize);
608  }
609 
610  /* Restore the cursor state */
611  ScrSetCursor(DeviceExtension);
612  ScrSetCursorShape(DeviceExtension);
613  }
614  DeviceExtension->Enabled = TRUE;
615  }
616  else
617  {
618  DeviceExtension->Enabled = FALSE;
619  if (FullReset)
620  {
621  /*
622  * Fully disable the screen and reset all its settings.
623  */
624 
625  /* Clean INBV up */
626  ScrInbvCleanup();
627 
628  /* Unmap any previously mapped video memory */
629  if (DeviceExtension->VideoMemory)
630  {
631  ASSERT(DeviceExtension->VideoMemorySize != 0);
632  MmUnmapIoSpace(DeviceExtension->VideoMemory, DeviceExtension->VideoMemorySize);
633  }
634  DeviceExtension->VideoMemory = NULL;
635  DeviceExtension->VideoMemorySize = 0;
636 
637  /* Free any previously allocated backup screenbuffer */
638  if (DeviceExtension->ScreenBuffer)
639  {
640  ASSERT(DeviceExtension->ScreenBufferSize != 0);
641  ExFreePoolWithTag(DeviceExtension->ScreenBuffer, TAG_BLUE);
642  }
643  DeviceExtension->ScreenBuffer = NULL;
644  DeviceExtension->ScreenBufferSize = 0;
645 
646  /* Store dummy values */
647  DeviceExtension->Columns = 1;
648  DeviceExtension->Rows = 1;
649  DeviceExtension->ScanLines = 1;
650  }
651  else
652  {
653  /*
654  * Partially disable the screen such that it can be restored later.
655  */
656 
657  /* Take a snapshot of the video memory into the backup screenbuffer */
658  if (DeviceExtension->ScreenBuffer)
659  {
660  ASSERT(DeviceExtension->VideoMemory);
661  ASSERT(DeviceExtension->ScreenBuffer);
662  ASSERT(DeviceExtension->ScreenBufferSize != 0);
663  ASSERT(DeviceExtension->VideoMemorySize == DeviceExtension->ScreenBufferSize);
664 
665  RtlCopyMemory(DeviceExtension->ScreenBuffer,
666  DeviceExtension->VideoMemory,
667  DeviceExtension->VideoMemorySize);
668  }
669  }
670  }
671 
672  return TRUE; // STATUS_SUCCESS;
673 }
static VOID FASTCALL ScrSetCursorShape(_In_ PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:383
static VOID FASTCALL ScrSetCursor(_In_ PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:363
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
#define ENABLE_WRAP_AT_EOL_OUTPUT
Definition: blue.h:54
#define FALSE
Definition: types.h:117
#define VIDMEM_BASE
Definition: blue.h:99
static VOID FASTCALL ScrAcquireOwnership(_In_ PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:412
#define TAG_BLUE
Definition: blue.h:14
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:45
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static NTSTATUS ScrInbvInitialize(VOID)
Definition: blue.c:252
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:53
#define FOREGROUND_LIGHTGRAY
static NTSTATUS ScrInbvCleanup(VOID)
Definition: blue.c:278
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define BACKGROUND_BLUE
Definition: blue.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by DriverEntry(), InbvMonitorThread(), ScrIoControl(), and ScrResetDisplayParametersEx().

◆ ScrSetCursor()

static VOID FASTCALL ScrSetCursor ( _In_ PDEVICE_EXTENSION  DeviceExtension)
static

Definition at line 363 of file blue.c.

365 {
366  ULONG Offset;
367 
368  if (!DeviceExtension->VideoMemory)
369  return;
370 
371  Offset = (DeviceExtension->CursorY * DeviceExtension->Columns) + DeviceExtension->CursorX;
372 
373  _disable();
378  _enable();
379 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define CRTC_CURSORPOSHI
Definition: blue.h:111
#define CRTC_DATA
Definition: blue.h:103
#define CRTC_CURSORPOSLO
Definition: blue.h:112
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define CRTC_COMMAND
Definition: blue.h:102
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1

Referenced by ScrIoControl(), ScrResetScreen(), and ScrWrite().

◆ ScrSetCursorShape()

static VOID FASTCALL ScrSetCursorShape ( _In_ PDEVICE_EXTENSION  DeviceExtension)
static

Definition at line 383 of file blue.c.

385 {
386  ULONG size, height;
387  UCHAR data, value;
388 
389  if (!DeviceExtension->VideoMemory)
390  return;
391 
392  height = DeviceExtension->ScanLines;
393  data = (DeviceExtension->CursorVisible) ? 0x00 : 0x20;
394 
395  size = (DeviceExtension->CursorSize * height) / 100;
396  if (size < 1)
397  size = 1;
398 
399  data |= (UCHAR)(height - size);
400 
401  _disable();
405  value = READ_PORT_UCHAR(CRTC_DATA) & 0xE0;
407  _enable();
408 }
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define CRTC_DATA
Definition: blue.h:103
GLsizeiptr size
Definition: glext.h:5919
#define CRTC_CURSOREND
Definition: blue.h:110
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned char UCHAR
Definition: xmlstorage.h:181
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
GLsizei const GLfloat * value
Definition: glext.h:6069
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define CRTC_COMMAND
Definition: blue.h:102
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define CRTC_CURSORSTART
Definition: blue.h:109

Referenced by ScrIoControl(), and ScrResetScreen().

◆ ScrSetRegisters()

static VOID FASTCALL ScrSetRegisters ( const VGA_REGISTERS Registers)
static

Definition at line 309 of file blue.c.

310 {
311  UINT32 i;
312 
313  /* Update misc output register */
314  WRITE_PORT_UCHAR(MISC, Registers->Misc);
315 
316  /* Synchronous reset on */
317  WRITE_PORT_UCHAR(SEQ, 0x00);
318  WRITE_PORT_UCHAR(SEQDATA, 0x01);
319 
320  /* Write sequencer registers */
321  for (i = 1; i < sizeof(Registers->Sequencer); i++)
322  {
324  WRITE_PORT_UCHAR(SEQDATA, Registers->Sequencer[i]);
325  }
326 
327  /* Synchronous reset off */
328  WRITE_PORT_UCHAR(SEQ, 0x00);
329  WRITE_PORT_UCHAR(SEQDATA, 0x03);
330 
331  /* Deprotect CRT registers 0-7 */
332  WRITE_PORT_UCHAR(CRTC, 0x11);
333  WRITE_PORT_UCHAR(CRTCDATA, Registers->CRT[0x11] & 0x7f);
334 
335  /* Write CRT registers */
336  for (i = 0; i < sizeof(Registers->CRT); i++)
337  {
339  WRITE_PORT_UCHAR(CRTCDATA, Registers->CRT[i]);
340  }
341 
342  /* Write graphics controller registers */
343  for (i = 0; i < sizeof(Registers->Graphics); i++)
344  {
346  WRITE_PORT_UCHAR(GRAPHICSDATA, Registers->Graphics[i]);
347  }
348 
349  /* Write attribute controller registers */
350  for (i = 0; i < sizeof(Registers->Attribute); i++)
351  {
354  WRITE_PORT_UCHAR(ATTRIB, Registers->Attribute[i]);
355  }
356 
357  /* Set the PEL mask */
358  WRITE_PORT_UCHAR(PELMASK, 0xff);
359 }
#define CRTCDATA
Definition: blue.h:138
#define GRAPHICSDATA
Definition: blue.h:140
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
UCHAR Sequencer[5]
Definition: blue.c:50
#define ATTRIB
Definition: blue.h:141
#define MISC
Definition: blue.h:134
#define PELMASK
Definition: blue.h:143
unsigned int UINT32
UCHAR Misc
Definition: blue.c:51
UCHAR Graphics[9]
Definition: blue.c:49
#define SEQ
Definition: blue.h:135
#define STATUS
Definition: blue.h:142
UCHAR CRT[24]
Definition: blue.c:47
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
UCHAR Attribute[21]
Definition: blue.c:48
#define CRTC
Definition: blue.h:137
#define SEQDATA
Definition: blue.h:136
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
#define GRAPHICS
Definition: blue.h:139

Referenced by ScrAcquireOwnership().

◆ ScrWrite()

static NTSTATUS NTAPI ScrWrite ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)
static

Definition at line 698 of file blue.c.

701 {
704  PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
705  PCHAR pch = Irp->UserBuffer;
706  PUCHAR vidmem;
707  ULONG i;
708  ULONG j, offset;
709  USHORT cursorx, cursory;
710  USHORT rows, columns;
711  BOOLEAN processed = !!(DeviceExtension->Mode & ENABLE_PROCESSED_OUTPUT);
712 
713  if (!DeviceExtension->Enabled || !DeviceExtension->VideoMemory)
714  {
715  /* Display is not enabled, we're not allowed to touch it */
717 
718  Irp->IoStatus.Status = Status;
720 
721  return Status;
722  }
723 
724  vidmem = DeviceExtension->VideoMemory;
725  rows = DeviceExtension->Rows;
726  columns = DeviceExtension->Columns;
727  cursorx = DeviceExtension->CursorX;
728  cursory = DeviceExtension->CursorY;
729 
730  if (!processed)
731  {
732  /* Raw output mode */
733 
734  /* Calculate the offset from the cursor position */
735  offset = cursorx + cursory * columns;
736 
737  // FIXME: Does the buffer only contains chars? or chars + attributes?
738  // FIXME2: Fix buffer overflow.
739  RtlCopyMemory(&vidmem[offset * 2], pch, stk->Parameters.Write.Length);
740  offset += (stk->Parameters.Write.Length / 2);
741 
742  /* Set the cursor position, clipping it to the screen */
743  cursorx = (USHORT)(offset % columns);
744  cursory = (USHORT)(offset / columns);
745  // cursorx = min(max(cursorx, 0), columns - 1);
746  cursory = min(max(cursory, 0), rows - 1);
747  }
748  else
749  {
750  /* Cooked output mode */
751  for (i = 0; i < stk->Parameters.Write.Length; i++, pch++)
752  {
753  switch (*pch)
754  {
755  case '\b':
756  {
757  if (cursorx > 0)
758  {
759  cursorx--;
760  }
761  else if (cursory > 0)
762  {
763  cursory--;
764  cursorx = columns - 1;
765  }
766  offset = cursorx + cursory * columns;
767  vidmem[offset * 2] = ' ';
768  vidmem[offset * 2 + 1] = (char)DeviceExtension->CharAttribute;
769  break;
770  }
771 
772  case '\n':
773  cursory++;
774  /* Fall back */
775  case '\r':
776  cursorx = 0;
777  break;
778 
779  case '\t':
780  {
781  offset = TAB_WIDTH - (cursorx % TAB_WIDTH);
782  while (offset--)
783  {
784  vidmem[(cursorx + cursory * columns) * 2] = ' ';
785  cursorx++;
786  if (cursorx >= columns)
787  {
788  cursorx = 0;
789  cursory++;
790  /* We jumped to the next line, stop there */
791  break;
792  }
793  }
794  break;
795  }
796 
797  default:
798  {
799  offset = cursorx + cursory * columns;
800  vidmem[offset * 2] = *pch;
801  vidmem[offset * 2 + 1] = (char)DeviceExtension->CharAttribute;
802  cursorx++;
803  if (cursorx >= columns)
804  {
805  cursorx = 0;
806  cursory++;
807  }
808  break;
809  }
810  }
811 
812  /* Scroll up the contents of the screen if we are at the end */
813  if (cursory >= rows)
814  {
816 
818  &vidmem[columns * 2],
819  columns * (rows - 1) * 2);
820 
821  LinePtr = (PUSHORT)&vidmem[columns * (rows - 1) * 2];
822 
823  for (j = 0; j < columns; j++)
824  {
825  LinePtr[j] = DeviceExtension->CharAttribute << 8;
826  }
827  cursory = rows - 1;
828  for (j = 0; j < columns; j++)
829  {
830  offset = j + cursory * columns;
831  vidmem[offset * 2] = ' ';
832  vidmem[offset * 2 + 1] = (char)DeviceExtension->CharAttribute;
833  }
834  }
835  }
836  }
837 
838  /* Set the cursor position */
839  ASSERT((0 <= cursorx) && (cursorx < DeviceExtension->Columns));
840  ASSERT((0 <= cursory) && (cursory < DeviceExtension->Rows));
841  DeviceExtension->CursorX = cursorx;
842  DeviceExtension->CursorY = cursory;
843  ScrSetCursor(DeviceExtension);
844 
846 
847  Irp->IoStatus.Status = Status;
849 
850  return Status;
851 }
signed char * PCHAR
Definition: retypes.h:7
#define max(a, b)
Definition: svc.c:63
PBYTE vidmem
Definition: vgavideo.c:18
static VOID FASTCALL ScrSetCursor(_In_ PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:363
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
struct Line * LinePtr
Definition: ncftp.h:78
#define pch(ap)
Definition: match.c:418
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
unsigned char BOOLEAN
unsigned char
Definition: typeof.h:29
_In_ ULONG Rows
Definition: haltypes.h:7
#define IoCompleteRequest
Definition: irp.c:1240
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 GLint GLint j
Definition: glfuncs.h:250
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
if(!(yy_init))
Definition: macro.lex.yy.c:714
GLintptr offset
Definition: glext.h:5920
Definition: ncftp.h:79
#define IO_VIDEO_INCREMENT
Definition: iotypes.h:592
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:53
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
static const COLUMN_LIST Columns[]
Definition: listview.c:19
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
unsigned short USHORT
Definition: pedump.c:61
#define TAB_WIDTH
Definition: blue.h:16
#define min(a, b)
Definition: monoChain.cc:55
static int processed(const type_t *type)
Definition: typegen.c:2236
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
unsigned short * PUSHORT
Definition: retypes.h:2

Variable Documentation

◆ DefaultPalette

const UCHAR DefaultPalette[]
static
Initial value:
=
{
0, 0, 0,
0, 0, 0xC0,
0, 0xC0, 0,
0, 0xC0, 0xC0,
0xC0, 0, 0,
0xC0, 0, 0xC0,
0xC0, 0xC0, 0,
0xC0, 0xC0, 0xC0,
0x80, 0x80, 0x80,
0, 0, 0xFF,
0, 0xFF, 0,
0, 0xFF, 0xFF,
0xFF, 0, 0,
0xFF, 0, 0xFF,
0xFF, 0xFF, 0,
0xFF, 0xFF, 0xFF
}

Definition at line 70 of file blue.c.

Referenced by DrvDisablePDEV(), ScrAcquireOwnership(), and VidpBuildColor().

◆ InbvMonitoring

BOOLEAN InbvMonitoring = FALSE
static

Definition at line 100 of file blue.c.

Referenced by InbvMonitorThread(), and ScrResetDisplayParametersEx().

◆ InbvThreadHandle

HANDLE InbvThreadHandle = NULL
static

Definition at line 99 of file blue.c.

Referenced by ScrInbvCleanup(), and ScrInbvInitialize().

◆ ResetDisplayParametersDeviceExtension

PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension = NULL
static

Definition at line 98 of file blue.c.

Referenced by DriverEntry(), InbvMonitorThread(), ScrInbvCleanup(), and ScrResetDisplayParametersEx().

◆ ScrCreateClose

DRIVER_DISPATCH ScrCreateClose
static

Definition at line 675 of file blue.c.

Referenced by DriverEntry().

◆ ScrDispatch

DRIVER_DISPATCH ScrDispatch
static

Definition at line 1569 of file blue.c.

Referenced by DriverEntry().

◆ ScrIoControl

DRIVER_DISPATCH ScrIoControl
static

Definition at line 853 of file blue.c.

Referenced by DriverEntry().

◆ ScrWrite

DRIVER_DISPATCH ScrWrite
static

Definition at line 695 of file blue.c.

Referenced by DriverEntry().

◆ VidpMode3Regs

const VGA_REGISTERS VidpMode3Regs
static
Initial value:
=
{
{0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, 0x47, 0x1E, 0x00,
0x00, 0x00, 0x05, 0xF0, 0x9C, 0x8E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3},
{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B,
0x3C, 0x3D, 0x3E, 0x3F, 0x0C, 0x00, 0x0F, 0x08, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x00, 0xFF},
{0x03, 0x00, 0x03, 0x00, 0x02},
0x67
}

Definition at line 54 of file blue.c.

Referenced by ScrAcquireOwnership().