VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
DiskAnalyzer.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 "DiskAnalyzerTypes.h"
16#include "DiskTypes.h"
17#include "CoreObject.h"
18#include "IOUtils.h"
19
20namespace vc64 {
21
22class DiskAnalyzer final : public CoreObject {
23
24 // Lengths of all halftracks
25 isize length[85];
26
27 // Data of all halftracks (repeated twice, one byte for each bit on disk)
28 u8 *data[85];
29
30 // Result of the analysis
31 DiskInfo diskInfo = { };
32
33 // Error log (one for each halftrack)
34 string logbook[85];
35
36 // Error log created by analyzeTrack
37 std::vector<string> errorLog[85];
38
39 // Stores the start offset of the erroneous bit sequence
40 std::vector<isize> errorStartIndex[85];
41
42 // Stores the end offset of the erroneous bit sequence
43 std::vector<isize> errorEndIndex[85];
44
45 // Textual representation of track data
46 char text[maxBitsOnTrack + 1] = { };
47
48
49 //
50 // Methods
51 //
52
53public:
54
55 DiskAnalyzer(const class Disk &disk);
56 ~DiskAnalyzer();
57
58
59 //
60 // Methods from CoreObject
61 //
62
63private:
64
65 const char *objectName() const override { return "DiskAnalyzer"; }
66
67
68 //
69 // Analyzing the disk
70 //
71
72public:
73
74 // Returns the length of a halftrack in bits
75 isize lengthOfTrack(Track t) const;
76 isize lengthOfHalftrack(Halftrack ht) const;
77
78 // Decodes a GCR-encoded nibble or byte
79 u8 decodeGcrNibble(Halftrack ht, isize offset);
80 u8 decodeGcr(Halftrack ht, isize offset);
81
82private:
83
84 // Analyzes the whole disk
85 void analyzeDisk();
86
87 // Analyzes a certain track or halftrack
88 TrackInfo analyzeTrack(Track t);
89 TrackInfo analyzeHalftrack(Halftrack ht);
90
91 // Analyzes all sectors of a certain track
92 void analyzeSectorBlocks(Halftrack ht, TrackInfo &trackInfo);
93
94 // Analyzes a single sector header block or sector data block
95 void analyzeSectorHeaderBlock(Halftrack ht, isize offset, TrackInfo &trackInfo);
96 void analyzeSectorDataBlock(Halftrack ht, isize offset, TrackInfo &trackInfo);
97
98 // Writes an error message into the error log
99 void log(Halftrack ht, isize begin, isize length, const char *fmt, ...);
100
101public:
102
103 // Returns the layout of a certain track
104 const SectorInfo &sectorLayout(Halftrack ht, Sector nr);
105
106 // Returns the logbook for a certain track
107 const string &getLogbook(Halftrack ht) { return logbook[ht]; }
108
109 // Returns the number of entries in the error log
110 isize numErrors(Halftrack ht) { return isize(errorLog[ht].size()); }
111
112 // Reads an error message from the error log
113 string errorMessage(Halftrack ht, isize nr) const { return errorLog[ht].at(nr); }
114
115 // Reads the error begin index from the error log
116 isize firstErroneousBit(Halftrack ht, isize nr) const { return errorStartIndex[ht].at(nr); }
117
118 // Reads the error end index from the error log
119 isize lastErroneousBit(Halftrack ht, isize nr) const { return errorEndIndex[ht].at(nr); }
120
121 // Returns a textual representation of the disk name
122 const char *diskNameAsString();
123
124 // Returns a textual representation of the data stored in trackInfo
125 const char *trackBitsAsString(Halftrack ht);
126
127 // Returns a textual representation of the data stored in trackInfo
128 const char *sectorHeaderBytesAsString(Halftrack ht, Sector nr, bool hex);
129
130 // Returns a textual representation of the data stored in trackInfo
131 const char *sectorDataBytesAsString(Halftrack ht, Sector nr, bool hex);
132
133private:
134
135 // Returns a textual representation
136 const char *sectorBytesAsString(Halftrack ht, isize offset, isize length, bool hex);
137};
138
139}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16