Debian Codegraph @

include/dos_system.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /* $Id: dos_system.h,v 1.47 2009-03-04 21:08:22 c2woody Exp $ */
20
21 #ifndef DOSBOX_DOS_SYSTEM_H
22 #define DOSBOX_DOS_SYSTEM_H
23
24 #include <vector>
25 #ifndef DOSBOX_DOSBOX_H
26 #include "dosbox.h"
27 #endif
28 #ifndef DOSBOX_CROSS_H
29 #include "cross.h"
30 #endif
31 #ifndef DOSBOX_SUPPORT_H
32 #include "support.h"
33 #endif
34 #ifndef DOSBOX_MEM_H
35 #include "mem.h"
36 #endif
37
38 #define DOS_NAMELENGTH 12
39 #define DOS_NAMELENGTH_ASCII (DOS_NAMELENGTH+1)
40 #define DOS_FCBNAME 15
41 #define DOS_DIRDEPTH 8
42 #define DOS_PATHLENGTH 80
43 #define DOS_TEMPSIZE 1024
44
45 enum {
46 DOS_ATTR_READ_ONLY= 0x01,
47 DOS_ATTR_HIDDEN= 0x02,
48 DOS_ATTR_SYSTEM= 0x04,
49 DOS_ATTR_VOLUME= 0x08,
50 DOS_ATTR_DIRECTORY= 0x10,
51 DOS_ATTR_ARCHIVE= 0x20,
52 DOS_ATTR_DEVICE= 0x40
53 };
54
55 struct FileStat_Block {
56 Bit32u size;
57 Bit16u time;
58 Bit16u date;
59 Bit16u attr;
60 };
61
62 class DOS_DTA;
63
64 class DOS_File {
65 public:
66 DOS_File():flags(0) { name=0; refCtr = 0; hdrive=0xff; };
67 DOS_File(const DOS_File& orig);
68 DOS_File & operator= (const DOS_File & orig);
69 virtual ~DOS_File(){if(name) delete [] name;};
70 virtual bool Read(Bit8u * data,Bit16u * size)=0;
71 virtual bool Write(Bit8u * data,Bit16u * size)=0;
72 virtual bool Seek(Bit32u * pos,Bit32u type)=0;
73 virtual bool Close()=0;
74 virtual Bit16u GetInformation(void)=0;
75 virtual void SetName(const char* _name) { if (name) delete[] name; name = new char[strlen(_name)+1]; strcpy(name,_name); }
76 virtual char* GetName(void) { return name; };
77 virtual bool IsOpen() { return open; };
78 virtual bool IsName(const char* _name) { if (!name) return false; return strcasecmp(name,_name)==0; };
79 virtual void AddRef() { refCtr++; };
80 virtual Bits RemoveRef() { return --refCtr; };
81 virtual bool UpdateDateTimeFromHost() { return true; }
82 void SetDrive(Bit8u drv) { hdrive=drv;}
83 Bit8u GetDrive(void) { return hdrive;}
84 Bit32u flags;
85 Bit16u time;
86 Bit16u date;
87 Bit16u attr;
88 Bits refCtr;
89 bool open;
90 char* name;
91 /* Some Device Specific Stuff */
92 private:
93 Bit8u hdrive;
94 };
95
96 class DOS_Device : public DOS_File {
97 public:
98 DOS_Device(const DOS_Device& orig):DOS_File(orig) {
99 devnum=orig.devnum;
100 open=true;
101 }
102 DOS_Device & operator= (const DOS_Device & orig) {
103 DOS_File::operator=(orig);
104 devnum=orig.devnum;
105 open=true;
106 return *this;
107 }
108 DOS_Device():DOS_File(),devnum(0){};
109 virtual bool Read(Bit8u * data,Bit16u * size);
110 virtual bool Write(Bit8u * data,Bit16u * size);
111 virtual bool Seek(Bit32u * pos,Bit32u type);
112 virtual bool Close();
113 virtual Bit16u GetInformation(void);
114 virtual bool ReadFromControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode);
115 virtual bool WriteToControlChannel(PhysPt bufptr,Bit16u size,Bit16u * retcode);
116 void SetDeviceNumber(Bitu num) { devnum=num;}
117 private:
118 Bitu devnum;
119 };
120
121 /* The following variable can be lowered to free up some memory.
122 * The negative side effect: The stored searches will be turned over faster.
123 * Should not have impact on systems with few directory entries. */
124 #define MAX_OPENDIRS 2048
125 //Can be high as it's only storage (16 bit variable)
126
127 class DOS_Drive_Cache {
128 public:
129 DOS_Drive_Cache (void);
130 DOS_Drive_Cache (const char* path);
131 ~DOS_Drive_Cache (void);
132
133 enum TDirSort { NOSORT, ALPHABETICAL, DIRALPHABETICAL, ALPHABETICALREV, DIRALPHABETICALREV };
134
135 void SetBaseDir (const char* path);
136 void SetDirSort (TDirSort sort) { sortDirType = sort; };
137 bool OpenDir (const char* path, Bit16u& id);
138 bool ReadDir (Bit16u id, char* &result);
139
140 void ExpandName (char* path);
141 char* GetExpandName (const char* path);
142 bool GetShortName (const char* fullname, char* shortname);
143
144 bool FindFirst (char* path, Bit16u& id);
145 bool FindNext (Bit16u id, char* &result);
146
147 void CacheOut (const char* path, bool ignoreLastDir = false);
148 void AddEntry (const char* path, bool checkExist = false);
149 void DeleteEntry (const char* path, bool ignoreLastDir = false);
150
151 void EmptyCache (void);
152 void SetLabel (const char* name,bool cdrom,bool allowupdate);
153 char* GetLabel (void) { return label; };
154
155 class CFileInfo {
156 public:
157 CFileInfo(void) {
158 orgname[0] = shortname[0] = 0;
159 nextEntry = shortNr = 0;
160 isDir = false;
161 }
162 ~CFileInfo(void) {
163 for (Bit32u i=0; i<fileList.size(); i++) delete fileList[i];
164 fileList.clear();
165 longNameList.clear();
166 };
167 char orgname [CROSS_LEN];
168 char shortname [DOS_NAMELENGTH_ASCII];
169 bool isDir;
170 Bitu nextEntry;
171 Bitu shortNr;
172 // contents
173 std::vector<CFileInfo*> fileList;
174 std::vector<CFileInfo*> longNameList;
175 };
176
177 private:
178
179 bool RemoveTrailingDot (char* shortname);
180 Bits GetLongName (CFileInfo* info, char* shortname);
181 void CreateShortName (CFileInfo* dir, CFileInfo* info);
182 Bitu CreateShortNameID (CFileInfo* dir, const char* name);
183 int CompareShortname (const char* compareName, const char* shortName);
184 bool SetResult (CFileInfo* dir, char * &result, Bitu entryNr);
185 bool IsCachedIn (CFileInfo* dir);
186 CFileInfo* FindDirInfo (const char* path, char* expandedPath);
187 bool RemoveSpaces (char* str);
188 bool OpenDir (CFileInfo* dir, const char* path, Bit16u& id);
189 void CreateEntry (CFileInfo* dir, const char* name, bool query_directory);
190 void CopyEntry (CFileInfo* dir, CFileInfo* from);
191 Bit16u GetFreeID (CFileInfo* dir);
192 void Clear (void);
193
194 CFileInfo* dirBase;
195 char dirPath [CROSS_LEN];
196 char basePath [CROSS_LEN];
197 bool dirFirstTime;
198 TDirSort sortDirType;
199 CFileInfo* save_dir;
200 char save_path [CROSS_LEN];
201 char save_expanded [CROSS_LEN];
202
203 Bit16u srchNr;
204 CFileInfo* dirSearch [MAX_OPENDIRS];
205 char dirSearchName [MAX_OPENDIRS];
206 bool free [MAX_OPENDIRS];
207 CFileInfo* dirFindFirst [MAX_OPENDIRS];
208 Bit16u nextFreeFindFirst;
209
210 char label [CROSS_LEN];
211 bool updatelabel;
212 };
213
214 class DOS_Drive {
215 public:
216 DOS_Drive();
217 virtual ~DOS_Drive(){};
218 virtual bool FileOpen(DOS_File * * file,char * name,Bit32u flags)=0;
219 virtual bool FileCreate(DOS_File * * file,char * name,Bit16u attributes)=0;
220 virtual bool FileUnlink(char * _name)=0;
221 virtual bool RemoveDir(char * _dir)=0;
222 virtual bool MakeDir(char * _dir)=0;
223 virtual bool TestDir(char * _dir)=0;
224 virtual bool FindFirst(char * _dir,DOS_DTA & dta,bool fcb_findfirst=false)=0;
225 virtual bool FindNext(DOS_DTA & dta)=0;
226 virtual bool GetFileAttr(char * name,Bit16u * attr)=0;
227 virtual bool Rename(char * oldname,char * newname)=0;
228 virtual bool AllocationInfo(Bit16u * _bytes_sector,Bit8u * _sectors_cluster,Bit16u * _total_clusters,Bit16u * _free_clusters)=0;
229 virtual bool FileExists(const char* name)=0;
230 virtual bool FileStat(const char* name, FileStat_Block * const stat_block)=0;
231 virtual Bit8u GetMediaByte(void)=0;
232 virtual void SetDir(const char* path) { strcpy(curdir,path); };
233 virtual void EmptyCache(void) { dirCache.EmptyCache(); };
234 virtual bool isRemote(void)=0;
235 virtual bool isRemovable(void)=0;
236 virtual Bits UnMount(void)=0;
237
238 char * GetInfo(void);
239 char curdir[DOS_PATHLENGTH];
240 char info[256];
241 /* Can be overridden for example in iso images */
242 virtual char const * GetLabel(){return dirCache.GetLabel();};
243
244 DOS_Drive_Cache dirCache;
245
246 // disk cycling functionality (request resources)
247 virtual void Activate(void) {};
248 };
249
250 enum { OPEN_READ=0,OPEN_WRITE=1,OPEN_READWRITE=2, DOS_NOT_INHERIT=128};
251 enum { DOS_SEEK_SET=0,DOS_SEEK_CUR=1,DOS_SEEK_END=2};
252
253
254 /*
255 A multiplex handler should read the registers to check what function is being called
256 If the handler returns false dos will stop checking other handlers
257 */
258
259 typedef bool (MultiplexHandler)(void);
260 void DOS_AddMultiplexHandler(MultiplexHandler * handler);
261 void DOS_DelMultiplexHandler(MultiplexHandler * handler);
262
263 /* AddDevice stores the pointer to a created device */
264 void DOS_AddDevice(DOS_Device * adddev);
265 /* DelDevice destroys the device that is pointed to. */
266 void DOS_DelDevice(DOS_Device * dev);
267
268 void VFILE_Register(const char * name,Bit8u * data,Bit32u size);
269 #endif