Skip to content

fix implementation of sqrt in freebios - #2720

Open
bigfarts wants to merge 1 commit into
melonDS-emu:masterfrom
bigfarts:master
Open

fix implementation of sqrt in freebios#2720
bigfarts wants to merge 1 commit into
melonDS-emu:masterfrom
bigfarts:master

Conversation

@bigfarts

@bigfarts bigfarts commented Aug 1, 2026

Copy link
Copy Markdown

The sqrt SWI takes an unsigned integer, but subge/orrge perform signed comparisons. This means for any number >= 0x80000000, we perform incorrect arithmetic and the root gets forced to 0. This switches the instructions to perform unsigned comparisons.

An example of this bug can be observed in Rockman.EXE Operate Shooting Star, where if Rockman is on the furthest row from a Beetank, the Beetank's projectile will be aimed at itself rather than Rockman.

Before:
image

After:
image
image

The sqrt SWI takes an unsigned integer, but subge/orrge perform signed comparisons. This means for any number >= 0x80000000, we perform incorrect arithmetic and the root gets forced to 0. This switches the instructions to perform unsigned comparisons.
@Jaklyy

Jaklyy commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

skimmed through the retail ntr arm9 bios and this looks like a correct fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants