1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-27 01:31:42 +00:00

Adds a third keyboard input mode, which maps to posting things as a typer.

This commit is contained in:
Thomas Harte 2020-02-29 18:17:39 -05:00
parent 8a5c4e384a
commit 4572c86f0f
3 changed files with 20 additions and 8 deletions

View File

@ -532,7 +532,7 @@ class MachineDocument:
// MARK: Joystick-via-the-keyboard selection
@IBAction func useKeyboardAsKeyboard(_ sender: NSMenuItem?) {
machine.inputMode = .keyboard
machine.inputMode = .keyboardPhysical
}
@IBAction func useKeyboardAsJoystick(_ sender: NSMenuItem?) {
@ -551,7 +551,7 @@ class MachineDocument:
return false
}
menuItem.state = machine.inputMode == .keyboard ? .on : .off
menuItem.state = machine.inputMode == .keyboardPhysical ? .on : .off
return true
case #selector(self.useKeyboardAsJoystick):

View File

@ -28,8 +28,9 @@ typedef NS_ENUM(NSInteger, CSMachineVideoSignal) {
};
typedef NS_ENUM(NSInteger, CSMachineKeyboardInputMode) {
CSMachineKeyboardInputModeKeyboard,
CSMachineKeyboardInputModeJoystick
CSMachineKeyboardInputModeKeyboardPhysical,
CSMachineKeyboardInputModeKeyboardLogical,
CSMachineKeyboardInputModeJoystick,
};
@interface CSMissingROM: NSObject

View File

@ -201,9 +201,10 @@ struct ActivityObserver: public Activity::Observer {
return nil;
}
// Use the keyboard as a joystick if the machine has no keyboard, or if it has a 'non-exclusive' keyboard.
_inputMode =
(_machine->keyboard_machine() && _machine->keyboard_machine()->get_keyboard().is_exclusive())
? CSMachineKeyboardInputModeKeyboard : CSMachineKeyboardInputModeJoystick;
? CSMachineKeyboardInputModeKeyboardPhysical : CSMachineKeyboardInputModeJoystick;
_leds = [[NSMutableArray alloc] init];
Activity::Source *const activity_source = _machine->activity_source();
@ -429,7 +430,7 @@ struct ActivityObserver: public Activity::Observer {
- (void)setKey:(uint16_t)key characters:(NSString *)characters isPressed:(BOOL)isPressed {
auto keyboard_machine = _machine->keyboard_machine();
if(keyboard_machine && (self.inputMode == CSMachineKeyboardInputModeKeyboard || !keyboard_machine->get_keyboard().is_exclusive())) {
if(keyboard_machine && (self.inputMode != CSMachineKeyboardInputModeJoystick || !keyboard_machine->get_keyboard().is_exclusive())) {
Inputs::Keyboard::Key mapped_key = Inputs::Keyboard::Key::Help; // Make an innocuous default guess.
#define BIND(source, dest) case source: mapped_key = Inputs::Keyboard::Key::dest; break;
// Connect the Carbon-era Mac keyboard scancodes to Clock Signal's 'universal' enumeration in order
@ -503,9 +504,19 @@ struct ActivityObserver: public Activity::Observer {
}
}
if(self.inputMode == CSMachineKeyboardInputModeKeyboardLogical) {
if(isPressed) {
@synchronized(self) {
char string[2] = { pressedKey, 0 };
keyboard_machine->type_string(string);
}
}
} else {
@synchronized(self) {
keyboard.set_key_pressed(mapped_key, pressedKey, isPressed);
}
}
return;
}
}