# SM64 movement-core parity harness # # make fetch clone the decomp (n64decomp/sm64) into ./sm64 # make build both targets # make test run every input script on both targets and diff # make profile count soft-float calls per frame on the ARM build # make gba-test build one GBA ROM per script, run in mGBA, diff + cycles # make controls two deliberately wrong builds that must FAIL # make demo playable demo ROM: build/demo/sm64demo.gba # make demo-check demo physics vs reference, plus frame-rate tour in mGBA # make bench-check bench ROM in mGBA and NanoBoyAdvance (cycle-accurate) # # Targets: # build/host/harness x86, 32-bit, SSE scalar floats, no FMA: the reference # build/arm/harness ARM7TDMI (GBA CPU), Thumb, soft-float, run under qemu # build/gba/*.gba same ARM objects linked as real GBA ROMs, run in mGBA SM64 ?= sm64 SM64_REV ?= 9921382a68bb0c865e5e45eb594d9c64db59b1af QEMU ?= qemu-arm -cpu ti925t PYTHON ?= python3 DECOMP_SRCS := \ src/game/mario.c \ src/game/mario_step.c \ src/game/mario_actions_moving.c \ src/game/mario_actions_airborne.c \ src/game/mario_actions_stationary.c \ src/game/mario_actions_automatic.c \ src/game/mario_actions_submerged.c \ src/game/mario_actions_object.c \ src/game/mario_actions_cutscene.c \ src/game/macro_special_objects.c \ src/engine/surface_collision.c \ src/engine/surface_load.c \ src/engine/math_util.c OUR_SRCS := src/harness.c src/stubs.c src/anim.c src/levels.c src/bhv_dummies.c DEFINES := -DVERSION_US -DNON_MATCHING -DAVOID_UB -D_LANGUAGE_C -DF3D_OLD \ -DTARGET_N64 -DNO_SEGMENTED_MEMORY INCLUDES := -I$(SM64)/include -I$(SM64)/include/libc -I$(SM64)/src -I$(SM64) \ -I$(SM64)/src/game -Isrc -Ibuild # Strict IEEE single precision on both sides: no fused multiply-add (the # N64's VR4300 has none), no fast-math reassociation. CORE_CFLAGS := -O2 -w -nostdinc -fno-builtin -fno-strict-aliasing \ -ffp-contract=off -fno-fast-math $(DEFINES) $(INCLUDES) HOST_CC := gcc HOST_ARCH := -m32 -msse2 -mfpmath=sse ARM_CC := arm-none-eabi-gcc ARM_ARCH := -mcpu=arm7tdmi -mthumb -mthumb-interwork -mfloat-abi=soft ANIM_SRC := build/mario_anim_data.c HOST_OBJS := $(addprefix build/host/,$(notdir $(DECOMP_SRCS:.c=.o) $(OUR_SRCS:.c=.o))) \ build/host/mario_anim_data.o build/host/platform_stdio.o build/host/sqrtf_host.o ARM_OBJS := $(addprefix build/arm/,$(notdir $(DECOMP_SRCS:.c=.o) $(OUR_SRCS:.c=.o))) \ build/arm/mario_anim_data.o build/arm/platform_stdio.o vpath %.c $(SM64)/src/game $(SM64)/src/engine src build .PHONY: all fetch test profile controls gba gba-test opt-test gba-opt-test gba-prof props props-arm equiv equiv-arm gba-pcprof demo demo-check demo-video bench bench-check bench-report dirty-check skeleton-check render-check import unimport import-check clean inputs .SECONDARY: all: build/host/harness build/arm/harness # Pinned decomp revision, so results stay comparable across machines. fetch: git init -q $(SM64) git -C $(SM64) fetch -q --depth 1 https://github.com/n64decomp/sm64.git $(SM64_REV) git -C $(SM64) checkout -q FETCH_HEAD # Outside tools, fetched at pinned revisions on first use into ext/ (not part # of this repository): devkitPro's gbafix (LGPL) writes the Nintendo logo a # GBA's BIOS checks before it boots a cartridge; NanoBoyAdvance (GPL) is a # cycle-accurate GBA emulator the bench also runs in. GBATOOLS_REV ?= 054d507f90d32784274b6cf7e03f1c43d02d7a57 NBA_REV ?= 55b5cf0ae3d929582ac5bfd486558173502b8354 ext/gba-tools/src/gbafix.c: git init -q ext/gba-tools git -C ext/gba-tools fetch -q --depth 1 https://github.com/devkitPro/gba-tools.git $(GBATOOLS_REV) git -C ext/gba-tools checkout -q FETCH_HEAD ext/nba/CMakeLists.txt: git init -q ext/nba git -C ext/nba fetch -q --depth 1 https://github.com/nba-emu/NanoBoyAdvance.git $(NBA_REV) git -C ext/nba checkout -q FETCH_HEAD # Mario's animation table, generated by the decomp's own converter. $(ANIM_SRC): | build cd $(SM64) && $(PYTHON) tools/mario_anims_converter.py > $(CURDIR)/$@ build build/host build/arm: mkdir -p $@ build/host/%.o: %.c $(ANIM_SRC) | build/host $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) -c $< -o $@ build/arm/%.o: %.c $(ANIM_SRC) | build/arm $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) -c $< -o $@ # Platform glue uses the real toolchain libc, so no -nostdinc here. build/host/platform_stdio.o: src/platform_stdio.c | build/host $(HOST_CC) $(HOST_ARCH) -O2 -Isrc -c $< -o $@ build/host/sqrtf_host.o: src/sqrtf_host.c | build/host $(HOST_CC) $(HOST_ARCH) -O2 -fno-math-errno -c $< -o $@ build/arm/platform_stdio.o: src/platform_stdio.c | build/arm $(ARM_CC) $(ARM_ARCH) -O2 -Isrc -c $< -o $@ build/host/harness: $(HOST_OBJS) $(HOST_CC) $(HOST_ARCH) $^ -o $@ build/arm/harness: $(ARM_OBJS) $(ARM_CC) $(ARM_ARCH) --specs=rdimon.specs $^ -lm -o $@ # ---------- soft-float call profile ---------- FP_WRAPS := $(shell cat src/fp_wraps.txt 2>/dev/null) build/arm/fp_profile.o: src/fp_profile.c | build/arm $(ARM_CC) $(ARM_ARCH) -O2 -Isrc -c $< -o $@ build/arm/platform_stdio_prof.o: src/platform_stdio.c | build/arm $(ARM_CC) $(ARM_ARCH) -O2 -Isrc -DFP_PROFILE -c $< -o $@ build/arm/harness_prof: $(filter-out build/arm/platform_stdio.o,$(ARM_OBJS)) \ build/arm/platform_stdio_prof.o build/arm/fp_profile.o $(ARM_CC) $(ARM_ARCH) --specs=rdimon.specs $^ -lm \ $(foreach f,$(FP_WRAPS),-Wl,--wrap=$(f)) -o $@ profile: build/arm/harness_prof @for f in inputs/*.inp; do \ echo "== $$f"; $(QEMU) build/arm/harness_prof < $$f > /dev/null; \ done # ---------- negative controls ---------- # Two deliberately wrong builds. If the harness is a real oracle, both must # FAIL: x87 keeps 80-bit intermediates, -ffast-math reorders float math. X87_OBJS := $(subst build/host/,build/x87/,$(HOST_OBJS)) FASTARM_OBJS := $(subst build/arm/,build/armfast/,$(ARM_OBJS)) build/x87 build/armfast: mkdir -p $@ build/x87/%.o: %.c $(ANIM_SRC) | build/x87 $(HOST_CC) -m32 -mfpmath=387 $(CORE_CFLAGS) -c $< -o $@ build/x87/platform_stdio.o build/x87/sqrtf_host.o: build/x87/%.o: build/host/%.o | build/x87 cp $< $@ build/x87/harness: $(X87_OBJS) $(HOST_CC) -m32 $^ -o $@ build/armfast/%.o: %.c $(ANIM_SRC) | build/armfast $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) -ffast-math -c $< -o $@ build/armfast/platform_stdio.o: build/arm/platform_stdio.o | build/armfast cp $< $@ build/armfast/harness: $(FASTARM_OBJS) $(ARM_CC) $(ARM_ARCH) --specs=rdimon.specs $^ -lm -o $@ controls: build/host/harness build/x87/harness build/armfast/harness @echo "== control 1: host x87 (80-bit intermediates) vs reference" -$(PYTHON) tools/run_parity.py --host build/host/harness --arm build/x87/harness \ --qemu "" inputs/*.inp | grep -E "^FAIL|bit-exact" | head -8 @echo "== control 2: ARM soft-float with -ffast-math vs reference" -$(PYTHON) tools/run_parity.py --host build/host/harness --arm build/armfast/harness \ --qemu "$(QEMU)" inputs/*.inp | grep -E "^FAIL|bit-exact" | head -8 # ---------- GBA ROMs ---------- # The movement core objects are the very same ones as build/arm; only the # platform layer and the startup code differ. INPUTS := $(wildcard inputs/*.inp) GBA_ROMS := $(patsubst inputs/%.inp,build/gba/%.gba,$(INPUTS)) GBA_CORE := $(filter-out build/arm/platform_stdio.o,$(ARM_OBJS)) GBA_LDFLAGS := -mcpu=arm7tdmi -mthumb-interwork -nostartfiles -T gba/gba.ld --specs=nosys.specs build/gba build/gba/inputs: mkdir -p $@ build/gba/crt0.o: gba/crt0.s | build/gba $(ARM_CC) -mcpu=arm7tdmi -c $< -o $@ build/gba/platform_gba.o: gba/platform_gba.c src/platform.h | build/gba $(ARM_CC) $(ARM_ARCH) -O2 -Isrc -c $< -o $@ build/gba/inputs/%.c: inputs/%.inp tools/embed_input.py | build/gba/inputs $(PYTHON) tools/embed_input.py $< $@ build/gba/inputs/%.o: build/gba/inputs/%.c $(ARM_CC) $(ARM_ARCH) -O2 -c $< -o $@ build/gba/%.elf: build/gba/crt0.o $(GBA_CORE) build/gba/platform_gba.o build/gba/inputs/%.o gba/gba.ld $(ARM_CC) $(GBA_LDFLAGS) build/gba/crt0.o $(GBA_CORE) build/gba/platform_gba.o \ build/gba/inputs/$*.o -lm -lc -lgcc -Wl,-Map,$@.map -o $@ build/gba/%.gba: build/gba/%.elf tools/fix_gba_header.py arm-none-eabi-objcopy -O binary $< $@ $(PYTHON) tools/fix_gba_header.py $@ build/mgba_runner: gba/mgba_runner.c demo/bench.h | build $(HOST_CC) -O2 -Idemo $< -lmgba -o $@ # NanoBoyAdvance, headless (gba/nba/nba_runner.cc), with a stand-in BIOS. build/nba_runner: gba/nba/nba_runner.cc gba/nba/CMakeLists.txt demo/bench.h ext/nba/CMakeLists.txt cmake -S gba/nba -B build/nba -DNBA_DIR=$(CURDIR)/ext/nba -DCMAKE_BUILD_TYPE=Release > /dev/null cmake --build build/nba -j $$(nproc) > /dev/null cp build/nba/nba_runner $@ build/nba/mini_bios.bin: gba/nba/mini_bios.s mkdir -p build/nba $(ARM_CC) -mcpu=arm7tdmi -c $< -o build/nba/mini_bios.o arm-none-eabi-objcopy -O binary build/nba/mini_bios.o $@ build/tools/gbafix: ext/gba-tools/src/gbafix.c mkdir -p build/tools $(HOST_CC) -O2 -w $< -o $@ gba: $(GBA_ROMS) build/mgba_runner gba-test: build/host/harness gba $(PYTHON) tools/run_gba.py --host build/host/harness --runner build/mgba_runner \ --roms build/gba inputs/*.inp # ---------- optimized build ---------- # Same objects as build/arm except the hot files, which come from src/opt/ # (bit-exact rewrites) and are compiled as ARM code. On the GBA, files named # *_iw.o and libgcc's float routines are linked into IWRAM (gba/gba_opt.ld). # The reference stays the unmodified decomp: that is what opt must match. # Files compiled as ARM into IWRAM. A src/opt/.c rewrite is used when # it exists, otherwise the unmodified decomp file. OPT_SRCS ?= surface_collision mario_step OPT_IW_OBJS := $(addprefix build/armopt/,$(addsuffix _iw.o,$(OPT_SRCS))) OPT_ARM_OBJS := $(filter-out $(addprefix build/arm/,$(addsuffix .o,$(OPT_SRCS) anim harness)),$(ARM_OBJS)) \ $(OPT_IW_OBJS) build/armopt/anim_zc.o build/armopt/harness_opt.o build/armopt/collision_cache.o # The collision cache is rebuilt after every static-surface load. OPT_LDWRAP := -Wl,--wrap=load_area_terrain OPT_GBA_CORE := $(filter-out build/arm/platform_stdio.o,$(OPT_ARM_OBJS)) OPT_GBA_ROMS := $(patsubst inputs/%.inp,build/gbaopt/%.gba,$(INPUTS)) ARM_MODE := -mcpu=arm7tdmi -marm -mthumb-interwork -mfloat-abi=soft build/armopt build/gbaopt: mkdir -p $@ build/armopt/%_iw.o: src/opt/%.c src/opt/collision_cache.h $(ANIM_SRC) | build/armopt $(ARM_CC) $(ARM_MODE) $(CORE_CFLAGS) -I$(SM64)/src/engine -Isrc/opt -c $< -o $@ build/armopt/%_iw.o: %.c $(ANIM_SRC) | build/armopt $(ARM_CC) $(ARM_MODE) $(CORE_CFLAGS) -I$(SM64)/src/engine -c $< -o $@ build/armopt/anim_zc.o: src/anim.c $(ANIM_SRC) | build/armopt $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) -DANIM_ZERO_COPY -c $< -o $@ build/armopt/harness_opt.o: src/harness.c $(ANIM_SRC) | build/armopt $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) -DMARIO_ANIM_BUFFER_SIZE=64 -c $< -o $@ build/armopt/collision_cache.o: src/opt/collision_cache.c src/opt/collision_cache.h | build/armopt $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) -Isrc/opt -c $< -o $@ build/armopt/harness: $(OPT_ARM_OBJS) $(ARM_CC) $(ARM_ARCH) --specs=rdimon.specs $^ -lm $(OPT_LDWRAP) -o $@ build/gbaopt/%.elf: build/gba/crt0.o $(OPT_GBA_CORE) build/gba/platform_gba.o build/gba/inputs/%.o gba/gba_opt.ld | build/gbaopt $(ARM_CC) $(subst gba/gba.ld,gba/gba_opt.ld,$(GBA_LDFLAGS)) build/gba/crt0.o $(OPT_GBA_CORE) \ build/gba/platform_gba.o build/gba/inputs/$*.o -lm -lc -lgcc $(OPT_LDWRAP) -Wl,-Map,$@.map -o $@ build/gbaopt/%.gba: build/gbaopt/%.elf tools/fix_gba_header.py arm-none-eabi-objcopy -O binary $< $@ $(PYTHON) tools/fix_gba_header.py $@ # Collision profile: same opt ROMs with collision queries wrapped and timed. PROF_WRAPS := f32_find_wall_collision find_wall_collisions find_floor find_floor_height find_ceil find_water_level build/gbaprof build/gbaprof/obj: mkdir -p $@ build/gbaprof/obj/platform_gba.o: gba/platform_gba.c src/platform.h | build/gbaprof/obj $(ARM_CC) $(ARM_ARCH) -O2 -Isrc -DGBA_PROF -c $< -o $@ build/gbaprof/obj/prof_gba.o: gba/prof_gba.c | build/gbaprof/obj $(ARM_CC) $(ARM_MODE) -O2 -c $< -o $@ build/gbaprof/%.gba: build/gba/crt0.o $(OPT_GBA_CORE) build/gbaprof/obj/platform_gba.o build/gbaprof/obj/prof_gba.o build/gba/inputs/%.o gba/gba_opt.ld | build/gbaprof $(ARM_CC) $(subst gba/gba.ld,gba/gba_opt.ld,$(GBA_LDFLAGS)) build/gba/crt0.o $(OPT_GBA_CORE) \ build/gbaprof/obj/platform_gba.o build/gbaprof/obj/prof_gba.o build/gba/inputs/$*.o \ -lm -lc -lgcc $(OPT_LDWRAP) $(foreach f,$(PROF_WRAPS),-Wl,--wrap=$(f)) -o $(@:.gba=.elf) arm-none-eabi-objcopy -O binary $(@:.gba=.elf) $@ $(PYTHON) tools/fix_gba_header.py $@ gba-prof: $(patsubst inputs/%.inp,build/gbaprof/%.gba,$(INPUTS)) build/mgba_runner $(PYTHON) tools/gba_prof.py --runner build/mgba_runner --roms build/gbaprof inputs/*.inp # Property tests for the exactness arguments behind src/opt/ (host, strict IEEE). PROPS_OBJS := $(filter-out build/host/surface_collision.o build/host/harness.o,$(HOST_OBJS)) build/host/props: src/test/props.c src/opt/surface_collision.c build/host/collision_cache.o $(PROPS_OBJS) $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) -I$(SM64)/src/engine -Isrc/opt -c src/test/props.c -o build/host/props.o $(HOST_CC) $(HOST_ARCH) build/host/props.o build/host/collision_cache.o $(PROPS_OBJS) -lm $(OPT_LDWRAP) -o $@ props: build/host/props ./build/host/props # Same tests on ARM7 soft-float (smaller counts), plus the f2iz sweep. PROPS_ARM_OBJS := $(filter-out build/arm/surface_collision.o build/arm/harness.o,$(ARM_OBJS)) build/armopt/props: src/test/props.c src/opt/surface_collision.c build/armopt/collision_cache.o $(PROPS_ARM_OBJS) | build/armopt $(ARM_CC) $(ARM_MODE) $(CORE_CFLAGS) -I$(SM64)/src/engine -Isrc/opt -DPROPS_SCALE=20 \ -c src/test/props.c -o build/armopt/props.o $(ARM_CC) $(ARM_ARCH) --specs=rdimon.specs build/armopt/props.o build/armopt/collision_cache.o \ $(PROPS_ARM_OBJS) -lm $(OPT_LDWRAP) -o $@ props-arm: build/armopt/props $(QEMU) build/armopt/props # Equivalence test: src/opt/surface_collision.c against the unmodified decomp # file, linked into one binary with the decomp's symbols renamed ref_*. REF_RENAMES := $(foreach s,find_floor find_ceil find_wall_collisions f32_find_wall_collision \ find_floor_height find_floor_height_and_data find_water_level find_poison_gas_level \ debug_surface_list_info unused_obj_find_floor_height unused_find_dynamic_floor \ unused_resolve_floor_or_ceil_collisions sFloorGeo,-D$(s)=ref_$(s)) EQUIV_BASE := $(filter-out surface_collision.o harness.o,$(notdir $(HOST_OBJS))) EQUIV_ARM_QUERIES ?= 200000 build/host/ref_surface_collision.o: $(SM64)/src/engine/surface_collision.c | build/host $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) $(REF_RENAMES) -c $< -o $@ build/host/opt_surface_collision.o: src/opt/surface_collision.c src/opt/collision_cache.h | build/host $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) -I$(SM64)/src/engine -Isrc/opt -c $< -o $@ build/host/collision_cache.o: src/opt/collision_cache.c src/opt/collision_cache.h | build/host $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) -Isrc/opt -c $< -o $@ build/host/equiv: src/test/equiv.c build/host/ref_surface_collision.o build/host/opt_surface_collision.o \ build/host/collision_cache.o $(addprefix build/host/,$(EQUIV_BASE)) $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) -c src/test/equiv.c -o build/host/equiv.o $(HOST_CC) $(HOST_ARCH) build/host/equiv.o build/host/ref_surface_collision.o \ build/host/opt_surface_collision.o build/host/collision_cache.o \ $(addprefix build/host/,$(EQUIV_BASE)) -lm $(OPT_LDWRAP) -o $@ build/armopt/ref_surface_collision.o: $(SM64)/src/engine/surface_collision.c | build/armopt $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) $(REF_RENAMES) -c $< -o $@ build/armopt/equiv: src/test/equiv.c build/armopt/ref_surface_collision.o build/armopt/surface_collision_iw.o \ build/armopt/collision_cache.o $(filter-out build/arm/surface_collision.o build/arm/harness.o,$(ARM_OBJS)) $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) -DEQUIV_QUERIES_PER_LEVEL=$(EQUIV_ARM_QUERIES) \ -c src/test/equiv.c -o build/armopt/equiv.o $(ARM_CC) $(ARM_ARCH) --specs=rdimon.specs build/armopt/equiv.o build/armopt/ref_surface_collision.o \ build/armopt/surface_collision_iw.o build/armopt/collision_cache.o \ $(filter-out build/arm/surface_collision.o build/arm/harness.o,$(ARM_OBJS)) -lm $(OPT_LDWRAP) -o $@ equiv: build/host/equiv ./build/host/equiv equiv-arm: build/armopt/equiv $(QEMU) build/armopt/equiv # Sampling profile of the optimized ROMs (PC/LR every 97 cycles, only inside # Mario's frame update), symbolized with soft-float charged to its callers. gba-pcprof: $(OPT_GBA_ROMS) build/mgba_runner @mkdir -p build/pcprof @ls inputs/*.inp | xargs -P $$(nproc) -I{} sh -c 'n=$$(basename {} .inp); \ MGBA_PROFILE=build/pcprof/$$n.prof ./build/mgba_runner build/gbaopt/$$n.gba >/dev/null 2>&1' $(PYTHON) tools/gba_pcprof.py $(foreach f,$(INPUTS),build/gbaopt/$(basename $(notdir $(f))).elf:build/pcprof/$(basename $(notdir $(f))).prof) opt-test: build/host/harness build/armopt/harness $(PYTHON) tools/run_parity.py --host build/host/harness --arm build/armopt/harness \ --qemu "$(QEMU)" inputs/*.inp gba-opt-test: build/host/harness $(OPT_GBA_ROMS) build/mgba_runner $(PYTHON) tools/run_gba.py --host build/host/harness --runner build/mgba_runner \ --roms build/gbaopt inputs/*.inp # ---------- playable demo ---------- # The same optimized Mario objects as build/gbaopt (bit-exact physics), plus # the demo loop and software renderer. Surface pools are sized for the four # levels (alloc_surface_pools wrapped), which frees ~70 KB of EWRAM. # mario_step.c runs from ROM here (Thumb, as in build/arm, also parity-tested): # its 5.7 KB of IWRAM is worth more as stack and renderer code. DEMO_CORE := $(filter-out build/armopt/harness_opt.o build/arm/stubs.o build/armopt/mario_step_iw.o,$(OPT_GBA_CORE)) \ build/arm/mario_step.o DEMO_OBJS := build/demo/demo_main.o build/demo/render_build.o build/demo/render_iw.o \ build/demo/hud.o build/demo/irq.o build/demo/render_tables.o build/demo/stubs.o \ build/demo/mannequin.o build/demo/skeleton.o DEMO_CFLAGS := -O2 -w -fno-strict-aliasing -Idemo # Imported assets (make import ROM=...): build/import/import_data.c, made from # the user's ROM by tools/import_rom.py. When present (and NOIMPORT is unset) # the demo draws the real Mario model and level meshes; otherwise the # collision mesh and the mannequin. A mode file forces a rebuild on switch. IMPORT_C := $(if $(NOIMPORT),,$(wildcard build/import/import_data.c)) DEMO_MODE := $(if $(IMPORT_C),imported,plain) DEMO_DEFS := $(if $(IMPORT_C),-DDEMO_IMPORTED,) DEMO_MODE_FILE := build/demo/mode.$(DEMO_MODE) $(shell mkdir -p build/demo; [ -f $(DEMO_MODE_FILE) ] || { rm -f build/demo/mode.*; touch $(DEMO_MODE_FILE); }) ifneq ($(IMPORT_C),) DEMO_OBJS += build/demo/import_data.o endif DEMO_LDWRAP := $(OPT_LDWRAP) -Wl,--wrap=alloc_surface_pools build/demo: mkdir -p $@ build/demo/render_tables.c: tools/gen_render_tables.py | build/demo $(PYTHON) tools/gen_render_tables.py $@ build/demo/render_tables.o: build/demo/render_tables.c $(ARM_CC) $(ARM_ARCH) -O2 -c $< -o $@ build/demo/demo_main.o: demo/demo_main.c demo/render.h demo/hud.h demo/mannequin.h demo/gba.h demo/import.h $(DEMO_MODE_FILE) $(ANIM_SRC) | build/demo $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) $(DEMO_DEFS) -Idemo -c $< -o $@ build/demo/render_build.o: demo/render_build.c demo/render.h demo/gba.h demo/import.h $(DEMO_MODE_FILE) | build/demo $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) $(DEMO_DEFS) -Idemo -c $< -o $@ build/demo/render_iw.o: demo/render_iw.c demo/render.h demo/gba.h demo/import.h $(DEMO_MODE_FILE) | build/demo $(ARM_CC) $(ARM_MODE) $(DEMO_CFLAGS) $(DEMO_DEFS) -c $< -o $@ build/demo/import_data.o: build/import/import_data.c demo/import.h | build/demo $(ARM_CC) $(ARM_ARCH) -O2 -w -Idemo -c $< -o $@ # Convert your own ROM: make import ROM=path/to/sm64.z64 (US/JP/EU/Shindou/iQue, # any byte order). The output is derived from your ROM: don't distribute it. import: @test -n "$(ROM)" || { echo "usage: make import ROM=path/to/your/sm64.z64"; exit 1; } $(PYTHON) tools/import_rom.py "$(ROM)" --decomp $(SM64) --out build/import unimport: rm -rf build/import # The import's ROM reading against the decomp's own tools (mio0, n64graphics, # skyconv): synthetic data always, every texture and skybox with ROM=... import-check: $(PYTHON) tools/test_import.py --decomp $(SM64) $(if $(ROM),--rom "$(ROM)",) # Mario's joint hierarchy, extracted from the decomp's geo layout. build/demo/skeleton.c: tools/gen_skeleton.py $(SM64)/actors/mario/geo.inc.c | build/demo $(PYTHON) tools/gen_skeleton.py $(SM64)/actors/mario/geo.inc.c $@ > /dev/null build/demo/skeleton.o: build/demo/skeleton.c $(ARM_CC) $(ARM_ARCH) -O2 -c $< -o $@ build/demo/mannequin.o: demo/mannequin.c demo/mannequin.h demo/render.h demo/gba.h $(DEMO_MODE_FILE) $(ANIM_SRC) | build/demo $(ARM_CC) $(ARM_MODE) $(CORE_CFLAGS) $(DEMO_DEFS) -Idemo -c $< -o $@ build/demo/hud.o: demo/hud.c demo/hud.h demo/gba.h | build/demo $(ARM_CC) $(ARM_ARCH) $(DEMO_CFLAGS) -c $< -o $@ build/demo/irq.o: demo/irq.s | build/demo $(ARM_CC) -mcpu=arm7tdmi -c $< -o $@ build/demo/stubs.o: src/stubs.c $(ANIM_SRC) | build/demo $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) -DPOOL_BYTES=95488 -c $< -o $@ build/demo/sm64demo.elf: build/gba/crt0.o $(DEMO_CORE) $(DEMO_OBJS) gba/gba_opt.ld $(ARM_CC) $(subst gba/gba.ld,gba/gba_opt.ld,$(GBA_LDFLAGS)) build/gba/crt0.o $(DEMO_CORE) \ $(DEMO_OBJS) -lm -lc -lgcc $(DEMO_LDWRAP) -Wl,-Map,$@.map -o $@ # Real hardware: the BIOS only boots a ROM whose header has the Nintendo # logo, which isn't in this repository: devkitPro's gbafix (fetched, see # ext/ above) writes it, then the header is checked as the BIOS would. TITLE_sm64demo := SM64DEMAKE TITLE_sm64bench := SM64BENCH build/demo/%.gba: build/demo/%.elf tools/fix_gba_header.py build/tools/gbafix arm-none-eabi-objcopy -O binary $< $@ $(PYTHON) tools/fix_gba_header.py $@ $(TITLE_$*) build/tools/gbafix $@ > /dev/null $(PYTHON) tools/fix_gba_header.py $@ --check demo: build/demo/sm64demo.gba @grep -E "__iwram_end|__bss_end" build/demo/sm64demo.elf.map | awk '{print " " $$1 " " $$2}' # Plays the demo in mGBA: (1) the physics check replays the inputs the demo # fed Mario through the host reference and compares his position every frame, # (2) a tour of all four levels reports frame rate and quality steps used. demo-check: build/demo/sm64demo.gba build/mgba_runner build/host/harness $(PYTHON) tools/demo_physics_check.py --runner build/mgba_runner --rom build/demo/sm64demo.gba \ --harness build/host/harness --keys demo/keys/physics_check.keys --frames 1500 ./build/mgba_runner build/demo/sm64demo.gba --frames 2880 --keys demo/keys/tour.keys > build/demo/tour.log 2>/dev/null $(PYTHON) tools/demo_stats.py build/demo/tour.log # ---------- bench ---------- # The demo with a built-in tour (demo/keys/bench.keys, by game frame) that # records every frame in the cartridge's save RAM (demo/bench.h). The same ROM # runs in mGBA, in NanoBoyAdvance and on a GBA from a flash cart, and # tools/bench_report.py reads the .sav each one leaves. build/demo/bench_keys.c: demo/keys/bench.keys tools/embed_keys.py | build/demo $(PYTHON) tools/embed_keys.py $< $@ build/demo/bench_keys.o: build/demo/bench_keys.c demo/bench.h $(ARM_CC) $(ARM_ARCH) -O2 -Idemo -c $< -o $@ build/demo/demo_main_bench.o: demo/demo_main.c demo/bench.h demo/render.h demo/hud.h demo/mannequin.h demo/gba.h demo/import.h $(DEMO_MODE_FILE) $(ANIM_SRC) | build/demo $(ARM_CC) $(ARM_ARCH) $(CORE_CFLAGS) $(DEMO_DEFS) -DDEMO_BENCH -Idemo -c $< -o $@ BENCH_OBJS := $(filter-out build/demo/demo_main.o,$(DEMO_OBJS)) build/demo/demo_main_bench.o build/demo/bench_keys.o build/demo/sm64bench.elf: build/gba/crt0.o $(DEMO_CORE) $(BENCH_OBJS) gba/gba_opt.ld $(ARM_CC) $(subst gba/gba.ld,gba/gba_opt.ld,$(GBA_LDFLAGS)) build/gba/crt0.o $(DEMO_CORE) \ $(BENCH_OBJS) -lm -lc -lgcc $(DEMO_LDWRAP) -Wl,-Map,$@.map -o $@ bench: build/demo/sm64bench.gba BENCH_RUN := build/demo/sm64bench.gba BENCH_MGBA := ./build/mgba_runner $(BENCH_RUN) --frames 5000 --sram # The bench in mGBA and in NanoBoyAdvance. mGBA's run replays its first level # through the host reference (Mario bit for bit); NBA's must match mGBA's on # every frame, and the two emulators' frame timings are compared. bench-check: $(BENCH_RUN) build/mgba_runner build/nba_runner build/nba/mini_bios.bin build/host/harness $(BENCH_MGBA) build/demo/bench_mgba.sav > /dev/null 2>&1 ./build/nba_runner $(BENCH_RUN) build/nba/mini_bios.bin build/demo/bench_nba.sav 5000 > /dev/null $(PYTHON) tools/bench_report.py build/demo/bench_mgba.sav --rom $(BENCH_RUN) --harness build/host/harness $(PYTHON) tools/bench_report.py build/demo/bench_nba.sav --rom $(BENCH_RUN) --ref build/demo/bench_mgba.sav # A .sav from a GBA or another emulator, against mGBA's run of the same ROM: # make bench-report SAV=path/to/sm64bench.sav bench-report: $(BENCH_RUN) build/mgba_runner build/host/harness @test -n "$(SAV)" || { echo "usage: make bench-report SAV=path/to/sm64bench.sav"; exit 1; } $(BENCH_MGBA) build/demo/bench_mgba.sav > /dev/null 2>&1 $(PYTHON) tools/bench_report.py "$(SAV)" --rom $(BENCH_RUN) --ref build/demo/bench_mgba.sav --harness build/host/harness # Emulators start with memory zeroed; a GBA powers on with whatever its RAM # holds. The tour with work RAM, VRAM, palette and sprite memory filled with # random bytes must play exactly as with zeroed memory: same stats lines # every frame, same pictures. DIRTY_TOUR := ./build/mgba_runner build/demo/sm64demo.gba --frames 2880 --keys demo/keys/tour.keys dirty-check: build/demo/sm64demo.gba build/mgba_runner $(DIRTY_TOUR) --video-hash build/demo/zeroed.hash > build/demo/zeroed.log 2>/dev/null $(DIRTY_TOUR) --dirty 1 --video-hash build/demo/dirty.hash > build/demo/dirty.log 2>/dev/null @cmp -s build/demo/zeroed.log build/demo/dirty.log || { echo "FAIL: stats differ with random memory"; \ diff build/demo/zeroed.log build/demo/dirty.log | head -5; exit 1; } @cmp -s build/demo/zeroed.hash build/demo/dirty.hash || { echo "FAIL: pictures differ with random memory"; \ diff build/demo/zeroed.hash build/demo/dirty.hash | head -5; exit 1; } @echo "PASS: $$(grep -c '^f ' build/demo/dirty.log) game frames and $$(wc -l < build/demo/dirty.hash) pictures identical with random power-on memory" # The mannequin's fixed-point skeleton against the game's float matrix chain, # for all 209 animations (host). build/host/skeleton_check: src/test/skeleton_check.c demo/mannequin.c build/demo/skeleton.c \ build/demo/render_tables.c $(filter-out build/host/harness.o,$(HOST_OBJS)) $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) -Idemo -c src/test/skeleton_check.c -o build/host/skeleton_check.o $(HOST_CC) $(HOST_ARCH) -O2 -c build/demo/skeleton.c -o build/host/skeleton.o $(HOST_CC) $(HOST_ARCH) -O2 -c build/demo/render_tables.c -o build/host/render_tables.o $(HOST_CC) $(HOST_ARCH) build/host/skeleton_check.o build/host/skeleton.o build/host/render_tables.o \ $(filter-out build/host/harness.o,$(HOST_OBJS)) -lm -o $@ skeleton-check: build/host/skeleton_check ./build/host/skeleton_check # The demo's renderer run on the host against a z-buffered reference, from # views all around every pit (src/test/render_check.c). build/host/render_check: src/test/render_check.c demo/render_iw.c demo/render_build.c demo/render.h \ build/demo/render_tables.c $(filter-out build/host/harness.o,$(HOST_OBJS)) $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) -Idemo -c src/test/render_check.c -o build/host/render_check.o $(HOST_CC) $(HOST_ARCH) $(CORE_CFLAGS) -Idemo -c demo/render_build.c -o build/host/render_build.o $(HOST_CC) $(HOST_ARCH) $(DEMO_CFLAGS) -c demo/render_iw.c -o build/host/render_iw.o $(HOST_CC) $(HOST_ARCH) -O2 -c build/demo/render_tables.c -o build/host/render_tables.o $(HOST_CC) $(HOST_ARCH) build/host/render_check.o build/host/render_build.o build/host/render_iw.o \ build/host/render_tables.o $(filter-out build/host/harness.o,$(HOST_OBJS)) -lm -o $@ render-check: build/host/render_check ./build/host/render_check # Preview video of the tour (needs ffmpeg). demo-video: build/demo/sm64demo.gba build/mgba_runner rm -rf build/demo/frames && mkdir -p build/demo/frames ./build/mgba_runner build/demo/sm64demo.gba --frames 2880 --keys demo/keys/tour.keys \ --capture build/demo/frames 2 > /dev/null 2>&1 ffmpeg -loglevel error -y -framerate 30 -pattern_type glob -i "build/demo/frames/*.ppm" \ -vf "scale=720:480:flags=neighbor" -c:v libx264 -pix_fmt yuv420p -crf 18 build/demo/preview.mp4 # ---------- tests ---------- inputs: $(PYTHON) tools/gen_inputs.py inputs test: all $(PYTHON) tools/run_parity.py --host build/host/harness --arm build/arm/harness \ --qemu "$(QEMU)" inputs/*.inp clean: rm -rf build