Hello again all.
I'm getting to a point in my game where I'm considering adding a status bar, and even though I haven't dug into writing the code for it yet I'm foreseeing some issues.
I read the Advanced Nerdy Nights tutorial on using the sprite 0 hit to determine the scanline where you want to change your scroll. What I'm worried about is that it seems like when you do that you're spending a significant amount of time in your NMI handler just waiting for that sprite 0 hit. Now, I'm not totally sure how long it takes my main program loop to execute, or if there is even a way to know. But I recently incorporated horizontal scrolling into my program, and I'm noticing an intermittent lack of smoothness in the scrolling, and I'm not sure the cause, but I think it could be that my main loop is taking longer than one frame to execute at times, so you can understand why I'd be concerned about the waiting time for the sprite 0 hit.
So, what's the solution? There's a throwaway line in the NesDev wiki article about using an IRQ to track your scanline (I guess if you're using a mapper that does that). I know that an IRQ is a type of interrupt, but I'm not really familiar with what exactly it is or what causes it, or how you would go about setting it up. But in my head I'm imagining:
1. Interrupt when your status bar is completely drawn.
2. Interrupt handler changes the PPU scroll value.
3. Return to main loop.
Is that a good way to do it? How would you go about it? Am I worrying too much about the time for the sprite 0 hit? Is there a way to track the execution time of your main logic? Is there some other solution I'm not thinking of? Sorry I couldn't boil this down to a single question, but if someone can give some advice or direct me to some post or tutorial that would be great. Thanks in advance for your help!
I'm getting to a point in my game where I'm considering adding a status bar, and even though I haven't dug into writing the code for it yet I'm foreseeing some issues.
I read the Advanced Nerdy Nights tutorial on using the sprite 0 hit to determine the scanline where you want to change your scroll. What I'm worried about is that it seems like when you do that you're spending a significant amount of time in your NMI handler just waiting for that sprite 0 hit. Now, I'm not totally sure how long it takes my main program loop to execute, or if there is even a way to know. But I recently incorporated horizontal scrolling into my program, and I'm noticing an intermittent lack of smoothness in the scrolling, and I'm not sure the cause, but I think it could be that my main loop is taking longer than one frame to execute at times, so you can understand why I'd be concerned about the waiting time for the sprite 0 hit.
So, what's the solution? There's a throwaway line in the NesDev wiki article about using an IRQ to track your scanline (I guess if you're using a mapper that does that). I know that an IRQ is a type of interrupt, but I'm not really familiar with what exactly it is or what causes it, or how you would go about setting it up. But in my head I'm imagining:
1. Interrupt when your status bar is completely drawn.
2. Interrupt handler changes the PPU scroll value.
3. Return to main loop.
Is that a good way to do it? How would you go about it? Am I worrying too much about the time for the sprite 0 hit? Is there a way to track the execution time of your main logic? Is there some other solution I'm not thinking of? Sorry I couldn't boil this down to a single question, but if someone can give some advice or direct me to some post or tutorial that would be great. Thanks in advance for your help!