[NTVDM]
[reactos.git] / reactos / subsystems / mvdm / ntvdm / emulator.c
index 57a3afc..344f64e 100644 (file)
@@ -405,6 +405,51 @@ VOID DumpMemory(BOOLEAN TextFormat)
     DPRINT1("Memory dump done\n");
 }
 
+VOID MountFloppy(IN ULONG DiskNumber)
+{
+// FIXME: This should be present in PSDK commdlg.h
+//
+// FlagsEx Values
+#if (_WIN32_WINNT >= 0x0500)
+#define  OFN_EX_NOPLACESBAR         0x00000001
+#endif // (_WIN32_WINNT >= 0x0500)
+
+    OPENFILENAMEA ofn;
+    CHAR szFile[MAX_PATH] = "";
+
+    RtlZeroMemory(&ofn, sizeof(ofn));
+    ofn.lStructSize  = sizeof(ofn);
+    ofn.hwndOwner    = hConsoleWnd;
+    ofn.lpstrTitle   = "Select a virtual floppy image";
+    ofn.Flags        = OFN_EXPLORER | OFN_ENABLESIZING | OFN_LONGNAMES | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
+//  ofn.FlagsEx      = OFN_EX_NOPLACESBAR;
+    ofn.lpstrFilter  = "Virtual floppy images (*.vfd;*.img;*.ima;*.dsk)\0*.vfd\0All files (*.*)\0*.*\0";
+    ofn.lpstrDefExt  = "vfd";
+    ofn.nFilterIndex = 0;
+    ofn.lpstrFile    = szFile;
+    ofn.nMaxFile     = ARRAYSIZE(szFile);
+
+    if (!GetOpenFileNameA(&ofn))
+    {
+        DPRINT1("CommDlgExtendedError = %d\n", CommDlgExtendedError());
+        return;
+    }
+
+    // TODO: Refresh the menu state
+
+    if (!MountDisk(FLOPPY_DISK, DiskNumber, szFile, !!(ofn.Flags & OFN_READONLY)))
+        DisplayMessage(L"An error happened when mounting disk %d", DiskNumber);
+}
+
+VOID EjectFloppy(IN ULONG DiskNumber)
+{
+    // TODO: Refresh the menu state
+
+    if (!UnmountDisk(FLOPPY_DISK, DiskNumber))
+        DisplayMessage(L"An error happened when ejecting disk %d", DiskNumber);
+}
+
+
 VOID EmulatorPause(VOID)
 {
     /* Pause the VDM */
@@ -430,6 +475,8 @@ VOID EmulatorTerminate(VOID)
 
 BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
 {
+    USHORT i;
+
     /* Initialize memory */
     if (!MemInitialize())
     {
@@ -506,6 +553,28 @@ BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
         return FALSE;
     }
 
+    /* Mount the available floppy disks */
+    for (i = 0; i < ARRAYSIZE(GlobalSettings.FloppyDisks); ++i)
+    {
+        if (GlobalSettings.FloppyDisks[i].Length != 0 &&
+            GlobalSettings.FloppyDisks[i].Buffer      &&
+            GlobalSettings.FloppyDisks[i].Buffer != '\0')
+        {
+            MountDisk(FLOPPY_DISK, i, GlobalSettings.FloppyDisks[i].Buffer, FALSE);
+        }
+    }
+
+    /* Mount the available hard disks */
+    for (i = 0; i < ARRAYSIZE(GlobalSettings.HardDisks); ++i)
+    {
+        if (GlobalSettings.HardDisks[i].Length != 0 &&
+            GlobalSettings.HardDisks[i].Buffer      &&
+            GlobalSettings.HardDisks[i].Buffer != '\0')
+        {
+            MountDisk(HARD_DISK, i, GlobalSettings.HardDisks[i].Buffer, FALSE);
+        }
+    }
+
     /* Initialize the software callback system and register the emulator BOPs */
     InitializeInt32();
     RegisterBop(BOP_DEBUGGER  , EmulatorDebugBreakBop);