ii-vision/transcoder/machine.py

45 lines
1.0 KiB
Python

"""Representation of Apple II + player virtual machine state."""
from typing import Iterator
import numpy as np
import screen
class CycleCounter:
def __init__(self):
self.cycles = 0 # type:int
def tick(self, cycles: int) -> None:
self.cycles += cycles
def reset(self) -> None:
self.cycles = 0
class Machine:
"""Represents virtual machine state."""
def __init__(self, cycle_counter: CycleCounter,
memmap: screen.MemoryMap, update_priority: np.array):
self.page = 0x20
self.content = 0x7f
self.memmap = memmap
self.cycle_counter = cycle_counter
self.update_priority = update_priority
def emit(self, opcode: "Opcode") -> Iterator[int]:
cmd = opcode.emit_command(opcode)
if cmd:
yield from cmd
data = opcode.emit_data()
if data:
yield from data
# Update changes in memory map, if any
opcode.apply(self)
# Tick 6502 CPU
self.cycle_counter.tick(opcode.cycles)