mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 16:31:31 +00:00
Factored out the table-lookup approach to being a typer, and adjusted so as definitely to limit myself to positive offset table lookups.
This commit is contained in:
parent
ef03c84b21
commit
3f609e17b3
@ -9,10 +9,10 @@
|
|||||||
#include "Vic20.hpp"
|
#include "Vic20.hpp"
|
||||||
|
|
||||||
uint16_t *Commodore::Vic20::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
uint16_t *Commodore::Vic20::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
||||||
#define KEYS(...) {__VA_ARGS__, TerminateSequence}
|
#define KEYS(...) {__VA_ARGS__, EndSequence}
|
||||||
#define SHIFT(...) {KeyLShift, __VA_ARGS__, TerminateSequence}
|
#define SHIFT(...) {KeyLShift, __VA_ARGS__, EndSequence}
|
||||||
#define X {NotMapped}
|
#define X {NotMapped}
|
||||||
static Key key_sequences[][3] = {
|
static KeySequence key_sequences[] = {
|
||||||
/* NUL */ X, /* SOH */ X,
|
/* NUL */ X, /* SOH */ X,
|
||||||
/* STX */ X, /* ETX */ X,
|
/* STX */ X, /* ETX */ X,
|
||||||
/* EOT */ X, /* ENQ */ X,
|
/* EOT */ X, /* ENQ */ X,
|
||||||
@ -80,7 +80,5 @@ uint16_t *Commodore::Vic20::Machine::sequence_for_character(Utility::Typer *type
|
|||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
if(character > sizeof(key_sequences) / sizeof(*key_sequences)) return nullptr;
|
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
||||||
if(key_sequences[character][0] == NotMapped) return nullptr;
|
|
||||||
return (uint16_t *)key_sequences[character];
|
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,6 @@ enum Key: uint16_t {
|
|||||||
KeyI = key(1, 0x10), KeyP = key(1, 0x20), KeyAsterisk = key(1, 0x40), KeyReturn = key(1, 0x80),
|
KeyI = key(1, 0x10), KeyP = key(1, 0x20), KeyAsterisk = key(1, 0x40), KeyReturn = key(1, 0x80),
|
||||||
Key1 = key(0, 0x01), Key3 = key(0, 0x02), Key5 = key(0, 0x04), Key7 = key(0, 0x08),
|
Key1 = key(0, 0x01), Key3 = key(0, 0x02), Key5 = key(0, 0x04), Key7 = key(0, 0x08),
|
||||||
Key9 = key(0, 0x10), KeyPlus = key(0, 0x20), KeyGBP = key(0, 0x40), KeyDelete = key(0, 0x80),
|
Key9 = key(0, 0x10), KeyPlus = key(0, 0x20), KeyGBP = key(0, 0x40), KeyDelete = key(0, 0x80),
|
||||||
|
|
||||||
TerminateSequence = 0xffff, NotMapped = 0xfffe
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum JoystickInput {
|
enum JoystickInput {
|
||||||
|
@ -57,8 +57,6 @@ enum Key: uint16_t {
|
|||||||
KeyShift = 0x00d0 | 0x08, KeyControl = 0x00d0 | 0x04, KeyFunc = 0x00d0 | 0x02, KeyEscape = 0x00d0 | 0x01,
|
KeyShift = 0x00d0 | 0x08, KeyControl = 0x00d0 | 0x04, KeyFunc = 0x00d0 | 0x02, KeyEscape = 0x00d0 | 0x01,
|
||||||
|
|
||||||
KeyBreak = 0xfffd,
|
KeyBreak = 0xfffd,
|
||||||
|
|
||||||
TerminateSequence = 0xffff, NotMapped = 0xfffe,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -17,11 +17,11 @@ int Electron::Machine::get_typer_frequency() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t *Electron::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
uint16_t *Electron::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
||||||
#define KEYS(...) {__VA_ARGS__, TerminateSequence}
|
#define KEYS(...) {__VA_ARGS__, EndSequence}
|
||||||
#define SHIFT(...) {KeyShift, __VA_ARGS__, TerminateSequence}
|
#define SHIFT(...) {KeyShift, __VA_ARGS__, EndSequence}
|
||||||
#define CTRL(...) {KeyControl, __VA_ARGS__, TerminateSequence}
|
#define CTRL(...) {KeyControl, __VA_ARGS__, EndSequence}
|
||||||
#define X {NotMapped}
|
#define X {NotMapped}
|
||||||
static Key key_sequences[][3] = {
|
static KeySequence key_sequences[] = {
|
||||||
/* NUL */ X, /* SOH */ X,
|
/* NUL */ X, /* SOH */ X,
|
||||||
/* STX */ X, /* ETX */ X,
|
/* STX */ X, /* ETX */ X,
|
||||||
/* EOT */ X, /* ENQ */ X,
|
/* EOT */ X, /* ENQ */ X,
|
||||||
@ -91,7 +91,5 @@ uint16_t *Electron::Machine::sequence_for_character(Utility::Typer *typer, char
|
|||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
if(character > sizeof(key_sequences) / sizeof(*key_sequences)) return nullptr;
|
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
||||||
if(key_sequences[character][0] == NotMapped) return nullptr;
|
|
||||||
return (uint16_t *)key_sequences[character];
|
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,6 @@ enum Key: uint16_t {
|
|||||||
KeyForwardSlash = 0x0700 | 0x08, Key0 = 0x0700 | 0x04, KeyL = 0x0700 | 0x02, Key8 = 0x0700 | 0x01,
|
KeyForwardSlash = 0x0700 | 0x08, Key0 = 0x0700 | 0x04, KeyL = 0x0700 | 0x02, Key8 = 0x0700 | 0x01,
|
||||||
|
|
||||||
KeyNMI = 0xfffd,
|
KeyNMI = 0xfffd,
|
||||||
|
|
||||||
TerminateSequence = 0xffff, NotMapped = 0xfffe
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ROM {
|
enum ROM {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#include "Oric.hpp"
|
#include "Oric.hpp"
|
||||||
|
|
||||||
uint16_t *Oric::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
uint16_t *Oric::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
||||||
#define KEYS(...) {__VA_ARGS__, TerminateSequence}
|
#define KEYS(...) {__VA_ARGS__, EndSequence}
|
||||||
#define SHIFT(...) {KeyLeftShift, __VA_ARGS__, TerminateSequence}
|
#define SHIFT(...) {KeyLeftShift, __VA_ARGS__, EndSequence}
|
||||||
#define X {NotMapped}
|
#define X {NotMapped}
|
||||||
static Key key_sequences[][3] = {
|
static KeySequence key_sequences[] = {
|
||||||
/* NUL */ X, /* SOH */ X,
|
/* NUL */ X, /* SOH */ X,
|
||||||
/* STX */ X, /* ETX */ X,
|
/* STX */ X, /* ETX */ X,
|
||||||
/* EOT */ X, /* ENQ */ X,
|
/* EOT */ X, /* ENQ */ X,
|
||||||
@ -73,7 +73,5 @@ uint16_t *Oric::Machine::sequence_for_character(Utility::Typer *typer, char char
|
|||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
if(character > sizeof(key_sequences) / sizeof(*key_sequences)) return nullptr;
|
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
||||||
if(key_sequences[character][0] == NotMapped) return nullptr;
|
|
||||||
return (uint16_t *)key_sequences[character];
|
|
||||||
}
|
}
|
||||||
|
@ -77,3 +77,10 @@ bool Typer::Delegate::typer_set_next_character(Utility::Typer *typer, char chara
|
|||||||
uint16_t *Typer::Delegate::sequence_for_character(Typer *typer, char character) {
|
uint16_t *Typer::Delegate::sequence_for_character(Typer *typer, char character) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t *Typer::Delegate::table_lookup_sequence_for_character(KeySequence *sequences, size_t length, char character) {
|
||||||
|
size_t ucharacter = (size_t)((unsigned char)character);
|
||||||
|
if(ucharacter > (length / sizeof(KeySequence))) return nullptr;
|
||||||
|
if(sequences[ucharacter][0] == NotMapped) return nullptr;
|
||||||
|
return sequences[ucharacter];
|
||||||
|
}
|
||||||
|
@ -23,7 +23,11 @@ class Typer {
|
|||||||
|
|
||||||
virtual uint16_t *sequence_for_character(Typer *typer, char character);
|
virtual uint16_t *sequence_for_character(Typer *typer, char character);
|
||||||
|
|
||||||
|
typedef uint16_t KeySequence[16];
|
||||||
|
uint16_t *table_lookup_sequence_for_character(KeySequence *sequences, size_t length, char character);
|
||||||
|
|
||||||
const uint16_t EndSequence = 0xffff;
|
const uint16_t EndSequence = 0xffff;
|
||||||
|
const uint16_t NotMapped = 0xfffe;
|
||||||
};
|
};
|
||||||
|
|
||||||
Typer(const char *string, int delay, int frequency, Delegate *delegate);
|
Typer(const char *string, int delay, int frequency, Delegate *delegate);
|
||||||
|
@ -9,11 +9,10 @@
|
|||||||
#include "ZX8081.hpp"
|
#include "ZX8081.hpp"
|
||||||
|
|
||||||
uint16_t *ZX8081::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
uint16_t *ZX8081::Machine::sequence_for_character(Utility::Typer *typer, char character) {
|
||||||
#define KEYS(...) {__VA_ARGS__, TerminateSequence}
|
#define KEYS(...) {__VA_ARGS__, EndSequence}
|
||||||
#define SHIFT(...) {KeyShift, __VA_ARGS__, TerminateSequence}
|
#define SHIFT(...) {KeyShift, __VA_ARGS__, EndSequence}
|
||||||
#define X {NotMapped}
|
#define X {NotMapped}
|
||||||
typedef Key KeyTable[126][3];
|
static KeySequence zx81_key_sequences[] = {
|
||||||
KeyTable zx81_key_sequences = {
|
|
||||||
/* NUL */ X, /* SOH */ X,
|
/* NUL */ X, /* SOH */ X,
|
||||||
/* STX */ X, /* ETX */ X,
|
/* STX */ X, /* ETX */ X,
|
||||||
/* EOT */ X, /* ENQ */ X,
|
/* EOT */ X, /* ENQ */ X,
|
||||||
@ -79,7 +78,7 @@ uint16_t *ZX8081::Machine::sequence_for_character(Utility::Typer *typer, char ch
|
|||||||
/* | */ X, /* } */ X,
|
/* | */ X, /* } */ X,
|
||||||
};
|
};
|
||||||
|
|
||||||
KeyTable zx80_key_sequences = {
|
static KeySequence zx80_key_sequences[] = {
|
||||||
/* NUL */ X, /* SOH */ X,
|
/* NUL */ X, /* SOH */ X,
|
||||||
/* STX */ X, /* ETX */ X,
|
/* STX */ X, /* ETX */ X,
|
||||||
/* EOT */ X, /* ENQ */ X,
|
/* EOT */ X, /* ENQ */ X,
|
||||||
@ -148,10 +147,8 @@ uint16_t *ZX8081::Machine::sequence_for_character(Utility::Typer *typer, char ch
|
|||||||
#undef SHIFT
|
#undef SHIFT
|
||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
size_t ucharacter = (size_t)character;
|
if(is_zx81_)
|
||||||
if(ucharacter > sizeof(zx81_key_sequences) / sizeof(*zx81_key_sequences)) return nullptr;
|
return table_lookup_sequence_for_character(zx81_key_sequences, sizeof(zx81_key_sequences), character);
|
||||||
|
else
|
||||||
KeyTable *table = is_zx81_ ? &zx81_key_sequences : &zx80_key_sequences;
|
return table_lookup_sequence_for_character(zx80_key_sequences, sizeof(zx80_key_sequences), character);
|
||||||
if((*table)[ucharacter][0] == NotMapped) return nullptr;
|
|
||||||
return (uint16_t *)(*table)[ucharacter];
|
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,6 @@ enum Key: uint16_t {
|
|||||||
KeyP = 0x0500 | 0x01, KeyO = 0x0500 | 0x02, KeyI = 0x0500 | 0x04, KeyU = 0x0500 | 0x08, KeyY = 0x0500 | 0x10,
|
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,
|
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,
|
KeySpace = 0x0700 | 0x01, KeyDot = 0x0700 | 0x02, KeyM = 0x0700 | 0x04, KeyN = 0x0700 | 0x08, KeyB = 0x0700 | 0x10,
|
||||||
|
|
||||||
TerminateSequence = 0xffff, NotMapped = 0xfffe
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Machine:
|
class Machine:
|
||||||
|
Loading…
Reference in New Issue
Block a user