factor out State and CycleCounter to a new machine module and rename

This commit is contained in:
kris
2019-03-21 16:48:02 +00:00
parent cf493e782c
commit 5411793ea4
3 changed files with 50 additions and 45 deletions

View File

@ -3,49 +3,8 @@
import enum
from typing import Iterator, Tuple
import numpy as np
import screen
import symbol_table
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 State:
"""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)
from machine import Machine
_op_cmds = [
"TERMINATE",
@ -94,7 +53,7 @@ class Opcode:
def emit_data(self) -> Iterator[int]:
return
def apply(self, state: State):
def apply(self, state: Machine):
pass