mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-23 03:32:32 +00:00
Made an attempt to consolidate the Objective-C++ side of things based on the incoming CRTMachine::Machine
.
This commit is contained in:
parent
5c4f35e13f
commit
8dc66167be
@ -35,7 +35,7 @@ class Speaker: public ::Outputs::Filter<Speaker> {
|
||||
int _shift_counters[2];
|
||||
};
|
||||
|
||||
class Machine: public CPU6502::Processor<Machine>, CRTMachine::Machine {
|
||||
class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine {
|
||||
|
||||
public:
|
||||
Machine();
|
||||
|
@ -141,7 +141,7 @@ class Speaker: public ::Outputs::Filter<Speaker> {
|
||||
@discussion An instance of Electron::Machine represents the current state of an
|
||||
Acorn Electron.
|
||||
*/
|
||||
class Machine: public CPU6502::Processor<Machine>, Tape::Delegate, CRTMachine::Machine {
|
||||
class Machine: public CPU6502::Processor<Machine>, public CRTMachine::Machine, Tape::Delegate {
|
||||
|
||||
public:
|
||||
|
||||
|
@ -15,6 +15,4 @@
|
||||
- (void)setState:(BOOL)state forDigitalInput:(Atari2600DigitalInput)digitalInput;
|
||||
- (void)setResetLineEnabled:(BOOL)enabled;
|
||||
|
||||
- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty;
|
||||
|
||||
@end
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user