Skip to content

Error in THUMB mode SBC carry flag setting #1818

Closed
@DenSinH

Description

@DenSinH

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:

image

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions