From 8bdad221624d3bf0e620d73844b1cf57c9bd88fe Mon Sep 17 00:00:00 2001 From: kris Date: Thu, 21 Mar 2019 22:42:09 +0000 Subject: [PATCH] Stop ticking cycles as part of emitting the opcodes, we are counting them externally in audio.py now. Add some docstrings --- transcoder/machine.py | 30 ++++++++++++++++++++---------- transcoder/opcodes.py | 10 ---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/transcoder/machine.py b/transcoder/machine.py index 92e6a62..db71a44 100644 --- a/transcoder/machine.py +++ b/transcoder/machine.py @@ -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) \ No newline at end of file + opcode.apply(self) \ No newline at end of file diff --git a/transcoder/opcodes.py b/transcoder/opcodes.py index 3f0d94b..97cc185 100644 --- a/transcoder/opcodes.py +++ b/transcoder/opcodes.py @@ -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: