From b03d91d5dd470386f5aba15eefb1d020bdf20ab2 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 8 Jul 2022 15:38:29 -0400 Subject: [PATCH] Permit granular specification of what to flush. --- Machines/Amiga/Amiga.cpp | 2 +- Machines/MasterSystem/MasterSystem.cpp | 12 ++++++++---- Machines/TimedMachine.hpp | 9 +++++++-- OSBindings/Mac/Clock Signal/Machine/CSMachine.mm | 4 ++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Machines/Amiga/Amiga.cpp b/Machines/Amiga/Amiga.cpp index 5a345359b..30afa9f43 100644 --- a/Machines/Amiga/Amiga.cpp +++ b/Machines/Amiga/Amiga.cpp @@ -219,7 +219,7 @@ class ConcreteMachine: mc68000_.run_for(cycles); } - void flush_output() final { + void flush_output(Output) final { flush(); } diff --git a/Machines/MasterSystem/MasterSystem.cpp b/Machines/MasterSystem/MasterSystem.cpp index 507b318df..6c5b9dc49 100644 --- a/Machines/MasterSystem/MasterSystem.cpp +++ b/Machines/MasterSystem/MasterSystem.cpp @@ -210,10 +210,14 @@ class ConcreteMachine: z80_.run_for(cycles); } - void flush_output() final { - vdp_.flush(); - update_audio(); - audio_queue_.perform(); + void flush_output(Output output) final { + if(int(output) & int(Output::Video)) { + vdp_.flush(); + } + if(int(output) & int(Output::Audio)) { + update_audio(); + audio_queue_.perform(); + } } forceinline HalfCycles perform_machine_cycle(const CPU::Z80::PartialMachineCycle &cycle) { diff --git a/Machines/TimedMachine.hpp b/Machines/TimedMachine.hpp index df17baece..c741d9016 100644 --- a/Machines/TimedMachine.hpp +++ b/Machines/TimedMachine.hpp @@ -61,8 +61,13 @@ class TimedMachine { virtual float get_confidence() { return 0.5f; } virtual std::string debug_type() { return ""; } - /// Ensures all locally-buffered output is posted onward. - virtual void flush_output() {} + enum class Output { + Video = 1 << 0, + Audio = 1 << 1 + }; + /// Ensures all locally-buffered output is posted onward for the types of output indicated + /// by the bitfield argument. + virtual void flush_output(Output) {} protected: /// Runs the machine for @c cycles. diff --git a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm index bb66f3461..579a66451 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSMachine.mm @@ -678,13 +678,13 @@ struct ActivityObserver: public Activity::Observer { - (void)audioQueueIsRunningDry:(nonnull CSAudioQueue *)audioQueue { updater.update([self] { - updater.performer.machine->flush_output(); + updater.performer.machine->flush_output(MachineTypes::TimedMachine::Output::Audio); }); } - (void)scanTargetViewDisplayLinkDidFire:(CSScanTargetView *)view now:(const CVTimeStamp *)now outputTime:(const CVTimeStamp *)outputTime { updater.update([self] { - updater.performer.machine->flush_output(); + updater.performer.machine->flush_output(MachineTypes::TimedMachine::Output::Video); dispatch_async(dispatch_get_main_queue(), ^{ [self.view updateBacking]; [self.view draw];