2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
5 * PURPOSE: VDM DOS Kernel
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
9 /* INCLUDES *******************************************************************/
18 #include "bios/bios.h"
20 /* PRIVATE VARIABLES **********************************************************/
22 // static BYTE CurrentDrive;
23 // static CHAR CurrentDirectories[NUM_DRIVES][DOS_DIR_LENGTH];
25 /* PRIVATE FUNCTIONS **********************************************************/
27 /* PUBLIC FUNCTIONS ***********************************************************/
29 CHAR
DosReadCharacter(WORD FileHandle
)
31 CHAR Character
= '\0';
34 /* Use the file reading function */
35 DosReadFile(FileHandle
, &Character
, 1, &BytesRead
);
40 BOOLEAN
DosCheckInput(VOID
)
42 HANDLE Handle
= DosGetRealHandle(DOS_INPUT_HANDLE
);
44 if (IsConsoleHandle(Handle
))
50 setAH(0x01); // or 0x11 for enhanced, but what to choose?
51 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
56 /* Return keyboard status */
57 return (getZF() == 0);
62 DWORD FileSize
= GetFileSize(Handle
, &FileSizeHigh
);
63 LONG LocationHigh
= 0;
64 DWORD Location
= SetFilePointer(Handle
, 0, &LocationHigh
, FILE_CURRENT
);
66 return ((Location
!= FileSize
) || (LocationHigh
!= FileSizeHigh
));
70 VOID
DosPrintCharacter(WORD FileHandle
, CHAR Character
)
74 /* Use the file writing function */
75 DosWriteFile(FileHandle
, &Character
, 1, &BytesWritten
);
78 BOOLEAN
DosBIOSInitialize(VOID
)
80 PDOS_MCB Mcb
= SEGMENT_TO_MCB(FIRST_MCB_SEGMENT
);
82 LPWSTR SourcePtr
, Environment
;
85 LPSTR DestPtr
= (LPSTR
)SEG_OFF_TO_PTR(SYSTEM_ENV_BLOCK
, 0);
89 CHAR CurrentDirectory
[MAX_PATH
];
90 CHAR DosDirectory
[DOS_DIR_LENGTH
];
97 /* Initialize the MCB */
99 Mcb
->Size
= USER_MEMORY_SIZE
;
102 /* Initialize the link MCB to the UMB area */
103 Mcb
= SEGMENT_TO_MCB(FIRST_MCB_SEGMENT
+ USER_MEMORY_SIZE
+ 1);
104 Mcb
->BlockType
= 'M';
105 Mcb
->Size
= UMB_START_SEGMENT
- FIRST_MCB_SEGMENT
- USER_MEMORY_SIZE
- 2;
106 Mcb
->OwnerPsp
= SYSTEM_PSP
;
108 /* Initialize the UMB area */
109 Mcb
= SEGMENT_TO_MCB(UMB_START_SEGMENT
);
110 Mcb
->BlockType
= 'Z';
111 Mcb
->Size
= UMB_END_SEGMENT
- UMB_START_SEGMENT
;
114 /* Get the environment strings */
115 SourcePtr
= Environment
= GetEnvironmentStringsW();
116 if (Environment
== NULL
) return FALSE
;
118 /* Fill the DOS system environment block */
121 /* Get the size of the ASCII string */
122 AsciiSize
= WideCharToMultiByte(CP_ACP
,
131 /* Allocate memory for the ASCII string */
132 AsciiString
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, AsciiSize
);
133 if (AsciiString
== NULL
)
135 FreeEnvironmentStringsW(Environment
);
139 /* Convert to ASCII */
140 WideCharToMultiByte(CP_ACP
,
149 /* Copy the string into DOS memory */
150 strcpy(DestPtr
, AsciiString
);
152 /* Move to the next string */
153 SourcePtr
+= wcslen(SourcePtr
) + 1;
154 DestPtr
+= strlen(AsciiString
);
157 /* Free the memory */
158 HeapFree(GetProcessHeap(), 0, AsciiString
);
162 /* Free the memory allocated for environment strings */
163 FreeEnvironmentStringsW(Environment
);
168 /* Clear the current directory buffer */
169 ZeroMemory(CurrentDirectories
, sizeof(CurrentDirectories
));
171 /* Get the current directory */
172 if (!GetCurrentDirectoryA(MAX_PATH
, CurrentDirectory
))
174 // TODO: Use some kind of default path?
178 /* Convert that to a DOS path */
179 if (!GetShortPathNameA(CurrentDirectory
, DosDirectory
, DOS_DIR_LENGTH
))
181 // TODO: Use some kind of default path?
186 CurrentDrive
= DosDirectory
[0] - 'A';
188 /* Get the directory part of the path */
189 Path
= strchr(DosDirectory
, '\\');
192 /* Skip the backslash */
196 /* Set the directory */
199 strncpy(CurrentDirectories
[CurrentDrive
], Path
, DOS_DIR_LENGTH
);
202 /* Read CONFIG.SYS */
203 Stream
= _wfopen(DOS_CONFIG_PATH
, L
"r");
206 while (fgetws(Buffer
, sizeof(Buffer
)/sizeof(Buffer
[0]), Stream
))
208 // TODO: Parse the line
216 /* Register the DOS 32-bit Interrupts */
217 // RegisterDosInt32(0x20, DosInt20h);
219 /* Initialize the DOS kernel */
220 return DosKRNLInitialize();