Skip to content

Commit

Permalink
Make tap2sna.py track and record AY state
Browse files Browse the repository at this point in the history
At least one game requires this: Tai-Pan (Ocean).
  • Loading branch information
skoolkid committed Jul 20, 2023
1 parent f15dc7e commit 35aa71d
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions skoolkit/kbtracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def __init__(self, simulator, keys, delay):
self.keys = get_keys(keys, delay)
self.border = 7
self.out7ffd = 0
self.outfffd = 0
self.ay = [0] * 16

def run(self, stop):
simulator = self.simulator
Expand Down
4 changes: 3 additions & 1 deletion skoolkit/loadtracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_edges(blocks, first_edge, analyse=False):

class LoadTracer(PagingTracer):
def __init__(self, simulator, blocks, accelerators, pause, first_edge, finish_tape,
in_min_addr, accel_dec_a, list_accelerators, border, out7ffd):
in_min_addr, accel_dec_a, list_accelerators, border, out7ffd, outfffd, ay):
self.accelerators = defaultdict(int)
self.inc_b_misses = 0
self.dec_b_misses = 0
Expand Down Expand Up @@ -202,6 +202,8 @@ def __init__(self, simulator, blocks, accelerators, pause, first_edge, finish_ta
self.custom_loader = False
self.border = border
self.out7ffd = out7ffd
self.outfffd = outfffd
self.ay = ay
self.text = TextReader()

def run(self, stop, fast_load, timeout, trace, trace_line, prefix, byte_fmt, word_fmt):
Expand Down
4 changes: 4 additions & 0 deletions skoolkit/pagingtracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ def write_port(self, registers, port, value):
if isinstance(memory, Memory):
memory.out7ffd(value)
self.out7ffd = value
elif port == 0xFFFD: # pragma: no cover
self.outfffd = value
elif port == 0xBFFD: # pragma: no cover
self.ay[self.outfffd % 16] = value
7 changes: 7 additions & 0 deletions skoolkit/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def set_z80_state(z80, *specs):
z80[55:58] = (t1 % 256, t1 // 256, (2 - t2) % 4)
elif name == '7ffd': # pragma: no cover
z80[35] = get_int_param(val) & 255
elif name == 'fffd': # pragma: no cover
z80[38] = get_int_param(val) & 255
elif name.startswith('ay[') and name.endswith(']'): # pragma: no cover
r = get_int_param(name[3:-1]) & 15
z80[39 + r] = get_int_param(val) & 255
else:
raise SkoolKitError("Invalid parameter: {}".format(spec))
except ValueError:
Expand All @@ -200,7 +205,9 @@ def print_state_help(short_option=None, show_defaults=True):
Set a hardware state attribute. Recognised names {infix}are:
7ffd - last OUT to port 0x7ffd (128K only)
ay[N] - contents of AY register N (N=0-15; 128K only)
border - border colour{border}
fffd - last OUT to port 0xfffd (128K only)
iff - interrupt flip-flop: 0=disabled, 1=enabled{iff}
im - interrupt mode{im}
issue2 - issue 2 emulation: 0=disabled, 1=enabled{issue2}
Expand Down
10 changes: 8 additions & 2 deletions skoolkit/tap2sna.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ def sim_load(blocks, options, config):
tracer.run(stop)
border = tracer.border
out7ffd = tracer.out7ffd
outfffd = tracer.outfffd
ay = tracer.ay
except KeyboardInterrupt:
write_line(f'Simulation stopped (interrupted): PC={simulator.registers[PC]}')
interrupted = True
Expand All @@ -388,6 +390,8 @@ def sim_load(blocks, options, config):
simulator = Simulator(memory, {'PC': 0x0605, 'SP': 0xFF50})
border = 7
out7ffd = 0
outfffd = 0
ay = [0] * 16

if not interrupted:
if options.contended_in: # pragma: no cover
Expand All @@ -396,7 +400,7 @@ def sim_load(blocks, options, config):
in_min_addr = 0x8000
tracer = LoadTracer(simulator, blocks, accelerators, options.pause, options.first_edge,
options.finish_tape, in_min_addr, options.accelerate_dec_a, list_accelerators,
border, out7ffd)
border, out7ffd, outfffd, ay)
simulator.set_tracer(tracer, False, False)
op_fmt = config['TraceOperand']
prefix, byte_fmt, word_fmt = (op_fmt + ',' * (2 - op_fmt.count(','))).split(',')[:3]
Expand Down Expand Up @@ -440,8 +444,10 @@ def sim_load(blocks, options, config):
f'im={simulator.imode}',
f'iff={simulator.iff}',
f'border={tracer.border}',
f'7ffd={tracer.out7ffd}'
f'7ffd={tracer.out7ffd}',
f'fffd={tracer.outfffd}'
]
state.extend(f'ay[{r}]={v}' for r, v in enumerate(tracer.ay))
options.state = state + options.state
if isinstance(memory, Memory):
return memory.banks # pragma: no cover
Expand Down
2 changes: 2 additions & 0 deletions sphinx/source/man/bin2sna.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ Recognised attribute names and their default values are:

