![]() |
The ZX Ecosystem v5.1.0;_GUI_v3.1.0
|
Provides the ZX keyboard behavior.
NOTE:
-The classes in this module are not thread-safe.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Namespaces | |
namespace | zxeco |
The main namespace of the library, that spans across all the zx modules. | |
Classes | |
class | zxeco::KeyComb |
A combination of 2 keys. More... | |
class | zxeco::SetOfKeys |
A set of several keys, not repeated. More... | |
class | zxeco::Membrane |
The zx keyboard as a membrane. Useful for games and those sort of things. More... | |
class | zxeco::Membrane::KeyInRow |
Complete definition of a key in the membrane. More... | |
class | zxeco::Keyboard |
The ZX keyboard as it behaves (for typing) under the ZX operating system. More... | |
class zxeco::KeyComb |
A combination of 2 keys.
This represents 2 keys pressed simultaneously, one of them being a shift. It can be invalid (not all such combinations have sense).
Definition at line 130 of file ZXKeyboard.h.
Public Member Functions | |
KeyComb (void) noexcept | |
Default constructor: an invalid combination. More... | |
KeyComb (Key shift, Key other) | |
Constructor of a combination with the given SHIFT and OTHER keys. More... | |
virtual | ~KeyComb (void)=default |
Destructor. | |
bool | valid (void) const noexcept |
Return TRUE if the combination is a valid one. More... | |
bool | is (Key shift, Key other) const |
Whether this combination is composed concretely of SHIFT + OTHER. More... | |
Key | shift (void) const |
Return the shift key if valid; raise an exception otherwise. | |
Key | other (void) const |
Return the other key if valid; raise an exception otherwise. | |
std::string | to_string (void) const noexcept |
Convert the combination to a string. | |
|
inlinenoexcept |
Default constructor: an invalid combination.
Definition at line 134 of file ZXKeyboard.h.
Constructor of a combination with the given SHIFT and OTHER keys.
If the combination is invalid, this is set to invalid.
NOTE:
-If the combination is symbol (the shift) + caps (the other), it will be transformed into caps (the shift) + symbol (the other).
|
inlinenoexcept |
Return TRUE if the combination is a valid one.
Definition at line 149 of file ZXKeyboard.h.
class zxeco::SetOfKeys |
A set of several keys, not repeated.
Definition at line 182 of file ZXKeyboard.h.
Public Types | |
typedef std::set< Key > | Base |
Just syntactic sugar. More... | |
Public Member Functions | |
SetOfKeys (void)=default | |
Default constructor: an empty set of keys. | |
SetOfKeys (const KeyComb &kc) | |
Constructor from a given combination, or empty if KC is invalid. | |
SetOfKeys (const Base &b) | |
Constructor from an initialized set of keys. More... | |
KeyComb | toKeyComb (void) const noexcept |
Conversion to a combination of keys. More... | |
std::string | to_string (void) const noexcept |
Return a string describing the set of keys. | |
typedef std::set<Key> zxeco::SetOfKeys::Base |
Just syntactic sugar.
Definition at line 186 of file ZXKeyboard.h.
|
inline |
Constructor from an initialized set of keys.
This allows us to use initializer lists for SetOfKeys, as long as they are a Base.
Definition at line 194 of file ZXKeyboard.h.
class zxeco::Membrane |
The zx keyboard as a membrane. Useful for games and those sort of things.
Definition at line 218 of file ZXKeyboard.h.
Public Types | |
enum | HalfRow { CAPS_V = 0 , A_G , Q_T , ONE_FIVE , ZERO_SIX , P_Y , ENTER_H , SPC_B , NUMHALFROWS } |
Half-rows that form the membrane of the zx, in the same order as ZX port. More... | |
enum | RowMask : unsigned char { MK1 = 1 , MK2 = 1 << 1 , MK3 = 1 << 2 , MK4 = 1 << 3 , MK5 = 1 << 4 } |
Constants that are useful to select a key within a half row. More... | |
Static Public Attributes | |
static constexpr unsigned char | KEYSPERROW = 5 |
Number of keys per half row. More... | |
static constexpr uint8_t | MASKKEYS = 0x1F |
Constant that serves to mask out non-keys bits from a half row status. More... | |
Public Attributes | |
unsigned char | krows [NUMHALFROWS] |
The membrane status. More... | |
Public Member Functions | |
-------------— Constructors ----------------— | |
Membrane (void) noexcept | |
Default constructor: the entire membrane is set to 0. More... | |
virtual | ~Membrane (void)=default |
Destructor. | |
-------------— Membrane methods ---------------— | |
void | clear (void) noexcept |
Clear all keys pressed. More... | |
unsigned char | numKeysPressed (void) const noexcept |
Get number of keys pressed. More... | |
bool | someKeyUnpressed (const Membrane &oth) const noexcept |
Check if this has keys of OTH unpressed. More... | |
bool | someKeyPressed (const Membrane &oth) const noexcept |
Check if this has keys additionaly pressed to the ones of OTH. More... | |
bool | someNewKeyPressed (const Membrane &oth) const noexcept |
Check if OTH keys pressed that are not pressed in this. More... | |
-------------— Key-based methods ---------------— | |
void | setKeyState (Key k, bool pressed=true) |
Change the press state of K to PRESSED. Exception if K is invalid. | |
void | setKeyState (const SetOfKeys &soks, bool pressed=true) |
Change the press state of the entire set SOKS to PRESSED. | |
void | setKeyState (const KeyComb &kc, bool pressed=true) |
Change the press state of the combination KC to PRESSED. | |
bool | keyState (Key k) const noexcept |
Return the state of key K in the membrane. FALSE if K is invalid. | |
SetOfKeys | keysPressed (void) const noexcept |
Return the set of keys that are pressed currently in the membrane. | |
KeyComb | combinationPressed (void) const noexcept |
Get the combination that is currently pressed in the membrane, if any. More... | |
-------------— Logical comparisons -------------— | |
Return TRUE(FALSE) if krows are not in the same (different) state in OTH and in THIS. | |
bool | operator!= (const Membrane &oth) const noexcept |
bool | operator== (const Membrane &oth) const noexcept |
-------------— Logical operations -------------— | |
(Unused bits will be set to 0 in the results) | |
Membrane & | operator^= (const Membrane &oth) noexcept |
XOR + assignment. | |
Membrane & | operator&= (const Membrane &oth) noexcept |
< XOR. More... | |
Membrane & | operator|= (const Membrane &oth) noexcept |
OR + assignment. | |
Membrane | operator~ (void) noexcept |
NOT. | |
std::string | to_string (void) const noexcept |
Return a string representing the Membrane. | |
Membrane | operator^ (Membrane lhs, const Membrane &rhs) noexcept |
XOR + assignment. More... | |
Membrane | operator& (Membrane lhs, const Membrane &rhs) noexcept |
AND. More... | |
Membrane | operator| (Membrane lhs, const Membrane &rhs) noexcept |
OR. More... | |
Half-rows that form the membrane of the zx, in the same order as ZX port.
Definition at line 226 of file ZXKeyboard.h.
enum zxeco::Membrane::RowMask : unsigned char |
Constants that are useful to select a key within a half row.
Enumerator | |
---|---|
MK1 | First key (outer) in a HalfRow. |
MK2 | Second key. |
MK3 | Third key. |
MK4 | Fourth key. |
MK5 | Fifth key (inner). |
Definition at line 242 of file ZXKeyboard.h.
|
inlinenoexcept |
Default constructor: the entire membrane is set to 0.
Definition at line 297 of file ZXKeyboard.h.
|
inlinenoexcept |
Clear all keys pressed.
Definition at line 309 of file ZXKeyboard.h.
|
noexcept |
Get number of keys pressed.
Scan the krows attribute to calculate the number of keys currently pressed in the membrane.
|
noexcept |
Check if this has keys of OTH unpressed.
Return TRUE if OTH's krows is the same as this' but with some key(s) additionally unpressed.
|
noexcept |
Check if this has keys additionaly pressed to the ones of OTH.
Return TRUE if OTH's krows is the same as this' but with some key(s) additionally pressed.
|
noexcept |
|
noexcept |
Get the combination that is currently pressed in the membrane, if any.
Scan the krows attribute to detect the combination currently pressed in the map (or an invalid one if none is found or some is found but with additional keys pressed).
|
inlinenoexcept |
Definition at line 366 of file ZXKeyboard.h.
XOR + assignment.
Definition at line 380 of file ZXKeyboard.h.
AND.
Definition at line 392 of file ZXKeyboard.h.
OR.
Definition at line 399 of file ZXKeyboard.h.
|
staticconstexpr |
Number of keys per half row.
Definition at line 238 of file ZXKeyboard.h.
|
staticconstexpr |
Constant that serves to mask out non-keys bits from a half row status.
Apply this and-mask to the status of a half row to clean unused bits.
Definition at line 252 of file ZXKeyboard.h.
unsigned char zxeco::Membrane::krows[NUMHALFROWS] |
The membrane status.
One byte per half-row and per key (0->unpressed, 1->pressed). This must be externally filled/updated. Its layout is exactly the same as in the original ZX but with the pressed/unpressed state inverted.
Definition at line 290 of file ZXKeyboard.h.
class zxeco::Membrane::KeyInRow |
Complete definition of a key in the membrane.
It consists of a half row plus the mask to get the key state. You can reach the two elements of the pair through .first and .second vars.
Definition at line 258 of file ZXKeyboard.h.
Public Types | |
typedef std::pair< HalfRow, RowMask > | Base |
Just sugar. More... | |
Static Public Member Functions | |
static void | checkPair (const Base &b) |
Throw an exception if B contains an invalid half row or mask. | |
Public Member Functions | |
KeyInRow (HalfRow h=CAPS_V, RowMask m=MK1) | |
Default constructor, and from row and mask. Exception if invalid. | |
KeyInRow (Key k) | |
Constructor from a key id. Exception if K is invalid. | |
KeyInRow (const Base &b) | |
Constructor from base object. Exception if invalid. More... | |
virtual | ~KeyInRow (void)=default |
Destructor. | |
operator Key (void) const | |
Convert this pair to a key identifier. Exception if invalid. | |
typedef std::pair<HalfRow,RowMask> zxeco::Membrane::KeyInRow::Base |
Just sugar.
Definition at line 262 of file ZXKeyboard.h.
|
inline |
Constructor from base object. Exception if invalid.
Definition at line 271 of file ZXKeyboard.h.
class zxeco::Keyboard |
The ZX keyboard as it behaves (for typing) under the ZX operating system.
It is a view built upon Membrane, but this keyboard, unlike the Membrane, has history. Its current state depends on successive instantaneous Membranes that are fed into it at the pace the user of this class sets (for instance, changing current state (E,C,K,...) depends on the previous state, not only on the keys pressed now).
Definition at line 426 of file ZXKeyboard.h.
Public Types | |
enum class | Mode { NORMAL = 0 , EXTENDED , GRAPHICS , NUMMODES } |
The keyboard modes recognized by the zx operating system. More... | |
Static Public Member Functions | |
static uint8_t | keyToASCII (Mode km, bool capslock, Key shift, Key k) |
Return the ASCII code correponding to the given key pressing SHIFT + K. More... | |
Public Member Functions | |
-------------— Constructors --------------— | |
(Leave other constructors by default) | |
Keyboard (const Membrane &mem0=Membrane{}) | |
Default constructor. No key pressed, no capslock, NORMAL mode. More... | |
virtual | ~Keyboard (void)=default |
Destructor. | |
-------------— Setter methods --------------— | |
void | reset (void) |
Reset the keyboard to its initial state: key pressed, NO_KEY. | |
void | setKeyRepetitions (std::chrono::steady_clock::duration repdel=std::chrono::milliseconds{700}, std::chrono::steady_clock::duration repper=std::chrono::milliseconds{100}) noexcept |
Set key repetition parameters. More... | |
bool | newMembrane (const Membrane &newmembrane, std::string *lastprstr=nullptr) |
Update state of the keyboard from the given Membrane. More... | |
-------------— Getter methods --------------— | |
void | keyRepetitions (std::chrono::steady_clock::duration &repdel, std::chrono::steady_clock::duration &repper) const noexcept |
Fill both arguments with the current repetition parameters. More... | |
Mode | mode (void) const noexcept |
Return the current keyboard mode. More... | |
bool | capsLock (void) const noexcept |
Return the current capslock state. More... | |
std::chrono::steady_clock::time_point | lastEffectiveChange (void) const noexcept |
Get the time of the last change that was recognized by the keyboard. More... | |
const Membrane & | lastMembrane (void) const noexcept |
Return the last membrane that this Keyboard is aware of. More... | |
Key | lastKey (void) const noexcept |
Get the key pressed in the last membrane fed into this keyboard. More... | |
KeyComb | lastKeyComb (void) const noexcept |
Get the combination of keys pressed in the last membrane fed into this. More... | |
bool | anyKey (void) const noexcept |
Return TRUE if a key or combination of keys were pressed in last membr. More... | |
-------------— Miscellaneous methods --------------— | |
std::string | to_string (void) const noexcept |
Return a string representing the whole keyboard state. | |
|
strong |
The keyboard modes recognized by the zx operating system.
Enumerator | |
---|---|
NORMAL | Normal mode (C or L). |
EXTENDED | Extended mode (E). |
GRAPHICS | Graphics mode (G). |
Definition at line 434 of file ZXKeyboard.h.
Default constructor. No key pressed, no capslock, NORMAL mode.
MEM0 becomes the initial state of the keys.
Definition at line 451 of file ZXKeyboard.h.
Return the ASCII code correponding to the given key pressing SHIFT + K.
Assume keyboard state is mode = KM, capslock = CAPSLOCK. Return 0 if there is no ascii code for that pressing.
|
inlinenoexcept |
Set key repetition parameters.
Change repetition times. REPDEL is the delay from the time when a key is first pressed to the time when it should begin to repeat automatically; REPPER is the period of those repetitions. Their default values are the ones of the original ZX after start-up.
Definition at line 466 of file ZXKeyboard.h.
bool zxeco::Keyboard::newMembrane | ( | const Membrane & | newmembrane, |
std::string * | lastprstr = nullptr |
||
) |
Update state of the keyboard from the given Membrane.
Update state of the keyboard (mode, capslock, etc.) based on the new membrane state given by NEWMEMBRANE, that is assumed to have been read right now (i.e., there have been no changes in the membrane since the last call to this method). If more than two simultaneous changes (i.e., more than two keys simultaneously pressed) are detected in the membrane, return FALSE and do not update the state, since a too slow sampling of the keyboard is assumed. The lastKey() and lastKeyComb() are updated with the key pressed in this new membrane. If LASTPRSTR != nullptr, fill it in with the string that corresponds to the last pressed key or keycomb, according to the mode in which the keyboard was when they were pressed.
|
inlinenoexcept |
Fill both arguments with the current repetition parameters.
Definition at line 499 of file ZXKeyboard.h.
|
inlinenoexcept |
Return the current keyboard mode.
Definition at line 505 of file ZXKeyboard.h.
|
inlinenoexcept |
Return the current capslock state.
Definition at line 508 of file ZXKeyboard.h.
|
inlinenoexcept |
Get the time of the last change that was recognized by the keyboard.
Return a copy of the last time were an effective change in the state of some key or of the keyboard state/capslock was recorded, or an undefined value if no change has occurred yet.
Definition at line 511 of file ZXKeyboard.h.
|
inlinenoexcept |
Return the last membrane that this Keyboard is aware of.
Definition at line 518 of file ZXKeyboard.h.
|
inlinenoexcept |
Get the key pressed in the last membrane fed into this keyboard.
If the latest event was pressing a single key, return it; otherwise, return Key::NO_KEY. This and the next methods are exclusive: if one of them provides a positive answer, the other one does not.
Definition at line 522 of file ZXKeyboard.h.
|
inlinenoexcept |
Get the combination of keys pressed in the last membrane fed into this.
If the last event was pressing a key combination, return it; otherwise, return an invalid one. This and the previous methods are exclusive: if one of them provides a positive answer, the other one does not.
Definition at line 528 of file ZXKeyboard.h.
|
inlinenoexcept |
Return TRUE if a key or combination of keys were pressed in last membr.
Definition at line 535 of file ZXKeyboard.h.
bool zxeco::Keyboard::keyorkeycomb |
Definition at line 553 of file ZXKeyboard.h.
Key zxeco::Keyboard::key |
Definition at line 554 of file ZXKeyboard.h.
KeyComb zxeco::Keyboard::keycomb |
Definition at line 555 of file ZXKeyboard.h.