mirror of
https://github.com/reactos/reactos.git
synced 2024-08-01 09:01:13 +00:00
[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. svn path=/branches/ntvdm/; revision=59659
This commit is contained in:
parent
455deb3bde
commit
5bc19fdbfb
|
@ -216,14 +216,13 @@ static VOID BiosReadWindow(LPWORD Buffer, SMALL_RECT Rectangle, BYTE Page)
|
|||
{
|
||||
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 @@ static VOID BiosWriteWindow(LPWORD Buffer, SMALL_RECT Rectangle, BYTE Page)
|
|||
{
|
||||
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),
|
||||
|
@ -369,33 +369,38 @@ BOOLEAN BiosInitialize(VOID)
|
|||
BiosCode[Offset++] = 0xCF; // iret
|
||||
}
|
||||
|
||||
/* Get the input and output handles to the real console */
|
||||
BiosConsoleInput = CreateFile(TEXT("CONIN$"),
|
||||
/* 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);
|
||||
|
||||
BiosConsoleOutput = CreateFile(TEXT("CONOUT$"),
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -444,8 +449,8 @@ VOID BiosCleanup(VOID)
|
|||
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)
|
||||
|
|
|
@ -543,14 +543,14 @@ VOID EmulatorStep(VOID)
|
|||
|
||||
VOID EmulatorCleanup(VOID)
|
||||
{
|
||||
/* 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);
|
||||
softx86_free(&EmulatorContext);
|
||||
#endif
|
||||
|
||||
/* Free the memory allocated for the 16-bit address space */
|
||||
if (BaseAddress != NULL) HeapFree(GetProcessHeap(), 0, BaseAddress);
|
||||
}
|
||||
|
||||
VOID EmulatorSetA20(BOOLEAN Enabled)
|
||||
|
|
|
@ -50,7 +50,7 @@ VOID DisplayMessage(LPCWSTR Format, ...)
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
|
||||
/* 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;
|
||||
static BYTE VgaSeqIndex = VGA_SEQ_RESET_REG;
|
||||
|
@ -63,8 +66,7 @@ static inline INT VgaGetAddressSize(VOID)
|
|||
|
||||
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 VgaTranslateReadAddress(DWORD Address)
|
|||
|
||||
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 @@ static VOID VgaUpdateTextCursor(VOID)
|
|||
|
||||
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];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue