Skip to content

Add SHC v5.0 (Release 32) for Saturn - #2115

Merged
mkst merged 6 commits into
decompme:mainfrom
masonc15:saturn-shc
Sep 27, 2026
Merged

mkst merged 6 commits into
decompme:mainfrom
masonc15:saturn-shc

Conversation

@masonc15

@masonc15 masonc15 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Hi! I'm working on a matching decomp of Tetris: The Absolute The Grand Master 2 PLUS, a Psikyo SH-2 arcade game. It turns out it was built with Hitachi SHC v5.0, which decomp.me already has for Dreamcast. But those entries hard-code -cpu=sh4 -endian=little -fpu=single -macsave=0, so they can't produce SH-2 code.

This adds shc-v5.0r32-sh2 to the Saturn platform. It reuses the Dreamcast shc-v5.0r32 package through base_compiler, the same way the IRIX IDO compilers reuse the N64 ones, so nothing is needed in the compilers repo. It gets its own command line (-cpu=sh2 -endian=big) and a small shc-sh2 flag class. That class drops -fpu/-round, which have no effect on SH-2 (I compiled the same file with and without them under -cpu=sh2 and the code is byte-identical), keeps -aggressive=2, which still applies without an FPU (it turns x / 3.0f into a __muls by the reciprocal 0x3eaaaaab instead of a __divs by 3.0f), and adds -division and -macsave. Leaving those unset gives the compiler defaults, -division=cpu and -macsave=1, which I checked by compiling with and without them.

I tested it on a local instance, and scratches for two functions from the ROM compiled and scored 0. ruff check, ruff format --check, mypy and Biome pass too. One caveat is that rof2elf.py pads alignment gaps with 0x00 while this ROM has 0xFF, so a literal pool padding halfword can show up as a diff.

I only added r32, since that's the release I matched against (r26 through r31 give identical output on this game). The other SHC releases could go in the same way if anyone needs them.

Let me know if this approach makes sense. Thanks for taking a look!

Comment thread backend/coreapp/flags.py Outdated
@mkst

mkst commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Does rof2elf.py need updating to add a flag e.g. --padding 0xff (defaults to 0x0)?

@masonc15

Copy link
Copy Markdown
Contributor Author

Does rof2elf.py need updating to add a flag e.g. --padding 0xff (defaults to 0x0)?

Yeah, that would work to fix the padding difference. We'd also need to update the pinned script in decompme/compilers.

Would it make sense to let each scratch choose the padding value? This game uses 0xff for those gaps, but I haven't checked other games. The scratch's compiler flags currently go to shc.exe, so we'd need to pass this one separately to rof2elf.py. Happy to do whatever you prefer.

@mkst

mkst commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

I think KISS, so just set the padding to 0xFF for this compiler and worry about needing something different if that scenario ever comes up in the wild.

@masonc15

Copy link
Copy Markdown
Contributor Author

Done! I opened decompme/compilers#89 first, since rof2elf.py needed the new option. It still uses 0x00 by default, so Dreamcast stays the same. This PR now passes --padding 0xff for Saturn.

Please merge the compilers PR first and rebuild the SHC images. Otherwise this one will break. I tested both together locally, and the padding diffs are gone.

@jnackmclain

Copy link
Copy Markdown

This PR is ai btw, you can find the ai's notes on how to gently make a pr that doesnt set off ai red flags here
https://github.com/masonc15/tgm2p-decomp/blob/main/decompme/NOTES.md

with the pr its making here
https://github.com/masonc15/tgm2p-decomp/blob/main/decompme/PR.md

This one section specifically is pretty funny
image

@masonc15

masonc15 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor Author

This PR is ai btw, you can find the ai's notes on how to gently make a pr that doesnt set off ai red flags here https://github.com/masonc15/tgm2p-decomp/blob/main/decompme/NOTES.md

with the pr its making here https://github.com/masonc15/tgm2p-decomp/blob/main/decompme/PR.md

This one section specifically is pretty funny

What's the point of this? This repository has no rule banning AI-assisted contributions, and yes, I did use Astra and Opus 5.5 in combination with my existing programming experience to create this PR. This PR is to add a currently unsupported platform to decomp.me to support a game I want to decompile. If you have actual criticism on the quality of the code in this PR, I'd be all ears.

@mkst

mkst commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for your input, this is quite a targeted PR to add/repurpose an existing compiler. The verbose comments (that I asked to be removed) along with the PR wording in general gave the impression that this was, at the minimal, guided by AI. But I don't have an issue with the result.

@masonc15

Copy link
Copy Markdown
Contributor Author

@mkst Is this good to be merged? Should be all set.

@mkst
mkst merged commit 4ab701a into decompme:main Sep 27, 2026
7 checks passed

This branch was successfully deployed

1 active deployment
Preview — db713f79 Deployed Sep 24, 2026 by vercel[bot]
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.

3 participants