[NTVDM]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Thu, 15 Aug 2013 01:40:50 +0000 (01:40 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Thu, 15 Aug 2013 01:40:50 +0000 (01:40 +0000)
Make the BIOS Data Area accessible to other parts of ntvdm.
Properly redirect read/write access to the console to the keyboard and VGA systems, respectively.

svn path=/branches/ntvdm/; revision=59741

subsystems/ntvdm/bios.c
subsystems/ntvdm/bios.h
subsystems/ntvdm/dos.c
subsystems/ntvdm/dos.h
subsystems/ntvdm/ntvdm.h

index e5f44e4..e9f9d3d 100644 (file)
@@ -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;
index 2ba7896..0b6320f 100644 (file)
@@ -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,
index 18509d6..8faff7c 100644 (file)
@@ -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 */
index 5763f6f..6697669 100644 (file)
@@ -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
 {
index f343548..5d96120 100644 (file)
@@ -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 ******************************************************************/