mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-25 16:31:42 +00:00
Enhance to support 'try-any' density.
This commit is contained in:
parent
a40ae08248
commit
e79727d30d
@ -14,6 +14,9 @@
|
|||||||
|
|
||||||
using namespace Storage::Encodings::MFM;
|
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) :
|
Parser::Parser(Density density, const std::shared_ptr<Storage::Disk::Disk> &disk) :
|
||||||
disk_(disk), density_(density) {}
|
disk_(disk), density_(density) {}
|
||||||
|
|
||||||
@ -27,15 +30,30 @@ void Parser::install_track(const Storage::Disk::Track::Address &address) {
|
|||||||
return;
|
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;
|
std::map<int, Storage::Encodings::MFM::Sector> sectors_by_id;
|
||||||
for(const auto §or : sectors) {
|
if(density_) {
|
||||||
sectors_by_id.insert(std::make_pair(sector.second.address.sector, std::move(sector.second)));
|
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 §or : 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) {
|
const Sector *Parser::sector(int head, int track, uint8_t sector) {
|
||||||
|
@ -11,9 +11,12 @@
|
|||||||
|
|
||||||
#include "Constants.hpp"
|
#include "Constants.hpp"
|
||||||
#include "Sector.hpp"
|
#include "Sector.hpp"
|
||||||
|
#include "SegmentParser.hpp"
|
||||||
#include "../../Track/Track.hpp"
|
#include "../../Track/Track.hpp"
|
||||||
#include "../../Drive.hpp"
|
#include "../../Drive.hpp"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace Storage::Encodings::MFM {
|
namespace Storage::Encodings::MFM {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -21,8 +24,12 @@ namespace Storage::Encodings::MFM {
|
|||||||
*/
|
*/
|
||||||
class Parser {
|
class Parser {
|
||||||
public:
|
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);
|
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
|
Seeks to the physical track at @c head and @c track. Searches on it for a sector
|
||||||
with logical address @c 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);
|
const Storage::Encodings::MFM::Sector *sector(int head, int track, uint8_t sector);
|
||||||
|
|
||||||
|
// TODO: set_sector.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<Storage::Disk::Disk> disk_;
|
std::shared_ptr<Storage::Disk::Disk> disk_;
|
||||||
Density density_ = Density::Double;
|
std::optional<Density> density_;
|
||||||
|
|
||||||
void install_track(const Storage::Disk::Track::Address &address);
|
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
|
// Maps from a track address, i.e. head and position, to a map from
|
||||||
// sector IDs to sectors.
|
// sector IDs to sectors.
|
||||||
|
Loading…
Reference in New Issue
Block a user