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