mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-13 07:30:21 +00:00
Revokes -[CSMachine init] and the slightly troubling create-on-demand semantics it places upon subclasses via .machine. Therefore each machine must announce its own implementation of -init.
This commit is contained in:
parent
b4c532c0d5
commit
522839143f
@ -11,7 +11,5 @@
|
|||||||
|
|
||||||
@interface CSMachine (Subclassing)
|
@interface CSMachine (Subclassing)
|
||||||
|
|
||||||
- (CRTMachine::Machine * const)machine;
|
|
||||||
- (void)setupOutputWithAspectRatio:(float)aspectRatio;
|
- (void)setupOutputWithAspectRatio:(float)aspectRatio;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -18,6 +18,15 @@
|
|||||||
|
|
||||||
@interface CSMachine : NSObject
|
@interface CSMachine : NSObject
|
||||||
|
|
||||||
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
|
/*!
|
||||||
|
Initialises an instance of CSMachine.
|
||||||
|
|
||||||
|
@param machine The pointer to an instance of @c CRTMachine::Machine* . C++ type is omitted because
|
||||||
|
this header is visible to Swift, and the designated initialiser cannot be placed into a category.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithMachine:(void *)machine NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
||||||
- (void)runForNumberOfCycles:(int)numberOfCycles;
|
- (void)runForNumberOfCycles:(int)numberOfCycles;
|
||||||
|
|
||||||
- (float)idealSamplingRateFromRange:(NSRange)range;
|
- (float)idealSamplingRateFromRange:(NSRange)range;
|
||||||
|
@ -39,14 +39,17 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
|||||||
@implementation CSMachine {
|
@implementation CSMachine {
|
||||||
SpeakerDelegate _speakerDelegate;
|
SpeakerDelegate _speakerDelegate;
|
||||||
MachineDelegate _machineDelegate;
|
MachineDelegate _machineDelegate;
|
||||||
|
CRTMachine::Machine *_machine;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)initWithMachine:(void *)machine {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if(self) {
|
if(self) {
|
||||||
|
_machine = (CRTMachine::Machine *)machine;
|
||||||
_machineDelegate.machine = self;
|
_machineDelegate.machine = self;
|
||||||
self.machine->set_delegate(&_machineDelegate);
|
|
||||||
_speakerDelegate.machine = self;
|
_speakerDelegate.machine = self;
|
||||||
|
|
||||||
|
_machine->set_delegate(&_machineDelegate);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -66,14 +69,14 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
|||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[_view performWithGLContext:^{
|
[_view performWithGLContext:^{
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
self.machine->close_output();
|
_machine->close_output();
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float)idealSamplingRateFromRange:(NSRange)range {
|
- (float)idealSamplingRateFromRange:(NSRange)range {
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
std::shared_ptr<Outputs::Speaker> speaker = self.machine->get_speaker();
|
std::shared_ptr<Outputs::Speaker> speaker = _machine->get_speaker();
|
||||||
if(speaker)
|
if(speaker)
|
||||||
{
|
{
|
||||||
return speaker->get_ideal_clock_rate_in_range((float)range.location, (float)(range.location + range.length));
|
return speaker->get_ideal_clock_rate_in_range((float)range.location, (float)(range.location + range.length));
|
||||||
@ -90,7 +93,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
|||||||
|
|
||||||
- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(float)sampleRate bufferSize:(NSUInteger)bufferSize {
|
- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(float)sampleRate bufferSize:(NSUInteger)bufferSize {
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
std::shared_ptr<Outputs::Speaker> speaker = self.machine->get_speaker();
|
std::shared_ptr<Outputs::Speaker> speaker = _machine->get_speaker();
|
||||||
if(speaker)
|
if(speaker)
|
||||||
{
|
{
|
||||||
speaker->set_output_rate(sampleRate, (int)bufferSize);
|
speaker->set_output_rate(sampleRate, (int)bufferSize);
|
||||||
@ -103,7 +106,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
|||||||
|
|
||||||
- (void)runForNumberOfCycles:(int)numberOfCycles {
|
- (void)runForNumberOfCycles:(int)numberOfCycles {
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
self.machine->run_for(Cycles(numberOfCycles));
|
_machine->run_for(Cycles(numberOfCycles));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,26 +118,26 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)setupOutputWithAspectRatio:(float)aspectRatio {
|
- (void)setupOutputWithAspectRatio:(float)aspectRatio {
|
||||||
self.machine->setup_output(aspectRatio);
|
_machine->setup_output(aspectRatio);
|
||||||
|
|
||||||
// Since OS X v10.6, Macs have had a gamma of 2.2.
|
// Since OS X v10.6, Macs have had a gamma of 2.2.
|
||||||
self.machine->get_crt()->set_output_gamma(2.2f);
|
_machine->get_crt()->set_output_gamma(2.2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty {
|
- (void)drawViewForPixelSize:(CGSize)pixelSize onlyIfDirty:(BOOL)onlyIfDirty {
|
||||||
self.machine->get_crt()->draw_frame((unsigned int)pixelSize.width, (unsigned int)pixelSize.height, onlyIfDirty ? true : false);
|
_machine->get_crt()->draw_frame((unsigned int)pixelSize.width, (unsigned int)pixelSize.height, onlyIfDirty ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double)clockRate {
|
- (double)clockRate {
|
||||||
return self.machine->get_clock_rate();
|
return _machine->get_clock_rate();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)clockIsUnlimited {
|
- (BOOL)clockIsUnlimited {
|
||||||
return self.machine->get_clock_is_unlimited() ? YES : NO;
|
return _machine->get_clock_is_unlimited() ? YES : NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)paste:(NSString *)paste {
|
- (void)paste:(NSString *)paste {
|
||||||
Utility::TypeRecipient *typeRecipient = dynamic_cast<Utility::TypeRecipient *>(self.machine);
|
Utility::TypeRecipient *typeRecipient = dynamic_cast<Utility::TypeRecipient *>(_machine);
|
||||||
if(typeRecipient)
|
if(typeRecipient)
|
||||||
typeRecipient->set_typer_for_string([paste UTF8String]);
|
typeRecipient->set_typer_for_string([paste UTF8String]);
|
||||||
}
|
}
|
||||||
@ -142,7 +145,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
|||||||
- (void)applyTarget:(const StaticAnalyser::Target &)target {
|
- (void)applyTarget:(const StaticAnalyser::Target &)target {
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
ConfigurationTarget::Machine *const configurationTarget =
|
ConfigurationTarget::Machine *const configurationTarget =
|
||||||
dynamic_cast<ConfigurationTarget::Machine *>(self.machine);
|
dynamic_cast<ConfigurationTarget::Machine *>(_machine);
|
||||||
if(configurationTarget) configurationTarget->configure_as_target(target);
|
if(configurationTarget) configurationTarget->configure_as_target(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +153,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
|||||||
- (void)applyMedia:(const StaticAnalyser::Media &)media {
|
- (void)applyMedia:(const StaticAnalyser::Media &)media {
|
||||||
@synchronized(self) {
|
@synchronized(self) {
|
||||||
ConfigurationTarget::Machine *const configurationTarget =
|
ConfigurationTarget::Machine *const configurationTarget =
|
||||||
dynamic_cast<ConfigurationTarget::Machine *>(self.machine);
|
dynamic_cast<ConfigurationTarget::Machine *>(_machine);
|
||||||
if(configurationTarget) configurationTarget->insert_media(media);
|
if(configurationTarget) configurationTarget->insert_media(media);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,4 +11,6 @@
|
|||||||
|
|
||||||
@interface CSAmstradCPC : CSMachine <CSKeyboardMachine>
|
@interface CSAmstradCPC : CSMachine <CSKeyboardMachine>
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -18,17 +18,13 @@
|
|||||||
std::unique_ptr<AmstradCPC::Machine> _amstradCPC;
|
std::unique_ptr<AmstradCPC::Machine> _amstradCPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CRTMachine::Machine * const)machine {
|
|
||||||
if(!_amstradCPC) {
|
|
||||||
_amstradCPC.reset(AmstradCPC::Machine::AmstradCPC());
|
|
||||||
}
|
|
||||||
return _amstradCPC.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
self = [super init];
|
AmstradCPC::Machine *machine = AmstradCPC::Machine::AmstradCPC();
|
||||||
|
|
||||||
|
self = [super initWithMachine:machine];
|
||||||
if(self) {
|
if(self) {
|
||||||
[self machine];
|
_amstradCPC.reset(machine);
|
||||||
|
|
||||||
NSDictionary *roms = @{
|
NSDictionary *roms = @{
|
||||||
@(AmstradCPC::ROMType::OS464) : @"os464",
|
@(AmstradCPC::ROMType::OS464) : @"os464",
|
||||||
@(AmstradCPC::ROMType::OS664) : @"os664",
|
@(AmstradCPC::ROMType::OS664) : @"os664",
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
@interface CSAtari2600 : CSMachine <CSJoystickMachine>
|
@interface CSAtari2600 : CSMachine <CSJoystickMachine>
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
|
||||||
- (void)setResetLineEnabled:(BOOL)enabled;
|
- (void)setResetLineEnabled:(BOOL)enabled;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL colourButton;
|
@property (nonatomic, assign) BOOL colourButton;
|
||||||
|
@ -15,11 +15,13 @@
|
|||||||
std::unique_ptr<Atari2600::Machine> _atari2600;
|
std::unique_ptr<Atari2600::Machine> _atari2600;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CRTMachine::Machine * const)machine {
|
- (instancetype)init {
|
||||||
if(!_atari2600) {
|
Atari2600::Machine *machine = Atari2600::Machine::Atari2600();
|
||||||
_atari2600.reset(Atari2600::Machine::Atari2600());
|
self = [super initWithMachine:machine];
|
||||||
|
if(self) {
|
||||||
|
_atari2600.reset(machine);
|
||||||
}
|
}
|
||||||
return _atari2600.get();
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDirection:(CSJoystickDirection)direction onPad:(NSUInteger)pad isPressed:(BOOL)isPressed {
|
- (void)setDirection:(CSJoystickDirection)direction onPad:(NSUInteger)pad isPressed:(BOOL)isPressed {
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
@interface CSElectron : CSMachine <CSKeyboardMachine, CSFastLoading>
|
@interface CSElectron : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
||||||
@property (nonatomic, assign) BOOL useTelevisionOutput;
|
@property (nonatomic, assign) BOOL useTelevisionOutput;
|
||||||
|
|
||||||
|
@ -19,16 +19,13 @@
|
|||||||
std::unique_ptr<Electron::Machine> _electron;
|
std::unique_ptr<Electron::Machine> _electron;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CRTMachine::Machine * const)machine {
|
|
||||||
if(!_electron) {
|
|
||||||
_electron.reset(Electron::Machine::Electron());
|
|
||||||
}
|
|
||||||
return _electron.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
self = [super init];
|
Electron::Machine *machine = Electron::Machine::Electron();
|
||||||
|
|
||||||
|
self = [super initWithMachine:machine];
|
||||||
if(self) {
|
if(self) {
|
||||||
|
_electron.reset(machine);
|
||||||
|
|
||||||
[self setOSROM:[self rom:@"os"]];
|
[self setOSROM:[self rom:@"os"]];
|
||||||
[self setBASICROM:[self rom:@"basic"]];
|
[self setBASICROM:[self rom:@"basic"]];
|
||||||
[self setDFSROM:[self rom:@"DFS-1770-2.20"]];
|
[self setDFSROM:[self rom:@"DFS-1770-2.20"]];
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
@interface CSOric : CSMachine <CSKeyboardMachine, CSFastLoading>
|
@interface CSOric : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
||||||
@property (nonatomic, assign) BOOL useCompositeOutput;
|
@property (nonatomic, assign) BOOL useCompositeOutput;
|
||||||
|
|
||||||
|
@ -19,16 +19,13 @@
|
|||||||
std::unique_ptr<Oric::Machine> _oric;
|
std::unique_ptr<Oric::Machine> _oric;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CRTMachine::Machine * const)machine {
|
|
||||||
if(!_oric) {
|
|
||||||
_oric.reset(Oric::Machine::Oric());
|
|
||||||
}
|
|
||||||
return _oric.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
self = [super init];
|
Oric::Machine *machine = Oric::Machine::Oric();
|
||||||
|
|
||||||
|
self = [super initWithMachine:machine];
|
||||||
if(self) {
|
if(self) {
|
||||||
|
_oric.reset(machine);
|
||||||
|
|
||||||
NSData *basic10 = [self rom:@"basic10"];
|
NSData *basic10 = [self rom:@"basic10"];
|
||||||
NSData *basic11 = [self rom:@"basic11"];
|
NSData *basic11 = [self rom:@"basic11"];
|
||||||
NSData *colour = [self rom:@"colour"];
|
NSData *colour = [self rom:@"colour"];
|
||||||
|
@ -28,6 +28,8 @@ typedef NS_ENUM(NSInteger, CSVic20MemorySize)
|
|||||||
|
|
||||||
@interface CSVic20 : CSMachine <CSKeyboardMachine, CSFastLoading>
|
@interface CSVic20 : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
||||||
@property (nonatomic, assign) CSVic20Country country;
|
@property (nonatomic, assign) CSVic20Country country;
|
||||||
@property (nonatomic, assign) CSVic20MemorySize memorySize;
|
@property (nonatomic, assign) CSVic20MemorySize memorySize;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "G64.hpp"
|
#include "G64.hpp"
|
||||||
#include "D64.hpp"
|
#include "D64.hpp"
|
||||||
|
|
||||||
|
#import "CSmachine+Subclassing.h"
|
||||||
#import "NSBundle+DataResource.h"
|
#import "NSBundle+DataResource.h"
|
||||||
|
|
||||||
using namespace Commodore::Vic20;
|
using namespace Commodore::Vic20;
|
||||||
@ -22,17 +23,14 @@ using namespace Commodore::Vic20;
|
|||||||
BOOL _joystickMode;
|
BOOL _joystickMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CRTMachine::Machine * const)machine {
|
|
||||||
if(!_vic20) {
|
|
||||||
_vic20.reset(Commodore::Vic20::Machine::Vic20());
|
|
||||||
}
|
|
||||||
return _vic20.get();
|
|
||||||
}
|
|
||||||
- (NSString *)userDefaultsPrefix { return @"vic20"; }
|
- (NSString *)userDefaultsPrefix { return @"vic20"; }
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
self = [super init];
|
Machine *machine = Commodore::Vic20::Machine::Vic20();
|
||||||
|
|
||||||
|
self = [super initWithMachine:machine];
|
||||||
if(self) {
|
if(self) {
|
||||||
|
_vic20.reset(machine);
|
||||||
[self setDriveROM:[[NSBundle mainBundle] dataForResource:@"1540" withExtension:@"bin" subdirectory:@"ROMImages/Commodore1540"]];
|
[self setDriveROM:[[NSBundle mainBundle] dataForResource:@"1540" withExtension:@"bin" subdirectory:@"ROMImages/Commodore1540"]];
|
||||||
[self setBASICROM:[self rom:@"basic"]];
|
[self setBASICROM:[self rom:@"basic"]];
|
||||||
[self setCountry:CSVic20CountryEuropean];
|
[self setCountry:CSVic20CountryEuropean];
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
@interface CSZX8081 : CSMachine <CSKeyboardMachine, CSFastLoading>
|
@interface CSZX8081 : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL useAutomaticTapeMotorControl;
|
@property (nonatomic, assign) BOOL useAutomaticTapeMotorControl;
|
||||||
|
@ -18,16 +18,12 @@
|
|||||||
std::unique_ptr<ZX8081::Machine> _zx8081;
|
std::unique_ptr<ZX8081::Machine> _zx8081;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CRTMachine::Machine * const)machine {
|
|
||||||
if(!_zx8081) {
|
|
||||||
_zx8081.reset(ZX8081::Machine::ZX8081());
|
|
||||||
}
|
|
||||||
return _zx8081.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
self = [super init];
|
ZX8081::Machine *machine = ZX8081::Machine::ZX8081();
|
||||||
|
|
||||||
|
self = [super initWithMachine:machine];
|
||||||
if(self) {
|
if(self) {
|
||||||
|
_zx8081.reset(machine);
|
||||||
_zx8081->set_rom(ZX8081::ROMType::ZX80, [self rom:@"zx80"].stdVector8);
|
_zx8081->set_rom(ZX8081::ROMType::ZX80, [self rom:@"zx80"].stdVector8);
|
||||||
_zx8081->set_rom(ZX8081::ROMType::ZX81, [self rom:@"zx81"].stdVector8);
|
_zx8081->set_rom(ZX8081::ROMType::ZX81, [self rom:@"zx81"].stdVector8);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user