I've started writing my first emulator a few months ago (18 months actually according to hg log, but stopped 7 months ago). I want to continue making this thing for educational purposes. As for now it's working quite ok - 6502 emulation is almost 100% complete (per-cycle emulation), few simple non-MMC mappers are implemented, simple APU with pulse1 and pulse2 is added and PPU is good enough for games like Contra.
As for now main loop of emulator looks like this (simplified, not raw copy paste):
Code: Select all
while(1)
{
//HandleEvents()
//Input()
while (!cpu->ppu.framerendered)
{
for(int i=0; i<3; i++) cpu->ppu.Step();
cpu->Step();
}
DrawFrame();
// Sleep long enough to keep 60fps
}
My question is: how to implement changing values of PPU registers during visible scanlines correctly? One of my ideas is just to plot pixel during every PPU cycle, but this is extremely inefficient. Second thought is to render screen scanline by scanline, not whole frame at once. My last concept is to store register values when CPU is writing to them in some kind of vector in form of [scanline, pixel, value] per register. Then use those values during frame rendering.
Which approach is best one? Is there better way to implement this?