diff --git a/skoolkit/config.py b/skoolkit/config.py index 4d2d661a..66c61be3 100644 --- a/skoolkit/config.py +++ b/skoolkit/config.py @@ -130,6 +130,7 @@ 'trace': { 'PNGScale': (2, ''), 'ScreenFps': (50, ''), + 'ScreenScale': (2, ''), 'TraceLine': ("${pc:04X} {i}", ''), 'TraceLine2': ( "${pc:04X} {i:<15} " diff --git a/skoolkit/trace.py b/skoolkit/trace.py index e0ded2bd..e3b62e42 100644 --- a/skoolkit/trace.py +++ b/skoolkit/trace.py @@ -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: diff --git a/sphinx/source/changelog.rst b/sphinx/source/changelog.rst index e7657a57..c388494c 100644 --- a/sphinx/source/changelog.rst +++ b/sphinx/source/changelog.rst @@ -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 ` (to specify the frame rate when displaying - screen contents) +* Added the ``ScreenFps`` and ``ScreenScale`` configuration parameters for + :ref:`trace.py ` (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 diff --git a/sphinx/source/commands.rst b/sphinx/source/commands.rst index feeb2a74..e3de9525 100644 --- a/sphinx/source/commands.rst +++ b/sphinx/source/commands.rst @@ -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: @@ -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 @@ -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`` | diff --git a/sphinx/source/man/trace.py.rst b/sphinx/source/man/trace.py.rst index b0c3c53e..54848f0e 100644 --- a/sphinx/source/man/trace.py.rst +++ b/sphinx/source/man/trace.py.rst @@ -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 diff --git a/tests/test_trace.py b/tests/test_trace.py index e434f3f6..15977ff1 100644 --- a/tests/test_trace.py +++ b/tests/test_trace.py @@ -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 " @@ -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} @@ -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]