diff --git a/Machines/ZX8081/Keyboard.cpp b/Machines/ZX8081/Keyboard.cpp index a84fac93d..fde1b7938 100644 --- a/Machines/ZX8081/Keyboard.cpp +++ b/Machines/ZX8081/Keyboard.cpp @@ -28,6 +28,9 @@ uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) { BIND(FullStop, KeyDot); BIND(Enter, KeyEnter); BIND(Space, KeySpace); + + // Virtual keys follow. + BIND(Backspace, KeyDelete); } #undef BIND return KeyboardMachine::MappedMachine::KeyNotMapped; diff --git a/Machines/ZX8081/Keyboard.hpp b/Machines/ZX8081/Keyboard.hpp index 53482542f..2eca45080 100644 --- a/Machines/ZX8081/Keyboard.hpp +++ b/Machines/ZX8081/Keyboard.hpp @@ -23,6 +23,9 @@ enum Key: uint16_t { KeyP = 0x0500 | 0x01, KeyO = 0x0500 | 0x02, KeyI = 0x0500 | 0x04, KeyU = 0x0500 | 0x08, KeyY = 0x0500 | 0x10, KeyEnter = 0x0600 | 0x01, KeyL = 0x0600 | 0x02, KeyK = 0x0600 | 0x04, KeyJ = 0x0600 | 0x08, KeyH = 0x0600 | 0x10, KeySpace = 0x0700 | 0x01, KeyDot = 0x0700 | 0x02, KeyM = 0x0700 | 0x04, KeyN = 0x0700 | 0x08, KeyB = 0x0700 | 0x10, + + // Add some virtual keys; these do not exist on a real ZX80 or ZX81. They're just a convenience. + KeyDelete = 0x0801, }; struct KeyboardMapper: public KeyboardMachine::MappedMachine::KeyboardMapper { diff --git a/Machines/ZX8081/ZX8081.cpp b/Machines/ZX8081/ZX8081.cpp index 9c67055bc..4bc876763 100644 --- a/Machines/ZX8081/ZX8081.cpp +++ b/Machines/ZX8081/ZX8081.cpp @@ -349,10 +349,23 @@ template class ConcreteMachine: // MARK: - Keyboard void set_key_state(uint16_t key, bool is_pressed) final { - if(is_pressed) - key_states_[key >> 8] &= static_cast(~key); - else - key_states_[key >> 8] |= static_cast(key); + const auto line = key >> 8; + + // Check for special cases. + if(line == 8) { + switch(key) { + case KeyDelete: + // Map delete to shift+0. + set_key_state(KeyShift, is_pressed); + set_key_state(Key0, is_pressed); + break; + } + } else { + if(is_pressed) + key_states_[line] &= uint8_t(~key); + else + key_states_[line] |= uint8_t(key); + } } void clear_all_keys() final {