1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00

Parameterised to perform FM and MFM encodings, at least subject to CRCs still being missing.

This commit is contained in:
Thomas Harte 2016-09-18 17:16:20 -04:00
parent 22eed60d2b
commit 55a7418cbf
2 changed files with 144 additions and 108 deletions

View File

@ -12,27 +12,120 @@
using namespace Storage::Encodings::MFM; using namespace Storage::Encodings::MFM;
std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSectors(const std::vector<Sector> &sectors) template <class T> class Shifter {
{ public:
class MFMVectorShifter: public MFMShifter<MFMVectorShifter> { virtual void add_byte(uint8_t input) = 0;
void output_short(uint16_t value) { virtual void add_index_address_mark() = 0;
data.push_back(value & 0xff); virtual void add_ID_address_mark() = 0;
data.push_back(value >> 8); virtual void add_data_address_mark() = 0;
virtual void add_deleted_data_address_mark() = 0;
protected:
// override me!
void output_short(uint16_t value);
};
template <class T> class MFMShifter: public Shifter<T> {
public:
void add_byte(uint8_t input) {
uint16_t spread_value =
(uint16_t)(
((input & 0x01) << 0) |
((input & 0x02) << 1) |
((input & 0x04) << 2) |
((input & 0x08) << 3) |
((input & 0x10) << 4) |
((input & 0x20) << 5) |
((input & 0x40) << 6) |
((input & 0x80) << 7)
);
uint16_t or_bits = (uint16_t)((spread_value << 1) | (spread_value >> 1) | (output_ << 15));
output_ = spread_value | ((~or_bits) & 0xaaaa);
static_cast<T *>(this)->output_short(output_);
} }
std::vector<uint8_t> data; void add_index_address_mark() {
} shifter; static_cast<T *>(this)->output_short(output_ = 0x5224);
add_byte(0xfc);
}
void add_ID_address_mark() {
static_cast<T *>(this)->output_short(output_ = 0x4489);
add_byte(0xfe);
}
void add_data_address_mark() {
static_cast<T *>(this)->output_short(output_ = 0x4489);
add_byte(0xfb);
}
void add_deleted_data_address_mark() {
static_cast<T *>(this)->output_short(output_ = 0x4489);
add_byte(0xf8);
}
private:
uint16_t output_;
};
template <class T> class FMShifter: public Shifter<T> {
public:
void add_byte(uint8_t input) {
static_cast<T *>(this)->output_short(
(uint16_t)(
((input & 0x01) << 1) |
((input & 0x02) << 2) |
((input & 0x04) << 3) |
((input & 0x08) << 4) |
((input & 0x10) << 5) |
((input & 0x20) << 6) |
((input & 0x40) << 7) |
((input & 0x80) << 8) |
0x5555
));
}
void add_index_address_mark() {
// data 0xfc, with clock 0xd7 => 1111 1100 with clock 1101 0111 => 1111 1011 1011 0101
static_cast<T *>(this)->output_short(0xfbb5);
}
void add_ID_address_mark() {
// data 0xfe, with clock 0xc7 => 1111 1110 with clock 1100 0111 => 1111 1010 1011 1101
static_cast<T *>(this)->output_short(0xfabd);
}
void add_data_address_mark() {
// data 0xfb, with clock 0xc7 => 1111 1011 with clock 1100 0111 => 1111 1010 1001 1111
static_cast<T *>(this)->output_short(0xfa9f);
}
void add_deleted_data_address_mark() {
// data 0xf8, with clock 0xc7 => 1111 1000 with clock 1100 0111 => 1111 1010 1001 0101
static_cast<T *>(this)->output_short(0xfa95);
}
};
template<class T> std::shared_ptr<Storage::Disk::Track>
GetTrackWithSectors(
const std::vector<Sector> &sectors,
size_t post_index_address_mark_bytes, uint8_t post_index_address_mark_value,
size_t pre_address_mark_bytes, size_t post_address_mark_bytes,
size_t pre_data_mark_bytes, size_t post_data_bytes,
size_t inter_sector_gap)
{
T shifter;
// output the index mark // output the index mark
shifter.add_index_address_mark(); shifter.add_index_address_mark();
// add the post-index mark // add the post-index mark
for(int c = 0; c < 50; c++) shifter.add_byte(0x4e); for(int c = 0; c < post_index_address_mark_bytes; c++) shifter.add_byte(post_index_address_mark_value);
// add sectors // add sectors
for(const Sector &sector : sectors) for(const Sector &sector : sectors)
{ {
for(int c = 0; c < 12; c++) shifter.add_byte(0x00); for(int c = 0; c < pre_address_mark_bytes; c++) shifter.add_byte(0x00);
shifter.add_ID_address_mark(); shifter.add_ID_address_mark();
shifter.add_byte(sector.track); shifter.add_byte(sector.track);
@ -49,15 +142,15 @@ std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSe
} }
// TODO: CRC of bytes since the track number // TODO: CRC of bytes since the track number
for(int c = 0; c < 22; c++) shifter.add_byte(0x4e); for(int c = 0; c < post_address_mark_bytes; c++) shifter.add_byte(0x4e);
for(int c = 0; c < 12; c++) shifter.add_byte(0x00); for(int c = 0; c < pre_data_mark_bytes; c++) shifter.add_byte(0x00);
shifter.add_data_address_mark(); shifter.add_data_address_mark();
for(size_t c = 0; c < sector.data.size(); c++) shifter.add_byte(sector.data[c]); for(size_t c = 0; c < sector.data.size(); c++) shifter.add_byte(sector.data[c]);
// TODO: CRC of data // TODO: CRC of data
for(int c = 0; c < 18; c++) shifter.add_byte(0x00); for(int c = 0; c < post_data_bytes; c++) shifter.add_byte(0x00);
for(int c = 0; c < 32; c++) shifter.add_byte(0x4e); for(int c = 0; c < inter_sector_gap; c++) shifter.add_byte(0x4e);
} }
// TODO: total size check // TODO: total size check
@ -65,3 +158,40 @@ std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSe
Storage::Disk::PCMSegment segment; Storage::Disk::PCMSegment segment;
return std::shared_ptr<Storage::Disk::Track>(new Storage::Disk::PCMTrack(std::move(segment))); return std::shared_ptr<Storage::Disk::Track>(new Storage::Disk::PCMTrack(std::move(segment)));
} }
std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetFMTrackWithSectors(const std::vector<Sector> &sectors)
{
struct VectorShifter: public FMShifter<VectorShifter> {
void output_short(uint16_t value) {
data.push_back(value & 0xff);
data.push_back(value >> 8);
}
std::vector<uint8_t> data;
};
return GetTrackWithSectors<VectorShifter>(
sectors,
16, 0x00,
6, 0,
17, 14,
0);
}
std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSectors(const std::vector<Sector> &sectors)
{
struct VectorShifter: public MFMShifter<VectorShifter> {
void output_short(uint16_t value) {
data.push_back(value & 0xff);
data.push_back(value >> 8);
}
std::vector<uint8_t> data;
};
return GetTrackWithSectors<VectorShifter>(
sectors,
50, 0x4e,
12, 22,
12, 18,
32);
}

