I'm writing an NES emulator and I've completed the CPU with cycle timing.
I'm now working on the PPU but having an issue trying to grasp how to actually do timing/drawing.
The CPU and the PPU have fixed frequencies. The frequency to on the CPU makes sense to me... The CPU executes instructions in memory, each having their own cycle counts.
The PPU, on the other hand, doesn't actually execute any instructions, yet it still has a clock rate. From the emulators perspective, I'm having difficulty trying to figure out what to do with the clock rate of the PPU, and tying that into drawing pixels on the screen.
My code is like this:
But I dont understand where the PPU clock should tie into this. Am I approaching this wrong?
If anyone has any advice or articles that they can point me to, I'd greatly appreciate it. Thanks.
I'm now working on the PPU but having an issue trying to grasp how to actually do timing/drawing.
The CPU and the PPU have fixed frequencies. The frequency to on the CPU makes sense to me... The CPU executes instructions in memory, each having their own cycle counts.
The PPU, on the other hand, doesn't actually execute any instructions, yet it still has a clock rate. From the emulators perspective, I'm having difficulty trying to figure out what to do with the clock rate of the PPU, and tying that into drawing pixels on the screen.
My code is like this:
Code:
while (1)
{
int cpu_cycles = execute_next_cpu_instruction();
wait_until_cpu_cycles_elapse(cpu_cycles);
}
{
int cpu_cycles = execute_next_cpu_instruction();
wait_until_cpu_cycles_elapse(cpu_cycles);
}
But I dont understand where the PPU clock should tie into this. Am I approaching this wrong?
If anyone has any advice or articles that they can point me to, I'd greatly appreciate it. Thanks.