Skip to content

Commit

Permalink
[#18] Move the most basic emulator methods to the machine class.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarev committed Jan 31, 2021
1 parent 6d4f1ce commit 2d0fcb5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 3 additions & 14 deletions zx/_emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from ._data import SoundFile
from ._device import DeviceEvent
from ._error import Error
from ._except import EmulationExit
from ._except import EmulatorException
from ._file import parse_file
from ._gui import ScreenWindow
Expand Down Expand Up @@ -66,6 +65,9 @@ def __init__(self, speed_factor=1.0, profile=None, devices=None):
if devices is None and self.__speed_factor is not None:
self.__devices = [ScreenWindow(self)]

# TODO: Eliminate the undescored version.
self.devices = self.__devices

self.__keyboard_state = KeyboardState()
self.set_on_input_callback(self.__on_input)

Expand All @@ -79,16 +81,6 @@ def __init__(self, speed_factor=1.0, profile=None, devices=None):
if self.__profile:
self.set_breakpoints(0, 0x10000)

def __enter__(self):
return self

def destroy(self):
for device in self.__devices:
device.destroy()

def __exit__(self, type, value, tb):
self.destroy()

# TODO: Double-underscore or make public.
def _is_paused(self):
return self.__is_paused_flag
Expand Down Expand Up @@ -117,9 +109,6 @@ def _save_snapshot_file(self, format, filename):
image = snapshot
f.write(image)

def stop(self):
raise EmulationExit()

# TODO: Double-underscore or make public.
def _is_tape_paused(self):
return self._tape_player.is_paused()
Expand Down
14 changes: 14 additions & 0 deletions zx/_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ._data import MachineSnapshot
from ._data import ProcessorSnapshot
from ._emulatorbase import _Spectrum48Base
from ._except import EmulationExit
from ._rom import get_rom_image
from ._utils import make16

Expand Down Expand Up @@ -352,6 +353,19 @@ def __init__(self):
# Install ROM.
self.write(0x0000, get_rom_image(self.machine_kind))

def destroy(self):
for device in self.devices:
device.destroy()

def __enter__(self):
return self

def __exit__(self, type, value, tb):
self.destroy()

def stop(self):
raise EmulationExit()

def set_breakpoints(self, addr, size):
self.mark_addrs(addr, size, self._BREAKPOINT_MARK)

Expand Down

0 comments on commit 2d0fcb5

Please sign in to comment.