Skip to content

Commit 9e28115

Browse files
committed
Switch to 320x200 256-colors (Mode 13h)
1 parent 6d93257 commit 9e28115

File tree

4 files changed

+1334
-25
lines changed

4 files changed

+1334
-25
lines changed

doomgeneric/doomgeneric_nt.c

Lines changed: 150 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ int* _imp___errno()
106106
}
107107

108108
static PVOID heap = NULL;
109+
static BOOLEAN InhibitGraphicsPrint = FALSE;
109110

110111
#define strace(s, x, ...) nt_printf(x": 0x%X", __VA_ARGS__, s)
111112
#define etrace(x, ...) nt_printf(x, __VA_ARGS__)
@@ -174,7 +175,10 @@ int __cdecl nt_printf (const char* fmt, ...)
174175
//
175176
// Display it on screen
176177
//
177-
Status = ZwDisplayString(&MessageString);
178+
if (!InhibitGraphicsPrint)
179+
Status = ZwDisplayString(&MessageString);
180+
181+
DbgPrint("%ls", MessageString.Buffer);
178182

179183
//
180184
// Free Memory
@@ -679,14 +683,36 @@ static BOOLEAN IsWindows8OrLater()
679683
}
680684

681685
static byte DGNT_ScrBuf[DOOMGENERIC_RESX * DOOMGENERIC_RESY];
686+
extern ULONG_PTR VgaBase;
687+
688+
extern BOOLEAN NTAPI VidInitialize(BOOLEAN SetMode);
689+
extern int init_graph_vga(int width, int height,int chain4);
690+
extern VOID TextMode(VOID);
691+
692+
#define LO 85
693+
#define MD 170
694+
#define HI 255
695+
696+
typedef struct tagRGBQUAD
697+
{
698+
UCHAR rgbBlue;
699+
UCHAR rgbGreen;
700+
UCHAR rgbRed;
701+
UCHAR rgbReserved;
702+
} RGBQUAD, *LPRGBQUAD;
703+
704+
RGBQUAD gray = { 127, 127, 127, 255 };
705+
706+
extern VOID NTAPI SetPaletteEntryRGB(ULONG Id, RGBQUAD Rgb);
682707
void DG_Init()
683708
{
684709
IO_STATUS_BLOCK iosb;
685710
NTSTATUS Status;
686711
OBJECT_ATTRIBUTES ObjectAttributes;
687712
UNICODE_STRING ustr;
688713
IO_STATUS_BLOCK Iosb;
689-
ULONG solidcolfillparams[5] = { 0, 0, 639, 479, 0 };
714+
//ULONG solidcolfillparams[5] = { 0, 0, 639, 479, 0 };
715+
unsigned int i = 0;
690716

691717
if (IsWindows8OrLater())
692718
{
@@ -697,11 +723,12 @@ void DG_Init()
697723
}
698724
}
699725
//nt_printf("%s\n", __func__);
700-
InbvResetDisplay();
701-
InbvSetTextColor(BV_COLOR_WHITE);
702-
InbvInstallDisplayStringFilter(NULL);
703-
InbvEnableDisplayString(TRUE);
704-
InbvSetScrollRegion(0, 0, 679, 449);
726+
//InbvResetDisplay();
727+
//InbvSetTextColor(BV_COLOR_WHITE);
728+
//InbvInstallDisplayStringFilter(NULL);
729+
//InbvEnableDisplayString(TRUE);
730+
//InbvSetScrollRegion(0, 0, 679, 449);
731+
705732
//nt_printf("%s 4\n", __func__);
706733
RtlInitUnicodeString(&ustr, L"\\Device\\KeyboardClass0");
707734
InitializeObjectAttributes(&ObjectAttributes,
@@ -719,6 +746,68 @@ void DG_Init()
719746
DG_SleepMs(1);
720747
}
721748
}
749+
750+
RtlInitUnicodeString(&ustr, L"\\Device\\Video0");
751+
InitializeObjectAttributes(&ObjectAttributes,
752+
&ustr,
753+
OBJ_CASE_INSENSITIVE,
754+
NULL,
755+
NULL);
756+
//nt_printf("%s 5\n", __func__);
757+
758+
#if 0
759+
Status = NtCreateFile(&pVideoDevice, SYNCHRONIZE | GENERIC_READ | FILE_READ_ATTRIBUTES, &ObjectAttributes, &Iosb, NULL, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, FILE_DIRECTORY_FILE, NULL, 0);
760+
if (!NT_SUCCESS(Status))
761+
{
762+
nt_printf("Failed to open \\Device\\Video0: 0x%X.\n", Status);
763+
while (1)
764+
{
765+
DG_SleepMs(1);
766+
}
767+
}
768+
769+
//ZwDeviceIoControlFile(pVideoDevice, NULL, NULL, NULL, &Iosb, IOCTL_VIDEO_RESET_DEVICE, NULL, 0, NULL, 0);
770+
nt_ioctl((NT_FILE*)&pVideoDevice, IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES, "doomgeneric_nt", NULL, 0, (void*)&numModes, sizeof(VIDEO_NUM_MODES), NULL);
771+
nt_printf("%d, %lu\n", numModes.NumModes, numModes.ModeInformationLength);
772+
773+
modes = nt_calloc(numModes.NumModes, numModes.ModeInformationLength);
774+
775+
nt_ioctl((NT_FILE*)&pVideoDevice, IOCTL_VIDEO_QUERY_AVAIL_MODES, "doomgeneric_nt", NULL, 0, (void*)modes, numModes.ModeInformationLength * numModes.NumModes, NULL);
776+
777+
for (i = 0; i < numModes.NumModes; i++)
778+
{
779+
nt_printf("%dx%dx%d\n", modes[i].VisScreenWidth, modes[i].VisScreenHeight, modes[i].BitsPerPlane * modes[i].NumberOfPlanes);
780+
}
781+
782+
for (i = 0; i < numModes.NumModes; i++)
783+
{
784+
if (modes[i].VisScreenWidth == 320 && modes[i].VisScreenHeight == 200)
785+
{
786+
VIDEO_MODE mode;
787+
mode.RequestedMode = i;
788+
nt_ioctl((NT_FILE*)&pVideoDevice, IOCTL_VIDEO_SET_CURRENT_MODE, "doomgeneric_nt", (void*)&mode, sizeof(VIDEO_MODE), NULL, 0, NULL);
789+
nt_printf("%dx%dx%d set\n", modes[i].VisScreenWidth, modes[i].VisScreenHeight, modes[i].BitsPerPlane * modes[i].NumberOfPlanes);
790+
}
791+
//nt_printf("%dx%dx%d\n", modes[i].VisScreenWidth, modes[i].VisScreenHeight, modes[i].BitsPerPlane * modes[i].NumberOfPlanes);
792+
}
793+
794+
memReq.RequestedVirtualAddress = NULL;
795+
RtlZeroMemory(&memInfo, sizeof(VIDEO_MEMORY_INFORMATION));
796+
nt_ioctl((NT_FILE*)&pVideoDevice, IOCTL_VIDEO_MAP_VIDEO_MEMORY, "doomgeneric_nt", (void*)&memReq, sizeof(VIDEO_MEMORY), (void*)&memInfo, sizeof(VIDEO_MEMORY_INFORMATION), NULL);
797+
if (memInfo.VideoRamBase)
798+
{
799+
uint16_t* buffer = (uint16_t*)memInfo.FrameBufferBase;
800+
buffer[0] = 'T' | (0x0f00);
801+
buffer[1] = 'e' | (0x0f00);
802+
buffer[2] = 's' | (0x0f00);
803+
buffer[3] = 't' | (0x0f00);
804+
while (1)
805+
{
806+
DG_SleepMs(1);
807+
}
808+
}
809+
#endif
810+
722811
//nt_printf("%s 6\n", __func__);
723812
InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
724813
ZwCreateEvent(&hKeyboardEvent, EVENT_ALL_ACCESS, &ObjectAttributes, 1, 0);
@@ -747,17 +836,6 @@ void DG_SleepMs(uint32_t ms)
747836
sleepAmount.QuadPart = -((LONGLONG)(ms) * 10000);
748837
KeDelayExecutionThread(KernelMode, FALSE, &sleepAmount);
749838
}
750-
#define LO 85
751-
#define MD 170
752-
#define HI 255
753-
754-
typedef struct tagRGBQUAD
755-
{
756-
UCHAR rgbBlue;
757-
UCHAR rgbGreen;
758-
UCHAR rgbRed;
759-
UCHAR rgbReserved;
760-
} RGBQUAD, *LPRGBQUAD;
761839

