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: class CycleCounter:
"""Counts clock cycles."""
def __init__(self): def __init__(self):
self.cycles = 0 # type:int self.cycles = 0 # type:int
def tick(self, cycles: int) -> None: 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 self.cycles += cycles
def reset(self) -> None: def reset(self) -> None:
"""Reset cycle counter to 0."""
self.cycles = 0 self.cycles = 0
class Machine: class Machine:
"""Represents virtual machine state.""" """Represents Apple II and player virtual machine state."""
def __init__(self, cycle_counter: CycleCounter, def __init__(self, cycle_counter: CycleCounter,
memmap: screen.MemoryMap, update_priority: np.array): memmap: screen.MemoryMap, update_priority: np.array):
self.page = 0x20 self.page = 0x20 # type: int
self.content = 0x7f self.content = 0x7f # type: int
self.memmap = memmap self.memmap = memmap # type: screen.MemoryMap
self.cycle_counter = cycle_counter self.cycle_counter = cycle_counter # type: CycleCounter
self.update_priority = update_priority self.update_priority = update_priority # type: np.array
def emit(self, opcode: "Opcode") -> Iterator[int]: def emit(self, opcode: "Opcode") -> Iterator[int]:
"""
:param opcode:
:return:
"""
cmd = opcode.emit_command(opcode) cmd = opcode.emit_command(opcode)
if cmd: if cmd:
yield from cmd yield from cmd
@ -40,6 +53,3 @@ class Machine:
# Update changes in memory map, if any # Update changes in memory map, if any
opcode.apply(self) opcode.apply(self)
# Tick 6502 CPU
self.cycle_counter.tick(opcode.cycles)

View File

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