dcf9e124fe1853a6781a760f373c28110bfa4943
[reactos.git] / subsystems / ntvdm / dos.h
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: dos.h
5 * PURPOSE: VDM DOS Kernel (header file)
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7 */
8
9 #ifndef _DOS_H_
10 #define _DOS_H_
11
12 /* INCLUDES *******************************************************************/
13
14 #include "ntvdm.h"
15
16 /* DEFINES ********************************************************************/
17
18 //
19 // We are DOS 5.00 (reported by INT 21h, AH=30h)
20 // and DOS 5.50 (reported by INT 21h, AX=3306h) for Windows NT Compatibility
21 //
22 #define DOS_VERSION MAKEWORD(5, 00)
23 #define NTDOS_VERSION MAKEWORD(5, 50)
24
25 #define DOS_CONFIG_PATH L"%SystemRoot%\\system32\\CONFIG.NT"
26 #define DOS_COMMAND_INTERPRETER L"%SystemRoot%\\system32\\COMMAND.COM /k %SystemRoot%\\system32\\AUTOEXEC.NT"
27 #define FIRST_MCB_SEGMENT 0x1000
28 #define USER_MEMORY_SIZE 0x8FFE
29 #define SYSTEM_PSP 0x08
30 #define SYSTEM_ENV_BLOCK 0x800
31 #define INVALID_DOS_HANDLE 0xFFFF
32 #define DOS_INPUT_HANDLE 0
33 #define DOS_OUTPUT_HANDLE 1
34 #define DOS_ERROR_HANDLE 2
35 #define DOS_SFT_SIZE 255
36 #define SEGMENT_TO_MCB(seg) ((PDOS_MCB)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
37 #define SEGMENT_TO_PSP(seg) ((PDOS_PSP)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), 0)))
38 #define UMB_START_SEGMENT 0xC000
39 #define UMB_END_SEGMENT 0xDFFF
40 #define DOS_ALLOC_HIGH 0x40
41 #define DOS_ALLOC_HIGH_LOW 0x80
42 #define DOS_CMDLINE_LENGTH 127
43 #define DOS_DIR_LENGTH 64
44 #define NUM_DRIVES ('Z' - 'A' + 1)
45 #define DOS_CHAR_ATTRIBUTE 0x07
46
47 enum DOS_ALLOC_STRATEGY
48 {
49 DOS_ALLOC_FIRST_FIT,
50 DOS_ALLOC_BEST_FIT,
51 DOS_ALLOC_LAST_FIT
52 };
53
54 #pragma pack(push, 1)
55
56 typedef struct _DOS_MCB
57 {
58 CHAR BlockType;
59 WORD OwnerPsp;
60 WORD Size;
61 BYTE Unused[3];
62 CHAR Name[8];
63 } DOS_MCB, *PDOS_MCB;
64
65 typedef struct _DOS_FCB
66 {
67 BYTE DriveNumber;
68 CHAR FileName[8];
69 CHAR FileExt[3];
70 WORD BlockNumber;
71 WORD RecordSize;
72 DWORD FileSize;
73 WORD LastWriteDate;
74 WORD LastWriteTime;
75 BYTE Reserved[8];
76 BYTE BlockRecord;
77 BYTE RecordNumber[3];
78 } DOS_FCB, *PDOS_FCB;
79
80 typedef struct _DOS_PSP
81 {
82 BYTE Exit[2];
83 WORD LastParagraph;
84 BYTE Reserved0[6];
85 DWORD TerminateAddress;
86 DWORD BreakAddress;
87 DWORD CriticalAddress;
88 WORD ParentPsp;
89 BYTE HandleTable[20];
90 WORD EnvBlock;
91 DWORD LastStack;
92 WORD HandleTableSize;
93 DWORD HandleTablePtr;
94 DWORD PreviousPsp;
95 DWORD Reserved1;
96 WORD DosVersion;
97 BYTE Reserved2[14];
98 BYTE FarCall[3];
99 BYTE Reserved3[9];
100 DOS_FCB Fcb;
101 BYTE CommandLineSize;
102 CHAR CommandLine[DOS_CMDLINE_LENGTH];
103 } DOS_PSP, *PDOS_PSP;
104
105 typedef struct _DOS_INPUT_BUFFER
106 {
107 BYTE MaxLength;
108 BYTE Length;
109 CHAR Buffer[ANYSIZE_ARRAY];
110 } DOS_INPUT_BUFFER, *PDOS_INPUT_BUFFER;
111
112 typedef struct _DOS_DRIVER_HEADER
113 {
114 DWORD NextDriver;
115 WORD Attributes;
116 WORD StrategyEntry;
117 WORD InterruptEntry;
118 CHAR DeviceName[8];
119 } DOS_DRIVER_HEADER, *PDOS_DRIVER_HEADER;
120
121 #pragma pack(pop)
122
123 /* FUNCTIONS ******************************************************************/
124
125 WORD DosAllocateMemory(WORD Size, WORD *MaxAvailable);
126 BOOLEAN DosResizeMemory(WORD BlockData, WORD NewSize, WORD *MaxAvailable);
127 BOOLEAN DosFreeMemory(WORD BlockData);
128 WORD DosCreateFile(LPWORD Handle, LPCSTR FilePath, WORD Attributes);
129 WORD DosOpenFile(LPWORD Handle, LPCSTR FilePath, BYTE AccessMode);
130 WORD DosReadFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesRead);
131 WORD DosWriteFile(WORD FileHandle, LPVOID Buffer, WORD Count, LPWORD BytesWritten);
132 WORD DosSeekFile(WORD FileHandle, LONG Offset, BYTE Origin, LPDWORD NewOffset);
133 BOOLEAN DosDuplicateHandle(WORD OldHandle, WORD NewHandle);
134 BOOLEAN DosCloseHandle(WORD DosHandle);
135 VOID DosInitializePsp(WORD PspSegment, LPCSTR CommandLine, WORD ProgramSize, WORD Environment);
136 BOOLEAN DosCreateProcess(LPCSTR CommandLine, WORD EnvBlock);
137 VOID DosTerminateProcess(WORD Psp, BYTE ReturnCode);
138 CHAR DosReadCharacter(VOID);
139 VOID DosPrintCharacter(CHAR Character);
140 BOOLEAN DosHandleIoctl(BYTE ControlCode, WORD FileHandle);
141
142 VOID WINAPI DosInt20h(LPWORD Stack);
143 VOID WINAPI DosInt21h(LPWORD Stack);
144 VOID WINAPI DosBreakInterrupt(LPWORD Stack);
145 VOID WINAPI DosInt2Fh(LPWORD Stack);
146
147 BOOLEAN DosInitialize(VOID);
148
149 #endif // _DOS_H_
150
151 /* EOF */