Skip to content

Commit

Permalink
[#20] The tape player to know about frame ends by catching events.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Feb 28, 2021
1 parent 2a74491 commit 3038e43
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions zx/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class DeviceEvent(object):
pass


class EndOfFrame(DeviceEvent):
pass


class GetEmulationPauseState(DeviceEvent):
pass

Expand Down
3 changes: 2 additions & 1 deletion zx/_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import time
from ._data import MachineSnapshot
from ._data import SoundFile
from ._device import EndOfFrame
from ._device import PauseStateUpdated
from ._device import QuantumRun
from ._device import ScreenUpdated
Expand Down Expand Up @@ -325,7 +326,7 @@ def __run_quantum(self, speed_factor=None):
pixels = self.get_frame_pixels()
self.devices.notify(ScreenUpdated(pixels))

self._tape_player.skip_rest_of_frame()
self.devices.notify(EndOfFrame())
self._emulation_time.advance(1 / 50)

if speed_factor:
Expand Down
3 changes: 3 additions & 0 deletions zx/_tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


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


Expand Down Expand Up @@ -169,4 +170,6 @@ def skip_rest_of_frame(self):
self._tick -= self._ticks_per_frame

def on_event(self, event, devices, result):
if isinstance(event, EndOfFrame):
self.skip_rest_of_frame()
return result

0 comments on commit 3038e43

Please sign in to comment.