2016-01-05 04:16:37 +00:00
|
|
|
//
|
|
|
|
// CSElectron.m
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/01/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "CSElectron.h"
|
|
|
|
|
2016-06-25 20:24:52 +00:00
|
|
|
#include "Electron.hpp"
|
2016-08-28 16:43:17 +00:00
|
|
|
#include "StaticAnalyser.hpp"
|
2016-01-05 04:16:37 +00:00
|
|
|
|
2016-10-03 00:39:06 +00:00
|
|
|
#import "CSMachine+Subclassing.h"
|
|
|
|
#import "NSData+StdVector.h"
|
|
|
|
#import "NSBundle+DataResource.h"
|
|
|
|
|
2016-01-05 04:16:37 +00:00
|
|
|
@implementation CSElectron {
|
2017-08-16 19:33:40 +00:00
|
|
|
std::unique_ptr<Electron::Machine> _electron;
|
2016-01-05 04:16:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 00:39:06 +00:00
|
|
|
- (instancetype)init {
|
2017-08-27 20:36:21 +00:00
|
|
|
Electron::Machine *machine = Electron::Machine::Electron();
|
|
|
|
|
|
|
|
self = [super initWithMachine:machine];
|
2017-07-23 02:17:29 +00:00
|
|
|
if(self) {
|
2017-08-27 20:36:21 +00:00
|
|
|
_electron.reset(machine);
|
|
|
|
|
2016-10-03 00:39:06 +00:00
|
|
|
[self setOSROM:[self rom:@"os"]];
|
|
|
|
[self setBASICROM:[self rom:@"basic"]];
|
|
|
|
[self setDFSROM:[self rom:@"DFS-1770-2.20"]];
|
|
|
|
|
|
|
|
NSMutableData *adfs = [[self rom:@"ADFS-E00_1"] mutableCopy];
|
|
|
|
[adfs appendData:[self rom:@"ADFS-E00_2"]];
|
|
|
|
[self setADFSROM:adfs];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-07-23 02:17:29 +00:00
|
|
|
- (NSData *)rom:(NSString *)name {
|
2016-10-03 00:39:06 +00:00
|
|
|
return [[NSBundle mainBundle] dataForResource:name withExtension:@"rom" subdirectory:@"ROMImages/Electron"];
|
2016-08-28 16:43:17 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 00:39:06 +00:00
|
|
|
#pragma mark - ROM setting
|
|
|
|
|
2016-09-20 11:36:57 +00:00
|
|
|
- (void)setOSROM:(nonnull NSData *)rom { [self setROM:rom slot:Electron::ROMSlotOS]; }
|
|
|
|
- (void)setBASICROM:(nonnull NSData *)rom { [self setROM:rom slot:Electron::ROMSlotBASIC]; }
|
|
|
|
- (void)setADFSROM:(nonnull NSData *)rom { [self setROM:rom slot:Electron::ROMSlotADFS]; }
|
|
|
|
- (void)setDFSROM:(nonnull NSData *)rom { [self setROM:rom slot:Electron::ROMSlotDFS]; }
|
2016-01-07 04:14:36 +00:00
|
|
|
|
2016-01-13 03:34:26 +00:00
|
|
|
- (void)setROM:(nonnull NSData *)rom slot:(int)slot {
|
2016-10-03 00:39:06 +00:00
|
|
|
if(rom)
|
|
|
|
{
|
|
|
|
@synchronized(self) {
|
2017-08-16 19:33:40 +00:00
|
|
|
_electron->set_rom((Electron::ROMSlot)slot, rom.stdVector8, false);
|
2016-10-03 00:39:06 +00:00
|
|
|
}
|
2016-03-20 02:46:17 +00:00
|
|
|
}
|
2016-01-13 03:34:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-03 00:39:06 +00:00
|
|
|
#pragma mark - Keyboard Mapping
|
2016-01-18 23:06:09 +00:00
|
|
|
|
2016-06-01 02:16:20 +00:00
|
|
|
- (void)clearAllKeys {
|
2016-03-20 02:46:17 +00:00
|
|
|
@synchronized(self) {
|
2017-08-16 19:33:40 +00:00
|
|
|
_electron->clear_all_keys();
|
2016-03-20 02:46:17 +00:00
|
|
|
}
|
2016-01-14 02:03:43 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 00:48:31 +00:00
|
|
|
- (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed {
|
2016-03-20 02:46:17 +00:00
|
|
|
@synchronized(self) {
|
|
|
|
switch(key)
|
|
|
|
{
|
2017-08-16 19:33:40 +00:00
|
|
|
case VK_ANSI_0: _electron->set_key_state(Electron::Key::Key0, isPressed); break;
|
|
|
|
case VK_ANSI_1: _electron->set_key_state(Electron::Key::Key1, isPressed); break;
|
|
|
|
case VK_ANSI_2: _electron->set_key_state(Electron::Key::Key2, isPressed); break;
|
|
|
|
case VK_ANSI_3: _electron->set_key_state(Electron::Key::Key3, isPressed); break;
|
|
|
|
case VK_ANSI_4: _electron->set_key_state(Electron::Key::Key4, isPressed); break;
|
|
|
|
case VK_ANSI_5: _electron->set_key_state(Electron::Key::Key5, isPressed); break;
|
|
|
|
case VK_ANSI_6: _electron->set_key_state(Electron::Key::Key6, isPressed); break;
|
|
|
|
case VK_ANSI_7: _electron->set_key_state(Electron::Key::Key7, isPressed); break;
|
|
|
|
case VK_ANSI_8: _electron->set_key_state(Electron::Key::Key8, isPressed); break;
|
|
|
|
case VK_ANSI_9: _electron->set_key_state(Electron::Key::Key9, isPressed); break;
|
|
|
|
|
|
|
|
case VK_ANSI_Q: _electron->set_key_state(Electron::Key::KeyQ, isPressed); break;
|
|
|
|
case VK_ANSI_W: _electron->set_key_state(Electron::Key::KeyW, isPressed); break;
|
|
|
|
case VK_ANSI_E: _electron->set_key_state(Electron::Key::KeyE, isPressed); break;
|
|
|
|
case VK_ANSI_R: _electron->set_key_state(Electron::Key::KeyR, isPressed); break;
|
|
|
|
case VK_ANSI_T: _electron->set_key_state(Electron::Key::KeyT, isPressed); break;
|
|
|
|
case VK_ANSI_Y: _electron->set_key_state(Electron::Key::KeyY, isPressed); break;
|
|
|
|
case VK_ANSI_U: _electron->set_key_state(Electron::Key::KeyU, isPressed); break;
|
|
|
|
case VK_ANSI_I: _electron->set_key_state(Electron::Key::KeyI, isPressed); break;
|
|
|
|
case VK_ANSI_O: _electron->set_key_state(Electron::Key::KeyO, isPressed); break;
|
|
|
|
case VK_ANSI_P: _electron->set_key_state(Electron::Key::KeyP, isPressed); break;
|
|
|
|
case VK_ANSI_A: _electron->set_key_state(Electron::Key::KeyA, isPressed); break;
|
|
|
|
case VK_ANSI_S: _electron->set_key_state(Electron::Key::KeyS, isPressed); break;
|
|
|
|
case VK_ANSI_D: _electron->set_key_state(Electron::Key::KeyD, isPressed); break;
|
|
|
|
case VK_ANSI_F: _electron->set_key_state(Electron::Key::KeyF, isPressed); break;
|
|
|
|
case VK_ANSI_G: _electron->set_key_state(Electron::Key::KeyG, isPressed); break;
|
|
|
|
case VK_ANSI_H: _electron->set_key_state(Electron::Key::KeyH, isPressed); break;
|
|
|
|
case VK_ANSI_J: _electron->set_key_state(Electron::Key::KeyJ, isPressed); break;
|
|
|
|
case VK_ANSI_K: _electron->set_key_state(Electron::Key::KeyK, isPressed); break;
|
|
|
|
case VK_ANSI_L: _electron->set_key_state(Electron::Key::KeyL, isPressed); break;
|
|
|
|
case VK_ANSI_Z: _electron->set_key_state(Electron::Key::KeyZ, isPressed); break;
|
|
|
|
case VK_ANSI_X: _electron->set_key_state(Electron::Key::KeyX, isPressed); break;
|
|
|
|
case VK_ANSI_C: _electron->set_key_state(Electron::Key::KeyC, isPressed); break;
|
|
|
|
case VK_ANSI_V: _electron->set_key_state(Electron::Key::KeyV, isPressed); break;
|
|
|
|
case VK_ANSI_B: _electron->set_key_state(Electron::Key::KeyB, isPressed); break;
|
|
|
|
case VK_ANSI_N: _electron->set_key_state(Electron::Key::KeyN, isPressed); break;
|
|
|
|
case VK_ANSI_M: _electron->set_key_state(Electron::Key::KeyM, isPressed); break;
|
|
|
|
|
|
|
|
case VK_Space: _electron->set_key_state(Electron::Key::KeySpace, isPressed); break;
|
2016-03-21 02:48:56 +00:00
|
|
|
case VK_ANSI_Grave:
|
|
|
|
case VK_ANSI_Backslash:
|
2017-08-16 19:33:40 +00:00
|
|
|
_electron->set_key_state(Electron::Key::KeyCopy, isPressed); break;
|
|
|
|
case VK_Return: _electron->set_key_state(Electron::Key::KeyReturn, isPressed); break;
|
|
|
|
case VK_ANSI_Minus: _electron->set_key_state(Electron::Key::KeyMinus, isPressed); break;
|
2016-03-20 02:46:17 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
case VK_RightArrow: _electron->set_key_state(Electron::Key::KeyRight, isPressed); break;
|
|
|
|
case VK_LeftArrow: _electron->set_key_state(Electron::Key::KeyLeft, isPressed); break;
|
|
|
|
case VK_DownArrow: _electron->set_key_state(Electron::Key::KeyDown, isPressed); break;
|
|
|
|
case VK_UpArrow: _electron->set_key_state(Electron::Key::KeyUp, isPressed); break;
|
2016-03-20 02:46:17 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
case VK_Delete: _electron->set_key_state(Electron::Key::KeyDelete, isPressed); break;
|
|
|
|
case VK_Escape: _electron->set_key_state(Electron::Key::KeyEscape, isPressed); break;
|
2016-03-20 02:46:17 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
case VK_ANSI_Comma: _electron->set_key_state(Electron::Key::KeyComma, isPressed); break;
|
|
|
|
case VK_ANSI_Period: _electron->set_key_state(Electron::Key::KeyFullStop, isPressed); break;
|
2016-03-20 02:46:17 +00:00
|
|
|
|
2016-03-21 02:48:56 +00:00
|
|
|
case VK_ANSI_Semicolon:
|
2017-08-16 19:33:40 +00:00
|
|
|
_electron->set_key_state(Electron::Key::KeySemiColon, isPressed); break;
|
|
|
|
case VK_ANSI_Quote: _electron->set_key_state(Electron::Key::KeyColon, isPressed); break;
|
2016-03-20 02:46:17 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
case VK_ANSI_Slash: _electron->set_key_state(Electron::Key::KeySlash, isPressed); break;
|
2016-03-20 02:46:17 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
case VK_Shift: _electron->set_key_state(Electron::Key::KeyShift, isPressed); break;
|
|
|
|
case VK_Control: _electron->set_key_state(Electron::Key::KeyControl, isPressed); break;
|
2016-04-20 01:29:10 +00:00
|
|
|
case VK_Command:
|
2017-08-16 19:33:40 +00:00
|
|
|
case VK_Option: _electron->set_key_state(Electron::Key::KeyFunc, isPressed); break;
|
2016-03-20 02:46:17 +00:00
|
|
|
|
2017-08-16 19:33:40 +00:00
|
|
|
case VK_F12: _electron->set_key_state(Electron::Key::KeyBreak, isPressed); break;
|
2016-03-20 02:46:17 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// printf("%02x\n", key);
|
|
|
|
break;
|
|
|
|
}
|
2016-01-12 00:48:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-03 01:56:50 +00:00
|
|
|
- (NSString *)userDefaultsPrefix { return @"electron"; }
|
|
|
|
|
2016-10-03 00:39:06 +00:00
|
|
|
#pragma mark - Options
|
|
|
|
|
2016-03-13 21:39:53 +00:00
|
|
|
- (void)setUseFastLoadingHack:(BOOL)useFastLoadingHack {
|
2016-06-01 02:16:20 +00:00
|
|
|
@synchronized(self) {
|
|
|
|
_useFastLoadingHack = useFastLoadingHack;
|
2017-08-16 19:33:40 +00:00
|
|
|
_electron->set_use_fast_tape_hack(useFastLoadingHack ? true : false);
|
2016-06-01 02:16:20 +00:00
|
|
|
}
|
2016-03-13 21:39:53 +00:00
|
|
|
}
|
|
|
|
|
2016-04-18 12:27:58 +00:00
|
|
|
- (void)setUseTelevisionOutput:(BOOL)useTelevisionOutput {
|
|
|
|
@synchronized(self) {
|
|
|
|
_useTelevisionOutput = useTelevisionOutput;
|
2017-08-16 19:33:40 +00:00
|
|
|
_electron->get_crt()->set_output_device(useTelevisionOutput ? Outputs::CRT::Television : Outputs::CRT::Monitor);
|
2016-04-18 12:27:58 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-05 04:16:37 +00:00
|
|
|
@end
|