From ffc872db98e909df6adecea4fa741c8e69fb7793 Mon Sep 17 00:00:00 2001 From: Richard Dymond Date: Sat, 22 Jul 2023 08:51:11 -0300 Subject: [PATCH] Relax KeyboardTracer's requirement for spaces between key specs --- skoolkit/kbtracer.py | 56 ++++++++++++++++++++++++++++++-- skoolkit/tap2sna.py | 14 +++++--- sphinx/source/commands.rst | 24 +++++++------- sphinx/source/man/tap2sna.py.rst | 25 +++++++------- 4 files changed, 89 insertions(+), 30 deletions(-) diff --git a/skoolkit/kbtracer.py b/skoolkit/kbtracer.py index 4be919c8..3c703765 100644 --- a/skoolkit/kbtracer.py +++ b/skoolkit/kbtracer.py @@ -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', @@ -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', @@ -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 = {} diff --git a/skoolkit/tap2sna.py b/skoolkit/tap2sna.py index 03ed13d0..2832be3b 100644 --- a/skoolkit/tap2sna.py +++ b/skoolkit/tap2sna.py @@ -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 diff --git a/sphinx/source/commands.rst b/sphinx/source/commands.rst index 986e835b..f9ec2fe3 100644 --- a/sphinx/source/commands.rst +++ b/sphinx/source/commands.rst @@ -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 @@ -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: diff --git a/sphinx/source/man/tap2sna.py.rst b/sphinx/source/man/tap2sna.py.rst index 1592c9a2..85f40573 100644 --- a/sphinx/source/man/tap2sna.py.rst +++ b/sphinx/source/man/tap2sna.py.rst @@ -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 @@ -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 ===============