mirror of
https://github.com/reactos/reactos.git
synced 2024-08-01 00:58:16 +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
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
static PBIOS_DATA_AREA Bda;
|
static PBIOS_DATA_AREA Bda;
|
||||||
static BYTE BiosKeyboardMap[256];
|
static BYTE BiosKeyboardMap[256];
|
||||||
static HANDLE BiosConsoleInput = INVALID_HANDLE_VALUE;
|
static HANDLE BiosConsoleInput = INVALID_HANDLE_VALUE;
|
||||||
static HANDLE BiosConsoleOutput = INVALID_HANDLE_VALUE;
|
static HANDLE BiosConsoleOutput = INVALID_HANDLE_VALUE;
|
||||||
static CONSOLE_SCREEN_BUFFER_INFO BiosSavedBufferInfo;
|
static CONSOLE_SCREEN_BUFFER_INFO BiosSavedBufferInfo;
|
||||||
|
|
||||||
|
@ -216,14 +216,13 @@ static VOID BiosReadWindow(LPWORD Buffer, SMALL_RECT Rectangle, BYTE Page)
|
||||||
{
|
{
|
||||||
INT i, j;
|
INT i, j;
|
||||||
INT Counter = 0;
|
INT Counter = 0;
|
||||||
|
WORD Character;
|
||||||
DWORD VideoAddress = TO_LINEAR(TEXT_VIDEO_SEG, Page * Bda->VideoPageSize);
|
DWORD VideoAddress = TO_LINEAR(TEXT_VIDEO_SEG, Page * Bda->VideoPageSize);
|
||||||
|
|
||||||
for (i = Rectangle.Top; i <= Rectangle.Bottom; i++)
|
for (i = Rectangle.Top; i <= Rectangle.Bottom; i++)
|
||||||
{
|
{
|
||||||
for (j = Rectangle.Left; j <= Rectangle.Right; j++)
|
for (j = Rectangle.Left; j <= Rectangle.Right; j++)
|
||||||
{
|
{
|
||||||
WORD Character;
|
|
||||||
|
|
||||||
/* Read from video memory */
|
/* Read from video memory */
|
||||||
VgaReadMemory(VideoAddress + (i * Bda->ScreenColumns + j) * sizeof(WORD),
|
VgaReadMemory(VideoAddress + (i * Bda->ScreenColumns + j) * sizeof(WORD),
|
||||||
(LPVOID)&Character,
|
(LPVOID)&Character,
|
||||||
|
@ -239,13 +238,14 @@ static VOID BiosWriteWindow(LPWORD Buffer, SMALL_RECT Rectangle, BYTE Page)
|
||||||
{
|
{
|
||||||
INT i, j;
|
INT i, j;
|
||||||
INT Counter = 0;
|
INT Counter = 0;
|
||||||
|
WORD Character;
|
||||||
DWORD VideoAddress = TO_LINEAR(TEXT_VIDEO_SEG, Page * Bda->VideoPageSize);
|
DWORD VideoAddress = TO_LINEAR(TEXT_VIDEO_SEG, Page * Bda->VideoPageSize);
|
||||||
|
|
||||||
for (i = Rectangle.Top; i <= Rectangle.Bottom; i++)
|
for (i = Rectangle.Top; i <= Rectangle.Bottom; i++)
|
||||||
{
|
{
|
||||||
for (j = Rectangle.Left; j <= Rectangle.Right; j++)
|
for (j = Rectangle.Left; j <= Rectangle.Right; j++)
|
||||||
{
|
{
|
||||||
WORD Character = Buffer[Counter++];
|
Character = Buffer[Counter++];
|
||||||
|
|
||||||
/* Read from video memory */
|
/* Read from video memory */
|
||||||
VgaWriteMemory(VideoAddress + (i * Bda->ScreenColumns + j) * sizeof(WORD),
|
VgaWriteMemory(VideoAddress + (i * Bda->ScreenColumns + j) * sizeof(WORD),
|
||||||
|
@ -304,7 +304,7 @@ BOOLEAN BiosSetVideoMode(BYTE ModeNumber)
|
||||||
/* Update the values in the BDA */
|
/* Update the values in the BDA */
|
||||||
Bda->VideoMode = ModeNumber;
|
Bda->VideoMode = ModeNumber;
|
||||||
Bda->VideoPage = 0;
|
Bda->VideoPage = 0;
|
||||||
Bda->VideoPageSize = BIOS_PAGE_SIZE;
|
Bda->VideoPageSize = BIOS_PAGE_SIZE;
|
||||||
Bda->VideoPageOffset = 0;
|
Bda->VideoPageOffset = 0;
|
||||||
Bda->CharacterHeight = 16;
|
Bda->CharacterHeight = 16;
|
||||||
|
|
||||||
|
@ -369,33 +369,38 @@ BOOLEAN BiosInitialize(VOID)
|
||||||
BiosCode[Offset++] = 0xCF; // iret
|
BiosCode[Offset++] = 0xCF; // iret
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the input and output handles to the real console */
|
/* Get the input handle to the real console, and check for success */
|
||||||
BiosConsoleInput = CreateFile(TEXT("CONIN$"),
|
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,
|
GENERIC_READ | GENERIC_WRITE,
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
NULL,
|
NULL,
|
||||||
OPEN_EXISTING,
|
OPEN_EXISTING,
|
||||||
0,
|
0,
|
||||||
NULL);
|
NULL);
|
||||||
|
if (BiosConsoleInput == INVALID_HANDLE_VALUE)
|
||||||
/* Make sure it was successful */
|
|
||||||
if ((BiosConsoleInput == INVALID_HANDLE_VALUE)
|
|
||||||
|| (BiosConsoleOutput == INVALID_HANDLE_VALUE))
|
|
||||||
{
|
{
|
||||||
return FALSE;
|
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 */
|
/* Save the console screen buffer information */
|
||||||
if (!GetConsoleScreenBufferInfo(BiosConsoleOutput, &BiosSavedBufferInfo))
|
if (!GetConsoleScreenBufferInfo(BiosConsoleOutput, &BiosSavedBufferInfo))
|
||||||
{
|
{
|
||||||
|
CloseHandle(BiosConsoleOutput);
|
||||||
|
CloseHandle(BiosConsoleInput);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,23 +415,23 @@ BOOLEAN BiosInitialize(VOID)
|
||||||
|
|
||||||
/* Initialize the PIC */
|
/* Initialize the PIC */
|
||||||
PicWriteCommand(PIC_MASTER_CMD, PIC_ICW1 | PIC_ICW1_ICW4);
|
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 */
|
/* Set the interrupt offsets */
|
||||||
PicWriteData(PIC_MASTER_DATA, BIOS_PIC_MASTER_INT);
|
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 */
|
/* Tell the master PIC there is a slave at IRQ 2 */
|
||||||
PicWriteData(PIC_MASTER_DATA, 1 << 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 */
|
/* Make sure the PIC is in 8086 mode */
|
||||||
PicWriteData(PIC_MASTER_DATA, PIC_ICW4_8086);
|
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 */
|
/* Clear the masks for both PICs */
|
||||||
PicWriteData(PIC_MASTER_DATA, 0x00);
|
PicWriteData(PIC_MASTER_DATA, 0x00);
|
||||||
PicWriteData(PIC_SLAVE_DATA, 0x00);
|
PicWriteData(PIC_SLAVE_DATA , 0x00);
|
||||||
|
|
||||||
PitWriteCommand(0x34);
|
PitWriteCommand(0x34);
|
||||||
PitWriteData(0, 0x00);
|
PitWriteData(0, 0x00);
|
||||||
|
@ -444,8 +449,8 @@ VOID BiosCleanup(VOID)
|
||||||
SetConsoleScreenBufferSize(BiosConsoleOutput, BiosSavedBufferInfo.dwSize);
|
SetConsoleScreenBufferSize(BiosConsoleOutput, BiosSavedBufferInfo.dwSize);
|
||||||
|
|
||||||
/* Close the console handles */
|
/* Close the console handles */
|
||||||
if (BiosConsoleInput != INVALID_HANDLE_VALUE) CloseHandle(BiosConsoleInput);
|
|
||||||
if (BiosConsoleOutput != INVALID_HANDLE_VALUE) CloseHandle(BiosConsoleOutput);
|
if (BiosConsoleOutput != INVALID_HANDLE_VALUE) CloseHandle(BiosConsoleOutput);
|
||||||
|
if (BiosConsoleInput != INVALID_HANDLE_VALUE) CloseHandle(BiosConsoleInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
WORD BiosPeekCharacter(VOID)
|
WORD BiosPeekCharacter(VOID)
|
||||||
|
@ -512,9 +517,9 @@ VOID BiosSetCursorPosition(BYTE Row, BYTE Column, BYTE Page)
|
||||||
|
|
||||||
/* Modify the CRTC registers */
|
/* Modify the CRTC registers */
|
||||||
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_LOC_LOW_REG);
|
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_INDEX, VGA_CRTC_CURSOR_LOC_HIGH_REG);
|
||||||
VgaWritePort(VGA_CRTC_DATA, HIBYTE(Offset));
|
VgaWritePort(VGA_CRTC_DATA , HIBYTE(Offset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,9 +638,9 @@ VOID BiosVideoService(LPWORD Stack)
|
||||||
|
|
||||||
/* Modify the CRTC registers */
|
/* Modify the CRTC registers */
|
||||||
VgaWritePort(VGA_CRTC_INDEX, VGA_CRTC_CURSOR_START_REG);
|
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_INDEX, VGA_CRTC_CURSOR_END_REG);
|
||||||
VgaWritePort(VGA_CRTC_DATA, Bda->CursorEndLine);
|
VgaWritePort(VGA_CRTC_DATA , Bda->CursorEndLine);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -543,14 +543,14 @@ VOID EmulatorStep(VOID)
|
||||||
|
|
||||||
VOID EmulatorCleanup(VOID)
|
VOID EmulatorCleanup(VOID)
|
||||||
{
|
{
|
||||||
/* Free the memory allocated for the 16-bit address space */
|
|
||||||
if (BaseAddress != NULL) HeapFree(GetProcessHeap(), 0, BaseAddress);
|
|
||||||
|
|
||||||
#ifndef NEW_EMULATOR
|
#ifndef NEW_EMULATOR
|
||||||
/* Free the softx86 CPU and FPU emulator */
|
/* Free the softx86 CPU and FPU emulator */
|
||||||
softx86_free(&EmulatorContext);
|
|
||||||
softx87_free(&FpuEmulatorContext);
|
softx87_free(&FpuEmulatorContext);
|
||||||
|
softx86_free(&EmulatorContext);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Free the memory allocated for the 16-bit address space */
|
||||||
|
if (BaseAddress != NULL) HeapFree(GetProcessHeap(), 0, BaseAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID EmulatorSetA20(BOOLEAN Enabled)
|
VOID EmulatorSetA20(BOOLEAN Enabled)
|
||||||
|
|
|
@ -50,7 +50,7 @@ VOID DisplayMessage(LPCWSTR Format, ...)
|
||||||
|
|
||||||
va_start(Parameters, Format);
|
va_start(Parameters, Format);
|
||||||
_vsnwprintf(Buffer, 256, Format, Parameters);
|
_vsnwprintf(Buffer, 256, Format, Parameters);
|
||||||
MessageBox(NULL, Buffer, L"NTVDM Subsystem", MB_OK);
|
MessageBoxW(NULL, Buffer, L"NTVDM Subsystem", MB_OK);
|
||||||
va_end(Parameters);
|
va_end(Parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
|
|
||||||
/* PRIVATE VARIABLES **********************************************************/
|
/* 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 VgaMemory[VGA_NUM_BANKS * VGA_BANK_SIZE];
|
||||||
static BYTE VgaMiscRegister;
|
static BYTE VgaMiscRegister;
|
||||||
static BYTE VgaSeqIndex = VGA_SEQ_RESET_REG;
|
static BYTE VgaSeqIndex = VGA_SEQ_RESET_REG;
|
||||||
|
@ -63,8 +66,7 @@ static inline INT VgaGetAddressSize(VOID)
|
||||||
|
|
||||||
static inline DWORD VgaTranslateReadAddress(DWORD Address)
|
static inline DWORD VgaTranslateReadAddress(DWORD Address)
|
||||||
{
|
{
|
||||||
CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
|
DWORD Offset = Address - VgaGetVideoBaseAddress();
|
||||||
DWORD Offset = Address - MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
|
|
||||||
BYTE Plane;
|
BYTE Plane;
|
||||||
|
|
||||||
/* Check for chain-4 and odd-even mode */
|
/* Check for chain-4 and odd-even mode */
|
||||||
|
@ -94,8 +96,7 @@ static inline DWORD VgaTranslateReadAddress(DWORD Address)
|
||||||
|
|
||||||
static inline DWORD VgaTranslateWriteAddress(DWORD Address)
|
static inline DWORD VgaTranslateWriteAddress(DWORD Address)
|
||||||
{
|
{
|
||||||
CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
|
DWORD Offset = Address - VgaGetVideoBaseAddress();
|
||||||
DWORD Offset = Address - MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
|
|
||||||
|
|
||||||
/* Check for chain-4 and odd-even mode */
|
/* Check for chain-4 and odd-even mode */
|
||||||
if (VgaSeqRegisters[VGA_SEQ_MEM_REG] & VGA_SEQ_MEM_C4)
|
if (VgaSeqRegisters[VGA_SEQ_MEM_REG] & VGA_SEQ_MEM_C4)
|
||||||
|
@ -514,13 +515,11 @@ static VOID VgaUpdateTextCursor(VOID)
|
||||||
|
|
||||||
DWORD VgaGetVideoBaseAddress(VOID)
|
DWORD VgaGetVideoBaseAddress(VOID)
|
||||||
{
|
{
|
||||||
CONST DWORD MemoryBase[] = { 0xA0000, 0xA0000, 0xB0000, 0xB8000 };
|
|
||||||
return MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
|
return MemoryBase[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD VgaGetVideoLimitAddress(VOID)
|
DWORD VgaGetVideoLimitAddress(VOID)
|
||||||
{
|
{
|
||||||
CONST DWORD MemoryLimit[] = { 0xA7FFF, 0xA7FFF, 0xB7FFF, 0xBFFFF };
|
|
||||||
return MemoryLimit[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
|
return MemoryLimit[(VgaGcRegisters[VGA_GC_MISC_REG] >> 2) & 0x03];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue