Skip to content

Commit

Permalink
[#20] Get tape levels with events.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Feb 28, 2021
1 parent 3038e43 commit 74764bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions zx/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions zx/_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions zx/_tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from ._device import Device
from ._device import EndOfFrame
from ._device import GetTapeLevel
from ._time import Time


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

0 comments on commit 74764bf

Please sign in to comment.