mgba-emu / mgba

mGBA Game Boy Advance Emulator
https://mgba.io/
Mozilla Public License 2.0
5.72k stars 790 forks source link

Initial-D gb (sgb enhanced) game crashes when starting a race #2501

Closed Bunkai9448 closed 1 year ago

Bunkai9448 commented 2 years ago

Game rom: Initial D Gaiden (Japan) (SGB Enhanced) CRC-32: 6CC56612

The game crashes right after entering in a race. It doesn't matter if it is in time attack (タイムアタック) or in story mode (シナリオ)

Here's the bug report from the PC (v0.9.3) version bug initial-d gb.zip

It also happens on the same version (v0.9.3) in the psVita.

PS: I've tried in the lastest version of hhugboy and BGB and it doesn't happen in those, that's why i think is a mgba bug.

CasualPokePlayer commented 2 years ago

Seems that at some point mGBA gets into a loop where the STAT interrupt occurs within STAT interrupt handler. Game only enables mode 0 IRQ for STAT anyways. Interestingly, the game does write to STAT during the interrupt handler, and that ends up triggering the IRQ? Which that shouldn't be triggering the STAT IRQ in this case (especially since I was using CGB mode, might be some bug with STAT write handling?)

endrift commented 2 years ago

While I'm working on some other stuff, @CasualPokePlayer can you check if this is a regression? It was totally broken before #1473 was fixed, but there's a good range there in the middle.

CasualPokePlayer commented 2 years ago

The game crashes the same way on the commit that fixed that issue.

Although interesting, it doesn't crash if I select CGB mode on that commit. Which means some sort of regression is causing it to occur in CGB mode mode too (CGB-DMG mode having the STAT bug instead of not like before?). Suppose anyways that probably means STAT bug is triggering an IRQ (although it shouldn't be in this case).

https://github.com/LIJI32/SameBoy/blob/76b881c2e153e164485814257fee472572dd8482/Core/sm83_cpu.c#L148-L151 This comment from SameBoy's source seems interesting (as the mode 1->2 transition is "4" cycles away (according to mGBA debugger) when STAT is written to)