Author: hbelusca
Date: Tue Aug 6 20:01:05 2013
New Revision: 59659
URL:
http://svn.reactos.org/svn/reactos?rev=59659&view=rev
Log:
[NTVDM]
- Don't leak console input/output handles when opening them in BiosInitialize.
- Deinitialize the emulator in the reverse order it was initialized.
- Simplify VgaGetVideoBaseAddress and VgaGetVideoLimitAddress and use the former one in
VgaTranslate[Read-Write]Address.
- Use only unicode Win32 APIs where it's needed.
Modified:
branches/ntvdm/subsystems/ntvdm/bios.c
branches/ntvdm/subsystems/ntvdm/emulator.c
branches/ntvdm/subsystems/ntvdm/ntvdm.c
branches/ntvdm/subsystems/ntvdm/vga.c
Modified: branches/ntvdm/subsystems/ntvdm/bios.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios.c?r…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/bios.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/bios.c [iso-8859-1] Tue Aug 6 20:01:05 2013
@@ -21,7 +21,7 @@
static PBIOS_DATA_AREA Bda;
static BYTE BiosKeyboardMap[256];
-static HANDLE BiosConsoleInput = INVALID_HANDLE_VALUE;
+static HANDLE BiosConsoleInput = INVALID_HANDLE_VALUE;
static HANDLE BiosConsoleOutput = INVALID_HANDLE_VALUE;
static CONSOLE_SCREEN_BUFFER_INFO BiosSavedBufferInfo;
@@ -216,14 +216,13 @@
{
INT i, j;
INT Counter = 0;
+ WORD Character;
DWORD VideoAddress = TO_LINEAR(TEXT_VIDEO_SEG, Page * Bda->VideoPageSize);
for (i = Rectangle.Top; i <= Rectangle.Bottom; i++)
{
for (j = Rectangle.Left; j <= Rectangle.Right; j++)
{
- WORD Character;
-
/* Read from video memory */
VgaReadMemory(VideoAddress + (i * Bda->ScreenColumns + j) * sizeof(WORD),
(LPVOID)&Character,
@@ -239,13 +238,14 @@
{
INT i, j;
INT Counter = 0;
+ WORD Character;
DWORD VideoAddress = TO_LINEAR(TEXT_VIDEO_SEG, Page * Bda->VideoPageSize);
for (i = Rectangle.Top; i <= Rectangle.Bottom; i++)
{
for (j = Rectangle.Left; j <= Rectangle.Right; j++)
{
- WORD Character = Buffer[Counter++];
+ Character = Buffer[Counter++];
/* Read from video memory */
VgaWriteMemory(VideoAddress + (i * Bda->ScreenColumns + j) *
sizeof(WORD),
@@ -304,7 +304,7 @@
/* Update the values in the BDA */
Bda->VideoMode = ModeNumber;
Bda->VideoPage = 0;
- Bda->VideoPageSize = BIOS_PAGE_SIZE;
+ Bda->VideoPageSize = BIOS_PAGE_SIZE;
Bda->VideoPageOffset = 0;
Bda->CharacterHeight = 16;
@@ -369,33 +369,38 @@
BiosCode[Offset++] = 0xCF; // iret
}
- /* Get the input and output handles to the real console */
- BiosConsoleInput = CreateFile(TEXT("CONIN$"),
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
-
- BiosConsoleOutput = CreateFile(TEXT("CONOUT$"),
+ /* Get the input handle to the real console, and check for success */
+ BiosConsoleInput = CreateFileW(L"CONIN$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
-
- /* Make sure it was successful */
- if ((BiosConsoleInput == INVALID_HANDLE_VALUE)
- || (BiosConsoleOutput == INVALID_HANDLE_VALUE))
- {
+ if (BiosConsoleInput == INVALID_HANDLE_VALUE)
+ {
+ return FALSE;
+ }
+
+ /* Get the output handle to the real console, and check for success */
+ BiosConsoleOutput = CreateFileW(L"CONOUT$",
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ 0,
+ NULL);
+ if (BiosConsoleOutput == INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(BiosConsoleInput);
return FALSE;
}
/* Save the console screen buffer information */
if (!GetConsoleScreenBufferInfo(BiosConsoleOutput, &BiosSavedBufferInfo))
{
+ CloseHandle(BiosConsoleOutput);
+ CloseHandle(BiosConsoleInput);
return FALSE;
}
@@ -410,23 +415,23 @@
/* Initialize the PIC */
PicWriteCommand(PIC_MASTER_CMD, PIC_ICW1 | PIC_ICW1_ICW4);
- PicWriteCommand(PIC_SLAVE_CMD, PIC_ICW1 | PIC_ICW1_ICW4);
+ PicWriteCommand(PIC_SLAVE_CMD , PIC_ICW1 | PIC_ICW1_ICW4);
/* Set the interrupt offsets */
PicWriteData(PIC_MASTER_DATA, BIOS_PIC_MASTER_INT);
- PicWriteData(PIC_SLAVE_DATA, BIOS_PIC_SLAVE_INT);
+ PicWriteData(PIC_SLAVE_DATA , BIOS_PIC_SLAVE_INT);
/* Tell the master PIC there is a slave at IRQ 2 */
PicWriteData(PIC_MASTER_DATA, 1 << 2);
- PicWriteData(PIC_SLAVE_DATA, 2);
+ PicWriteData(PIC_SLAVE_DATA , 2);
/* Make sure the PIC is in 8086 mode */
PicWriteData(PIC_MASTER_DATA, PIC_ICW4_8086);
- PicWriteData(PIC_SLAVE_DATA, PIC_ICW4_8086);
+ PicWriteData(PIC_SLAVE_DATA , PIC_ICW4_8086);
/* Clear the masks for both PICs */
PicWriteData(PIC_MASTER_DATA, 0x00);
- PicWriteData(PIC_SLAVE_DATA, 0x00);
+ PicWriteData(PIC_SLAVE_DATA , 0x00);
PitWriteCommand(0x34);
PitWriteData(0, 0x00);
@@ -444,8 +449,8 @@
SetConsoleScreenBufferSize(BiosConsoleOutput, BiosSavedBufferInfo.dwSize);
/* Close the console handles */
- if (BiosConsoleInput != INVALID_HANDLE_VALUE) CloseHandle(BiosConsoleInput);
if (BiosConsoleOutput != INVALID_HANDLE_VALUE) CloseHandle(BiosConsoleOutput);
+ if (BiosConsoleInput != INVALID_HANDLE_VALUE) CloseHandle(BiosConsoleInput);
}
WORD BiosPeekCharacter(VOID)
@@ -512,9 +517,9 @@
/* Modify the CRTC registers */
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_LOC_LOW_REG);
- VgaWritePort(VGA_CRTC_DATA, LOBYTE(Offset));
+ VgaWritePort(VGA_CRTC_DATA , LOBYTE(Offset));
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_LOC_HIGH_REG);
- VgaWritePort(VGA_CRTC_DATA, HIBYTE(Offset));
+ VgaWritePort(VGA_CRTC_DATA , HIBYTE(Offset));
}
}
@@ -633,9 +638,9 @@
/* Modify the CRTC registers */
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_START_REG);
- VgaWritePort(VGA_CRTC_DATA, Bda->CursorStartLine);
+ VgaWritePort(VGA_CRTC_DATA , Bda->CursorStartLine);
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_END_REG);
- VgaWritePort(VGA_CRTC_DATA, Bda->CursorEndLine);
+ VgaWritePort(VGA_CRTC_DATA , Bda->CursorEndLine);
break;
}
Modified: branches/ntvdm/subsystems/ntvdm/emulator.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] Tue Aug 6 20:01:05 2013
@@ -543,14 +543,14 @@
VOID EmulatorCleanup(VOID)
{
+#ifndef NEW_EMULATOR
+ /* Free the softx86 CPU and FPU emulator */
+ softx87_free(&FpuEmulatorContext);
+ softx86_free(&EmulatorContext);
+#endif
+
/* Free the memory allocated for the 16-bit address space */
if (BaseAddress != NULL) HeapFree(GetProcessHeap(), 0, BaseAddress);
-
-#ifndef NEW_EMULATOR
- /* Free the softx86 CPU and FPU emulator */
- softx86_free(&EmulatorContext);
- softx87_free(&FpuEmulatorContext);
-#endif
}
VOID EmulatorSetA20(BOOLEAN Enabled)
Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.c?…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] Tue Aug 6 20:01:05 2013
@@ -50,7 +50,7 @@
va_start(Parameters, Format);
_vsnwprintf(Buffer, 256, Format, Parameters);
- MessageBox(NULL, Buffer, L"NTVDM Subsystem", MB_OK);
+ MessageBoxW(NULL, Buffer, L"NTVDM Subsystem", MB_OK);
va_end(Parameters);
}
Modified: branches/ntvdm/subsystems/ntvdm/vga.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/vga.c?re…
==============================================================================
--- branches/ntvdm/subsystems/ntvdm/vga.c [iso-8859-1] (original)
+++ branches/ntvdm/subsystems/ntvdm/vga.c [iso-8859-1] Tue Aug 6 20:01:05 2013
@@ -14,6 +14,9 @@
#include "bios.h"
/* PRIVATE VARIABLES **********************************************************/
+
+static CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
+static CONST DWORD MemoryLimit[] = { 0xA7FFF, 0xA7FFF, 0xB7FFF, 0xBFFFF };
static BYTE VgaMemory[VGA_NUM_BANKS * VGA_BANK_SIZE];
static BYTE VgaMiscRegister;
@@ -63,8 +66,7 @@
static inline DWORD VgaTranslateReadAddress(DWORD Address)
{
- CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
- DWORD Offset = Address - MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2)
& 0x03];
+ DWORD Offset = Address - VgaGetVideoBaseAddress();
BYTE Plane;
/* Check for chain-4 and odd-even mode */
@@ -94,8 +96,7 @@
static inline DWORD VgaTranslateWriteAddress(DWORD Address)
{
- CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
- DWORD Offset = Address - MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2)
& 0x03];
+ DWORD Offset = Address - VgaGetVideoBaseAddress();
/* Check for chain-4 and odd-even mode */
if (VgaSeqRegisters[VGA_SEQ_MEM_REG] & VGA_SEQ_MEM_C4)
@@ -514,13 +515,11 @@
DWORD VgaGetVideoBaseAddress(VOID)
{
- CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
return MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
}
DWORD VgaGetVideoLimitAddress(VOID)
{
- CONST DWORD MemoryLimit[] = { 0xA7FFF, 0xA7FFF, 0xB7FFF, 0xBFFFF };
return MemoryLimit[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
}