762840
static const RGBQUAD TextModePalette[16] =
763841
{
@@ -814,7 +892,7 @@ static int GetPaletteIndex(int r, int g, int b)
814892

815893
return best;
816894
}
817-
extern RGBQUAD* I_GetPalPtr();
895+
extern RGBQUAD* I_GetPalPtr(void);
818896
static void RGBtoHSV(float r, float g, float b, float* h, float* s, float* v)
819897
{
820898
float min, max, delta, foo;
@@ -889,16 +967,19 @@ struct ColFillParams
889967
ULONG Bottom;
890968
ULONG color;
891969
};
892-
#define UNDETAILLEVELX 4
893-
#define UNDETAILLEVELY 4
970+
#define UNDETAILLEVELX 2
971+
#define UNDETAILLEVELY 2
972+
extern void I_ReadScreen (byte* scr);
894973
void DG_DrawFrame()
895974
{
975+
#if 0
896976
UINT32 x = 0, y = 0;
897977
uint8_t* dgPixBuf = (void*)DG_ScreenBuffer;
898978
for (y = 0; y < DOOMGENERIC_RESY; y += UNDETAILLEVELX)
899979
{
900980
for (x = 0; x < DOOMGENERIC_RESX; x += UNDETAILLEVELY)
901981
{
982+
902983
float h = 0, s = 0, v = 0;
903984
float r = dgPixBuf[y * DOOMGENERIC_RESX * 4 + x * 4 + 2] / 255.f;
904985
float g = dgPixBuf[y * DOOMGENERIC_RESX * 4 + x * 4 + 1] / 255.f;
@@ -929,9 +1010,29 @@ void DG_DrawFrame()
9291010
fillcol.color = attrib & 0xF;
9301011
DGNT_ScrBuf[y * DOOMGENERIC_RESX + x] = attrib;
9311012
//nt_ioctl((NT_FILE*)&pDevice, IOCTL_INBVSHIM_SOLID_COLOR_FILL, "doomgeneric_nt", &fillcol, sizeof(struct ColFillParams), NULL, 0, NULL);
932-
InbvSolidColorFill(fillcol.Left, fillcol.Top, fillcol.Right, fillcol.Bottom, fillcol.color);
1013+
//InbvSolidColorFill(fillcol.Left, fillcol.Top, fillcol.Right, fillcol.Bottom, fillcol.color);
1014+
1015+
9331016
}
9341017
}
1018+
#endif
1019+
int i = 0;
1020+
RGBQUAD* palette;
1021+
1022+
if (!InhibitGraphicsPrint) {
1023+
InbvEnableBootDriver(FALSE);
1024+
VidInitialize(TRUE);
1025+
init_graph_vga(320, 200, 1);
1026+
memset((void*)VgaBase, 0x0, 0x10000);
1027+
InhibitGraphicsPrint = 1;
1028+
}
1029+
1030+
palette = I_GetPalPtr();
1031+
for (i = 0; i < 256; i++)
1032+
{
1033+
SetPaletteEntryRGB(i, palette[i]);
1034+
}
1035+
I_ReadScreen((byte*)VgaBase);
9351036
keysRead = 0;
9361037
}
9371038

