I've come to the point where my emulator runs most (all?) mapper-0 games pretty well, but the frame rate is so high that it renders the games unplayable. my PPU implementation is currently scanline-based, and the whole thing is currently wildly inaccurate, but that's beside the point.
So, what's the best way of implementing a frame limiter?
I was thinking about doing it like I would do if I was programming a video game, that is, calculate a delta time and match it against my desired frame rate (60 Hz)
something like this:
I do realize that this might not be completely kosher though, and it might waste a lot of CPU cycles for nothing.
here is some pseudocode of my emulators main loop:
while(cpu_cycles() < 113)
run_cpu();
nextscanline();
clear_cpu_cycles();
check_for_irqs()
if(nmi_occured)
{
do_nmi_stuff();
draw_to_screen();
}
any suggestions or good advice?
So, what's the best way of implementing a frame limiter?
I was thinking about doing it like I would do if I was programming a video game, that is, calculate a delta time and match it against my desired frame rate (60 Hz)
something like this:
Code:
starttime = getticks();
emulate_one_frame();
delta = getticks()-starttime;
if(delta < some_value)
delay(some_value - delta);
emulate_one_frame();
delta = getticks()-starttime;
if(delta < some_value)
delay(some_value - delta);
I do realize that this might not be completely kosher though, and it might waste a lot of CPU cycles for nothing.
here is some pseudocode of my emulators main loop:
Code:
while(cpu_cycles() < 113)
run_cpu();
nextscanline();
clear_cpu_cycles();
check_for_irqs()
if(nmi_occured)
{
do_nmi_stuff();
draw_to_screen();
}
any suggestions or good advice?