2017-09-25 00:31:19 +00:00
|
|
|
//
|
|
|
|
// Parser.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 24/09/2017.
|
|
|
|
// Copyright © 2017 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Parser.hpp"
|
|
|
|
|
|
|
|
#include "Constants.hpp"
|
2017-09-30 00:08:36 +00:00
|
|
|
#include "../../Track/TrackSerialiser.hpp"
|
|
|
|
#include "SegmentParser.hpp"
|
2017-09-25 00:31:19 +00:00
|
|
|
|
|
|
|
using namespace Storage::Encodings::MFM;
|
|
|
|
|
|
|
|
Parser::Parser(bool is_mfm, const std::shared_ptr<Storage::Disk::Disk> &disk) :
|
2017-11-11 03:57:03 +00:00
|
|
|
disk_(disk), is_mfm_(is_mfm) {}
|
2017-09-25 00:31:19 +00:00
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
void Parser::install_sectors_from_track(const Storage::Disk::Track::Address &address) {
|
|
|
|
if(sectors_by_address_by_track_.find(address) != sectors_by_address_by_track_.end()) {
|
|
|
|
return;
|
2017-09-25 00:31:19 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 01:45:12 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Track> track = disk_->get_track_at_position(address);
|
2017-09-30 00:08:36 +00:00
|
|
|
if(!track) {
|
|
|
|
return;
|
2017-09-25 00:31:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-11 20:28:40 +00:00
|
|
|
std::map<std::size_t, Sector> sectors = sectors_from_segment(
|
2017-09-30 00:08:36 +00:00
|
|
|
Storage::Disk::track_serialisation(*track, is_mfm_ ? MFMBitLength : FMBitLength),
|
|
|
|
is_mfm_);
|
2017-09-25 00:31:19 +00:00
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
std::map<int, Storage::Encodings::MFM::Sector> sectors_by_id;
|
2018-05-01 02:23:57 +00:00
|
|
|
for(const auto §or : sectors) {
|
2017-09-30 00:08:36 +00:00
|
|
|
sectors_by_id.insert(std::make_pair(sector.second.address.sector, std::move(sector.second)));
|
2017-09-25 00:31:19 +00:00
|
|
|
}
|
2017-09-30 00:08:36 +00:00
|
|
|
sectors_by_address_by_track_.insert(std::make_pair(address, std::move(sectors_by_id)));
|
2017-09-25 00:31:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
Sector *Parser::get_sector(int head, int track, uint8_t sector) {
|
2018-05-07 03:17:36 +00:00
|
|
|
Disk::Track::Address address(head, Storage::Disk::HeadPosition(track));
|
2017-09-30 00:08:36 +00:00
|
|
|
install_sectors_from_track(address);
|
2017-09-25 00:31:19 +00:00
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
auto sectors = sectors_by_address_by_track_.find(address);
|
|
|
|
if(sectors == sectors_by_address_by_track_.end()) {
|
|
|
|
return nullptr;
|
2017-09-25 00:31:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
auto stored_sector = sectors->second.find(sector);
|
|
|
|
if(stored_sector == sectors->second.end()) {
|
|
|
|
return nullptr;
|
2017-09-25 00:31:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
return &stored_sector->second;
|
2017-09-25 00:31:19 +00:00
|
|
|
}
|