From 64827931bf9c60fb1bf0fdbac3a34e2855602fb9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 7 Nov 2016 21:57:58 -0500 Subject: [PATCH] Switched the Oric implementation simply to rely upon the Storage-level tape parser. So now there's only one, authoritative one of those. --- Machines/Oric/Oric.cpp | 79 ++++-------------------------------------- Machines/Oric/Oric.hpp | 18 ++-------- 2 files changed, 9 insertions(+), 88 deletions(-) diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index 64f53df89..a3a5b7b3c 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -17,7 +17,6 @@ Machine::Machine() : _typer_delay(2500000) { set_clock_rate(1000000); - _via.tape.reset(new TapePlayer); _via.set_interrupt_delegate(this); _keyboard.reset(new Keyboard); _via.keyboard = _keyboard; @@ -171,7 +170,10 @@ void Machine::run_for_cycles(int number_of_cycles) #pragma mark - The 6522 -Machine::VIA::VIA() : MOS::MOS6522(), _cycles_since_ay_update(0) {} +Machine::VIA::VIA() : + MOS::MOS6522(), + _cycles_since_ay_update(0), + tape(new TapePlayer) {} void Machine::VIA::set_control_line_output(Port port, Line line, bool value) { @@ -231,79 +233,10 @@ void Machine::VIA::update_ay() #pragma mark - TapePlayer Machine::TapePlayer::TapePlayer() : - Storage::Tape::BinaryTapePlayer(1000000), - _is_catching_bytes(false) + Storage::Tape::BinaryTapePlayer(1000000) {} uint8_t Machine::TapePlayer::get_next_byte(bool fast) { - _is_in_fast_mode = fast; - _is_catching_bytes = true; - - _was_high = get_input(); - _queued_lengths_pointer = 0; - _data_register = 0; - _cycle_length = 0.0f; - - _bit_count = 0; - while(_bit_count < 10) - { - process_next_event(); - } - - _is_catching_bytes = false; - return (uint8_t)(_data_register >> 1); -} - -void Machine::TapePlayer::process_input_pulse(Storage::Tape::Tape::Pulse pulse) -{ - Storage::Tape::BinaryTapePlayer::process_input_pulse(pulse); - - if(_is_catching_bytes) - { - _cycle_length += pulse.length.get_float(); - bool is_high = get_input(); - if(is_high != _was_high) - { - // queue up the new length - _queued_lengths[_queued_lengths_pointer] = _cycle_length; - _cycle_length = 0.0f; - _queued_lengths_pointer++; - - // search for bits - if(_is_in_fast_mode) - { - if(_queued_lengths_pointer >= 2) - { - float first_two = _queued_lengths[0] + _queued_lengths[1]; - if(first_two < 0.000512*2.0 && _queued_lengths[0] >= _queued_lengths[1] - 0.000256) - { - int new_bit = (first_two < 0.000512) ? 1 : 0; - if(_bit_count || !new_bit) - { - _data_register |= (new_bit << _bit_count); - _bit_count++; - } - memmove(_queued_lengths, &_queued_lengths[2], sizeof(float)*14); - _queued_lengths_pointer -= 2; - } - else - { - memmove(_queued_lengths, &_queued_lengths[1], sizeof(float)*15); - _queued_lengths_pointer--; - } - } - } - else - { - // TODO - } - } - _was_high = is_high; - } -} - -void Machine::TapePlayer::run_for_cycles(int number_of_cycles) -{ - if(!_is_catching_bytes) Storage::Tape::BinaryTapePlayer::run_for_cycles(number_of_cycles); + return (uint8_t)_parser.get_next_byte(get_tape(), fast); } diff --git a/Machines/Oric/Oric.hpp b/Machines/Oric/Oric.hpp index d020dd3c6..7a2939992 100644 --- a/Machines/Oric/Oric.hpp +++ b/Machines/Oric/Oric.hpp @@ -16,6 +16,7 @@ #include "../../Processors/6502/CPU6502.hpp" #include "../../Components/6522/6522.hpp" #include "../../Components/AY38910/AY38910.hpp" +#include "../../Storage/Tape/Parsers/Oric.hpp" #include "Video.hpp" @@ -112,22 +113,9 @@ class Machine: public: TapePlayer(); uint8_t get_next_byte(bool fast); - void run_for_cycles(int number_of_cycles); private: - bool _is_catching_bytes; // `true` to enable tape byte parsing, `false` otherwise - bool _is_in_fast_mode; // `true` to indicate that tape byte parsing should use the Oric's fast encoding, `false` otherwise - - float _cycle_length; // a counter for the amount of time since the tape input changed - bool _was_high; // a latch to spot when the tape input changes - - float _queued_lengths[16]; // a history of previous half-wave lengths - int _queued_lengths_pointer; // a pointer into the history, showing the number of lengths waiting to be parsed - - int _data_register; // the accumulation of input bits - int _bit_count; // a counter of accumulated bits - - virtual void process_input_pulse(Storage::Tape::Tape::Pulse pulse); + Storage::Tape::Oric::Parser _parser; }; bool _use_fast_tape_hack; @@ -143,7 +131,7 @@ class Machine: inline void run_for_cycles(unsigned int number_of_cycles); std::shared_ptr ay8910; - std::shared_ptr tape; + std::unique_ptr tape; std::shared_ptr keyboard; void synchronise();