ITotalJustice / notorious_beeg

gba emulator written in c++23
https://notorious-beeg.netlify.app/
GNU General Public License v3.0
41 stars 4 forks source link

[v-rally 3] flashing whilst racing #54

Closed ITotalJustice closed 2 years ago

ITotalJustice commented 2 years ago

this is a bug with my scheduler timing, either interrupt related or timer (likely) related.

the game only flashes if the irq for fifo dma fires. this doesnt happen in non-scheduler build.

had some audio issues iirc due to scheduler in other games as well, need to look into this at some point.

ITotalJustice commented 2 years ago

https://user-images.githubusercontent.com/47043333/164571435-302cdf81-9392-49f5-a324-b9a66b4dfcf6.mp4

ITotalJustice commented 2 years ago

Went down the rabbit hole of debugging this.

I first figured it was the timers on the scheduler being inconsistent as to when they were fired, nope. Maybe it's dma delay? Nope. How about ppu timing between each mode? Nope.

Only thing left was interrupts. Having everything on the scheduler, but manually checking the interrupts at each time I tick the cpu works. I don't understand why.

What seems to be happening though is vcount and dma2 irq seem to both always be enabled when the flash happens (in the scheduler build). This is not the case when manually handling irq.

To fix this, I need to get the timing as to when the irq is being being fired. From there I get maybe understand the timing difference

ITotalJustice commented 2 years ago

fixed locally. i found the bug by setting a bool everytime an interrupt is scheduled, and unset everytime an interrupt is fired.

By doing this, i found a number of bugs where interrupts are not set when the cpsr.I flag is unset (and (IE & IE) > 0).

for this issue in particular, it is caused from returning from an interrupt: https://github.com/ITotalJustice/notorious_beeg/blob/fc0ea56583616fef7679e530f6ec74571a5949e3/src/core/arm7tdmi/arm/data_processing.cpp#L139 which restores spsr into cpsr https://github.com/ITotalJustice/notorious_beeg/blob/fc0ea56583616fef7679e530f6ec74571a5949e3/src/core/arm7tdmi/arm7tdmi.cpp#L404 which actually sets cpsr.I=false, which enables interrupts.


for the other bugs i found (that don't effect this game)