From 3038e43a9f1533c46f687edf4191d2aa2961a4c9 Mon Sep 17 00:00:00 2001 From: Ivan Kosarev Date: Sun, 28 Feb 2021 15:15:06 +0200 Subject: [PATCH] [#20] The tape player to know about frame ends by catching events. --- zx/_device.py | 4 ++++ zx/_emulator.py | 3 ++- zx/_tape.py | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/zx/_device.py b/zx/_device.py index dd2fbd8..7b84c73 100644 --- a/zx/_device.py +++ b/zx/_device.py @@ -15,6 +15,10 @@ class DeviceEvent(object): pass +class EndOfFrame(DeviceEvent): + pass + + class GetEmulationPauseState(DeviceEvent): pass diff --git a/zx/_emulator.py b/zx/_emulator.py index a85803d..4bce45c 100644 --- a/zx/_emulator.py +++ b/zx/_emulator.py @@ -12,6 +12,7 @@ import time from ._data import MachineSnapshot from ._data import SoundFile +from ._device import EndOfFrame from ._device import PauseStateUpdated from ._device import QuantumRun from ._device import ScreenUpdated @@ -325,7 +326,7 @@ def __run_quantum(self, speed_factor=None): pixels = self.get_frame_pixels() self.devices.notify(ScreenUpdated(pixels)) - self._tape_player.skip_rest_of_frame() + self.devices.notify(EndOfFrame()) self._emulation_time.advance(1 / 50) if speed_factor: diff --git a/zx/_tape.py b/zx/_tape.py index fd758e3..ef4654e 100644 --- a/zx/_tape.py +++ b/zx/_tape.py @@ -10,6 +10,7 @@ from ._device import Device +from ._device import EndOfFrame from ._time import Time @@ -169,4 +170,6 @@ def skip_rest_of_frame(self): self._tick -= self._ticks_per_frame def on_event(self, event, devices, result): + if isinstance(event, EndOfFrame): + self.skip_rest_of_frame() return result