2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: dos/dos32krnl/bios.c
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
9 /* INCLUDES *******************************************************************/
17 #include "bios/bios.h"
19 // This is needed because on UNICODE this symbol is redirected to
20 // GetEnvironmentStringsW whereas on ANSI it corresponds to the real
21 // "ANSI" function (and GetEnvironmentStringsA is aliased to it).
22 #undef GetEnvironmentStrings
24 // Symmetrize the dumbness of the previous symbol: on UNICODE
25 // FreeEnvironmentStrings aliases to FreeEnvironmentStringsW but
26 // on "ANSI" FreeEnvironmentStrings aliases to FreeEnvironmentStringsA
27 #undef FreeEnvironmentStrings
28 #define FreeEnvironmentStrings FreeEnvironmentStringsA
30 /* PRIVATE VARIABLES **********************************************************/
32 // static BYTE CurrentDrive;
33 // static CHAR CurrentDirectories[NUM_DRIVES][DOS_DIR_LENGTH];
35 /* PRIVATE FUNCTIONS **********************************************************/
37 /* PUBLIC FUNCTIONS ***********************************************************/
39 CHAR
DosReadCharacter(WORD FileHandle
)
41 CHAR Character
= '\0';
44 DPRINT("DosReadCharacter\n");
46 /* Use the file reading function */
47 DosReadFile(FileHandle
, &Character
, 1, &BytesRead
);
52 BOOLEAN
DosCheckInput(VOID
)
54 HANDLE Handle
= DosGetRealHandle(DOS_INPUT_HANDLE
);
56 if (IsConsoleHandle(Handle
))
62 setAH(0x01); // or 0x11 for enhanced, but what to choose?
63 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
68 /* Return keyboard status */
69 return (getZF() == 0);
74 DWORD FileSize
= GetFileSize(Handle
, &FileSizeHigh
);
75 LONG LocationHigh
= 0;
76 DWORD Location
= SetFilePointer(Handle
, 0, &LocationHigh
, FILE_CURRENT
);
78 return ((Location
!= FileSize
) || (LocationHigh
!= FileSizeHigh
));
82 VOID
DosPrintCharacter(WORD FileHandle
, CHAR Character
)
86 /* Use the file writing function */
87 DosWriteFile(FileHandle
, &Character
, 1, &BytesWritten
);
90 BOOLEAN
DosBIOSInitialize(VOID
)
92 PDOS_MCB Mcb
= SEGMENT_TO_MCB(FIRST_MCB_SEGMENT
);
94 LPSTR SourcePtr
, Environment
;
95 LPSTR DestPtr
= (LPSTR
)SEG_OFF_TO_PTR(SYSTEM_ENV_BLOCK
, 0);
99 CHAR CurrentDirectory
[MAX_PATH
];
100 CHAR DosDirectory
[DOS_DIR_LENGTH
];
107 /* Initialize the MCB */
108 Mcb
->BlockType
= 'Z';
109 Mcb
->Size
= USER_MEMORY_SIZE
;
112 /* Initialize the link MCB to the UMB area */
113 Mcb
= SEGMENT_TO_MCB(FIRST_MCB_SEGMENT
+ USER_MEMORY_SIZE
+ 1);
114 Mcb
->BlockType
= 'M';
115 Mcb
->Size
= UMB_START_SEGMENT
- FIRST_MCB_SEGMENT
- USER_MEMORY_SIZE
- 2;
116 Mcb
->OwnerPsp
= SYSTEM_PSP
;
118 /* Initialize the UMB area */
119 Mcb
= SEGMENT_TO_MCB(UMB_START_SEGMENT
);
120 Mcb
->BlockType
= 'Z';
121 Mcb
->Size
= UMB_END_SEGMENT
- UMB_START_SEGMENT
;
124 /* Get the environment strings */
125 SourcePtr
= Environment
= GetEnvironmentStrings();
126 if (Environment
== NULL
) return FALSE
;
128 /* Fill the DOS system environment block */
132 * - Ignore environment strings starting with a '=',
133 * they describe current directories.
134 * - Ignore also the WINDIR environment variable since
135 * DOS apps should ignore that we started from ReactOS.
136 * - Upper-case the environment names, not their values.
138 if (*SourcePtr
!= '=' && _strnicmp(SourcePtr
, "WINDIR", 6) != 0)
142 /* Copy the environment string */
143 strcpy(DestPtr
, SourcePtr
);
145 /* Upper-case the environment name */
146 Delim
= strchr(DestPtr
, '='); // Find the '=' delimiter
147 if (Delim
) *Delim
= '\0'; // Temporarily replace it by NULL
148 _strupr(DestPtr
); // Upper-case
149 if (Delim
) *Delim
= '='; // Restore the delimiter
151 DestPtr
+= strlen(SourcePtr
);
153 /* NULL-terminate the environment string */
157 /* Move to the next string */
158 SourcePtr
+= strlen(SourcePtr
) + 1;
160 /* NULL-terminate the environment block */
163 /* Free the memory allocated for environment strings */
164 FreeEnvironmentStrings(Environment
);
169 /* Clear the current directory buffer */
170 RtlZeroMemory(CurrentDirectories
, sizeof(CurrentDirectories
));
172 /* Get the current directory */
173 if (!GetCurrentDirectoryA(MAX_PATH
, CurrentDirectory
))
175 // TODO: Use some kind of default path?
179 /* Convert that to a DOS path */
180 if (!GetShortPathNameA(CurrentDirectory
, DosDirectory
, DOS_DIR_LENGTH
))
182 // TODO: Use some kind of default path?
187 CurrentDrive
= DosDirectory
[0] - 'A';
189 /* Get the directory part of the path */
190 Path
= strchr(DosDirectory
, '\\');
193 /* Skip the backslash */
197 /* Set the directory */
200 strncpy(CurrentDirectories
[CurrentDrive
], Path
, DOS_DIR_LENGTH
);
203 /* Read CONFIG.SYS */
204 Stream
= _wfopen(DOS_CONFIG_PATH
, L
"r");
207 while (fgetws(Buffer
, sizeof(Buffer
)/sizeof(Buffer
[0]), Stream
))
209 // TODO: Parse the line
217 /* Register the DOS 32-bit Interrupts */
218 // RegisterDosInt32(0x20, DosInt20h);
220 /* Initialize the DOS kernel */
221 return DosKRNLInitialize();