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

Enhance to support 'try-any' density.

This commit is contained in:
Thomas Harte 2023-12-11 10:32:13 -05:00
parent a40ae08248
commit e79727d30d
2 changed files with 37 additions and 8 deletions

View File

@ -14,6 +14,9 @@
using namespace Storage::Encodings::MFM;
Parser::Parser(const std::shared_ptr<Storage::Disk::Disk> &disk) :
disk_(disk) {}
Parser::Parser(Density density, const std::shared_ptr<Storage::Disk::Disk> &disk) :
disk_(disk), density_(density) {}
@ -27,15 +30,30 @@ void Parser::install_track(const Storage::Disk::Track::Address &address) {
return;
}
std::map<std::size_t, Sector> sectors = sectors_from_segment(
Storage::Disk::track_serialisation(*track, bit_length(density_)),
density_);
std::map<int, Storage::Encodings::MFM::Sector> sectors_by_id;
for(const auto &sector : sectors) {
sectors_by_id.insert(std::make_pair(sector.second.address.sector, std::move(sector.second)));
if(density_) {
append(parse_track(*track, *density_), sectors_by_id);
return;
} else {
// Just try all three in succession.
append(parse_track(*track, Density::Single), sectors_by_id);
append(parse_track(*track, Density::Double), sectors_by_id);
append(parse_track(*track, Density::High), sectors_by_id);;
}
sectors_by_address_by_track_.emplace(address, std::move(sectors_by_id));
}
SectorMap Parser::parse_track(const Storage::Disk::Track &track, Density density) {
return sectors_from_segment(
Storage::Disk::track_serialisation(track, bit_length(density)),
density);
}
void Parser::append(const SectorMap &source, std::map<int, Sector> &destination) {
for(const auto &sector : source) {
destination.emplace(sector.second.address.sector, std::move(sector.second));
}
sectors_by_address_by_track_.insert(std::make_pair(address, std::move(sectors_by_id)));
}
const Sector *Parser::sector(int head, int track, uint8_t sector) {

View File

@ -11,9 +11,12 @@
#include "Constants.hpp"
#include "Sector.hpp"
#include "SegmentParser.hpp"
#include "../../Track/Track.hpp"
#include "../../Drive.hpp"
#include <optional>
namespace Storage::Encodings::MFM {
/*!
@ -21,8 +24,12 @@ namespace Storage::Encodings::MFM {
*/
class Parser {
public:
/// Creates a parser that will only attempt to interpret the underlying disk as being of @c density.
Parser(Density density, const std::shared_ptr<Storage::Disk::Disk> &disk);
/// Creates a parser that will automatically try all available FM and MFM densities to try to extract sectors.
Parser(const std::shared_ptr<Storage::Disk::Disk> &disk);
/*!
Seeks to the physical track at @c head and @c track. Searches on it for a sector
with logical address @c sector.
@ -31,11 +38,15 @@ class Parser {
*/
const Storage::Encodings::MFM::Sector *sector(int head, int track, uint8_t sector);
// TODO: set_sector.
private:
std::shared_ptr<Storage::Disk::Disk> disk_;
Density density_ = Density::Double;
std::optional<Density> density_;
void install_track(const Storage::Disk::Track::Address &address);
static SectorMap parse_track(const Storage::Disk::Track &track, Density density);
static void append(const SectorMap &source, std::map<int, Sector> &destination);
// Maps from a track address, i.e. head and position, to a map from
// sector IDs to sectors.