From 9c35b60ec73800fb378460355adf1c1d12ddbebc Mon Sep 17 00:00:00 2001 From: Ivan Kosarev Date: Sun, 7 Mar 2021 11:55:29 +0200 Subject: [PATCH] [#20] Load tapes with events. --- zx/_device.py | 5 +++++ zx/_emulator.py | 3 ++- zx/_tape.py | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/zx/_device.py b/zx/_device.py index e77f1a8..bbce42d 100644 --- a/zx/_device.py +++ b/zx/_device.py @@ -45,6 +45,11 @@ class IsTapePlayerStopped(DeviceEvent): pass +class LoadTape(DeviceEvent): + def __init__(self, file): + self.file = file + + class KeyStroke(DeviceEvent): def __init__(self, id, pressed): self.id = id diff --git a/zx/_emulator.py b/zx/_emulator.py index 0a520b9..d045f83 100644 --- a/zx/_emulator.py +++ b/zx/_emulator.py @@ -15,6 +15,7 @@ from ._device import EndOfFrame from ._device import GetTapeLevel from ._device import IsTapePlayerStopped +from ._device import LoadTape from ._device import PauseStateUpdated from ._device import QuantumRun from ._device import ScreenUpdated @@ -117,7 +118,7 @@ def _toggle_tape_pause(self): self.__pause_tape(not self._is_tape_paused()) def __load_tape_to_player(self, file): - self._tape_player.load_tape(file) + self.devices.notify(LoadTape(file)) self.__pause_tape() # TODO: Do we still need? diff --git a/zx/_tape.py b/zx/_tape.py index dae95e1..bdfdf74 100644 --- a/zx/_tape.py +++ b/zx/_tape.py @@ -13,6 +13,7 @@ from ._device import EndOfFrame from ._device import GetTapeLevel from ._device import IsTapePlayerStopped +from ._device import LoadTape from ._time import Time @@ -178,4 +179,6 @@ def on_event(self, event, devices, result): return self.get_level_at_frame_tick(event.frame_tick) elif isinstance(event, IsTapePlayerStopped): return self.is_end() + elif isinstance(event, LoadTape): + self.load_tape(event.file) return result