Skip to content

Commit

Permalink
[#20] Catch end of tape with events.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Feb 28, 2021
1 parent 74764bf commit f595827
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions zx/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class IsTapePlayerPaused(DeviceEvent):
pass


class IsTapePlayerStopped(DeviceEvent):
pass


class KeyStroke(DeviceEvent):
def __init__(self, id, pressed):
self.id = id
Expand Down
15 changes: 11 additions & 4 deletions zx/_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions zx/_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions zx/_tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ._device import Device
from ._device import EndOfFrame
from ._device import GetTapeLevel
from ._device import IsTapePlayerStopped
from ._time import Time


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

0 comments on commit f595827

Please sign in to comment.