From c618d18d46d31d845dbe809544b9d752a556d8db Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 3 Jan 2025 20:29:19 -0500 Subject: [PATCH] Allow typers to be attached. --- Machines/Commodore/Plus4/Keyboard.cpp | 150 +++++++++++++------------- Machines/Commodore/Plus4/Keyboard.hpp | 6 +- Machines/Commodore/Plus4/Plus4.cpp | 15 ++- 3 files changed, 92 insertions(+), 79 deletions(-) diff --git a/Machines/Commodore/Plus4/Keyboard.cpp b/Machines/Commodore/Plus4/Keyboard.cpp index 1158c25b2..356de92c9 100644 --- a/Machines/Commodore/Plus4/Keyboard.cpp +++ b/Machines/Commodore/Plus4/Keyboard.cpp @@ -58,77 +58,79 @@ uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) const { return MachineTypes::MappedKeyboardMachine::KeyNotMapped; } -//const uint16_t *CharacterMapper::sequence_for_character(char character) const { -//#define KEYS(...) {__VA_ARGS__, MachineTypes::MappedKeyboardMachine::KeyEndSequence} -//#define SHIFT(...) {KeyLShift, __VA_ARGS__, MachineTypes::MappedKeyboardMachine::KeyEndSequence} -//#define X {MachineTypes::MappedKeyboardMachine::KeyNotMapped} -// static KeySequence key_sequences[] = { -// /* NUL */ X, /* SOH */ X, -// /* STX */ X, /* ETX */ X, -// /* EOT */ X, /* ENQ */ X, -// /* ACK */ X, /* BEL */ X, -// /* BS */ KEYS(KeyDelete), /* HT */ X, -// /* LF */ KEYS(KeyReturn), /* VT */ X, -// /* FF */ X, /* CR */ X, -// /* SO */ X, /* SI */ X, -// /* DLE */ X, /* DC1 */ X, -// /* DC2 */ X, /* DC3 */ X, -// /* DC4 */ X, /* NAK */ X, -// /* SYN */ X, /* ETB */ X, -// /* CAN */ X, /* EM */ X, -// /* SUB */ X, /* ESC */ X, -// /* FS */ X, /* GS */ X, -// /* RS */ X, /* US */ X, -// /* space */ KEYS(KeySpace), /* ! */ SHIFT(Key1), -// /* " */ SHIFT(Key2), /* # */ SHIFT(Key3), -// /* $ */ SHIFT(Key4), /* % */ SHIFT(Key5), -// /* & */ SHIFT(Key6), /* ' */ SHIFT(Key7), -// /* ( */ SHIFT(Key8), /* ) */ SHIFT(Key9), -// /* * */ KEYS(KeyAsterisk), /* + */ KEYS(KeyPlus), -// /* , */ KEYS(KeyComma), /* - */ KEYS(KeyDash), -// /* . */ KEYS(KeyFullStop), /* / */ KEYS(KeySlash), -// /* 0 */ KEYS(Key0), /* 1 */ KEYS(Key1), -// /* 2 */ KEYS(Key2), /* 3 */ KEYS(Key3), -// /* 4 */ KEYS(Key4), /* 5 */ KEYS(Key5), -// /* 6 */ KEYS(Key6), /* 7 */ KEYS(Key7), -// /* 8 */ KEYS(Key8), /* 9 */ KEYS(Key9), -// /* : */ KEYS(KeyColon), /* ; */ KEYS(KeySemicolon), -// /* < */ SHIFT(KeyComma), /* = */ KEYS(KeyEquals), -// /* > */ SHIFT(KeyFullStop), /* ? */ SHIFT(KeySlash), -// /* @ */ KEYS(KeyAt), /* A */ KEYS(KeyA), -// /* B */ KEYS(KeyB), /* C */ KEYS(KeyC), -// /* D */ KEYS(KeyD), /* E */ KEYS(KeyE), -// /* F */ KEYS(KeyF), /* G */ KEYS(KeyG), -// /* H */ KEYS(KeyH), /* I */ KEYS(KeyI), -// /* J */ KEYS(KeyJ), /* K */ KEYS(KeyK), -// /* L */ KEYS(KeyL), /* M */ KEYS(KeyM), -// /* N */ KEYS(KeyN), /* O */ KEYS(KeyO), -// /* P */ KEYS(KeyP), /* Q */ KEYS(KeyQ), -// /* R */ KEYS(KeyR), /* S */ KEYS(KeyS), -// /* T */ KEYS(KeyT), /* U */ KEYS(KeyU), -// /* V */ KEYS(KeyV), /* W */ KEYS(KeyW), -// /* X */ KEYS(KeyX), /* Y */ KEYS(KeyY), -// /* Z */ KEYS(KeyZ), /* [ */ SHIFT(KeyColon), -// /* \ */ X, /* ] */ SHIFT(KeySemicolon), -// /* ^ */ X, /* _ */ X, -// /* ` */ X, /* a */ KEYS(KeyA), -// /* b */ KEYS(KeyB), /* c */ KEYS(KeyC), -// /* d */ KEYS(KeyD), /* e */ KEYS(KeyE), -// /* f */ KEYS(KeyF), /* g */ KEYS(KeyG), -// /* h */ KEYS(KeyH), /* i */ KEYS(KeyI), -// /* j */ KEYS(KeyJ), /* k */ KEYS(KeyK), -// /* l */ KEYS(KeyL), /* m */ KEYS(KeyM), -// /* n */ KEYS(KeyN), /* o */ KEYS(KeyO), -// /* p */ KEYS(KeyP), /* q */ KEYS(KeyQ), -// /* r */ KEYS(KeyR), /* s */ KEYS(KeyS), -// /* t */ KEYS(KeyT), /* u */ KEYS(KeyU), -// /* v */ KEYS(KeyV), /* w */ KEYS(KeyW), -// /* x */ KEYS(KeyX), /* y */ KEYS(KeyY), -// /* z */ KEYS(KeyZ) -// }; -//#undef KEYS -//#undef SHIFT -//#undef X -// -// return table_lookup_sequence_for_character(key_sequences, character); -//} +const uint16_t *CharacterMapper::sequence_for_character(char character) const { + constexpr KeySequence X = { MachineTypes::MappedKeyboardMachine::KeyNotMapped }; + const auto key = [](Key k) -> KeySequence { + return { k, MachineTypes::MappedKeyboardMachine::KeyEndSequence }; + }; + const auto shift = [](Key k) -> KeySequence { + return { Key::Shift, k, MachineTypes::MappedKeyboardMachine::KeyEndSequence }; + }; + + static KeySequence key_sequences[] = { + /* NUL */ X, /* SOH */ X, + /* STX */ X, /* ETX */ X, + /* EOT */ X, /* ENQ */ X, + /* ACK */ X, /* BEL */ X, + /* BS */ key(Key::InsDel), /* HT */ X, + /* LF */ key(Key::Return), /* VT */ X, + /* FF */ X, /* CR */ X, + /* SO */ X, /* SI */ X, + /* DLE */ X, /* DC1 */ X, + /* DC2 */ X, /* DC3 */ X, + /* DC4 */ X, /* NAK */ X, + /* SYN */ X, /* ETB */ X, + /* CAN */ X, /* EM */ X, + /* SUB */ X, /* ESC */ X, + /* FS */ X, /* GS */ X, + /* RS */ X, /* US */ X, + /* space */ key(Key::Space), /* ! */ shift(Key::k1), + /* " */ shift(Key::k2), /* # */ shift(Key::k3), + /* $ */ shift(Key::k4), /* % */ shift(Key::k5), + /* & */ shift(Key::k6), /* ' */ shift(Key::k7), + /* ( */ shift(Key::k8), /* ) */ shift(Key::k9), + /* * */ key(Key::Asterisk), /* + */ key(Key::Plus), + /* , */ key(Key::Comma), /* - */ key(Key::Minus), + /* . */ key(Key::FullStop), /* / */ key(Key::Slash), + /* 0 */ key(Key::k0), /* 1 */ key(Key::k1), + /* 2 */ key(Key::k2), /* 3 */ key(Key::k3), + /* 4 */ key(Key::k4), /* 5 */ key(Key::k5), + /* 6 */ key(Key::k6), /* 7 */ key(Key::k7), + /* 8 */ key(Key::k8), /* 9 */ key(Key::k9), + /* : */ key(Key::Colon), /* ; */ key(Key::Semicolon), + /* < */ shift(Key::Comma), /* = */ key(Key::Equals), + /* > */ shift(Key::FullStop), /* ? */ shift(Key::Slash), + /* @ */ key(Key::At), /* A */ key(Key::A), + /* B */ key(Key::B), /* C */ key(Key::C), + /* D */ key(Key::D), /* E */ key(Key::E), + /* F */ key(Key::F), /* G */ key(Key::G), + /* H */ key(Key::H), /* I */ key(Key::I), + /* J */ key(Key::J), /* K */ key(Key::K), + /* L */ key(Key::L), /* M */ key(Key::M), + /* N */ key(Key::N), /* O */ key(Key::O), + /* P */ key(Key::P), /* Q */ key(Key::Q), + /* R */ key(Key::R), /* S */ key(Key::S), + /* T */ key(Key::T), /* U */ key(Key::U), + /* V */ key(Key::V), /* W */ key(Key::W), + /* X */ key(Key::X), /* Y */ key(Key::Y), + /* Z */ key(Key::Z), /* [ */ shift(Key::Colon), + /* \ */ X, /* ] */ shift(Key::Semicolon), + /* ^ */ X, /* _ */ X, + /* ` */ X, /* a */ key(Key::A), + /* b */ key(Key::B), /* c */ key(Key::C), + /* d */ key(Key::D), /* e */ key(Key::E), + /* f */ key(Key::F), /* g */ key(Key::G), + /* h */ key(Key::H), /* i */ key(Key::I), + /* j */ key(Key::J), /* k */ key(Key::K), + /* l */ key(Key::L), /* m */ key(Key::M), + /* n */ key(Key::N), /* o */ key(Key::O), + /* p */ key(Key::P), /* q */ key(Key::Q), + /* r */ key(Key::R), /* s */ key(Key::S), + /* t */ key(Key::T), /* u */ key(Key::U), + /* v */ key(Key::V), /* w */ key(Key::W), + /* x */ key(Key::X), /* y */ key(Key::Y), + /* z */ key(Key::Z) + }; + + return table_lookup_sequence_for_character(key_sequences, character); +} diff --git a/Machines/Commodore/Plus4/Keyboard.hpp b/Machines/Commodore/Plus4/Keyboard.hpp index 850c1bdaa..d089e9d46 100644 --- a/Machines/Commodore/Plus4/Keyboard.hpp +++ b/Machines/Commodore/Plus4/Keyboard.hpp @@ -75,8 +75,8 @@ struct KeyboardMapper: public MachineTypes::MappedKeyboardMachine::KeyboardMappe uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) const final; }; -//struct CharacterMapper: public ::Utility::CharacterMapper { -// const uint16_t *sequence_for_character(char character) const final; -//}; +struct CharacterMapper: public ::Utility::CharacterMapper { + const uint16_t *sequence_for_character(char character) const final; +}; } diff --git a/Machines/Commodore/Plus4/Plus4.cpp b/Machines/Commodore/Plus4/Plus4.cpp index 9f305087f..f2e127409 100644 --- a/Machines/Commodore/Plus4/Plus4.cpp +++ b/Machines/Commodore/Plus4/Plus4.cpp @@ -128,7 +128,8 @@ class ConcreteMachine: public MachineTypes::TimedMachine, public MachineTypes::ScanProducer, public MachineTypes::MediaTarget, - public Machine { + public Machine, + public Utility::TypeRecipient { public: ConcreteMachine(const Analyser::Static::Commodore::Target &target, const ROMMachine::ROMFetcher &rom_fetcher) : m6502_(*this), @@ -176,7 +177,9 @@ public: tape_player_ = std::make_unique(clock); insert_media(target.media); - printf("Loading command is: %s\n", target.loading_command.c_str()); + if(!target.loading_command.empty()) { + type_string(target.loading_command); + } } ~ConcreteMachine() { @@ -505,6 +508,14 @@ private: return &keyboard_mapper_; } + void type_string(const std::string &string) final { + Utility::TypeRecipient::add_typer(string); + } + + bool can_type(const char c) const final { + return Utility::TypeRecipient::can_type(c); + } + void set_key_state(uint16_t key, bool is_pressed) override { if(is_pressed) { key_states_[line(key)] |= mask(key);