*edit* Sorry for the double post on this, folks. Everything below constitutes me misidentifying a very simple bug in my own code. Perhaps it is good to leave posts like this in the forum for others to learn from
*edit* To avoid spamming the forum with an additional thread I'll just update this one. I've since weeded out OAM as the source of the bug I've described. I think it may actually be a bus conflict bug. I use the wiki's recommended best practice for switching banks with UnROM:
And, in one part of my code, I'm doing this inside a loop with rendering off, but also at the end of nmi to update the sound engine. I'm switching to the same bank in all cases, yet I've determined that sometimes I am switched to the wrong bank---but only in the main thread. Thus, it seems like allowing the bankswitch code to get interrupted by nmi can screw up the mapper. I'm certain that I saw a comment by tepples about this some many months ago, but I was not able to find it.
Original post (with bug misidentified):
One bug that shook out of investigating scroll glitch hiding has me a bit puzzled. When I load a location on a map, at a high level, I am currently doing this:
-turn off graphics (both bg and sprites) (assume palette is all black, safely, by now)
-upload all nametable data we want to see when we fade the palette back in. Each chunk of nametable data (row or column) is also accompanied by a sprite OAM command (this stuck around from being adapted from a vblank routine)
-turn on graphics safely and then fade in the palette
So, 99% of the time, this works. But there's a strange bug there where nametable data gets corrupted. I've narrowed it down (I think) to calling sprite OAM with graphics and sprites disabled. When I protected the sprite OAM with a flag like the rest of my data, and only use it when actually ready to show something, the bug I mentioned goes away.
I know I read some comments in a few threads about sprite OAM itself getting corrupted with bg and sprites disabled, but in this case other data in the PPU seems to get corrupted.
The weird thing is, this bug was not present before adding all the extra cycle padding for hiding scrolling glitches. This makes me wonder if it is a pretty rare edge case and is simply working by coincidence (without the new code), and I *should not* be using sprite OAM outside of vblank (with gfx and sprites off), under any circumstances?
*edit* To avoid spamming the forum with an additional thread I'll just update this one. I've since weeded out OAM as the source of the bug I've described. I think it may actually be a bus conflict bug. I use the wiki's recommended best practice for switching banks with UnROM:
Code:
.segment "CODE"
bankswitch:
lda banktable, y ;read a byte from the banktable
sta banktable, y ;and write it back, switching banks
sty current_bank ;store the current bank in RAM
rts
bankswitch:
lda banktable, y ;read a byte from the banktable
sta banktable, y ;and write it back, switching banks
sty current_bank ;store the current bank in RAM
rts
And, in one part of my code, I'm doing this inside a loop with rendering off, but also at the end of nmi to update the sound engine. I'm switching to the same bank in all cases, yet I've determined that sometimes I am switched to the wrong bank---but only in the main thread. Thus, it seems like allowing the bankswitch code to get interrupted by nmi can screw up the mapper. I'm certain that I saw a comment by tepples about this some many months ago, but I was not able to find it.
Original post (with bug misidentified):
One bug that shook out of investigating scroll glitch hiding has me a bit puzzled. When I load a location on a map, at a high level, I am currently doing this:
-turn off graphics (both bg and sprites) (assume palette is all black, safely, by now)
-upload all nametable data we want to see when we fade the palette back in. Each chunk of nametable data (row or column) is also accompanied by a sprite OAM command (this stuck around from being adapted from a vblank routine)
-turn on graphics safely and then fade in the palette
So, 99% of the time, this works. But there's a strange bug there where nametable data gets corrupted. I've narrowed it down (I think) to calling sprite OAM with graphics and sprites disabled. When I protected the sprite OAM with a flag like the rest of my data, and only use it when actually ready to show something, the bug I mentioned goes away.
I know I read some comments in a few threads about sprite OAM itself getting corrupted with bg and sprites disabled, but in this case other data in the PPU seems to get corrupted.
The weird thing is, this bug was not present before adding all the extra cycle padding for hiding scrolling glitches. This makes me wonder if it is a pretty rare edge case and is simply working by coincidence (without the new code), and I *should not* be using sprite OAM outside of vblank (with gfx and sprites off), under any circumstances?