| e8555c89 Andy McCall |
1 |
#ifndef RAWTRACK_HH |
| 2 |
#define RAWTRACK_HH |
| 3 |
|
| 4 |
#include "narrow.hh" |
| 5 |
#include "serialize_meta.hh" |
| 6 |
#include <cstdint> |
| 7 |
#include <optional> |
| 8 |
#include <span> |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
namespace openmsx { |
| 12 |
|
| 13 |
class CRC16; |
| 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 |
class RawTrack { |
| 66 |
public: |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
static constexpr unsigned STANDARD_SIZE = 6250; |
| 75 |
|
| 76 |
struct Sector |
| 77 |
{ |
| 78 |
|
| 79 |
int addrIdx = 0; |
| 80 |
int dataIdx = 0; |
| 81 |
uint8_t track = 0; |
| 82 |
uint8_t head = 0; |
| 83 |
uint8_t sector = 0; |
| 84 |
uint8_t sizeCode = 0; |
| 85 |
bool deleted = false; |
| 86 |
bool addrCrcErr = false; |
| 87 |
bool dataCrcErr = false; |
| 88 |
|
| 89 |
template<typename Archive> |
| 90 |
void serialize(Archive& ar, unsigned version); |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
explicit RawTrack(unsigned size = STANDARD_SIZE); |
| 95 |
|
| 96 |
|
| 97 |
void clear(unsigned size); |
| 98 |
|
| 99 |
|
| 100 |
[[nodiscard]] unsigned getLength() const { return unsigned(data.size()); } |
| 101 |
|
| 102 |
void addIdam(unsigned idx); |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
[[nodiscard]] uint8_t read(int idx) const { return data[wrapIndex(idx)]; } |
| 108 |
void write(int idx, uint8_t val, bool setIdam = false); |
| 109 |
[[nodiscard]] int wrapIndex(int idx) const { |
| 110 |
|
| 111 |
|
| 112 |
int size = narrow<int>(data.size()); |
| 113 |
int tmp = idx % size; |
| 114 |
return (tmp >= 0) ? tmp : (tmp + size); |
| 115 |
} |
| 116 |
|
| 117 |
[[nodiscard]] std::span< uint8_t> getRawBuffer() { return data; } |
| 118 |
[[nodiscard]] std::span<const uint8_t> getRawBuffer() const { return data; } |
| 119 |
[[nodiscard]] const auto& getIdamBuffer() const { return idam; } |
| 120 |
|
| 121 |
|
| 122 |
[[nodiscard]] std::vector<Sector> decodeAll() const; |
| 123 |
|
| 124 |
|
| 125 |
[[nodiscard]] std::optional<Sector> decodeNextSector(unsigned startIdx) const; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
[[nodiscard]] std::optional<Sector> decodeSector(uint8_t sectorNum) const; |
| 133 |
|
| 134 |
|
| 135 |
void readBlock (int idx, std::span<uint8_t> destination) const; |
| 136 |
void writeBlock(int idx, std::span<const uint8_t> source); |
| 137 |
|
| 138 |
|
| 139 |
[[nodiscard]] uint16_t calcCrc(int idx, int size) const; |
| 140 |
void updateCrc(CRC16& crc, int idx, int size) const; |
| 141 |
|
| 142 |
void applyWd2793ReadTrackQuirk(); |
| 143 |
|
| 144 |
template<typename Archive> |
| 145 |
void serialize(Archive& ar, unsigned version); |
| 146 |
|
| 147 |
private: |
| 148 |
[[nodiscard]] std::optional<Sector> decodeSectorImpl(int idx) const; |
| 149 |
|
| 150 |
private: |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
std::vector<unsigned> idam; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
std::vector<uint8_t> data; |
| 160 |
}; |
| 161 |
SERIALIZE_CLASS_VERSION(RawTrack, 2); |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
#endif |