16#include "DiskAnalyzerTypes.h"
18#include "SubComponent.h"
27class Disk final :
public CoreObject {
37 static const TrackDefaults trackDefaults[43];
40 static constexpr u8 gcr[16] = {
42 0x0a, 0x0b, 0x12, 0x13,
43 0x0e, 0x0f, 0x16, 0x17,
44 0x09, 0x19, 0x1a, 0x1b,
45 0x0d, 0x1d, 0x1e, 0x15
49 static constexpr u8 invgcr[32] = {
69 bool writeProtected =
false;
72 bool modified =
false;
85 DiskLength length = { };
95 static isize numberOfSectorsInTrack(Track t);
96 static isize numberOfSectorsInHalftrack(Halftrack ht);
99 static isize speedZoneOfTrack(Track t);
100 static isize speedZoneOfHalftrack(Halftrack ht);
103 static bool isValidTrackSectorPair(Track t, Sector s);
104 static bool isValidHalftrackSectorPair(Halftrack ht, Sector s);
114 Disk(
const fs::path &path,
bool wp =
false) throws { init(path, wp); }
115 Disk(DOSType type, PETName<16> name,
bool wp =
false) { init(type, name, wp); }
116 Disk(
const FileSystem &device,
bool wp =
false) { init(device, wp); }
117 Disk(
const class G64File &g64,
bool wp =
false) { init(g64, wp); }
118 Disk(
const class D64File &d64,
bool wp =
false) throws { init(d64, wp); }
119 Disk(
class AnyCollection &archive,
bool wp =
false) throws { init(archive, wp); }
120 Disk(SerReader &reader)
throws { init(reader); }
124 void init(
const fs::path &path,
bool wp)
throws;
125 void init(DOSType type, PETName<16> name,
bool wp);
126 void init(
const class FileSystem &device,
bool wp);
127 void init(
const class G64File &g64,
bool wp);
128 void init(
const class D64File &d64,
bool wp)
throws;
129 void init(
class AnyCollection &archive,
bool wp)
throws;
130 void init(SerReader &reader)
throws;
134 Disk& operator= (
const Disk& other) {
136 CLONE(writeProtected)
152 void serialize(T& worker)
154 if (isResetter(worker))
return;
171 const char *objectName()
const override {
return "Disk"; }
172 void _dump(Category category, std::ostream& os)
const override;
181 bool isWriteProtected()
const {
return writeProtected; }
182 void setWriteProtection(
bool b) { writeProtected = b; }
183 void toggleWriteProtection() { writeProtected = !writeProtected; }
185 bool isModified()
const {
return modified; }
186 void setModified(
bool b);
196 static u8 bin2gcr(u8 value) { assert(value < 16);
return gcr[value]; }
197 static u8 gcr2bin(u8 value) { assert(value < 32);
return invgcr[value]; }
200 static bool isGcr(u8 value) { assert(value < 32);
return invgcr[value] != 0xFF; }
206 void encodeGcr(u8 value, Track t, HeadPos offset);
207 void encodeGcr(u8 *values, isize length, Track t, HeadPos offset);
215 bool isValidHeadPos(Halftrack ht, HeadPos pos)
const;
218 HeadPos wrap(Halftrack ht, HeadPos pos)
const;
226 u64 _bitDelay(Halftrack ht, HeadPos pos)
const;
227 u64 bitDelay(Halftrack ht, HeadPos pos)
const {
return _bitDelay(ht, wrap(ht, pos)); }
233 u8 _readBitFromHalftrack(Halftrack ht, HeadPos pos)
const {
234 assert(isValidHeadPos(ht, pos));
235 return (data.halftrack[ht][pos >> 3] & (0x80 >> (pos & 7))) != 0;
237 u8 readBitFromHalftrack(Halftrack ht, HeadPos pos)
const {
238 return _readBitFromHalftrack(ht, wrap(ht, pos));
240 void _writeBitToHalftrack(Halftrack ht, HeadPos pos,
bool bit) {
241 assert(isValidHeadPos(ht, pos));
243 data.halftrack[ht][pos >> 3] |= (0x0080 >> (pos & 7));
245 data.halftrack[ht][pos >> 3] &= (0xFF7F >> (pos & 7));
248 void _writeBitToTrack(Track t, HeadPos pos,
bool bit) {
249 _writeBitToHalftrack(2 * t - 1, pos, bit);
251 void writeBitToHalftrack(Halftrack ht, HeadPos pos,
bool bit) {
252 _writeBitToHalftrack(ht, wrap(ht, pos), bit);
254 void writeBitToTrack(Track t, HeadPos pos,
bool bit) {
255 _writeBitToHalftrack(2 * t - 1, pos, bit);
259 void writeBitToHalftrack(Halftrack ht, HeadPos pos,
bool bit, isize count) {
260 for (isize i = 0; i < count; i++)
261 writeBitToHalftrack(ht, pos++, bit);
263 void writeBitToTrack(Track t, HeadPos pos,
bool bit, isize count) {
264 writeBitToHalftrack(2 * t - 1, pos, bit, count);
268 void writeByteToHalftrack(Halftrack ht, HeadPos pos, u8
byte) {
269 for (u8 mask = 0x80; mask != 0; mask >>= 1)
270 writeBitToHalftrack(ht, pos++,
byte & mask);
272 void writeByteToTrack(Track t, HeadPos pos, u8
byte) {
273 writeByteToHalftrack(2 * t - 1, pos,
byte);
277 void writeGapToHalftrack(Halftrack ht, HeadPos pos, isize length) {
278 for (isize i = 0; i < length; i++, pos += 8)
279 writeByteToHalftrack(ht, pos, 0x55);
281 void writeGapToTrack(Track t, HeadPos pos, isize length) {
282 writeGapToHalftrack(2 * t - 1, pos, length);
286 void clearHalftrack(Halftrack ht);
301 bool trackIsEmpty(Track t)
const;
302 bool halftrackIsEmpty(Halftrack ht)
const;
303 isize nonemptyHalftracks()
const;
306 isize lengthOfTrack(Track t)
const;
307 isize lengthOfHalftrack(Halftrack ht)
const;
321 isize decodeDisk(u8 *dest);
325 isize decodeDisk(u8 *dest, isize numTracks, DiskAnalyzer &analyzer);
326 isize decodeTrack(Track t, u8 *dest, DiskAnalyzer &analyzer);
327 isize decodeHalfrack(Halftrack ht, u8 *dest, DiskAnalyzer &analyzer);
328 isize decodeSector(Halftrack ht, isize offset, u8 *dest, DiskAnalyzer &analyzer);
338 void encodeG64(
const G64File &a);
344 void encode(
const FileSystem &fs,
bool alignTracks =
false);
356 isize encodeTrack(
const FileSystem &fs, Track t, isize gap, HeadPos start);
363 isize encodeSector(
const FileSystem &fs, Track t, Sector sector, HeadPos start, isize gap);
VirtualC64 project namespace.
Definition CmdQueue.cpp:16