2017-09-25 00:31:19 +00:00
|
|
|
//
|
|
|
|
// Parser.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 24/09/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-09-25 00:31:19 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Parser_hpp
|
|
|
|
#define Parser_hpp
|
|
|
|
|
2023-12-11 03:17:23 +00:00
|
|
|
#include "Constants.hpp"
|
2017-09-25 00:31:19 +00:00
|
|
|
#include "Sector.hpp"
|
2023-12-11 15:32:13 +00:00
|
|
|
#include "SegmentParser.hpp"
|
2017-09-30 00:08:36 +00:00
|
|
|
#include "../../Track/Track.hpp"
|
|
|
|
#include "../../Drive.hpp"
|
2017-09-25 00:31:19 +00:00
|
|
|
|
2023-12-11 15:32:13 +00:00
|
|
|
#include <optional>
|
|
|
|
|
2023-05-10 21:02:18 +00:00
|
|
|
namespace Storage::Encodings::MFM {
|
2017-09-25 00:31:19 +00:00
|
|
|
|
2017-09-30 00:08:36 +00:00
|
|
|
/*!
|
|
|
|
Provides a mechanism for collecting sectors from a disk.
|
|
|
|
*/
|
|
|
|
class Parser {
|
2017-09-25 00:31:19 +00:00
|
|
|
public:
|
2023-12-11 15:32:13 +00:00
|
|
|
/// Creates a parser that will only attempt to interpret the underlying disk as being of @c density.
|
2023-12-11 03:17:23 +00:00
|
|
|
Parser(Density density, const std::shared_ptr<Storage::Disk::Disk> &disk);
|
2017-09-25 00:31:19 +00:00
|
|
|
|
2023-12-11 15:32:13 +00:00
|
|
|
/// 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);
|
|
|
|
|
2017-09-25 00:31:19 +00:00
|
|
|
/*!
|
2017-09-30 00:08:36 +00:00
|
|
|
Seeks to the physical track at @c head and @c track. Searches on it for a sector
|
|
|
|
with logical address @c sector.
|
2017-09-25 00:31:19 +00:00
|
|
|
|
|
|
|
@returns a sector if one was found; @c nullptr otherwise.
|
|
|
|
*/
|
2023-12-11 14:58:24 +00:00
|
|
|
const Storage::Encodings::MFM::Sector *sector(int head, int track, uint8_t sector);
|
2017-09-25 00:31:19 +00:00
|
|
|
|
2023-12-11 15:32:13 +00:00
|
|
|
// TODO: set_sector.
|
|
|
|
|
2017-09-25 00:31:19 +00:00
|
|
|
private:
|
2017-09-30 00:08:36 +00:00
|
|
|
std::shared_ptr<Storage::Disk::Disk> disk_;
|
2023-12-11 15:32:13 +00:00
|
|
|
std::optional<Density> density_;
|
2017-09-25 00:31:19 +00:00
|
|
|
|
2023-12-11 14:58:24 +00:00
|
|
|
void install_track(const Storage::Disk::Track::Address &address);
|
2023-12-11 15:32:13 +00:00
|
|
|
static SectorMap parse_track(const Storage::Disk::Track &track, Density density);
|
|
|
|
static void append(const SectorMap &source, std::map<int, Sector> &destination);
|
2023-12-11 14:58:24 +00:00
|
|
|
|
|
|
|
// Maps from a track address, i.e. head and position, to a map from
|
|
|
|
// sector IDs to sectors.
|
|
|
|
std::map<
|
|
|
|
Storage::Disk::Track::Address,
|
|
|
|
std::map<int, Storage::Encodings::MFM::Sector>
|
|
|
|
> sectors_by_address_by_track_;
|
2017-09-25 00:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Parser_hpp */
|