1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-15 14:27:29 +00:00

Made an attempt to consolidate the Objective-C++ side of things based on the incoming CRTMachine::Machine.

This commit is contained in:
Thomas Harte
2016-05-31 22:16:20 -04:00
parent 5c4f35e13f
commit 8dc66167be
9 changed files with 50 additions and 73 deletions

View File

@@ -35,7 +35,7 @@ class Speaker: public ::Outputs::Filter<Speaker> {
int _shift_counters[2]; int _shift_counters[2];
}; };
class Machine: public CPU6502::Processor<Machine>, CRTMachine::Machine { class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine {
public: public:
Machine(); Machine();

View File

@@ -141,7 +141,7 @@ class Speaker: public ::Outputs::Filter<Speaker> {
@discussion An instance of Electron::Machine represents the current state of an @discussion An instance of Electron::Machine represents the current state of an
Acorn Electron. Acorn Electron.
*/ */
class Machine: public CPU6502::Processor<Machine>, Tape::Delegate, CRTMachine::Machine { class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine, Tape::Delegate {
public: public:

View File

@@ -15,6 +15,4 @@
- (void)setState:(BOOL)state forDigitalInput:(Atari2600DigitalInput)digitalInput; - (void)setState:(BOOL)state forDigitalInput:(Atari2600DigitalInput)digitalInput;
- (void)setResetLineEnabled:(BOOL)enabled; - (void)setResetLineEnabled:(BOOL)enabled;
- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty;
@end @end

View File

@@ -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 { - (void)setROM:(NSData *)rom {
@synchronized(self) { @synchronized(self) {
_atari2600.set_rom(rom.length, (const uint8_t *)rom.bytes); _atari2600.set_rom(rom.length, (const uint8_t *)rom.bytes);
@@ -79,16 +69,14 @@ struct CRTDelegate: public Outputs::CRT::Delegate {
- (void)setupOutputWithAspectRatio:(float)aspectRatio { - (void)setupOutputWithAspectRatio:(float)aspectRatio {
@synchronized(self) { @synchronized(self) {
_atari2600.setup_output(aspectRatio); [super setupOutputWithAspectRatio:aspectRatio];
_atari2600.get_crt()->set_delegate(&_crtDelegate); _atari2600.get_crt()->set_delegate(&_crtDelegate);
_crtDelegate.atari2600 = self; _crtDelegate.atari2600 = self;
} }
} }
- (void)closeOutput { - (CRTMachine::Machine * const)machine {
@synchronized(self) { return &_atari2600;
_atari2600.close_output();
}
} }
@end @end

View File

@@ -19,8 +19,6 @@
- (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed; - (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed;
- (void)clearAllKeys; - (void)clearAllKeys;
- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty;
@property (nonatomic, assign) BOOL useFastLoadingHack; @property (nonatomic, assign) BOOL useFastLoadingHack;
@property (nonatomic, assign) BOOL useTelevisionOutput; @property (nonatomic, assign) BOOL useTelevisionOutput;

View File

@@ -16,10 +16,8 @@
Electron::Machine _electron; Electron::Machine _electron;
} }
- (void)runForNumberOfCycles:(int)numberOfCycles { - (CRTMachine::Machine * const)machine {
@synchronized(self) { return &_electron;
_electron.run_for_cycles(numberOfCycles);
}
} }
- (void)setOSROM:(nonnull NSData *)rom { - (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 { - (BOOL)openUEFAtURL:(NSURL *)URL {
@synchronized(self) { @synchronized(self) {
try { try {
@@ -56,24 +50,13 @@
} }
} }
- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate {
@synchronized(self) {
_electron.get_speaker()->set_output_rate(sampleRate, 256);
_electron.get_speaker()->set_delegate(delegate);
return YES;
}
}
- (void)clearAllKeys { - (void)clearAllKeys {
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
@synchronized(self) { @synchronized(self) {
_electron.clear_all_keys(); _electron.clear_all_keys();
} }
// });
} }
- (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed { - (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed {
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
@synchronized(self) { @synchronized(self) {
switch(key) switch(key)
{ {
@@ -151,16 +134,13 @@
break; break;
} }
} }
// });
} }
- (void)setUseFastLoadingHack:(BOOL)useFastLoadingHack { - (void)setUseFastLoadingHack:(BOOL)useFastLoadingHack {
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
@synchronized(self) { @synchronized(self) {
_useFastLoadingHack = useFastLoadingHack; _useFastLoadingHack = useFastLoadingHack;
_electron.set_use_fast_tape_hack(useFastLoadingHack ? true : false); _electron.set_use_fast_tape_hack(useFastLoadingHack ? true : false);
} }
// });
} }
- (void)setUseTelevisionOutput:(BOOL)useTelevisionOutput { - (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 @end

View File

@@ -7,16 +7,15 @@
// //
#import "CSMachine.h" #import "CSMachine.h"
#include "CRT.hpp" #include "CRTMachine.hpp"
#include "Speaker.hpp"
@interface CSMachine (Subclassing) @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)performAsync:(dispatch_block_t)action;
- (void)performSync:(dispatch_block_t)action; - (void)performSync:(dispatch_block_t)action;
- (CRTMachine::Machine * const)machine;
- (void)setupOutputWithAspectRatio:(float)aspectRatio; - (void)setupOutputWithAspectRatio:(float)aspectRatio;
- (void)closeOutput;
@end @end

View File

@@ -13,7 +13,9 @@
@interface CSMachine : NSObject @interface CSMachine : NSObject
- (void)runForNumberOfCycles:(int)numberOfCycles; - (void)runForNumberOfCycles:(int)numberOfCycles;
- (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio; - (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio;
- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty;
@property (nonatomic, weak) AudioQueue *audioQueue; @property (nonatomic, weak) AudioQueue *audioQueue;
@property (nonatomic, readonly) CSOpenGLView *view; @property (nonatomic, readonly) CSOpenGLView *view;

View File

@@ -9,6 +9,10 @@
#import "CSMachine.h" #import "CSMachine.h"
#import "CSMachine+Subclassing.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 { struct SpeakerDelegate: public Outputs::Speaker::Delegate {
__weak CSMachine *machine; __weak CSMachine *machine;
void speaker_did_complete_samples(Outputs::Speaker *speaker, const int16_t *buffer, int buffer_size) { 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 { - (void)dealloc {
[_view performWithGLContext:^{ [_view performWithGLContext:^{
[self closeOutput]; @synchronized(self) {
self.machine->close_output();
}
}]; }];
} }
- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate { - (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate {
@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; return NO;
} }
}
- (void)runForNumberOfCycles:(int)numberOfCycles {} - (void)runForNumberOfCycles:(int)numberOfCycles {
@synchronized(self) {
self.machine->run_for_cycles(numberOfCycles);
}
}
- (void)performSync:(dispatch_block_t)action { - (void)performSync:(dispatch_block_t)action {
dispatch_sync(_serialDispatchQueue, action); dispatch_sync(_serialDispatchQueue, action);
@@ -57,10 +76,6 @@ struct SpeakerDelegate: public Outputs::Speaker::Delegate {
dispatch_async(_serialDispatchQueue, action); dispatch_async(_serialDispatchQueue, action);
} }
- (void)setupOutputWithAspectRatio:(float)aspectRatio {}
- (void)closeOutput {}
- (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio { - (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio {
_view = view; _view = view;
[view performWithGLContext:^{ [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 @end