From 08348be6e1408eda3d3d20b26f77ff71c8f3605a Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 10:55:53 -0300 Subject: [PATCH 01/35] remove --- .vscode/settings.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4c4b984f..ec06a287 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,6 +14,5 @@ "tools/gfxsotn/**": false, }, "files.associations": { - "functions.h": "c" }, } \ No newline at end of file From ce9b18d811842e124a2110359a8f0d96a5620837 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 12:27:32 -0300 Subject: [PATCH 02/35] O1 -g0 rule for controller.o --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index badd35e2..f0d1225c 100644 --- a/Makefile +++ b/Makefile @@ -191,6 +191,7 @@ build/src/main/1EB50.o: OPTFLAGS := -O1 -g0 build/src/libultra/2BDF0.o: OPTFLAGS := -O1 -g0 build/src/libultra/2C700.o: OPTFLAGS := -O1 -g0 build/src/libultra/2D300.o: OPTFLAGS := -O1 -g0 +build/src/libultra/io/controller.o: OPTFLAGS := -O1 -g0 # cc & asm-processor build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(CC) -- $(AS) $(ASFLAGS) -- From b5e4837005603b741d0b59b56d19ec18ec084234 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 12:27:39 -0300 Subject: [PATCH 03/35] controller header --- include/PR/controller.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 include/PR/controller.h diff --git a/include/PR/controller.h b/include/PR/controller.h new file mode 100644 index 00000000..83838d1b --- /dev/null +++ b/include/PR/controller.h @@ -0,0 +1,23 @@ +#ifndef PR_CONTROLLER_H +#define PR_CONTROLLER_H + +#include "global.h" +#include "PR/os.h" + +#define UNK(n) 500000 * (u64)(n) / 1000000 +#define CONT_CMD_REQUEST_STATUS 0 + +typedef struct +{ + u32 ramarray[15]; + u32 pifstatus; +} OSPifRam; + +extern u32 __osContinitialized; +extern u8 __osMaxControllers; +extern u8 __osContLastCmd; +extern OSPifRam __osContPifRam; +extern OSMesgQueue __osEepromTimerQ; +extern OSMesg __osEepromTimerMsg; + +#endif \ No newline at end of file From 14481a3b1ba333efa3b5dbf76dfbab398fa79b3f Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 12:29:19 -0300 Subject: [PATCH 04/35] decompile osContInit. Co-authored-by: @rainchus @Tharo @Mallos31 --- src/libultra/io/controller.c | 40 ++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c index ba278426..4ad2eaf1 100644 --- a/src/libultra/io/controller.c +++ b/src/libultra/io/controller.c @@ -1,6 +1,42 @@ -#include "common.h" +#include "global.h" +#include "PR/controller.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/controller/osContInit.s") +s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { + OSMesg dummy; + s32 ret = 0; + OSTime t; + OSTimer mytimer; + OSMesgQueue timerMesgQueue; + + if (__osContinitialized != 0) { + return 0; + } + + __osContinitialized = 1; + t = osGetTime(); + + if (t < UNK(osClockRate)) { + osCreateMesgQueue(&timerMesgQueue, &dummy, 1); + osSetTimer(&mytimer, UNK(osClockRate) - t, 0, &timerMesgQueue, &dummy); + osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); + } + __osMaxControllers = 4; + + __osPackRequestData(CONT_CMD_REQUEST_STATUS); + + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, &dummy, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + osRecvMesg(mq, &dummy, OS_MESG_BLOCK); + + __osContGetInitData(bitpattern, data); + __osContLastCmd = CONT_CMD_REQUEST_STATUS; + __osSiCreateAccessQueue(); + osCreateMesgQueue(&__osEepromTimerQ, &__osEepromTimerMsg, 1); + + return ret; +} #pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/controller/__osContGetInitData.s") From ab9c0f98374598917a58538ceb321243afaacf47 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 12:33:45 -0300 Subject: [PATCH 05/35] silent jobs --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index f0d1225c..522b521c 100644 --- a/Makefile +++ b/Makefile @@ -199,11 +199,11 @@ build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(CC) -- $(AS) $(ASFLAGS) -- all: uncompressed init: - $(MAKE) clean - $(MAKE) decompress - $(MAKE) extract -j $(N_THREADS) - $(MAKE) all -j $(N_THREADS) - $(MAKE) compressed + @$(MAKE) clean + @$(MAKE) decompress + @$(MAKE) extract -j $(N_THREADS) + @$(MAKE) all -j $(N_THREADS) + @$(MAKE) compressed uncompressed: $(ROM) ifneq ($(COMPARE),0) From 32bcc57984fbb11f0e889e95008d59328d15819a Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 12:58:34 -0300 Subject: [PATCH 06/35] MD5 CHECK --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 522b521c..8d6ce357 100644 --- a/Makefile +++ b/Makefile @@ -207,6 +207,7 @@ init: uncompressed: $(ROM) ifneq ($(COMPARE),0) + @echo MD5 CHECK: @md5sum $(ROM) @md5sum -c $(TARGET).$(VERSION).uncompressed.md5 endif @@ -251,6 +252,7 @@ expected: #### Various Recipes #### $(ROM): $(ELF) + @echo "ELF->ROM:" $(OBJCOPY) -O binary $< $@ $(ROMC): $(BASEROM_UNCOMPRESSED) @@ -261,6 +263,7 @@ $(ROMC): $(BASEROM_UNCOMPRESSED) # TODO: avoid using auto/undefined $(ELF): $(LIBULTRA_O) $(O_FILES) $(LD_SCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld + @echo "Linking..." $(LD) $(LDFLAGS) -T $(LD_SCRIPT) \ -T $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld \ -T $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld \ From 1d53ba1360ce874988a18456478184efae4d0476 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:32:12 -0300 Subject: [PATCH 07/35] add ARRAY_COUNT macro --- include/macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/macros.h b/include/macros.h index 5a7124ff..424291b7 100644 --- a/include/macros.h +++ b/include/macros.h @@ -1,6 +1,6 @@ #ifndef MACROS_H #define MACROS_H - +#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #endif // MACROS_H From 742a17763783e156ed72181b28be4d0cba3a05b2 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:32:30 -0300 Subject: [PATCH 08/35] // Joybus commands --- include/PR/controller.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/PR/controller.h b/include/PR/controller.h index 83838d1b..36fe093b 100644 --- a/include/PR/controller.h +++ b/include/PR/controller.h @@ -4,8 +4,22 @@ #include "global.h" #include "PR/os.h" -#define UNK(n) 500000 * (u64)(n) / 1000000 +// Joybus commands #define CONT_CMD_REQUEST_STATUS 0 +#define CONT_CMD_READ_BUTTON 1 +#define CONT_CMD_READ_PAK 2 +#define CONT_CMD_WRITE_PAK 3 +#define CONT_CMD_READ_EEPROM 4 +#define CONT_CMD_WRITE_EEPROM 5 +#define CONT_CMD_READ36_VOICE 9 +#define CONT_CMD_WRITE20_VOICE 10 +#define CONT_CMD_READ2_VOICE 11 +#define CONT_CMD_WRITE4_VOICE 12 +#define CONT_CMD_SWRITE_VOICE 13 +#define CONT_CMD_CHANNEL_RESET 0xFD +#define CONT_CMD_RESET 0xFF + +#define UNK(n) 500000 * (u64)(n) / 1000000 typedef struct { @@ -20,4 +34,4 @@ extern OSPifRam __osContPifRam; extern OSMesgQueue __osEepromTimerQ; extern OSMesg __osEepromTimerMsg; -#endif \ No newline at end of file +#endif From 7f398ed008de3844d2e102809379e1b94d3525bb Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:34:03 -0300 Subject: [PATCH 09/35] __OSContRequestHeader struct --- include/PR/controller.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/PR/controller.h b/include/PR/controller.h index 36fe093b..51ca97e6 100644 --- a/include/PR/controller.h +++ b/include/PR/controller.h @@ -4,6 +4,17 @@ #include "global.h" #include "PR/os.h" +typedef struct { + /* 0x00 */ u8 align; + /* 0x01 */ u8 txsize; + /* 0x02 */ u8 rxsize; + /* 0x03 */ u8 poll; + /* 0x04 */ u8 typeh; + /* 0x05 */ u8 typel; + /* 0x06 */ u8 status; + /* 0x07 */ u8 align1; +} __OSContRequestHeader; // size = 0x8 + // Joybus commands #define CONT_CMD_REQUEST_STATUS 0 #define CONT_CMD_READ_BUTTON 1 @@ -34,4 +45,6 @@ extern OSPifRam __osContPifRam; extern OSMesgQueue __osEepromTimerQ; extern OSMesg __osEepromTimerMsg; +void __osPackRequestData(u8 poll); + #endif From 0a2caee482d3f20d23f96c342ebdbd47d167c6bd Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:34:10 -0300 Subject: [PATCH 10/35] decompile __osPackRequestData --- src/libultra/io/controller.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c index 4ad2eaf1..923ffc57 100644 --- a/src/libultra/io/controller.c +++ b/src/libultra/io/controller.c @@ -40,4 +40,29 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { #pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/controller/__osContGetInitData.s") -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/controller/__osPackRequestData.s") +void __osPackRequestData(u8 poll) { + u8* ptr; + __OSContRequestHeader requestHeader; + s32 i; + + for (i = 0; i < 16; i++) { + __osContPifRam.ramarray[i] = 0; + } + + __osContPifRam.pifstatus = CONT_CMD_READ_BUTTON; + ptr = (u8*)__osContPifRam.ramarray; + requestHeader.align = 255; + requestHeader.txsize = 1; + requestHeader.rxsize = 3; + requestHeader.poll = poll; + requestHeader.typeh = 255; + requestHeader.typel = 255; + requestHeader.status = 255; + requestHeader.align1 = 255; + + for (i = 0; i < __osMaxControllers; i++) { + *(__OSContRequestHeader*)ptr = requestHeader; + ptr += sizeof(requestHeader); + } + *ptr = 254; +} From 1359630bcdc70f5e7ec80b7ada8c29be78a2d851 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:36:10 -0300 Subject: [PATCH 11/35] decompile __osContGetInitData --- include/PR/controller.h | 1 + src/libultra/io/controller.c | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/PR/controller.h b/include/PR/controller.h index 51ca97e6..d2b0b812 100644 --- a/include/PR/controller.h +++ b/include/PR/controller.h @@ -46,5 +46,6 @@ extern OSMesgQueue __osEepromTimerQ; extern OSMesg __osEepromTimerMsg; void __osPackRequestData(u8 poll); +void __osContGetInitData(u8* pattern, OSContStatus* data); #endif diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c index 923ffc57..90bf1169 100644 --- a/src/libultra/io/controller.c +++ b/src/libultra/io/controller.c @@ -38,7 +38,26 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { return ret; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/io/controller/__osContGetInitData.s") +void __osContGetInitData(u8* pattern, OSContStatus* data) { + u8* ptr; + __OSContRequestHeader requestHeader; + s32 i; + u8 bits; + + bits = 0; + ptr = (u8*)__osContPifRam.ramarray; + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestHeader), data++) { + requestHeader = *(__OSContRequestHeader*)ptr; + data->errno = (requestHeader.rxsize & 0xC0) >> 4; + if (data->errno == 0) { + data->type = requestHeader.typel << 8 | requestHeader.typeh; + data->status = requestHeader.status; + + bits |= 1 << i; + } + } + *pattern = bits; +} void __osPackRequestData(u8 poll) { u8* ptr; From 003384482a8da1982f7c63b99871ef6d030d7b98 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:37:57 -0300 Subject: [PATCH 12/35] format --- include/PR/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/PR/os.h b/include/PR/os.h index d6ec937a..073232e7 100644 --- a/include/PR/os.h +++ b/include/PR/os.h @@ -877,7 +877,7 @@ extern int osStopTimer(OSTimer *); /* Controller interface */ -extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); +extern s32 osContInit(OSMesgQueue * mq, u8 * bitpattern, OSContStatus * data); extern s32 osContReset(OSMesgQueue *, OSContStatus *); extern s32 osContStartQuery(OSMesgQueue *); extern s32 osContStartReadData(OSMesgQueue *); From 49859317146e00d6c8d2c666129c42ae4b33b6fb Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:52:40 -0300 Subject: [PATCH 13/35] decompile memcpy --- Makefile | 1 + include/PR/ultratypes.h | 2 ++ src/libultra/libc/string.c | 16 ++++++++++++++-- tools/permuter_settings.toml | 5 ++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8d6ce357..78145cdf 100644 --- a/Makefile +++ b/Makefile @@ -192,6 +192,7 @@ build/src/libultra/2BDF0.o: OPTFLAGS := -O1 -g0 build/src/libultra/2C700.o: OPTFLAGS := -O1 -g0 build/src/libultra/2D300.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/controller.o: OPTFLAGS := -O1 -g0 +build/src/libultra/libc/string.o: OPTFLAGS := -O2 -g0 # cc & asm-processor build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(CC) -- $(AS) $(ASFLAGS) -- diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 85e44f2e..6af7c9ff 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -57,6 +57,8 @@ typedef volatile long long vs64; /* signed 64-bit */ typedef float f32; /* single prec floating point */ typedef double f64; /* double prec floating point */ +typedef u32 size_t; + #endif /* _LANGUAGE_C */ diff --git a/src/libultra/libc/string.c b/src/libultra/libc/string.c index 5561b1b9..10d54d31 100644 --- a/src/libultra/libc/string.c +++ b/src/libultra/libc/string.c @@ -1,6 +1,18 @@ -#include "common.h" +#include "global.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/string/memcpy.s") +void* memcpy(void* s1, const void* s2, size_t n) { + unsigned char* su1 = (unsigned char*)s1; + const unsigned char* su2 = (const unsigned char*)s2; + + while (n > 0) { + *su1 = *su2; + su1++; + su2++; + n--; + } + + return s1; +} #pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/string/strlen.s") diff --git a/tools/permuter_settings.toml b/tools/permuter_settings.toml index d9acc8df..e86aa08a 100644 --- a/tools/permuter_settings.toml +++ b/tools/permuter_settings.toml @@ -1 +1,4 @@ -compiler_type = "ido" \ No newline at end of file +compiler_type = "ido" + +[decompme.compilers] +"tools/ido_recomp/linux/5.3/cc" = "ido5.3" \ No newline at end of file From e5ef31fe377e88a521c36b624117d799c7665f0d Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:53:36 -0300 Subject: [PATCH 14/35] decompile strlen --- src/libultra/libc/string.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libultra/libc/string.c b/src/libultra/libc/string.c index 10d54d31..7a3db93f 100644 --- a/src/libultra/libc/string.c +++ b/src/libultra/libc/string.c @@ -14,6 +14,15 @@ void* memcpy(void* s1, const void* s2, size_t n) { return s1; } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/string/strlen.s") +size_t strlen(const char* s) { + const char* sc = s; + + while (*sc != '\0') { + sc++; + } + + return (size_t)(sc - s); +} + #pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/string/strchr.s") From 73e7e3637506f281e178208c55c2717e6c91eda2 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:54:00 -0300 Subject: [PATCH 15/35] decompile strchr --- src/libultra/libc/string.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libultra/libc/string.c b/src/libultra/libc/string.c index 7a3db93f..e60b64c0 100644 --- a/src/libultra/libc/string.c +++ b/src/libultra/libc/string.c @@ -25,4 +25,15 @@ size_t strlen(const char* s) { } -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/string/strchr.s") +const char* strchr(const char* s, int c) { + const unsigned char ch = c; + + while (*s != ch) { + if (*s == '\0') { + return NULL; + } + s++; + } + + return s; +} From a105c1e09963b06239b7120b7488884543428010 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:58:39 -0300 Subject: [PATCH 16/35] stddef.h --- include/libc/stddef.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 include/libc/stddef.h diff --git a/include/libc/stddef.h b/include/libc/stddef.h new file mode 100644 index 00000000..1dc74697 --- /dev/null +++ b/include/libc/stddef.h @@ -0,0 +1,14 @@ +#ifndef LIBC_STDDEF_H +#define LIBC_STDDEF_H + +#include "PR/ultratypes.h" + +typedef s32 ptrdiff_t; + +#ifdef __GNUC__ +#define offsetof(structure, member) __builtin_offsetof (structure, member) +#else +#define offsetof(structure, member) ((size_t)&(((structure*)0)->member)) +#endif + +#endif /* STDDEF_H */ \ No newline at end of file From 1a9167437a75eeace1d8967a7b54e38c506f75a7 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:58:53 -0300 Subject: [PATCH 17/35] stdlib.h --- include/libc/stdlib.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 include/libc/stdlib.h diff --git a/include/libc/stdlib.h b/include/libc/stdlib.h new file mode 100644 index 00000000..ec15b4f6 --- /dev/null +++ b/include/libc/stdlib.h @@ -0,0 +1,28 @@ +#ifndef LIBC_STDLIB_H +#define LIBC_STDLIB_H + +#include "libc/stddef.h" + +typedef struct { + /* 0x0 */ int quot; + /* 0x4 */ int rem; +} div_t; + +typedef struct { + /* 0x0 */ long quot; + /* 0x4 */ long rem; +} ldiv_t; + +typedef struct { + /* 0x0 */ long long quot; + /* 0x8 */ long long rem; +} lldiv_t; + +typedef int ssize_t; + +typedef long wchar_t; + +ldiv_t ldiv(long numer, long denom); +lldiv_t lldiv(long long numer, long long denom); + +#endif /* STDLIB_H */ From a36b61f73bc2839ce963cd8ebaa85d5195414330 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 13:59:04 -0300 Subject: [PATCH 18/35] decompile ldiv --- src/libultra/libc/ldiv.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/libultra/libc/ldiv.c b/src/libultra/libc/ldiv.c index a9f3099e..899d716f 100644 --- a/src/libultra/libc/ldiv.c +++ b/src/libultra/libc/ldiv.c @@ -1,5 +1,17 @@ -#include "common.h" +#include "global.h" +#include "libc/stdlib.h" #pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/ldiv/lldiv.s") -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/ldiv/ldiv.s") +ldiv_t ldiv(long numer, long denom) { + ldiv_t val; + + val.quot = numer / denom; + val.rem = numer - denom * val.quot; + if ((val.quot < 0) && (val.rem > 0)) { + val.quot++; + val.rem -= denom; + } + + return val; +} From d98938673dc46b4bf0f85a479cb7e5d3b22cd5e3 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:01:54 -0300 Subject: [PATCH 19/35] decompile lldiv --- Makefile | 1 + src/libultra/libc/ldiv.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 78145cdf..a6b876b8 100644 --- a/Makefile +++ b/Makefile @@ -193,6 +193,7 @@ build/src/libultra/2C700.o: OPTFLAGS := -O1 -g0 build/src/libultra/2D300.o: OPTFLAGS := -O1 -g0 build/src/libultra/io/controller.o: OPTFLAGS := -O1 -g0 build/src/libultra/libc/string.o: OPTFLAGS := -O2 -g0 +build/src/libultra/libc/ldiv.o: OPTFLAGS := -O2 -g0 # cc & asm-processor build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(CC) -- $(AS) $(ASFLAGS) -- diff --git a/src/libultra/libc/ldiv.c b/src/libultra/libc/ldiv.c index 899d716f..657071f6 100644 --- a/src/libultra/libc/ldiv.c +++ b/src/libultra/libc/ldiv.c @@ -1,7 +1,18 @@ #include "global.h" #include "libc/stdlib.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/libc/ldiv/lldiv.s") +lldiv_t lldiv(long long numer, long long denom) { + lldiv_t val; + + val.quot = numer / denom; + val.rem = numer - denom * val.quot; + if ((val.quot < 0) && (val.rem > 0)) { + val.quot++; + val.rem -= denom; + } + + return val; +} ldiv_t ldiv(long numer, long denom) { ldiv_t val; From c8218ec4611eeb5f99c3ce1dcf42249e45dfaefa Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:46:11 -0300 Subject: [PATCH 20/35] Link comment --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index a6b876b8..ae10a7da 100644 --- a/Makefile +++ b/Makefile @@ -271,6 +271,7 @@ $(ELF): $(LIBULTRA_O) $(O_FILES) $(LD_SCRIPT) $(BUILD_DIR)/linker_scripts/$(VERS -T $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld \ -Map $(LD_MAP) -o $@ +# Link $(BUILD_DIR)/%.ld: %.ld $(CPP) $(CPPFLAGS) $(BUILD_DEFINES) $(IINC) $< > $@ From 5ef3cbcf0e12c4eaa9afb284f3f4db81d9fb6c0e Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:47:20 -0300 Subject: [PATCH 21/35] comments --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ae10a7da..60daa2de 100644 --- a/Makefile +++ b/Makefile @@ -253,17 +253,16 @@ expected: #### Various Recipes #### +# Uncompressed ROM $(ROM): $(ELF) @echo "ELF->ROM:" $(OBJCOPY) -O binary $< $@ +# Final ROM $(ROMC): $(BASEROM_UNCOMPRESSED) @echo "Compressing ROM..." @$(PYTHON) $(COMPTOOL) -c $(ROM) $(ROMC) -# TODO: update rom header checksum - -# TODO: avoid using auto/undefined $(ELF): $(LIBULTRA_O) $(O_FILES) $(LD_SCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld @echo "Linking..." $(LD) $(LDFLAGS) -T $(LD_SCRIPT) \ From 483a8a349d4cde898ffc07edd09ad39588ae19d6 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:48:49 -0300 Subject: [PATCH 22/35] phony --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 60daa2de..c86bf507 100644 --- a/Makefile +++ b/Makefile @@ -295,4 +295,4 @@ $(BUILD_DIR)/%.o: %.c # Print target for debugging print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true -.PHONY: all uncompressed compressed clean init extract format checkformat decompress \ No newline at end of file +.PHONY: all uncompressed compressed clean init extract expected format checkformat decompress \ No newline at end of file From be3c03cd5ffe67d9e51b16d2e10af18922667b8d Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:50:24 -0300 Subject: [PATCH 23/35] comments --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c86bf507..68587ef4 100644 --- a/Makefile +++ b/Makefile @@ -263,6 +263,7 @@ $(ROMC): $(BASEROM_UNCOMPRESSED) @echo "Compressing ROM..." @$(PYTHON) $(COMPTOOL) -c $(ROM) $(ROMC) +# Link $(ELF): $(LIBULTRA_O) $(O_FILES) $(LD_SCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld @echo "Linking..." $(LD) $(LDFLAGS) -T $(LD_SCRIPT) \ @@ -270,7 +271,7 @@ $(ELF): $(LIBULTRA_O) $(O_FILES) $(LD_SCRIPT) $(BUILD_DIR)/linker_scripts/$(VERS -T $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld -T $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld \ -Map $(LD_MAP) -o $@ -# Link +# PreProcessor $(BUILD_DIR)/%.ld: %.ld $(CPP) $(CPPFLAGS) $(BUILD_DEFINES) $(IINC) $< > $@ From 19e864bb06bb4e9d94d1d137b8dd9bc3ec58ad9c Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:51:04 -0300 Subject: [PATCH 24/35] reorder --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 68587ef4..c671bd43 100644 --- a/Makefile +++ b/Makefile @@ -253,16 +253,16 @@ expected: #### Various Recipes #### -# Uncompressed ROM -$(ROM): $(ELF) - @echo "ELF->ROM:" - $(OBJCOPY) -O binary $< $@ - # Final ROM $(ROMC): $(BASEROM_UNCOMPRESSED) @echo "Compressing ROM..." @$(PYTHON) $(COMPTOOL) -c $(ROM) $(ROMC) +# Uncompressed ROM +$(ROM): $(ELF) + @echo "ELF->ROM:" + $(OBJCOPY) -O binary $< $@ + # Link $(ELF): $(LIBULTRA_O) $(O_FILES) $(LD_SCRIPT) $(BUILD_DIR)/linker_scripts/$(VERSION)/hardware_regs.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/undefined_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/pif_syms.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_syms_auto.ld $(BUILD_DIR)/linker_scripts/$(VERSION)/auto/undefined_funcs_auto.ld @echo "Linking..." From b42c6bf53927f344e6d8f12e9656b14d310a5266 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:55:18 -0300 Subject: [PATCH 25/35] echo --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c671bd43..ace0d144 100644 --- a/Makefile +++ b/Makefile @@ -227,9 +227,11 @@ decompress: $(BASEROM) @$(PYTHON) $(COMPTOOL) -de $(COMPTOOL_DIR) -m $(MIO0) $(BASEROM) $(BASEROM_UNCOMPRESSED) extract: - $(RM) -r asm/$(VERSION) bin/$(VERSION) - $(CAT) yamls/$(VERSION)/header.yaml yamls/$(VERSION)/makerom.yaml yamls/$(VERSION)/main.yaml yamls/$(VERSION)/overlays.yaml > $(SPLAT_YAML) - $(SPLAT) $(SPLAT_YAML) + @$(RM) -r asm/$(VERSION) bin/$(VERSION) + @echo "Unifying yamls..." + @$(CAT) yamls/$(VERSION)/header.yaml yamls/$(VERSION)/makerom.yaml yamls/$(VERSION)/main.yaml yamls/$(VERSION)/overlays.yaml > $(SPLAT_YAML) + @echo "Extracting..." + @$(SPLAT) $(SPLAT_YAML) clean: @git clean -fdx asm/ From 7069284fe8733bd8484863b3a11bfe255540666a Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:56:11 -0300 Subject: [PATCH 26/35] format --- src/libultra/libc/string.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libultra/libc/string.c b/src/libultra/libc/string.c index e60b64c0..f35bb375 100644 --- a/src/libultra/libc/string.c +++ b/src/libultra/libc/string.c @@ -24,7 +24,6 @@ size_t strlen(const char* s) { return (size_t)(sc - s); } - const char* strchr(const char* s, int c) { const unsigned char ch = c; From e1180d9ea9ebb11bddb4bc6cb191d40d8614501f Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 14:57:33 -0300 Subject: [PATCH 27/35] check_format.sh --- tools/check_format.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 tools/check_format.sh diff --git a/tools/check_format.sh b/tools/check_format.sh new file mode 100755 index 00000000..e614db66 --- /dev/null +++ b/tools/check_format.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +STATUSOLD=`git status --porcelain` +./tools/format.py -j +if [ $? -ne 0 ] +then + echo "Formatter failed. Exiting." + exit -1 +fi +STATUSNEW=`git status --porcelain` + +if [ "${STATUSOLD}" != "${STATUSNEW}" ]; +then + echo "" + echo "Misformatted files found. Run ./tools/format.py and verify codegen is not impacted." + echo "" + diff --unified=0 --label "Old git status" <(echo "${STATUSOLD}") --label "New git status" <(echo "${STATUSNEW}") + echo "" + echo "Exiting." + exit 1 +fi + +exit 0 From 0ea7627364f27fb615641f6700d52255e92a8d1b Mon Sep 17 00:00:00 2001 From: Alejandro Asenjo Nitti <96613413+sonicdcer@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:19:30 -0300 Subject: [PATCH 28/35] Create ci.yaml --- .github/workflows/ci.yaml | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..09f50c14 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,44 @@ +name: Build + +# Build on every branch push, tag push, and pull request change: +on: [push, pull_request_target] + +jobs: + build_repo: + name: Build repo + runs-on: ubuntu-latest + + strategy: + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Install package requirements + run: sudo apt-get install -y git make git build-essential binutils-mips-linux-gnu python3 python3-pip libpng-dev + + - name: Install Python dependencies + run: python3 -m pip install -r ./tools/requirements-python.txt + + - name: Update submodules + run: git submodule update --init --recursive + + - name: Get extra dependencies + uses: actions/checkout@v4 + with: + repository: ${{ secrets.SF64_DEPENDENCIES }} + token: ${{ secrets.SF64_TOKEN }} + path: sf64-secret + + - name: Get the dependency + run: cp -r sf64/baserom.us.z64 ./ + + - name: Compile + run: make init + +# - name: Upload frogress +# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} +# run: python3 tools/upload_frogress.py --apikey ${{ secrets.PROGRESS_API_KEY }} From 755097a5a504bbff21dc8c60023a333c9a0dc2f3 Mon Sep 17 00:00:00 2001 From: Alejandro Asenjo Nitti <96613413+sonicdcer@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:52:35 -0300 Subject: [PATCH 29/35] Update ci.yaml --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 09f50c14..d090f9db 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,7 +34,7 @@ jobs: path: sf64-secret - name: Get the dependency - run: cp -r sf64/baserom.us.z64 ./ + run: cp -r sf64-secret/baserom.us.z64 ./ - name: Compile run: make init From 491b9931c4015d9c39ccb8ff68729b66ae97ec7f Mon Sep 17 00:00:00 2001 From: Alejandro Asenjo Nitti <96613413+sonicdcer@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:56:53 -0300 Subject: [PATCH 30/35] Create format.yaml --- .github/workflows/format.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/format.yaml diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml new file mode 100644 index 00000000..3e6d933f --- /dev/null +++ b/.github/workflows/format.yaml @@ -0,0 +1,19 @@ +name: Check Format + +# Build on every branch push, tag push, and pull request change: +on: [push, pull_request] + +jobs: + build: + name: Check format + runs-on: ubuntu-latest + + steps: + - name: Checkout reposistory + uses: actions/checkout@v4 + + - name: Install package requirements + run: sudo apt-get install -y python3 python3-pip clang-format-14 clang-tidy-14 + + - name: Check format + run: ./tools/check_format.sh From 42e10c45f6ab6639f1798d1e2d5617fac580a428 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 16:00:35 -0300 Subject: [PATCH 31/35] test format check --- src/libultra/io/controller.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c index 90bf1169..3561f6b6 100644 --- a/src/libultra/io/controller.c +++ b/src/libultra/io/controller.c @@ -71,7 +71,7 @@ void __osPackRequestData(u8 poll) { __osContPifRam.pifstatus = CONT_CMD_READ_BUTTON; ptr = (u8*)__osContPifRam.ramarray; requestHeader.align = 255; - requestHeader.txsize = 1; + requestHeader.txsize = 1; requestHeader.rxsize = 3; requestHeader.poll = poll; requestHeader.typeh = 255; From bc14ecbb176d56f0f8e0cd23d5682e97d7d801c4 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 16:02:23 -0300 Subject: [PATCH 32/35] check_format correction --- src/libultra/io/controller.c | 2 +- tools/check_format.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c index 3561f6b6..90bf1169 100644 --- a/src/libultra/io/controller.c +++ b/src/libultra/io/controller.c @@ -71,7 +71,7 @@ void __osPackRequestData(u8 poll) { __osContPifRam.pifstatus = CONT_CMD_READ_BUTTON; ptr = (u8*)__osContPifRam.ramarray; requestHeader.align = 255; - requestHeader.txsize = 1; + requestHeader.txsize = 1; requestHeader.rxsize = 3; requestHeader.poll = poll; requestHeader.typeh = 255; diff --git a/tools/check_format.sh b/tools/check_format.sh index e614db66..051e5a7b 100755 --- a/tools/check_format.sh +++ b/tools/check_format.sh @@ -12,7 +12,7 @@ STATUSNEW=`git status --porcelain` if [ "${STATUSOLD}" != "${STATUSNEW}" ]; then echo "" - echo "Misformatted files found. Run ./tools/format.py and verify codegen is not impacted." + echo "Misformatted files found. Run 'make format' and verify codegen is not impacted." echo "" diff --unified=0 --label "Old git status" <(echo "${STATUSOLD}") --label "New git status" <(echo "${STATUSNEW}") echo "" From 6d9c9ea68e4ed04085fdc366ce5a3d8af96f93d2 Mon Sep 17 00:00:00 2001 From: Alejandro Asenjo Nitti <96613413+sonicdcer@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:34:35 -0300 Subject: [PATCH 33/35] Update ci.yaml --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d090f9db..e2fe1323 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} - name: Install package requirements - run: sudo apt-get install -y git make git build-essential binutils-mips-linux-gnu python3 python3-pip libpng-dev + run: sudo apt-get install -y git make git build-essential binutils-mips-linux-gnu python3 python3-pip - name: Install Python dependencies run: python3 -m pip install -r ./tools/requirements-python.txt From be7ae632f3fd742b22d69b07317c854f7d9b37bf Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 17:45:24 -0300 Subject: [PATCH 34/35] caps --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95f3349d..1994621a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This is a WIP **decompilation** of ***Starfox 64***. The purpose of the project It currently builds the following ROM: -* starfox64.us.z64 `md5: 741a94eee093c4c8684e66b89f8685e8` +* starfox64.us.z64 `MD5: 741a94eee093c4c8684e66b89f8685e8` **This repo does not include any assets or assembly code necessary for compiling the ROM. A prior copy of the game is required to extract the required assets.** From e7225bdc5d1c7968f728a4bf8c009c08793e5e73 Mon Sep 17 00:00:00 2001 From: Alejandro Javier Asenjo Nitti Date: Mon, 16 Oct 2023 17:45:49 -0300 Subject: [PATCH 35/35] discard libpng-dev as a dependency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1994621a..e6ea1d7e 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Under Debian / Ubuntu (which we recommend using), you can install them with the ```bash sudo apt update -sudo apt install make git build-essential binutils-mips-linux-gnu python3 python3-pip libpng-dev +sudo apt install make git build-essential binutils-mips-linux-gnu python3 python3-pip ``` #### 2. Clone the repository