From dbc0ecde311bb491bc0fede3ebb669063cb42d78 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 30 Jun 2024 21:26:16 -0400 Subject: [PATCH] Catch SSM events. --- Machines/AmstradCPC/AmstradCPC.cpp | 29 ++++++++++++++----- .../Mac/Clock SignalTests/CPCShakerTests.mm | 15 ++++++---- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index a7a046d3b..ff547d481 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -946,14 +946,29 @@ class ConcreteMachine: 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) - )); + if(ssm_delegate_) { + if((ssm_code_ & 0xff00ff00) == 0xed00ed00) { + const auto code = uint16_t( + (ssm_code_ & 0xff) | ((ssm_code_ >> 8) & 0xff00) + ); + ssm_code_ = 0; + + if( + (code <= 0x3f3f) || + (code >= 0x7f7f && code <= 0x9f9f) || + (code >= 0xa4a4 && code <= 0xa7a7) || + (code >= 0xacac && code <= 0xafaf) || + (code >= 0xb4b4 && code <= 0xb7b7) || + (code >= 0xbcbc && code <= 0xbfbf) || + (code >= 0xc0c0 && code <= 0xfdfd) + ) { + ssm_delegate_->perform(code); + } } - ssm_code_ = 0; + } else if((ssm_code_ & 0xffff) == 0xedfe) { + ssm_delegate_->perform(0xfffe); + } else if((ssm_code_ & 0xffff) == 0xedff) { + ssm_delegate_->perform(0xffff); } } [[fallthrough]]; diff --git a/OSBindings/Mac/Clock SignalTests/CPCShakerTests.mm b/OSBindings/Mac/Clock SignalTests/CPCShakerTests.mm index 9fc81a247..7ffc35ef4 100644 --- a/OSBindings/Mac/Clock SignalTests/CPCShakerTests.mm +++ b/OSBindings/Mac/Clock SignalTests/CPCShakerTests.mm @@ -21,8 +21,10 @@ #include "KeyboardMachine.hpp" #include "MachineForTarget.hpp" -struct CSLPerformer { - +struct SSMDelegate: public AmstradCPC::Machine::SSMDelegate { + void perform(uint16_t code) { + NSLog(@"SSM %04x", code); + } }; // @@ -31,23 +33,27 @@ struct CSLPerformer { @interface CPCShakerTests : XCTestCase @end -@implementation CPCShakerTests { -} +@implementation CPCShakerTests {} - (void)testCSLPath:(NSString *)path name:(NSString *)name { using namespace Storage::Automation; const auto steps = CSL::parse([[path stringByAppendingPathComponent:name] UTF8String]); + SSMDelegate ssm_delegate; + std::unique_ptr lazy_machine; CSL::KeyDelay key_delay; using Target = Analyser::Static::AmstradCPC::Target; Target target; target.catch_ssm_codes = true; + target.model = Target::Model::CPC6128; const auto machine = [&]() -> Machine::DynamicMachine& { if(!lazy_machine) { Machine::Error error; lazy_machine = Machine::MachineForTarget(&target, CSROMFetcher(), error); + reinterpret_cast(lazy_machine->raw_pointer()) + ->set_ssm_delegate(&ssm_delegate); } return *lazy_machine; }; @@ -56,7 +62,6 @@ struct CSLPerformer { }; using Type = CSL::Instruction::Type; - int c = 0; for(const auto &step: steps) { switch(step.type) { case Type::Version: