mirror of
https://github.com/KrisKennaway/ii-vision.git
synced 2024-11-16 19:08:52 +00:00
factor out State and CycleCounter to a new machine module and rename
This commit is contained in:
parent
cf493e782c
commit
5411793ea4
45
transcoder/machine.py
Normal file
45
transcoder/machine.py
Normal file
@ -0,0 +1,45 @@
|
||||
"""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)
|
@ -3,6 +3,7 @@
|
||||
from typing import Iterable, Iterator
|
||||
|
||||
import audio
|
||||
import machine
|
||||
import opcodes
|
||||
import video
|
||||
|
||||
@ -18,9 +19,9 @@ class Movie:
|
||||
|
||||
self.stream_pos = 0 # type: int
|
||||
|
||||
self.cycle_counter = opcodes.CycleCounter()
|
||||
self.cycle_counter = machine.CycleCounter()
|
||||
|
||||
self.state = opcodes.State(
|
||||
self.state = machine.Machine(
|
||||
self.cycle_counter,
|
||||
self.video.memory_map,
|
||||
self.video.update_priority
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user