Skip to content

Commit

Permalink
Make snapinfo.py show the last OUT to port $FE in SZX snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Sep 10, 2024
1 parent 297acba commit 98bf7c4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
1 change: 1 addition & 0 deletions skoolkit/snapinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def _print_spcr(block, reg):
lines = [f'Border: {reg.border}']
if reg.machine_id > 1:
lines.append(f'Port $7FFD: {reg.out7ffd} (bank {reg.out7ffd % 8} paged into 49152-65535 C000-FFFF)')
lines.append(f'Port $FE: {reg.outfe:08b}')
return lines

def _print_z80r(block, reg):
Expand Down
1 change: 1 addition & 0 deletions sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Changelog
* Added the ``PNGScale`` configuration parameter for
:ref:`trace.py <trace-conf>` (to specify the scale factor of the PNG image)
* :ref:`snapinfo.py` now shows AY register values in 128K SZX and Z80 snapshots
and the last value written to port $FE in SZX snapshots
* Added support to the :ref:`FOREACH` macro for the ``POKEname`` special
variable
* Added support to the :ref:`LET` macro for setting individual key-value pairs
Expand Down
3 changes: 2 additions & 1 deletion sphinx/source/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,8 @@ Configuration parameters may also be set on the command line by using the
+---------+-------------------------------------------------------------------+
| Version | Changes |
+=========+===================================================================+
| 9.4 | Shows AY register values in 128K SZX and Z80 snapshots |
| 9.4 | Shows AY register values in 128K SZX and Z80 snapshots and the |
| | last value written to port $FE in SZX snapshots |
+---------+-------------------------------------------------------------------+
| 9.3 | The ``--find``, ``--find-text`` and ``--find-tile`` options |
| | search all RAM banks in a 128K snapshot by default |
Expand Down
20 changes: 12 additions & 8 deletions tests/skoolkittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,17 +674,21 @@ def write_z80(self, ram, version=3, compress=False, machine_id=0, modify=False,
def write_z80_file(self, header, ram, version=3, compress=False, machine_id=0, modify=False, out7ffd=0, pages={}, registers=None, ay=None, ret_data=False):
return self.write_z80(ram, version, compress, machine_id, modify, out7ffd, pages, header, registers, ay, ret_data)[1]

def _get_szx_header(self, machine_id=1, ch7ffd=0, specregs=True, border=0):
def _get_szx_header(self, machine_id=1, ch7ffd=0, border=0, chFe=0, specregs=True):
header = [90, 88, 83, 84] # ZXST
header.extend((1, 4)) # Version 1.4
header.append(machine_id) # 0=16K, 1=48K, 2+=128K
header.append(0) # Flags
if specregs:
header.extend((83, 80, 67, 82)) # SPCR
header.extend((8, 0, 0, 0)) # Size
header.append(border) # BORDER
header.append(ch7ffd) # Last OUT to port $7FFD
header.extend((0, 0, 0, 0, 0, 0))
header.extend((
83, 80, 67, 82, # SPCR
8, 0, 0, 0, # Size
border, # chBorder
ch7ffd, # ch7ffd
0, # ch1ffd/chEff7
chFe, # chFe
0, 0, 0, 0 # Reserved
))
return header

def _get_zxstz80regs(self, registers):
Expand All @@ -707,8 +711,8 @@ def _get_zxstrampage(self, page, compress, data):
ramp.extend(ram)
return ramp

def write_szx(self, ram, compress=True, machine_id=1, ch7ffd=0, pages={}, registers=(), border=0, keyb=False, issue2=0, ay=None, blocks=(), ret_data=False):
szx = self._get_szx_header(machine_id, ch7ffd, border=border)
def write_szx(self, ram, compress=True, machine_id=1, ch7ffd=0, pages={}, registers=(), border=0, keyb=False, issue2=0, ay=None, chFe=0, blocks=(), ret_data=False):
szx = self._get_szx_header(machine_id, ch7ffd, border, chFe)
if keyb:
szx.extend((75, 69, 89, 66)) # KEYB
szx.extend((5, 0, 0, 0)) # Size
Expand Down
22 changes: 14 additions & 8 deletions tests/test_snapinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def _test_z80(self, exp_output, options='', header=None, ram=None, version=3, co
self.assertEqual(error, '')
self.assertEqual(dedent(exp_output).lstrip(), output)

def _test_szx(self, exp_output, registers=None, border=0, keyb=False, issue2=0, ram=None, compress=False, machine_id=1, ch7ffd=0, pages=None, ay=None):
def _test_szx(self, exp_output, registers=None, border=0, keyb=False, issue2=0, ram=None, compress=False, machine_id=1, ch7ffd=0, pages=None, ay=None, chFe=0):
if ram is None:
ram = [0] * 49152
if machine_id > 1 and pages is None:
bank = (0,) * 16384
pages = {p: bank for p in (1, 3, 4, 6, 7)}
szxfile = self.write_szx(ram, compress, machine_id, ch7ffd, pages, registers, border, keyb, issue2, ay)
szxfile = self.write_szx(ram, compress, machine_id, ch7ffd, pages, registers, border, keyb, issue2, ay, chFe)
output, error = self.run_snapinfo(szxfile)
self.assertEqual(error, '')
self.assertEqual(dedent(exp_output).lstrip(), output)
Expand Down Expand Up @@ -569,6 +569,7 @@ def test_szx_16k_uncompressed(self):
Machine: 16K ZX Spectrum
SPCR: 8 bytes
Border: 1
Port $FE: 00100000
Z80R: 37 bytes
Interrupts: disabled
Interrupt mode: 1
Expand All @@ -592,7 +593,7 @@ def test_szx_16k_uncompressed(self):
Page: 5
RAM: 16384-32767 4000-7FFF: 16384 bytes, uncompressed
"""
self._test_szx(exp_output, registers, border=1, compress=False, machine_id=0)
self._test_szx(exp_output, registers, border=1, compress=False, machine_id=0, chFe=32)

def test_szx_16k_compressed(self):
registers = list(range(32, 58)) # Registers
Expand All @@ -605,6 +606,7 @@ def test_szx_16k_compressed(self):
Machine: 16K ZX Spectrum
SPCR: 8 bytes
Border: 2
Port $FE: 00010000
KEYB: 5 bytes
Issue 2 emulation: disabled
Z80R: 37 bytes
Expand All @@ -630,7 +632,7 @@ def test_szx_16k_compressed(self):
Page: 5
RAM: 16384-32767 4000-7FFF: 39 bytes, compressed
"""
self._test_szx(exp_output, registers, border=2, keyb=True, issue2=0, compress=True, machine_id=0)
self._test_szx(exp_output, registers, border=2, keyb=True, issue2=0, compress=True, machine_id=0, chFe=16)

def test_szx_48k_uncompressed(self):
registers = list(range(26)) # Registers
Expand All @@ -643,6 +645,7 @@ def test_szx_48k_uncompressed(self):
Machine: 48K ZX Spectrum
SPCR: 8 bytes
Border: 3
Port $FE: 10000000
KEYB: 5 bytes
Issue 2 emulation: enabled
Z80R: 37 bytes
Expand Down Expand Up @@ -674,7 +677,7 @@ def test_szx_48k_uncompressed(self):
Page: 5
RAM: 16384-32767 4000-7FFF: 16384 bytes, uncompressed
"""
self._test_szx(exp_output, registers, border=3, keyb=True, issue2=1, compress=False)
self._test_szx(exp_output, registers, border=3, keyb=True, issue2=1, compress=False, chFe=128)

def test_szx_48k_compressed(self):
registers = list(range(26)) # Registers
Expand All @@ -687,6 +690,7 @@ def test_szx_48k_compressed(self):
Machine: 48K ZX Spectrum
SPCR: 8 bytes
Border: 4
Port $FE: 01000000
Z80R: 37 bytes
Interrupts: enabled
Interrupt mode: 2
Expand Down Expand Up @@ -716,7 +720,7 @@ def test_szx_48k_compressed(self):
Page: 5
RAM: 16384-32767 4000-7FFF: 39 bytes, compressed
"""
self._test_szx(exp_output, registers, border=4, compress=True)
self._test_szx(exp_output, registers, border=4, compress=True, chFe=64)

def test_szx_128k_uncompressed(self):
registers = list(range(16, 42)) # Registers
Expand All @@ -730,6 +734,7 @@ def test_szx_128k_uncompressed(self):
SPCR: 8 bytes
Border: 6
Port $7FFD: 1 (bank 1 paged into 49152-65535 C000-FFFF)
Port $FE: 00001000
KEYB: 5 bytes
Issue 2 emulation: disabled
AY: 18 bytes
Expand Down Expand Up @@ -779,7 +784,7 @@ def test_szx_128k_uncompressed(self):
Page: 7
RAM: 16384 bytes, uncompressed
"""
self._test_szx(exp_output, registers, border=6, keyb=True, issue2=0, compress=False, machine_id=2, ch7ffd=1, pages=None, ay=range(5, 134, 8))
self._test_szx(exp_output, registers, border=6, keyb=True, issue2=0, compress=False, machine_id=2, ch7ffd=1, pages=None, ay=range(5, 134, 8), chFe=8)

def test_szx_128k_compressed(self):
registers = list(range(16, 42)) # Registers
Expand All @@ -793,6 +798,7 @@ def test_szx_128k_compressed(self):
SPCR: 8 bytes
Border: 7
Port $7FFD: 1 (bank 1 paged into 49152-65535 C000-FFFF)
Port $FE: 00000100
AY: 18 bytes
Current AY register: 13
Registers: 0F 11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D
Expand Down Expand Up @@ -840,7 +846,7 @@ def test_szx_128k_compressed(self):
Page: 7
RAM: 39 bytes, compressed
"""
self._test_szx(exp_output, registers, border=7, compress=True, machine_id=2, ch7ffd=1, pages=None, ay=range(13, 46, 2))
self._test_szx(exp_output, registers, border=7, compress=True, machine_id=2, ch7ffd=1, pages=None, ay=range(13, 46, 2), chFe=4)

def test_szx_without_magic_number(self):
non_szx = self.write_bin_file((1, 2, 3), suffix='.szx')
Expand Down

0 comments on commit 98bf7c4

Please sign in to comment.