2016-11-06 21:13:13 +00:00
|
|
|
//
|
|
|
|
// Commodore.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 06/11/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-11-06 21:13:13 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Storage_Tape_Parsers_Commodore_hpp
|
|
|
|
#define Storage_Tape_Parsers_Commodore_hpp
|
|
|
|
|
|
|
|
#include "TapeParser.hpp"
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
namespace Tape {
|
|
|
|
namespace Commodore {
|
|
|
|
|
|
|
|
enum class WaveType {
|
|
|
|
Short, Medium, Long, Unrecognised
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class SymbolType {
|
|
|
|
One, Zero, Word, EndOfBlock, LeadIn
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Header {
|
|
|
|
enum {
|
|
|
|
RelocatableProgram,
|
|
|
|
NonRelocatableProgram,
|
|
|
|
DataSequenceHeader,
|
|
|
|
DataBlock,
|
|
|
|
EndOfTape,
|
|
|
|
Unknown
|
|
|
|
} type;
|
|
|
|
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
std::wstring name;
|
|
|
|
std::vector<uint8_t> raw_name;
|
|
|
|
uint16_t starting_address;
|
|
|
|
uint16_t ending_address;
|
|
|
|
bool parity_was_valid;
|
|
|
|
bool duplicate_matched;
|
2017-05-08 00:32:48 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Writes a byte serialised version of this header to @c target, writing at most
|
|
|
|
@c length bytes.
|
|
|
|
*/
|
|
|
|
void serialise(uint8_t *target, uint16_t length);
|
2016-11-06 21:13:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
bool parity_was_valid;
|
|
|
|
bool duplicate_matched;
|
|
|
|
};
|
|
|
|
|
2017-07-15 23:07:35 +00:00
|
|
|
class Parser: public Storage::Tape::PulseClassificationParser<WaveType, SymbolType> {
|
2016-11-06 21:13:13 +00:00
|
|
|
public:
|
|
|
|
Parser();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Advances to the next block on the tape, treating it as a header, then consumes, parses, and returns it.
|
|
|
|
Returns @c nullptr if any wave-encoding level errors are encountered.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<Header> get_next_header(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Advances to the next block on the tape, treating it as data, then consumes, parses, and returns it.
|
|
|
|
Returns @c nullptr if any wave-encoding level errors are encountered.
|
|
|
|
*/
|
|
|
|
std::unique_ptr<Data> get_next_data(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/*!
|
|
|
|
Template for the logic in selecting which of two copies of something to consider authoritative,
|
|
|
|
including setting the duplicate_matched flag.
|
|
|
|
*/
|
|
|
|
template<class ObjectType>
|
|
|
|
std::unique_ptr<ObjectType> duplicate_match(std::unique_ptr<ObjectType> first_copy, std::unique_ptr<ObjectType> second_copy);
|
|
|
|
|
|
|
|
std::unique_ptr<Header> get_next_header_body(const std::shared_ptr<Storage::Tape::Tape> &tape, bool is_original);
|
|
|
|
std::unique_ptr<Data> get_next_data_body(const std::shared_ptr<Storage::Tape::Tape> &tape, bool is_original);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Finds and completes the next landing zone.
|
|
|
|
*/
|
|
|
|
void proceed_to_landing_zone(const std::shared_ptr<Storage::Tape::Tape> &tape, bool is_original);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Swallows the next byte; sets the error flag if it is not equal to @c value.
|
|
|
|
*/
|
|
|
|
void expect_byte(const std::shared_ptr<Storage::Tape::Tape> &tape, uint8_t value);
|
|
|
|
|
2017-11-11 03:47:10 +00:00
|
|
|
uint8_t parity_byte_ = 0;
|
2016-11-06 21:13:13 +00:00
|
|
|
void reset_parity_byte();
|
|
|
|
uint8_t get_parity_byte();
|
|
|
|
void add_parity_byte(uint8_t byte);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Proceeds to the next word marker then returns the result of @c get_next_byte_contents.
|
|
|
|
*/
|
|
|
|
uint8_t get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
|
|
|
|
|
|
|
/*!
|
2017-11-08 03:54:22 +00:00
|
|
|
Reads the next nine symbols and applies a binary test to each to differentiate between ::One and not-::One.
|
2016-11-06 21:13:13 +00:00
|
|
|
Returns a byte composed of the first eight of those as bits; sets the error flag if any symbol is not
|
|
|
|
::One and not ::Zero, or if the ninth bit is not equal to the odd parity of the other eight.
|
|
|
|
*/
|
|
|
|
uint8_t get_next_byte_contents(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the result of two consecutive @c get_next_byte calls, arranged in little-endian format.
|
|
|
|
*/
|
|
|
|
uint16_t get_next_short(const std::shared_ptr<Storage::Tape::Tape> &tape);
|
|
|
|
|
|
|
|
/*!
|
2018-01-25 02:48:44 +00:00
|
|
|
Per the contract with Analyser::Static::TapeParser; sums time across pulses. If this pulse
|
2016-11-06 21:13:13 +00:00
|
|
|
indicates a high to low transition, inspects the time since the last transition, to produce
|
|
|
|
a long, medium, short or unrecognised wave period.
|
|
|
|
*/
|
2021-03-07 20:56:58 +00:00
|
|
|
void process_pulse(const Storage::Tape::Tape::Pulse &pulse) override;
|
2017-11-11 03:47:10 +00:00
|
|
|
bool previous_was_high_ = false;
|
|
|
|
float wave_period_ = 0.0f;
|
2016-11-06 21:13:13 +00:00
|
|
|
|
|
|
|
/*!
|
2018-01-25 02:48:44 +00:00
|
|
|
Per the contract with Analyser::Static::TapeParser; produces any of a word marker, an end-of-block marker,
|
2016-11-06 21:13:13 +00:00
|
|
|
a zero, a one or a lead-in symbol based on the currently captured waves.
|
|
|
|
*/
|
2021-03-07 20:56:58 +00:00
|
|
|
void inspect_waves(const std::vector<WaveType> &waves) override;
|
2016-11-06 21:13:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Commodore_hpp */
|