Skip to content

Commit

Permalink
[#20] Load tapes with events.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Mar 7, 2021
1 parent f595827 commit 9c35b60
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions zx/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion zx/_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
3 changes: 3 additions & 0 deletions zx/_tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ._device import EndOfFrame
from ._device import GetTapeLevel
from ._device import IsTapePlayerStopped
from ._device import LoadTape
from ._time import Time


Expand Down Expand Up @@ -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

0 comments on commit 9c35b60

Please sign in to comment.