main loop or nmi?

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

main loop or nmi?

Post by nineTENdo »

Ive been wondering whats the main difference in using a MAIN loop over a NMI. On my demos some subroutines work better in NMI than in Main loop, or sometimes not at all. I've been wondering cause ive been realizing that sometimes my code begins to get buggy after a while, when run in the NMI.

For example in my debounce routine. I never used a delay routine only a STATE to check for a closure. But then i realized that after my code started getting longer and putting more strane on the NMI I had to eventualay add a delay routine b/w closures so that it wouldnt skip a number or so.

After only using NMI to run my code i eventually got lazy and just kept using them to run my code. so i program my code to always looking for closures and then branching. updating what ever it needed when needed and then returning to look for new closures.

I guess what im trying to say is. when it feaseable to use code in your MAIN loop over the NMI? My impression is that while NMI is always updating. MAIN loop is always setting up.

thanks for looking
el

p.s. sorry for the format its better on the eyes and reading flows better
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Using a main loop ensures that there is only one thread of execution, simplifying coding. Putting code in NMI ensures that it runs every frame, regardless of what the main loop is doing. Therefore, you I recommend using the main loop for everything except that which must run every frame.
Post Reply