Skip to content

Fix output of incbins for SN64#445

Merged
ethteck merged 3 commits intoethteck:mainfrom
galaxyhaxz:sn64_incbin_fix
Mar 10, 2025
Merged

Fix output of incbins for SN64#445
ethteck merged 3 commits intoethteck:mainfrom
galaxyhaxz:sn64_incbin_fix

Conversation

@galaxyhaxz
Copy link
Copy Markdown
Contributor

@galaxyhaxz galaxyhaxz commented Feb 26, 2025

ASN64 requires labels to be used for globals in order to access them, which by default, are not generated for text/(ro)databins. It is however generated for regular code, as shown here. I simply mimicked the same logic for the incbin generation. With this fix, an SN64 rom can now be split and reassembled to bin exactness without any manual changes done to splat's output, via modern-asn64.

Before:

.globl gspF3DEX2_fifoTextStart
.incbin "assets/rsp/gspF3DEX2_fifo.textbin.bin"
.end gspF3DEX2_fifoTextStart

After:

.globl gspF3DEX2_fifoTextStart
.ent gspF3DEX2_fifoTextStart
gspF3DEX2_fifoTextStart:
.incbin "assets/rsp/gspF3DEX2_fifo.textbin.bin"
.end gspF3DEX2_fifoTextStart

Co-authored-by: Anghelo Carvajal <angheloalf95@gmail.com>
@AngheloAlf
Copy link
Copy Markdown
Collaborator

I just noticed you are using modern-asn64. The main advantage of it is being able to not deal with the SN64 assembler's weirdness.

In that case you should use other compiler setting in your splat yaml (like KMC ) instead of the SN64 setting.

@galaxyhaxz
Copy link
Copy Markdown
Contributor Author

galaxyhaxz commented Feb 28, 2025

In that case you should use other compiler setting in your splat yaml (like KMC ) instead of the SN64 setting.

I actually already do that--I use KMC but override the labels to be .globl, then assemble with mips64-elf-as--which uses the same label names/format as ASN rather than KMC (it requires globl and not glabel). modern-asn64 is nice but it doesn't handle all edge cases such as usage of the $at register. It's basically required though as asn64 doesn't support %gp_rel, and in general struggles with asm weirdness so whole files need to be pure C before it works right. It's all a hacky workaround.

Trying to use SN64 instead of KMC forces the SN64 div/divu fixes, which don't assemble with mips64-elf-as and likely other modern assemblers, so I actually use KMC just to workaround this issue. That specific setting should probably be configurable so SN64 games can specify SN64 then customize it to work with a modern pipeline.

@Mr-Wiseguy
Copy link
Copy Markdown
Contributor

Mr-Wiseguy commented Feb 28, 2025

then assemble with mips64-elf-as--which uses the same label names/format as ASN rather than KMC (it requires globl and not glabel).

glabel isn't a built-in feature of any assembler, it's just an asm macro. You don't need to switch to .globl here, you just need to include a macro definition file that has glabel defined (like macro.inc which is commonly found in decomps). The reason it works out of the box with modern-asn64 is that I added built in definitions for the common macros that decomps use to it.

@galaxyhaxz
Copy link
Copy Markdown
Contributor Author

galaxyhaxz commented Feb 28, 2025

Ah I see now! That makes sense why these macros are added via the script:

        ".macro glabel label\n"
        "    .global \\label\n"
        "    \\label:\n"
        ".endm\n"
        ".macro dlabel label\n"
        "    .global \\label\n"
        "    \\label:\n"
        ".endm\n"

However, the fix in this PR should still be applied IMO because it ensures it works without having to resort to a macro should you actually use SN64's defaults or .global manually specified.

(And thanks to all your work on Rocket Robot on Wheels, btw, for which the pipeline has largely created a framework for dealing with SN games lol)

@galaxyhaxz galaxyhaxz requested a review from AngheloAlf March 9, 2025 04:53
@galaxyhaxz
Copy link
Copy Markdown
Contributor Author

galaxyhaxz commented Mar 9, 2025

Two more fixes. The first emits a label for incbin data end points (i.e. rspbootTextEnd) to go along with the first fix. The second ensures .globl is used by default for all the labels for SN64 (handwritten asm such as Psy-Q debug stuff).

@Mr-Wiseguy
Copy link
Copy Markdown
Contributor

Mr-Wiseguy commented Mar 9, 2025

Ah I see now! That makes sense why these macros are added via the script:

        ".macro glabel label\n"
        "    .global \\label\n"
        "    \\label:\n"
        ".endm\n"
        ".macro dlabel label\n"
        "    .global \\label\n"
        "    \\label:\n"
        ".endm\n"

However, the fix in this PR should still be applied IMO because it ensures it works without having to resort to a macro should you actually use SN64's defaults or .global manually specified.

(And thanks to all your work on Rocket Robot on Wheels, btw, for which the pipeline has largely created a framework for dealing with SN games lol)

Yeah, agreed since the incbin segments wouldn't work when using the SN64 preset otherwise. These changes also line up with how splat turns on the corresponding functionality in spimdisasm.

@ethteck ethteck merged commit a90e127 into ethteck:main Mar 10, 2025
9 checks passed
@galaxyhaxz galaxyhaxz deleted the sn64_incbin_fix branch March 10, 2025 23:00
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.

4 participants