Author: hbelusca
Date: Mon Sep 28 01:36:31 2015
New Revision: 69390
URL:
http://svn.reactos.org/svn/reactos?rev=69390&view=rev
Log:
[NTVDM]
Read global settings from the register (in
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NTVDM ; note that this is a
ReactOS-only configuration key, because no equivalent functionality exists on windows),
and currently initialize:
- the BIOS and ROM files to be used;
- the hard disks to be mounted at startup (they cannot be unmounted at runtime, contrary
to the floppies) (maximum 4 hard disks).
Modified:
trunk/reactos/subsystems/mvdm/ntvdm/emulator.c
trunk/reactos/subsystems/mvdm/ntvdm/ntvdm.c
trunk/reactos/subsystems/mvdm/ntvdm/ntvdm.h
Modified: trunk/reactos/subsystems/mvdm/ntvdm/emulator.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/emul…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/emulator.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/emulator.c [iso-8859-1] Mon Sep 28 01:36:31 2015
@@ -475,6 +475,8 @@
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
{
+ USHORT i;
+
/* Initialize memory */
if (!MemInitialize())
{
@@ -551,17 +553,16 @@
return FALSE;
}
-#if 0
- // The following commands are examples of MountDisk usage.
- // NOTE: Those values are hardcoded paths on my local test machines!!
-
- // MountDisk(FLOPPY_DISK, 0, "H:\\trunk\\ntvdm_studies\\diskette_high.vfd",
TRUE);
- // MountDisk(FLOPPY_DISK, 0, "H:\\DOS_tests\\Dos5.0.img", TRUE);
- // MountDisk(FLOPPY_DISK, 0,
"H:\\trunk\\ntvdm_studies\\hdd_10Mo_fixed.vhd", TRUE);
- // MountDisk(FLOPPY_DISK, 0, "H:\\DOS_tests\\diskette_test.vfd", FALSE);
-
- MountDisk(HARD_DISK, 0, "H:\\DOS_tests\\MS-DOS 6_fixed_size.vhd", FALSE);
-#endif
+ /* 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();
Modified: trunk/reactos/subsystems/mvdm/ntvdm/ntvdm.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/ntvd…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/ntvdm.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/ntvdm.c [iso-8859-1] Mon Sep 28 01:36:31 2015
@@ -25,6 +25,8 @@
static HANDLE ConsoleInput = INVALID_HANDLE_VALUE;
static HANDLE ConsoleOutput = INVALID_HANDLE_VALUE;
static DWORD OrgConsoleInputMode, OrgConsoleOutputMode;
+
+NTVDM_SETTINGS GlobalSettings;
// Command line of NTVDM
INT NtVdmArgc;
@@ -276,325 +278,171 @@
}
}
-/* PUBLIC FUNCTIONS ***********************************************************/
-
-VOID
-DisplayMessage(IN LPCWSTR Format, ...)
-{
-#ifndef WIN2K_COMPLIANT
- WCHAR StaticBuffer[256];
- LPWSTR Buffer = StaticBuffer; // Use the static buffer by default.
-#else
- WCHAR Buffer[2048]; // Large enough. If not, increase it by hand.
-#endif
- size_t MsgLen;
- va_list Parameters;
-
- va_start(Parameters, Format);
-
-#ifndef WIN2K_COMPLIANT
- /*
- * Retrieve the message length and if it is too long, allocate
- * an auxiliary buffer; otherwise use the static buffer.
- * The string is built to be NULL-terminated.
- */
- MsgLen = _vscwprintf(Format, Parameters);
- if (MsgLen >= ARRAYSIZE(StaticBuffer))
- {
- Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, (MsgLen + 1) *
sizeof(WCHAR));
- if (Buffer == NULL)
- {
- /* Allocation failed, use the static buffer and display a suitable error
message */
- Buffer = StaticBuffer;
- Format = L"DisplayMessage()\nOriginal message is too long and allocating
an auxiliary buffer failed.";
- MsgLen = wcslen(Format);
- }
- }
-#else
- MsgLen = ARRAYSIZE(Buffer) - 1;
-#endif
-
- RtlZeroMemory(Buffer, (MsgLen + 1) * sizeof(WCHAR));
- _vsnwprintf(Buffer, MsgLen, Format, Parameters);
-
- va_end(Parameters);
-
- /* Display the message */
- DPRINT1("\n\nNTVDM Subsystem\n%S\n\n", Buffer);
- MessageBoxW(hConsoleWnd, Buffer, L"NTVDM Subsystem", MB_OK);
-
-#ifndef WIN2K_COMPLIANT
- /* Free the buffer if needed */
- if (Buffer != StaticBuffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
-#endif
-}
-
-static VOID
-ConsoleCleanup(VOID);
-
-static VOID
-VdmShutdown(BOOLEAN Immediate)
-{
- /*
- * Immediate = TRUE: Immediate shutdown;
- * FALSE: Delayed shutdown.
- */
- static BOOLEAN MustShutdown = FALSE;
-
- /* If a shutdown is ongoing, just return */
- if (MustShutdown)
- {
- DPRINT1("Shutdown is ongoing...\n");
- Sleep(INFINITE);
- return;
- }
-
- /* First notify DOS to see whether we can shut down now */
- MustShutdown = DosShutdown(Immediate);
- /*
- * In case we perform an immediate shutdown, or the DOS says
- * we can shut down, do it now.
- */
- MustShutdown = MustShutdown || Immediate;
-
- if (MustShutdown)
- {
- EmulatorTerminate();
-
- BiosCleanup();
- EmulatorCleanup();
- ConsoleCleanup();
-
- DPRINT1("\n\n\nNTVDM - Exiting...\n\n\n");
- /* Some VDDs rely on the fact that NTVDM calls ExitProcess on Windows */
- ExitProcess(0);
- }
-}
+
+static NTSTATUS
+NTAPI
+NtVdmConfigureBios(IN PWSTR ValueName,
+ IN ULONG ValueType,
+ IN PVOID ValueData,
+ IN ULONG ValueLength,
+ IN PVOID Context,
+ IN PVOID EntryContext)
+{
+ PNTVDM_SETTINGS Settings = (PNTVDM_SETTINGS)Context;
+ UNICODE_STRING ValueString;
+
+ /* Check for the type of the value */
+ if (ValueType != REG_SZ)
+ {
+ RtlInitEmptyAnsiString(&Settings->BiosFileName, NULL, 0);
+ return STATUS_SUCCESS;
+ }
+
+ /* Convert the UNICODE string to ANSI and store it */
+ RtlInitEmptyUnicodeString(&ValueString, (PWCHAR)ValueData, ValueLength);
+ ValueString.Length = ValueString.MaximumLength;
+ RtlUnicodeStringToAnsiString(&Settings->BiosFileName, &ValueString,
TRUE);
+
+ return STATUS_SUCCESS;
+}
+
+static NTSTATUS
+NTAPI
+NtVdmConfigureRom(IN PWSTR ValueName,
+ IN ULONG ValueType,
+ IN PVOID ValueData,
+ IN ULONG ValueLength,
+ IN PVOID Context,
+ IN PVOID EntryContext)
+{
+ PNTVDM_SETTINGS Settings = (PNTVDM_SETTINGS)Context;
+ UNICODE_STRING ValueString;
+
+ /* Check for the type of the value */
+ if (ValueType != REG_MULTI_SZ)
+ {
+ RtlInitEmptyAnsiString(&Settings->RomFiles, NULL, 0);
+ return STATUS_SUCCESS;
+ }
+
+ /* Convert the UNICODE string to ANSI and store it */
+ RtlInitEmptyUnicodeString(&ValueString, (PWCHAR)ValueData, ValueLength);
+ ValueString.Length = ValueString.MaximumLength;
+ RtlUnicodeStringToAnsiString(&Settings->RomFiles, &ValueString, TRUE);
+
+ return STATUS_SUCCESS;
+}
+
+static NTSTATUS
+NTAPI
+NtVdmConfigureHDD(IN PWSTR ValueName,
+ IN ULONG ValueType,
+ IN PVOID ValueData,
+ IN ULONG ValueLength,
+ IN PVOID Context,
+ IN PVOID EntryContext)
+{
+ PNTVDM_SETTINGS Settings = (PNTVDM_SETTINGS)Context;
+ UNICODE_STRING ValueString;
+ ULONG DiskNumber = (ULONG)EntryContext;
+
+ ASSERT(DiskNumber < ARRAYSIZE(Settings->HardDisks));
+
+ /* Check whether the Hard Disk entry was not already configured */
+ if (Settings->HardDisks[DiskNumber].Buffer != NULL)
+ {
+ DPRINT1("Hard Disk %d -- '%Z' already configured\n",
DiskNumber, &Settings->HardDisks[DiskNumber]);
+ return STATUS_SUCCESS;
+ }
+
+ /* Check for the type of the value */
+ if (ValueType != REG_SZ)
+ {
+ RtlInitEmptyAnsiString(&Settings->HardDisks[DiskNumber], NULL, 0);
+ return STATUS_SUCCESS;
+ }
+
+ /* Convert the UNICODE string to ANSI and store it */
+ RtlInitEmptyUnicodeString(&ValueString, (PWCHAR)ValueData, ValueLength);
+ ValueString.Length = ValueString.MaximumLength;
+ RtlUnicodeStringToAnsiString(&Settings->HardDisks[DiskNumber],
&ValueString, TRUE);
+
+ return STATUS_SUCCESS;
+}
+
+static RTL_QUERY_REGISTRY_TABLE
+NtVdmConfigurationTable[] =
+{
+ {
+ NtVdmConfigureBios,
+ 0,
+ L"BiosFile",
+ NULL,
+ REG_NONE,
+ NULL,
+ 0
+ },
+
+ {
+ NtVdmConfigureRom,
+ RTL_QUERY_REGISTRY_NOEXPAND,
+ L"RomFiles",
+ NULL,
+ REG_NONE,
+ NULL,
+ 0
+ },
+
+ {
+ NtVdmConfigureHDD,
+ 0,
+ L"HardDisk0",
+ (PVOID)0,
+ REG_NONE,
+ NULL,
+ 0
+ },
+
+ {
+ NtVdmConfigureHDD,
+ 0,
+ L"HardDisk1",
+ (PVOID)1,
+ REG_NONE,
+ NULL,
+ 0
+ },
+
+ {
+ NtVdmConfigureHDD,
+ 0,
+ L"HardDisk2",
+ (PVOID)2,
+ REG_NONE,
+ NULL,
+ 0
+ },
+
+ {
+ NtVdmConfigureHDD,
+ 0,
+ L"HardDisk3",
+ (PVOID)3,
+ REG_NONE,
+ NULL,
+ 0
+ },
+
+ /* End of table */
+ {0}
+};
static BOOL
-WINAPI
-ConsoleCtrlHandler(DWORD ControlType)
-{
- switch (ControlType)
- {
- case CTRL_LAST_CLOSE_EVENT:
- {
- /* Delayed shutdown */
- DPRINT1("NTVDM delayed killing in the CTRL_LAST_CLOSE_EVENT
CtrlHandler!\n");
- VdmShutdown(FALSE);
- break;
- }
-
- default:
- {
- /* Stop the VDM if the user logs out or closes the console */
- DPRINT1("Killing NTVDM in the 'default' CtrlHandler!\n");
- VdmShutdown(TRUE);
- }
- }
- return TRUE;
-}
-
-static VOID
-ConsoleInitUI(VOID)
-{
- hConsoleWnd = GetConsoleWindow();
- CreateVdmMenu(ConsoleOutput);
-}
-
-static VOID
-ConsoleCleanupUI(VOID)
-{
- /* Display again properly the mouse pointer */
- if (ShowPointer) ShowHideMousePointer(ConsoleOutput, ShowPointer);
-
- DestroyVdmMenu();
-}
-
-BOOL
-ConsoleAttach(VOID)
-{
- /* Save the original input and output console modes */
- if (!GetConsoleMode(ConsoleInput , &OrgConsoleInputMode ) ||
- !GetConsoleMode(ConsoleOutput, &OrgConsoleOutputMode))
- {
- CloseHandle(ConsoleOutput);
- CloseHandle(ConsoleInput);
- wprintf(L"FATAL: Cannot save console in/out modes\n");
- return FALSE;
- }
-
- /* 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, 0 /* | ENABLE_WINDOW_INPUT */);
- EnableExtraHardware(ConsoleInput);
-
- /* Set the console output mode */
- // SetConsoleMode(ConsoleOutput, ENABLE_PROCESSED_OUTPUT |
ENABLE_WRAP_AT_EOL_OUTPUT);
-
- /* Initialize the UI */
- ConsoleInitUI();
-
- return TRUE;
-}
-
-VOID
-ConsoleDetach(VOID)
-{
- /* Cleanup the UI */
- ConsoleCleanupUI();
-
- /* Restore the original input and output console modes */
- SetConsoleMode(ConsoleOutput, OrgConsoleOutputMode);
- SetConsoleMode(ConsoleInput , OrgConsoleInputMode );
-}
-
-static BOOL
-ConsoleInit(VOID)
-{
- /* Set the handler routine */
- SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
-
- /* Enable the CTRL_LAST_CLOSE_EVENT */
- SetLastConsoleEventActive();
-
- /*
- * NOTE: The CONIN$ and CONOUT$ "virtual" files
- * always point to non-redirected console handles.
- */
-
- /* Get the input handle to the real console, and check for success */
- ConsoleInput = CreateFileW(L"CONIN$",
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- if (ConsoleInput == INVALID_HANDLE_VALUE)
- {
- wprintf(L"FATAL: Cannot retrieve a handle to the console input\n");
- return FALSE;
- }
-
- /* Get the output handle to the real console, and check for success */
- ConsoleOutput = CreateFileW(L"CONOUT$",
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
- if (ConsoleOutput == INVALID_HANDLE_VALUE)
- {
- CloseHandle(ConsoleInput);
- wprintf(L"FATAL: Cannot retrieve a handle to the console output\n");
- return FALSE;
- }
-
- /* Effectively attach to the console */
- return ConsoleAttach();
-}
-
-static VOID
-ConsoleCleanup(VOID)
-{
- /* Detach from the console */
- ConsoleDetach();
-
- /* Close the console handles */
- if (ConsoleOutput != INVALID_HANDLE_VALUE) CloseHandle(ConsoleOutput);
- if (ConsoleInput != INVALID_HANDLE_VALUE) CloseHandle(ConsoleInput);
-}
-
-VOID MenuEventHandler(PMENU_EVENT_RECORD MenuEvent)
-{
- switch (MenuEvent->dwCommandId)
- {
- case ID_SHOWHIDE_MOUSE:
- ShowHideMousePointer(ConsoleOutput, ShowPointer);
- ShowPointer = !ShowPointer;
- break;
-
- case ID_VDM_DUMPMEM_TXT:
- DumpMemory(TRUE);
- break;
-
- case ID_VDM_DUMPMEM_BIN:
- DumpMemory(FALSE);
- break;
-
- /* Drive 0 -- Mount */
- /* Drive 1 -- Mount */
- case ID_VDM_DRIVES + 0:
- case ID_VDM_DRIVES + 2:
- {
- ULONG DiskNumber = (MenuEvent->dwCommandId - ID_VDM_DRIVES) / 2;
- MountFloppy(DiskNumber);
- break;
- }
-
- /* Drive 0 -- Eject */
- /* Drive 1 -- Eject */
- case ID_VDM_DRIVES + 1:
- case ID_VDM_DRIVES + 3:
- {
- ULONG DiskNumber = (MenuEvent->dwCommandId - ID_VDM_DRIVES - 1) / 2;
- EjectFloppy(DiskNumber);
- break;
- }
-
- case ID_VDM_QUIT:
- /* Stop the VDM */
- // EmulatorTerminate();
-
- /* Nothing runs, so exit immediately */
- DPRINT1("Killing NTVDM via console menu!\n");
- VdmShutdown(TRUE);
- break;
-
- default:
- break;
- }
-}
-
-VOID FocusEventHandler(PFOCUS_EVENT_RECORD FocusEvent)
-{
- DPRINT1("Focus events not handled\n");
-}
-
-static BOOL
-LoadGlobalSettings(VOID)
-{
-// FIXME: These strings should be localized.
-#define ERROR_MEMORYVDD L"Insufficient memory to load installable Virtual Device
Drivers."
-#define ERROR_REGVDD L"Virtual Device Driver format in the registry is
invalid."
-#define ERROR_LOADVDD L"An installable Virtual Device Driver failed Dll
initialization."
-
- BOOL Success = TRUE;
- LONG Error = 0;
-
- HKEY hNTVDMKey;
- LPCWSTR NTVDMKeyName = L"SYSTEM\\CurrentControlSet\\Control\\NTVDM";
-
- /* Try to open the NTVDM registry key */
- Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
- NTVDMKeyName,
- 0,
- KEY_QUERY_VALUE,
- &hNTVDMKey);
- if (Error == ERROR_FILE_NOT_FOUND)
- {
- /* If the key just doesn't exist, don't do anything else */
- return TRUE;
- }
- else if (Error != ERROR_SUCCESS)
- {
- /* The key exists but there was an access error: display an error and quit */
- DisplayMessage(ERROR_REGVDD);
- return FALSE;
- }
+LoadGlobalSettings(IN PNTVDM_SETTINGS Settings)
+{
+ NTSTATUS Status;
+
+ ASSERT(Settings);
/*
* Now we can do:
@@ -606,11 +454,329 @@
* - Standalone mode?
* - Debug settings
*/
-
-// Quit:
- RegCloseKey(hNTVDMKey);
- return Success;
-}
+ Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
+ L"NTVDM",
+ NtVdmConfigurationTable,
+ Settings,
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("NTVDM registry settings cannot be fully initialized, using default
ones. Status = 0x%08lx\n", Status);
+ }
+
+ return NT_SUCCESS(Status);
+}
+
+static VOID
+FreeGlobalSettings(IN PNTVDM_SETTINGS Settings)
+{
+ USHORT i;
+
+ ASSERT(Settings);
+
+ if (Settings->BiosFileName.Buffer)
+ RtlFreeAnsiString(&Settings->BiosFileName);
+
+ if (Settings->RomFiles.Buffer)
+ RtlFreeAnsiString(&Settings->RomFiles);
+
+ for (i = 0; i < ARRAYSIZE(Settings->HardDisks); ++i)
+ {
+ if (Settings->HardDisks[i].Buffer)
+ RtlFreeAnsiString(&Settings->HardDisks[i]);
+ }
+}
+
+/* PUBLIC FUNCTIONS ***********************************************************/
+
+VOID
+DisplayMessage(IN LPCWSTR Format, ...)
+{
+#ifndef WIN2K_COMPLIANT
+ WCHAR StaticBuffer[256];
+ LPWSTR Buffer = StaticBuffer; // Use the static buffer by default.
+#else
+ WCHAR Buffer[2048]; // Large enough. If not, increase it by hand.
+#endif
+ size_t MsgLen;
+ va_list Parameters;
+
+ va_start(Parameters, Format);
+
+#ifndef WIN2K_COMPLIANT
+ /*
+ * Retrieve the message length and if it is too long, allocate
+ * an auxiliary buffer; otherwise use the static buffer.
+ * The string is built to be NULL-terminated.
+ */
+ MsgLen = _vscwprintf(Format, Parameters);
+ if (MsgLen >= ARRAYSIZE(StaticBuffer))
+ {
+ Buffer = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, (MsgLen + 1) *
sizeof(WCHAR));
+ if (Buffer == NULL)
+ {
+ /* Allocation failed, use the static buffer and display a suitable error
message */
+ Buffer = StaticBuffer;
+ Format = L"DisplayMessage()\nOriginal message is too long and allocating
an auxiliary buffer failed.";
+ MsgLen = wcslen(Format);
+ }
+ }
+#else
+ MsgLen = ARRAYSIZE(Buffer) - 1;
+#endif
+
+ RtlZeroMemory(Buffer, (MsgLen + 1) * sizeof(WCHAR));
+ _vsnwprintf(Buffer, MsgLen, Format, Parameters);
+
+ va_end(Parameters);
+
+ /* Display the message */
+ DPRINT1("\n\nNTVDM Subsystem\n%S\n\n", Buffer);
+ MessageBoxW(hConsoleWnd, Buffer, L"NTVDM Subsystem", MB_OK);
+
+#ifndef WIN2K_COMPLIANT
+ /* Free the buffer if needed */
+ if (Buffer != StaticBuffer) RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
+#endif
+}
+
+static VOID
+ConsoleCleanup(VOID);
+
+static VOID
+VdmShutdown(BOOLEAN Immediate)
+{
+ /*
+ * Immediate = TRUE: Immediate shutdown;
+ * FALSE: Delayed shutdown.
+ */
+ static BOOLEAN MustShutdown = FALSE;
+
+ /* If a shutdown is ongoing, just return */
+ if (MustShutdown)
+ {
+ DPRINT1("Shutdown is ongoing...\n");
+ Sleep(INFINITE);
+ return;
+ }
+
+ /* First notify DOS to see whether we can shut down now */
+ MustShutdown = DosShutdown(Immediate);
+ /*
+ * In case we perform an immediate shutdown, or the DOS says
+ * we can shut down, do it now.
+ */
+ MustShutdown = MustShutdown || Immediate;
+
+ if (MustShutdown)
+ {
+ EmulatorTerminate();
+
+ BiosCleanup();
+ EmulatorCleanup();
+ ConsoleCleanup();
+
+ FreeGlobalSettings(&GlobalSettings);
+
+ DPRINT1("\n\n\nNTVDM - Exiting...\n\n\n");
+ /* Some VDDs rely on the fact that NTVDM calls ExitProcess on Windows */
+ ExitProcess(0);
+ }
+}
+
+static BOOL
+WINAPI
+ConsoleCtrlHandler(DWORD ControlType)
+{
+ switch (ControlType)
+ {
+ case CTRL_LAST_CLOSE_EVENT:
+ {
+ /* Delayed shutdown */
+ DPRINT1("NTVDM delayed killing in the CTRL_LAST_CLOSE_EVENT
CtrlHandler!\n");
+ VdmShutdown(FALSE);
+ break;
+ }
+
+ default:
+ {
+ /* Stop the VDM if the user logs out or closes the console */
+ DPRINT1("Killing NTVDM in the 'default' CtrlHandler!\n");
+ VdmShutdown(TRUE);
+ }
+ }
+ return TRUE;
+}
+
+static VOID
+ConsoleInitUI(VOID)
+{
+ hConsoleWnd = GetConsoleWindow();
+ CreateVdmMenu(ConsoleOutput);
+}
+
+static VOID
+ConsoleCleanupUI(VOID)
+{
+ /* Display again properly the mouse pointer */
+ if (ShowPointer) ShowHideMousePointer(ConsoleOutput, ShowPointer);
+
+ DestroyVdmMenu();
+}
+
+BOOL
+ConsoleAttach(VOID)
+{
+ /* Save the original input and output console modes */
+ if (!GetConsoleMode(ConsoleInput , &OrgConsoleInputMode ) ||
+ !GetConsoleMode(ConsoleOutput, &OrgConsoleOutputMode))
+ {
+ CloseHandle(ConsoleOutput);
+ CloseHandle(ConsoleInput);
+ wprintf(L"FATAL: Cannot save console in/out modes\n");
+ return FALSE;
+ }
+
+ /* 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, 0 /* | ENABLE_WINDOW_INPUT */);
+ EnableExtraHardware(ConsoleInput);
+
+ /* Set the console output mode */
+ // SetConsoleMode(ConsoleOutput, ENABLE_PROCESSED_OUTPUT |
ENABLE_WRAP_AT_EOL_OUTPUT);
+
+ /* Initialize the UI */
+ ConsoleInitUI();
+
+ return TRUE;
+}
+
+VOID
+ConsoleDetach(VOID)
+{
+ /* Cleanup the UI */
+ ConsoleCleanupUI();
+
+ /* Restore the original input and output console modes */
+ SetConsoleMode(ConsoleOutput, OrgConsoleOutputMode);
+ SetConsoleMode(ConsoleInput , OrgConsoleInputMode );
+}
+
+static BOOL
+ConsoleInit(VOID)
+{
+ /* Set the handler routine */
+ SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE);
+
+ /* Enable the CTRL_LAST_CLOSE_EVENT */
+ SetLastConsoleEventActive();
+
+ /*
+ * NOTE: The CONIN$ and CONOUT$ "virtual" files
+ * always point to non-redirected console handles.
+ */
+
+ /* Get the input handle to the real console, and check for success */
+ ConsoleInput = CreateFileW(L"CONIN$",
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ 0,
+ NULL);
+ if (ConsoleInput == INVALID_HANDLE_VALUE)
+ {
+ wprintf(L"FATAL: Cannot retrieve a handle to the console input\n");
+ return FALSE;
+ }
+
+ /* Get the output handle to the real console, and check for success */
+ ConsoleOutput = CreateFileW(L"CONOUT$",
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ 0,
+ NULL);
+ if (ConsoleOutput == INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(ConsoleInput);
+ wprintf(L"FATAL: Cannot retrieve a handle to the console output\n");
+ return FALSE;
+ }
+
+ /* Effectively attach to the console */
+ return ConsoleAttach();
+}
+
+static VOID
+ConsoleCleanup(VOID)
+{
+ /* Detach from the console */
+ ConsoleDetach();
+
+ /* Close the console handles */
+ if (ConsoleOutput != INVALID_HANDLE_VALUE) CloseHandle(ConsoleOutput);
+ if (ConsoleInput != INVALID_HANDLE_VALUE) CloseHandle(ConsoleInput);
+}
+
+VOID MenuEventHandler(PMENU_EVENT_RECORD MenuEvent)
+{
+ switch (MenuEvent->dwCommandId)
+ {
+ case ID_SHOWHIDE_MOUSE:
+ ShowHideMousePointer(ConsoleOutput, ShowPointer);
+ ShowPointer = !ShowPointer;
+ break;
+
+ case ID_VDM_DUMPMEM_TXT:
+ DumpMemory(TRUE);
+ break;
+
+ case ID_VDM_DUMPMEM_BIN:
+ DumpMemory(FALSE);
+ break;
+
+ /* Drive 0 -- Mount */
+ /* Drive 1 -- Mount */
+ case ID_VDM_DRIVES + 0:
+ case ID_VDM_DRIVES + 2:
+ {
+ ULONG DiskNumber = (MenuEvent->dwCommandId - ID_VDM_DRIVES) / 2;
+ MountFloppy(DiskNumber);
+ break;
+ }
+
+ /* Drive 0 -- Eject */
+ /* Drive 1 -- Eject */
+ case ID_VDM_DRIVES + 1:
+ case ID_VDM_DRIVES + 3:
+ {
+ ULONG DiskNumber = (MenuEvent->dwCommandId - ID_VDM_DRIVES - 1) / 2;
+ EjectFloppy(DiskNumber);
+ break;
+ }
+
+ case ID_VDM_QUIT:
+ /* Stop the VDM */
+ // EmulatorTerminate();
+
+ /* Nothing runs, so exit immediately */
+ DPRINT1("Killing NTVDM via console menu!\n");
+ VdmShutdown(TRUE);
+ break;
+
+ default:
+ break;
+ }
+}
+
+VOID FocusEventHandler(PFOCUS_EVENT_RECORD FocusEvent)
+{
+ DPRINT1("Focus events not handled\n");
+}
+
INT
wmain(INT argc, WCHAR *argv[])
@@ -649,7 +815,7 @@
#endif
/* Load global VDM settings */
- LoadGlobalSettings();
+ LoadGlobalSettings(&GlobalSettings);
DPRINT1("\n\n\nNTVDM - Starting...\n\n\n");
@@ -668,7 +834,8 @@
}
/* Initialize the system BIOS and option ROMs */
- if (!BiosInitialize(NULL, NULL))
+ if (!BiosInitialize(GlobalSettings.BiosFileName.Buffer,
+ GlobalSettings.RomFiles.Buffer))
{
wprintf(L"FATAL: Failed to initialize the VDM BIOS.\n");
goto Cleanup;
Modified: trunk/reactos/subsystems/mvdm/ntvdm/ntvdm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/mvdm/ntvdm/ntvd…
==============================================================================
--- trunk/reactos/subsystems/mvdm/ntvdm/ntvdm.h [iso-8859-1] (original)
+++ trunk/reactos/subsystems/mvdm/ntvdm/ntvdm.h [iso-8859-1] Mon Sep 28 01:36:31 2015
@@ -69,7 +69,17 @@
#define ADVANCED_DEBUGGING_LEVEL 1
#endif
-/* FUNCTIONS ******************************************************************/
+
+/* VARIABLES ******************************************************************/
+
+typedef struct _NTVDM_SETTINGS
+{
+ ANSI_STRING BiosFileName;
+ ANSI_STRING RomFiles;
+ ANSI_STRING HardDisks[4];
+} NTVDM_SETTINGS, *PNTVDM_SETTINGS;
+
+extern NTVDM_SETTINGS GlobalSettings;
// Command line of NTVDM
extern INT NtVdmArgc;
@@ -77,6 +87,8 @@
extern HWND hConsoleWnd;
+
+/* FUNCTIONS ******************************************************************/
/*
* Interface functions