From a32a2f36be6369478bc18fac78ff50b6398d9882 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 12 Mar 2021 19:15:35 -0500 Subject: [PATCH] Advances to correctly reading bytes. Something is still amiss though. Maybe I'm supposed to update the checksum? --- Machines/AmstradCPC/AmstradCPC.cpp | 11 ++++++++++- Storage/Tape/Parsers/Spectrum.hpp | 7 ++++++- Storage/Tape/Tape.cpp | 8 ++++++++ Storage/Tape/Tape.hpp | 3 +++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index 6595fa47e..4ed228ace 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -919,12 +919,21 @@ template class ConcreteMachine: if(address == tape_read_byte_address && read_pointers_[0] == roms_[ROMType::OS].data()) { using Parser = Storage::Tape::ZXSpectrum::Parser; Parser parser(Parser::MachineType::AmstradCPC); - parser.set_cpc_read_speed(read_pointers_[tape_speed_value_address >> 14][tape_speed_value_address & 16383]); + const auto speed = read_pointers_[tape_speed_value_address >> 14][tape_speed_value_address & 16383]; + parser.set_cpc_read_speed(speed); + + // Seed with the current pulse; the CPC will have finished the + // preceding symbol and be a short way into the pulse that should determine the + // first bit of this byte. + parser.process_pulse(tape_player_.get_current_pulse()); const auto byte = parser.get_byte(tape_player_.get_tape()); auto flags = z80_.get_value_of_register(CPU::Z80::Register::Flags); if(byte) { + // In A ROM-esque fashion, begin the first pulse after the final one + // that was just consumed. + tape_player_.complete_pulse(); z80_.set_value_of_register(CPU::Z80::Register::A, *byte); flags |= CPU::Z80::Flag::Carry; } else { diff --git a/Storage/Tape/Parsers/Spectrum.hpp b/Storage/Tape/Parsers/Spectrum.hpp index 2b99fcbfb..db51c8f1b 100644 --- a/Storage/Tape/Parsers/Spectrum.hpp +++ b/Storage/Tape/Parsers/Spectrum.hpp @@ -94,6 +94,12 @@ class Parser: public Storage::Tape::PulseClassificationParser &waves) override; uint8_t checksum_ = 0; diff --git a/Storage/Tape/Tape.cpp b/Storage/Tape/Tape.cpp index 95d57346a..d2f440e1c 100644 --- a/Storage/Tape/Tape.cpp +++ b/Storage/Tape/Tape.cpp @@ -97,6 +97,14 @@ void TapePlayer::get_next_pulse() { set_next_event_time_interval(current_pulse_.length); } +Tape::Pulse TapePlayer::get_current_pulse() { + return current_pulse_; +} + +void TapePlayer::complete_pulse() { + jump_to_next_event(); +} + void TapePlayer::run_for(const Cycles cycles) { if(has_tape()) { TimedEventLoop::run_for(cycles); diff --git a/Storage/Tape/Tape.hpp b/Storage/Tape/Tape.hpp index d506e8851..005225d71 100644 --- a/Storage/Tape/Tape.hpp +++ b/Storage/Tape/Tape.hpp @@ -110,6 +110,9 @@ class TapePlayer: public TimedEventLoop, public ClockingHint::Source { ClockingHint::Preference preferred_clocking() const override; + Tape::Pulse get_current_pulse(); + void complete_pulse(); + protected: virtual void process_next_event() override; virtual void process_input_pulse(const Tape::Pulse &pulse) = 0;