Jump to content
IGNORED

NES: NMI versus main loop


tschak909

Recommended Posts

After reading the Super Mario Bros. disassembly quite thoroughly, I find myself asking what are the advantages/disadvantages to putting the whole game inside the NMI? This to me makes a lot of sense, because it's providing a very reliable way to not only trigger frame logic, but also to ensure that you're not using too many cycles (as overrun becomes very obvious.)

 

What else can any NES coders on here provide as far as insight into this?

 

-Thom

Link to comment
Share on other sites

Hi there,

 

I would tend to agree. I haven't coded for the NES but have stated the same for the 7800 and 5200.

 

A main loop seems fine for activities that aren't time bound. An NMI however guarantees you refresh with every frame. With the 7800, which handles turning off VBLANK for you, you can cause an NMI when your display physically ends and not wait for the system to do it for you. This saves cycles, as you've stated, and could give you a little more time for game logic.

Edited by DEBRO
Link to comment
Share on other sites

Yeah, and from the disassemblies i've seen, a lot of the early NES games literally just initialize the hardware, set the NMI and then throw themselves into a never ending loop, with the game happening in the NMI using a jump engine pattern... am considering this for my Wizard of Wor port as I don't need to do anything too special...

 

(I'm also seeing if I can do this in CC65...masochistic? perhaps.) ;)

 

-Thom

Link to comment
Share on other sites

There are 3 valid ways to do it. If you never have a frame that takes too long, then it doesn't matter much. Really, I'm no expert, there's a lot better info if you look at the nesdev wiki. That said, my understanding of the three is:

 

1. All in NMI (like Mario). Downside is that if you take too long in a frame, it re-starts NMI and things get wonky.

 

2. All in main (other than a flag that gets triggered in NMI). If a frame takes too long, your rendering doesn't happen during vblank and you get a couple wonky frames.

 

3. (What the NES Dev folks are recommending these days) do game logic in main, do vblank rendering and sound updates in NMI. This way if frames take too long, the game play slows down, but music and rendering isn't impacted.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...