mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-23 03:32:32 +00:00
Merge pull request #226 from TomHarte/TargetAwareness
Substantially rewires Mac-side target selection and as proof-of-concept adapts the generic-side ZX80 to instantiate without wait line support
This commit is contained in:
commit
3f22a71276
@ -29,7 +29,7 @@ namespace {
|
||||
|
||||
namespace ZX8081 {
|
||||
|
||||
class ConcreteMachine:
|
||||
template<bool is_zx81> class ConcreteMachine:
|
||||
public Utility::TypeRecipient,
|
||||
public CPU::Z80::BusHandler,
|
||||
public Machine {
|
||||
@ -332,7 +332,7 @@ class ConcreteMachine:
|
||||
HalfCycles get_typer_frequency() override final { return Cycles(390000); }
|
||||
|
||||
private:
|
||||
CPU::Z80::Processor<ConcreteMachine, false, true> z80_;
|
||||
CPU::Z80::Processor<ConcreteMachine, false, is_zx81> z80_;
|
||||
|
||||
std::shared_ptr<Video> video_;
|
||||
std::vector<uint8_t> zx81_rom_, zx80_rom_;
|
||||
@ -388,9 +388,13 @@ class ConcreteMachine:
|
||||
|
||||
using namespace ZX8081;
|
||||
|
||||
// See header; constructs and returns an instance of the ZX80/81.
|
||||
Machine *Machine::ZX8081() {
|
||||
return new ZX8081::ConcreteMachine;
|
||||
// See header; constructs and returns an instance of the ZX80 or 81.
|
||||
Machine *Machine::ZX8081(const StaticAnalyser::Target &target_hint) {
|
||||
// Instantiate the correct type of machine.
|
||||
if(target_hint.zx8081.isZX81)
|
||||
return new ZX8081::ConcreteMachine<true>();
|
||||
else
|
||||
return new ZX8081::ConcreteMachine<false>();
|
||||
}
|
||||
|
||||
Machine::~Machine() {}
|
||||
|
@ -38,7 +38,7 @@ class Machine:
|
||||
public ConfigurationTarget::Machine,
|
||||
public KeyboardMachine::Machine {
|
||||
public:
|
||||
static Machine *ZX8081();
|
||||
static Machine *ZX8081(const StaticAnalyser::Target &target_hint);
|
||||
virtual ~Machine();
|
||||
|
||||
virtual void set_rom(ROMType type, std::vector<uint8_t> data) = 0;
|
||||
|
@ -1061,6 +1061,7 @@
|
||||
4BF1354A1D6D2C300054B2EA /* StaticAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StaticAnalyser.cpp; path = ../../StaticAnalyser/StaticAnalyser.cpp; sourceTree = "<group>"; };
|
||||
4BF1354B1D6D2C300054B2EA /* StaticAnalyser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = StaticAnalyser.hpp; path = ../../StaticAnalyser/StaticAnalyser.hpp; sourceTree = "<group>"; };
|
||||
4BF4A2D91F534DB300B171F4 /* TargetPlatforms.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = TargetPlatforms.hpp; sourceTree = "<group>"; };
|
||||
4BF4A2DA1F5365C600B171F4 /* CSZX8081+Instantiation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CSZX8081+Instantiation.h"; sourceTree = "<group>"; };
|
||||
4BF6606A1F281573002CB053 /* ClockReceiver.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ClockReceiver.hpp; sourceTree = "<group>"; };
|
||||
4BF8295B1D8F048B001BAE39 /* MFM.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MFM.cpp; path = Encodings/MFM.cpp; sourceTree = "<group>"; };
|
||||
4BF8295C1D8F048B001BAE39 /* MFM.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = MFM.hpp; path = Encodings/MFM.hpp; sourceTree = "<group>"; };
|
||||
@ -1238,6 +1239,7 @@
|
||||
4BCF1FA61DADC5250039D2E7 /* CSOric.h */,
|
||||
4B2A539D1D117D36003C6002 /* CSVic20.h */,
|
||||
4B14978D1EE4B4D200CE2596 /* CSZX8081.h */,
|
||||
4BF4A2DA1F5365C600B171F4 /* CSZX8081+Instantiation.h */,
|
||||
4B38F34B1F2EC3CA00D9235D /* CSAmstradCPC.mm */,
|
||||
4B2A539A1D117D36003C6002 /* CSAtari2600.mm */,
|
||||
4B2A539C1D117D36003C6002 /* CSElectron.mm */,
|
||||
|
@ -11,7 +11,5 @@
|
||||
|
||||
@interface CSMachine (Subclassing)
|
||||
|
||||
- (CRTMachine::Machine * const)machine;
|
||||
- (void)setupOutputWithAspectRatio:(float)aspectRatio;
|
||||
|
||||
@end
|
||||
|
@ -18,6 +18,15 @@
|
||||
|
||||
@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;
|
||||
|
||||
- (float)idealSamplingRateFromRange:(NSRange)range;
|
||||
|
@ -39,14 +39,17 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
||||
@implementation CSMachine {
|
||||
SpeakerDelegate _speakerDelegate;
|
||||
MachineDelegate _machineDelegate;
|
||||
CRTMachine::Machine *_machine;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
- (instancetype)initWithMachine:(void *)machine {
|
||||
self = [super init];
|
||||
if(self) {
|
||||
_machine = (CRTMachine::Machine *)machine;
|
||||
_machineDelegate.machine = self;
|
||||
self.machine->set_delegate(&_machineDelegate);
|
||||
_speakerDelegate.machine = self;
|
||||
|
||||
_machine->set_delegate(&_machineDelegate);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -66,14 +69,14 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
||||
- (void)dealloc {
|
||||
[_view performWithGLContext:^{
|
||||
@synchronized(self) {
|
||||
self.machine->close_output();
|
||||
_machine->close_output();
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (float)idealSamplingRateFromRange:(NSRange)range {
|
||||
@synchronized(self) {
|
||||
std::shared_ptr<Outputs::Speaker> speaker = self.machine->get_speaker();
|
||||
std::shared_ptr<Outputs::Speaker> speaker = _machine->get_speaker();
|
||||
if(speaker)
|
||||
{
|
||||
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 {
|
||||
@synchronized(self) {
|
||||
std::shared_ptr<Outputs::Speaker> speaker = self.machine->get_speaker();
|
||||
std::shared_ptr<Outputs::Speaker> speaker = _machine->get_speaker();
|
||||
if(speaker)
|
||||
{
|
||||
speaker->set_output_rate(sampleRate, (int)bufferSize);
|
||||
@ -103,7 +106,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
||||
|
||||
- (void)runForNumberOfCycles:(int)numberOfCycles {
|
||||
@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 {
|
||||
self.machine->setup_output(aspectRatio);
|
||||
_machine->setup_output(aspectRatio);
|
||||
|
||||
// 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 {
|
||||
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 {
|
||||
return self.machine->get_clock_rate();
|
||||
return _machine->get_clock_rate();
|
||||
}
|
||||
|
||||
- (BOOL)clockIsUnlimited {
|
||||
return self.machine->get_clock_is_unlimited() ? YES : NO;
|
||||
return _machine->get_clock_is_unlimited() ? YES : NO;
|
||||
}
|
||||
|
||||
- (void)paste:(NSString *)paste {
|
||||
Utility::TypeRecipient *typeRecipient = dynamic_cast<Utility::TypeRecipient *>(self.machine);
|
||||
Utility::TypeRecipient *typeRecipient = dynamic_cast<Utility::TypeRecipient *>(_machine);
|
||||
if(typeRecipient)
|
||||
typeRecipient->set_typer_for_string([paste UTF8String]);
|
||||
}
|
||||
@ -142,7 +145,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
||||
- (void)applyTarget:(const StaticAnalyser::Target &)target {
|
||||
@synchronized(self) {
|
||||
ConfigurationTarget::Machine *const configurationTarget =
|
||||
dynamic_cast<ConfigurationTarget::Machine *>(self.machine);
|
||||
dynamic_cast<ConfigurationTarget::Machine *>(_machine);
|
||||
if(configurationTarget) configurationTarget->configure_as_target(target);
|
||||
}
|
||||
}
|
||||
@ -150,7 +153,7 @@ struct MachineDelegate: CRTMachine::Machine::Delegate {
|
||||
- (void)applyMedia:(const StaticAnalyser::Media &)media {
|
||||
@synchronized(self) {
|
||||
ConfigurationTarget::Machine *const configurationTarget =
|
||||
dynamic_cast<ConfigurationTarget::Machine *>(self.machine);
|
||||
dynamic_cast<ConfigurationTarget::Machine *>(_machine);
|
||||
if(configurationTarget) configurationTarget->insert_media(media);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#import "CSElectron.h"
|
||||
#import "CSOric.h"
|
||||
#import "CSVic20.h"
|
||||
#import "CSZX8081.h"
|
||||
#import "CSZX8081+Instantiation.h"
|
||||
|
||||
#import "Clock_Signal-Swift.h"
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
case StaticAnalyser::Target::Electron: return [[CSElectron alloc] init];
|
||||
case StaticAnalyser::Target::Oric: return [[CSOric alloc] init];
|
||||
case StaticAnalyser::Target::Vic20: return [[CSVic20 alloc] init];
|
||||
case StaticAnalyser::Target::ZX8081: return [[CSZX8081 alloc] init];
|
||||
case StaticAnalyser::Target::ZX8081: return [[CSZX8081 alloc] initWithIntendedTarget:_target];
|
||||
default: return nil;
|
||||
}
|
||||
}
|
||||
|
@ -11,4 +11,6 @@
|
||||
|
||||
@interface CSAmstradCPC : CSMachine <CSKeyboardMachine>
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
@end
|
||||
|
@ -18,17 +18,13 @@
|
||||
std::unique_ptr<AmstradCPC::Machine> _amstradCPC;
|
||||
}
|
||||
|
||||
- (CRTMachine::Machine * const)machine {
|
||||
if(!_amstradCPC) {
|
||||
_amstradCPC.reset(AmstradCPC::Machine::AmstradCPC());
|
||||
}
|
||||
return _amstradCPC.get();
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
AmstradCPC::Machine *machine = AmstradCPC::Machine::AmstradCPC();
|
||||
|
||||
self = [super initWithMachine:machine];
|
||||
if(self) {
|
||||
[self machine];
|
||||
_amstradCPC.reset(machine);
|
||||
|
||||
NSDictionary *roms = @{
|
||||
@(AmstradCPC::ROMType::OS464) : @"os464",
|
||||
@(AmstradCPC::ROMType::OS664) : @"os664",
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
@interface CSAtari2600 : CSMachine <CSJoystickMachine>
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
- (void)setResetLineEnabled:(BOOL)enabled;
|
||||
|
||||
@property (nonatomic, assign) BOOL colourButton;
|
||||
|
@ -15,11 +15,13 @@
|
||||
std::unique_ptr<Atari2600::Machine> _atari2600;
|
||||
}
|
||||
|
||||
- (CRTMachine::Machine * const)machine {
|
||||
if(!_atari2600) {
|
||||
_atari2600.reset(Atari2600::Machine::Atari2600());
|
||||
- (instancetype)init {
|
||||
Atari2600::Machine *machine = 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 {
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
@interface CSElectron : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
||||
@property (nonatomic, assign) BOOL useTelevisionOutput;
|
||||
|
||||
|
@ -19,16 +19,13 @@
|
||||
std::unique_ptr<Electron::Machine> _electron;
|
||||
}
|
||||
|
||||
- (CRTMachine::Machine * const)machine {
|
||||
if(!_electron) {
|
||||
_electron.reset(Electron::Machine::Electron());
|
||||
}
|
||||
return _electron.get();
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
Electron::Machine *machine = Electron::Machine::Electron();
|
||||
|
||||
self = [super initWithMachine:machine];
|
||||
if(self) {
|
||||
_electron.reset(machine);
|
||||
|
||||
[self setOSROM:[self rom:@"os"]];
|
||||
[self setBASICROM:[self rom:@"basic"]];
|
||||
[self setDFSROM:[self rom:@"DFS-1770-2.20"]];
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
@interface CSOric : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
||||
@property (nonatomic, assign) BOOL useCompositeOutput;
|
||||
|
||||
|
@ -19,16 +19,13 @@
|
||||
std::unique_ptr<Oric::Machine> _oric;
|
||||
}
|
||||
|
||||
- (CRTMachine::Machine * const)machine {
|
||||
if(!_oric) {
|
||||
_oric.reset(Oric::Machine::Oric());
|
||||
}
|
||||
return _oric.get();
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
Oric::Machine *machine = Oric::Machine::Oric();
|
||||
|
||||
self = [super initWithMachine:machine];
|
||||
if(self) {
|
||||
_oric.reset(machine);
|
||||
|
||||
NSData *basic10 = [self rom:@"basic10"];
|
||||
NSData *basic11 = [self rom:@"basic11"];
|
||||
NSData *colour = [self rom:@"colour"];
|
||||
|
@ -28,6 +28,8 @@ typedef NS_ENUM(NSInteger, CSVic20MemorySize)
|
||||
|
||||
@interface CSVic20 : CSMachine <CSKeyboardMachine, CSFastLoading>
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
@property (nonatomic, assign) BOOL useFastLoadingHack;
|
||||
@property (nonatomic, assign) CSVic20Country country;
|
||||
@property (nonatomic, assign) CSVic20MemorySize memorySize;
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "G64.hpp"
|
||||
#include "D64.hpp"
|
||||
|
||||
#import "CSmachine+Subclassing.h"
|
||||
#import "NSBundle+DataResource.h"
|
||||
|
||||
using namespace Commodore::Vic20;
|
||||
@ -22,17 +23,14 @@ using namespace Commodore::Vic20;
|
||||
BOOL _joystickMode;
|
||||
}
|
||||
|
||||
- (CRTMachine::Machine * const)machine {
|
||||
if(!_vic20) {
|
||||
_vic20.reset(Commodore::Vic20::Machine::Vic20());
|
||||
}
|
||||
return _vic20.get();
|
||||
}
|
||||
- (NSString *)userDefaultsPrefix { return @"vic20"; }
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
Machine *machine = Commodore::Vic20::Machine::Vic20();
|
||||
|
||||
self = [super initWithMachine:machine];
|
||||
if(self) {
|
||||
_vic20.reset(machine);
|
||||
[self setDriveROM:[[NSBundle mainBundle] dataForResource:@"1540" withExtension:@"bin" subdirectory:@"ROMImages/Commodore1540"]];
|
||||
[self setBASICROM:[self rom:@"basic"]];
|
||||
[self setCountry:CSVic20CountryEuropean];
|
||||
|
@ -0,0 +1,16 @@
|
||||
//
|
||||
// CSZX8081+Instantiation.h
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 27/08/2017.
|
||||
// Copyright © 2017 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "StaticAnalyser.hpp"
|
||||
#import "CSZX8081.h"
|
||||
|
||||
@interface CSZX8081 (Instantiation)
|
||||
|
||||
- (instancetype)initWithIntendedTarget:(const StaticAnalyser::Target &)target;
|
||||
|
||||
@end
|
@ -18,16 +18,12 @@
|
||||
std::unique_ptr<ZX8081::Machine> _zx8081;
|
||||
}
|
||||
|
||||
- (CRTMachine::Machine * const)machine {
|
||||
if(!_zx8081) {
|
||||
_zx8081.reset(ZX8081::Machine::ZX8081());
|
||||
}
|
||||
return _zx8081.get();
|
||||
}
|
||||
- (instancetype)initWithIntendedTarget:(const StaticAnalyser::Target &)target {
|
||||
ZX8081::Machine *machine = ZX8081::Machine::ZX8081(target);
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
self = [super initWithMachine:machine];
|
||||
if(self) {
|
||||
_zx8081.reset(machine);
|
||||
_zx8081->set_rom(ZX8081::ROMType::ZX80, [self rom:@"zx80"].stdVector8);
|
||||
_zx8081->set_rom(ZX8081::ROMType::ZX81, [self rom:@"zx81"].stdVector8);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user