From 74764bf744759f563ebbe9bd96dc0ba282c0ff45 Mon Sep 17 00:00:00 2001 From: Ivan Kosarev Date: Sun, 28 Feb 2021 16:42:36 +0200 Subject: [PATCH] [#20] Get tape levels with events. --- zx/_device.py | 5 +++++ zx/_emulator.py | 4 ++-- zx/_tape.py | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/zx/_device.py b/zx/_device.py index 7b84c73..5490ede 100644 --- a/zx/_device.py +++ b/zx/_device.py @@ -27,6 +27,11 @@ class GetEmulationTime(DeviceEvent): pass +class GetTapeLevel(DeviceEvent): + def __init__(self, frame_tick): + self.frame_tick = frame_tick + + # TODO: Combine these into Get/SetState kind of events. class GetTapePlayerTime(DeviceEvent): pass diff --git a/zx/_emulator.py b/zx/_emulator.py index 4bce45c..d46ac98 100644 --- a/zx/_emulator.py +++ b/zx/_emulator.py @@ -13,6 +13,7 @@ from ._data import MachineSnapshot from ._data import SoundFile from ._device import EndOfFrame +from ._device import GetTapeLevel from ._device import PauseStateUpdated from ._device import QuantumRun from ._device import ScreenUpdated @@ -168,8 +169,7 @@ def __on_input(self, addr): # TODO: Use the tick when the ear value is sampled # instead of the tick of the beginning of the input # cycle. - tick = self.ticks_since_int - if self._tape_player.get_level_at_frame_tick(tick): + if self.devices.notify(GetTapeLevel(self.ticks_since_int)): n |= 0x40 END_OF_TAPE = RunEvents.END_OF_TAPE diff --git a/zx/_tape.py b/zx/_tape.py index ef4654e..0c0adc2 100644 --- a/zx/_tape.py +++ b/zx/_tape.py @@ -11,6 +11,7 @@ from ._device import Device from ._device import EndOfFrame +from ._device import GetTapeLevel from ._time import Time @@ -172,4 +173,6 @@ def skip_rest_of_frame(self): def on_event(self, event, devices, result): if isinstance(event, EndOfFrame): self.skip_rest_of_frame() + elif isinstance(event, GetTapeLevel): + return self.get_level_at_frame_tick(event.frame_tick) return result