1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-22 12:33:29 +00:00

Adds automatic media starts.

This commit is contained in:
Thomas Harte 2021-03-22 20:12:03 -04:00
parent cc3c3663f6
commit 08432dd94b
3 changed files with 30 additions and 1 deletions

View File

@ -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;
}

View File

@ -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()) {

View File

@ -83,6 +83,13 @@ template<Model model> 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<Model model> 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<Model model> 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<Model model> class ConcreteMachine:
// MARK: - Disc.
JustInTimeActor<Amstrad::FDC, 1, 1, Cycles> fdc_;
// MARK: - Automatic startup.
Cycles duration_to_press_enter_;
};