-- Inject a native-mode interrupt into memBlockIrq while an armed outer -- move is executing its block-move stub on the stack (PB 0, PC below the -- program at $1000), never into a handler and at most every third frame, -- so the outer moves make progress between handlers. local cpu = manager.machine.devices[":maincpu"] local mem = cpu.spaces["program"] local irqFrame = 0 emu.register_frame_done(function() irqFrame = irqFrame + 1 if irqFrame % 3 ~= 0 then return end if mem:read_u16(0x025022) ~= 1 or mem:read_u16(0x025028) ~= 0 then return end local pc = cpu.state["PC"].value if cpu.state["PB"].value ~= 0 or pc < 0x0100 or pc >= 0x1000 then return end local s = cpu.state["S"].value local p = cpu.state["P"].value mem:write_u8(s, cpu.state["PB"].value) mem:write_u8(s - 1, (pc >> 8) & 0xFF) mem:write_u8(s - 2, pc & 0xFF) mem:write_u8(s - 3, p) cpu.state["S"].value = s - 4 cpu.state["P"].value = (p | 0x04) & 0xF7 cpu.state["PC"].value = mem:read_u16(0x025020) mem:write_u16(0x025028, 1) mem:write_u16(0x025024, mem:read_u16(0x025024) + 1) end)