2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
5 * PURPOSE: Virtual DOS Machine
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
11 BOOLEAN VdmRunning
= TRUE
;
12 LPVOID BaseAddress
= NULL
;
13 LPCWSTR ExceptionName
[] =
20 L
"Bound Range Exceeded",
25 VOID
DisplayMessage(LPCWSTR Format
, ...)
30 va_start(Parameters
, Format
);
31 _vsnwprintf(Buffer
, 256, Format
, Parameters
);
32 MessageBox(NULL
, Buffer
, L
"NTVDM Subsystem", MB_OK
);
36 BOOL WINAPI
ConsoleCtrlHandler(DWORD ControlType
)
41 case CTRL_BREAK_EVENT
:
43 /* Perform interrupt 0x23 */
44 EmulatorInterrupt(0x23);
48 /* Stop the VDM if the user logs out or closes the console */
55 INT
wmain(INT argc
, WCHAR
*argv
[])
58 BOOLEAN PrintUsage
= TRUE
;
59 CHAR CommandLine
[128];
60 LARGE_INTEGER Frequency
, LastTimerTick
, Counter
;
63 /* Set the handler routine */
64 SetConsoleCtrlHandler(ConsoleCtrlHandler
, TRUE
);
66 /* Parse the command line arguments */
67 for (i
= 1; i
< argc
; i
++)
69 if (argv
[i
][0] != L
'-' && argv
[i
][0] != L
'/') continue;
76 if (argv
[i
+1] != NULL
)
78 /* The DOS command line must be ASCII */
79 WideCharToMultiByte(CP_ACP
, 0, argv
[i
+1], -1, CommandLine
, 128, NULL
, NULL
);
81 /* This is the only mandatory parameter */
88 wprintf(L
"Unknown option: %s", argv
[i
]);
95 wprintf(L
"ReactOS Virtual DOS Machine\n\n");
96 wprintf(L
"Usage: NTVDM /F <PROGRAM>\n");
100 if (!EmulatorInitialize()) return 1;
102 /* Initialize the performance counter (needed for hardware timers) */
103 if (!QueryPerformanceFrequency(&Frequency
))
105 wprintf(L
"FATAL: Performance counter not available\n");
109 /* Initialize the system BIOS */
110 if (!BiosInitialize())
112 wprintf(L
"FATAL: Failed to initialize the VDM BIOS.\n");
116 /* Initialize the VDM DOS kernel */
117 if (!DosInitialize())
119 wprintf(L
"FATAL: Failed to initialize the VDM DOS kernel.\n");
123 /* Start the process from the command line */
124 if (!DosCreateProcess(CommandLine
, 0))
126 DisplayMessage(L
"Could not start program: %S", CommandLine
);
130 /* Set the last timer tick to the current time */
131 QueryPerformanceCounter(&LastTimerTick
);
136 /* Get the current time */
137 QueryPerformanceCounter(&Counter
);
139 /* Get the number of PIT ticks that have passed */
140 TimerTicks
= ((Counter
.QuadPart
- LastTimerTick
.QuadPart
)
141 * PIT_BASE_FREQUENCY
) / Frequency
.QuadPart
;
144 for (i
= 0; i
< TimerTicks
; i
++) PitDecrementCount();
145 LastTimerTick
= Counter
;
147 /* Check for console input events */
148 CheckForInputEvents();
150 /* Continue CPU emulation */