1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

Starts to make formal Spectrum accommodations.

This commit is contained in:
Thomas Harte 2021-03-19 11:06:09 -04:00
parent 2371048ad1
commit a35e1f4fbe
2 changed files with 46 additions and 13 deletions

View File

@ -29,10 +29,28 @@ uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) const {
BIND(B, KeyB); BIND(N, KeyN); BIND(M, KeyM); BIND(B, KeyB); BIND(N, KeyN); BIND(M, KeyM);
BIND(LeftShift, KeyShift); BIND(RightShift, KeyShift); BIND(LeftShift, KeyShift); BIND(RightShift, KeyShift);
BIND(FullStop, KeyDot);
BIND(Enter, KeyEnter); BIND(Enter, KeyEnter);
BIND(Space, KeySpace); BIND(Space, KeySpace);
// Full stop has a key on the ZX80 and ZX81; it doesn't have a dedicated key on the Spectrum.
case Inputs::Keyboard::Key::FullStop:
if(machine_ == Machine::ZXSpectrum) {
return KeySpectrumDot;
} else {
return KeyDot;
}
break;
// Map controls and options to symbol shift, if this is a ZX Spectrum.
case Inputs::Keyboard::Key::LeftOption:
case Inputs::Keyboard::Key::RightOption:
case Inputs::Keyboard::Key::LeftControl:
case Inputs::Keyboard::Key::RightControl:
if(machine_ == Machine::ZXSpectrum) {
return KeySymbolShift;
}
break;
// Virtual keys follow. // Virtual keys follow.
BIND(Backspace, KeyDelete); BIND(Backspace, KeyDelete);
BIND(Escape, KeyBreak); BIND(Escape, KeyBreak);
@ -41,6 +59,7 @@ uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) const {
BIND(Left, KeyLeft); BIND(Left, KeyLeft);
BIND(Right, KeyRight); BIND(Right, KeyRight);
BIND(BackTick, KeyEdit); BIND(F1, KeyEdit); BIND(BackTick, KeyEdit); BIND(F1, KeyEdit);
BIND(Comma, KeyComma);
} }
#undef BIND #undef BIND
return MachineTypes::MappedKeyboardMachine::KeyNotMapped; return MachineTypes::MappedKeyboardMachine::KeyNotMapped;
@ -211,19 +230,33 @@ void Keyboard::set_key_state(uint16_t key, bool is_pressed) {
// Check for special cases. // Check for special cases.
if(line > 7) { if(line > 7) {
switch(key) { switch(key) {
#define ShiftedKey(source, base) \ #define ShiftedKey(source, base, shift) \
case source: \ case source: \
set_key_state(KeyShift, is_pressed); \ set_key_state(shift, is_pressed); \
set_key_state(base, is_pressed); \ set_key_state(base, is_pressed); \
break; break;
ShiftedKey(KeyDelete, Key0); ShiftedKey(KeyDelete, Key0, KeyShift);
ShiftedKey(KeyBreak, KeySpace); ShiftedKey(KeyBreak, KeySpace, KeyShift);
ShiftedKey(KeyUp, Key7); ShiftedKey(KeyUp, Key7, KeyShift);
ShiftedKey(KeyDown, Key6); ShiftedKey(KeyDown, Key6, KeyShift);
ShiftedKey(KeyLeft, Key5); ShiftedKey(KeyLeft, Key5, KeyShift);
ShiftedKey(KeyRight, Key8); ShiftedKey(KeyRight, Key8, KeyShift);
ShiftedKey(KeyEdit, (machine_ == Machine::ZX80) ? KeyEnter : Key1); ShiftedKey(KeyEdit, (machine_ == Machine::ZX80) ? KeyEnter : Key1, KeyShift);
ShiftedKey(KeySpectrumDot, KeyM, KeySymbolShift);
case KeyComma:
if(machine_ == Machine::ZXSpectrum) {
// Spectrum: comma = symbol shift + n.
set_key_state(KeySymbolShift, is_pressed);
set_key_state(KeyN, is_pressed);
} else {
// ZX80/81: comma = shift + dot.
set_key_state(KeyShift, is_pressed);
set_key_state(KeyDot, is_pressed);
}
break;
#undef ShiftedKey #undef ShiftedKey
} }

View File

@ -36,7 +36,7 @@ enum Key: uint16_t {
// Add some virtual keys; these do not exist on a real ZX80, ZX81 or early Spectrum, those all were added to the 128kb Spectrums. // Add some virtual keys; these do not exist on a real ZX80, ZX81 or early Spectrum, those all were added to the 128kb Spectrums.
// Either way, they're a convenience. // Either way, they're a convenience.
KeyDelete = 0x0801, KeyDelete = 0x0801,
KeyBreak, KeyLeft, KeyRight, KeyUp, KeyDown, KeyEdit KeyBreak, KeyLeft, KeyRight, KeyUp, KeyDown, KeyEdit, KeySpectrumDot, KeyComma,
}; };
class Keyboard { class Keyboard {