mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-21 21:33:54 +00:00
Resolves potential source of errors: specifying incorrect table size.
(Having made exactly this mistake with the ZX Spectrum)
This commit is contained in:
parent
17f11a3be3
commit
9cc747b3e2
@ -151,7 +151,7 @@ const uint16_t *CharacterMapper::sequence_for_character(char character) const {
|
||||
#undef SHIFT
|
||||
#undef X
|
||||
|
||||
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
||||
return table_lookup_sequence_for_character(key_sequences, character);
|
||||
}
|
||||
|
||||
bool CharacterMapper::needs_pause_after_key(uint16_t key) const {
|
||||
|
@ -151,5 +151,5 @@ const uint16_t *CharacterMapper::sequence_for_character(char character) const {
|
||||
#undef SHIFT
|
||||
#undef X
|
||||
|
||||
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
||||
return table_lookup_sequence_for_character(key_sequences, character);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ const uint16_t *CharacterMapper::sequence_for_character(char character) const {
|
||||
#undef SHIFT
|
||||
#undef X
|
||||
|
||||
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
||||
return table_lookup_sequence_for_character(key_sequences, character);
|
||||
}
|
||||
|
||||
bool CharacterMapper::needs_pause_after_key(uint16_t key) const {
|
||||
|
@ -127,5 +127,5 @@ const uint16_t *CharacterMapper::sequence_for_character(char character) const {
|
||||
#undef SHIFT
|
||||
#undef X
|
||||
|
||||
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
||||
return table_lookup_sequence_for_character(key_sequences, character);
|
||||
}
|
||||
|
@ -275,13 +275,13 @@ const uint16_t *CharacterMapper::sequence_for_character(char character) const {
|
||||
|
||||
switch(machine_) {
|
||||
case Machine::ZX80:
|
||||
return table_lookup_sequence_for_character(zx80_key_sequences, sizeof(zx80_key_sequences), character);
|
||||
return table_lookup_sequence_for_character(zx80_key_sequences, character);
|
||||
|
||||
case Machine::ZX81:
|
||||
return table_lookup_sequence_for_character(zx81_key_sequences, sizeof(zx81_key_sequences), character);
|
||||
return table_lookup_sequence_for_character(zx81_key_sequences, character);
|
||||
|
||||
case Machine::ZXSpectrum:
|
||||
return table_lookup_sequence_for_character(spectrum_key_sequences, sizeof(zx81_key_sequences), character);
|
||||
return table_lookup_sequence_for_character(spectrum_key_sequences, character);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,13 +131,3 @@ bool Typer::type_next_character() {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// MARK: - Character mapper
|
||||
|
||||
const uint16_t *CharacterMapper::table_lookup_sequence_for_character(const KeySequence *sequences, std::size_t length, char character) const {
|
||||
std::size_t ucharacter = size_t((unsigned char)character);
|
||||
if(ucharacter >= (length / sizeof(KeySequence))) return nullptr;
|
||||
if(sequences[ucharacter][0] == MachineTypes::MappedKeyboardMachine::KeyNotMapped) return nullptr;
|
||||
return sequences[ucharacter];
|
||||
}
|
||||
|
||||
|
@ -44,11 +44,15 @@ class CharacterMapper {
|
||||
typedef uint16_t KeySequence[16];
|
||||
|
||||
/*!
|
||||
Provided in the base class as a convenience: given the lookup table of key sequences @c sequences,
|
||||
with @c length entries, returns the sequence for character @c character if it exists; otherwise
|
||||
returns @c nullptr.
|
||||
Provided in the base class as a convenience: given the C array of key sequences @c sequences,
|
||||
returns the sequence for character @c character if it exists; otherwise returns @c nullptr.
|
||||
*/
|
||||
const uint16_t *table_lookup_sequence_for_character(const KeySequence *sequences, std::size_t length, char character) const;
|
||||
template <typename Collection> const uint16_t *table_lookup_sequence_for_character(const Collection &sequences, char character) const {
|
||||
std::size_t ucharacter = size_t((unsigned char)character);
|
||||
if(ucharacter >= sizeof(sequences) / sizeof(KeySequence)) return nullptr;
|
||||
if(sequences[ucharacter][0] == MachineTypes::MappedKeyboardMachine::KeyNotMapped) return nullptr;
|
||||
return sequences[ucharacter];
|
||||
}
|
||||
};
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user