[NTVDM]
[reactos.git] / subsystems / ntvdm / ntvdm.c
index ab185ac..a533fe5 100644 (file)
@@ -124,12 +124,11 @@ CreateVdmMenu(HANDLE ConOutHandle)
     hConsoleMenu = ConsoleMenuControl(ConsoleOutput,
                                       ID_SHOWHIDE_MOUSE,
                                       ID_VDM_QUIT);
-    if (hConsoleMenu != NULL)
-    {
-        VdmMenuPos = GetMenuItemCount(hConsoleMenu);
-        AppendMenuItems(hConsoleMenu, VdmMainMenuItems);
-        DrawMenuBar(GetConsoleWindow());
-    }
+    if (hConsoleMenu == NULL) return;
+
+    VdmMenuPos = GetMenuItemCount(hConsoleMenu);
+    AppendMenuItems(hConsoleMenu, VdmMainMenuItems);
+    DrawMenuBar(GetConsoleWindow());
 }
 
 static VOID
@@ -151,7 +150,16 @@ static VOID ShowHideMousePointer(HANDLE ConOutHandle, BOOLEAN ShowPtr)
 {
     WCHAR szMenuString[255] = L"";
 
-    ShowConsoleCursor(ConOutHandle, ShowPtr);
+    if (ShowPtr)
+    {
+        /* Be sure the cursor will be shown */
+        while (ShowConsoleCursor(ConOutHandle, TRUE) < 0) ;
+    }
+    else
+    {
+        /* Be sure the cursor will be hidden */
+        while (ShowConsoleCursor(ConOutHandle, FALSE) >= 0) ;
+    }
 
     if (LoadStringW(GetModuleHandle(NULL),
                     (!ShowPtr ? IDS_SHOW_MOUSE : IDS_HIDE_MOUSE),
@@ -191,7 +199,7 @@ BOOL WINAPI ConsoleCtrlHandler(DWORD ControlType)
         default:
         {
             /* Stop the VDM if the user logs out or closes the console */
-            VdmRunning = FALSE;
+            EmulatorTerminate();
         }
     }
     return TRUE;
@@ -247,7 +255,8 @@ DWORD WINAPI PumpConsoleInput(LPVOID Parameter)
                         break;
 
                     case ID_VDM_QUIT:
-                        VdmRunning = FALSE;
+                        /* Stop the VDM */
+                        EmulatorTerminate();
                         break;
 
                     default:
@@ -328,23 +337,20 @@ BOOL ConsoleInit(VOID)
 VOID ConsoleCleanup(VOID)
 {
     SMALL_RECT ConRect;
-    CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
 
     /* Restore the old screen buffer */
     SetConsoleActiveScreenBuffer(ConsoleOutput);
 
     /* Restore the original console size */
-    GetConsoleScreenBufferInfo(ConsoleOutput, &ConsoleInfo);
-    ConRect.Left = 0; // OrgConsoleBufferInfo.srWindow.Left;
-    // ConRect.Top  = ConsoleInfo.dwCursorPosition.Y / (OrgConsoleBufferInfo.srWindow.Bottom - OrgConsoleBufferInfo.srWindow.Top + 1);
-    // ConRect.Top *= (OrgConsoleBufferInfo.srWindow.Bottom - OrgConsoleBufferInfo.srWindow.Top + 1);
-    ConRect.Top    = ConsoleInfo.dwCursorPosition.Y;
+    ConRect.Left   = 0;
+    ConRect.Top    = 0;
     ConRect.Right  = ConRect.Left + OrgConsoleBufferInfo.srWindow.Right  - OrgConsoleBufferInfo.srWindow.Left;
     ConRect.Bottom = ConRect.Top  + OrgConsoleBufferInfo.srWindow.Bottom - OrgConsoleBufferInfo.srWindow.Top ;
-    /* See the following trick explanation in vga.c:VgaEnterTextMode() */
+    /*
+     * See the following trick explanation in vga.c:VgaEnterTextMode() .
+     */
     SetConsoleScreenBufferSize(ConsoleOutput, OrgConsoleBufferInfo.dwSize);
     SetConsoleWindowInfo(ConsoleOutput, TRUE, &ConRect);
-    // SetConsoleWindowInfo(ConsoleOutput, TRUE, &OrgConsoleBufferInfo.srWindow);
     SetConsoleScreenBufferSize(ConsoleOutput, OrgConsoleBufferInfo.dwSize);
 
     /* Restore the original cursor shape */
@@ -365,9 +371,14 @@ VOID ConsoleCleanup(VOID)
 INT wmain(INT argc, WCHAR *argv[])
 {
 #ifndef STANDALONE
-    wprintf(L"\nReactOS Virtual DOS Machine\n\n"
-            L"OS integration (BaseVDM) unimplemented\n");
-    return 0;
+
+    VDM_COMMAND_INFO CommandInfo;
+    CHAR CmdLine[MAX_PATH];
+    CHAR AppName[MAX_PATH];
+    CHAR PifFile[MAX_PATH];
+    CHAR Desktop[MAX_PATH];
+    CHAR Title[MAX_PATH];
+
 #else
 
     CHAR CommandLine[DOS_CMDLINE_LENGTH];
@@ -385,6 +396,8 @@ INT wmain(INT argc, WCHAR *argv[])
 
     DPRINT1("\n\n\nNTVDM - Starting '%s'...\n\n\n", CommandLine);
 
+#endif
+
     /* Initialize the console */
     if (!ConsoleInit())
     {
@@ -400,7 +413,7 @@ INT wmain(INT argc, WCHAR *argv[])
     }
 
     /* Initialize the system BIOS */
-    if (!BiosInitialize(NULL, ConsoleInput, ConsoleOutput))
+    if (!BiosInitialize(NULL))
     {
         wprintf(L"FATAL: Failed to initialize the VDM BIOS.\n");
         goto Cleanup;
@@ -413,6 +426,44 @@ INT wmain(INT argc, WCHAR *argv[])
         goto Cleanup;
     }
 
+#ifndef STANDALONE
+
+    while (TRUE)
+    {
+        /* Clear the structure */
+        ZeroMemory(&CommandInfo, sizeof(CommandInfo));
+
+        /* Initialize the structure members */
+        CommandInfo.VDMState = VDM_NOT_LOADED;
+        CommandInfo.CmdLine = CmdLine;
+        CommandInfo.CmdLen = sizeof(CmdLine);
+        CommandInfo.AppName = AppName;
+        CommandInfo.AppLen = sizeof(AppName);
+        CommandInfo.PifFile = PifFile;
+        CommandInfo.PifLen = sizeof(PifFile);
+        CommandInfo.Desktop = Desktop;
+        CommandInfo.DesktopLen = sizeof(Desktop);
+        CommandInfo.Title = Title;
+        CommandInfo.TitleLen = sizeof(Title);
+
+        if (!GetNextVDMCommand(&CommandInfo)) break;
+
+        /* Start the process from the command line */
+        if (!DosCreateProcess(AppName, 0))
+        {
+            DisplayMessage(L"Could not start program: %S", AppName);
+            goto Cleanup;
+        }
+
+        /* Start simulation */
+        EmulatorSimulate();
+
+        /* Perform another screen refresh */
+        VgaRefreshDisplay();
+    }
+
+#else
+
     /* Start the process from the command line */
     if (!DosCreateProcess(CommandLine, 0))
     {
@@ -423,6 +474,8 @@ INT wmain(INT argc, WCHAR *argv[])
     /* Start simulation */
     EmulatorSimulate();
 
+#endif
+
     /* Perform another screen refresh */
     VgaRefreshDisplay();
 
@@ -431,11 +484,11 @@ Cleanup:
     EmulatorCleanup();
     ConsoleCleanup();
 
+    /* Quit the VDM */
     DPRINT1("\n\n\nNTVDM - Exiting...\n\n\n");
+    ExitVDM(FALSE, 0);
 
     return 0;
-
-#endif
 }
 
 /* EOF */