# SPDX-License-Identifier: MIT """The NOPs: ``$EA`` and every undefined opcode, by class, each with its evidence. No undefined opcode changes a register, a flag or memory (DS Table 7-1 "All are NOP's"; CL section 9), but they differ in length, cycles and what they read (docs/timing.md, "Undefined opcodes"). """ from sixfiveohtwo.frame import NO_POLL class NopMixin: """NOP in its seven shapes.""" # Evidence tags (emulator-lineage docs/methodology.md): every length and # cycle count below is DOC (DS Table 7-1, GDS Table V, CL section 9) and # MEASURED (CAP) on the G65SC12 and the R65C02, except `$CB`/`$DB` as NOPs # (DOC only, U3). That no NOP changes a register, flag or memory: DOC (DS # Table 7-1) and MEASURED (CAP's lockstep). #: U7: whether an interrupt may be taken directly after a one-byte, one-cycle #: NOP. False: it never is; the NOP "attaches or merges with" the following #: instruction (CL section 9, Laughton's bench; LT `cpu` test 8 on real Lynxes). # DOC (CL section 9, LK's bench report) and TEST ROM (LT `cpu` test 8); not # MEASURED by CAP (U7 stays open for the parts not covered). one_cycle_nops_poll = False #: U9: what `$5C` reads in its last five cycles. "ff_page": ``$FF00 + low #: operand byte`` once, then ``$FFFF`` four times (LK, observed on a chip; #: CAP: the last four bytes are `$FFFF`'s on both captured parts). "pc": the #: next opcode's address five times (MAME's reading, which CAP contradicts #: on those two parts): kept as a setting for a part not captured. # The `$FFFF` reads: MEASURED (CAP, both parts). The `$FF00 + low` read: # DOC (LK), MEASURED only where CAP's model knew the byte (U9). # "pc" is OBSERVED (MAME) and contradicted by CAP. nop_5c_reads = "ff_page" #: C10: what `$DC` and `$FC` read in their fourth cycle. "absolute": the #: address their operand names (CL section 9 note i; LK; CAP agrees in the 8 #: executions it can tell). "operand": the last operand byte again (SST, #: which CAP contradicts in all 12 executions). # MEASURED (CAP, in the executions it can tell); DOC (CL note i, LK). # "operand" is OBSERVED (SST) and contradicted by CAP. nop_dc_fc_reads = "absolute" def _op_nop(self) -> None: """NOP -- `$EA`: two cycles, the second a dropped read of the next byte (DS Table 6-4).""" self._fetch_discard() def _op_nop_one_cycle(self) -> None: """NOP -- one byte, one cycle: `x3`, `xB`, and `x7`, `xF`, `$CB`, `$DB` where the row has no instruction there (DS Table 7-1; GDS Table V; CAP: `03` 1, `07` 1 on the G65SC12).""" # The opcode fetch was the whole instruction. There is no second-to-last # cycle in which to poll, and no interrupt is taken after it (U7). # One cycle: MEASURED (CAP). No poll: DOC (CL, LK) and TEST ROM (LT test 8). if not self.one_cycle_nops_poll: self._polled = NO_POLL self._deferred = None def _op_nop_imm(self) -> None: """NOP -- two bytes, two cycles: `02 22 42 62 82 C2 E2` (DS Table 7-1; CAP: `02` 2).""" self._fetch() def _op_nop_zp(self) -> None: """NOP -- `$44`: two bytes, three cycles, reads the zero-page byte (DS Table 7-1; CL section 9 note g; CAP: 3).""" address = self._fetch() self._read(address) def _op_nop_zpx(self) -> None: """NOP -- `54 D4 F4`: two bytes, four cycles, a `zp,X` read (DS Table 7-1; CL section 9 note h; CAP: `54` 4).""" address = self._ea_zpx() self._read(address) def _op_nop_abs(self) -> None: """NOP -- `DC FC`: three bytes, four cycles, an absolute read (DS Table 7-1; CL section 9 note i; CAP: `DC` 4).""" address = self._fetch_word() if self.nop_dc_fc_reads == "absolute": self._read(address) # C10: CL note i, LK and CAP else: self._read((self.pc - 1) & 0xFFFF) # the corpus's address def _op_nop_5c(self) -> None: """NOP -- `$5C`: three bytes, eight cycles (DS Table 7-1; CAP: 8 on both parts; SST says 4, C1).""" low = self._fetch() self._fetch() if self.nop_5c_reads == "ff_page": self._read(0xFF00 | low) # U9: LK; CAP could tell in 3 of 9 executions, and agrees for _ in range(4): self._read(0xFFFF) else: for _ in range(5): self._fetch_discard()