Skip to content

Commit

Permalink
Add the ScreenScale configuration parameter for trace.py
Browse files Browse the repository at this point in the history
  • Loading branch information
skoolkid committed Aug 30, 2024
1 parent f8cced5 commit 3521d63
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 11 deletions.
1 change: 1 addition & 0 deletions skoolkit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
'trace': {
'PNGScale': (2, ''),
'ScreenFps': (50, ''),
'ScreenScale': (2, ''),
'TraceLine': ("${pc:04X} {i}", ''),
'TraceLine2': (
"${pc:04X} {i:<15} "
Expand Down
2 changes: 1 addition & 1 deletion skoolkit/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def run(snafile, options, config):
except Exception as e:
raise SkoolKitError(f"Invalid format string: '{orig_trace_line}'")
if options.screen and pygame:
screen = Screen(2, config['ScreenFps'], 'trace.py')
screen = Screen(config['ScreenScale'], config['ScreenFps'], 'trace.py')
print(screen.pygame_msg)
draw = screen.draw
else:
Expand Down
6 changes: 3 additions & 3 deletions sphinx/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Changelog
specified by the ``PadLeft`` and ``PadRight`` configuration parameters)
* Added the ``--screen`` option to :ref:`trace.py` (for displaying screen
contents while running)
* Added the ``ScreenFps`` configuration parameter for
:ref:`trace.py <trace-conf>` (to specify the frame rate when displaying
screen contents)
* Added the ``ScreenFps`` and ``ScreenScale`` configuration parameters for
:ref:`trace.py <trace-conf>` (to specify the frame rate and scale factor when
displaying screen contents)
* Added support to :ref:`trace.py` for writing a PNG file after code execution
has completed
* Added the ``PNGScale`` configuration parameter for
Expand Down
14 changes: 8 additions & 6 deletions sphinx/source/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2047,9 +2047,9 @@ produce a WAV file for the sound effect that would be produced by the same code
running on a real ZX Spectrum.

If the ``--screen`` option is given and `pygame`_ is installed, `trace.py` will
use it to render the Spectrum's screen contents at 50 frames per second while
running. The frame rate can be changed by setting the ``ScreenFps``
configuration parameter.
use it to render the Spectrum's screen contents at 50 frames per second with a
scale factor of 2 while running. The frame rate and scale factor can be changed
by setting the ``ScreenFps`` and ``ScreenScale`` configuration parameters.

.. _trace-conf:

Expand All @@ -2061,7 +2061,9 @@ configuration parameters are:

* ``PNGScale`` - the PNG image scale factor (default: ``2``)
* ``ScreenFps`` - frames per second to display when ``--screen`` is used
(default: 50); if set to 0, `trace.py` runs at maximum speed
(default: ``50``); if set to 0, `trace.py` runs at maximum speed
* ``ScreenScale`` - screen scale factor when ``--screen`` is used (default:
``2``)
* ``TraceLine`` - the format of each instruction line when ``-v`` is used
(default: ``${pc:04X} {i}``)
* ``TraceLine2`` - the format of each instruction line when ``-vv`` is used
Expand Down Expand Up @@ -2116,8 +2118,8 @@ Configuration parameters may also be set on the command line by using the
| Version | Changes |
+=========+===================================================================+
| 9.4 | Added the ``--screen`` option; added support for writing a PNG |
| | file after execution has completed; added the ``PNGScale`` and |
| | ``ScreenFps`` configuration parameters |
| | file after execution has completed; added the ``PNGScale``, |
| | ``ScreenFps`` and ``ScreenScale`` configuration parameters |
+---------+-------------------------------------------------------------------+
| 9.3 | Added the ``--state`` option; added support for writing a WAV |
| | file after execution has completed; added support for the ``m`` |
Expand Down
3 changes: 2 additions & 1 deletion sphinx/source/man/trace.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ configuration parameters are:

:PNGScale: The PNG image scale factor (default: ``2``).
:ScreenFps: Frames per second to display when ``--screen`` is used (default:
50). If set to 0, ``trace.py`` runs at maximum speed.
``50``). If set to 0, ``trace.py`` runs at maximum speed.
:ScreenScale: Screen scale factor when ``--screen`` is used (default: ``2``).
:TraceLine: The format of each instruction line when ``-v`` is used
(default: ``${pc:04X} {i}``).
:TraceLine2: The format of each instruction line when ``-vv`` is used. Use
Expand Down
61 changes: 61 additions & 0 deletions tests/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,7 @@ def test_option_show_config(self):
"[trace]\n"
"PNGScale=2\n"
"ScreenFps=50\n"
"ScreenScale=2\n"
"TraceLine=${pc:04X} {i}\n"
"TraceLine2=${pc:04X} {i:<15} "
"A={r[a]:02X} F={r[f]:08b} BC={r[bc]:04X} DE={r[de]:04X} HL={r[hl]:04X} IX={r[ix]:04X} IY={r[iy]:04X}\\n "
Expand All @@ -1724,6 +1725,7 @@ def test_option_show_config_read_from_file(self):
[trace]
PNGScale=2
ScreenFps=50
ScreenScale=2
TraceLine=${pc:04X} {i}
TraceLine2=${pc:04x} {i:<15} A={r[a]:02X}
TraceLineDecimal={pc:05} {i}
Expand Down Expand Up @@ -2163,6 +2165,65 @@ def test_config_ScreenFps_set_on_command_line(self):
self.assertEqual(screen.scr[0], 1)
self.assertEqual(screen.frame, 1)

