public void DisasmLDDEFFFF() { cpu.Reset(); memory.Write8(0x0000, 0x11); // LD DE, nn memory.Write8(0x0001, 0xFF); memory.Write8(0x0002, 0xFF); ushort next = cpu.Disassemble(0x0000, out result); Assert.AreEqual(0x0003, next, "The next op addr must be 0x0003"); Assert.AreEqual("ld de, $FFFF", result, "Disassembly string mismatch"); }
void CpuExecutionThread() { Debug.Log("CPU is waiting for hardware to become ready"); while (!mem.isReady) { Thread.Sleep(10); } while (!screen.isReady) { Thread.Sleep(10); } Debug.Log("CPU started"); Cpu.Reset(); dasm = Cpu.Disassemble(Cpu.Registers.PC); Cpu.ExecutionInfo ei; int cycles; while (!stopped) { if (triggerReset) { triggerReset = false; mem.LoadRom(); Cpu.Reset(); } if (stepMode) { if (!nextStep) { Thread.Sleep(10); continue; } else { nextStep = false; cycles = Cpu.ExecuteSingle(); cyclesExecuted += cycles; dasm = Cpu.Disassemble(Cpu.Registers.PC); } } else { ei = Cpu.Execute(cyclesPerExec); if (ei.cyclesExecuted == 0) { stopped = true; // breakpoint probably } if (autoAdjustCycles) { if (ei.cyclesSlept > 5) { cyclesPerExec -= (ei.cyclesSlept - 5) * 1000; if (cyclesPerExec < 1000) { cyclesPerExec = 1000; } } else if (ei.cyclesSlept < 1) { cyclesPerExec += 5000; } } cyclesExecuted += ei.cyclesExecuted; dasm = Cpu.Disassemble(Cpu.Registers.PC); } } Debug.Log("CPU has stopped"); }