Just for reference, here is my 'main' topic:
viewtopic.php?f=1&t=8236
Anyways, something new, and not specifically related to my project alone. I'm wondering if y'all have any ideas on how to detect infinite loops on the NES.
Some background: The NES runs the CPU 100% of the time. There is no halting that I know of. When a game is done processing during a particular frame, it just runs an infinite loop until NMI hits. Sometimes a game will poll the V-SYNC flag from the PPU while waiting for NMI, sometimes a game will just do nothing at all while waiting for NMI. I suppose a game could also be waiting for Sprite 0 Hit (which it must poll for), or it could be waiting for an IRQ though that's somewhat rare I believe.
But how can I detect when it is doing this? Mainly so that I can then attempt to cut down on CPU usage. Essentially I want to find a way for my NES emulator to stop running infinite loops and instead devote that time to doing graphics or sound or whatever else needs attention. Optimization!
Some ideas:
1) I could just see if it's polling the V-sync or Sprite-0 flags concurrently. For V-sync I could just say "Ok, shut down until V-sync actually happens". For Sprite-0 I could just say, "Ok, I know when that is coming up again, shut down until that moment." That would help some games, but not all.
2) In many cases, games do something silly like:
Code: Select all
LDA #$00
.loop
BEQ loop
Code: Select all
LDA #$00
.blank
STA ppu_data
BEQ .blank
3) I could pre-program for some known loops. Say, "Oh Mario does this, so I'll code for that. Zelda does this other thing, so I'll code for that too." Ugh, I don't want to program for specific games, but at the same time I might need to. I won't tell the emulator "oh this is Mario so do this" but I would say "hey Mario and other types of games do this, so watch for that". Again this could optimize some or even most games, but it feels a bit of a hack.
EDIT: Something else I just thought of: Some games like Donkey Kong uses this 'infinite loop' time to generate random numbers. So, is that something I can skip and reasonably get a 'good enough' experience?
Any other ideas? I'd love to hear them!
Thank you everyone.
Chad