@patch.object(trace, 'pygame', True)
@patch.object(trace, 'Screen', MockScreen)
def test_config_ScreenScale_read_from_file(self):
ini = """
[trace]
ScreenScale=1
"""
self.write_text_file(dedent(ini).strip(), 'skoolkit.ini')
data = (
0x00, # $8000 NOP ; T=69886 (screen draw follows)
0x00, # $8001 NOP ; T=69890
)
start = 0x8000
stop = start + len(data)
ram = [0] * 49152
ram[0] = 240
ram[start - 0x4000:stop - 0x4000] = data
registers = {'PC': start, 'tstates': 69886}
z80file = self.write_z80_file(None, ram, registers=registers)
output, error = self.run_trace(f'-S {stop} --screen {z80file}')
self.assertEqual(error, '')
exp_output = f"""
Using pygame
Stopped at ${stop:04X}
"""
self.assertEqual(dedent(exp_output).strip(), output.rstrip())
self.assertEqual(screen.scale, 1)
self.assertEqual(screen.fps, 50)
self.assertEqual(screen.caption, 'trace.py')
self.assertEqual(screen.scr[0], 240)
self.assertEqual(screen.frame, 1)

@patch.object(trace, 'pygame', True)
@patch.object(trace, 'Screen', MockScreen)
def test_config_ScreenScale_set_on_command_line(self):
data = (
0x00, # $8000 NOP ; T=69886 (screen draw follows)
0x00, # $8001 NOP ; T=69890
)
start = 0x8000
stop = start + len(data)
ram = [0] * 49152
ram[0] = 16
ram[start - 0x4000:stop - 0x4000] = data
registers = {'PC': start, 'tstates': 69886}
z80file = self.write_z80_file(None, ram, registers=registers)
output, error = self.run_trace(f'-I ScreenScale=3 -S {stop} --screen {z80file}')
self.assertEqual(error, '')
exp_output = f"""
Using pygame
Stopped at ${stop:04X}
"""
self.assertEqual(dedent(exp_output).strip(), output.rstrip())
self.assertEqual(screen.scale, 3)
self.assertEqual(screen.fps, 50)
self.assertEqual(screen.caption, 'trace.py')
self.assertEqual(screen.scr[0], 16)
self.assertEqual(screen.frame, 1)

def test_config_TraceLine_read_from_file(self):
ini = """
[trace]
Expand Down

0 comments on commit 3521d63

Please sign in to comment.