From b4ed87bb3a939cc1aa5715e58a276a1a31a095b9 Mon Sep 17 00:00:00 2001 From: Aleksandar Andrejevic Date: Wed, 7 Aug 2013 19:56:28 +0000 Subject: [PATCH] [NTVDM] Fix coding style. Fix initial cursor position bug. Fix memory limit constant for VGA memory modes 0 and 1 (64 KB not 32 KB). svn path=/branches/ntvdm/; revision=59669 --- subsystems/ntvdm/bios.c | 10 +++++---- subsystems/ntvdm/bios.h | 1 + subsystems/ntvdm/dos.c | 6 ++++-- subsystems/ntvdm/dos.h | 3 ++- subsystems/ntvdm/emulator.c | 19 +++++++++++++++++ subsystems/ntvdm/ntvdm.c | 5 ++++- subsystems/ntvdm/ntvdm.h | 1 + subsystems/ntvdm/vga.c | 41 ++++++++++++++++++------------------- 8 files changed, 57 insertions(+), 29 deletions(-) diff --git a/subsystems/ntvdm/bios.c b/subsystems/ntvdm/bios.c index 8b142cad495..ae7fea465f9 100644 --- a/subsystems/ntvdm/bios.c +++ b/subsystems/ntvdm/bios.c @@ -404,12 +404,14 @@ BOOLEAN BiosInitialize(VOID) return FALSE; } - /* Store the cursor position */ - Bda->CursorPosition[0] = MAKEWORD(BiosSavedBufferInfo.dwCursorPosition.X, - BiosSavedBufferInfo.dwCursorPosition.Y); - + /* Initialize VGA */ VgaInitialize(BiosConsoleOutput); + /* Update the cursor position */ + BiosSetCursorPosition(BiosSavedBufferInfo.dwCursorPosition.Y, + BiosSavedBufferInfo.dwCursorPosition.Y, + 0); + /* Set the console input mode */ SetConsoleMode(BiosConsoleInput, ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT); diff --git a/subsystems/ntvdm/bios.h b/subsystems/ntvdm/bios.h index a31f9cf5406..f9454aeb0e2 100644 --- a/subsystems/ntvdm/bios.h +++ b/subsystems/ntvdm/bios.h @@ -105,6 +105,7 @@ BYTE BiosGetVideoMode(VOID); BOOLEAN BiosSetVideoMode(BYTE ModeNumber); WORD BiosPeekCharacter(VOID); WORD BiosGetCharacter(VOID); +VOID BiosSetCursorPosition(BYTE Row, BYTE Column, BYTE Page); VOID BiosVideoService(LPWORD Stack); VOID BiosEquipmentService(LPWORD Stack); VOID BiosKeyboardService(LPWORD Stack); diff --git a/subsystems/ntvdm/dos.c b/subsystems/ntvdm/dos.c index 67a53b33985..90fc79c80cb 100644 --- a/subsystems/ntvdm/dos.c +++ b/subsystems/ntvdm/dos.c @@ -205,7 +205,7 @@ static VOID DosCopyHandleTable(LPBYTE DestinationTable) for (i = 0; i <= 2; i++) { /* Set the index in the SFT */ - DestinationTable[i] = i; + DestinationTable[i] = (BYTE)i; /* Increase the reference count */ DosSftRefCount[i]++; @@ -864,7 +864,7 @@ VOID DosInitializePsp(WORD PspSegment, LPCSTR CommandLine, WORD ProgramSize, WOR PspBlock->FarCall[2] = 0xCB; // retf /* Set the command line */ - PspBlock->CommandLineSize = strlen(CommandLine); + PspBlock->CommandLineSize = (BYTE)min(strlen(CommandLine), DOS_CMDLINE_LENGTH); RtlCopyMemory(PspBlock->CommandLine, CommandLine, PspBlock->CommandLineSize); PspBlock->CommandLine[PspBlock->CommandLineSize] = '\r'; } @@ -1936,6 +1936,8 @@ VOID DosInt21h(LPWORD Stack) VOID DosBreakInterrupt(LPWORD Stack) { + UNREFERENCED_PARAMETER(Stack); + VdmRunning = FALSE; } diff --git a/subsystems/ntvdm/dos.h b/subsystems/ntvdm/dos.h index 38b225e37de..2071db5d70a 100644 --- a/subsystems/ntvdm/dos.h +++ b/subsystems/ntvdm/dos.h @@ -33,6 +33,7 @@ #define UMB_END_SEGMENT 0xDFFF #define DOS_ALLOC_HIGH 0x40 #define DOS_ALLOC_HIGH_LOW 0x80 +#define DOS_CMDLINE_LENGTH 127 enum DOS_ALLOC_STRATEGY { @@ -89,7 +90,7 @@ typedef struct _DOS_PSP BYTE Reserved3[9]; DOS_FCB Fcb; BYTE CommandLineSize; - CHAR CommandLine[127]; + CHAR CommandLine[DOS_CMDLINE_LENGTH]; } DOS_PSP, *PDOS_PSP; typedef struct _DOS_INPUT_BUFFER diff --git a/subsystems/ntvdm/emulator.c b/subsystems/ntvdm/emulator.c index 56cabc8b494..c0915cea24a 100644 --- a/subsystems/ntvdm/emulator.c +++ b/subsystems/ntvdm/emulator.c @@ -35,6 +35,8 @@ static BOOLEAN A20Line = FALSE; static VOID EmulatorReadMemory(PVOID Context, UINT Address, LPBYTE Buffer, INT Size) { + UNREFERENCED_PARAMETER(Context); + /* If the A20 line is disabled, mask bit 20 */ if (!A20Line) Address &= ~(1 << 20); @@ -58,6 +60,8 @@ static VOID EmulatorReadMemory(PVOID Context, UINT Address, LPBYTE Buffer, INT S static VOID EmulatorWriteMemory(PVOID Context, UINT Address, LPBYTE Buffer, INT Size) { + UNREFERENCED_PARAMETER(Context); + /* If the A20 line is disabled, mask bit 20 */ if (!A20Line) Address &= ~(1 << 20); @@ -84,6 +88,9 @@ static VOID EmulatorWriteMemory(PVOID Context, UINT Address, LPBYTE Buffer, INT static VOID EmulatorReadIo(PVOID Context, UINT Address, LPBYTE Buffer, INT Size) { + UNREFERENCED_PARAMETER(Context); + UNREFERENCED_PARAMETER(Size); + switch (Address) { case PIC_MASTER_CMD: @@ -151,6 +158,9 @@ static VOID EmulatorWriteIo(PVOID Context, UINT Address, LPBYTE Buffer, INT Size { BYTE Byte = *Buffer; + UNREFERENCED_PARAMETER(Context); + UNREFERENCED_PARAMETER(Size); + switch (Address) { case PIT_COMMAND_PORT: @@ -333,16 +343,25 @@ static VOID EmulatorBop(WORD Code) static VOID EmulatorSoftwareInt(PVOID Context, BYTE Number) { + UNREFERENCED_PARAMETER(Context); + UNREFERENCED_PARAMETER(Number); + /* Do nothing */ } static VOID EmulatorHardwareInt(PVOID Context, BYTE Number) { + UNREFERENCED_PARAMETER(Context); + UNREFERENCED_PARAMETER(Number); + /* Do nothing */ } static VOID EmulatorHardwareIntAck(PVOID Context, BYTE Number) { + UNREFERENCED_PARAMETER(Context); + UNREFERENCED_PARAMETER(Number); + /* Do nothing */ } diff --git a/subsystems/ntvdm/ntvdm.c b/subsystems/ntvdm/ntvdm.c index 7a32e1b2275..a6d6a2a654a 100644 --- a/subsystems/ntvdm/ntvdm.c +++ b/subsystems/ntvdm/ntvdm.c @@ -90,6 +90,9 @@ INT wmain(INT argc, WCHAR *argv[]) SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE); #ifndef TESTING + UNREFERENCED_PARAMETER(argc); + UNREFERENCED_PARAMETER(argv); + /* The DOS command line must be ASCII */ WideCharToMultiByte(CP_ACP, 0, GetCommandLine(), -1, CommandLine, 128, NULL, NULL); #else @@ -185,7 +188,7 @@ INT wmain(INT argc, WCHAR *argv[]) if ((CurrentTickCount - LastCyclePrintout) >= 1000) { - DPRINT1("NTVDM: %d Instructions Per Second\n", Cycles); + DPRINT1("NTVDM: %lu Instructions Per Second\n", Cycles); LastCyclePrintout = CurrentTickCount; Cycles = 0; } diff --git a/subsystems/ntvdm/ntvdm.h b/subsystems/ntvdm/ntvdm.h index 9a04e0d3d2b..282d3f07157 100644 --- a/subsystems/ntvdm/ntvdm.h +++ b/subsystems/ntvdm/ntvdm.h @@ -16,6 +16,7 @@ #include #include #include +#include /* DEFINES ********************************************************************/ diff --git a/subsystems/ntvdm/vga.c b/subsystems/ntvdm/vga.c index 0241671b7b3..8b6f850a5f9 100644 --- a/subsystems/ntvdm/vga.c +++ b/subsystems/ntvdm/vga.c @@ -15,8 +15,8 @@ /* PRIVATE VARIABLES **********************************************************/ -static CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 }; -static CONST DWORD MemoryLimit[] = { 0xA7FFF, 0xA7FFF, 0xB7FFF, 0xBFFFF }; +static CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 }; +static CONST DWORD MemoryLimit[] = { 0xAFFFF, 0xAFFFF, 0xB7FFF, 0xBFFFF }; static BYTE VgaMemory[VGA_NUM_BANKS * VGA_BANK_SIZE]; static BYTE VgaMiscRegister; @@ -124,8 +124,8 @@ static inline VOID VgaMarkForUpdate(SHORT Row, SHORT Column) /* Check if this is the first time the rectangle is updated */ if (!NeedsUpdate) { - UpdateRectangle.Left = UpdateRectangle.Top = (SHORT)0x7FFF; - UpdateRectangle.Right = UpdateRectangle.Bottom = (SHORT)0x8000; + UpdateRectangle.Left = UpdateRectangle.Top = SHRT_MAX; + UpdateRectangle.Right = UpdateRectangle.Bottom = SHRT_MIN; } /* Expand the rectangle to include the point */ @@ -216,7 +216,7 @@ static VOID VgaWriteAc(BYTE Data) VgaAcRegisters[VgaAcIndex] = Data; } -static BOOL VgaEnterGraphicsMode(PCOORD Resolution, UINT BitDepth) +static BOOL VgaEnterGraphicsMode(PCOORD Resolution) { DWORD i; CONSOLE_GRAPHICS_BUFFER_INFO GraphicsBufferInfo; @@ -227,16 +227,15 @@ static BOOL VgaEnterGraphicsMode(PCOORD Resolution, UINT BitDepth) /* Fill the bitmap info header */ ZeroMemory(&BitmapInfo->bmiHeader, sizeof(BITMAPINFOHEADER)); BitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - BitmapInfo->bmiHeader.biWidth = Resolution->X; + BitmapInfo->bmiHeader.biWidth = Resolution->X; BitmapInfo->bmiHeader.biHeight = Resolution->Y; BitmapInfo->bmiHeader.biBitCount = 8; - BitmapInfo->bmiHeader.biPlanes = 1; + BitmapInfo->bmiHeader.biPlanes = 1; BitmapInfo->bmiHeader.biCompression = BI_RGB; - BitmapInfo->bmiHeader.biSizeImage = Resolution->X * Resolution->Y - * (BitDepth / 8); + BitmapInfo->bmiHeader.biSizeImage = Resolution->X * Resolution->Y; /* Fill the palette data */ - for (i = 0; i < BitDepth; i++) PaletteIndex[i] = (WORD)i; + for (i = 0; i < (VGA_PALETTE_SIZE / 3); i++) PaletteIndex[i] = (WORD)i; /* Fill the console graphics buffer info */ GraphicsBufferInfo.dwBitMapInfoLength = VGA_BITMAP_INFO_SIZE; @@ -281,7 +280,7 @@ static BOOL VgaEnterTextMode(PCOORD Resolution) ConsoleFramebuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Resolution->X * Resolution->Y - * sizeof(CHAR_INFO)); + * sizeof(CHAR_INFO)); if (ConsoleFramebuffer == NULL) { DisplayMessage(L"An unexpected error occurred!\n"); @@ -305,7 +304,7 @@ static VOID VgaUpdateMode(VOID) if (!TextMode) { - /* Switching from graphics mode to text mode */ + /* Leave the current graphics mode */ VgaLeaveGraphicsMode(); } else @@ -326,7 +325,7 @@ static VOID VgaUpdateMode(VOID) else { /* Enter 8-bit graphics mode */ - if (!VgaEnterGraphicsMode(&Resolution, 8)) return; + if (!VgaEnterGraphicsMode(&Resolution)) return; /* Clear the text mode flag */ TextMode = FALSE; @@ -334,9 +333,9 @@ static VOID VgaUpdateMode(VOID) /* Perform a full update */ NeedsUpdate = TRUE; - UpdateRectangle.Left = 0; - UpdateRectangle.Top = 0; - UpdateRectangle.Right = Resolution.X; + UpdateRectangle.Left = 0; + UpdateRectangle.Top = 0; + UpdateRectangle.Right = Resolution.X; UpdateRectangle.Bottom = Resolution.Y; } @@ -441,7 +440,7 @@ static VOID VgaUpdateFramebuffer(VOID) { BYTE PlaneData = VgaMemory[k * VGA_BANK_SIZE + (Address + (j / 8)) * AddressSize]; - + /* If the bit on that plane is set, set it */ if (PlaneData & (1 << (7 - (j % 8)))) PixelData |= 1 << k; } @@ -953,11 +952,11 @@ VOID VgaInitialize(HANDLE TextHandle) ModeChanged = FALSE; /* Get the data */ - Resolution = VgaGetDisplayResolution(); - CharBuffer = (PCHAR_INFO)ConsoleFramebuffer; + Resolution = VgaGetDisplayResolution(); + CharBuffer = (PCHAR_INFO)ConsoleFramebuffer; AddressSize = VgaGetAddressSize(); - ScreenRect.Left = ScreenRect.Top = 0; - ScreenRect.Right = Resolution.X; + ScreenRect.Left = ScreenRect.Top = 0; + ScreenRect.Right = Resolution.X; ScreenRect.Bottom = Resolution.Y; ScanlineSize = (DWORD)VgaCrtcRegisters[VGA_CRTC_OFFSET_REG] * 2; -- 2.17.1