Skip to content

Commit

Permalink
Relax KeyboardTracer's requirement for spaces between key specs
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Jul 22, 2023
1 parent 42750e8 commit ffc872d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 30 deletions.
56 changes: 54 additions & 2 deletions skoolkit/kbtracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,49 @@
}

TOKENS = {
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
'0': '0',

'a': 'a',
'b': 'b',
'c': 'c',
'd': 'd',
'e': 'e',
'f': 'f',
'g': 'g',
'h': 'h',
'i': 'i',
'j': 'j',
'k': 'k',
'l': 'l',
'm': 'm',
'n': 'n',
'o': 'o',
'p': 'p',
'q': 'q',
'r': 'r',
's': 's',
't': 't',
'u': 'u',
'v': 'v',
'w': 'w',
'x': 'x',
'y': 'y',
'z': 'z',

'CS': 'CS', # CAPS SHIFT
'SS': 'SS', # SYMBOL SHIFT
'SPACE': 'SPACE',
'ENTER': 'ENTER',

'DOWN': 'CS+6', # Cursor down

'A': 'CS+a',
Expand Down Expand Up @@ -213,7 +256,7 @@
'INVERSE': 'CS+SS SS+m',
'OVER': 'CS+SS SS+n',
'OUT': 'CS+SS SS+o',
'(C)': 'CS+SS SS+p', # ©
'©': 'CS+SS SS+p',
'ASN': 'CS+SS SS+q',
'VERIFY': 'CS+SS SS+r',
'|': 'CS+SS SS+s',
Expand All @@ -233,7 +276,16 @@ def get_keys(keyspecs, delay): # pragma: no cover

specs = []
for spec in keyspecs:
specs.extend(TOKENS.get(spec, spec).split())
if '+' in spec:
specs.append(spec)
elif spec in TOKENS:
specs.extend(TOKENS[spec].split())
else:
try:
for k in spec:
specs.extend(TOKENS[k].split())
except KeyError as ke:
raise SkoolKitError(f'Unrecognised token: {ke.args[0]}')

for spec in specs:
kb = {}
Expand Down
14 changes: 9 additions & 5 deletions skoolkit/tap2sna.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,15 @@ def _print_sim_load_config_help():
By default, the simulated LOAD begins by executing either 'LOAD ""' or
'LOAD ""CODE' (depending on whether the tape begins with a Bytes block). If
an alternative command line is required to load the tape, it can be specified
by this parameter, where KEYS is a space-separated list of keys to press.
Each alphanumeric key is denoted by its digit or letter. Multiple
simultaneous keypresses are denoted by separating them with '+'. All BASIC
tokens except those that contain a space are recognised. The following
special tokens are also recognised:
by this parameter. KEYS is a space-separated list of 'words' (a 'word' being
a sequence of any characters other than space), each of which is broken down
into a sequence of one or more keypresses. If a word contains the '+' symbol,
the tokens it separates are converted into keypresses made simultaneously. If
a word matches a BASIC token, the corresponding sequence of keypresses to
produce that token are substituted. Otherwise, each character in the word is
converted individually into the appropriate keypresses.
The following special tokens are also recognised:
CS - CAPS SHIFT
SS - SYMBOL SHIFT
Expand Down
24 changes: 13 additions & 11 deletions sphinx/source/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1496,12 +1496,15 @@ loop accelerators are:

The ``load`` parameter may be used to specify an alternative command line to
load the tape in cases where neither 'LOAD ""' nor 'LOAD ""CODE' works. Its
value is a space-separated list of keys to press to build the command line.
Each alphanumeric key is denoted by its digit or letter. Multiple simultaneous
keypresses are denoted by separating them with '+'. All BASIC tokens except
those that contain a space are translated into their corresponding digit,
letter, special key or combination thereof. The following special tokens are
also recognised:
value is a space-separated list of 'words' (a 'word' being a sequence of any
characters other than space), each of which is broken down into a sequence of
one or more keypresses. If a word contains the '+' symbol, the tokens it
separates are converted into keypresses made simultaneously. If a word matches
a BASIC token, the corresponding sequence of keypresses to produce that token
are substituted. Otherwise, each character in the word is converted
individually into the appropriate keypresses.

The following special tokens are also recognised:

* ``CS`` - CAPS SHIFT
* ``SS`` - SYMBOL SHIFT
Expand All @@ -1521,13 +1524,12 @@ Spectrum). The simulated LOAD begins at this address.

``ENTER`` is automatically appended to the command line if not already present.

For example::

CLEAR 3 5 0 0 0 : LOAD " "
For example, the ``load`` parameter may be set to::

With this value, the ``load`` parameter sets the command line to::
CLEAR 34999: LOAD "" CODE : RANDOMIZE USR 35000

CLEAR 35000: LOAD ""
Note that the spaces around ``CLEAR``, ``LOAD``, ``CODE``, ``RANDOMIZE`` and
``USR`` are required in order for them to be recognised as BASIC tokens.

.. _tap2sna-conf:

Expand Down
25 changes: 13 additions & 12 deletions sphinx/source/man/tap2sna.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,15 @@ loop accelerators are:
The ``load`` parameter may be used to specify an alternative command line to
load the tape in cases where neither 'LOAD ""' nor 'LOAD ""CODE' works. Its
value is a space-separated list of keys to press to build the command line.
Each alphanumeric key is denoted by its digit or letter. Multiple simultaneous
keypresses are denoted by separating them with '+'. All BASIC tokens except
those that contain a space are translated into their corresponding digit,
letter, special key or combination thereof. The following special tokens are
also recognised:
value is a space-separated list of 'words' (a 'word' being a sequence of any
characters other than space), each of which is broken down into a sequence of
one or more keypresses. If a word contains the '+' symbol, the tokens it
separates are converted into keypresses made simultaneously. If a word matches
a BASIC token, the corresponding sequence of keypresses to produce that token
are substituted. Otherwise, each character in the word is converted
individually into the appropriate keypresses.

The following special tokens are also recognised:

|
| ``CS`` - CAPS SHIFT
Expand All @@ -254,15 +257,13 @@ Spectrum). The simulated LOAD begins at this address.

``ENTER`` is automatically appended to the command line if not already present.

For example:
For example, the ``load`` parameter may be set to:

|
| CLEAR 3 5 0 0 0 : LOAD " "
| CLEAR 34999: LOAD "" CODE : RANDOMIZE USR 35000
With this value, the ``load`` parameter sets the command line to:

|
| CLEAR 35000: LOAD ""
Note that the spaces around ``CLEAR``, ``LOAD``, ``CODE``, ``RANDOMIZE`` and
``USR`` are required in order for them to be recognised as BASIC tokens.

CALL OPERATIONS
===============
Expand Down

0 comments on commit ffc872d

Please sign in to comment.