public static bool IsInfiniteLoop(Gameboy gb) { Cpu cpu = gb.Cpu; if (cpu.State != State.OPCODE) { return(false); } Registers regs = cpu.Registers; IAddressSpace mem = gb.Mmu; int i = regs.PC; bool found = true; foreach (int v in new int[] { 0x18, 0xfe }) { // jr fe if (mem.GetByte(i++) != v) { found = false; break; } } if (found) { return(true); } i = regs.PC; foreach (int v in new int[] { 0xc3, BitUtils.GetLsb(i), BitUtils.GetMsb(i) }) { // jp pc if (mem.GetByte(i++) != v) { return(false); } } return(true); }