-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc64disktrack.cpp
61 lines (59 loc) · 2.09 KB
/
c64disktrack.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
#include "c64disktrack.h"
#include "c64disk.h"
#include "c64exception.h"
#include <QDebug>
#define SECTOR_SIZE 256
C64DiskTrack::C64DiskTrack(C64Disk *parent, int id) {
this->Parent = parent;
this->ID = id;
this->Data = NULL;
}
C64DiskTrack::C64DiskTrack(C64Disk *parent, int id, char *data) {
this->Parent = parent;
this->ID = id;
this->Data = data;
C64DiskSector *sector;
int len = 0;
if (this->parent()->type() == C64Disk::DT_D64) {
if (this->id() <= 17) len = 21;
else if (this->id() <= 24) len = 19;
else if (this->id() <= 30) len = 18;
else if (this->id() <= 35) len = 17;
} else if (this->parent()->type() == C64Disk::DT_D71) {
if (this->id() <= 17) len = 21;
else if (this->id() <= 24) len = 19;
else if (this->id() <= 30) len = 18;
else if (this->id() <= 35) len = 17;
else if (this->id() <= 52) len = 21;
else if (this->id() <= 59) len = 19;
else if (this->id() <= 65) len = 18;
else if (this->id() <= 70) len = 17;
} else if (this->parent()->type() == C64Disk::DT_D81) len = 40;
for (int s = 0; s < len; s++) {
/*if (this->id() == 18) {
qDebug() << "Extracting Track 18 Sector " << s << " telling next coords track " << (int)data[0] << " sector " << (int)data[1] << data - this->Data;
}*/
sector = new C64DiskSector(this, s, data);
this->Sectors.append(sector);
this->parent()->appendSector(sector);
data = data + SECTOR_SIZE;
}
}
C64DiskTrack::~C64DiskTrack() {
while (!this->Sectors.isEmpty()) delete this->Sectors.takeFirst();
if (this->Data != NULL) delete []this->Data;
}
int C64DiskTrack::id() {
return this->ID;
}
C64Disk *C64DiskTrack::parent() {
return this->Parent;
}
C64DiskSector *C64DiskTrack::sector(int i) {
if (i < 0 || i > this->Sectors.count() - 1) throw new C64Exception("Track index out of limits.");
//qDebug() << "returning sector " << i << " from track " << this->id();
return this->Sectors.at(i);
}
int C64DiskTrack::sectorsCount() {
return this->Sectors.count();
}