1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-25 03:32:01 +00:00

Added enough stuff to put the emulated Amstrad CPC in a state of knowing whether its '0' key is pressed.

This commit is contained in:
Thomas Harte 2017-08-01 17:31:56 -04:00
parent e6854ff8db
commit f5b278d683
4 changed files with 124 additions and 1 deletions

View File

@ -439,6 +439,12 @@ class ConcreteMachine:
}
}
void set_key_state(uint16_t key, bool isPressed) {
}
void clear_all_keys() {
}
private:
CRTCBusHandler crtc_bus_handler_;
Motorola::CRTC::CRTC6845<CRTCBusHandler> crtc_;

View File

@ -20,12 +20,40 @@ enum ROMType: uint8_t {
AMSDOS
};
enum Key: uint16_t {
#define Line(l, k1, k2, k3, k4, k5, k6, k7, k8) \
k1 = (l << 4) | 0x08,\
k2 = (l << 4) | 0x07,\
k3 = (l << 4) | 0x06,\
k4 = (l << 4) | 0x05,\
k5 = (l << 4) | 0x04,\
k6 = (l << 4) | 0x03,\
k7 = (l << 4) | 0x02,\
k8 = (l << 4) | 0x01,
Line(0, KeyFDot, KeyEnter, KeyF3, KeyF6, KeyF9, KeyDown, KeyRight, KeyUp)
Line(1, KeyF0, KeyF2, KeyF1, KeyF5, KeyF8, KeyF7, KeyCopy, KeyLeft)
Line(2, KeyControl, KeyBackSlash, KeyShift, KeyF4, KeyRightSquareBracket, KeyReturn, KeyLeftSquareBracket, KeyClear)
Line(3, KeyFullStop, KeyForwardSlash, KeyColon, KeySemicolon, KeyP, KeyAt, KeyMinus, KeyCaret)
Line(4, KeyComma, KeyM, KeyK, KeyL, KeyI, KeyO, Key9, Key0)
Line(5, KeySpace, KeyN, KeyJ, KeyH, KeyY, KeyU, Key7, Key8)
Line(6, KeyV, KeyB, KeyF, KeyG, KeyT, KeyR, Key5, Key6)
Line(7, KeyX, KeyC, KeyD, KeyS, KeyW, KeyE, Key3, Key4)
Line(8, KeyZ, KeyCapsLock, KeyA, KeyTab, KeyQ, KeyEscape, Key2, Key1)
Line(9, KeyDelete, KeyJoy1Fire3, KeyJoy2Fire2, KeyJoy1Fire1, KeyJoy1Right, KeyJoy1Left, KeyJoy1Down, KeyJoy1Up)
#undef Line
};
class Machine:
public CRTMachine::Machine,
public ConfigurationTarget::Machine {
public:
static Machine *AmstradCPC();
virtual void set_rom(ROMType type, std::vector<uint8_t> data) = 0;
virtual void set_key_state(uint16_t key, bool isPressed) = 0;
virtual void clear_all_keys() = 0;
};
}

View File

@ -7,7 +7,8 @@
//
#import "CSMachine.h"
#import "CSKeyboardMachine.h"
@interface CSAmstradCPC : CSMachine
@interface CSAmstradCPC : CSMachine <CSKeyboardMachine>
@end

View File

@ -59,4 +59,92 @@
- (NSString *)userDefaultsPrefix { return @"amstradCPC"; }
#pragma mark - Keyboard Mapping
- (void)clearAllKeys {
@synchronized(self) {
_amstradCPC->clear_all_keys();
}
}
- (void)setKey:(uint16_t)key isPressed:(BOOL)isPressed {
@synchronized(self) {
switch(key)
{
case VK_ANSI_0: _amstradCPC->set_key_state(AmstradCPC::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;
case VK_ANSI_Grave:
case VK_ANSI_Backslash:
_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;
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;
case VK_Delete: _electron.set_key_state(Electron::Key::KeyDelete, isPressed); break;
case VK_Escape: _electron.set_key_state(Electron::Key::KeyEscape, isPressed); break;
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;
case VK_ANSI_Semicolon:
_electron.set_key_state(Electron::Key::KeySemiColon, isPressed); break;
case VK_ANSI_Quote: _electron.set_key_state(Electron::Key::KeyColon, isPressed); break;
case VK_ANSI_Slash: _electron.set_key_state(Electron::Key::KeySlash, isPressed); break;
case VK_Shift: _electron.set_key_state(Electron::Key::KeyShift, isPressed); break;
case VK_Control: _electron.set_key_state(Electron::Key::KeyControl, isPressed); break;
case VK_Command:
case VK_Option: _electron.set_key_state(Electron::Key::KeyFunc, isPressed); break;
case VK_F12: _electron.set_key_state(Electron::Key::KeyBreak, isPressed); break;
default:
// printf("%02x\n", key);
break;*/
}
}
}
@end