View File

@ -17,100 +17,6 @@ namespace Storage {
namespace Encodings { namespace Encodings {
namespace MFM { namespace MFM {
template <class T> class Shifter {
public:
virtual void add_byte(uint8_t input) = 0;
virtual void add_index_address_mark() = 0;
virtual void add_ID_address_mark() = 0;
virtual void add_data_address_mark() = 0;
virtual void add_deleted_data_address_mark() = 0;
protected:
// override me!
void output_short(uint16_t value);
};
template <class T> class MFMShifter: public Shifter<T> {
public:
void add_byte(uint8_t input) {
uint16_t spread_value =
(uint16_t)(
((input & 0x01) << 0) |
((input & 0x02) << 1) |
((input & 0x04) << 2) |
((input & 0x08) << 3) |
((input & 0x10) << 4) |
((input & 0x20) << 5) |
((input & 0x40) << 6) |
((input & 0x80) << 7)
);
uint16_t or_bits = (uint16_t)((spread_value << 1) | (spread_value >> 1) | (output_ << 15));
output_ = spread_value | ((~or_bits) & 0xaaaa);
static_cast<T *>(this)->output_short(output_);
}
void add_index_address_mark() {
static_cast<T *>(this)->output_short(output_ = 0x5224);
add_byte(0xfc);
}
void add_ID_address_mark() {
static_cast<T *>(this)->output_short(output_ = 0x4489);
add_byte(0xfe);
}
void add_data_address_mark() {
static_cast<T *>(this)->output_short(output_ = 0x4489);
add_byte(0xfb);
}
void add_deleted_data_address_mark() {
static_cast<T *>(this)->output_short(output_ = 0x4489);
add_byte(0xf8);
}
private:
uint16_t output_;
};
template <class T> class FMShifter: public Shifter<T> {
public:
void add_byte(uint8_t input) {
static_cast<T *>(this)->output_short(
(uint16_t)(
((input & 0x01) << 1) |
((input & 0x02) << 2) |
((input & 0x04) << 3) |
((input & 0x08) << 4) |
((input & 0x10) << 5) |
((input & 0x20) << 6) |
((input & 0x40) << 7) |
((input & 0x80) << 8) |
0x5555
));
}
void add_index_address_mark() {
// data 0xfc, with clock 0xd7 => 1111 1100 with clock 1101 0111 => 1111 1011 1011 0101
static_cast<T *>(this)->output_short(0xfbb5);
}
void add_ID_address_mark() {
// data 0xfe, with clock 0xc7 => 1111 1110 with clock 1100 0111 => 1111 1010 1011 1101
static_cast<T *>(this)->output_short(0xfabd);
}
void add_data_address_mark() {
// data 0xfb, with clock 0xc7 => 1111 1011 with clock 1100 0111 => 1111 1010 1001 1111
static_cast<T *>(this)->output_short(0xfa9f);
}
void add_deleted_data_address_mark() {
// data 0xf8, with clock 0xc7 => 1111 1000 with clock 1100 0111 => 1111 1010 1001 0101
static_cast<T *>(this)->output_short(0xfa95);
}
};
struct Sector { struct Sector {
uint8_t track, side, sector; uint8_t track, side, sector;
std::vector<uint8_t> data; std::vector<uint8_t> data;