// // CAS.hpp // Clock Signal // // Created by Thomas Harte on 25/11/2017. // Copyright 2017 Thomas Harte. All rights reserved. // #pragma once #include "../Tape.hpp" #include "../../FileHolder.hpp" #include #include #include namespace Storage::Tape { /*! Provides a @c Tape containing a CAS tape image, which is an MSX byte stream. */ class CAS: public Tape { public: /*! Constructs a @c CAS containing content from the file with name @c file_name. @throws ErrorNotCAS if this file could not be opened and recognised as a valid CAS file. */ CAS(const std::string &file_name); enum { ErrorNotCAS }; private: struct Serialiser: public TapeSerialiser { Serialiser(const std::string &file_name); private: bool is_at_end() const override; void reset() override; Pulse next_pulse() override; // Storage for the array of data blobs to transcribe into audio; // each chunk is preceded by a header which may be long, and is optionally // also preceded by a gap. struct Chunk { bool has_gap; bool long_header; std::vector data; Chunk(bool has_gap, bool long_header, const std::vector &data) : has_gap(has_gap), long_header(long_header), data(std::move(data)) {} }; std::vector chunks_; // Tracker for active state within the file list. std::size_t chunk_pointer_ = 0; enum class Phase { Header, Bytes, Gap, EndOfFile } phase_ = Phase::Header; std::size_t distance_into_phase_ = 0; std::size_t distance_into_bit_ = 0; } serialiser_; }; }