dos_system.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // Wengier: LFN support
  2. #ifndef vDOS_DOS_SYSTEM_H
  3. #define vDOS_DOS_SYSTEM_H
  4. #include <vector>
  5. #include "vDos.h"
  6. #include "support.h"
  7. #include "mem.h"
  8. #define DOS_NAMELENGTH 12
  9. #define DOS_NAMELENGTH_ASCII (DOS_NAMELENGTH+1)
  10. #define DOS_FCBNAME 15
  11. #define DOS_PATHLENGTH 255
  12. #define LFN_NAMELENGTH 255
  13. enum {
  14. DOS_ATTR_READ_ONLY= 0x01,
  15. DOS_ATTR_HIDDEN= 0x02,
  16. DOS_ATTR_SYSTEM= 0x04,
  17. DOS_ATTR_VOLUME= 0x08,
  18. DOS_ATTR_DIRECTORY= 0x10,
  19. DOS_ATTR_ARCHIVE= 0x20,
  20. DOS_ATTR_DEVICE= 0x40
  21. };
  22. class DOS_DTA;
  23. class DOS_File
  24. {
  25. public:
  26. DOS_File():flags(0) { name = 0; refCtr = 0; hdrive = 0xff; };
  27. DOS_File(const DOS_File& orig);
  28. // DOS_File & operator= (const DOS_File & orig);
  29. virtual ~DOS_File() { if (name) delete [] name; };
  30. virtual bool Read(Bit8u * data, Bit16u * size) = 0;
  31. virtual bool Write(Bit8u * data, Bit16u * size) = 0;
  32. virtual bool Seek(Bit32u * pos, Bit32u type) = 0;
  33. virtual void Close() {};
  34. virtual bool LockFile(Bit8u mode, Bit32u pos, Bit32u size) { return false; };
  35. virtual Bit16u GetInformation(void) = 0;
  36. virtual void SetName(const char* _name) { if (name) delete[] name; name = new char[strlen(_name)+1]; strcpy(name, _name); }
  37. // virtual char* GetName(void) { return name; };
  38. virtual bool IsName(const char* _name) { if (!name) return false; return stricmp(name, _name) == 0; };
  39. virtual void AddRef() { refCtr++; };
  40. virtual Bits RemoveRef() { return --refCtr; };
  41. virtual void UpdateDateTimeFromHost() {}
  42. virtual bool UpdateHostDateTime(Bit16u ntime, Bit16u ndate, int type) { return false; }
  43. void SetDrive(Bit8u drv) { hdrive = drv;}
  44. Bit8u GetDrive(void) { return hdrive;}
  45. Bit32u flags;
  46. Bit16u atime;
  47. Bit16u adate;
  48. Bit16u ctime;
  49. Bit16u cdate;
  50. Bit16u time;
  51. Bit16u date;
  52. Bit16u attr;
  53. Bits refCtr;
  54. char* name;
  55. private:
  56. Bit8u hdrive;
  57. };
  58. class DOS_Device : public DOS_File
  59. {
  60. public:
  61. DOS_Device(const DOS_Device& orig):DOS_File(orig)
  62. {
  63. devnum = orig.devnum;
  64. }
  65. DOS_Device & operator= (const DOS_Device & orig)
  66. {
  67. DOS_File::operator = (orig);
  68. devnum = orig.devnum;
  69. return *this;
  70. }
  71. DOS_Device():DOS_File(), devnum(0){};
  72. virtual bool Read(Bit8u * data,Bit16u * size);
  73. virtual bool Write(Bit8u * data,Bit16u * size);
  74. virtual bool Seek(Bit32u * pos, Bit32u type);
  75. virtual void Close();
  76. virtual Bit16u GetInformation(void);
  77. void SetDeviceNumber(Bitu num)
  78. {
  79. devnum = num;
  80. }
  81. Bitu GetDeviceNumber(void)
  82. {
  83. return devnum;
  84. }
  85. Bit64u timeOutAt;
  86. bool ffWasLast;
  87. private:
  88. Bitu devnum;
  89. };
  90. class Disk_File : public DOS_File
  91. {
  92. public:
  93. Disk_File(const char* name, HANDLE handle);
  94. bool Read(Bit8u * data, Bit16u * size);
  95. bool Write(Bit8u * data, Bit16u * size);
  96. bool Seek(Bit32u * pos, Bit32u type);
  97. void Close();
  98. bool LockFile(Bit8u mode, Bit32u pos, Bit32u size);
  99. Bit16u GetInformation(void);
  100. void UpdateDateTimeFromHost();
  101. bool UpdateHostDateTime(Bit16u ntime, Bit16u ndate, int type);
  102. private:
  103. HANDLE hFile;
  104. };
  105. class DOS_Drive
  106. {
  107. public:
  108. DOS_Drive(const char* startdir, Bit8u driveNo, bool use=false);
  109. virtual ~DOS_Drive() { };
  110. void SetBaseDir(const char* startdir);
  111. bool FileCreate(DOS_File * * file, char * name, Bit16u attributes);
  112. bool FileOpen(DOS_File * * file, char * name, Bit32u flags);
  113. bool FileExists(const char* name);
  114. bool FileUnlink(char * _name, bool wildcard);
  115. bool FindFirst(char * _dir, DOS_DTA & dta, int handle);
  116. bool SetFileAttr(char * name, Bit16u attr);
  117. bool GetFileAttr(char * name, Bit16u * attr);
  118. bool GetFileAttrEx(char* name, LPVOID fad);
  119. bool GetVolumeInfo(char* name, char* volume_label, DWORD *serial_number);
  120. bool GetFreeDiskSpace(struct _diskfree_t* df);
  121. bool GetDiskFreeSpace32(char* name, DWORD* sectors_per_cluster, DWORD* bytes_per_sector, DWORD* free_clusters, DWORD* total_clusters);
  122. DWORD GetCompressedSize(char* name);
  123. HANDLE CreateOpenFile(char const* const name);
  124. bool MakeDir(char * _dir);
  125. bool RemoveDir(char * _dir);
  126. bool Rename(char * oldname, char * newname);
  127. bool TestDir(char* dir);
  128. char* GetWinDir(void) { return basedir; };
  129. char* GetLabel(void) { return label; };
  130. char basedir[MAX_PATH_LEN];
  131. Bit32u VolSerial;
  132. char curdir[DOS_PATHLENGTH];
  133. char label[14];
  134. bool remote;
  135. bool autouse;
  136. };
  137. enum {OPEN_READ = 0, OPEN_WRITE = 1, OPEN_READWRITE = 2, DOS_NOT_INHERIT = 128};
  138. enum {DOS_SEEK_SET = 0, DOS_SEEK_CUR = 1, DOS_SEEK_END = 2};
  139. bool DoFindNext(int handle);
  140. void closeWinSeachByPSP(Bit16u psp);
  141. /*
  142. A multiplex handler should read the registers to check what function is being called
  143. If the handler returns false dos will stop checking other handlers
  144. */
  145. typedef bool (MultiplexHandler)(void);
  146. // AddDevice stores the pointer to a created device
  147. void DOS_AddDevice(DOS_Device * adddev);
  148. bool WildFileCmp(const char * file, const char * wild);
  149. #endif