diff --git a/zx/_device.py b/zx/_device.py index 5490ede..e77f1a8 100644 --- a/zx/_device.py +++ b/zx/_device.py @@ -41,6 +41,10 @@ class IsTapePlayerPaused(DeviceEvent): pass +class IsTapePlayerStopped(DeviceEvent): + pass + + class KeyStroke(DeviceEvent): def __init__(self, id, pressed): self.id = id diff --git a/zx/_emulator.py b/zx/_emulator.py index d46ac98..0a520b9 100644 --- a/zx/_emulator.py +++ b/zx/_emulator.py @@ -14,6 +14,7 @@ from ._data import SoundFile from ._device import EndOfFrame from ._device import GetTapeLevel +from ._device import IsTapePlayerStopped from ._device import PauseStateUpdated from ._device import QuantumRun from ._device import ScreenUpdated @@ -69,9 +70,14 @@ def __init__(self, speed_factor=1.0, profile=None, devices=None): # this field. self._tape_player = TapePlayer() - # Don't even create the window on full throttle. - if devices is None and self.__speed_factor is not None: - devices = Dispatcher([self, ScreenWindow(), self._tape_player]) + if devices is None: + devices = [self, self._tape_player] + + # Don't even create the window on full throttle. + if self.__speed_factor is not None: + devices.append(ScreenWindow()) + + devices = Dispatcher(devices) self.devices = devices @@ -114,8 +120,9 @@ def __load_tape_to_player(self, file): self._tape_player.load_tape(file) self.__pause_tape() + # TODO: Do we still need? def __is_end_of_tape(self): - return self._tape_player.is_end() + return self.devices.notify(IsTapePlayerStopped()) # TODO: Double-underscore or make public. def _handle_key_stroke(self, key_info, pressed): diff --git a/zx/_machine.py b/zx/_machine.py index c916b6d..9d88ba8 100644 --- a/zx/_machine.py +++ b/zx/_machine.py @@ -335,16 +335,17 @@ def fetches_limit(self): def fetches_limit(self, fetches_to_stop): self.__fetches_to_stop[:] = _split32(fetches_to_stop) - ''' TODO + # TODO: Can we do without this? def get_events(self): - return self.get('events') + return _make32(*self.__events) + # TODO: Can we do without this? def set_events(self, events): - self.set('events', events) + self.__events[:] = _split32(events) + # TODO: Can we do without this? def raise_events(self, events): self.set_events(self.get_events() | events) - ''' @property def ticks_since_int(self): diff --git a/zx/_tape.py b/zx/_tape.py index 0c0adc2..dae95e1 100644 --- a/zx/_tape.py +++ b/zx/_tape.py @@ -12,6 +12,7 @@ from ._device import Device from ._device import EndOfFrame from ._device import GetTapeLevel +from ._device import IsTapePlayerStopped from ._time import Time @@ -175,4 +176,6 @@ def on_event(self, event, devices, result): self.skip_rest_of_frame() elif isinstance(event, GetTapeLevel): return self.get_level_at_frame_tick(event.frame_tick) + elif isinstance(event, IsTapePlayerStopped): + return self.is_end() return result