VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
D64File.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "AnyFile.h"
16#include "DriveTypes.h"
17
18namespace vc64 {
19
20class D64File : public AnyFile {
21
22public:
23
24 // D64 files come in six different sizes
25 static const isize D64_683_SECTORS = 174848;
26 static const isize D64_683_SECTORS_ECC = 175531;
27 static const isize D64_768_SECTORS = 196608;
28 static const isize D64_768_SECTORS_ECC = 197376;
29 static const isize D64_802_SECTORS = 205312;
30 static const isize D64_802_SECTORS_ECC = 206114;
31
32 // Error information stored in the D64 archive
33 u8 errors[802];
34
35 static bool isCompatible(const fs::path &name);
36 static bool isCompatible(std::istream &stream);
37
38
39 //
40 // Initializing
41 //
42
43 D64File();
44 D64File(isize tracks, bool ecc);
45 D64File(const fs::path &path) throws : D64File() { init(path); }
46 D64File(const u8 *buf, isize len) throws : D64File() { init(buf, len); }
47 D64File(class FileSystem &fs) throws : D64File() { init(fs); }
48
49private:
50
51 using AnyFile::init;
52 void init(isize tracks, bool ecc);
53 void init(FileSystem &fs) throws;
54
55
56 //
57 // Methods from CoreObject
58 //
59
60public:
61
62 const char *objectName() const override { return "D64File"; }
63
64
65 //
66 // Methods from AnyFile
67 //
68
69 bool isCompatiblePath(const fs::path &path) override { return isCompatible(path); }
70 bool isCompatibleStream(std::istream &stream) override { return isCompatible(stream); }
71 FileType type() const override { return FILETYPE_D64; }
72 PETName<16> getName() const override;
73 void finalizeRead() throws override;
74
75
76 //
77 // Querying properties
78 //
79
80public:
81
82 // Returns the number of halftracks or tracks stored in this file
83 Track numHalftracks() const;
84 Track numTracks() const { return numHalftracks() / 2; }
85
86 // Returns the error code for the specified sector (01 = no error)
87 u8 getErrorCode(Block b) const;
88
89private:
90
91 // Translates a track and sector number into an offset (-1 if invalid)
92 isize offset(Track track, Sector sector) const;
93
94
95 //
96 // Debugging
97 //
98
99public:
100
101 // Dumps the contents of a sector
102 void dump(Track track, Sector sector) const;
103};
104
105}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16