-
Notifications
You must be signed in to change notification settings - Fork 37
/
t64driver.hpp
executable file
·134 lines (111 loc) · 3.05 KB
/
t64driver.hpp
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
#ifndef T64DRIVER_H
#define T64DRIVER_H
#include "filedriverbase.hpp"
//
// Title : MMC2IEC - T64DRIVER
// Author : Lars Pontoppidan
// Version : 0.6
// Target MCU : AtMega32(L) at 8 MHz
//
// DESCRIPTION:
// This module works on top of the FAT driver, providing access to files in an
// T64 tape image.
//
// DISCLAIMER:
// The author is in no way responsible for any problems or damage caused by
// using this code. Use at your own risk.
//
// LICENSE:
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
class T64 : public FileDriverBase
{
public:
// Host file system D64-image can be opened from constructor, if specified.
T64(const QString& fileName = QString());
virtual ~T64();
const QString& extension() const
{
static const QString ext("T64");
return ext;
} // extension
// The host file system T64 image is opened or re-opened with the method below.
// If cannot be opened or not a T64 image, it returns false, true otherwise.
bool openHostFile(const QString& fileName);
void closeHostFile();
// t64 driver api
//
// It can be checked if the disk image is considered OK:
FSStatus status(void) const;
bool sendListing(ISendLine& cb);
bool supportsListing() const
{
return true;
}
// Whether this file system supports media info or not (true == supports it).
bool supportsMediaInfo() const
{
return true;
}
bool sendMediaInfo(ISendLine &cb);
// Open a file by filename: Returns true if successfull
bool fopen(const QString &fileName);
QString openedFileName() const;
ushort openedFileSize() const;
//
// Get character from open file:
char getc(void);
//
// Returns true if last character was retrieved:
bool isEOF(void) const;
//
// Close current file
bool close(void);
private:
typedef struct __attribute__((packed))
{
uchar c64sFileType;
uchar d64FileType;
uchar startAddressLo;
uchar startAddressHi;
uchar endAddressLo;
uchar endAddressHi;
uchar unused[2];
ulong fileOffset;
uchar unused2[4];
uchar fileName[16];
} DirEntry; // 32 bytes
typedef struct __attribute__((packed))
{
uchar signature[32];
ushort versionNo;
uchar maxEntriesLo;
uchar maxEntriesHi;
uchar usedEntriesLo;
uchar usedEntriesHi;
uchar reserved[2];
uchar tapeName[24];
} Header; // 32 bytes
// The real host file system D64 image file:
QFile m_hostFile;
// T64 driver state variables:
ushort m_dirEntries;
ushort m_dirEntry;
// file status
uchar m_fileStartAddress[2]; // first two basic bytes
ushort m_fileOffset; // progress in file
ushort m_fileLength;
QString m_lastOpenedFileName;
qint32 hostSize() const
{
return static_cast<qint32>(m_hostFile.size());
}
uchar hostReadByte(uint length = 1);
bool hostSeek(qint32 pos, bool relative = false);
bool getDirEntry(DirEntry& dir);
ushort calcFileLength(DirEntry dir);
bool seekFirstDir(void);
void seekToTapeName(void);
};
#endif