ReactOS  0.4.14-dev-999-g61c8d34
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 1544 of file blue.c.

1547 {
1548  NTSTATUS Status;
1550  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\BlueScreen");
1551  UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\??\\BlueScreen");
1552 
1553  DPRINT("Screen Driver 0.0.6\n");
1554 
1560 
1562  sizeof(DEVICE_EXTENSION),
1563  &DeviceName,
1566  TRUE,
1567  &DeviceObject);
1568  if (!NT_SUCCESS(Status))
1569  {
1570  return Status;
1571  }
1572 
1573  Status = IoCreateSymbolicLink(&SymlinkName, &DeviceName);
1574  if (NT_SUCCESS(Status))
1575  {
1576  /* By default disable the screen (but don't touch INBV: ResetDisplayParametersDeviceExtension is still NULL) */
1578  /* Now set ResetDisplayParametersDeviceExtension to enable synchronizing with INBV */
1581  }
1582  else
1583  {
1585  }
1586  return Status;
1587 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define FILE_DEVICE_SCREEN
Definition: winioctl.h:133
LONG NTSTATUS
Definition: precomp.h:26
static DRIVER_DISPATCH ScrDispatch
Definition: blue.c:1520
static BOOLEAN ScrResetScreen(_In_ PDEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FullReset, _In_ BOOLEAN Enable)
Definition: blue.c:496
WCHAR DeviceName[]
Definition: adapter.cpp:21
static DRIVER_DISPATCH ScrCreateClose
Definition: blue.c:661
static DRIVER_DISPATCH ScrWrite
Definition: blue.c:681
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
#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:839
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IRP_MJ_READ
Definition: rdpdr.c:46
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
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:97
#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 188 of file blue.c.

190 {
191  LARGE_INTEGER Delay;
192  USHORT i;
193 
195 
196  while (TRUE)
197  {
198  /*
199  * During one second, check the INBV status each 100 milliseconds,
200  * then revert to 1 second delay.
201  */
202  i = 10;
203  Delay.QuadPart = (LONGLONG)-100*1000*10; // 100 millisecond delay
204  while (!InbvMonitoring)
205  {
207 
208  if ((i > 0) && (--i == 0))
209  Delay.QuadPart = (LONGLONG)-1*1000*1000*10; // 1 second delay
210  }
211 
212  /*
213  * Loop while the display is owned by INBV. We cannot do anything else
214  * than polling since INBV does not offer a proper notification system.
215  *
216  * During one second, check the INBV status each 100 milliseconds,
217  * then revert to 1 second delay.
218  */
219  i = 10;
220  Delay.QuadPart = (LONGLONG)-100*1000*10; // 100 millisecond delay
221  while (InbvCheckDisplayOwnership())
222  {
224 
225  if ((i > 0) && (--i == 0))
226  Delay.QuadPart = (LONGLONG)-1*1000*1000*10; // 1 second delay
227  }
228 
229  /* Reset the monitoring */
231 
232  /*
233  * Somebody released INBV display ownership, usually by invoking
234  * InbvNotifyDisplayOwnershipLost(). However the caller of this
235  * function certainly specified a different callback than ours.
236  * As we are going to be the only owner of the active display,
237  * we need to re-register our own display reset callback.
238  */
240 
241  /* Re-enable the screen, keeping the original screen settings */
244  }
245 
246  // FIXME: See ScrInbvCleanup().
247  // PsTerminateSystemThread(STATUS_SUCCESS);
248 }
VOID NTAPI InbvNotifyDisplayOwnershipLost(IN INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:641
#define TRUE
Definition: types.h:120
static BOOLEAN InbvMonitoring
Definition: blue.c:99
#define LOW_REALTIME_PRIORITY
static BOOLEAN ScrResetScreen(_In_ PDEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FullReset, _In_ BOOLEAN Enable)
Definition: blue.c:496
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
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:67
static BOOLEAN NTAPI ScrResetDisplayParameters(_In_ ULONG Columns, _In_ ULONG Rows)
Definition: blue.c:146
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:556
#define KeGetCurrentThread
Definition: hal.h:44
static PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension
Definition: blue.c:97
LONGLONG QuadPart
Definition: typedefs.h:113

Referenced by ScrInbvInitialize().

◆ ScrAcquireOwnership()

static VOID FASTCALL ScrAcquireOwnership ( _In_ PDEVICE_EXTENSION  DeviceExtension)
static

Definition at line 411 of file blue.c.

413 {
414  UCHAR data, value;
415  ULONG offset;
416  ULONG Index;
417 
418  _disable();
419 
421 
422  /* Disable screen and enable palette access */
424  WRITE_PORT_UCHAR(ATTRIB, 0x00);
425 
426  for (Index = 0; Index < sizeof(DefaultPalette) / 3; Index++)
427  {
432  }
433 
434  /* Enable screen and disable palette access */
436  WRITE_PORT_UCHAR(ATTRIB, 0x20);
437 
438  /* Switch blinking characters off */
443  data = data & ~0x08;
447 
448  /* Read screen information from CRT controller */
450  DeviceExtension->Columns = READ_PORT_UCHAR(CRTC_DATA) + 1;
452  DeviceExtension->Rows = READ_PORT_UCHAR(CRTC_DATA);
455  DeviceExtension->Rows |= (((data & 0x02) << 7) | ((data & 0x40) << 3));
456  DeviceExtension->Rows++;
458  DeviceExtension->ScanLines = (READ_PORT_UCHAR(CRTC_DATA) & 0x1F) + 1;
459 
460  /* Retrieve the current output cursor position */
464  offset += (READ_PORT_UCHAR(CRTC_DATA) << 8);
465 
466  /* Show blinking cursor */
467  // FIXME: cursor block? Call ScrSetCursorShape() instead?
469  WRITE_PORT_UCHAR(CRTC_DATA, (DeviceExtension->ScanLines - 1) & 0x1F);
471  data = READ_PORT_UCHAR(CRTC_DATA) & 0xE0;
473  data | ((DeviceExtension->ScanLines - 1) & 0x1F));
474 
475  _enable();
476 
477  /* Calculate number of text rows */
478  DeviceExtension->Rows = DeviceExtension->Rows / DeviceExtension->ScanLines;
479 
480  /* Set the cursor position, clipping it to the screen */
481  DeviceExtension->CursorX = (USHORT)(offset % DeviceExtension->Columns);
482  DeviceExtension->CursorY = (USHORT)(offset / DeviceExtension->Columns);
483  // DeviceExtension->CursorX = min(max(DeviceExtension->CursorX, 0), DeviceExtension->Columns - 1);
484  DeviceExtension->CursorY = min(max(DeviceExtension->CursorY, 0), DeviceExtension->Rows - 1);
485 
486  /* Upload a default font for the current codepage */
487  ScrLoadFontTable(DeviceExtension->CodePage);
488 
489  DPRINT("%d Columns %d Rows %d Scanlines\n",
490  DeviceExtension->Columns,
491  DeviceExtension->Rows,
492  DeviceExtension->ScanLines);
493 }
#define CRTC_SCANLINES
Definition: blue.h:108
#define max(a, b)
Definition: svc.c:63
static const VGA_REGISTERS VidpMode3Regs
Definition: blue.c:53
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
void __cdecl _enable(void)
Definition: intrin_arm.h:373
GLintptr offset
Definition: glext.h:5920
#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:69
#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
static const UCHAR Index[8]
Definition: usbohci.c:18
#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 CRTC_OVERFLOW
Definition: blue.h:106
GLsizei const GLfloat * value
Definition: glext.h:6069
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
unsigned int ULONG
Definition: retypes.h:1
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
static VOID FASTCALL ScrSetRegisters(const VGA_REGISTERS *Registers)
Definition: blue.c:308
#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 664 of file blue.c.

