[BLUE] Add an IOCTL to directly choose which font to use (instead of codepage)

This commit is contained in:
Hervé Poussineau 2020-04-25 21:34:16 +02:00
parent d5f0b2b160
commit aaa416d36a
4 changed files with 75 additions and 2 deletions

View file

@ -38,6 +38,7 @@ typedef struct _DEVICE_EXTENSION
USHORT Rows; /* Number of rows */ USHORT Rows; /* Number of rows */
USHORT Columns; /* Number of columns */ USHORT Columns; /* Number of columns */
USHORT CursorX, CursorY; /* Cursor position */ USHORT CursorX, CursorY; /* Cursor position */
PUCHAR FontBitfield; /* Specifies the font. If NULL, use CodePage */
ULONG CodePage; /* Specifies the font associated to this code page */ ULONG CodePage; /* Specifies the font associated to this code page */
} DEVICE_EXTENSION, *PDEVICE_EXTENSION; } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
@ -483,8 +484,15 @@ ScrAcquireOwnership(
// DeviceExtension->CursorX = min(max(DeviceExtension->CursorX, 0), DeviceExtension->Columns - 1); // DeviceExtension->CursorX = min(max(DeviceExtension->CursorX, 0), DeviceExtension->Columns - 1);
DeviceExtension->CursorY = min(max(DeviceExtension->CursorY, 0), DeviceExtension->Rows - 1); DeviceExtension->CursorY = min(max(DeviceExtension->CursorY, 0), DeviceExtension->Rows - 1);
/* Upload a default font for the current codepage */ if (DeviceExtension->FontBitfield)
ScrLoadFontTable(DeviceExtension->CodePage); {
ScrSetFont(DeviceExtension->FontBitfield);
}
else
{
/* Upload a default font for the current codepage */
ScrLoadFontTable(DeviceExtension->CodePage);
}
DPRINT("%d Columns %d Rows %d Scanlines\n", DPRINT("%d Columns %d Rows %d Scanlines\n",
DeviceExtension->Columns, DeviceExtension->Columns,
@ -511,6 +519,12 @@ ScrResetScreen(
DeviceExtension->CursorSize = 5; /* FIXME: value correct?? */ DeviceExtension->CursorSize = 5; /* FIXME: value correct?? */
DeviceExtension->CursorVisible = TRUE; DeviceExtension->CursorVisible = TRUE;
if (DeviceExtension->FontBitfield)
{
ExFreePoolWithTag(DeviceExtension->FontBitfield, TAG_BLUE);
DeviceExtension->FontBitfield = NULL;
}
/* More initialization */ /* More initialization */
DeviceExtension->CharAttribute = BACKGROUND_BLUE | FOREGROUND_LIGHTGRAY; DeviceExtension->CharAttribute = BACKGROUND_BLUE | FOREGROUND_LIGHTGRAY;
DeviceExtension->Mode = ENABLE_PROCESSED_OUTPUT | DeviceExtension->Mode = ENABLE_PROCESSED_OUTPUT |
@ -1496,6 +1510,11 @@ ScrIoControl(
} }
ASSERT(Irp->AssociatedIrp.SystemBuffer); ASSERT(Irp->AssociatedIrp.SystemBuffer);
if (DeviceExtension->FontBitfield)
{
ExFreePoolWithTag(DeviceExtension->FontBitfield, TAG_BLUE);
DeviceExtension->FontBitfield = NULL;
}
DeviceExtension->CodePage = *(PULONG)Irp->AssociatedIrp.SystemBuffer; DeviceExtension->CodePage = *(PULONG)Irp->AssociatedIrp.SystemBuffer;
/* Upload a font for the codepage if needed */ /* Upload a font for the codepage if needed */
@ -1507,6 +1526,36 @@ ScrIoControl(
break; break;
} }
case IOCTL_CONSOLE_SETFONT:
{
/* Validate input buffer */
if (stk->Parameters.DeviceIoControl.InputBufferLength < 256 * 8)
{
Status = STATUS_INVALID_PARAMETER;
break;
}
ASSERT(Irp->AssociatedIrp.SystemBuffer);
DeviceExtension->CodePage = 0;
if (DeviceExtension->FontBitfield)
ExFreePoolWithTag(DeviceExtension->FontBitfield, TAG_BLUE);
DeviceExtension->FontBitfield = ExAllocatePoolWithTag(NonPagedPool, 256 * 8, TAG_BLUE);
if (!DeviceExtension->FontBitfield)
{
Status = STATUS_NO_MEMORY;
break;
}
RtlCopyMemory(DeviceExtension->FontBitfield, Irp->AssociatedIrp.SystemBuffer, 256 * 8);
/* Upload the font if needed */
if (DeviceExtension->Enabled && DeviceExtension->VideoMemory)
ScrSetFont(DeviceExtension->FontBitfield);
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
break;
}
default: default:
Status = STATUS_NOT_IMPLEMENTED; Status = STATUS_NOT_IMPLEMENTED;
} }

View file

@ -145,5 +145,6 @@ typedef struct _CFFILE
#define PELDATA (PUCHAR)0x3c9 #define PELDATA (PUCHAR)0x3c9
VOID ScrLoadFontTable(_In_ ULONG CodePage); VOID ScrLoadFontTable(_In_ ULONG CodePage);
VOID ScrSetFont(_In_ PUCHAR FontBitfield);
#endif /* _BLUE_PCH_ */ #endif /* _BLUE_PCH_ */

View file

@ -62,6 +62,28 @@ ScrLoadFontTable(
CloseBitPlane(); CloseBitPlane();
} }
VOID
ScrSetFont(
_In_ PUCHAR FontBitfield)
{
PHYSICAL_ADDRESS BaseAddress;
PUCHAR Bitplane;
/* open bit plane for font table access */
OpenBitPlane();
/* get pointer to video memory */
BaseAddress.QuadPart = BITPLANE_BASE;
Bitplane = (PUCHAR)MmMapIoSpace(BaseAddress, 0xFFFF, MmNonCached);
LoadFont(Bitplane, FontBitfield);
MmUnmapIoSpace(Bitplane, 0xFFFF);
/* close bit plane */
CloseBitPlane();
}
/* PRIVATE FUNCTIONS *********************************************************/ /* PRIVATE FUNCTIONS *********************************************************/
NTSTATUS NTSTATUS

View file

@ -22,6 +22,7 @@
#define IOCTL_CONSOLE_DRAW CTL_CODE(FILE_DEVICE_SCREEN, 0x830, METHOD_IN_DIRECT, FILE_WRITE_ACCESS) #define IOCTL_CONSOLE_DRAW CTL_CODE(FILE_DEVICE_SCREEN, 0x830, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
#define IOCTL_CONSOLE_LOADFONT CTL_CODE(FILE_DEVICE_SCREEN, 0x840, METHOD_IN_DIRECT, FILE_WRITE_ACCESS) #define IOCTL_CONSOLE_LOADFONT CTL_CODE(FILE_DEVICE_SCREEN, 0x840, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
#define IOCTL_CONSOLE_SETFONT CTL_CODE(FILE_DEVICE_SCREEN, 0x841, METHOD_IN_DIRECT, FILE_WRITE_ACCESS)
/* TYPEDEFS **************************************************************/ /* TYPEDEFS **************************************************************/