|
| ``7ffd`` - last OUT to port 0x7ffd (128K only)
| ``ay[N]`` - contents of AY register N (N=0-15; 128K only)
| ``border`` - border colour (default=0)
| ``fffd`` - last OUT to port 0xfffd (128K only)
| ``iff`` - interrupt flip-flop: 0=disabled, 1=enabled (default=1)
| ``im`` - interrupt mode (default=1)
| ``issue2`` - issue 2 emulation: 0=disabled, 1=enabled (default=0)
Expand Down
2 changes: 2 additions & 0 deletions sphinx/source/man/snapmod.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ Recognised attribute names are:

|
| ``7ffd`` - last OUT to port 0x7ffd (128K only)
| ``ay[N]`` - contents of AY register N (N=0-15; 128K only)
| ``border`` - border colour
| ``fffd`` - last OUT to port 0xfffd (128K only)
| ``iff`` - interrupt flip-flop: 0=disabled, 1=enabled
| ``im`` - interrupt mode
| ``issue2`` - issue 2 emulation: 0=disabled, 1=enabled
Expand Down
2 changes: 2 additions & 0 deletions sphinx/source/man/tap2sna.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ Recognised attribute names and their default values are:

|
| ``7ffd`` - last OUT to port 0x7ffd (128K only)
| ``ay[N]`` - contents of AY register N (N=0-15; 128K only)
| ``border`` - border colour (default=0)
| ``fffd`` - last OUT to port 0xfffd (128K only)
| ``iff`` - interrupt flip-flop: 0=disabled, 1=enabled (default=1)
| ``im`` - interrupt mode (default=1)
| ``issue2`` - issue 2 emulation: 0=disabled, 1=enabled (default=0)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_bin2sna.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ def test_option_state_help(self):
Set a hardware state attribute. Recognised names and their default values are:
7ffd - last OUT to port 0x7ffd (128K only)
ay[N] - contents of AY register N (N=0-15; 128K only)
border - border colour (default=0)
fffd - last OUT to port 0xfffd (128K only)
iff - interrupt flip-flop: 0=disabled, 1=enabled (default=1)
im - interrupt mode (default=1)
issue2 - issue 2 emulation: 0=disabled, 1=enabled (default=0)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_snapmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ def test_state_help(self):
Set a hardware state attribute. Recognised names are:
7ffd - last OUT to port 0x7ffd (128K only)
ay[N] - contents of AY register N (N=0-15; 128K only)
border - border colour
fffd - last OUT to port 0xfffd (128K only)
iff - interrupt flip-flop: 0=disabled, 1=enabled
im - interrupt mode
issue2 - issue 2 emulation: 0=disabled, 1=enabled
Expand Down
2 changes: 2 additions & 0 deletions tests/test_tap2sna.py
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,9 @@ def test_state_help(self):
Set a hardware state attribute. Recognised names and their default values are:
7ffd - last OUT to port 0x7ffd (128K only)
ay[N] - contents of AY register N (N=0-15; 128K only)
border - border colour (default=0)
fffd - last OUT to port 0xfffd (128K only)
iff - interrupt flip-flop: 0=disabled, 1=enabled (default=1)
im - interrupt mode (default=1)
issue2 - issue 2 emulation: 0=disabled, 1=enabled (default=0)
Expand Down

0 comments on commit 35aa71d

Please sign in to comment.