667 {
669 
671 
672  if (stk->MajorFunction == IRP_MJ_CREATE)
673  Irp->IoStatus.Information = FILE_OPENED;
674  // else: IRP_MJ_CLOSE
675 
676  Irp->IoStatus.Status = STATUS_SUCCESS;
678  return STATUS_SUCCESS;
679 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define FILE_OPENED
Definition: nt_native.h:769
#define IoCompleteRequest
Definition: irp.c:1240
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ ScrDispatch()

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

Definition at line 1523 of file blue.c.

1526 {
1528 
1530 
1531  DPRINT1("ScrDispatch(0x%p): stk->MajorFunction = %lu UNIMPLEMENTED\n",
1532  DeviceObject, stk->MajorFunction);
1533 
1534  Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
1536  return STATUS_NOT_IMPLEMENTED;
1537 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define IoCompleteRequest
Definition: irp.c:1240
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:566

◆ ScrInbvCleanup()

static NTSTATUS ScrInbvCleanup ( VOID  )
static

Definition at line 277 of file blue.c.

278 {
279  // HANDLE ThreadHandle;
280 
281  // ResetDisplayParametersDeviceExtension = NULL;
283  {
286  // or InbvAcquireDisplayOwnership(); ?
287  }
288 
289 #if 0
290  // TODO: Find the best way to communicate the request.
291  /* Signal the INBV monitoring thread and wait for it to terminate */
293  if (ThreadHandle)
294  {
295  ZwWaitForSingleObject(ThreadHandle, Executive, KernelMode, FALSE, NULL);
296  /* Close its handle */
297  ObCloseHandle(ThreadHandle, KernelMode);
298  }
299 #endif
300 
301  return STATUS_SUCCESS;
302 }
VOID NTAPI InbvNotifyDisplayOwnershipLost(IN INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:641
smooth NULL
Definition: ftsmooth.c:416
static BOOLEAN NTAPI ScrResetDisplayParametersEx(_In_ ULONG Columns, _In_ ULONG Rows, _In_ BOOLEAN CalledByInbv)
Definition: blue.c:118
#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:98
static PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension
Definition: blue.c:97
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by ScrResetScreen().

◆ ScrInbvInitialize()

static NTSTATUS ScrInbvInitialize ( VOID  )
static

Definition at line 251 of file blue.c.

252 {
253  /* Create the INBV monitoring thread if needed */
254  if (!InbvThreadHandle)
255  {
258 
260  0,
262  NULL,
263  NULL,
265  NULL);
266  if (!NT_SUCCESS(Status))
268  }
269 
270  /* Re-register the display reset callback with INBV */
272 
273  return STATUS_SUCCESS;
274 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
VOID NTAPI InbvNotifyDisplayOwnershipLost(IN INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:641
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static BOOLEAN NTAPI ScrResetDisplayParameters(_In_ ULONG Columns, _In_ ULONG Rows)
Definition: blue.c:146
static VOID NTAPI InbvMonitorThread(_In_ PVOID Context)
Definition: blue.c:188
Status
Definition: gdiplustypes.h:24
static HANDLE InbvThreadHandle
Definition: blue.c:98
#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
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by ScrResetScreen().

◆ ScrIoControl()

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

Definition at line 842 of file blue.c.

845 {
849 
850  switch (stk->Parameters.DeviceIoControl.IoControlCode)
851  {
853  {
854  BOOLEAN Enable;
855 
856  /* Validate input buffer */
857  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG))
858  {
860  break;
861  }
862  ASSERT(Irp->AssociatedIrp.SystemBuffer);
863 
864  Enable = !!*(PULONG)Irp->AssociatedIrp.SystemBuffer;
865 
866  /* Fully enable or disable the screen */
867  Status = (ScrResetScreen(DeviceExtension, TRUE, Enable)
869  Irp->IoStatus.Information = 0;
870  break;
871  }
872 
874  {
876  USHORT rows = DeviceExtension->Rows;
877  USHORT columns = DeviceExtension->Columns;
878 
879  /* Validate output buffer */
880  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_SCREEN_BUFFER_INFO))
881  {
883  break;
884  }
885  ASSERT(Irp->AssociatedIrp.SystemBuffer);
886 
887  pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
889 
890  pcsbi->dwSize.X = columns;
891  pcsbi->dwSize.Y = rows;
892 
893  pcsbi->dwCursorPosition.X = DeviceExtension->CursorX;
894  pcsbi->dwCursorPosition.Y = DeviceExtension->CursorY;
895 
896  pcsbi->wAttributes = DeviceExtension->CharAttribute;
897 
898  pcsbi->srWindow.Left = 0;
899  pcsbi->srWindow.Right = columns - 1;
900  pcsbi->srWindow.Top = 0;
901  pcsbi->srWindow.Bottom = rows - 1;
902 
903  pcsbi->dwMaximumWindowSize.X = columns;
904  pcsbi->dwMaximumWindowSize.Y = rows;
905 
906  Irp->IoStatus.Information = sizeof(CONSOLE_SCREEN_BUFFER_INFO);
908  break;
909  }
910 
912  {
914 
915  /* Validate input buffer */
916  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(CONSOLE_SCREEN_BUFFER_INFO))
917  {
919  break;
920  }
921  ASSERT(Irp->AssociatedIrp.SystemBuffer);
922 
923  pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
924 
925  if ( pcsbi->dwCursorPosition.X < 0 || pcsbi->dwCursorPosition.X >= DeviceExtension->Columns ||
926  pcsbi->dwCursorPosition.Y < 0 || pcsbi->dwCursorPosition.Y >= DeviceExtension->Rows )
927  {
928  Irp->IoStatus.Information = 0;
930  break;
931  }
932 
933  DeviceExtension->CharAttribute = pcsbi->wAttributes;
934 
935  /* Set the cursor position */
936  ASSERT((0 <= pcsbi->dwCursorPosition.X) && (pcsbi->dwCursorPosition.X < DeviceExtension->Columns));
937  ASSERT((0 <= pcsbi->dwCursorPosition.Y) && (pcsbi->dwCursorPosition.Y < DeviceExtension->Rows));
938  DeviceExtension->CursorX = pcsbi->dwCursorPosition.X;
939  DeviceExtension->CursorY = pcsbi->dwCursorPosition.Y;
940  if (DeviceExtension->Enabled)
941  ScrSetCursor(DeviceExtension);
942 
943  Irp->IoStatus.Information = 0;
945  break;
946  }
947 
949  {
951 
952  /* Validate output buffer */
953  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_CURSOR_INFO))
954  {
956  break;
957  }
958  ASSERT(Irp->AssociatedIrp.SystemBuffer);
959 
960  pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
961  RtlZeroMemory(pcci, sizeof(CONSOLE_CURSOR_INFO));
962 
963  pcci->dwSize = DeviceExtension->CursorSize;
964  pcci->bVisible = DeviceExtension->CursorVisible;
965 
966  Irp->IoStatus.Information = sizeof(CONSOLE_CURSOR_INFO);
968  break;
969  }
970 
972  {
974 
975  /* Validate input buffer */
976  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(CONSOLE_CURSOR_INFO))
977  {
979  break;
980  }
981  ASSERT(Irp->AssociatedIrp.SystemBuffer);
982 
983  pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
984 
985  DeviceExtension->CursorSize = pcci->dwSize;
986  DeviceExtension->CursorVisible = pcci->bVisible;
987  if (DeviceExtension->Enabled)
988  ScrSetCursorShape(DeviceExtension);
989 
990  Irp->IoStatus.Information = 0;
992  break;
993  }
994 
996  {
997  PCONSOLE_MODE pcm;
998 
999  /* Validate output buffer */
1000  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_MODE))
1001  {
1003  break;
1004  }
1005  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1006 
1007  pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
1008  RtlZeroMemory(pcm, sizeof(CONSOLE_MODE));
1009 
1010  pcm->dwMode = DeviceExtension->Mode;
1011 
1012  Irp->IoStatus.Information = sizeof(CONSOLE_MODE);
1014  break;
1015  }
1016 
1018  {
1019  PCONSOLE_MODE pcm;
1020 
1021  /* Validate input buffer */
1022  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(CONSOLE_MODE))
1023  {
1025  break;
1026  }
1027  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1028 
1029  pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
1030  DeviceExtension->Mode = pcm->dwMode;
1031 
1032  Irp->IoStatus.Information = 0;
1034  break;
1035  }
1036 
1038  {
1039  POUTPUT_ATTRIBUTE Buf;
1040  PUCHAR vidmem;
1041  ULONG offset;
1042  ULONG dwCount;
1043  ULONG nMaxLength;
1044 
1045  /* Validate input and output buffers */
1046  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(OUTPUT_ATTRIBUTE) ||
1047  stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(OUTPUT_ATTRIBUTE))
1048  {
1050  break;
1051  }
1052  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1053 
1054  Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
1055  nMaxLength = Buf->nLength;
1056 
1057  Buf->dwTransfered = 0;
1058  Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
1059 
1060  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
1061  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows ||
1062  nMaxLength == 0 )
1063  {
1065  break;
1066  }
1067 
1068  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1069  {
1070  vidmem = DeviceExtension->VideoMemory;
1071  offset = (Buf->dwCoord.X + Buf->dwCoord.Y * DeviceExtension->Columns) * 2 + 1;
1072 
1073  nMaxLength = min(nMaxLength,
1074  (DeviceExtension->Rows - Buf->dwCoord.Y)
1075  * DeviceExtension->Columns - Buf->dwCoord.X);
1076 
1077  for (dwCount = 0; dwCount < nMaxLength; dwCount++)
1078  {
1079  vidmem[offset + (dwCount * 2)] = (char)Buf->wAttribute;
1080  }
1081  Buf->dwTransfered = dwCount;
1082  }
1083 
1085  break;
1086  }
1087 
1089  {
1090  POUTPUT_ATTRIBUTE Buf;
1091  PUSHORT pAttr;
1092  PUCHAR vidmem;
1093  ULONG offset;
1094  ULONG dwCount;
1095  ULONG nMaxLength;
1096 
1097  /* Validate input buffer */
1098  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(OUTPUT_ATTRIBUTE))
1099  {
1101  break;
1102  }
1103  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1104 
1105  Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
1106  Irp->IoStatus.Information = 0;
1107 
1108  /* Validate output buffer */
1109  if (stk->Parameters.DeviceIoControl.OutputBufferLength == 0)
1110  {
1112  break;
1113  }
1114  ASSERT(Irp->MdlAddress);
1115  pAttr = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1116  if (pAttr == NULL)
1117  {
1119  break;
1120  }
1121 
1122  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
1123  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
1124  {
1126  break;
1127  }
1128 
1129  nMaxLength = stk->Parameters.DeviceIoControl.OutputBufferLength;
1130  nMaxLength /= sizeof(USHORT);
1131 
1132  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1133  {
1134  vidmem = DeviceExtension->VideoMemory;
1135  offset = (Buf->dwCoord.X + Buf->dwCoord.Y * DeviceExtension->Columns) * 2 + 1;
1136 
1137  nMaxLength = min(nMaxLength,
1138  (DeviceExtension->Rows - Buf->dwCoord.Y)
1139  * DeviceExtension->Columns - Buf->dwCoord.X);
1140 
1141  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pAttr++)
1142  {
1143  *((PCHAR)pAttr) = vidmem[offset + (dwCount * 2)];
1144  }
1145  Irp->IoStatus.Information = dwCount * sizeof(USHORT);
1146  }
1147 
1149  break;
1150  }
1151 
1153  {
1154  COORD dwCoord;
1155  PCOORD pCoord;
1156  PUSHORT pAttr;
1157  PUCHAR vidmem;
1158  ULONG offset;
1159  ULONG dwCount;
1160  ULONG nMaxLength;
1161 
1162  //
1163  // NOTE: For whatever reason no OUTPUT_ATTRIBUTE structure
1164  // is used for this IOCTL.
1165  //
1166 
1167  /* Validate output buffer */
1168  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(COORD))
1169  {
1171  break;
1172  }
1173  ASSERT(Irp->MdlAddress);
1174  pCoord = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1175  if (pCoord == NULL)
1176  {
1178  break;
1179  }
1180  /* Capture the input info data */
1181  dwCoord = *pCoord;
1182 
1183  nMaxLength = stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(COORD);
1184  nMaxLength /= sizeof(USHORT);
1185 
1186  Irp->IoStatus.Information = 0;
1187 
1188  if ( dwCoord.X < 0 || dwCoord.X >= DeviceExtension->Columns ||
1189  dwCoord.Y < 0 || dwCoord.Y >= DeviceExtension->Rows ||
1190  nMaxLength == 0 )
1191  {
1193  break;
1194  }
1195 
1196  pAttr = (PUSHORT)(pCoord + 1);
1197 
1198  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1199  {
1200  vidmem = DeviceExtension->VideoMemory;
1201  offset = (dwCoord.X + dwCoord.Y * DeviceExtension->Columns) * 2 + 1;
1202 
1203  nMaxLength = min(nMaxLength,
1204  (DeviceExtension->Rows - dwCoord.Y)
1205  * DeviceExtension->Columns - dwCoord.X);
1206 
1207  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pAttr++)
1208  {
1209  vidmem[offset + (dwCount * 2)] = *((PCHAR)pAttr);
1210  }
1211  Irp->IoStatus.Information = dwCount * sizeof(USHORT);
1212  }
1213 
1215  break;
1216  }
1217 
1219  {
1220  /* Validate input buffer */
1221  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(USHORT))
1222  {
1224  break;
1225  }
1226  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1227 
1228  DeviceExtension->CharAttribute = *(PUSHORT)Irp->AssociatedIrp.SystemBuffer;
1229 
1230  Irp->IoStatus.Information = 0;
1232  break;
1233  }
1234 
1236  {
1237  POUTPUT_CHARACTER Buf;
1238  PUCHAR vidmem;
1239  ULONG offset;
1240  ULONG dwCount;
1241  ULONG nMaxLength;
1242 
1243  /* Validate input and output buffers */
1244  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(OUTPUT_CHARACTER) ||
1245  stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(OUTPUT_CHARACTER))
1246  {
1248  break;
1249  }
1250  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1251 
1252  Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
1253  nMaxLength = Buf->nLength;
1254 
1255  Buf->dwTransfered = 0;
1256  Irp->IoStatus.Information = sizeof(OUTPUT_CHARACTER);
1257 
1258  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
1259  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows ||
1260  nMaxLength == 0 )
1261  {
1263  break;
1264  }
1265 
1266  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1267  {
1268  vidmem = DeviceExtension->VideoMemory;
1269  offset = (Buf->dwCoord.X + Buf->dwCoord.Y * DeviceExtension->Columns) * 2;
1270 
1271  nMaxLength = min(nMaxLength,
1272  (DeviceExtension->Rows - Buf->dwCoord.Y)
1273  * DeviceExtension->Columns - Buf->dwCoord.X);
1274 
1275  for (dwCount = 0; dwCount < nMaxLength; dwCount++)
1276  {
1277  vidmem[offset + (dwCount * 2)] = (char)Buf->cCharacter;
1278  }
1279  Buf->dwTransfered = dwCount;
1280  }
1281 
1283  break;
1284  }
1285 
1287  {
1288  POUTPUT_CHARACTER Buf;
1289  PCHAR pChar;
1290  PUCHAR vidmem;
1291  ULONG offset;
1292  ULONG dwCount;
1293  ULONG nMaxLength;
1294 
1295  /* Validate input buffer */
1296  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(OUTPUT_CHARACTER))
1297  {
1299  break;
1300  }
1301  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1302 
1303  Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
1304  Irp->IoStatus.Information = 0;
1305 
1306  /* Validate output buffer */
1307  if (stk->Parameters.DeviceIoControl.OutputBufferLength == 0)
1308  {
1310  break;
1311  }
1312  ASSERT(Irp->MdlAddress);
1313  pChar = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1314  if (pChar == NULL)
1315  {
1317  break;
1318  }
1319 
1320  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
1321  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
1322  {
1324  break;
1325  }
1326 
1327  nMaxLength = stk->Parameters.DeviceIoControl.OutputBufferLength;
1328 
1329  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1330  {
1331  vidmem = DeviceExtension->VideoMemory;
1332  offset = (Buf->dwCoord.X + Buf->dwCoord.Y * DeviceExtension->Columns) * 2;
1333 
1334  nMaxLength = min(nMaxLength,
1335  (DeviceExtension->Rows - Buf->dwCoord.Y)
1336  * DeviceExtension->Columns - Buf->dwCoord.X);
1337 
1338  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pChar++)
1339  {
1340  *pChar = vidmem[offset + (dwCount * 2)];
1341  }
1342  Irp->IoStatus.Information = dwCount * sizeof(CHAR);
1343  }
1344 
1346  break;
1347  }
1348 
1350  {
1351  COORD dwCoord;
1352  PCOORD pCoord;
1353  PCHAR pChar;
1354  PUCHAR vidmem;
1355  ULONG offset;
1356  ULONG dwCount;
1357  ULONG nMaxLength;
1358 
1359  //
1360  // NOTE: For whatever reason no OUTPUT_CHARACTER structure
1361  // is used for this IOCTL.
1362  //
1363 
1364  /* Validate output buffer */
1365  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(COORD))
1366  {
1368  break;
1369  }
1370  ASSERT(Irp->MdlAddress);
1371  pCoord = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1372  if (pCoord == NULL)
1373  {
1375  break;
1376  }
1377  /* Capture the input info data */
1378  dwCoord = *pCoord;
1379 
1380  nMaxLength = stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(COORD);
1381  Irp->IoStatus.Information = 0;
1382 
1383  if ( dwCoord.X < 0 || dwCoord.X >= DeviceExtension->Columns ||
1384  dwCoord.Y < 0 || dwCoord.Y >= DeviceExtension->Rows ||
1385  nMaxLength == 0 )
1386  {
1388  break;
1389  }
1390 
1391  pChar = (PCHAR)(pCoord + 1);
1392 
1393  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1394  {
1395  vidmem = DeviceExtension->VideoMemory;
1396  offset = (dwCoord.X + dwCoord.Y * DeviceExtension->Columns) * 2;
1397 
1398  nMaxLength = min(nMaxLength,
1399  (DeviceExtension->Rows - dwCoord.Y)
1400  * DeviceExtension->Columns - dwCoord.X);
1401 
1402  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pChar++)
1403  {
1404  vidmem[offset + (dwCount * 2)] = *pChar;
1405  }
1406  Irp->IoStatus.Information = dwCount * sizeof(CHAR);
1407  }
1408 
1410  break;
1411  }
1412 
1413  case IOCTL_CONSOLE_DRAW:
1414  {
1415  CONSOLE_DRAW ConsoleDraw;
1416  PCONSOLE_DRAW pConsoleDraw;
1417  PUCHAR Src, Dest;
1418  UINT32 SrcDelta, DestDelta, i;
1419 
1420  /* Validate output buffer */
1421  if (stk->Parameters.DeviceIoControl.OutputBufferLength < sizeof(CONSOLE_DRAW))
1422  {
1424  break;
1425  }
1426  ASSERT(Irp->MdlAddress);
1427  pConsoleDraw = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
1428  if (pConsoleDraw == NULL)
1429  {
1431  break;
1432  }
1433  /* Capture the input info data */
1434  ConsoleDraw = *pConsoleDraw;
1435 
1436  /* Check whether we have the size for the header plus the data area */
1437  if ((stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(CONSOLE_DRAW)) / 2
1438  < ((ULONG)ConsoleDraw.SizeX * (ULONG)ConsoleDraw.SizeY))
1439  {
1441  break;
1442  }
1443 
1444  // TODO: For the moment if the ConsoleDraw rectangle has borders
1445  // out of the screen-buffer we just bail out. Would it be better
1446  // to actually clip the rectangle within its borders instead?
1447  if ( ConsoleDraw.X < 0 || ConsoleDraw.X >= DeviceExtension->Columns ||
1448  ConsoleDraw.Y < 0 || ConsoleDraw.Y >= DeviceExtension->Rows )
1449  {
1451  break;
1452  }
1453  if ( ConsoleDraw.SizeX >= DeviceExtension->Columns - ConsoleDraw.X ||
1454  ConsoleDraw.SizeY >= DeviceExtension->Rows - ConsoleDraw.Y )
1455  {
1457  break;
1458  }
1459 
1460  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1461  {
1462  Src = (PUCHAR)(pConsoleDraw + 1);
1463  SrcDelta = ConsoleDraw.SizeX * 2;
1464  Dest = DeviceExtension->VideoMemory +
1465  (ConsoleDraw.X + ConsoleDraw.Y * DeviceExtension->Columns) * 2;
1466  DestDelta = DeviceExtension->Columns * 2;
1467  /* 2 == sizeof(CHAR) + sizeof(BYTE) */
1468 
1469  /* Copy each line */
1470  for (i = 0; i < ConsoleDraw.SizeY; i++)
1471  {
1472  RtlCopyMemory(Dest, Src, SrcDelta);
1473  Src += SrcDelta;
1474  Dest += DestDelta;
1475  }
1476  }
1477 
1478  /* Set the cursor position, clipping it to the screen */
1479  DeviceExtension->CursorX = min(max(ConsoleDraw.CursorX, 0), DeviceExtension->Columns - 1);
1480  DeviceExtension->CursorY = min(max(ConsoleDraw.CursorY, 0), DeviceExtension->Rows - 1);
1481  if (DeviceExtension->Enabled)
1482  ScrSetCursor(DeviceExtension);
1483 
1484  Irp->IoStatus.Information = 0;
1486  break;
1487  }
1488 
1490  {
1491  /* Validate input buffer */
1492  if (stk->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG))
1493  {
1495  break;
1496  }
1497  ASSERT(Irp->AssociatedIrp.SystemBuffer);
1498 
1499  DeviceExtension->CodePage = *(PULONG)Irp->AssociatedIrp.SystemBuffer;
1500 
1501  /* Upload a font for the codepage if needed */
1502  if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
1503  ScrLoadFontTable(DeviceExtension->CodePage);
1504 
1505  Irp->IoStatus.Information = 0;
1507  break;
1508  }
1509 
1510  default:
1512  }
1513 
1514  Irp->IoStatus.Status = Status;
1516 
1517  return Status;
1518 }
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:382
#define IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:15
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#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:53
#define IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE
Definition: ntddblue.h:16
static VOID FASTCALL ScrSetCursor(_In_ PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:362
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#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
GLintptr offset
Definition: glext.h:5920
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:496
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
#define IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER
Definition: ntddblue.h:18
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 int UINT32
#define IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:13
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#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
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:636
struct _COORD COORD
USHORT CursorX
Definition: ntddblue.h:55
SHORT Bottom
Definition: blue.h:35
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define IOCTL_CONSOLE_GET_MODE
Definition: ntddblue.h:10
SHORT Top
Definition: blue.h:33
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IO_VIDEO_INCREMENT
Definition: iotypes.h:577
USHORT CursorY
Definition: ntddblue.h:56
#define IOCTL_CONSOLE_RESET_SCREEN
Definition: ntddblue.h:4
Definition: bl.h:1338
#define IOCTL_CONSOLE_DRAW
Definition: ntddblue.h:22
Status
Definition: gdiplustypes.h:24
ULONG dwMode
Definition: ntddblue.h:30
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct tagOUTPUT_CHARACTER * POUTPUT_CHARACTER
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
USHORT SizeY
Definition: ntddblue.h:54
unsigned short USHORT
Definition: pedump.c:61
#define IOCTL_CONSOLE_SET_MODE
Definition: ntddblue.h:11
struct tagCONSOLE_MODE CONSOLE_MODE
#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 IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:6
#define IOCTL_CONSOLE_LOADFONT
Definition: ntddblue.h:24
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER
Definition: ntddblue.h:20
SHORT Right
Definition: blue.h:34
struct tagCONSOLE_SCREEN_BUFFER_INFO * PCONSOLE_SCREEN_BUFFER_INFO
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
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 146 of file blue.c.

149 {
150  /* Call the extended function, specifying we were called by INBV */
152 }
#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:118
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 118 of file blue.c.

122 {
123  PDEVICE_EXTENSION DeviceExtension;
124 
125  /* Bail out early if we don't have any resettable adapter */
127  return FALSE; // No adapter found: request HAL to perform a full reset.
128 
129  /*
130  * If we have been unexpectedly called via a callback from
131  * InbvAcquireDisplayOwnership(), start monitoring INBV.
132  */
133  if (CalledByInbv)
135 
136  DeviceExtension = ResetDisplayParametersDeviceExtension;
137  ASSERT(DeviceExtension);
138 
139  /* Disable the screen but don't reset all screen settings (OK at high IRQL) */
140  return ScrResetScreen(DeviceExtension, FALSE, FALSE);
141 }
#define TRUE
Definition: types.h:120
static BOOLEAN InbvMonitoring
Definition: blue.c:99
static BOOLEAN ScrResetScreen(_In_ PDEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FullReset, _In_ BOOLEAN Enable)
Definition: blue.c:496
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension
Definition: blue.c:97

Referenced by ScrInbvCleanup(), and ScrResetDisplayParameters().

◆ ScrResetScreen()

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

Definition at line 496 of file blue.c.

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

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

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

◆ ScrSetCursorShape()

static VOID FASTCALL ScrSetCursorShape ( _In_ PDEVICE_EXTENSION  DeviceExtension)
static

Definition at line 382 of file blue.c.

384 {
385  ULONG size, height;
386  UCHAR data, value;
387 
388  if (!DeviceExtension->VideoMemory)
389  return;
390 
391  height = DeviceExtension->ScanLines;
392  data = (DeviceExtension->CursorVisible) ? 0x00 : 0x20;
393 
394  size = (DeviceExtension->CursorSize * height) / 100;
395  if (size < 1)
396  size = 1;
397 
398  data |= (UCHAR)(height - size);
399 
400  _disable();
404  value = READ_PORT_UCHAR(CRTC_DATA) & 0xE0;
406  _enable();
407 }
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
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
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
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
#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 308 of file blue.c.

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

Referenced by ScrAcquireOwnership().

◆ ScrWrite()

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

Definition at line 684 of file blue.c.

687 {
691  PCHAR pch = Irp->UserBuffer;
692  PUCHAR vidmem;
693  ULONG i;
694  ULONG j, offset;
695  USHORT cursorx, cursory;
696  USHORT rows, columns;
697  BOOLEAN processed = !!(DeviceExtension->Mode & ENABLE_PROCESSED_OUTPUT);
698 
699  if (!DeviceExtension->Enabled || !DeviceExtension->VideoMemory)
700  {
701  /* Display is not enabled, we're not allowed to touch it */
703 
704  Irp->IoStatus.Status = Status;
706 
707  return Status;
708  }
709 
710  vidmem = DeviceExtension->VideoMemory;
711  rows = DeviceExtension->Rows;
712  columns = DeviceExtension->Columns;
713  cursorx = DeviceExtension->CursorX;
714  cursory = DeviceExtension->CursorY;
715 
716  if (!processed)
717  {
718  /* Raw output mode */
719 
720  /* Calculate the offset from the cursor position */
721  offset = cursorx + cursory * columns;
722 
723  // FIXME: Does the buffer only contains chars? or chars + attributes?
724  // FIXME2: Fix buffer overflow.
725  RtlCopyMemory(&vidmem[offset * 2], pch, stk->Parameters.Write.Length);
726  offset += (stk->Parameters.Write.Length / 2);
727 
728  /* Set the cursor position, clipping it to the screen */
729  cursorx = (USHORT)(offset % columns);
730  cursory = (USHORT)(offset / columns);
731  // cursorx = min(max(cursorx, 0), columns - 1);
732  cursory = min(max(cursory, 0), rows - 1);
733  }
734  else
735  {
736  /* Cooked output mode */
737  for (i = 0; i < stk->Parameters.Write.Length; i++, pch++)
738  {
739  switch (*pch)
740  {
741  case '\b':
742  {
743  if (cursorx > 0)
744  {
745  cursorx--;
746  }
747  else if (cursory > 0)
748  {
749  cursory--;
750  cursorx = columns - 1;
751  }
752  offset = cursorx + cursory * columns;
753  vidmem[offset * 2] = ' ';
754  vidmem[offset * 2 + 1] = (char)DeviceExtension->CharAttribute;
755  break;
756  }
757 
758  case '\n':
759  cursory++;
760  /* Fall back */
761  case '\r':
762  cursorx = 0;
763  break;
764 
765  case '\t':
766  {
767  offset = TAB_WIDTH - (cursorx % TAB_WIDTH);
768  while (offset--)
769  {
770  vidmem[(cursorx + cursory * columns) * 2] = ' ';
771  cursorx++;
772  if (cursorx >= columns)
773  {
774  cursorx = 0;
775  cursory++;
776  /* We jumped to the next line, stop there */
777  break;
778  }
779  }
780  break;
781  }
782 
783  default:
784  {
785  offset = cursorx + cursory * columns;
786  vidmem[offset * 2] = *pch;
787  vidmem[offset * 2 + 1] = (char)DeviceExtension->CharAttribute;
788  cursorx++;
789  if (cursorx >= columns)
790  {
791  cursorx = 0;
792  cursory++;
793  }
794  break;
795  }
796  }
797 
798  /* Scroll up the contents of the screen if we are at the end */
799  if (cursory >= rows)
800  {
802 
804  &vidmem[columns * 2],
805  columns * (rows - 1) * 2);
806 
807  LinePtr = (PUSHORT)&vidmem[columns * (rows - 1) * 2];
808 
809  for (j = 0; j < columns; j++)
810  {
811  LinePtr[j] = DeviceExtension->CharAttribute << 8;
812  }
813  cursory = rows - 1;
814  for (j = 0; j < columns; j++)
815  {
816  offset = j + cursory * columns;
817  vidmem[offset * 2] = ' ';
818  vidmem[offset * 2 + 1] = (char)DeviceExtension->CharAttribute;
819  }
820  }
821  }
822  }
823 
824  /* Set the cursor position */
825  ASSERT((0 <= cursorx) && (cursorx < DeviceExtension->Columns));
826  ASSERT((0 <= cursory) && (cursory < DeviceExtension->Rows));
827  DeviceExtension->CursorX = cursorx;
828  DeviceExtension->CursorY = cursory;
829  ScrSetCursor(DeviceExtension);
830 
832 
833  Irp->IoStatus.Status = Status;
835 
836  return Status;
837 }
signed char * PCHAR
Definition: retypes.h:7
#define max(a, b)
Definition: svc.c:63
PBYTE vidmem
Definition: vgavideo.c:18
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static VOID FASTCALL ScrSetCursor(_In_ PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:362
_In_ PIRP Irp
Definition: csq.h:116
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
GLintptr offset
Definition: glext.h:5920
struct Line * LinePtr
Definition: ncftp.h:78
#define pch(ap)
Definition: match.c:418
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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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
if(!(yy_init))
Definition: macro.lex.yy.c:714
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: ncftp.h:79
#define IO_VIDEO_INCREMENT
Definition: iotypes.h:577
Status
Definition: gdiplustypes.h:24
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:53
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
static const COLUMN_LIST Columns[]
Definition: listview.c:19
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:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
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 69 of file blue.c.

Referenced by DrvDisablePDEV(), and ScrAcquireOwnership().

◆ InbvMonitoring

BOOLEAN InbvMonitoring = FALSE
static

Definition at line 99 of file blue.c.

Referenced by InbvMonitorThread(), and ScrResetDisplayParametersEx().

◆ InbvThreadHandle

HANDLE InbvThreadHandle = NULL
static

Definition at line 98 of file blue.c.

Referenced by ScrInbvCleanup(), and ScrInbvInitialize().

◆ ResetDisplayParametersDeviceExtension

PDEVICE_EXTENSION ResetDisplayParametersDeviceExtension = NULL
static

Definition at line 97 of file blue.c.

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

◆ ScrCreateClose

DRIVER_DISPATCH ScrCreateClose
static

Definition at line 661 of file blue.c.

Referenced by DriverEntry().

◆ ScrDispatch

DRIVER_DISPATCH ScrDispatch
static

Definition at line 1520 of file blue.c.

Referenced by DriverEntry().

◆ ScrIoControl

DRIVER_DISPATCH ScrIoControl
static

Definition at line 839 of file blue.c.

Referenced by DriverEntry().

◆ ScrWrite

DRIVER_DISPATCH ScrWrite
static

Definition at line 681 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 53 of file blue.c.

Referenced by ScrAcquireOwnership().