If you have raster effects in your game (status bars, parallax scrolling, etc.) and you don't want them to glitch out during lag frames, you have to setup and/or time these effects from the NMI handler. In addition to that, you must make sure that every variable related to these raster effects (scroll values, $2000/$2001 configurations, scanline offsets, etc.) must be in a state consistent with the frame that's being displayed (for the second - or third? fourth? - time), otherwise you might end up displaying the old frame with the next frame's effects, or, even worse, the partially updated next frame's effects (since this is a lag frame we're talking about).
To avoid that kind of trouble, you need to implement some sort of double buffer for these effects, so you can freely update one set of variables while the other is used for display, and once all frame processing is done, the temporary values get committed.
Back when I didn't support any raster effects, the only variables I had to care about where the general scroll position. The NMI handler itself would copy the temporary scroll values to the actual variables used to set the scroll, only when it wasn't dealing with a lag frame. But now that I'm thinking about implementing something more complex, there might be a lot more variables to commit, and this way doesn't sound so sensible anymore.
Do you think maybe indexing the two sets would work better? Variables would indicate which is the temporary set and which is the committed one, so that flipping between them would just be a matter of changing these indices? Has anyone here ever given some thought to this kind of problem?
To avoid that kind of trouble, you need to implement some sort of double buffer for these effects, so you can freely update one set of variables while the other is used for display, and once all frame processing is done, the temporary values get committed.
Back when I didn't support any raster effects, the only variables I had to care about where the general scroll position. The NMI handler itself would copy the temporary scroll values to the actual variables used to set the scroll, only when it wasn't dealing with a lag frame. But now that I'm thinking about implementing something more complex, there might be a lot more variables to commit, and this way doesn't sound so sensible anymore.
Do you think maybe indexing the two sets would work better? Variables would indicate which is the temporary set and which is the committed one, so that flipping between them would just be a matter of changing these indices? Has anyone here ever given some thought to this kind of problem?