mirror of
https://github.com/KrisKennaway/ii-vision.git
synced 2025-07-09 12:23:52 +00:00
factor out State and CycleCounter to a new machine module and rename
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user