From 8dc66167bedd7363f8608786d4de541a11367bc4 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 31 May 2016 22:16:20 -0400 Subject: [PATCH] Made an attempt to consolidate the Objective-C++ side of things based on the incoming `CRTMachine::Machine`. --- Machines/Atari2600/Atari2600.hpp | 2 +- Machines/Electron/Electron.hpp | 2 +- .../Mac/Clock Signal/Wrappers/CSAtari2600.h | 2 - .../Mac/Clock Signal/Wrappers/CSAtari2600.mm | 18 ++----- .../Mac/Clock Signal/Wrappers/CSElectron.h | 2 - .../Mac/Clock Signal/Wrappers/CSElectron.mm | 48 ++++--------------- .../Wrappers/CSMachine+Subclassing.h | 9 ++-- .../Mac/Clock Signal/Wrappers/CSMachine.h | 2 + .../Mac/Clock Signal/Wrappers/CSMachine.mm | 38 ++++++++++++--- 9 files changed, 50 insertions(+), 73 deletions(-) diff --git a/Machines/Atari2600/Atari2600.hpp b/Machines/Atari2600/Atari2600.hpp index 1596692c4..d29cb78bc 100644 --- a/Machines/Atari2600/Atari2600.hpp +++ b/Machines/Atari2600/Atari2600.hpp @@ -35,7 +35,7 @@ class Speaker: public ::Outputs::Filter { int _shift_counters[2]; }; -class Machine: public CPU6502::Processor, CRTMachine::Machine { +class Machine: public CPU6502::Processor, public CRTMachine::Machine { public: Machine(); diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index 373d555a6..d249bac0d 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -141,7 +141,7 @@ class Speaker: public ::Outputs::Filter { @discussion An instance of Electron::Machine represents the current state of an Acorn Electron. */ -class Machine: public CPU6502::Processor, Tape::Delegate, CRTMachine::Machine { +class Machine: public CPU6502::Processor, public CRTMachine::Machine, Tape::Delegate { public: diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.h b/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.h index c0e097c52..05a0b70c3 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.h @@ -15,6 +15,4 @@ - (void)setState:(BOOL)state forDigitalInput:(Atari2600DigitalInput)digitalInput; - (void)setResetLineEnabled:(BOOL)enabled; -- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty; - @end diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm index 4dab3724c..cec8e85bf 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSAtari2600.mm @@ -49,16 +49,6 @@ struct CRTDelegate: public Outputs::CRT::Delegate { } } -- (void)runForNumberOfCycles:(int)numberOfCycles { - @synchronized(self) { - _atari2600.run_for_cycles(numberOfCycles); - } -} - -- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty { - _atari2600.get_crt()->draw_frame((unsigned int)pixelSize.width, (unsigned int)pixelSize.height, onlyIfDirty ? true : false); -} - - (void)setROM:(NSData *)rom { @synchronized(self) { _atari2600.set_rom(rom.length, (const uint8_t *)rom.bytes); @@ -79,16 +69,14 @@ struct CRTDelegate: public Outputs::CRT::Delegate { - (void)setupOutputWithAspectRatio:(float)aspectRatio { @synchronized(self) { - _atari2600.setup_output(aspectRatio); + [super setupOutputWithAspectRatio:aspectRatio]; _atari2600.get_crt()->set_delegate(&_crtDelegate); _crtDelegate.atari2600 = self; } } -- (void)closeOutput { - @synchronized(self) { - _atari2600.close_output(); - } +- (CRTMachine::Machine * const)machine { + return &_atari2600; } @end diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.h b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.h index 3b4d45ff3..04d8e51ac 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.h @@ -19,8 +19,6 @@ - (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed; - (void)clearAllKeys; -- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty; - @property (nonatomic, assign) BOOL useFastLoadingHack; @property (nonatomic, assign) BOOL useTelevisionOutput; diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm index 08a039cec..c7b82425e 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSElectron.mm @@ -16,10 +16,8 @@ Electron::Machine _electron; } -- (void)runForNumberOfCycles:(int)numberOfCycles { - @synchronized(self) { - _electron.run_for_cycles(numberOfCycles); - } +- (CRTMachine::Machine * const)machine { + return &_electron; } - (void)setOSROM:(nonnull NSData *)rom { @@ -40,10 +38,6 @@ } } -- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty { - _electron.get_crt()->draw_frame((unsigned int)pixelSize.width, (unsigned int)pixelSize.height, onlyIfDirty ? true : false); -} - - (BOOL)openUEFAtURL:(NSURL *)URL { @synchronized(self) { try { @@ -56,24 +50,13 @@ } } -- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate { +- (void)clearAllKeys { @synchronized(self) { - _electron.get_speaker()->set_output_rate(sampleRate, 256); - _electron.get_speaker()->set_delegate(delegate); - return YES; + _electron.clear_all_keys(); } } -- (void)clearAllKeys { -// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ - @synchronized(self) { - _electron.clear_all_keys(); - } -// }); -} - - (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed { -// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ @synchronized(self) { switch(key) { @@ -151,16 +134,13 @@ break; } } -// }); } - (void)setUseFastLoadingHack:(BOOL)useFastLoadingHack { -// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ - @synchronized(self) { - _useFastLoadingHack = useFastLoadingHack; - _electron.set_use_fast_tape_hack(useFastLoadingHack ? true : false); - } -// }); + @synchronized(self) { + _useFastLoadingHack = useFastLoadingHack; + _electron.set_use_fast_tape_hack(useFastLoadingHack ? true : false); + } } - (void)setUseTelevisionOutput:(BOOL)useTelevisionOutput { @@ -170,16 +150,4 @@ } } -- (void)setupOutputWithAspectRatio:(float)aspectRatio { - @synchronized(self) { - _electron.setup_output(aspectRatio); - } -} - -- (void)closeOutput { - @synchronized(self) { - _electron.close_output(); - } -} - @end diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine+Subclassing.h b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine+Subclassing.h index 96d090697..59f724bb2 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine+Subclassing.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine+Subclassing.h @@ -7,16 +7,15 @@ // #import "CSMachine.h" -#include "CRT.hpp" -#include "Speaker.hpp" +#include "CRTMachine.hpp" @interface CSMachine (Subclassing) -- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate; -- (void)speaker:(Outputs::Speaker *)speaker didCompleteSamples:(const int16_t *)samples length:(int)length; - (void)performAsync:(dispatch_block_t)action; - (void)performSync:(dispatch_block_t)action; + +- (CRTMachine::Machine * const)machine; + - (void)setupOutputWithAspectRatio:(float)aspectRatio; -- (void)closeOutput; @end diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h index 89467de11..1791b3780 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.h @@ -13,7 +13,9 @@ @interface CSMachine : NSObject - (void)runForNumberOfCycles:(int)numberOfCycles; + - (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio; +- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty; @property (nonatomic, weak) AudioQueue *audioQueue; @property (nonatomic, readonly) CSOpenGLView *view; diff --git a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm index 7c5507218..10b5b67d0 100644 --- a/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm +++ b/OSBindings/Mac/Clock Signal/Wrappers/CSMachine.mm @@ -9,6 +9,10 @@ #import "CSMachine.h" #import "CSMachine+Subclassing.h" +@interface CSMachine() +- (void)speaker:(Outputs::Speaker *)speaker didCompleteSamples:(const int16_t *)samples length:(int)length; +@end + struct SpeakerDelegate: public Outputs::Speaker::Delegate { __weak CSMachine *machine; void speaker_did_complete_samples(Outputs::Speaker *speaker, const int16_t *buffer, int buffer_size) { @@ -39,15 +43,30 @@ struct SpeakerDelegate: public Outputs::Speaker::Delegate { - (void)dealloc { [_view performWithGLContext:^{ - [self closeOutput]; + @synchronized(self) { + self.machine->close_output(); + } }]; } - (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate { - return NO; + @synchronized(self) { + Outputs::Speaker *speaker = self.machine->get_speaker(); + if(speaker) + { + speaker->set_output_rate(sampleRate, 256); + speaker->set_delegate(delegate); + return YES; + } + return NO; + } } -- (void)runForNumberOfCycles:(int)numberOfCycles {} +- (void)runForNumberOfCycles:(int)numberOfCycles { + @synchronized(self) { + self.machine->run_for_cycles(numberOfCycles); + } +} - (void)performSync:(dispatch_block_t)action { dispatch_sync(_serialDispatchQueue, action); @@ -57,10 +76,6 @@ struct SpeakerDelegate: public Outputs::Speaker::Delegate { dispatch_async(_serialDispatchQueue, action); } -- (void)setupOutputWithAspectRatio:(float)aspectRatio {} - -- (void)closeOutput {} - - (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio { _view = view; [view performWithGLContext:^{ @@ -68,4 +83,13 @@ struct SpeakerDelegate: public Outputs::Speaker::Delegate { }]; } +- (void)setupOutputWithAspectRatio:(float)aspectRatio { + self.machine->setup_output(aspectRatio); +} + +- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty { + self.machine->get_crt()->draw_frame((unsigned int)pixelSize.width, (unsigned int)pixelSize.height, onlyIfDirty ? true : false); +} + + @end