diff --git a/Machines/Enterprise/Enterprise.cpp b/Machines/Enterprise/Enterprise.cpp index ef2752d51..528c6cacc 100644 --- a/Machines/Enterprise/Enterprise.cpp +++ b/Machines/Enterprise/Enterprise.cpp @@ -14,6 +14,7 @@ #include "Nick.hpp" #include "../MachineTypes.hpp" +#include "../Utility/Typer.hpp" #include "../../Analyser/Static/Enterprise/Target.hpp" #include "../../ClockReceiver/JustInTime.hpp" @@ -69,7 +70,8 @@ template class ConcreteMachine: public MachineTypes::MappedKeyboardMachine, public MachineTypes::MediaTarget, public MachineTypes::ScanProducer, - public MachineTypes::TimedMachine { + public MachineTypes::TimedMachine, + public Utility::TypeRecipient { private: constexpr uint8_t min_ram_slot(const Analyser::Static::Enterprise::Target &target) { size_t ram_size = 128*1024; @@ -310,6 +312,7 @@ template class ConcreteMachine: if(dave_timer_ += full_length) { set_interrupts(dave_timer_.last_valid()->get_new_interrupts(), dave_timer_.last_sequence_point_overrun()); } + if(typer_) typer_->run_for(cycle.length); // The WD/etc runs at a nominal 8Mhz. if constexpr (has_disk_controller) { @@ -578,6 +581,26 @@ template class ConcreteMachine: key_lines_.fill(0xff); } + // MARK: - Utility::TypeRecipient + HalfCycles get_typer_delay(const std::string &) const final { + if(!z80_.get_is_resetting()) { + return Cycles(0); + } + return HalfCycles(1'000'000); + } + + HalfCycles get_typer_frequency() const final { + return HalfCycles(60'000); + } + + void type_string(const std::string &string) final { + Utility::TypeRecipient::add_typer(string); + } + + bool can_type(char c) const final { + return Utility::TypeRecipient::can_type(c); + } + // MARK: - MediaTarget bool insert_media(const Analyser::Static::Media &media) final { if constexpr (has_disk_controller) { diff --git a/Machines/Enterprise/Keyboard.cpp b/Machines/Enterprise/Keyboard.cpp index 4c2444df3..56e0b81dd 100644 --- a/Machines/Enterprise/Keyboard.cpp +++ b/Machines/Enterprise/Keyboard.cpp @@ -20,7 +20,7 @@ uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) const { BIND(Tab, Tab); BIND(Escape, Escape); BIND(Hyphen, Hyphen); - BIND(Equals, Tilde); + BIND(Equals, Caret); BIND(Backspace, Erase); BIND(Delete, Delete); BIND(Semicolon, Semicolon); @@ -72,3 +72,80 @@ 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(x) {uint16_t(x), MachineTypes::MappedKeyboardMachine::KeyEndSequence} +#define SHIFT(x) {uint16_t(Key::LeftShift), uint16_t(x), 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(Key::Erase), /* HT */ X, + /* LF */ KEYS(Key::Enter), /* VT */ X, + /* FF */ X, /* CR */ KEYS(Key::Enter), + /* 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(Key::Space), /* ! */ SHIFT(Key::k1), + /* " */ SHIFT(Key::k2), /* # */ X, + /* $ */ SHIFT(Key::k4), /* % */ SHIFT(Key::k5), + /* & */ SHIFT(Key::k6), /* ' */ SHIFT(Key::k7), + /* ( */ SHIFT(Key::k8), /* ) */ SHIFT(Key::k9), + /* * */ SHIFT(Key::Colon), /* + */ SHIFT(Key::Semicolon), + /* , */ KEYS(Key::Comma), /* - */ KEYS(Key::Hyphen), + /* . */ KEYS(Key::FullStop), /* / */ KEYS(Key::ForwardSlash), + /* 0 */ KEYS(Key::k0), /* 1 */ KEYS(Key::k1), + /* 2 */ KEYS(Key::k2), /* 3 */ KEYS(Key::k3), + /* 4 */ KEYS(Key::k4), /* 5 */ KEYS(Key::k5), + /* 6 */ KEYS(Key::k6), /* 7 */ KEYS(Key::k7), + /* 8 */ KEYS(Key::k8), /* 9 */ KEYS(Key::k9), + /* : */ KEYS(Key::Colon), /* ; */ KEYS(Key::Semicolon), + /* < */ SHIFT(Key::Comma), /* = */ SHIFT(Key::Hyphen), + /* > */ SHIFT(Key::FullStop), /* ? */ SHIFT(Key::ForwardSlash), + /* @ */ KEYS(Key::At), /* A */ KEYS(Key::A), + /* B */ KEYS(Key::B), /* C */ KEYS(Key::C), + /* D */ KEYS(Key::D), /* E */ KEYS(Key::E), + /* F */ KEYS(Key::F), /* G */ KEYS(Key::G), + /* H */ KEYS(Key::H), /* I */ KEYS(Key::I), + /* J */ KEYS(Key::J), /* K */ KEYS(Key::K), + /* L */ KEYS(Key::L), /* M */ KEYS(Key::M), + /* N */ KEYS(Key::N), /* O */ KEYS(Key::O), + /* P */ KEYS(Key::P), /* Q */ KEYS(Key::Q), + /* R */ KEYS(Key::R), /* S */ KEYS(Key::S), + /* T */ KEYS(Key::T), /* U */ KEYS(Key::U), + /* V */ KEYS(Key::V), /* W */ KEYS(Key::W), + /* X */ KEYS(Key::X), /* Y */ KEYS(Key::Y), + /* Z */ KEYS(Key::Z), /* [ */ KEYS(Key::OpenSquareBracket), + /* \ */ KEYS(Key::Backslash), /* ] */ KEYS(Key::CloseSquareBracket), + /* ^ */ SHIFT(Key::Caret), /* _ */ SHIFT(Key::k0), + /* ` */ SHIFT(Key::At), /* a */ SHIFT(Key::A), + /* b */ SHIFT(Key::B), /* c */ SHIFT(Key::C), + /* d */ SHIFT(Key::D), /* e */ SHIFT(Key::E), + /* f */ SHIFT(Key::F), /* g */ SHIFT(Key::G), + /* h */ SHIFT(Key::H), /* i */ SHIFT(Key::I), + /* j */ SHIFT(Key::J), /* k */ SHIFT(Key::K), + /* l */ SHIFT(Key::L), /* m */ SHIFT(Key::M), + /* n */ SHIFT(Key::N), /* o */ SHIFT(Key::O), + /* p */ SHIFT(Key::P), /* q */ SHIFT(Key::Q), + /* r */ SHIFT(Key::R), /* s */ SHIFT(Key::S), + /* t */ SHIFT(Key::T), /* u */ SHIFT(Key::U), + /* v */ SHIFT(Key::V), /* w */ SHIFT(Key::W), + /* x */ SHIFT(Key::X), /* y */ SHIFT(Key::Y), + /* z */ SHIFT(Key::Z), /* { */ SHIFT(Key::OpenSquareBracket), + /* | */ SHIFT(Key::Backslash), /* } */ SHIFT(Key::CloseSquareBracket), + /* ~ */ SHIFT(Key::Caret) + }; +#undef KEYS +#undef SHIFT +#undef X + + return table_lookup_sequence_for_character(key_sequences, character); +} diff --git a/Machines/Enterprise/Keyboard.hpp b/Machines/Enterprise/Keyboard.hpp index 0a13b7e1a..4f611b293 100644 --- a/Machines/Enterprise/Keyboard.hpp +++ b/Machines/Enterprise/Keyboard.hpp @@ -10,6 +10,7 @@ #define Machines_Enterprise_Keyboard_hpp #include "../KeyboardMachine.hpp" +#include "../Utility/Typer.hpp" namespace Enterprise { @@ -32,7 +33,7 @@ enum class Key: uint16_t { F5 = 0x0400 | 0x10, F7 = 0x0400 | 0x20, F2 = 0x0400 | 0x40, F1 = 0x0400 | 0x80, k8 = 0x0500 | 0x01, k9 = 0x0500 | 0x04, Hyphen = 0x0500 | 0x08, - k0 = 0x0500 | 0x10, Tilde = 0x0500 | 0x20, Erase = 0x0500 | 0x40, + k0 = 0x0500 | 0x10, Caret = 0x0500 | 0x20, Erase = 0x0500 | 0x40, J = 0x0600 | 0x01, K = 0x0600 | 0x04, Semicolon = 0x0600 | 0x08, L = 0x0600 | 0x10, Colon = 0x0600 | 0x20, CloseSquareBracket = 0x0600 | 0x40, @@ -56,6 +57,10 @@ 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 override; +}; + } #endif /* Keyboard_hpp */