This is the script demonstrated in Discord, with both graphical and
command line interfaces.
I won't say it's particularly good Python, but it gets the job done for
now :)
This traverses all functions in /asm (after doing `make force_extract`),
and logs all functions called by every function. This takes several
seconds, so the result of this traversing is saved to a text file called
sotn_calltree.txt and used for future runs. I've added this to the
gitignore. As mentioned in the comments at the top of the Python file,
this file can be deleted if the user would like to re-generate the call
tree (mainly if symbols have been renamed, which would change the
generated assembly files).
This is very much meant to be a first draft; it may have bugs and it
definitely has ugly, low-quality code (I had to do a whole bunch of
special cases for assembly that calls functions indirectly, for
example), but at least for now this could be a useful starting point.
Hopefully myself or others will make improvements into the future!
This adds some new Makefile commands:
build_saturn_toolchain: Downloads GCCSH, and builds two docker
containers. One container is binutils for SuperH, and the other has
Dosemu.
build_saturn: Copies GCCSH, the source code, and asm into the build
directory and runs the GCCSH via Dosemu in the docker container.
Everything is kept in the same directory since it's hard to use Dosemu
otherwise.
check_saturn: Dumps the object files to binary using the binutils Docker
container, then checks the hashes.
diff_saturn: Compares the binaries and outputs a diff to
build/saturn/$FILENAME-diff.txt. Used like FILENAME=GAME.PRG make
diff_saturn.
I've added the source for game.c and t_bat.c. I've replaced one of the
asm functions in t_bat.c to show that it's possible to match simple
functions. I'm not able to generate linker scripts yet so functions that
rely on symbols from other overlays generally can't be matched yet.
This workflow is not all that clean so I'm open to ideas on improving
it. I tried using various versions of
https://github.com/decompals/old-gcc to try to get a native compiler but
couldn't get a matching build. I'm not 100% sure that this version of
GCCSH is correct but initial results seem promising.
As of right now, it's not possible to run this in CI since the dosemu
container changes the USER and Github won't let you write to disk if you
do that.
https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions#user