mgba icon indicating copy to clipboard operation
mgba copied to clipboard

Iridion 3D (USA, Europe): line corruption on the game over screen

Open fleroviux opened this issue 2 years ago • 5 comments

image

Start the game and let it run until you game over to reproduce this bug.

Unlike what GBATEK describes, the affine reference point registers aren't copied immediately into the internal registers after a write from the CPU or DMA, but at the start of the next scanline/H-draw period. This means that when writing BGX/BGY in the middle of a scanline, PB/PD won't be added to the internal registers effectively (the result of this operation is discarded, since the new values are latched after the increment).

Here is a hardware test that tests the timing for when the latching happens.

There's a chance for the same line glitches to also appear during the boot sequence of the game on the "Developed by SHiNEN" screen, as used to be the case in NanoBoyAdvance. However this doesn't happen with the way things are implemented currently in mGBA at least.

Credit to @skylersaleh since we worked together on fixing this game in our emulators.

fleroviux avatar Jul 12 '22 20:07 fleroviux

mGBA does not currently have much, if any, sub-scanline precision when it comes to rendering or register latching, which leads to fun issues with affine rendering overall. I'll fix that someday.

endrift avatar Jul 14 '22 00:07 endrift

It seems like the latching is done at (or close to) the very start of the scanline. Sub-scanline precision shouldn't really be necessary in this case specifically.

fleroviux avatar Jul 14 '22 08:07 fleroviux

I don't believe I start drawing a scanline until the end of it, so if the value is latched "instantly", it wouldn't matter as the value that's written mid-scanline would be used when it draws at the end of the scanline. I'd need to double check, though. Regardless, inserting another event into the middle of a scanline is...well, expensive. I'm not entirely sure why. I think it's due to cache penalties. I would prefer to see if I can fix it without doing that.

endrift avatar Jul 14 '22 08:07 endrift

In NBA I set flags when BGX/Y are written and then only latch them (only if they have been written) at the start of the next scanline. There was no need for another event in my case. (See: https://github.com/nba-emu/NanoBoyAdvance/commit/6c8c4e8789dbbef1b2580fe17ca1f3901e98151d)

I believe the same approach would also work for mGBA (despite rendering at a later point) since with this logic it's not possible for the internal reference point registers to actually change mid-scanline.

fleroviux avatar Jul 14 '22 08:07 fleroviux

I looked into doing something like that, but since mGBA's GBA renderer currently doesn't have a concept of registers being written inside hblank vs inside hdraw, it wasn't possible to get it to work right. This is the same reason the Lady Sia bug still isn't properly fixed (see #1486, which is another incarnation of the Lady Sia bug). I wanted to add that in 0.10, but it's been pushed out to 0.11...

endrift avatar Jul 14 '22 08:07 endrift