From 08432dd94bd2af02a3c4a5d5fa570d55f763a470 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 22 Mar 2021 20:12:03 -0400 Subject: [PATCH] Adds automatic media starts. --- Analyser/Static/ZXSpectrum/StaticAnalyser.cpp | 4 ++- Analyser/Static/ZXSpectrum/Target.hpp | 1 + Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp | 26 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Analyser/Static/ZXSpectrum/StaticAnalyser.cpp b/Analyser/Static/ZXSpectrum/StaticAnalyser.cpp index cb3e0f687..0c21161e8 100644 --- a/Analyser/Static/ZXSpectrum/StaticAnalyser.cpp +++ b/Analyser/Static/ZXSpectrum/StaticAnalyser.cpp @@ -86,8 +86,10 @@ Analyser::Static::TargetList Analyser::Static::ZXSpectrum::GetTargets(const Medi } // If any media survived, add the target. - if(!target->media.empty()) + if(!target->media.empty()) { + target->should_hold_enter = true; // To force entry into the 'loader' and thereby load the media. destination.push_back(std::move(target)); + } return destination; } diff --git a/Analyser/Static/ZXSpectrum/Target.hpp b/Analyser/Static/ZXSpectrum/Target.hpp index 159cec9ef..e2711ec55 100644 --- a/Analyser/Static/ZXSpectrum/Target.hpp +++ b/Analyser/Static/ZXSpectrum/Target.hpp @@ -24,6 +24,7 @@ struct Target: public ::Analyser::Static::Target, public Reflection::StructImpl< ); Model model = Model::Plus2a; + bool should_hold_enter = false; Target(): Analyser::Static::Target(Machine::ZXSpectrum) { if(needs_declare()) { diff --git a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp index 6da8f9de7..20dddc04b 100644 --- a/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp +++ b/Machines/Sinclair/ZXSpectrum/ZXSpectrum.cpp @@ -83,6 +83,13 @@ template class ConcreteMachine: // Insert media. insert_media(target.media); + + // Possibly depress the enter key. + if(target.should_hold_enter) { + // Hold it for five seconds, more or less. + duration_to_press_enter_ = Cycles(5 * clock_rate()); + keyboard_.set_key_state(ZX::Keyboard::KeyEnter, true); + } } ~ConcreteMachine() { @@ -124,6 +131,17 @@ template class ConcreteMachine: void run_for(const Cycles cycles) override { z80_.run_for(cycles); + + // Use this very broad timing base for the automatic enter depression. + // It's not worth polluting the main loop. + if(duration_to_press_enter_ > Cycles(0)) { + if(duration_to_press_enter_ < cycles) { + duration_to_press_enter_ = Cycles(0); + keyboard_.set_key_state(ZX::Keyboard::KeyEnter, false); + } else { + duration_to_press_enter_ -= cycles; + } + } } void flush() { @@ -358,6 +376,11 @@ template class ConcreteMachine: void clear_all_keys() override { keyboard_.clear_all_keys(); + + // Caveat: if holding enter synthetically, continue to do so. + if(duration_to_press_enter_ > Cycles(0)) { + keyboard_.set_key_state(ZX::Keyboard::KeyEnter, true); + } } // MARK: - MediaTarget. @@ -585,6 +608,9 @@ template class ConcreteMachine: // MARK: - Disc. JustInTimeActor fdc_; + + // MARK: - Automatic startup. + Cycles duration_to_press_enter_; };