[NTVDM]
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 14 May 2015 21:13:07 +0000 (21:13 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 14 May 2015 21:13:07 +0000 (21:13 +0000)
- Add some early "return" after calls to EmulatorTerminate()
- Some VDDs rely on the fact that NTVDM calls ExitProcess on Windows when it is going to quit, so let's do the same.
- Put port 61h (and 62h) support in ppi.c (programmable-peripheral-interface).

svn path=/trunk/; revision=67726

reactos/subsystems/mvdm/ntvdm/CMakeLists.txt
reactos/subsystems/mvdm/ntvdm/bios/bios32/bios32.c
reactos/subsystems/mvdm/ntvdm/dos/dem.c
reactos/subsystems/mvdm/ntvdm/emulator.c
reactos/subsystems/mvdm/ntvdm/emulator.h
reactos/subsystems/mvdm/ntvdm/hardware/ppi.c [new file with mode: 0644]
reactos/subsystems/mvdm/ntvdm/hardware/ppi.h [new file with mode: 0644]
reactos/subsystems/mvdm/ntvdm/hardware/ps2.c
reactos/subsystems/mvdm/ntvdm/memory.c
reactos/subsystems/mvdm/ntvdm/ntvdm.c
reactos/subsystems/mvdm/ntvdm/ntvdm.h

index 3941d8c..57d9b43 100644 (file)
@@ -24,6 +24,7 @@ list(APPEND SOURCE
     hardware/mouse.c
     hardware/pic.c
     hardware/pit.c
+    hardware/ppi.c
     hardware/ps2.c
     hardware/sound/speaker.c
     hardware/video/vga.c
index cf8fabe..c7d3a68 100644 (file)
@@ -454,7 +454,6 @@ static VOID WINAPI BiosRomBasic(LPWORD Stack)
 
     /* Stop the VDM */
     EmulatorTerminate();
-    return;
 }
 
 
index d53d575..c42ab46 100644 (file)
@@ -78,6 +78,7 @@ Quit:
             {
                 /* We failed everything, stop the VDM */
                 EmulatorTerminate();
+                return;
             }
 
             break;
index 71eb005..e3a9fa5 100644 (file)
 #include "hardware/keyboard.h"
 #include "hardware/mouse.h"
 #include "hardware/pic.h"
+#include "hardware/pit.h"
+#include "hardware/ppi.h"
 #include "hardware/ps2.h"
 #include "hardware/sound/speaker.h"
-#include "hardware/pit.h"
 #include "hardware/video/vga.h"
 
 #include "vddsup.h"
@@ -41,8 +42,7 @@
 LPVOID  BaseAddress = NULL;
 BOOLEAN VdmRunning  = TRUE;
 
-static BOOLEAN A20Line   = FALSE;
-static BYTE Port61hState = 0x00;
+static BOOLEAN A20Line = FALSE;
 
 static HANDLE InputThread = NULL;
 
@@ -149,7 +149,6 @@ VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack)
 
     /* Stop the VDM */
     EmulatorTerminate();
-    return;
 }
 
 VOID EmulatorTerminate(VOID)
@@ -181,36 +180,6 @@ static VOID WINAPI EmulatorDebugBreakBop(LPWORD Stack)
     DebugBreak();
 }
 
-static BYTE WINAPI Port61hRead(USHORT Port)
-{
-    return Port61hState;
-}
-
-static VOID WINAPI Port61hWrite(USHORT Port, BYTE Data)
-{
-    // BOOLEAN SpeakerStateChange = FALSE;
-    BYTE OldPort61hState = Port61hState;
-
-    /* Only the four lowest bytes can be written */
-    Port61hState = (Port61hState & 0xF0) | (Data & 0x0F);
-
-    if ((OldPort61hState ^ Port61hState) & 0x01)
-    {
-        DPRINT("PIT 2 Gate %s\n", Port61hState & 0x01 ? "on" : "off");
-        PitSetGate(2, !!(Port61hState & 0x01));
-        // SpeakerStateChange = TRUE;
-    }
-
-    if ((OldPort61hState ^ Port61hState) & 0x02)
-    {
-        /* There were some change for the speaker... */
-        DPRINT("Speaker %s\n", Port61hState & 0x02 ? "on" : "off");
-        // SpeakerStateChange = TRUE;
-    }
-    // if (SpeakerStateChange) SpeakerChange(Port61hState);
-    SpeakerChange(Port61hState);
-}
-
 static VOID WINAPI PitChan0Out(LPVOID Param, BOOLEAN State)
 {
     if (State)
@@ -466,21 +435,18 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
     /* Initialize DMA */
     DmaInitialize();
 
-    /* Initialize the PIC, the PIT, the CMOS and the PC Speaker */
+    /* Initialize PIC, PIT, CMOS, PC Speaker and PS/2 */
     PicInitialize();
-    PitInitialize();
-    CmosInitialize();
-    SpeakerInitialize();
 
-    /* Set output functions */
+    PitInitialize();
     PitSetOutFunction(0, NULL, PitChan0Out);
     PitSetOutFunction(1, NULL, PitChan1Out);
     PitSetOutFunction(2, NULL, PitChan2Out);
 
-    /* Register the I/O Ports */
-    RegisterIoPort(CONTROL_SYSTEM_PORT61H, Port61hRead, Port61hWrite);
+    CmosInitialize();
+    SpeakerInitialize();
+    PpiInitialize();
 
-    /* Initialize the PS/2 port */
     PS2Initialize();
 
     /* Initialize the keyboard and mouse and connect them to their PS/2 ports */
index 72977b8..0b032d7 100644 (file)
@@ -71,10 +71,6 @@ BCD_TO_BINARY(USHORT Value)
     return Result;
 }
 
