From a3684545b5647a9fcfb824f71bccdcbb46809d59 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 6 Jul 2017 22:33:54 -0400 Subject: [PATCH] Added a block on the tape motor for a short period after each time the ROM routine is intercepted for a substituted byte read. To reduce the collision between fast tape and real tape loading. --- Machines/ZX8081/ZX8081.cpp | 14 ++++++++++++-- Machines/ZX8081/ZX8081.hpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Machines/ZX8081/ZX8081.cpp b/Machines/ZX8081/ZX8081.cpp index 7c18fa392..cf3c24ed0 100644 --- a/Machines/ZX8081/ZX8081.cpp +++ b/Machines/ZX8081/ZX8081.cpp @@ -22,7 +22,8 @@ Machine::Machine() : hsync_(false), nmi_is_enabled_(false), tape_player_(ZX8081ClockRate), - use_fast_tape_hack_(false) { + use_fast_tape_hack_(false), + tape_advance_delay_(0) { set_clock_rate(ZX8081ClockRate); tape_player_.set_motor_control(true); clear_all_keys(); @@ -53,7 +54,11 @@ int Machine::perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) { } if(is_zx81_) horizontal_counter_ %= 207; - if(!use_fast_tape_hack_) tape_player_.run_for_cycles(cycle.length); + if(!tape_advance_delay_) { + tape_player_.run_for_cycles(cycle.length); + } else { + tape_advance_delay_ = std::max(tape_advance_delay_ - cycle.length, 0); + } if(nmi_is_enabled_ && !get_halt_line() && get_non_maskable_interrupt_line()) { set_wait_line(true); @@ -132,6 +137,11 @@ int Machine::perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) { ram_[hl & ram_mask_] = (uint8_t)next_byte; *cycle.value = 0x00; set_value_of_register(CPU::Z80::Register::ProgramCounter, tape_return_address_ - 1); + + // Assume that having read one byte quickly, we're probably going to be asked to read + // another shortly. Therefore, temporarily disable the tape motor for 1000 cycles in order + // to avoid fighting with real time. This is a stop-gap fix. + tape_advance_delay_ = 1000; return 0; } else { tape_player_.get_tape()->seek(time); diff --git a/Machines/ZX8081/ZX8081.hpp b/Machines/ZX8081/ZX8081.hpp index 9bd9044a5..d07ed461a 100644 --- a/Machines/ZX8081/ZX8081.hpp +++ b/Machines/ZX8081/ZX8081.hpp @@ -94,6 +94,7 @@ class Machine: uint8_t latched_video_byte_; bool use_fast_tape_hack_; + int tape_advance_delay_; }; }