Description
I wrote a test ROM generator (fuzzer) for the GBA, and generated some ROMs with it. Running them on mGBA shows that the way you determine your carry flag in THUMB SBC instructions does not always work. Below is the error my generated test ROM gives:
The test shifts r1
by r2
, stores it in r3
(clearing the carry flag), then the SBC instruction is called (SBC r4, r3
), which should have the carry flag cleared as output. YetAnotherEmuDev confirmed it, in your THUMB mode SBC carry flag checking, n
overflows, and is then used for calculating the flag.
By the way, the ROM was tested on hardware, and it passed, just to be clear. I hope this helps!
By the way, if you want to check this for yourself, the ROM that showed this particular issue is still in the repo, but really any ROM you generate with it with enough test cases will show this issue.
Also, the way you set it for ARM ADC/SBC/RSC instructions seems to be correct, so it should be an easy fix!