Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in THUMB mode SBC carry flag setting #1818

DenSinH opened this issue Jul 12, 2020 · 1 comment

Error in THUMB mode SBC carry flag setting #1818

DenSinH opened this issue Jul 12, 2020 · 1 comment


Copy link

@DenSinH DenSinH commented Jul 12, 2020

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!

endrift added a commit that referenced this issue Jul 12, 2020
@endrift endrift closed this in 007baef Jul 12, 2020
Copy link

@endrift endrift commented Jul 12, 2020

It was indeed an easy fix. I actually have tests for it, but only in ARM mode!

RetroEdit added a commit to TASVideos/mgba that referenced this issue Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants