-
Notifications
You must be signed in to change notification settings - Fork 0
/
atarifilesystem.h
executable file
·251 lines (211 loc) · 8 KB
/
atarifilesystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#ifndef ATARIFILESYSTEM_H
#define ATARIFILESYSTEM_H
#include <QString>
#include <QDateTime>
#include <QList>
#include "diskimage.h"
class AtariDirEntry
{
public:
AtariDirEntry() {no = -1;}
enum Attribute {
Locked = 1,
Hidden = 2,
Archived = 4,
Directory = 8,
Dos10 = 16,
Dos25 = 32,
MyDos = 64
};
Q_DECLARE_FLAGS(Attributes, Attribute)
quint16 firstSector;
QByteArray atariName;
Attributes attributes;
int no;
quint16 dir;
int size;
QDateTime dateTime;
QString name() const;
QString niceName() const;
QString baseName() const;
QString suffix() const;
QString attributeNames() const;
QByteArray internalData;
void makeFromAtariDosEntry(const QByteArray &entry, int aNo, int aDir, bool dd = false);
void makeFromSpartaDosEntry(const QByteArray &entry, int aNo, int aDir);
inline bool isValid() {return no != -1;}
};
Q_DECLARE_OPERATORS_FOR_FLAGS (AtariDirEntry::Attributes)
bool atariDirEntryNoLessThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryNoGreaterThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryNameLessThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryNameGreaterThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryExtensionLessThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryExtensionGreaterThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntrySizeLessThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntrySizeGreaterThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryDateLessThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryDateGreaterThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryNotesLessThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
bool atariDirEntryNotesGreaterThan(const AtariDirEntry &e1, const AtariDirEntry &e2);
class AtariFileSystem: public QObject
{
Q_OBJECT
protected:
SimpleDiskImage *m_image;
bool m_textConversion;
bool m_isConnected;
QByteArray bitmap;
quint16 m_freeSectors;
quint16 findFreeSector(quint16 from = 0);
void allocateSector(quint16 sector);
void freeSector(quint16 sector);
bool sectorIsFree(quint16 sector);
public:
AtariFileSystem(SimpleDiskImage *image) {m_image = image; m_textConversion = false;}
virtual QList <AtariDirEntry> getEntries(quint16 dir) = 0;
virtual uint totalCapacity() = 0;
virtual uint freeSpace() = 0;
virtual QString volumeLabel() = 0;
virtual bool setVolumeLabel(const QString &label) = 0;
bool extractRecursive(QList <AtariDirEntry> &entries, const QString &target);
bool deleteRecursive(QList <AtariDirEntry> &entries);
QList <AtariDirEntry> insertRecursive(quint16 dir, QStringList files);
QByteArray findName(quint16 dir, QString name);
virtual int findFreeFileNo(quint16 dir) = 0;
virtual bool extract(const AtariDirEntry &entry, const QString &target) = 0;
virtual AtariDirEntry insert(quint16 dir, const QString &name) = 0;
virtual bool erase(const AtariDirEntry &entry) = 0;
virtual bool rename(const AtariDirEntry &entry, const QByteArray &name) = 0;
virtual bool setTime(const AtariDirEntry &entry, const QDateTime &time) = 0;
virtual bool setReadOnly(const AtariDirEntry &entry) = 0;
virtual bool setHidden(const AtariDirEntry &entry) = 0;
virtual bool setArchived(const AtariDirEntry &entry) = 0;
inline SimpleDiskImage *image() {return m_image;}
inline bool textConversion() {return m_textConversion;}
inline void setTextConversion(bool conv) {m_textConversion = conv;}
virtual QString name() = 0;
virtual int fileSystemCode() = 0;
virtual bool removeDir(const AtariDirEntry &entry) = 0;
virtual AtariDirEntry makeDir(quint16 dir, const QString &name) = 0;
virtual quint16 rootDir() = 0;
inline bool isConnected() {return m_isConnected;}
};
class Dos10FileSystem: public AtariFileSystem
{
Q_OBJECT
protected:
QByteArray vtoc;
virtual bool writeBitmap();
public:
Dos10FileSystem(SimpleDiskImage *image);
QList <AtariDirEntry> getEntries(quint16 dir);
uint totalCapacity();
int findFreeFileNo(quint16 dir);
uint freeSpace() {return m_freeSectors * (m_image->geometry().bytesPerSector() - 3);}
QString volumeLabel();
bool setVolumeLabel(const QString &label);
bool extract(const AtariDirEntry &entry, const QString &target);
AtariDirEntry insert(quint16 dir, const QString &name);
AtariDirEntry makeDir(quint16 dir, const QString &name);
bool erase(const AtariDirEntry &entry);
bool rename(const AtariDirEntry &entry, const QByteArray &name);
bool setTime(const AtariDirEntry &entry, const QDateTime &time);
bool setReadOnly(const AtariDirEntry &entry);
bool setHidden(const AtariDirEntry &entry);
bool setArchived(const AtariDirEntry &entry);
QString name() {return "Atari Dos 1.0";}
int fileSystemCode() {return 1;}
bool removeDir(const AtariDirEntry &entry);
quint16 rootDir() {return 361;}
};
class Dos20FileSystem: public Dos10FileSystem
{
Q_OBJECT
public:
Dos20FileSystem(SimpleDiskImage *image);
uint totalCapacity();
QString name() {return "Atari Dos 2.0";}
int fileSystemCode() {return 2;}
};
class Dos25FileSystem: public Dos20FileSystem
{
Q_OBJECT
protected:
QByteArray vtoc2;
bool writeBitmap();
public:
Dos25FileSystem(SimpleDiskImage *image);
uint totalCapacity();
QString name() {return "Atari Dos 2.5";}
int fileSystemCode() {return 3;}
};
class MyDosFileSystem: public Dos20FileSystem
{
Q_OBJECT
protected:
QByteArray xvtoc;
bool writeBitmap();
public:
MyDosFileSystem(SimpleDiskImage *image);
uint totalCapacity();
QString name() {return "MyDos";}
int fileSystemCode() {return 4;}
};
class SpartaDosFileSystem;
class SpartaDosFile
{
protected:
SpartaDosFileSystem *m_fileSystem;
QByteArray m_currentSector;
QByteArray m_currentMap;
quint16 m_currentMapOffset;
quint16 m_currentSectorOffset;
quint16 m_firstMap;
uint m_size;
uint m_position;
bool m_isDir;
bool toNextSector();
public:
SpartaDosFile(SpartaDosFileSystem *fileSystem, quint16 firstMap, int size, bool isDir = false);
bool seek(uint position);
QByteArray read(uint bytes);
bool write(const QByteArray &data, uint bytes);
};
class SpartaDosFileSystem: public AtariFileSystem
{
Q_OBJECT
friend class SpartaDosFile;
protected:
quint16 m_rootDirMap;
quint16 m_sectorCount;
quint8 m_bitmapCount;
quint16 m_firstBitmapSector;
quint16 m_firstDataSector;
quint16 m_firstDirSector;
QByteArray m_volumeName;
quint8 m_fileSystemVersion;
quint8 m_sequenceNumber;
public:
SpartaDosFileSystem(SimpleDiskImage *image);
QList <AtariDirEntry> getEntries(quint16 dir);
uint totalCapacity();
uint freeSpace();
QString volumeLabel();
bool setVolumeLabel(const QString &label);
int findFreeFileNo(quint16 dir);
bool extract(const AtariDirEntry &entry, const QString &target);
AtariDirEntry insert(quint16 dir, const QString &name);
AtariDirEntry makeDir(quint16 dir, const QString &name);
bool erase(const AtariDirEntry &entry);
bool rename(const AtariDirEntry &entry, const QByteArray &name);
bool setTime(const AtariDirEntry &entry, const QDateTime &time);
bool setReadOnly(const AtariDirEntry &entry);
bool setHidden(const AtariDirEntry &entry);
bool setArchived(const AtariDirEntry &entry);
QString name() {return "SpartaDos";}
int fileSystemCode() {return 5;}
bool removeDir(const AtariDirEntry &entry);
quint16 rootDir() {return m_rootDirMap;}
};
#endif // ATARIFILESYSTEM_H