Rewrite Saturn make rules (#660)

## What

Enhance the existing `Makefile` to build new rules for the Saturn side
of the decomp. This should allow more flexibility when adding new
overlays or when tuning existing rules.

## Changes

I separated part of the Saturn build process in the separate file
`Makefile.saturn.mk`. I realise that naming it `saturn.mk` would have
been enough, but I pre-pended `Makefile.` so it can be found right below
the main `Makefile` when listing files in an alphabetic order. I plan to
do the same with the psx and psp toolchain, therefore you will find
`include Makefile.*.mk` in the main `Makefile`.

I deleted all the game building process done with Docker. Now that we
have an established way to do it natively I think it is no longer
required. We can always run the entire buildchain within a Docker
container instead of having `_native` and `_docker`. Now all the
`_native` references are removed. `build_saturn_native` is now
`build_saturn`.

`check_saturn` is no longer responsible of stripping the ELF into a
binary. That is now part of `build_saturn`.

I removed the references to `_li.o` (e.g. `alucard_li.o`) and used
`.elf` instead, which is closer to how the PSX build chain works. If
`_li.o` was a better preference, please let me know.

I am no longer using `./compile_dosemu.sh`. Instead I am using the new
`$(DOSEMU)` to directly invoke the tool within the Makefile. I have done
that to reduce the amount of dependent files.

I tried minimising duplication as much as possible. We now have a list
of overlays found in `SATURN_OVL_TARGETS`. Each expected output triggers
a series of dependencies so seamlessly build everything. `Makefile` is
smart enough to call `$(SATURN_TOOLCHAIN)` only once. If the game was
already built but just one source or symbol file changed, triggering a
new `build_saturn` will only compile the modified overlay.

The Saturn ADPCM files are now extracted in `assets/` instead of
`build/`. I think `assets/` should contain all the uncompressed and
uncooked files. The list of PCM file is not hardcoded. Instead I am now
using `$(wildcard disks/saturn/SD/*.PCM)`. This now means the tool tries
to convert PCMs from `SDD0.PCM` to `SDF0.PCM` with no success. As the
tool is silently failing I decided to leave it as I wrote it.

## Problems

I rewrote everything thinking about concurrency in mind. But `make -j
build_saturn` gives some unexpected output on `stdout`. I did not dig
too much into it. I suspect it might be dosemu. This is not a stopper as
we were not using `-j` when building the game anyway.

I also noticed doing `VERSION=saturn make build` calls
`mipsel-linux-gnu-ld` for `stage_02`. I suspect it is calling the rule
`$(MAIN_TARGET).elf: $(MAIN_O_FILES)` and simply moving `include
Makefile.*.mk` above it should fix it. But then it would cause the same
problem if I split the PSX rules into their own separate file. We never
used `make build` by setting the env variable `VERSION`, so this is not
either a breaking change or a stopper.

## Post thoughts

I am happy with what I achieved so far. I used the knowledge I
accumulated when maintaining the PSX counterpart. Since I now better
understand how `make` works, I was able to make some better decisions in
the Saturn counterpart. For example triggering a new build when the
symbol list changes is something the PSX build chain lacks of. I think
in the future it would be nice to trigger `make extract` when either the
YAML or the symbol list changes.
This commit is contained in:
Luciano Ciccariello 2023-10-03 21:42:08 +01:00 committed by GitHub
parent db74ae3b91
commit 45a71c03ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 137 additions and 276 deletions

View File

@ -58,14 +58,14 @@ jobs:
sudo dpkg -i fdpp-dev_1.6-1_amd64.deb
sudo dpkg -i comcom32_0.1~alpha3-1_all.deb
sudo dpkg -i dosemu2_2.0~pre9-1_amd64.deb
- name: Prep
run: make -j build_saturn_toolchain_native
- name: Extract dependencies
run: VERSION=saturn make extract_disk
- name: Extract asm
run: make extract_saturn
run: VERSION=saturn make extract
- name: Build saturn binaries
run: make build_saturn_native
run: make build_saturn
- name: Check saturn
run: make check_saturn_native
run: VERSION=saturn make check
function-finder-saturn:
if: github.repository == 'Xeeynamo/sotn-decomp' && github.ref == 'refs/heads/master' && github.event_name == 'push'
@ -100,11 +100,10 @@ jobs:
- name: Install bchunk 7zip
run: |
sudo apt-get install p7zip-full bchunk binutils-sh-elf
- name: Prep
run: make extract_disk_saturn
- name: Extract dependencies
run: VERSION=saturn make extract_disk
- name: Extract asm
run: make extract_saturn
run: VERSION=saturn make extract
- name: Clone asset repository
uses: actions/checkout@v3
with:

231
Makefile
View File

@ -63,9 +63,6 @@ GO := $(HOME)/go/bin/go
GOPATH := $(HOME)/go
SOTNDISK := $(GOPATH)/bin/sotn-disk
GFXSTAGE := $(PYTHON) $(TOOLS_DIR)/gfxstage.py
SATURN_SPLITTER_DIR := $(TOOLS_DIR)/saturn-splitter
SATURN_SPLITTER_APP := $(SATURN_SPLITTER_DIR)/rust-dis/target/release/rust-dis
SATURN_ADPCM_EXTRACT_APP := $(SATURN_SPLITTER_DIR)/adpcm-extract/target/release/adpcm-extract
ICONV := iconv --from-code=UTF-8 --to-code=Shift-JIS
define list_src_files
@ -99,7 +96,6 @@ define link
endef
all: build check
saturn: build_saturn_native check_saturn_native
build: build_$(VERSION)
build_us: main dra weapon ric cen dre mad no3 np3 nz0 sel st0 wrp rwrp tt_000
build_hd: dra
@ -329,65 +325,7 @@ extract_weapon: $(SPLAT_APP)
$(SPLAT) $(CONFIG_DIR)/splat.$(VERSION).weapon.yaml
$(CONFIG_DIR)/generated.$(VERSION).symbols.%.txt:
extract_saturn: $(SATURN_SPLITTER_APP)
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/game.prg.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/t_bat.prg.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/zero.bin.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/stage_02.prg.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/warp.prg.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/alucard.prg.yaml
extract_saturn_pcm: $(SATURN_SPLITTER_APP)
mkdir -p build/saturn/SD
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD01.PCM build/saturn/SD/SD01.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD02.PCM build/saturn/SD/SD02.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD03.PCM build/saturn/SD/SD03.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD04.PCM build/saturn/SD/SD04.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD05.PCM build/saturn/SD/SD05.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD06.PCM build/saturn/SD/SD06.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD07.PCM build/saturn/SD/SD07.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD08.PCM build/saturn/SD/SD08.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD09.PCM build/saturn/SD/SD09.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD0A.PCM build/saturn/SD/SD0A.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD0B.PCM build/saturn/SD/SD0B.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD0C.PCM build/saturn/SD/SD0C.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD0D.PCM build/saturn/SD/SD0D.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD0E.PCM build/saturn/SD/SD0E.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD0F.PCM build/saturn/SD/SD0F.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD10.PCM build/saturn/SD/SD10.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD11.PCM build/saturn/SD/SD11.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD12.PCM build/saturn/SD/SD12.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD13.PCM build/saturn/SD/SD13.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD14.PCM build/saturn/SD/SD14.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD15.PCM build/saturn/SD/SD15.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD16.PCM build/saturn/SD/SD16.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD17.PCM build/saturn/SD/SD17.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD18.PCM build/saturn/SD/SD18.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD19.PCM build/saturn/SD/SD19.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD1A.PCM build/saturn/SD/SD1A.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD1B.PCM build/saturn/SD/SD1B.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD1C.PCM build/saturn/SD/SD1C.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD1D.PCM build/saturn/SD/SD1D.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD1E.PCM build/saturn/SD/SD1E.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD1F.PCM build/saturn/SD/SD1F.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD20.PCM build/saturn/SD/SD20.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD21.PCM build/saturn/SD/SD21.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD22.PCM build/saturn/SD/SD22.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD23.PCM build/saturn/SD/SD23.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD24.PCM build/saturn/SD/SD24.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD25.PCM build/saturn/SD/SD25.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD26.PCM build/saturn/SD/SD26.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD27.PCM build/saturn/SD/SD27.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD28.PCM build/saturn/SD/SD28.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD29.PCM build/saturn/SD/SD29.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD2A.PCM build/saturn/SD/SD2A.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD2B.PCM build/saturn/SD/SD2B.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD2C.PCM build/saturn/SD/SD2C.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD2D.PCM build/saturn/SD/SD2D.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD2E.PCM build/saturn/SD/SD2E.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD2F.PCM build/saturn/SD/SD2F.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD30.PCM build/saturn/SD/SD30.wav
$(SATURN_ADPCM_EXTRACT_APP) disks/saturn/SD/SD31.PCM build/saturn/SD/SD31.wav
include Makefile.*.mk
# Force to extract all the assembly code regardless if a function is already decompiled
force_extract:
@ -423,9 +361,6 @@ extract_disk_psp%:
7z x disks/sotn.psp$*.iso -odisks/psp$*/
extract_disk_ps1%: $(SOTNDISK)
$(SOTNDISK) extract disks/sotn.$*.cue disks/$*
extract_disk_saturn:
bchunk disks/sotn.saturn.bin disks/sotn.saturn.cue disks/sotn.saturn.iso
7z x disks/sotn.saturn.iso01.iso -odisks/saturn/ || true
disk_prepare: build $(SOTNDISK)
mkdir -p $(DISK_DIR)
cp -r disks/${VERSION}/* $(DISK_DIR)
@ -467,11 +402,13 @@ update-dependencies: $(SPLAT_APP) $(ASMDIFFER_APP) $(M2CTX_APP) $(M2C_APP) $(MAS
$(GO) install github.com/xeeynamo/sotn-decomp/tools/sotn-disk@latest
git clean -fd bin/
bin/%:
cd ./bin && wget https://github.com/Xeeynamo/sotn-decomp/releases/download/$*/$*.tar.gz
rm -f $*.tar.gz*
cd ./bin && sha256sum --check $*.tar.gz.sha256 && tar -xzf $*.tar.gz
rm -f $*.tar.gz*
bin/%: bin/%.tar.gz
sha256sum --check $<.sha256
cd bin && tar -xzf ../$<
rm $<
touch $@
bin/%.tar.gz: bin/%.tar.gz.sha256
wget -O $@ https://github.com/Xeeynamo/sotn-decomp/releases/download/cc1-psx-26/$*.tar.gz
$(SPLAT_APP):
git submodule init $(SPLAT_DIR)
git submodule update $(SPLAT_DIR)
@ -495,162 +432,12 @@ $(GO):
$(SOTNDISK): $(GO)
$(GO) install github.com/xeeynamo/sotn-decomp/tools/sotn-disk@latest
$(SATURN_SPLITTER_APP):
git submodule init $(SATURN_SPLITTER_DIR)
git submodule update $(SATURN_SPLITTER_DIR)
cd $(SATURN_SPLITTER_DIR)/rust-dis && cargo build --release
cd $(SATURN_SPLITTER_DIR)/adpcm-extract && cargo build --release
$(BUILD_DIR)/%.s.o: %.s
$(AS) $(AS_FLAGS) -o $@ $<
$(BUILD_DIR)/%.c.o: %.c $(MASPSX_APP) $(CC1PSX)
# $(CROSS)gcc -c -nostartfiles -nodefaultlibs -ggdb -gdwarf-4 $(CPP_FLAGS) $(CC_FLAGS) $(LD_FLAGS) $< -o $@
$(CPP) $(CPP_FLAGS) -lang-c $< | $(ICONV) | $(CC) $(CC_FLAGS) $(PSXCC_FLAGS) | $(MASPSX) | $(AS) $(AS_FLAGS) -o $@
build_saturn_dosemu_docker_container:
docker build -t dosemu:latest -f tools/saturn_toolchain/dosemu_dockerfile .
build_saturn_binutils_docker_container:
docker build -t binutils-sh-elf:latest -f tools/saturn_toolchain/binutils_dockerfile .
build_saturn_toolchain_gccsh:
# get GCCSH
git clone https://github.com/sozud/saturn-compilers.git
rm -rf ./tools/saturn_toolchain/GCCSH
mv saturn-compilers/cygnus-2.7-96Q3-bin ./tools/saturn_toolchain/GCCSH
rm -rf saturn-compilers
# parallel OK
build_saturn_toolchain_docker: build_saturn_dosemu_docker_container build_saturn_binutils_docker_container build_saturn_toolchain_gccsh $(SATURN_SPLITTER_APP)
# CI prep, don't build dosemu container (parallel OK)
build_saturn_toolchain_native: extract_disk_saturn build_saturn_toolchain_gccsh $(SATURN_SPLITTER_APP)
SATURN_BUILD_DIR := build/saturn
# absolute path for docker mounts
SATURN_BUILD_ABS := $(shell pwd)/$(SATURN_BUILD_DIR)
SATURN_DISK_DIR := disks/saturn
# absolute path for docker mounts
SATURN_DISK_ABS := $(shell pwd)/$(SATURN_DISK_DIR)
build_saturn_copy_files:
# copy everything into same directory since dosemu is hard to use otherwise
rm -rf $(SATURN_BUILD_DIR)
mkdir -p $(SATURN_BUILD_DIR)
cp -r ./tools/saturn_toolchain/GCCSH/* $(SATURN_BUILD_DIR)
cp ./src/saturn/macro.inc $(SATURN_BUILD_DIR)
cp -r ./src/saturn/*.c $(SATURN_BUILD_DIR)
cp -r ./src/saturn/*.h $(SATURN_BUILD_DIR)
cp -r ./src/saturn/lib $(SATURN_BUILD_DIR)/lib
cp -r ./include/saturn $(SATURN_BUILD_DIR)/saturn
mkdir -p $(SATURN_BUILD_DIR)/asm/saturn/
mkdir -p $(SATURN_BUILD_DIR)/asm/saturn/
cp -r ./asm/saturn/game $(SATURN_BUILD_DIR)/asm/saturn/game
cp -r ./asm/saturn/t_bat $(SATURN_BUILD_DIR)/asm/saturn/t_bat
cp -r ./asm/saturn/zero $(SATURN_BUILD_DIR)/asm/saturn/zero
cp -r ./asm/saturn/stage_02 $(SATURN_BUILD_DIR)/asm/saturn/stage_02
cp -r ./asm/saturn/warp $(SATURN_BUILD_DIR)/asm/saturn/warp
cp -r ./asm/saturn/alucard $(SATURN_BUILD_DIR)/asm/saturn/alucard
cp ./tools/saturn_toolchain/compile_dosemu.sh $(SATURN_BUILD_DIR)
chmod +x $(SATURN_BUILD_DIR)/compile_dosemu.sh
build_saturn_dosemu_native:
cd build/saturn && OPT_FLAGS=-O2 FILENAME=game sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O2 FILENAME=t_bat sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O2 FILENAME=zero sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O2 FILENAME=stage_02 sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O2 FILENAME=warp sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O2 FILENAME=alucard sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/gfs sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/spr sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/dma sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/scl sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/csh sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/per sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/cdc sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/mth sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/bup sh ./compile_dosemu.sh
cd build/saturn && OPT_FLAGS=-O0 FILENAME=lib/sys sh ./compile_dosemu.sh
build_saturn_dosemu_docker:
docker run --rm -e FILENAME=game -v $(SATURN_BUILD_ABS):/build -w /build dosemu:latest /bin/bash -c "./compile_dosemu.sh"
docker run --rm -e FILENAME=t_bat -v $(SATURN_BUILD_ABS):/build -w /build dosemu:latest /bin/bash -c "./compile_dosemu.sh"
docker run --rm -e FILENAME=zero -v $(SATURN_BUILD_ABS):/build -w /build dosemu:latest /bin/bash -c "./compile_dosemu.sh"
docker run --rm -e FILENAME=stage_02 -v $(SATURN_BUILD_ABS):/build -w /build dosemu:latest /bin/bash -c "./compile_dosemu.sh"
docker run --rm -e FILENAME=warp -v $(SATURN_BUILD_ABS):/build -w /build dosemu:latest /bin/bash -c "./compile_dosemu.sh"
build_saturn_link_docker_ld:
docker run --rm -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c "sh-elf-ld -o zero_li.o -Map zero.map -T zero.ld -T all_syms.txt -T zero_user_syms.txt -verbose zero.o --no-check-sections -nostdlib -s"
docker run --rm -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c "sh-elf-ld -o t_bat_li.o -Map t_bat.map -T t_bat.ld -T all_syms.txt -T t_bat_user_syms.txt -verbose t_bat.o --no-check-sections -nostdlib -s"
docker run --rm -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c "sh-elf-ld -o game_li.o -Map game.map -T game.ld -T all_syms.txt -T game_user_syms.txt -verbose game.o --no-check-sections -nostdlib -s"
docker run --rm -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c "sh-elf-ld -o stage_02_li.o -Map stage_02.map -T stage_02.ld -T all_syms.txt -T stage_02_user_syms.txt -verbose stage_02.o --no-check-sections -nostdlib -s"
docker run --rm -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c "sh-elf-ld -o warp_li.o -Map warp.map -T warp.ld -T all_syms.txt -T warp_user_syms.txt -verbose warp.o --no-check-sections -nostdlib -s"
build_saturn_link_native_ld:
cd build/saturn && sh-elf-ld -o zero_li.o -Map zero.map -T zero.ld -T all_syms.txt -T zero_user_syms.txt -verbose zero.o lib/gfs.o lib/spr.o lib/dma.o lib/scl.o lib/csh.o lib/per.o lib/cdc.o lib/mth.o lib/bup.o lib/sys.o --no-check-sections -nostdlib
cd build/saturn && sh-elf-ld -o t_bat_li.o -Map t_bat.map -T t_bat.ld -T all_syms.txt -T t_bat_user_syms.txt -verbose t_bat.o --no-check-sections -nostdlib
cd build/saturn && sh-elf-ld -o game_li.o -Map game.map -T game.ld -T all_syms.txt -T game_user_syms.txt -verbose game.o --no-check-sections -nostdlib
cd build/saturn && sh-elf-ld -o stage_02_li.o -Map stage_02.map -T stage_02.ld -T all_syms.txt -T stage_02_user_syms.txt -verbose stage_02.o --no-check-sections -nostdlib
cd build/saturn && sh-elf-ld -o warp_li.o -Map warp.map -T warp.ld -T all_syms.txt -T warp_user_syms.txt -verbose warp.o --no-check-sections -nostdlib
cd build/saturn && sh-elf-ld -o alucard_li.o -Map alucard.map -T alucard.ld -T all_syms.txt -T alucard_user_syms.txt -verbose alucard.o --no-check-sections -nostdlib
build_saturn_link_copy:
# link
cat ./config/saturn/game_syms.txt > ./build/saturn/all_syms.txt
cat ./config/saturn/t_bat_syms.txt >> ./build/saturn/all_syms.txt
cat ./config/saturn/zero_syms.txt >> ./build/saturn/all_syms.txt
cp ./config/saturn/t_bat_user_syms.txt ./build/saturn/
cp ./config/saturn/game_user_syms.txt ./build/saturn/
cp ./config/saturn/stage_02_user_syms.txt ./build/saturn/
cp ./config/saturn/warp_user_syms.txt ./build/saturn/
cp ./config/saturn/alucard_user_syms.txt ./build/saturn/
cp ./config/saturn/zero_user_syms.txt ./build/saturn/
cp ./config/saturn/*.ld ./build/saturn
build_saturn_link_docker: build_saturn_link_copy build_saturn_link_docker_ld
build_saturn_link_native: build_saturn_link_copy build_saturn_link_native_ld
# do not run in parallel
build_saturn_docker: build_saturn_copy_files build_saturn_dosemu_docker build_saturn_link_docker
# do not run in parallel
build_saturn_native: build_saturn_copy_files build_saturn_dosemu_native build_saturn_link_native
check_saturn_docker:
# dump binaries using sh binutils container
chmod +x tools/saturn_toolchain/strip.sh
cp tools/saturn_toolchain/strip.sh $(SATURN_BUILD_DIR)
docker run --rm -e INPUT_FILENAME=game_li.o -e OUTPUT_FILENAME=GAME.PRG -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c ./strip.sh
docker run --rm -e INPUT_FILENAME=t_bat_li.o -e OUTPUT_FILENAME=T_BAT.PRG -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c ./strip.sh
docker run --rm -e INPUT_FILENAME=zero_li.o -e OUTPUT_FILENAME=0.BIN -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c ./strip.sh
docker run --rm -e INPUT_FILENAME=stage_02_li.o -e OUTPUT_FILENAME=STAGE_02.PRG -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c ./strip.sh
docker run --rm -e INPUT_FILENAME=warp_li.o -e OUTPUT_FILENAME=WARP.PRG -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c ./strip.sh
# check hashes
sha1sum --check config/check.saturn.sha
check_saturn_native:
# dump binaries using sh binutils container
sh-elf-objcopy ./build/saturn/game_li.o -O binary ./build/saturn/GAME.PRG
sh-elf-objcopy ./build/saturn/t_bat_li.o -O binary ./build/saturn/T_BAT.PRG
sh-elf-objcopy ./build/saturn/zero_li.o -O binary ./build/saturn/0.BIN
sh-elf-objcopy ./build/saturn/stage_02_li.o -O binary ./build/saturn/STAGE_02.PRG
sh-elf-objcopy ./build/saturn/warp_li.o -O binary ./build/saturn/WARP.PRG
sh-elf-objcopy ./build/saturn/alucard_li.o -O binary ./build/saturn/ALUCARD.PRG
# check hashes
sha1sum --check config/check.saturn.sha
diff_saturn_docker:
chmod +x tools/saturn_toolchain/diff.sh
cp tools/saturn_toolchain/diff.sh $(SATURN_BUILD_DIR)
docker run --rm -e FILENAME=$(FILENAME) -v $(SATURN_DISK_ABS):/theirs -v $(SATURN_BUILD_ABS):/build -w /build binutils-sh-elf:latest /bin/bash -c ./diff.sh
diff_saturn_native:
sh-elf-objdump -z -m sh2 -b binary -D ./build/saturn/$(FILENAME) > ./build/saturn/$(FILENAME)-ours.txt && \
sh-elf-objdump -z -m sh2 -b binary -D ./disks/saturn/$(FILENAME) > ./build/saturn/$(FILENAME)-theirs.txt && \
diff ./build/saturn/$(FILENAME)-ours.txt ./build/saturn/$(FILENAME)-theirs.txt > ./build/saturn/$(FILENAME)-diff.txt || true
# Handles assets
$(BUILD_DIR)/$(ASSETS_DIR)/%.layoutobj.json.o: $(ASSETS_DIR)/%.layoutobj.json
./tools/splat_ext/layoutobj.py $< $(BUILD_DIR)/$(ASSETS_DIR)/$*.bin
@ -690,7 +477,7 @@ SHELL = /bin/bash -e -o pipefail
include tools/tools.mk
.PHONY: all, clean, format, check, expected
.PHONY: all, clean, format, check, build, expected
.PHONY: main, dra, ric, cen, dre, mad, no3, np3, nz0, st0, wrp, rwrp, tt_000
.PHONY: %_dirs
.PHONY: extract, extract_%

118
Makefile.saturn.mk Normal file
View File

@ -0,0 +1,118 @@
SATURN_BUILD_DIR := build/saturn
SATURN_ASSETS_DIR := assets/saturn
SATURN_OVL_TARGETS := GAME ALUCARD STAGE_02 WARP T_BAT
SATURN_LIB_TARGETS := lib/gfs lib/spr lib/dma lib/scl lib/csh lib/per lib/cdc lib/mth lib/bup lib/sys
DOSEMU := dosemu -quiet -dumb -f ./dosemurc -K . -E
SATURN_TOOLCHAIN := bin/cygnus-2.7-96Q3-bin
CC1_SATURN := $(SATURN_BUILD_DIR)/CC1.EXE
SATURN_SPLITTER_DIR := $(TOOLS_DIR)/saturn-splitter
SATURN_SPLITTER_APP := $(SATURN_SPLITTER_DIR)/rust-dis/target/release/rust-dis
SATURN_ADPCM_EXTRACT_APP := $(SATURN_SPLITTER_DIR)/adpcm-extract/target/release/adpcm-extract
SATURN_OVL_PRGS := $(addprefix $(SATURN_BUILD_DIR)/,$(addsuffix .PRG,$(SATURN_OVL_TARGETS)))
SATURN_LIB_OBJECTS := $(addprefix $(SATURN_BUILD_DIR)/,$(addsuffix .o,$(SATURN_LIB_TARGETS)))
SATURN_PCM_FILES := $(wildcard disks/saturn/SD/*.PCM)
SATURN_WAV_FILES := $(patsubst disks/saturn/SD/%.PCM,$(SATURN_ASSETS_DIR)/SD/%.wav,$(SATURN_PCM_FILES))
.PHONY: saturn
saturn: build_saturn check_saturn
.PHONY: check_saturn
check_saturn:
sha1sum --check config/check.saturn.sha
.PHONY: build_saturn
build_saturn: $(SATURN_BUILD_DIR)/0.BIN $(SATURN_OVL_PRGS)
.PHONY: extract_saturn
extract_saturn: $(SATURN_SPLITTER_APP)
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/game.prg.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/t_bat.prg.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/zero.bin.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/stage_02.prg.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/warp.prg.yaml
$(SATURN_SPLITTER_APP) $(CONFIG_DIR)/saturn/alucard.prg.yaml
.PHONY: extract_disk_saturn
extract_disk_saturn:
bchunk disks/sotn.saturn.bin disks/sotn.saturn.cue disks/sotn.saturn.iso
7z x disks/sotn.saturn.iso01.iso -odisks/saturn/ || true
.PHONY: extract_saturn_pcm
extract_saturn_pcm: $(SATURN_WAV_FILES)
.PHONY: diff_saturn
diff_saturn:
sh-elf-objdump -z -m sh2 -b binary -D ./build/saturn/$(FILENAME) > ./build/saturn/$(FILENAME)-ours.txt && \
sh-elf-objdump -z -m sh2 -b binary -D ./disks/saturn/$(FILENAME) > ./build/saturn/$(FILENAME)-theirs.txt && \
diff ./build/saturn/$(FILENAME)-ours.txt ./build/saturn/$(FILENAME)-theirs.txt > ./build/saturn/$(FILENAME)-diff.txt || true
$(SATURN_BUILD_DIR)/0.BIN: $(SATURN_BUILD_DIR)/zero.elf
sh-elf-objcopy $< -O binary $@
$(SATURN_BUILD_DIR)/GAME.PRG: $(SATURN_BUILD_DIR)/game.elf
sh-elf-objcopy $< -O binary $@
$(SATURN_BUILD_DIR)/ALUCARD.PRG: $(SATURN_BUILD_DIR)/alucard.elf
sh-elf-objcopy $< -O binary $@
$(SATURN_BUILD_DIR)/STAGE_02.PRG: $(SATURN_BUILD_DIR)/stage_02.elf
sh-elf-objcopy $< -O binary $@
$(SATURN_BUILD_DIR)/WARP.PRG: $(SATURN_BUILD_DIR)/warp.elf
sh-elf-objcopy $< -O binary $@
$(SATURN_BUILD_DIR)/T_BAT.PRG: $(SATURN_BUILD_DIR)/t_bat.elf
sh-elf-objcopy $< -O binary $@
$(SATURN_BUILD_DIR)/zero.elf: $(SATURN_BUILD_DIR)/zero.o $(SATURN_LIB_OBJECTS) config/saturn/zero_syms.txt config/saturn/game_syms.txt config/saturn/zero_user_syms.txt
cd $(SATURN_BUILD_DIR) && \
sh-elf-ld -verbose --no-check-sections -nostdlib \
-o zero.elf \
-Map zero.map \
-T ../../config/saturn/zero.ld \
-T ../../config/saturn/zero_syms.txt \
-T ../../config/saturn/game_syms.txt \
-T ../../config/saturn/zero_user_syms.txt \
zero.o $(addsuffix .o,$(SATURN_LIB_TARGETS))
$(SATURN_BUILD_DIR)/%.elf: $(SATURN_BUILD_DIR)/%.o config/saturn/zero_syms.txt config/saturn/game_syms.txt config/saturn/%_user_syms.txt
cd $(SATURN_BUILD_DIR) && \
sh-elf-ld -verbose --no-check-sections -nostdlib \
-o $*.elf \
-Map $*.map \
-T ../../config/saturn/$*.ld \
-T ../../config/saturn/zero_syms.txt \
-T ../../config/saturn/game_syms.txt \
-T ../../config/saturn/$*_user_syms.txt \
$*.o
$(SATURN_BUILD_DIR)/lib/%.o: $(SRC_DIR)/saturn/lib/%.c $(CC1_SATURN)
mkdir -p $(dir $@)
cd $(SATURN_BUILD_DIR) && $(DOSEMU) "GCC.EXE -c -I./ -O0 -m2 -fsigned-char lib/$*.c -o lib/$*.o"
$(SATURN_BUILD_DIR)/%.o: $(SRC_DIR)/saturn/%.c $(CC1_SATURN)
mkdir -p $(dir $@)
cd $(SATURN_BUILD_DIR) && $(DOSEMU) "GCC.EXE -c -I./ -O2 -m2 -fsigned-char $*.c -o $*.o"
$(CC1_SATURN): $(SATURN_TOOLCHAIN)
mkdir -p $(dir $@)
cp -r $(SATURN_TOOLCHAIN)/* $(SATURN_BUILD_DIR)
cp ./src/saturn/macro.inc $(SATURN_BUILD_DIR)
cp -r ./src/saturn/*.c $(SATURN_BUILD_DIR)
cp -r ./src/saturn/*.h $(SATURN_BUILD_DIR)
cp -r ./src/saturn/lib $(SATURN_BUILD_DIR)/lib
cp -r ./include/saturn $(SATURN_BUILD_DIR)/saturn
mkdir -p $(SATURN_BUILD_DIR)/asm/saturn/
cp -r ./asm/saturn/game $(SATURN_BUILD_DIR)/asm/saturn/game
cp -r ./asm/saturn/t_bat $(SATURN_BUILD_DIR)/asm/saturn/t_bat
cp -r ./asm/saturn/zero $(SATURN_BUILD_DIR)/asm/saturn/zero
cp -r ./asm/saturn/stage_02 $(SATURN_BUILD_DIR)/asm/saturn/stage_02
cp -r ./asm/saturn/warp $(SATURN_BUILD_DIR)/asm/saturn/warp
cp -r ./asm/saturn/alucard $(SATURN_BUILD_DIR)/asm/saturn/alucard
touch $(CC1_SATURN)
$(SATURN_SPLITTER_APP):
git submodule init $(SATURN_SPLITTER_DIR)
git submodule update $(SATURN_SPLITTER_DIR)
cd $(SATURN_SPLITTER_DIR)/rust-dis && cargo build --release
cd $(SATURN_SPLITTER_DIR)/adpcm-extract && cargo build --release
assets/saturn/SD/%.wav: disks/saturn/SD/%.PCM $(SATURN_SPLITTER_APP)
mkdir -p $(ASSET_DIR)/saturn/SD
$(SATURN_ADPCM_EXTRACT_APP) $< $@

View File

@ -1 +1 @@
ab156fe598ccad6aef704b8b35f3272de7edaf7eaab4e3d504c346ce6647df6c cc1-psx-26.tar.gz
ab156fe598ccad6aef704b8b35f3272de7edaf7eaab4e3d504c346ce6647df6c bin/cc1-psx-26.tar.gz

View File

@ -0,0 +1 @@
04ea5aad6daac640c445e571453e7477896e2e3e1e4219787d268233fc9f4960 bin/cygnus-2.7-96Q3-bin.tar.gz

View File

@ -1,4 +0,0 @@
FROM debian:bookworm
RUN apt-get update && \
apt-get install binutils-sh-elf -y

View File

@ -1,2 +0,0 @@
# build object file with dosemu
dosemu -quiet -dumb -f ./dosemurc -K . -E "GCC.EXE -c -I./ $OPT_FLAGS -m2 -fsigned-char $FILENAME.c -o $FILENAME.o"

View File

@ -1,6 +0,0 @@
# disassemble our binary
sh-elf-objdump -z -m sh2 -b binary -D $FILENAME > $FILENAME-ours.txt &&
# disassemble their binary
sh-elf-objdump -z -m sh2 -b binary -D /theirs/$FILENAME > $FILENAME-theirs.txt &&
# diff
diff $FILENAME-ours.txt $FILENAME-theirs.txt > $FILENAME-diff.txt || true

View File

@ -1,30 +0,0 @@
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y -o APT::Immediate-Configure=false \
dos2unix software-properties-common && \
add-apt-repository -y ppa:dosemu2/ppa && \
apt-get update && \
apt-get install -y dosemu2;
ARG USERNAME=user
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
#
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
RUN mkdir -p /etc/dosemu/drives/c && chmod -R 777 /etc/dosemu/drives/c
RUN chmod -R 777 /etc/dosemu/drives/c
USER $USERNAME
WORKDIR /etc/dosemu/drives/c

View File

@ -1,2 +0,0 @@
# strip our binary
sh-elf-objcopy /build/$INPUT_FILENAME -O binary /build/$OUTPUT_FILENAME