Starting something for VDM support.
[reactos.git] / reactos / subsys / ntvdm / ntvdm.c
1 /* $Id: ntvdm.c,v 1.1 2002/10/28 13:59:59 robd Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: subsys/ntvdm/ntvdm.c
6 * PURPOSE: Virtual DOS Machine
7 * PROGRAMMER: Robert Dickenson (robd@mok.lvcm.com)
8 * UPDATE HISTORY:
9 * Created 23/10/2002
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ntos.h>
15 #include <windows.h>
16 #include <stdio.h>
17 #include <wchar.h>
18
19 #define NDEBUG
20 #include <debug.h>
21
22 /* GLOBALS ******************************************************************/
23
24
25 /* FUNCTIONS *****************************************************************/
26
27 void PrintString(char* fmt,...)
28 {
29 char buffer[512];
30 va_list ap;
31
32 va_start(ap, fmt);
33 vsprintf(buffer, fmt, ap);
34 va_end(ap);
35
36 OutputDebugString(buffer);
37 }
38
39 /*
40 GetVersion
41 GetVolumeInformationW
42 GetWindowsDirectoryA
43 GlobalMemoryStatus
44 HeapAlloc
45 HeapCreate
46 HeapDestroy
47 HeapFree
48 HeapReAlloc
49
50 GetNextVDMCommand
51 ExitVDM
52 RegisterConsoleVDM
53 SetVDMCurrentDirectories
54 VDMConsoleOperation
55 WriteConsoleInputVDMW
56
57 NtSetLdtEntries
58 NtTerminateProcess
59
60 NtMapViewOfSection
61 NtUnmapViewOfSection
62
63 NtVdmControl
64 */
65
66 BOOLEAN
67 StartVirtualMachine(VOID)
68 {
69 BOOLEAN Result;
70 STARTUPINFO StartupInfo;
71 PROCESS_INFORMATION ProcessInformation;
72 CHAR CommandLine[MAX_PATH];
73 CHAR CurrentDirectory[MAX_PATH];
74
75 GetSystemDirectory(CommandLine, MAX_PATH);
76 strcat(CommandLine, "\\hello.exe");
77 GetWindowsDirectory(CurrentDirectory, MAX_PATH);
78
79 StartupInfo.cb = sizeof(StartupInfo);
80 StartupInfo.lpReserved = NULL;
81 StartupInfo.lpDesktop = NULL;
82 StartupInfo.lpTitle = NULL;
83 StartupInfo.dwFlags = 0;
84 StartupInfo.cbReserved2 = 0;
85 StartupInfo.lpReserved2 = 0;
86
87 Result = CreateProcess(CommandLine,
88 NULL,
89 NULL,
90 NULL,
91 FALSE,
92 DETACHED_PROCESS,
93 NULL,
94 NULL,
95 &StartupInfo,
96 &ProcessInformation);
97 if (!Result) {
98 PrintString("WL: Failed to execute target process\n");
99 return FALSE;
100 }
101 WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
102 CloseHandle(ProcessInformation.hProcess);
103 CloseHandle(ProcessInformation.hThread);
104 return TRUE;
105 }
106
107 int STDCALL
108 WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
109 {
110 DWORD Result;
111 BOOL Success;
112 ULONG i;
113 NTSTATUS Status;
114
115 CHAR WelcomeMsg[] = "ReactOS Virtual DOS Machine support.\nType q<cr> to quit.";
116 CHAR InputBuffer[255];
117
118 AllocConsole();
119 SetConsoleTitle("ntvdm");
120 StartVirtualMachine();
121
122 for (;;) {
123 WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
124 WelcomeMsg, strlen(WelcomeMsg), // wcslen(WelcomeMsg),
125 &Result, NULL);
126 i = 0;
127 do {
128 ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
129 &InputBuffer[i], 1,
130 &Result, NULL);
131 if (++i >= (sizeof(InputBuffer) - 1)) {
132 break;
133 }
134 } while (InputBuffer[i - 1] != '\n');
135 InputBuffer[i - 1] = '\0';
136
137 if (InputBuffer[0] == 'q' || InputBuffer[0] == 'Q') {
138 break;
139 }
140 }
141
142 ExitProcess(0);
143 return 0;
144 }