-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc64diskheader.cpp
102 lines (89 loc) · 3.07 KB
/
c64diskheader.cpp
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
#include "c64diskheader.h"
#include "c64disk.h"
#include <string.h>
C64DiskHeader::C64DiskHeader(C64DiskSector *parent, char *data) : C64DiskBlock{parent, data} {
}
int C64DiskHeader::nextTrack() {
if (this->Disk->type() == C64Disk::DT_D64 ||
this->Disk->type() == C64Disk::DT_D71) return 18;
else if (this->Disk->type() == C64Disk::DT_D81) return 40;
return 0;
}
int C64DiskHeader::nextSector() {
if (this->Disk->type() == C64Disk::DT_D64 ||
this->Disk->type() == C64Disk::DT_D71) return 1;
else if (this->Disk->type() == C64Disk::DT_D81) return 3;
return 255;
}
QString C64DiskHeader::dosVersion() {
return QString(QChar((unsigned char)this->Data[2]));
}
bool C64DiskHeader::isSoftWriteProteced() {
if ((this->Disk->type() == C64Disk::DT_D64 ||
this->Disk->type() == C64Disk::DT_D71) &&
(this->Data[2] != 0x0 && this->Data[2] != 0x41))
return true;
else if ((this->Disk->type() == C64Disk::DT_D81) &&
(this->Data[2] != 0x0 && this->Data[2] != 0x44))
return true;
return false;
}
QString C64DiskHeader::diskName() {
char str[17];
str[16] = 0;
if (this->Disk->type() == C64Disk::DT_D64 ||
this->Disk->type() == C64Disk::DT_D71)
strncpy(str, this->Data + 0x90, 16);
else if (this->Disk->type() == C64Disk::DT_D81)
strncpy(str, this->Data + 0x04, 16);
else str[0] = 0;
C64DiskHeader::removeA0Padding(str);
return QString(str);
}
QString C64DiskHeader::diskID() {
char str[3];
str[2] = 0;
if (this->Disk->type() == C64Disk::DT_D64 ||
this->Disk->type() == C64Disk::DT_D71)
strncpy(str, this->Data + 0xA2, 2);
else if (this->Disk->type() == C64Disk::DT_D81)
strncpy(str, this->Data + 0x16, 2);
else str[0] = 0;
C64DiskHeader::removeA0Padding(str);
return QString(str);
}
QString C64DiskHeader::dosType() {
char str[3];
str[2] = 0;
if (this->Disk->type() == C64Disk::DT_D64 ||
this->Disk->type() == C64Disk::DT_D71)
strncpy(str, this->Data + 0xA5, 2);
else if (this->Disk->type() == C64Disk::DT_D81)
strncpy(str, this->Data + 0x19, 2);
else str[0] = 0;
C64DiskHeader::removeA0Padding(str);
return QString(str);
}
QString C64DiskHeader::geosIDString() {
// 0xAD - 0xBC
char str[17];
memset(str, '\0', 17);
strncpy(str, this->Data + 0xAD, 16);
return QString(str);
}
bool C64DiskHeader::isGeosDisk() {
if (this->geosIDString().startsWith("GEOS format")) return true;
return false;
}
bool C64DiskHeader::isDoubleSide() {
if (this->Disk->type() == C64Disk::DT_D71 && (unsigned char)this->Data[03] == 0x80) return true;
else if (this->Disk->type() == C64Disk::DT_D81) return true;
return false;
}
QByteArray C64DiskHeader::data() {
QByteArray data;
if (this->Disk->type() == C64Disk::DT_D64 || this->Disk->type() == C64Disk::DT_D71) {
for (int i = 0; i < 212; i++) data.append(this->Data[i]);
} else if (this->Disk->type() == C64Disk::DT_D81) return C64DiskBlock::data();
return data;
}