-/* System I/O ports */
-#define CONTROL_SYSTEM_PORT61H  0x61
-
-
 enum
 {
     EMULATOR_EXCEPTION_DIVISION_BY_ZERO,
diff --git a/reactos/subsystems/mvdm/ntvdm/hardware/ppi.c b/reactos/subsystems/mvdm/ntvdm/hardware/ppi.c
new file mode 100644 (file)
index 0000000..380600c
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * COPYRIGHT:       GPL - See COPYING in the top level directory
+ * PROJECT:         ReactOS Virtual DOS Machine
+ * FILE:            ppi.c
+ * PURPOSE:         Programmable Peripheral Interface emulation -
+ *                  i8255A-5 compatible
+ * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
+ *
+ * NOTES: - Most of its functionality as keyboard controller is replaced
+ *          by the PS/2 controller.
+ *        - This controller is here only for having ports 61h and 62h working.
+ */
+
+/* INCLUDES *******************************************************************/
+
+#define NDEBUG
+
+#include "ntvdm.h"
+#include "emulator.h"
+#include "ppi.h"
+
+#include "hardware/pit.h"
+#include "hardware/sound/speaker.h"
+
+#include "io.h"
+
+/* PRIVATE VARIABLES **********************************************************/
+
+/*static*/ BYTE Port61hState = 0x00; // Used in emulator.c
+static     BYTE Port62hState = 0x00;
+
+/* PRIVATE FUNCTIONS **********************************************************/
+
+static BYTE WINAPI PpiReadPort(USHORT Port)
+{
+    if (Port == PPI_PORT_61H)
+        return Port61hState;
+    else if (Port == PPI_PORT_62H)
+        return Port62hState;
+
+    return 0x00;
+}
+
+static VOID WINAPI Port61hWrite(USHORT Port, BYTE Data)
+{
+    // BOOLEAN SpeakerStateChange = FALSE;
+    BYTE OldPort61hState = Port61hState;
+
+    /* Only the four lowest bytes can be written */
+    Port61hState = (Port61hState & 0xF0) | (Data & 0x0F);
+
+    if ((OldPort61hState ^ Port61hState) & 0x01)
+    {
+        DPRINT("PIT 2 Gate %s\n", Port61hState & 0x01 ? "on" : "off");
+        PitSetGate(2, !!(Port61hState & 0x01));
+        // SpeakerStateChange = TRUE;
+    }
+
+    if ((OldPort61hState ^ Port61hState) & 0x02)
+    {
+        /* There were some change for the speaker... */
+        DPRINT("Speaker %s\n", Port61hState & 0x02 ? "on" : "off");
+        // SpeakerStateChange = TRUE;
+    }
+    // if (SpeakerStateChange) SpeakerChange(Port61hState);
+    SpeakerChange(Port61hState);
+}
+
+static VOID WINAPI Port62hWrite(USHORT Port, BYTE Data)
+{
+    Port62hState = Data;
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+VOID PpiInitialize(VOID)
+{
+    /* Register the I/O Ports */
+    // Port 0x60 is now used by the PS/2 controller
+    RegisterIoPort(PPI_PORT_61H, PpiReadPort, Port61hWrite);
+    RegisterIoPort(PPI_PORT_62H, PpiReadPort, Port62hWrite);
+    // Port 0x63 is unused
+}
+
+/* EOF */
diff --git a/reactos/subsystems/mvdm/ntvdm/hardware/ppi.h b/reactos/subsystems/mvdm/ntvdm/hardware/ppi.h
new file mode 100644 (file)
index 0000000..0f7e1f0
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * COPYRIGHT:       GPL - See COPYING in the top level directory
+ * PROJECT:         ReactOS Virtual DOS Machine
+ * FILE:            ppi.h
+ * PURPOSE:         Programmable Peripheral Interface emulation -
+ *                  i8255A-5 compatible
+ * PROGRAMMERS:     Hermes Belusca-Maito (hermes.belusca@sfr.fr)
+ */
+
+#ifndef _PPI_H_
+#define _PPI_H_
+
+/* DEFINES ********************************************************************/
+
+#define PPI_PORT_61H    0x61
+#define PPI_PORT_62H    0x62
+
+extern BYTE Port61hState;
+
+/* FUNCTIONS ******************************************************************/
+
+VOID PpiInitialize(VOID);
+
+#endif // _PPI_H_
+
+/* EOF */
index 829b6b7..df00ac5 100644 (file)
@@ -201,7 +201,7 @@ static VOID WINAPI PS2WritePort(USHORT Port, BYTE Data)
             {
                 /* Stop the VDM */
                 EmulatorTerminate();
-                break;
+                return;
             }
         }
     }
@@ -230,6 +230,7 @@ static VOID WINAPI PS2WritePort(USHORT Port, BYTE Data)
                     {
                         /* CPU disabled - Stop the VDM */
                         EmulatorTerminate();
+                        return;
                     }
 
                     /* Update the A20 line setting */
index 0b1c219..42da010 100644 (file)
@@ -14,9 +14,6 @@
 #include "emulator.h"
 #include "memory.h"
 
-/* Extra PSDK/NDK Headers */
-#include <ndk/mmfuncs.h>
-
 /* PRIVATE VARIABLES **********************************************************/
 
 typedef struct _MEM_HOOK
index 2399fe1..94e5414 100644 (file)
@@ -542,7 +542,8 @@ Cleanup:
 
     /* Quit the VDM */
     DPRINT1("\n\n\nNTVDM - Exiting...\n\n\n");
-
+    /* Some VDDs rely on the fact that NTVDM calls ExitProcess on Windows */
+    ExitProcess(0);
     return 0;
 }
 
index 193c792..f5f774d 100644 (file)
@@ -35,6 +35,7 @@ DWORD WINAPI SetLastConsoleEventActive(VOID);
 
 #define NTOS_MODE_USER
 #include <ndk/kefuncs.h>
+#include <ndk/mmfuncs.h>
 #include <ndk/obfuncs.h>
 #include <ndk/rtlfuncs.h>
 #include <ndk/rtltypes.h>