CPU emulation

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
CPU emulation
by on (#18236)
- When I wrote my CPU core, I used a single reference that 1 CPU clock equals to 3 PPU clocks. By reading the CPU opcodes reference, it seems clear enough that if a certain instruction (example) uses 1 cycle to fetch the opcode, another for the immediate byte and another for reading memory, so the PPU would execute 3 cycles per CPU cycle. By the way, the last CPU test ROMs fail and nobody could make my question answered... I knew the "half" CPU cycle thing, but what about the PPU itself? An hypotetical example (sorry for those ones that dislike pasting any code):

Code:
//this is pseudo-code

opcode = readmem(cpu->PC); ppu_clock(3);
byte = readmem(cpu->PC); ppu_clock(3);
cpu->A = readmem(byte);
ppu_clock(3); //executes 3 PPU cycles


The following block gives me an error of +1 CPU cycle. I wonder why...

by on (#18240)
Does it work if you take out one of the ppu_clock(3) calls? I'm assuming the above example is for a 3 CPU cycle instruction using zero-page addressing. Are you sure you aren't clocking the PPU elsewhere?