@@ -1003,11 +1104,37 @@ void DG_SetWindowTitle(const char* title)
10031104

10041105
}
10051106

1107+
#ifdef _M_X64
1108+
#define HAL_HalFindBusAddressTranslation_OFFSET 0x50
1109+
#else
1110+
#define HAL_HalFindBusAddressTranslation_OFFSET 0x28
1111+
#endif
1112+
1113+
#pragma pack(push, 1)
1114+
typedef struct _HAL_PRIVATE_DISPATCH_TABLE
1115+
{
1116+
union
1117+
{
1118+
ULONG Version;
1119+
struct {
1120+
char pad[HAL_HalFindBusAddressTranslation_OFFSET];
1121+
BOOLEAN (NTAPI *HalFindBusAddressTranslation)(PHYSICAL_ADDRESS, ULONG*, PHYSICAL_ADDRESS*, ULONG_PTR*, BOOLEAN);
1122+
BOOLEAN (NTAPI *HalResetDisplay)(VOID);
1123+
};
1124+
};
1125+
} HAL_PRIVATE_DISPATCH_TABLE;
1126+
#pragma pack(pop)
1127+
1128+
extern NTSYSAPI HAL_PRIVATE_DISPATCH_TABLE HalPrivateDispatchTable;
1129+
10061130
void nt_exit(int code)
10071131
{
10081132
//NtTerminateProcess(NtCurrentProcess(), code);
1009-
1133+
HalPrivateDispatchTable.HalResetDisplay();
1134+
InbvEnableBootDriver(TRUE);
1135+
InbvResetDisplay();
10101136
InbvSolidColorFill(0, 0, 639, 479, 0);
1137+
InhibitGraphicsPrint = 0;
10111138
nt_printf("Close not implemented!\n");
10121139

10131140
while (1) {

doomgeneric/i_video.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void I_SetPalette (byte* palette)
338338
}
339339
}
340340

341-
struct color* I_GetPalPtr()
341+
struct color* I_GetPalPtr(void)
342342
{
343343
return colors;
344344
}

doomgeneric/sources

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,6 @@ w_file_stdc.c \
9191
w_main.c \
9292
w_wad.c \
9393
wi_stuff.c \
94-
z_zone.c
94+
z_zone.c \
95+
vgahelper.c
9596

0 commit comments

Comments
 (0)