I searched for this, but couldn't seem to find anything related to my issue. Maybe I didn't look hard enough.
I've had this glitchy BG in TMNT 2 on my emulator forever, and I've never been able to determine the cause. Has anybody else run into this before? Maybe in an early stage in your own emulator... it's fine outside of the levels, like intro screen, character select, cutscenes. That all looks great.
Let's begin with... your rom crc (32-bit checksum).
0xA9217EA2
Don't think there's anything wrong with the ROM, it works fine in any other emulator.
Ok, it seems correct.
It's a mapper 4 game (MMC3). How is your PPU IRQ timing code?
Well I'm decrementing the counter on any PPU read where the address line transitions from low to high on bit 12 then doing the IRQ when it wraps around. I can't think of any other MMC3 games that don't look right in it.
Looks like they're changing CHR pages with the IRQ counter (i.e. changing CHR pages at a scanline). It appears they're changing out the CHR-ROM that maps to $0800-0FFF, happening "after" the status bar all the way to where the fire happens. The only thing I can't explain is the CHR swap that's happening on the scanlines near the doorway and under the painting on the left... I would think a lot more would be changing than just that.
Okay, checked it out in no$nes instead -- I highly recommend you do so too. Go to the VRAM Viewer, BG Map tab and take a look. You'll see the exact same behaviour there. So yeah, it's intentional.
Sprite 0 is not involved in any of this (just noting that here in case someone wonders).
I suppose reviewing my bank switching code closely is a good start.