dos_inc.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. // Wengier: LFN support
  2. #ifndef vDOS_DOS_INC_H
  3. #define vDOS_DOS_INC_H
  4. #include "dos_system.h"
  5. #include "mem.h"
  6. #ifdef _MSC_VER
  7. #pragma pack (1)
  8. #endif
  9. struct CommandTail{
  10. Bit8u count; // number of bytes returned
  11. char buffer[127]; // the buffer itself
  12. };
  13. #ifdef _MSC_VER
  14. #pragma pack ()
  15. #endif
  16. struct DOS_Date {
  17. Bit16u year;
  18. Bit8u month;
  19. Bit8u day;
  20. };
  21. struct DOS_Version {
  22. Bit8u major, minor;
  23. };
  24. enum {MCB_FREE = 0x0000, MCB_DOS = 0x0008};
  25. enum {RETURN_EXIT = 0, RETURN_CTRLC = 1, RETURN_ABORT = 2, RETURN_TSR = 3};
  26. #define DOS_DRIVES 26
  27. #define DOS_DEVICES 25
  28. // dos swappable area is 0x320 bytes beyond the sysvars table
  29. // device driver chain is inside sysvars
  30. #define DOS_INFOBLOCK_SEG 0x80 // sysvars (list of lists)
  31. #define DOS_CONDRV_SEG 0xa0
  32. #define DOS_CONSTRING_SEG 0xa8
  33. #define DOS_SDA_SEG 0xb2 // dos swappable area
  34. #define DOS_SDA_OFS 0
  35. #define DOS_CDS_SEG 0x108
  36. #define DOS_FIRST_SHELL 0x118
  37. #define DOS_MEM_START 0x16f // First Segment that DOS can use
  38. #define DOS_PRIVATE_SEGMENT 0xc400
  39. #define DOS_PRIVATE_SEGMENT_END 0xc800
  40. // internal Dos Tables
  41. extern DOS_File ** Files;
  42. extern DOS_Drive * Drives[DOS_DRIVES];
  43. extern DOS_Device * Devices[DOS_DEVICES];
  44. extern Bit8u dos_copybuf[0x10000];
  45. void DOS_SetError(Bit16u code);
  46. // File Handling Routines
  47. enum {STDIN = 0, STDOUT = 1, STDERR = 2, STDAUX = 3, STDPRN = 4};
  48. //enum {HAND_NONE = 0, HAND_FILE, HAND_DEVICE};
  49. // Routines for File Class
  50. void DOS_SetupFiles (void);
  51. bool DOS_ReadFile(Bit16u handle, Bit8u * data, Bit16u * amount);
  52. bool DOS_WriteFile(Bit16u handle, Bit8u * data, Bit16u * amount);
  53. bool DOS_SeekFile(Bit16u handle, Bit32u * pos, Bit32u type);
  54. bool DOS_LockFile(Bit16u entry, Bit8u mode, Bit32u pos, Bit32u size);
  55. bool DOS_CloseFile(Bit16u handle);
  56. bool DOS_FlushFile(Bit16u handle);
  57. bool DOS_DuplicateEntry(Bit16u entry, Bit16u * newentry);
  58. bool DOS_ForceDuplicateEntry(Bit16u entry, Bit16u newentry);
  59. bool DOS_GetFileDate(Bit16u entry, Bit16u* otime, Bit16u* odate, int type);
  60. bool DOS_SetFileDate(Bit16u entry, Bit16u ntime, Bit16u ndate, int type);
  61. // Routines for Drive Class
  62. bool DOS_OpenFile(char const * name, Bit8u flags, Bit16u * entry);
  63. bool DOS_OpenFileExtended(char const * name, Bit16u flags, Bit16u createAttr, Bit16u action, Bit16u *entry, Bit16u* status);
  64. bool DOS_CreateFile(char const * name, Bit16u attribute, Bit16u * entry);
  65. bool DOS_DeleteFile(char const * const name, bool wildcard);
  66. bool DOS_FindFirst(char *search, Bit16u attr, int handle);
  67. bool DOS_FindNext(int handle);
  68. bool DOS_Canonicalize(char const * const name, char * const big);
  69. bool DOS_CreateTempFile(char * const name, Bit16u * entry);
  70. bool DOS_FileExists(char const * const name);
  71. // Helper Functions
  72. bool DOS_MakeName(char const * const name, char * const fullname, Bit8u * drive);
  73. bool DOS_GetSFNPath(char const * const path, char * SFNPath, bool LFN);
  74. // Drive Handing Routines
  75. Bit8u DOS_GetDefaultDrive(void);
  76. void DOS_SetDefaultDrive(Bit8u drive);
  77. bool DOS_GetCurrentDir(Bit8u drive, char * const buffer, bool LFN);
  78. bool DOS_ChangeDir(char const * const dir);
  79. bool DOS_MakeDir(char const * const dir);
  80. bool DOS_RemoveDir(char const * const dir);
  81. bool DOS_Rename(char const * const oldname, char const * const newname);
  82. bool DOS_GetFreeDiskSpace(Bit8u drive, Bit16u* bytes_sector, Bit8u* sectors_cluster, Bit16u* total_clusters, Bit16u* free_clusters);
  83. bool DOS_GetDiskFreeSpace32(char* name, DWORD* sectors_per_cluster, DWORD* bytes_per_sector, DWORD* free_clusters, DWORD* total_clusters);
  84. bool DOS_GetFileAttr(char const * const name, Bit16u * attr);
  85. bool DOS_SetFileAttr(char const * const name, Bit16u attr);
  86. bool DOS_GetFileAttrEx(char const* const name, LPVOID fad, Bit8u hdrive=-1);
  87. bool DOS_GetVolumeInfo(char* name, char* volume_label, DWORD *serial_number);
  88. DWORD DOS_GetCompressedFileSize(char const* const name);
  89. HANDLE DOS_CreateOpenFile(char const* const name);
  90. bool DOS_GetAllocationInfo(Bit8u drive, Bit16u * bytes_sector, Bit8u * sectors_cluster, Bit16u * total_clusters);
  91. // IOCTL Stuff
  92. bool DOS_IOCTL(void);
  93. bool DOS_GetSTDINStatus();
  94. Bit8u DOS_FindDevice(char const * name);
  95. void DOS_SetupDevices(void);
  96. // Execute and new process creation
  97. bool DOS_NewPSP(Bit16u pspseg, Bit16u size);
  98. bool DOS_ChildPSP(Bit16u pspseg, Bit16u size);
  99. bool DOS_Execute(char * name, PhysPt block, Bit8u flags);
  100. void DOS_Terminate(Bit16u pspseg, bool tsr, Bit8u exitcode);
  101. // Memory Handling Routines
  102. void DOS_SetupMemory(bool low);
  103. bool DOS_GetFreeUMB(Bit16u * total, Bit16u * largest, Bit16u * count);
  104. bool DOS_AllocateMemory(Bit16u * segment, Bit16u * blocks);
  105. bool DOS_ResizeMemory(Bit16u segment, Bit16u * blocks);
  106. bool DOS_FreeMemory(Bit16u segment);
  107. void DOS_FreeProcessMemory(Bit16u pspseg);
  108. Bit16u DOS_GetPrivatMemory(Bit16u pages);
  109. bool DOS_FreePrivatMemory(Bit16u seg, Bit16u pages);
  110. bool DOS_SetMemAllocStrategy(Bit16u strat);
  111. Bit16u DOS_GetMemAllocStrategy(void);
  112. void DOS_BuildUMBChain(void);
  113. bool DOS_LinkUMBsToMemChain(Bit16u linkstate);
  114. // FCB stuff
  115. bool FCB_OpenFile(Bit16u seg, Bit16u offset);
  116. bool FCB_CreateFile(Bit16u seg, Bit16u offset);
  117. bool FCB_CloseFile(Bit16u seg, Bit16u offset);
  118. bool FCB_FindFirst(Bit16u seg, Bit16u offset);
  119. bool FCB_FindNext(Bit16u seg, Bit16u offset);
  120. Bit8u FCB_ReadFile(Bit16u seg, Bit16u offset, Bit16u numBlocks);
  121. Bit8u FCB_WriteFile(Bit16u seg, Bit16u offset, Bit16u numBlocks);
  122. Bit8u FCB_RandomRead(Bit16u seg, Bit16u offset, Bit16u *numRec, bool restore);
  123. Bit8u FCB_RandomWrite(Bit16u seg, Bit16u offset, Bit16u *numRec, bool restore);
  124. bool FCB_GetFileSize(Bit16u seg, Bit16u offset);
  125. bool FCB_DeleteFile(Bit16u seg, Bit16u offset);
  126. bool FCB_RenameFile(Bit16u seg, Bit16u offset);
  127. void FCB_SetRandomRecord(Bit16u seg, Bit16u offset);
  128. Bit8u FCB_Parsename(Bit16u seg, Bit16u offset, Bit8u parser ,char *string, Bit8u *change);
  129. // Extra DOS Interrupts
  130. void DOS_SetupMisc(void);
  131. // The DOS Tables
  132. void DOS_SetupTables(void);
  133. static Bit16u long2para(Bit32u size)
  134. {
  135. if (size > 0xFFFF0)
  136. return 0xffff;
  137. return (Bit16u)((size+15)/16);
  138. }
  139. static Bit16u DOS_PackTime(Bit16u hour, Bit16u min, Bit16u sec)
  140. {
  141. return (hour&0x1f)<<11 | (min&0x3f) << 5 | ((sec/2)&0x1f);
  142. }
  143. static Bit16u DOS_PackDate(Bit16u year, Bit16u mon, Bit16u day)
  144. {
  145. return ((year-1980)&0x7f)<<9 | (mon&0x3f) << 5 | (day&0x1f);
  146. }
  147. // Dos Error Codes
  148. #define DOSERR_NONE 0
  149. #define DOSERR_FUNCTION_NUMBER_INVALID 1
  150. #define DOSERR_FILE_NOT_FOUND 2
  151. #define DOSERR_PATH_NOT_FOUND 3
  152. #define DOSERR_TOO_MANY_OPEN_FILES 4
  153. #define DOSERR_ACCESS_DENIED 5
  154. #define DOSERR_INVALID_HANDLE 6
  155. #define DOSERR_MCB_DESTROYED 7
  156. #define DOSERR_INSUFFICIENT_MEMORY 8
  157. #define DOSERR_MB_ADDRESS_INVALID 9
  158. #define DOSERR_ENVIRONMENT_INVALID 10
  159. #define DOSERR_FORMAT_INVALID 11
  160. #define DOSERR_ACCESS_CODE_INVALID 12
  161. #define DOSERR_DATA_INVALID 13
  162. #define DOSERR_RESERVED 14
  163. #define DOSERR_FIXUP_OVERFLOW 14
  164. #define DOSERR_INVALID_DRIVE 15
  165. #define DOSERR_REMOVE_CURRENT_DIRECTORY 16
  166. #define DOSERR_NOT_SAME_DEVICE 17
  167. #define DOSERR_NO_MORE_FILES 18
  168. #define DOSERR_DRIVE_NOT_READY 21
  169. #define DOSERR_FILE_ALREADY_EXISTS 80
  170. // Remains some classes used to access certain things
  171. #define sGet(s ,m) GetIt(sizeof(((s *)&pt)->m), (PhysPt)offsetof(s, m))
  172. #define sSave(s, m, val) SaveIt(sizeof(((s *)&pt)->m), (PhysPt)offsetof(s, m), val)
  173. class MemStruct
  174. {
  175. public:
  176. Bitu GetIt(Bitu size, PhysPt addr)
  177. {
  178. switch (size)
  179. {
  180. case 1:
  181. return Mem_Lodsb(pt+addr);
  182. case 2:
  183. return Mem_Lodsw(pt+addr);
  184. case 4:
  185. return Mem_Lodsd(pt+addr);
  186. }
  187. return 0;
  188. }
  189. void SaveIt(Bitu size, PhysPt addr, Bitu val)
  190. {
  191. switch (size)
  192. {
  193. case 1:
  194. Mem_Stosb(pt+addr, (Bit8u)val);
  195. break;
  196. case 2:
  197. Mem_Stosw(pt+addr, (Bit16u)val);
  198. break;
  199. case 4:
  200. Mem_Stosd(pt+addr, (Bit32u)val);
  201. break;
  202. }
  203. }
  204. void SetPt(Bit16u seg)
  205. {
  206. pt = seg<<4;
  207. }
  208. void SetPt(Bit16u seg, Bit16u off)
  209. {
  210. pt = SegOff2Ptr(seg, off);
  211. }
  212. void SetPt(RealPt addr)
  213. {
  214. pt = dWord2Ptr(addr);
  215. }
  216. PhysPt GetPt(void)
  217. {
  218. return pt;
  219. }
  220. protected:
  221. PhysPt pt;
  222. };
  223. class DOS_PSP :public MemStruct
  224. {
  225. public:
  226. DOS_PSP (Bit16u segment) {SetPt(segment); seg=segment;};
  227. void MakeNew (Bit16u memSize);
  228. void CopyFileTable (DOS_PSP* srcpsp,bool createchildpsp);
  229. Bit16u FindFreeFileEntry (void);
  230. void CloseFiles (void);
  231. void SaveVectors (void);
  232. void RestoreVectors (void);
  233. void SetSize (Bit16u size) {sSave(sPSP, next_seg, size); };
  234. Bit16u GetSize (void) {return (Bit16u)sGet(sPSP, next_seg); };
  235. void SetEnvironment (Bit16u envseg) {sSave(sPSP, environment, envseg); };
  236. Bit16u GetEnvironment (void) {return (Bit16u)sGet(sPSP, environment); };
  237. Bit16u GetSegment (void) {return seg; };
  238. void SetFileHandle (Bit16u index, Bit8u handle);
  239. Bit8u GetFileHandle (Bit16u index);
  240. void SetParent (Bit16u parent) {sSave(sPSP, psp_parent, parent); };
  241. Bit16u GetParent (void) {return (Bit16u)sGet(sPSP, psp_parent); };
  242. void SetStack (RealPt stackpt) {sSave(sPSP, stack, stackpt); };
  243. RealPt GetStack (void) {return sGet(sPSP, stack); };
  244. void SetInt22 (RealPt int22pt) {sSave(sPSP,int_22, int22pt); };
  245. RealPt GetInt22 (void) {return sGet(sPSP, int_22); };
  246. void SetFCB1 (RealPt src);
  247. void SetFCB2 (RealPt src);
  248. void SetCommandTail (RealPt src);
  249. void StoreCommandTail (void);
  250. void RestoreCommandTail (void);
  251. void SetNumFiles (Bit16u fileNum);
  252. Bit16u FindEntryByHandle (Bit8u handle);
  253. private:
  254. #ifdef _MSC_VER
  255. #pragma pack(1)
  256. #endif
  257. struct sPSP {
  258. Bit8u exit[2]; // CP/M-like exit poimt
  259. Bit16u next_seg; // Segment of first byte beyond memory allocated or program
  260. Bit8u fill_1; // single char fill
  261. Bit8u far_call; // far call opcode
  262. RealPt cpm_entry; // CPM Service Request address
  263. RealPt int_22; // Terminate Address
  264. RealPt int_23; // Break Address
  265. RealPt int_24; // Critical Error Address
  266. Bit16u psp_parent; // Parent PSP Segment
  267. Bit8u files[20]; // File Table - 0xff is unused
  268. Bit16u environment; // Segment of evironment table
  269. RealPt stack; // SS:SP Save point for int 0x21 calls
  270. Bit16u max_files; // Maximum open files
  271. RealPt file_table; // Pointer to File Table PSP:0x18
  272. RealPt prev_psp; // Pointer to previous PSP
  273. Bit8u interim_flag;
  274. Bit8u truename_flag;
  275. Bit16u nn_flags;
  276. Bit16u dos_version;
  277. Bit8u fill_2[14]; // Lot's of unused stuff i can't care about
  278. Bit8u service[3]; // INT 0x21 Service call int 0x21;retf;
  279. Bit8u fill_3[9]; // This has some blocks with FCB info
  280. Bit8u fcb1[16]; // first FCB
  281. Bit8u fcb2[16]; // second FCB
  282. Bit8u fill_4[4]; // unused
  283. CommandTail cmdtail;
  284. };
  285. #ifdef _MSC_VER
  286. #pragma pack()
  287. #endif
  288. Bit16u seg;
  289. public:
  290. static Bit16u rootpsp;
  291. };
  292. class DOS_ParamBlock:public MemStruct
  293. {
  294. public:
  295. DOS_ParamBlock(PhysPt addr) {pt = addr;}
  296. void Clear(void);
  297. void LoadData(void);
  298. void SaveData(void); // Save it as an exec block
  299. #ifdef _MSC_VER
  300. #pragma pack (1)
  301. #endif
  302. struct sOverlay {
  303. Bit16u loadseg;
  304. Bit16u relocation;
  305. };
  306. struct sExec {
  307. Bit16u envseg;
  308. RealPt cmdtail;
  309. RealPt fcb1;
  310. RealPt fcb2;
  311. RealPt initsssp;
  312. RealPt initcsip;
  313. };
  314. #ifdef _MSC_VER
  315. #pragma pack()
  316. #endif
  317. sExec exec;
  318. sOverlay overlay;
  319. };
  320. class DOS_InfoBlock:public MemStruct {
  321. public:
  322. DOS_InfoBlock () {};
  323. void SetLocation(Bit16u seg);
  324. void SetFirstMCB(Bit16u _first_mcb);
  325. void SetBuffers(Bit16u x,Bit16u y);
  326. void SetCurDirStruct(Bit32u _curdirstruct);
  327. void SetFCBTable(Bit32u _fcbtable);
  328. void SetDeviceChainStart(Bit32u _devchain);
  329. void SetDiskBufferHeadPt(Bit32u _dbheadpt);
  330. void SetStartOfUMBChain(Bit16u _umbstartseg);
  331. void SetUMBChainState(Bit8u _umbchaining);
  332. Bit16u GetStartOfUMBChain(void);
  333. Bit8u GetUMBChainState(void);
  334. RealPt GetPointer(void);
  335. Bit32u GetDeviceChain(void);
  336. #ifdef _MSC_VER
  337. #pragma pack(1)
  338. #endif
  339. struct sDIB {
  340. Bit8u unknown1[4];
  341. Bit16u magicWord; // -0x22 needs to be 1
  342. Bit8u unknown2[8];
  343. Bit16u regCXfrom5e; // -0x18 CX from last int21/ah=5e
  344. Bit16u countLRUcache; // -0x16 LRU counter for FCB caching
  345. Bit16u countLRUopens; // -0x14 LRU counter for FCB openings
  346. Bit8u stuff[6]; // -0x12 some stuff, hopefully never used....
  347. Bit16u sharingCount; // -0x0c sharing retry count
  348. Bit16u sharingDelay; // -0x0a sharing retry delay
  349. RealPt diskBufPtr; // -0x08 pointer to disk buffer
  350. Bit16u ptrCONinput; // -0x04 pointer to con input
  351. Bit16u firstMCB; // -0x02 first memory control block
  352. RealPt firstDPB; // 0x00 first drive parameter block
  353. RealPt firstFileTable; // 0x04 first system file table
  354. RealPt activeClock; // 0x08 active clock device header
  355. RealPt activeCon; // 0x0c active console device header
  356. Bit16u maxSectorLength; // 0x10 maximum bytes per sector of any block device;
  357. RealPt diskInfoBuffer; // 0x12 pointer to disk info buffer
  358. RealPt curDirStructure; // 0x16 pointer to current array of directory structure
  359. RealPt fcbTable; // 0x1a pointer to system FCB table
  360. Bit16u protFCBs; // 0x1e protected fcbs
  361. Bit8u blockDevices; // 0x20 installed block devices
  362. Bit8u lastdrive; // 0x21 lastdrive
  363. Bit32u nulNextDriver; // 0x22 NUL driver next pointer
  364. Bit16u nulAttributes; // 0x26 NUL driver aattributes
  365. Bit32u nulStrategy; // 0x28 NUL driver strategy routine
  366. Bit8u nulString[8]; // 0x2c NUL driver name string
  367. Bit8u joindedDrives; // 0x34 joined drives
  368. Bit16u specialCodeSeg; // 0x35 special code segment
  369. RealPt setverPtr; // 0x37 pointer to setver
  370. Bit16u a20FixOfs; // 0x3b a20 fix routine offset
  371. Bit16u pspLastIfHMA; // 0x3d psp of last program (if dos in hma)
  372. Bit16u buffers_x; // 0x3f x in BUFFERS x,y
  373. Bit16u buffers_y; // 0x41 y in BUFFERS x,y
  374. Bit8u bootDrive; // 0x43 boot drive
  375. Bit8u useDwordMov; // 0x44 use dword moves
  376. Bit16u extendedSize; // 0x45 size of extended memory
  377. Bit32u diskBufferHeadPt; // 0x47 pointer to least-recently used buffer header
  378. Bit16u dirtyDiskBuffers; // 0x4b number of dirty disk buffers
  379. Bit32u lookaheadBufPt; // 0x4d pointer to lookahead buffer
  380. Bit16u lookaheadBufNumber; // 0x51 number of lookahead buffers
  381. Bit8u bufferLocation; // 0x53 workspace buffer location
  382. Bit32u workspaceBuffer; // 0x54 pointer to workspace buffer
  383. Bit8u unknown3[11]; // 0x58
  384. Bit8u chainingUMB; // 0x63 bit0: UMB chain linked to MCB chain
  385. Bit16u minMemForExec; // 0x64 minimum paragraphs needed for current program
  386. Bit16u startOfUMBChain; // 0x66 segment of first UMB-MCB
  387. Bit16u memAllocScanStart; // 0x68 start paragraph for memory allocation
  388. };
  389. #ifdef _MSC_VER
  390. #pragma pack ()
  391. #endif
  392. Bit16u seg;
  393. };
  394. class DOS_DTA:public MemStruct{
  395. public:
  396. DOS_DTA(RealPt addr) { SetPt(addr); }
  397. void SetupSearch(Bit8u _sdrive,int handle,Bit8u _sattr,Bit8u _rattr,char * _pattern);
  398. void SetResult(int handle,const char * _name,const char * _lname,Bit32u _hsize,Bit32u _size,Bit16u _date,Bit16u _time,Bit16u _adate,Bit16u _atime,Bit16u _cdate,Bit16u _ctime,Bit8u _attr);
  399. int GetFindData(int fmt,char * finddata,int *c);
  400. Bit8u GetSearchDrive(int handle);
  401. void GetSearchParams(int handle,Bit8u & _sattr,Bit8u & _rattr,char * _spattern);
  402. void GetResult(int handle,char * _name,char * _lname,Bit32u & _size,Bit16u & _date,Bit16u & _time,Bit8u & _attr);
  403. private:
  404. #ifdef _MSC_VER
  405. #pragma pack(1)
  406. #endif
  407. struct sDTA {
  408. Bit8u sdrive; // The Drive the search is taking place
  409. Bit8u spname[8]; // The Search pattern for the filename
  410. Bit8u spext[3]; // The Search pattern for the extenstion
  411. Bit8u sattr; // The Attributes that need to be found
  412. Bit32u nop; // Custom: Windows search handle for multiple searches at the same time
  413. Bit8u fill[4];
  414. Bit8u attr;
  415. Bit16u time;
  416. Bit16u date;
  417. Bit32u size;
  418. char name[DOS_NAMELENGTH_ASCII];
  419. };
  420. #ifdef _MSC_VER
  421. #pragma pack()
  422. #endif
  423. };
  424. class DOS_FCB: public MemStruct {
  425. public:
  426. DOS_FCB(Bit16u seg, Bit16u off, bool allow_extended = true);
  427. void Create(bool _extended);
  428. void SetName(Bit8u _drive,char * _fname,char * _ext);
  429. void SetResult(Bit32u _size,Bit16u _date,Bit16u _time,Bit8u _attr);
  430. void SetSizeDateTime(Bit32u _size,Bit16u _date,Bit16u _time);
  431. void GetSizeDateTime(Bit32u & _size,Bit16u & _date,Bit16u & _time);
  432. void GetName(char * fillname);
  433. void FileOpen(Bit8u _fhandle);
  434. void FileClose(Bit8u & _fhandle);
  435. void GetRecord(Bit16u & _cur_block,Bit8u & _cur_rec);
  436. void SetRecord(Bit16u _cur_block,Bit8u _cur_rec);
  437. void GetSeqData(Bit8u & _fhandle,Bit16u & _rec_size);
  438. void GetRandom(Bit32u & _random);
  439. void SetRandom(Bit32u _random);
  440. Bit8u GetDrive(void);
  441. bool Extended(void);
  442. void GetAttr(Bit8u & attr);
  443. void SetAttr(Bit8u attr);
  444. bool Valid(void);
  445. private:
  446. bool extended;
  447. PhysPt real_pt;
  448. #ifdef _MSC_VER
  449. #pragma pack (1)
  450. #endif
  451. struct sFCB {
  452. Bit8u drive; // Drive number 0=default, 1=A, etc
  453. Bit8u filename[8]; // Space padded name
  454. Bit8u ext[3]; // Space padded extension
  455. Bit16u cur_block; // Current Block
  456. Bit16u rec_size; // Logical record size
  457. Bit32u filesize; // File Size
  458. Bit16u date;
  459. Bit16u time;
  460. // Reserved Block should be 8 bytes
  461. Bit8u sft_entries;
  462. Bit8u share_attributes;
  463. Bit8u extra_info;
  464. Bit8u file_handle;
  465. Bit8u reserved[4];
  466. // end
  467. Bit8u cur_rec; // Current record in current block
  468. Bit32u rndm; // Current relative record number
  469. };
  470. #ifdef _MSC_VER
  471. #pragma pack ()
  472. #endif
  473. };
  474. class DOS_MCB : public MemStruct
  475. {
  476. public:
  477. DOS_MCB(Bit16u seg) { SetPt(seg);}
  478. void SetFileName(char const * const _name) { strncpy((char *)(MemBase+pt+offsetof(sMCB, filename)), _name, 8); }
  479. void GetFileName(char * const _name) { Mem_CopyFrom(pt+offsetof(sMCB, filename), _name, 8); _name[8] = 0;}
  480. void SetType(Bit8u _type) { sSave(sMCB, type, _type);}
  481. void SetSize(Bit16u _size) {sSave(sMCB, size, _size);}
  482. void SetPSPSeg(Bit16u _pspseg) { sSave(sMCB, psp_segment, _pspseg); if (_pspseg == MCB_FREE) SetFileName(" ");}
  483. Bit8u GetType(void) { return (Bit8u)sGet(sMCB, type);}
  484. Bit16u GetSize(void) { return (Bit16u)sGet(sMCB, size);}
  485. Bit16u GetPSPSeg(void) { return (Bit16u)sGet(sMCB, psp_segment);}
  486. private:
  487. #ifdef _MSC_VER
  488. #pragma pack (1)
  489. #endif
  490. struct sMCB {
  491. Bit8u type;
  492. Bit16u psp_segment;
  493. Bit16u size;
  494. Bit8u unused[3];
  495. Bit8u filename[8];
  496. };
  497. #ifdef _MSC_VER
  498. #pragma pack ()
  499. #endif
  500. };
  501. class DOS_SDA : public MemStruct {
  502. public:
  503. DOS_SDA(Bit16u _seg, Bit16u _offs) { SetPt(_seg, _offs); }
  504. void Init();
  505. void SetDrive(Bit8u _drive) { sSave(sSDA, current_drive, _drive); }
  506. void SetDTA(Bit32u _dta) { sSave(sSDA, current_dta, _dta); }
  507. void SetPSP(Bit16u _psp) { sSave(sSDA, current_psp, _psp); }
  508. Bit8u GetDrive(void) { return (Bit8u)sGet(sSDA, current_drive); }
  509. Bit16u GetPSP(void) { return (Bit16u)sGet(sSDA, current_psp); }
  510. Bit32u GetDTA(void) { return (Bit32u)sGet(sSDA, current_dta); }
  511. private:
  512. #ifdef _MSC_VER
  513. #pragma pack (1)
  514. #endif
  515. struct sSDA {
  516. Bit8u crit_error_flag; // 0x00 Critical Error Flag
  517. Bit8u inDOS_flag; // 0x01 InDOS flag (count of active INT 21 calls)
  518. Bit8u drive_crit_error; // 0x02 Drive on which current critical error occurred or FFh
  519. Bit8u locus_of_last_error; // 0x03 locus of last error
  520. Bit16u extended_error_code; // 0x04 extended error code of last error
  521. Bit8u suggested_action; // 0x06 suggested action for last error
  522. Bit8u error_class; // 0x07 class of last error
  523. Bit32u last_error_pointer; // 0x08 ES:DI pointer for last error
  524. Bit32u current_dta; // 0x0C current DTA (Disk Transfer Address)
  525. Bit16u current_psp; // 0x10 current PSP
  526. Bit16u sp_int_23; // 0x12 stores SP across an INT 23
  527. Bit16u return_code; // 0x14 return code from last process termination (zerod after reading with AH=4Dh)
  528. Bit8u current_drive; // 0x16 current drive
  529. Bit8u extended_break_flag; // 0x17 extended break flag
  530. Bit8u fill[2]; // 0x18 flag: code page switching || flag: copy of previous byte in case of INT 24 Abort
  531. };
  532. #ifdef _MSC_VER
  533. #pragma pack()
  534. #endif
  535. };
  536. extern DOS_InfoBlock dos_infoblock;
  537. struct DOS_Block {
  538. DOS_Date date;
  539. bool hostdate;
  540. DOS_Version version;
  541. Bit16u firstMCB;
  542. Bit16u errorcode;
  543. Bit16u psp(){ return DOS_SDA(DOS_SDA_SEG, DOS_SDA_OFS).GetPSP(); };
  544. void psp(Bit16u _seg){ DOS_SDA(DOS_SDA_SEG, DOS_SDA_OFS).SetPSP(_seg); };
  545. Bit16u env;
  546. RealPt cpmentry;
  547. RealPt dta(){ return DOS_SDA(DOS_SDA_SEG, DOS_SDA_OFS).GetDTA(); };
  548. void dta(RealPt _dta){ DOS_SDA(DOS_SDA_SEG, DOS_SDA_OFS).SetDTA(_dta); };
  549. Bit8u return_code, return_mode;
  550. Bit8u current_drive;
  551. bool verify;
  552. bool breakcheck;
  553. bool echo; // If set to true dev_con::read will echo input
  554. struct {
  555. RealPt mediaid;
  556. RealPt tempdta;
  557. RealPt tempdta_fcbdelete;
  558. RealPt dbcs;
  559. RealPt filenamechar;
  560. RealPt collatingseq;
  561. RealPt upcase;
  562. Bit8u* country; // Will be copied to dos memory. resides in real mem
  563. Bit16u dpb; // Fake Disk parameter system using only the first entry so the drive letter matches
  564. } tables;
  565. Bit16u loaded_codepage;
  566. };
  567. extern DOS_Block dos;
  568. static Bit8u RealHandle(Bit16u handle)
  569. {
  570. DOS_PSP psp(dos.psp());
  571. return psp.GetFileHandle(handle);
  572. }
  573. #endif