// global system clock public void Clock() { ppu.Clock(); if (clockCounter % 3 == 0) { if (dmaStarted) { if (dmaDummy) { if (clockCounter % 2 == 1) { dmaDummy = false; } } else { if (clockCounter % 2 == 0) { UInt16 address = BitMagic.Combine(dmaPage, dmaAddress); dmaData = CpuRead(address); } else { ppu.Oam[dmaAddress++] = dmaData; // after 256 writes dmaAddress loops back to zero if (dmaAddress == 0) { dmaStarted = false; dmaDummy = true; } } } } else { cpu.Clock(); } } if (ppu.EmitNmi) { cpu.NMI(); } clockCounter++; }