Skip to content

Commit

Permalink
Add the 'finish-tape' config parameter for 'tap2sna.py --sim-load'
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Apr 14, 2023
1 parent 9614d2b commit 130b0a6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
5 changes: 3 additions & 2 deletions skoolkit/loadtracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ def get_edges(blocks, first_edge):
return edges, indexes, data_blocks

class LoadTracer:
def __init__(self, simulator, blocks, accelerator, pause, first_edge):
def __init__(self, simulator, blocks, accelerator, pause, first_edge, finish_tape):
self.simulator = simulator
self.edges, self.indexes, self.blocks = get_edges(blocks, first_edge)
self.accelerator = accelerator
self.pause = pause
self.finish_tape = finish_tape
self.announce_data = True
opcodes = simulator.opcodes
memory = simulator.memory
Expand Down Expand Up @@ -184,7 +185,7 @@ def run(self, start, stop, fast_load, trace, timeout):

pc = registers[24]

if pc == stop:
if pc == stop and (self.end_of_tape or not self.finish_tape):
write_line(f'Simulation stopped (PC at start address): PC={pc}')
break

Expand Down
17 changes: 13 additions & 4 deletions skoolkit/tap2sna.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def _ram_operations(snapshot, ram_ops, blocks=None):
def _set_sim_load_config(options):
options.accelerator = None
options.fast_load = True
options.finish_tape = False
options.first_edge = -2168
options.pause = True
options.timeout = 900
Expand All @@ -290,6 +291,8 @@ def _set_sim_load_config(options):
options.accelerator = value
elif name == 'fast-load': # pragma: no cover
options.fast_load = parse_int(value, options.fast_load)
elif name == 'finish-tape': # pragma: no cover
options.finish_tape = parse_int(value, options.finish_tape)
elif name == 'first-edge': # pragma: no cover
options.first_edge = parse_int(value, options.first_edge)
elif name == 'pause': # pragma: no cover
Expand Down Expand Up @@ -326,7 +329,7 @@ def sim_load(blocks, options):
snapshot[a + 1] = b // 256
snapshot[0xFF58:] = snapshot[0x3E08:0x3EB0] # UDGs
simulator = Simulator(snapshot, {'SP': 0xFF50})
tracer = LoadTracer(simulator, blocks, accelerator, options.pause, options.first_edge)
tracer = LoadTracer(simulator, blocks, accelerator, options.pause, options.first_edge, options.finish_tape)
simulator.set_tracer(tracer)
try:
# Begin execution at 0x0605 (SAVE-ETC)
Expand Down Expand Up @@ -782,14 +785,13 @@ def _print_sim_load_config_help():
print(f"""
Usage: --sim-load-config accelerator=NAME
--sim-load-config fast-load=0/1
--sim-load-config finish-tape=0/1
--sim-load-config first-edge=N
--sim-load-config pause=0/1
--sim-load-config timeout=N
--sim-load-config trace=FILE
Use a specific tape-sampling loop accelerator, disable fast loading, set the
location of the leading edge of the first pulse on the tape, disable pausing
between tape blocks, set the timeout, or log executed instructions to a file.
Configure various properties of a simulated LOAD.
--sim-load-config accelerator=NAME
Expand All @@ -807,6 +809,13 @@ def _print_sim_load_config_help():
reduces the load time for many tapes, but can also cause some loaders to
fail. Set fast-load=0 to disable fast loading.
--sim-load-config finish-tape=0/1
By default, the simulated LOAD stops as soon as the program counter hits the
address specified by the '--start' option (if any), regardless of whether the
tape has finished running. Set finish-tape=1 to ensure that the end of the
tape is reached before stopping the simulation at the given start address.
--sim-load-config first-edge=N
Set the time (in T-states) from the start of the tape at which to place the
Expand Down
3 changes: 3 additions & 0 deletions sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Changelog

8.10b1
------
* Added the ``finish-tape`` parameter for the ``--sim-load-config`` option of
:ref:`tap2sna.py` (to specify whether to finish the tape before stopping the
simulation at the given start address)

8.9 (2023-02-19)
----------------
Expand Down
4 changes: 4 additions & 0 deletions sphinx/source/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,10 @@ parameters are:
* ``fast-load`` - enable fast loading (``1``, the default), or disable it
(``0``); fast loading significantly reduces the load time for many tapes, but
can also cause some loaders to fail
* ``finish-tape`` - run the tape to the end before stopping the simulation at
the address specified by the ``--start`` option (``1``), or stop the
simulation as soon as that address is reached, regardless of whether the tape
has finished (``0``, the default)
* ``first-edge`` - the time (in T-states) from the start of the tape at which
to place the leading edge of the first pulse (default: ``-2168``); the
default value places the trailing edge of the first pulse at time 0, but some
Expand Down
4 changes: 4 additions & 0 deletions sphinx/source/man/tap2sna.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ parameters are:
* ``fast-load`` - enable fast loading (``1``, the default), or disable it
(``0``); fast loading significantly reduces the load time for many tapes, but
can also cause some loaders to fail
* ``finish-tape`` - run the tape to the end before stopping the simulation at
the address specified by the ``--start`` option (``1``), or stop the
simulation as soon as that address is reached, regardless of whether the tape
has finished (``0``, the default)
* ``first-edge`` - the time (in T-states) from the start of the tape at which
to place the leading edge of the first pulse (default: ``-2168``); the
default value places the trailing edge of the first pulse at time 0, but some
Expand Down
16 changes: 16 additions & 0 deletions tests/slow_test_sim_load_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ def test_excelerator(self):
'-c accelerator=excelerator --start 65492'
)

def test_finish_tape(self):
# Hits the given start address (23367) before the tape has finished
self._test_sim_load(
'https://worldofspectrum.net/pub/sinclair/games/g/Gallipoli.tzx.zip',
'Gallipoli - 48k.tzx',
'1cdd5f519c467f434e67b910e171052d',
'1ba89616d2d1e9defbb68d13e8d4293e',
{
'AF,BC,DE,HL': '0001,0000,0000,053F',
"AF',BC',DE',HL'": 'FFA9,0021,369B,2758',
'PC,SP,IX,IY': '5B47,CEEA,AF01,5C3A',
'IR,iff,im,border': '3F00,1,1,3'
},
'-c finish-tape=1 --start 23367'
)

def test_firebird_bleepload(self):
self._test_sim_load(
'https://www.worldofspectrum.org/pub/sinclair/games/b/BlackLamp.tzx.zip',
Expand Down

0 comments on commit 130b0a6

Please sign in to comment.