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

Extends logic for when to fall back on standard keypress logic even in logical mode.

This commit is contained in:
Thomas Harte 2020-03-01 20:25:12 -05:00
parent 611182910a
commit ed18092088
14 changed files with 60 additions and 5 deletions

View File

@ -36,6 +36,14 @@ void MultiKeyboardMachine::type_string(const std::string &string) {
}
}
bool MultiKeyboardMachine::can_type(char c) {
bool can_type = true;
for(const auto &machine: machines_) {
can_type &= machine->can_type(c);
}
return can_type;
}
Inputs::Keyboard &MultiKeyboardMachine::get_keyboard() {
return keyboard_;
}

View File

@ -51,6 +51,7 @@ class MultiKeyboardMachine: public KeyboardMachine::Machine {
void clear_all_keys() final;
void set_key_state(uint16_t key, bool is_pressed) final;
void type_string(const std::string &) final;
bool can_type(char c) final;
Inputs::Keyboard &get_keyboard() final;
};

View File

@ -1082,6 +1082,10 @@ template <bool has_fdc> class ConcreteMachine:
Utility::TypeRecipient<CharacterMapper>::add_typer(string);
}
bool can_type(char c) final {
return Utility::TypeRecipient<CharacterMapper>::can_type(c);
}
HalfCycles get_typer_delay() final {
return z80_.get_is_resetting() ? Cycles(3'400'000) : Cycles(0);
}

View File

@ -858,6 +858,11 @@ template <Analyser::Static::AppleII::Target::Model model> class ConcreteMachine:
string_serialiser_ = std::make_unique<Utility::StringSerialiser>(string, true);
}
bool can_type(char c) final {
// Make an effort to type the entire printable ASCII range.
return c >= 32 && c < 127;
}
// MARK:: Configuration options.
std::vector<std::unique_ptr<Configurable::Option>> get_options() final {
return Apple::II::get_options();

View File

@ -648,6 +648,10 @@ class ConcreteMachine:
Utility::TypeRecipient<CharacterMapper>::add_typer(string);
}
bool can_type(char c) final {
return Utility::TypeRecipient<CharacterMapper>::can_type(c);
}
void tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape) final {
keyboard_via_.set_control_line_input(MOS::MOS6522::Port::A, MOS::MOS6522::Line::One, !tape->get_input());
}

View File

@ -416,6 +416,10 @@ class ConcreteMachine:
Utility::TypeRecipient<CharacterMapper>::add_typer(string);
}
bool can_type(char c) final {
return Utility::TypeRecipient<CharacterMapper>::can_type(c);
}
KeyboardMapper *get_keyboard_mapper() final {
return &keyboard_mapper_;
}

View File

@ -45,6 +45,11 @@ class Machine: public KeyActions {
*/
virtual void type_string(const std::string &);
/*!
@returns @c true if this machine can type the character @c c as part of a @c type_string; @c false otherwise.
*/
virtual bool can_type(char c) { return false; }
/*!
Provides a destination for keyboard input.
*/

View File

@ -369,6 +369,11 @@ class ConcreteMachine:
);
}
bool can_type(char c) final {
// Make an effort to type the entire printable ASCII range.
return c >= 32 && c < 127;
}
// MARK: MSX::MemoryMap
void map(int slot, std::size_t source_address, uint16_t destination_address, std::size_t length) final {
assert(!(destination_address & 8191));

View File

@ -589,6 +589,11 @@ template <Analyser::Static::Oric::Target::DiskInterface disk_interface> class Co
string_serialiser_ = std::make_unique<Utility::StringSerialiser>(string, true);
}
bool can_type(char c) final {
// Make an effort to type the entire printable ASCII range.
return c >= 32 && c < 127;
}
// DiskController::Delegate
void disk_controller_did_change_paged_item(DiskController *controller) final {
switch(controller->get_paged_item()) {

View File

@ -140,3 +140,4 @@ uint16_t *CharacterMapper::table_lookup_sequence_for_character(KeySequence *sequ
if(sequences[ucharacter][0] == KeyboardMachine::MappedMachine::KeyNotMapped) return nullptr;
return sequences[ucharacter];
}

View File

@ -115,6 +115,14 @@ class TypeRecipient: public Typer::Delegate {
}
}
/*!
@returns @c true if the character mapper provides a mapping for @c c; @c false otherwise.
*/
bool can_type(char c) {
const auto sequence = character_mapper.sequence_for_character(c);
return sequence && sequence[0] != KeyboardMachine::MappedMachine::KeyNotMapped;
}
/*!
Provided in order to conform to that part of the Typer::Delegate interface that goes above and
beyond KeyboardMachine::Machine; responds to the end of typing by clearing all keys.

View File

@ -344,6 +344,10 @@ template<bool is_zx81> class ConcreteMachine:
Utility::TypeRecipient<CharacterMapper>::add_typer(string);
}
bool can_type(char c) final {
return Utility::TypeRecipient<CharacterMapper>::can_type(c);
}
// MARK: - Keyboard
void set_key_state(uint16_t key, bool is_pressed) final {
const auto line = key >> 8;

View File

@ -508,14 +508,14 @@ struct ActivityObserver: public Activity::Observer {
// as something to type. If this isn't logical mode, or this key doesn't
// map to a symbol, pass it along as a standard press.
if(self.inputMode == CSMachineKeyboardInputModeKeyboardLogical) {
if(pressedKey) {
if(isPressed) {
@synchronized(self) {
@synchronized(self) {
if(pressedKey && keyboard_machine->can_type(pressedKey)) {
if(isPressed) {
char string[2] = { pressedKey, 0 };
keyboard_machine->type_string(string);
}
return;
}
return;
}
}

View File

@ -899,7 +899,8 @@ int main(int argc, char *argv[]) {
if(key_name[0] >= 0) key_value = key_name[0];
// If a logical mapping was selected and a symbol was found, type it.
if(logical_keyboard && key_value != '\0') {
if(logical_keyboard && key_value != '\0' && keyboard_machine->can_type(key_value)) {
char string[] = { key_value, 0 };
keyboard_machine->type_string(string);
break;
}