From f7422661778acca5777141aaf0f14ad7407e6d03 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 26 Jun 2024 21:53:11 -0400 Subject: [PATCH] Add SSM code capture to CPC. --- Analyser/Static/AmstradCPC/Target.hpp | 3 ++ Machines/AmstradCPC/AmstradCPC.cpp | 43 ++++++++++++++++++++++++--- Machines/AmstradCPC/AmstradCPC.hpp | 10 ++++++- Storage/Automation/CSL.cpp | 8 ----- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/Analyser/Static/AmstradCPC/Target.hpp b/Analyser/Static/AmstradCPC/Target.hpp index 9bffa3358..6a4e74e4f 100644 --- a/Analyser/Static/AmstradCPC/Target.hpp +++ b/Analyser/Static/AmstradCPC/Target.hpp @@ -20,6 +20,9 @@ struct Target: public Analyser::Static::Target, public Reflection::StructImpl class ConcreteMachine: +template +class ConcreteMachine: public MachineTypes::ScanProducer, public MachineTypes::AudioProducer, public MachineTypes::TimedMachine, @@ -942,6 +943,19 @@ template class ConcreteMachine: *cycle.value = 0xc9; break; } + + if constexpr (catches_ssm) { + ssm_code_ = (ssm_code_ << 8) | read_pointers_[address >> 14][address & 16383]; + if((ssm_code_ & 0xff00ff00) == 0xed00ed00) { + if(ssm_delegate_) { + ssm_delegate_->perform( + uint16_t( + (ssm_code_ & 0xff) | ((ssm_code_ >> 8) & 0xff00) + )); + } + ssm_code_ = 0; + } + } [[fallthrough]]; case CPU::Z80::PartialMachineCycle::Read: @@ -1115,6 +1129,10 @@ template class ConcreteMachine: tape_player_is_sleeping_ = tape_player_.preferred_clocking() == ClockingHint::Preference::None; } + void set_ssm_delegate(SSMDelegate *delegate) final { + ssm_delegate_ = delegate; + } + // MARK: - Keyboard void type_string(const std::string &string) final { Utility::TypeRecipient::add_typer(string); @@ -1276,6 +1294,9 @@ template class ConcreteMachine: KeyboardState key_state_; AmstradCPC::KeyboardMapper keyboard_mapper_; + SSMDelegate *ssm_delegate_ = nullptr; + uint32_t ssm_code_ = 0; + bool has_run_ = false; uint8_t ram_[128 * 1024]; }; @@ -1284,12 +1305,26 @@ template class ConcreteMachine: using namespace AmstradCPC; +namespace { + +template +std::unique_ptr machine(const Analyser::Static::AmstradCPC::Target &target, const ROMMachine::ROMFetcher &rom_fetcher) { + using Model = Analyser::Static::AmstradCPC::Target::Model; + switch(target.model) { + default: return std::make_unique>(target, rom_fetcher); + case Model::CPC464: return std::make_unique>(target, rom_fetcher); + } +} + +} + // See header; constructs and returns an instance of the Amstrad CPC. std::unique_ptr Machine::AmstradCPC(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher) { using Target = Analyser::Static::AmstradCPC::Target; const Target *const cpc_target = dynamic_cast(target); - switch(cpc_target->model) { - default: return std::make_unique>(*cpc_target, rom_fetcher); - case Target::Model::CPC464: return std::make_unique>(*cpc_target, rom_fetcher); + if(cpc_target->catch_ssm_codes) { + return machine(*cpc_target, rom_fetcher); + } else { + return machine(*cpc_target, rom_fetcher); } } diff --git a/Machines/AmstradCPC/AmstradCPC.hpp b/Machines/AmstradCPC/AmstradCPC.hpp index 33304eeb0..e29b46285 100644 --- a/Machines/AmstradCPC/AmstradCPC.hpp +++ b/Machines/AmstradCPC/AmstradCPC.hpp @@ -25,7 +25,10 @@ class Machine { virtual ~Machine() = default; /// Creates and returns an Amstrad CPC. - static std::unique_ptr AmstradCPC(const Analyser::Static::Target *target, const ROMMachine::ROMFetcher &rom_fetcher); + static std::unique_ptr AmstradCPC( + const Analyser::Static::Target *target, + const ROMMachine::ROMFetcher &rom_fetcher + ); /// Defines the runtime options available for an Amstrad CPC. class Options: @@ -47,6 +50,11 @@ class Machine { } } }; + + struct SSMDelegate { + virtual void perform(uint16_t) = 0; + }; + virtual void set_ssm_delegate(SSMDelegate *) = 0; }; } diff --git a/Storage/Automation/CSL.cpp b/Storage/Automation/CSL.cpp index 52a4e9666..2982fccd1 100644 --- a/Storage/Automation/CSL.cpp +++ b/Storage/Automation/CSL.cpp @@ -20,14 +20,6 @@ using namespace Storage::Automation; namespace { -struct CSLTest { - CSLTest() { - CSL::parse("/Users/thomasharte/Downloads/Shaker_CSL/MODULE A/SHAKE26A-4.CSL"); - } - -}; -CSLTest test; - bool append_typed(std::vector &down, std::vector &up, std::istringstream &stream) { const auto press = [&](uint16_t key) { CSL::KeyEvent event;