# SPDX-License-Identifier: MIT """megadrive-python's drawing switch (``VDP.rendering``, ``VDP.undrawn_frame``, since 5351daf and efd80fc) gates only the Mega Drive's pixels. With a 32X in the slot an undrawn frame must leave the whole machine as a drawn one does -- both SH-2s, SDRAM, the 32X's registers and frame buffers, the 68000 -- since the 32X answers socket 7 only for lines the Mega Drive draws (the composite is output, nothing software reads) and its own VDP runs from socket 6, which does not depend on the switch. This uses the save-state tests' synthetic machine (both SH-2s counting in SDRAM, the 68000 counting in RAM): it checks that undrawn frames with a 32X attached run, keep socket 7's hand-over in step and move nothing the machine holds. It draws little, so it is not the picture check; that was run once on testpico with the user's boot ROMs (docs/worklog.md, Session 18).""" from __future__ import annotations from megadrive_python.machine import MCLK_PER_LINE from test_savestate import _fingerprint, _machine #: Enough steps to cross several frames of the synthetic machine (a frame is 262 lines). FRAMES = 4 def _run(undrawn: str) -> tuple: system, device = _machine() frame_mclk = 262 * MCLK_PER_LINE end = system.mclk + FRAMES * frame_mclk frame = -1 while system.mclk < end: now = system.vdp.frame if now != frame: frame = now if undrawn == "every other": system.vdp.undrawn_frame = frame % 2 == 0 if undrawn == "off": system.vdp.rendering = False system.step() return ( _fingerprint(system, device), tuple(bytes(fb) for fb in device.framebuffers), tuple(device.comm), device.adapter, system.vdp.frame, system.vdp.renderer.collision, repr(device.vdp.picture), ) def test_an_undrawn_mega_drive_frame_changes_nothing_the_32x_holds() -> None: drawn = _run("never") assert _run("every other") == drawn assert _run("off") == drawn