2017-11-25 18:18:24 +00:00
|
|
|
//
|
|
|
|
// CAS.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 25/11/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-11-25 18:18:24 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef CAS_hpp
|
|
|
|
#define CAS_hpp
|
|
|
|
|
|
|
|
#include "../Tape.hpp"
|
|
|
|
#include "../../FileHolder.hpp"
|
|
|
|
|
2017-12-23 23:41:50 +00:00
|
|
|
#include <cstdint>
|
2018-04-06 21:42:24 +00:00
|
|
|
#include <string>
|
2017-12-23 23:41:50 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2017-11-25 18:18:24 +00:00
|
|
|
namespace Storage {
|
|
|
|
namespace 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.
|
|
|
|
*/
|
2018-04-06 21:42:24 +00:00
|
|
|
CAS(const std::string &file_name);
|
2017-11-25 18:18:24 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
ErrorNotCAS
|
|
|
|
};
|
|
|
|
|
|
|
|
// implemented to satisfy @c Tape
|
|
|
|
bool is_at_end();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void virtual_reset();
|
|
|
|
Pulse virtual_get_next_pulse();
|
2017-12-22 03:34:03 +00:00
|
|
|
|
2017-12-29 14:56:58 +00:00
|
|
|
// Storage for the array of data blobs to transcribe into audio;
|
2018-05-05 23:32:20 +00:00
|
|
|
// each chunk is preceded by a header which may be long, and is optionally
|
|
|
|
// also preceded by a gap.
|
2017-12-29 14:56:58 +00:00
|
|
|
struct Chunk {
|
2018-11-24 03:32:32 +00:00
|
|
|
bool has_gap;
|
2018-05-05 23:32:20 +00:00
|
|
|
bool long_header;
|
2017-12-29 14:56:58 +00:00
|
|
|
std::vector<std::uint8_t> data;
|
2019-03-02 19:19:54 +00:00
|
|
|
|
|
|
|
Chunk(bool has_gap, bool long_header, const std::vector<std::uint8_t> &data) :
|
|
|
|
has_gap(has_gap), long_header(long_header), data(std::move(data)) {}
|
2017-12-23 23:41:50 +00:00
|
|
|
};
|
2017-12-29 14:56:58 +00:00
|
|
|
std::vector<Chunk> chunks_;
|
2017-12-22 03:34:03 +00:00
|
|
|
|
2017-12-23 23:41:50 +00:00
|
|
|
// Tracker for active state within the file list.
|
|
|
|
std::size_t chunk_pointer_ = 0;
|
2017-12-22 03:34:03 +00:00
|
|
|
enum class Phase {
|
|
|
|
Header,
|
|
|
|
Bytes,
|
2017-12-23 23:41:50 +00:00
|
|
|
Gap,
|
|
|
|
EndOfFile
|
2017-12-22 03:34:03 +00:00
|
|
|
} phase_ = Phase::Header;
|
2017-12-23 23:41:50 +00:00
|
|
|
std::size_t distance_into_phase_ = 0;
|
|
|
|
std::size_t distance_into_bit_ = 0;
|
2017-11-25 18:18:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CAS_hpp */
|