"""Two things in huc6280-python v0.3.0 that looked odd while transcribing; shown, not fixed.""" from huc6280 import HuC6280 def machine(code, during): memory = bytearray(0x200000) memory[0x1F0000:0x1F0000+len(code)] = bytes(code) for vector, target in ((0xFFFA, 0x5000), (0xFFF8, 0x5100), (0xFFF6, 0x5200)): memory[0x1F0000 | vector & 0x1FFF] = target & 0xFF # MPR7 = $F8 too memory[(0x1F0000 | vector & 0x1FFF) + 1] = target >> 8 count = [0] def tick(): action = during.get(count[0]); count[0] += 1 if action: cpu.set_irq_lines(*action) def read(a): tick(); return memory[a] def write(a, v): tick(); memory[a] = v def idle(a): tick() cpu = HuC6280(read, write, idle) cpu.mpr[:] = [0xF8] * 8 cpu.pc = 0x4000 return cpu # (e) capture/restore at a boundary where the poll saw a line that has since dropped. # CLI; NOP; NOP: IRQ1 is up, and drops in the first NOP's last cycle (cycle 3). for restore in (False, True): cpu = machine([0x58, 0xEA, 0xEA], {3: (False, False, False)}) cpu.set_irq_lines(True, False, False) cpu.step(); cpu.step() if restore: cpu.restore_state(cpu.capture_state()) cpu.step() print(f"(e) restore={restore}: pc after the boundary ${cpu.pc:04X}") # (s) a swap of sources in the last cycle: TIQ up at the poll; in NOP1's last cycle TIQ drops and # IRQ1 rises. IRQ_LINE never changes, so the frame defers nothing and IRQ1 is taken at once. cpu = machine([0x58, 0xEA, 0xEA], {3: (True, False, False)}) cpu.set_irq_lines(False, False, True) cpu.step(); cpu.step(); cpu.step() print(f"(s) TIQ swapped for IRQ1 in the last cycle: pc after the boundary ${cpu.pc:04X}") # (a) the vanished interrupt runs the instruction through _enter_interrupt, which returns past # step()'s deferred bookkeeping: a line raised in that instruction's last cycle is then taken # at once, where after any other instruction it waits one more. # CLI; NOP; NOP; NOP; NOP. Case 1: TIQ up, drops in NOP1's last cycle (vanishes), IRQ1 rises in # NOP2's last cycle (cycle 5). Case 2: no TIQ at all, IRQ1 rises in NOP2's last cycle. for name, start, during in (("after a vanished entry", (False, False, True), {3: (False, False, False), 5: (True, False, False)}), ("after a plain instruction", (False, False, False), {5: (True, False, False)})): cpu = machine([0x58, 0xEA, 0xEA, 0xEA, 0xEA], during) cpu.set_irq_lines(*start) trail = [] for _ in range(5): cpu.step(); trail.append(f"${cpu.pc:04X}") print(f"(a) IRQ1 raised in the last cycle of NOP2, {name}: pc after each step {' '.join(trail)}")