diff --git a/subsystems/ntvdm/bios.c b/subsystems/ntvdm/bios.c index e5f44e42dd8..e9f9d3d306c 100644 --- a/subsystems/ntvdm/bios.c +++ b/subsystems/ntvdm/bios.c @@ -19,7 +19,7 @@ /* PRIVATE VARIABLES **********************************************************/ -static PBIOS_DATA_AREA Bda; +PBIOS_DATA_AREA Bda; static BYTE BiosKeyboardMap[256]; static HANDLE BiosConsoleInput = INVALID_HANDLE_VALUE; static HANDLE BiosConsoleOutput = INVALID_HANDLE_VALUE; diff --git a/subsystems/ntvdm/bios.h b/subsystems/ntvdm/bios.h index 2ba78969854..0b6320fef49 100644 --- a/subsystems/ntvdm/bios.h +++ b/subsystems/ntvdm/bios.h @@ -99,6 +99,8 @@ typedef struct /* FUNCTIONS ******************************************************************/ +extern PBIOS_DATA_AREA Bda; + BOOLEAN BiosInitialize(VOID); VOID BiosCleanup(VOID); BYTE BiosGetVideoMode(VOID); @@ -112,6 +114,7 @@ VOID BiosKeyboardService(LPWORD Stack); VOID BiosTimeService(LPWORD Stack); VOID BiosHandleIrq(BYTE IrqNumber, LPWORD Stack); VOID BiosSystemTimerInterrupt(LPWORD Stack); +VOID BiosPrintCharacter(CHAR Character, BYTE Attribute, BYTE Page); BOOLEAN BiosScrollWindow( INT Direction, DWORD Amount, diff --git a/subsystems/ntvdm/dos.c b/subsystems/ntvdm/dos.c index 18509d67b89..8faff7c7708 100644 --- a/subsystems/ntvdm/dos.c +++ b/subsystems/ntvdm/dos.c @@ -660,17 +660,30 @@ WORD DosReadFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesRead) WORD Result = ERROR_SUCCESS; DWORD BytesRead32 = 0; HANDLE Handle = DosGetRealHandle(FileHandle); + WORD i; DPRINT("DosReadFile: FileHandle 0x%04X, Count 0x%04X\n", FileHandle, Count); /* Make sure the handle is valid */ if (Handle == INVALID_HANDLE_VALUE) return ERROR_INVALID_HANDLE; - /* Read the file */ - if (!ReadFile(Handle, Buffer, Count, &BytesRead32, NULL)) + if (IsConsoleHandle(Handle)) { - /* Store the error code */ - Result = (WORD)GetLastError(); + for (i = 0; i < Count; i++) + { + /* Call the BIOS function to read the character */ + ((LPBYTE)Buffer)[i] = LOBYTE(BiosGetCharacter()); + BytesRead32++; + } + } + else + { + /* Read the file */ + if (!ReadFile(Handle, Buffer, Count, &BytesRead32, NULL)) + { + /* Store the error code */ + Result = (WORD)GetLastError(); + } } /* The number of bytes read is always 16-bit */ @@ -685,6 +698,7 @@ WORD DosWriteFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesWritte WORD Result = ERROR_SUCCESS; DWORD BytesWritten32 = 0; HANDLE Handle = DosGetRealHandle(FileHandle); + WORD i; DPRINT("DosWriteFile: FileHandle 0x%04X, Count 0x%04X\n", FileHandle, @@ -693,11 +707,23 @@ WORD DosWriteFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesWritte /* Make sure the handle is valid */ if (Handle == INVALID_HANDLE_VALUE) return ERROR_INVALID_HANDLE; - /* Write the file */ - if (!WriteFile(Handle, Buffer, Count, &BytesWritten32, NULL)) + if (IsConsoleHandle(Handle)) { - /* Store the error code */ - Result = (WORD)GetLastError(); + for (i = 0; i < Count; i++) + { + /* Call the BIOS to print the character */ + BiosPrintCharacter(((LPBYTE)Buffer)[i], DOS_CHAR_ATTRIBUTE, Bda->VideoPage); + BytesWritten32++; + } + } + else + { + /* Write the file */ + if (!WriteFile(Handle, Buffer, Count, &BytesWritten32, NULL)) + { + /* Store the error code */ + Result = (WORD)GetLastError(); + } } /* The number of bytes written is always 16-bit */ diff --git a/subsystems/ntvdm/dos.h b/subsystems/ntvdm/dos.h index 5763f6f30d7..669766982fb 100644 --- a/subsystems/ntvdm/dos.h +++ b/subsystems/ntvdm/dos.h @@ -36,6 +36,7 @@ #define DOS_CMDLINE_LENGTH 127 #define DOS_DIR_LENGTH 64 #define NUM_DRIVES ('Z' - 'A' + 1) +#define DOS_CHAR_ATTRIBUTE 0x07 enum DOS_ALLOC_STRATEGY { diff --git a/subsystems/ntvdm/ntvdm.h b/subsystems/ntvdm/ntvdm.h index f34354824b8..5d96120ca27 100644 --- a/subsystems/ntvdm/ntvdm.h +++ b/subsystems/ntvdm/ntvdm.h @@ -26,6 +26,7 @@ #define MAX_ADDRESS TO_LINEAR(MAX_SEGMENT, MAX_OFFSET) #define FAR_POINTER(x) ((ULONG_PTR)BaseAddress + TO_LINEAR(HIWORD(x), LOWORD(x))) #define STEPS_PER_CYCLE 256 +#define IsConsoleHandle(h) (((((ULONG_PTR)h) & 0x10000003) == 3) ? TRUE : FALSE) /* FUNCTIONS ******************************************************************/