Repository navigation
gba: the open BIOS's Div returns |quotient| in r3 (Minish Cap's file select) - #10
Merged
Merged
Conversation
…select) gpSP's open-source BIOS replacement computes |quotient| into r3 in swi_Div, but its SWI dispatcher restores the caller's r2 / r3 from the stack on the way out, so Div and DivArm never returned it. The real BIOS does, and The Legend of Zelda: The Minish Cap uses it: its file select screen stayed half slid in, with the file slots and the language menu off screen. One instruction in the image (0x17F0): `mov r3, r2` becomes `str r2, [sp, #4]`, which writes |quotient| into the saved r3 slot the dispatcher returns. Found by running the game headless on the Mac: upstream gpSP and ours both showed the broken screen, mGBA (HLE BIOS) did not, mGBA with this open BIOS did, and mGBA with its HLE Div not returning r3 did too. With the patch both gpSP and mGBA (open BIOS) reach the language menu and the file slots. The 11 other GBA games in the library render byte-identical frames (2100 frames each, scripted input) with and without the patch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ESP-IDF Size Report for 'Tab5 Emu'
FLASH uses app .bin size or json2 flash sum. RAM sums DRAM+IRAM via idf_size. Percentages shown when totals are available. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes The Legend of Zelda: The Minish Cap's file select screen. It stayed half slid in, with the file slots and the language menu off screen.
Cause
gpSP's built-in open-source BIOS computes |quotient| into r3 in
swi_Div, but its SWI dispatcher restores the caller's r2 and r3 on the way out (swi_complete: ldmfd sp!, {r2, r3, lr}). SoDivandDivArmnever return r3. The real BIOS does, and Minish Cap uses it.Fix
One instruction in the BIOS image, at offset 0x17F0.
mov r3, r2becomesstr r2, [sp, #4](0xE58D2004), which writes |quotient| into the saved-r3 stack slot that the dispatcher returns. A comment at the top ofopen_gba_bios.cdocuments the patch.How it was found and tested
I ran the game headless on the Mac with scripted input, through the libretro API:
Divnot returning r3Sqrtclobbering r1Regression check: the 11 other GBA games in the library render byte-identical frames with and without the patch (2,100 frames each, same scripted input).
Not tested on the Tab5 yet.
🤖 Generated with Claude Code