[NTVDM]
[reactos.git] / subsystems / ntvdm / emulator.c
index 0732ebb..6128d5d 100644 (file)
 #define NDEBUG
 
 #include "emulator.h"
+#include "callback.h"
 
 #include "clock.h"
-#include "bios/bios.h"
+#include "bios/rom.h"
 #include "hardware/cmos.h"
 #include "hardware/pic.h"
 #include "hardware/ps2.h"
@@ -169,7 +170,7 @@ VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack)
                    Opcode[9]);
 
     /* Stop the VDM */
-    VdmRunning = FALSE;
+    EmulatorTerminate();
     return;
 }
 
@@ -197,12 +198,12 @@ VOID EmulatorSimulate(VOID)
                        CpuCallLevel, MaxCpuCallLevel);
 
         /* Stop the VDM */
-        VdmRunning = FALSE;
+        EmulatorTerminate();
         return;
     }
     CpuCallLevel++;
 
-    CpuSimulate = TRUE;
+    VdmRunning = CpuSimulate = TRUE;
     while (VdmRunning && CpuSimulate) ClockUpdate();
 
     CpuCallLevel--;
@@ -218,6 +219,12 @@ VOID EmulatorUnsimulate(VOID)
     CpuSimulate = FALSE;
 }
 
+VOID EmulatorTerminate(VOID)
+{
+    /* Stop the VDM */
+    VdmRunning = FALSE;
+}
+
 VOID EmulatorInterrupt(BYTE Number)
 {
     /* Call the Fast486 API */
@@ -235,13 +242,13 @@ VOID EmulatorSetA20(BOOLEAN Enabled)
     A20Line = Enabled;
 }
 
-VOID WINAPI EmulatorDebugBreakBop(LPWORD Stack)
+static VOID WINAPI EmulatorDebugBreakBop(LPWORD Stack)
 {
     DPRINT1("NTVDM: BOP_DEBUGGER\n");
     DebugBreak();
 }
 
-VOID WINAPI EmulatorUnsimulateBop(LPWORD Stack)
+static VOID WINAPI EmulatorUnsimulateBop(LPWORD Stack)
 {
     EmulatorUnsimulate();
 }
@@ -379,12 +386,15 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
     /* Register the I/O Ports */
     RegisterIoPort(CONTROL_SYSTEM_PORT61H, Port61hRead, Port61hWrite);
 
+    /* Set the console input mode */
+    // FIXME: Activate ENABLE_WINDOW_INPUT when we will want to perform actions
+    // upon console window events (screen buffer resize, ...).
+    SetConsoleMode(ConsoleInput, ENABLE_PROCESSED_INPUT /* | ENABLE_WINDOW_INPUT */);
+    // SetConsoleMode(ConsoleOutput, ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
+
     /* Initialize the PS2 port */
     PS2Initialize(ConsoleInput);
 
-    /* Set the console input mode */
-    // SetConsoleMode(ConsoleInput, ENABLE_MOUSE_INPUT | ENABLE_PROCESSED_INPUT);
-
     /* Start the input thread */
     InputThread = CreateThread(NULL, 0, &PumpConsoleInput, ConsoleInput, 0, NULL);
     // if (InputThread == NULL) return FALSE;
@@ -406,7 +416,7 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
 
 VOID EmulatorCleanup(VOID)
 {
-    // VgaCleanup();
+    VgaCleanup();
 
     /* Close the input thread handle */
     if (InputThread != NULL) CloseHandle(InputThread);
@@ -439,7 +449,7 @@ WINAPI
 VDDTerminateVDM(VOID)
 {
     /* Stop the VDM */
-    VdmRunning = FALSE;
+    EmulatorTerminate();
 }
 
 PBYTE