1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-25 18:30:07 +00:00

Started sketching out basic MFM track encoding. Which possibly even means that the shifters don't need to be public?

This commit is contained in:
Thomas Harte 2016-09-18 16:53:21 -04:00
parent 0089c830c6
commit 22eed60d2b
2 changed files with 69 additions and 1 deletions

View File

@ -8,4 +8,60 @@
#include "MFM.hpp"
using namespace Storage::Encodings;
#import "../PCMTrack.hpp"
using namespace Storage::Encodings::MFM;
std::shared_ptr<Storage::Disk::Track> Storage::Encodings::MFM::GetMFMTrackWithSectors(const std::vector<Sector> &sectors)
{
class MFMVectorShifter: public MFMShifter<MFMVectorShifter> {
void output_short(uint16_t value) {
data.push_back(value & 0xff);
data.push_back(value >> 8);
}
std::vector<uint8_t> data;
} shifter;
// output the index mark
shifter.add_index_address_mark();
// add the post-index mark
for(int c = 0; c < 50; c++) shifter.add_byte(0x4e);
// add sectors
for(const Sector &sector : sectors)
{
for(int c = 0; c < 12; c++) shifter.add_byte(0x00);
shifter.add_ID_address_mark();
shifter.add_byte(sector.track);
shifter.add_byte(sector.side);
shifter.add_byte(sector.sector);
switch(sector.data.size())
{
default: shifter.add_byte(0); break;
case 256: shifter.add_byte(1); break;
case 512: shifter.add_byte(2); break;
case 1024: shifter.add_byte(3); break;
case 2048: shifter.add_byte(4); break;
case 4196: shifter.add_byte(5); break;
}
// TODO: CRC of bytes since the track number
for(int c = 0; c < 22; c++) shifter.add_byte(0x4e);
for(int c = 0; c < 12; c++) shifter.add_byte(0x00);
shifter.add_data_address_mark();
for(size_t c = 0; c < sector.data.size(); c++) shifter.add_byte(sector.data[c]);
// TODO: CRC of data
for(int c = 0; c < 18; c++) shifter.add_byte(0x00);
for(int c = 0; c < 32; c++) shifter.add_byte(0x4e);
}
// TODO: total size check
Storage::Disk::PCMSegment segment;
return std::shared_ptr<Storage::Disk::Track>(new Storage::Disk::PCMTrack(std::move(segment)));
}

View File

@ -10,9 +10,12 @@
#define Storage_Disk_Encodings_MFM_hpp
#include <cstdint>
#include <vector>
#import "../Disk.hpp"
namespace Storage {
namespace Encodings {
namespace MFM {
template <class T> class Shifter {
public:
@ -108,6 +111,15 @@ template <class T> class FMShifter: public Shifter<T> {
}
};
struct Sector {
uint8_t track, side, sector;
std::vector<uint8_t> data;
};
std::shared_ptr<Storage::Disk::Track> GetMFMTrackWithSectors(const std::vector<Sector> &sectors);
std::shared_ptr<Storage::Disk::Track> GetFMTrackWithSectors(const std::vector<Sector> &sectors);
}
}
}