-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc64diskbam.cpp
108 lines (102 loc) · 4.09 KB
/
c64diskbam.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
103
104
105
106
107
108
#include "c64diskbam.h"
#include <string.h>
#include "c64disk.h"
#include "c64disktrack.h"
C64DiskBAM::C64DiskBAM(C64DiskSector *parent, char *data) : C64DiskBlock{parent, data} {
}
int C64DiskBAM::nextTrack() {
if (this->Disk->type() == C64Disk::DT_D71 && this->Sector->id() == 0 && this->Track->id() == 18) return 53;
else if (this->Disk->type() == C64Disk::DT_D81 && this->Sector->id() == 1 && this->Track->id() == 40) return 40;
return 0;
}
int C64DiskBAM::nextSector() {
if (this->Disk->type() == C64Disk::DT_D71 && this->Sector->id() == 0 && this->Track->id() == 18) return 0;
else if (this->Disk->type() == C64Disk::DT_D81 && this->Sector->id() == 1 && this->Track->id() == 40) return 2;
return 255;
}
int C64DiskBAM::freeSectors() {
int total = 0;
int track = 1;
if (this->Disk->type() == C64Disk::DT_D64 && this->Track->id() == 18 && this->Sector->id() == 0) {
for (int i = 0x04; i <= 0x8C; i = i + 0x04) {
if (!this->Disk->isReservedTrack(track)) total = total + (unsigned char)this->Data[i];
track++;
}
} else if (this->Disk->type() == C64Disk::DT_D71 && this->Track->id() == 18 && this->Sector->id() == 0) {
// For tracks 1 to 35
for (int i = 0x04; i <= 0x8C; i = i + 0x04) {
if (!this->Disk->isReservedTrack(track)) total = total + (unsigned char)this->Data[i];
track++;
}
// For tracks 36 to 70
for (int i = 0xDD; i <= 0xFF; i++) {
if (!this->Disk->isReservedTrack(track)) total = total + (unsigned char)this->Data[i];
track++;
}
} else if (this->Disk->type() == C64Disk::DT_D81) {
if (this->Sector->id() == 2) track = 41;
for (int i = 0x10; i <= 0xFA; i = i + 0x06) {
if (!this->Disk->isReservedTrack(track)) total = total + (unsigned char)this->Data[i];
track++;
}
}
return total;
}
void C64DiskBAM::populateFreeSectorsMap(QMap <int, QMap<int, bool>> &map) {
const unsigned char MASK[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
int track = 1;
if (this->Disk->type() == C64Disk::DT_D64 || this->Disk->type() == C64Disk::DT_D71) {
int begin = 0x04;
int end = 0x8C;
int inc = 0x04;
int bias = 1;
if (this->Disk->type() == C64Disk::DT_D71 && this->Track->id() == 53 && this->Sector->id() == 0) {
track = 36;
begin = 0x00;
end = 0x66;
inc = 0x03;
bias = 0;
}
for (int i = begin; i <= end; i = i + inc) {
unsigned char *p = (unsigned char *)(this->Data + i + bias);
QMap<int, bool> sectors;
int sector = 0;
for (int j = 0; j < 3; j++) {
unsigned char *q = p + j;
int len = 8;
if (j == 2) {
if (track <= 17) len = 5;
else if (track <= 24) len = 3;
else if (track <= 30) len = 2;
else if (track <= 35) len = 1;
else if (track <= 52) len = 5;
else if (track <= 59) len = 3;
else if (track <= 65) len = 2;
else if (track <= 70) len = 1;
}
for (int k = 0; k < len; k++) {
sectors.insert(sector, *q & MASK[k] ? true : false);
sector++;
}
}
map.insert(track, sectors);
track++;
}
} else if (this->Disk->type() == C64Disk::DT_D81) {
if (this->Sector->id() == 2) track = 41;
for (int i = 0x10; i <= 0xFA; i = i + 0x06) {
unsigned char *p = (unsigned char *)(this->Data + i + 1);
QMap<int, bool> sectors;
int sector = 0;
for (int j = 0; j < 5; j++) {
unsigned char *q = p + j;
for (int k = 0; k < 8; k++) {
sectors.insert(sector, *q & MASK[k] ? true : false);
sector++;
}
}
map.insert(track, sectors);
track++;
}
}
}