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