From 9c2df231ce114874a846541d4ab093b04917cf2b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 3 Nov 2016 07:59:30 -0400 Subject: [PATCH] Made fast loading optional. --- Machines/Oric/Oric.cpp | 27 ++++++++++--------- Machines/Oric/Oric.hpp | 19 +++++++------ .../Clock Signal/Base.lproj/OricOptions.xib | 25 +++++++++++++---- .../Clock Signal/Machine/Wrappers/CSOric.h | 6 +++-- .../Clock Signal/Machine/Wrappers/CSOric.mm | 7 +++++ 5 files changed, 57 insertions(+), 27 deletions(-) diff --git a/Machines/Oric/Oric.cpp b/Machines/Oric/Oric.cpp index f04eeabcc..cb1ffec81 100644 --- a/Machines/Oric/Oric.cpp +++ b/Machines/Oric/Oric.cpp @@ -11,7 +11,7 @@ using namespace Oric; -Machine::Machine() : _cycles_since_video_update(0) +Machine::Machine() : _cycles_since_video_update(0), _use_fast_tape_hack(false) { set_clock_rate(1000000); _via.tape.reset(new TapePlayer); @@ -44,7 +44,7 @@ unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uin // 024D = 0 => fast; otherwise slow // E6C9 = read byte: return byte in A - if(address == 0xe6c9 && operation == CPU6502::BusOperation::ReadOpcode) + if(address == 0xe6c9 && _use_fast_tape_hack && operation == CPU6502::BusOperation::ReadOpcode) { uint8_t next_byte = _via.tape->get_next_byte(!_ram[0x024d]); set_value_of_register(CPU6502::A, next_byte); @@ -126,6 +126,11 @@ void Machine::clear_all_keys() memset(_keyboard->rows, 0, sizeof(_keyboard->rows)); } +void Machine::set_use_fast_tape_hack(bool activate) +{ + _use_fast_tape_hack = activate; +} + void Machine::tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape_player) { // set CB1 @@ -196,7 +201,7 @@ void Machine::VIA::run_for_cycles(unsigned int number_of_cycles) { _cycles_since_ay_update += number_of_cycles; MOS::MOS6522::run_for_cycles(number_of_cycles); - tape->run_for_cycles(number_of_cycles); + tape->run_for_cycles((int)number_of_cycles); } void Machine::VIA::update_ay() @@ -210,11 +215,7 @@ void Machine::VIA::update_ay() Machine::TapePlayer::TapePlayer() : Storage::Tape::BinaryTapePlayer(1000000), - _is_catching_bytes(false), - _cycle_length(0.0f), - _was_high(false), - _queued_lengths_pointer(0), - _shift_register(0) + _is_catching_bytes(false) {} uint8_t Machine::TapePlayer::get_next_byte(bool fast) @@ -222,17 +223,19 @@ uint8_t Machine::TapePlayer::get_next_byte(bool fast) _is_in_fast_mode = fast; _is_catching_bytes = true; - _bit_count = 0; _was_high = get_input(); _queued_lengths_pointer = 0; - _shift_register = 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)(_shift_register >> 1); + return (uint8_t)(_data_register >> 1); } void Machine::TapePlayer::process_input_pulse(Storage::Tape::Tape::Pulse pulse) @@ -261,7 +264,7 @@ void Machine::TapePlayer::process_input_pulse(Storage::Tape::Tape::Pulse pulse) int new_bit = (first_two < 0.000512) ? 1 : 0; if(_bit_count || !new_bit) { - _shift_register |= (new_bit << _bit_count); + _data_register |= (new_bit << _bit_count); _bit_count++; } memmove(_queued_lengths, &_queued_lengths[2], sizeof(float)*14); diff --git a/Machines/Oric/Oric.hpp b/Machines/Oric/Oric.hpp index 5b108bc82..c84d189d1 100644 --- a/Machines/Oric/Oric.hpp +++ b/Machines/Oric/Oric.hpp @@ -61,6 +61,8 @@ class Machine: void set_key_state(Key key, bool isPressed); void clear_all_keys(); + void set_use_fast_tape_hack(bool activate); + // to satisfy ConfigurationTarget::Machine void configure_as_target(const StaticAnalyser::Target &target); @@ -105,20 +107,21 @@ class Machine: void run_for_cycles(int number_of_cycles); private: - bool _is_in_fast_mode; - bool _is_catching_bytes; + 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; - bool _was_high; + 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]; - int _queued_lengths_pointer; + 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 _shift_register; - int _bit_count; + 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); }; + bool _use_fast_tape_hack; // VIA (which owns the tape and the AY) class VIA: public MOS::MOS6522, public MOS::MOS6522IRQDelegate { diff --git a/OSBindings/Mac/Clock Signal/Base.lproj/OricOptions.xib b/OSBindings/Mac/Clock Signal/Base.lproj/OricOptions.xib index e1cdad4d0..aea4e9546 100644 --- a/OSBindings/Mac/Clock Signal/Base.lproj/OricOptions.xib +++ b/OSBindings/Mac/Clock Signal/Base.lproj/OricOptions.xib @@ -1,5 +1,5 @@ - + @@ -14,12 +14,22 @@ - + - + + @@ -38,15 +48,20 @@ + + + + + - + - + diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSOric.h b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSOric.h index 3cd3e67d4..c284944c1 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSOric.h +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSOric.h @@ -8,9 +8,11 @@ #import "CSMachine.h" #import "CSKeyboardMachine.h" +#import "CSFastLoading.h" -@interface CSOric : CSMachine +@interface CSOric : CSMachine -@property(nonatomic, assign) BOOL useCompositeOutput; +@property (nonatomic, assign) BOOL useFastLoadingHack; +@property (nonatomic, assign) BOOL useCompositeOutput; @end diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSOric.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSOric.mm index c6dde0e4a..f25982c71 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSOric.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSOric.mm @@ -135,6 +135,13 @@ #pragma mark - Options +- (void)setUseFastLoadingHack:(BOOL)useFastLoadingHack { + @synchronized(self) { + _useFastLoadingHack = useFastLoadingHack; + _oric.set_use_fast_tape_hack(useFastLoadingHack ? true : false); + } +} + - (void)setUseCompositeOutput:(BOOL)useCompositeOutput { @synchronized(self) { _useCompositeOutput = useCompositeOutput;