From 3673cfe9be8bd81280f93219842202a1c63bb67e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 19 Feb 2018 16:57:24 -0500 Subject: [PATCH] Pulls method call for tape fast loading checks out of inner loop for the Vic, Electron and ZX80/81. --- Machines/Commodore/Vic-20/Vic20.cpp | 20 ++++++++++---------- Machines/Electron/Electron.cpp | 13 +++++++------ Machines/ZX8081/ZX8081.cpp | 13 ++++++++----- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index 551404825..d0edf7cf0 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -312,9 +312,6 @@ class ConcreteMachine: delete[] rom_; } - void set_rom(ROMSlot slot, const std::vector &data) { - } - // Obtains the system ROMs. bool set_rom_fetcher(const std::function>>(const std::string &machine, const std::vector &names)> &roms_with_names) override { auto roms = roms_with_names( @@ -396,6 +393,8 @@ class ConcreteMachine: write_to_map(processor_read_memory_map_, rom_, rom_address_, 0x2000); } + set_use_fast_tape(); + return !media.tapes.empty() || (!media.disks.empty() && c1540_ != nullptr) || !media.cartridges.empty(); } @@ -516,10 +515,6 @@ class ConcreteMachine: } } - void set_use_fast_tape_hack(bool activate) { - use_fast_tape_hack_ = activate; - } - // to satisfy CPU::MOS6502::Processor forceinline Cycles perform_bus_operation(CPU::MOS6502::BusOperation operation, uint16_t address, uint8_t *value) { // run the phase-1 part of this cycle, in which the VIC accesses memory @@ -539,7 +534,7 @@ class ConcreteMachine: // PC hits the start of the loop that just waits for an interesting tape interrupt to have // occurred then skip both 6522s and the tape ahead to the next interrupt without any further // CPU or 6560 costs. - if(use_fast_tape_hack_ && tape_->has_tape() && operation == CPU::MOS6502::BusOperation::ReadOpcode) { + if(use_fast_tape_hack_ && operation == CPU::MOS6502::BusOperation::ReadOpcode) { if(address == 0xf7b2) { // Address 0xf7b2 contains a JSR to 0xf8c0 that will fill the tape buffer with the next header. // So cancel that via a double NOP and fill in the next header programmatically. @@ -674,7 +669,8 @@ class ConcreteMachine: void set_selections(const Configurable::SelectionSet &selections_by_option) override { bool quickload; if(Configurable::get_quick_load_tape(selections_by_option, quickload)) { - set_use_fast_tape_hack(quickload); + allow_fast_tape_hack_ = quickload; + set_use_fast_tape(); } } @@ -739,8 +735,12 @@ class ConcreteMachine: // Tape std::shared_ptr tape_; - bool use_fast_tape_hack_; + bool use_fast_tape_hack_ = false; + bool allow_fast_tape_hack_ = false; bool is_running_at_zero_cost_ = false; + void set_use_fast_tape() { + use_fast_tape_hack_ = allow_fast_tape_hack_ && tape_->has_tape(); + } // Disk std::shared_ptr<::Commodore::C1540::Machine> c1540_; diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 714348515..34c77b0d7 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -115,10 +115,6 @@ class ConcreteMachine: if(is_holding_shift_) set_key_state(KeyShift, true); } - void set_use_fast_tape_hack(bool activate) { - use_fast_tape_hack_ = activate; - } - void configure_as_target(const Analyser::Static::Target &target) override final { if(target.loading_command.length()) { type_string(target.loading_command); @@ -158,6 +154,7 @@ class ConcreteMachine: slot = static_cast((static_cast(slot) + 1)&15); } + set_use_fast_tape_hack(); return !media.tapes.empty() || !media.disks.empty() || !media.cartridges.empty(); } @@ -283,7 +280,6 @@ class ConcreteMachine: if(isReadOperation(operation)) { if( use_fast_tape_hack_ && - tape_.has_tape() && (operation == CPU::MOS6502::BusOperation::ReadOpcode) && ( (address == 0xf4e5) || (address == 0xf4e6) || // double NOPs at 0xf4e5, 0xf6de, 0xf6fa and 0xfa51 @@ -437,7 +433,8 @@ class ConcreteMachine: void set_selections(const Configurable::SelectionSet &selections_by_option) override { bool quickload; if(Configurable::get_quick_load_tape(selections_by_option, quickload)) { - set_use_fast_tape_hack(quickload); + allow_fast_tape_hack_ = quickload; + set_use_fast_tape_hack(); } Configurable::Display display; @@ -526,6 +523,10 @@ class ConcreteMachine: // Tape Tape tape_; bool use_fast_tape_hack_ = false; + bool allow_fast_tape_hack_ = false; + void set_use_fast_tape_hack() { + use_fast_tape_hack_ = allow_fast_tape_hack_ && tape_.has_tape(); + } bool fast_load_is_in_data_ = false; // Disk diff --git a/Machines/ZX8081/ZX8081.cpp b/Machines/ZX8081/ZX8081.cpp index 7e8c8a507..017e4c153 100644 --- a/Machines/ZX8081/ZX8081.cpp +++ b/Machines/ZX8081/ZX8081.cpp @@ -158,7 +158,7 @@ template class ConcreteMachine: case CPU::Z80::PartialMachineCycle::ReadOpcode: // Check for use of the fast tape hack. - if(use_fast_tape_hack_ && address == tape_trap_address_ && tape_player_.has_tape()) { + if(use_fast_tape_hack_ && address == tape_trap_address_) { uint64_t prior_offset = tape_player_.get_tape()->get_offset(); int next_byte = parser_.get_next_byte(tape_player_.get_tape()); if(next_byte != -1) { @@ -290,6 +290,7 @@ template class ConcreteMachine: tape_player_.set_tape(media.tapes.front()); } + set_use_fast_tape(); return !media.tapes.empty(); } @@ -331,9 +332,6 @@ template class ConcreteMachine: } // MARK: - Tape control - void set_use_fast_tape_hack(bool activate) { - use_fast_tape_hack_ = activate; - } void set_use_automatic_tape_motor_control(bool enabled) { use_automatic_tape_motor_control_ = enabled; @@ -366,7 +364,8 @@ template class ConcreteMachine: void set_selections(const Configurable::SelectionSet &selections_by_option) override { bool quickload; if(Configurable::get_quick_load_tape(selections_by_option, quickload)) { - set_use_fast_tape_hack(quickload); + allow_fast_tape_hack_ = quickload; + set_use_fast_tape(); } bool autotapemotor; @@ -423,6 +422,10 @@ template class ConcreteMachine: bool has_latched_video_byte_ = false; bool use_fast_tape_hack_ = false; + bool allow_fast_tape_hack_ = false; + void set_use_fast_tape() { + use_fast_tape_hack_ = allow_fast_tape_hack_ && tape_player_.has_tape(); + } bool use_automatic_tape_motor_control_; HalfCycles tape_advance_delay_ = 0;