diff --git a/Makefile b/Makefile index 30574c4a..6a5268f0 100755 --- a/Makefile +++ b/Makefile @@ -41,6 +41,23 @@ ifeq ($(DUMMY),FAIL) $(error Failed to build tools) endif +########## Recomp ########## + +# List of IDO tools required for the repo. +# NOTE: If you are adding a tool here, make sure to update the Makefile in `/tools/ido-static-recomp/`! +RECOMP_TOOLS := cc cfe uopt ugen as1 ujoin uld usplit umerge + +RECOMP_DIR := ./tools/ido5.3_recomp/ +RECOMP_TOOLS_PATHS = $(addprefix $(RECOMP_DIR),$(RECOMP_TOOLS)) + +# Checks if all the recomp tools exist. +$(foreach p,$(RECOMP_TOOLS_PATHS),$(if $(wildcard $(p)),,$(info $(p) does not exist!) $(eval runRecomp:=yes))) + +# If any of the tools do not exist, then recomp needs to run to build them. +ifeq ($(runRecomp),yes) + DUMMY != make -s -C tools/ido-static-recomp >&2 || echo FAIL +endif + ######## Extract Assets & Microcode ######## DUMMY != python3 ./tools/python/check_if_need_to_extract.py $(VERSION) >&2 || echo FAIL @@ -67,11 +84,6 @@ BUILD_DIR = build/$(VERSION) ##################### Compiler Options ####################### -# If the `tools/ido5.3_recomp` directory doesn't exist, then we need to run recomp. -ifeq ($(wildcard ./tools/ido5.3_recomp/.*),) - DUMMY != make -s -C tools/ido-static-recomp >&2 || echo FAIL -endif - # Check if a binutils package is installed on the system. ifeq ($(shell type mips-linux-gnu-ld >/dev/null 2>/dev/null; echo $$?), 0) CROSS := mips-linux-gnu- @@ -101,8 +113,8 @@ C_DEFINES := $(foreach d,$(DEFINES),-D$(d)) DEF_INC_CFLAGS := $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(C_DEFINES) ASFLAGS = -mtune=vr4300 -march=vr4300 -mabi=32 $(foreach d,$(DEFINES),--defsym $(d)) -INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I . -CFLAGS = -c -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -Xfullwarn -signed $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(MIPSISET) $(DEF_INC_CFLAGS) +INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I src -I . +CFLAGS = -c -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -Xfullwarn -signed $(OPT_FLAGS) $(MIPSISET) $(INCLUDE_CFLAGS) $(DEF_INC_CFLAGS) LDFLAGS = undefined_syms.txt -T $(LD_SCRIPT) -Map $(BUILD_DIR)/dkr.map ####################### Other Tools ######################### @@ -123,7 +135,7 @@ COMPRESS = $(TOOLS_DIR)/dkr_decompressor -c LIB_DIRS := lib ASM_DIRS := asm asm/boot asm/assets data lib/asm -SRC_DIRS := src src/mips1 lib/src +SRC_DIRS := src lib/src lib/src/al GLOBAL_ASM_C_FILES != grep -rl 'GLOBAL_ASM(' $(wildcard src/*.c lib/src/*.c) GLOBAL_ASM_O_FILES = $(foreach file,$(GLOBAL_ASM_C_FILES),$(BUILD_DIR)/$(file:.c=.o)) @@ -246,6 +258,7 @@ ALL_ASSETS_BUILT += $(patsubst $(UCODE_IN_DIR)/%.bin,$(UCODE_OUT_DIR)/%.bin,$(UC $(BUILD_DIR)/lib/%.o: OPT_FLAGS := -O2 $(BUILD_DIR)/lib/%.o: MIPSISET := -mips2 +$(BUILD_DIR)/lib/src/al/%.o: OPT_FLAGS := -O3 $(BUILD_DIR)/lib/src/unknown_0C91A0.o : OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/unknown_0D29F0.o: OPT_FLAGS := -O1 $(BUILD_DIR)/lib/src/unknown_0CDE90.o: OPT_FLAGS := -O1 diff --git a/asm/non_matchings/unknown_0C83F0/alHeapDBAlloc.s b/asm/non_matchings/unknown_0C83F0/alHeapDBAlloc.s deleted file mode 100644 index b984266d..00000000 --- a/asm/non_matchings/unknown_0C83F0/alHeapDBAlloc.s +++ /dev/null @@ -1,28 +0,0 @@ -glabel alHeapDBAlloc -/* 0C83F0 800C77F0 8FAE0010 */ lw $t6, 0x10($sp) -/* 0C83F4 800C77F4 AFA40000 */ sw $a0, ($sp) -/* 0C83F8 800C77F8 AFA50004 */ sw $a1, 4($sp) -/* 0C83FC 800C77FC 00EE0019 */ multu $a3, $t6 -/* 0C8400 800C7800 8CD90008 */ lw $t9, 8($a2) -/* 0C8404 800C7804 8CD80000 */ lw $t8, ($a2) -/* 0C8408 800C7808 8CC40004 */ lw $a0, 4($a2) -/* 0C840C 800C780C 2401FFF0 */ li $at, -16 -/* 0C8410 800C7810 03194021 */ addu $t0, $t8, $t9 -/* 0C8414 800C7814 00001825 */ move $v1, $zero -/* 0C8418 800C7818 00001012 */ mflo $v0 -/* 0C841C 800C781C 2442000F */ addiu $v0, $v0, 0xf -/* 0C8420 800C7820 00417824 */ and $t7, $v0, $at -/* 0C8424 800C7824 008F4821 */ addu $t1, $a0, $t7 -/* 0C8428 800C7828 0109082B */ sltu $at, $t0, $t1 -/* 0C842C 800C782C 14200003 */ bnez $at, .L800C783C -/* 0C8430 800C7830 008F5021 */ addu $t2, $a0, $t7 -/* 0C8434 800C7834 00801825 */ move $v1, $a0 -/* 0C8438 800C7838 ACCA0004 */ sw $t2, 4($a2) -.L800C783C: -/* 0C843C 800C783C 03E00008 */ jr $ra -/* 0C8440 800C7840 00601025 */ move $v0, $v1 - -/* 0C8444 800C7844 00000000 */ nop -/* 0C8448 800C7848 00000000 */ nop -/* 0C844C 800C784C 00000000 */ nop - diff --git a/asm/non_matchings/unknown_0C8450/alCSPSetVol.s b/asm/non_matchings/unknown_0C8450/alCSPSetVol.s deleted file mode 100644 index 7a96d6b3..00000000 --- a/asm/non_matchings/unknown_0C8450/alCSPSetVol.s +++ /dev/null @@ -1,19 +0,0 @@ -glabel alCSPSetVol -/* 0C8450 800C7850 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0C8454 800C7854 AFBF0014 */ sw $ra, 0x14($sp) -/* 0C8458 800C7858 AFA5002C */ sw $a1, 0x2c($sp) -/* 0C845C 800C785C 00A07025 */ move $t6, $a1 -/* 0C8460 800C7860 240F000A */ li $t7, 10 -/* 0C8464 800C7864 A7AF0018 */ sh $t7, 0x18($sp) -/* 0C8468 800C7868 A7AE001C */ sh $t6, 0x1c($sp) -/* 0C846C 800C786C 27A50018 */ addiu $a1, $sp, 0x18 -/* 0C8470 800C7870 24840048 */ addiu $a0, $a0, 0x48 -/* 0C8474 800C7874 0C03246B */ jal alEvtqPostEvent -/* 0C8478 800C7878 00003025 */ move $a2, $zero -/* 0C847C 800C787C 8FBF0014 */ lw $ra, 0x14($sp) -/* 0C8480 800C7880 27BD0028 */ addiu $sp, $sp, 0x28 -/* 0C8484 800C7884 03E00008 */ jr $ra -/* 0C8488 800C7888 00000000 */ nop - -/* 0C848C 800C788C 00000000 */ nop - diff --git a/lib/src/alCSPGetChlVol.c b/lib/src/al/alCSPGetChlVol.c similarity index 78% rename from lib/src/alCSPGetChlVol.c rename to lib/src/al/alCSPGetChlVol.c index 33677763..1289f492 100644 --- a/lib/src/alCSPGetChlVol.c +++ b/lib/src/al/alCSPGetChlVol.c @@ -1,10 +1,8 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C79A0 */ - #include "audio_internal.h" -u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan) -{ +u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan){ return seqp->chanState[chan].vol; } \ No newline at end of file diff --git a/lib/src/al/alCSPSetVol.c b/lib/src/al/alCSPSetVol.c new file mode 100644 index 00000000..9910a3aa --- /dev/null +++ b/lib/src/al/alCSPSetVol.c @@ -0,0 +1,14 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C7850 */ + +#include "audio_internal.h" + +void alCSPSetVol(ALCSPlayer *seqp, s16 vol) { + ALEvent evt; + + evt.type = AL_SEQP_VOL_EVT; + evt.msg.spvol.vol = vol; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/src/al/alHeapDBAlloc.c b/lib/src/al/alHeapDBAlloc.c new file mode 100644 index 00000000..10bee9bb --- /dev/null +++ b/lib/src/al/alHeapDBAlloc.c @@ -0,0 +1,21 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C77F0 */ + +#include "audio_internal.h" + +void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size) { + s32 bytes; + u8 *ptr = 0; + + bytes = (num*size + AL_CACHE_ALIGN) & ~AL_CACHE_ALIGN; + + if ((hp->cur + bytes) <= (hp->base + hp->len)) { + ptr = hp->cur; + hp->cur += bytes; + } else { + } + + return ptr; +} + + diff --git a/lib/src/alHeapInit.c b/lib/src/al/alHeapInit.c similarity index 88% rename from lib/src/alHeapInit.c rename to lib/src/al/alHeapInit.c index ac5bd679..af4734d6 100644 --- a/lib/src/alHeapInit.c +++ b/lib/src/al/alHeapInit.c @@ -3,8 +3,7 @@ #include "audio_internal.h" -void alHeapInit(ALHeap *hp, u8 *base, s32 len) -{ +void alHeapInit(ALHeap *hp, u8 *base, s32 len){ s32 extraAlign = (AL_CACHE_ALIGN+1) - ((s32) base & AL_CACHE_ALIGN); if (extraAlign != AL_CACHE_ALIGN+1) diff --git a/lib/src/alSeqpGetChlFXMix.c b/lib/src/al/alSeqpGetChlFXMix.c similarity index 77% rename from lib/src/alSeqpGetChlFXMix.c rename to lib/src/al/alSeqpGetChlFXMix.c index 10803bce..e5017f3c 100644 --- a/lib/src/alSeqpGetChlFXMix.c +++ b/lib/src/al/alSeqpGetChlFXMix.c @@ -3,7 +3,6 @@ #include "audio_internal.h" -u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan) -{ +u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan){ return seqp->chanState[chan].fxmix; } \ No newline at end of file diff --git a/src/unknown_0C83F0.c b/src/unknown_0C83F0.c deleted file mode 100644 index 2133d77d..00000000 --- a/src/unknown_0C83F0.c +++ /dev/null @@ -1,7 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C77F0 */ - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("asm/non_matchings/unknown_0C83F0/alHeapDBAlloc.s") diff --git a/src/unknown_0C8450.c b/src/unknown_0C8450.c deleted file mode 100644 index 4b93212a..00000000 --- a/src/unknown_0C8450.c +++ /dev/null @@ -1,7 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C7850 */ - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("asm/non_matchings/unknown_0C8450/alCSPSetVol.s") diff --git a/tools/ido-static-recomp/Makefile b/tools/ido-static-recomp/Makefile index f13976d7..3bb8b713 100644 --- a/tools/ido-static-recomp/Makefile +++ b/tools/ido-static-recomp/Makefile @@ -5,22 +5,26 @@ OUT := ../ido5.3_recomp CXX := g++ GCC := gcc -DUMMY != echo "Statically recompiling IDO 5.3. This might take a while." >&2 || echo FAIL +DUMMY != echo "Statically recompiling IDO 5.3 tools. This might take a while." >&2 || echo FAIL DUMMY != mkdir -p $(OUT) >&2 || echo FAIL cc: OPT_CFLAGS := -O2 cfe: OPT_CFLAGS := -O2 uopt: OPT_CFLAGS := -O2 ugen: OPT_CFLAGS := -O2 +ujoin: OPT_CFLAGS := -O2 +usplit: OPT_CFLAGS := -O2 +umerge: OPT_CFLAGS := -O2 +uld: OPT_CFLAGS := -O2 as1: OPT_CFLAGS := -O2 acpp: OPT_CFLAGS := -O2 RECOMP := recomp -all: cc cfe uopt ugen as1 err.english.cc +all: cc cfe uopt ugen as1 ujoin uld usplit umerge err.english.cc clean: - $(RM) cc* cfe* uopt* ugen* as1* err.english.cc $(RECOMP) + $(RM) cc* cfe* uopt* ugen* as1* ujoin* uld* usplit* umerge* err.english.cc $(RECOMP) recomp: recomp.cpp g++ recomp.cpp -o $(RECOMP) -g -lcapstone diff --git a/tools/python/generate_ld.py b/tools/python/generate_ld.py index f63e51e3..581843dc 100644 --- a/tools/python/generate_ld.py +++ b/tools/python/generate_ld.py @@ -201,7 +201,7 @@ class GenerateLD: self.file.write('\n') def append_files(self, files, extensions, directory, outputDir): - filenames = FileUtil.get_filenames_from_directory(directory, extensions) + filenames = FileUtil.get_filenames_from_directory_recursive(directory, extensions) regex = r'[\/][*]+\s*RAM_POS:\s*0x([0-9a-fA-F]+)\s*[*]+[\/]' for filename in filenames: with open(directory + '/' + filename, 'r') as inFile: