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-09-30 00:08:36 +00:00
|
|
|
is_mfm_(is_mfm), disk_(disk) {}
|
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-09-30 00:08:36 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Track> track = disk_->get_track_at_position((unsigned int)address.head, (unsigned int)address.position);
|
|
|
|
if(!track) {
|
|
|
|
return;
|
2017-09-25 00:31:19 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
std::map<size_t, Sector> sectors = sectors_from_segment(
|
|
|
|
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;
|
|
|
|
for(auto §or : sectors) {
|
|
|
|
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) {
|
|
|
|
Disk::Track::Address address;
|
|
|
|
address.position = track;
|
|
|
|
address.head = head;
|
|
|
|
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
|
|
|
}
|