Stop ticking cycles as part of emitting the opcodes, we are counting

them externally in audio.py now.

Add some docstrings
This commit is contained in:
kris 2019-03-21 22:42:09 +00:00
parent ce078f493f
commit 8bdad22162
2 changed files with 20 additions and 20 deletions

View File

@ -8,29 +8,42 @@ import screen
class CycleCounter:
"""Counts clock cycles."""
def __init__(self):
self.cycles = 0 # type:int
def tick(self, cycles: int) -> None:
"""Advance cycle counter by some number of clock ticks.
:param cycles: How many clock cycles to advance
"""
self.cycles += cycles
def reset(self) -> None:
"""Reset cycle counter to 0."""
self.cycles = 0
class Machine:
"""Represents virtual machine state."""
"""Represents Apple II and player virtual machine state."""
def __init__(self, cycle_counter: CycleCounter,
memmap: screen.MemoryMap, update_priority: np.array):
self.page = 0x20
self.content = 0x7f
self.page = 0x20 # type: int
self.content = 0x7f # type: int
self.memmap = memmap
self.cycle_counter = cycle_counter
self.update_priority = update_priority
self.memmap = memmap # type: screen.MemoryMap
self.cycle_counter = cycle_counter # type: CycleCounter
self.update_priority = update_priority # type: np.array
def emit(self, opcode: "Opcode") -> Iterator[int]:
"""
:param opcode:
:return:
"""
cmd = opcode.emit_command(opcode)
if cmd:
yield from cmd
@ -39,7 +52,4 @@ class Machine:
yield from data
# Update changes in memory map, if any
opcode.apply(self)
# Tick 6502 CPU
self.cycle_counter.tick(opcode.cycles)
opcode.apply(self)

View File

@ -20,7 +20,6 @@ OpcodeCommand = enum.Enum("OpcodeCommand", _op_cmds)
class Opcode:
COMMAND = None # type: OpcodeCommand
_CYCLES = None # type: int
# Offset of start byte in decoder opcode
_START = None # type: int
@ -37,10 +36,6 @@ class Opcode:
def __data_eq__(self, other):
raise NotImplementedError
@property
def cycles(self) -> int:
return self._CYCLES
@staticmethod
def emit_command(opcode: "Opcode") -> Iterator[int]:
# Emit address of next opcode
@ -56,7 +51,6 @@ class Opcode:
class Nop(Opcode):
COMMAND = OpcodeCommand.NOP
_CYCLES = 11 # TODO: count
def __data_eq__(self, other):
return True
@ -64,7 +58,6 @@ class Nop(Opcode):
class Terminate(Opcode):
COMMAND = OpcodeCommand.TERMINATE
_CYCLES = 6 # TODO: count
def __data_eq__(self, other):
return True
@ -72,7 +65,6 @@ class Terminate(Opcode):
class Ack(Opcode):
COMMAND = OpcodeCommand.ACK
_CYCLES = 100 # TODO: count
def emit_data(self) -> Iterator[int]:
# Dummy bytes to pad out TCP frame
@ -84,8 +76,6 @@ class Ack(Opcode):
class BaseTick(Opcode):
_CYCLES = 73
def __init__(self, content: int, offsets: Tuple):
self.content = content
if len(offsets) != 4: