diff --git a/Makefile b/Makefile index e4ebcd0..b35a9e8 100644 --- a/Makefile +++ b/Makefile @@ -321,7 +321,7 @@ clean: build/us/src/dk64_boot/dk64_boot_3390.c.o: OPT_FLAGS = -O2 build/us/src/dk64_boot/dk64_boot_3D20.c.o: OPT_FLAGS = -O2 build/us/src/dk64_boot/dk64_boot_3C00.c.o: OPT_FLAGS = -O1 -build/us/src/dk64_boot/dk64_boot_5C70.c.o: OPT_FLAGS = -O2 +build/us/src/dk64_boot/io/aisetfreq.c.o: OPT_FLAGS = -O2 build/us/src/dk64_boot/dk64_boot_61D0.c.o: OPT_FLAGS = -O1 build/us/src/dk64_boot/dk64_boot_62F0.c.o: OPT_FLAGS = -O1 build/us/src/dk64_boot/ll.c.o: OPT_FLAGS = -O1 diff --git a/decompressed.us.yaml b/decompressed.us.yaml index dd17e47..d1588f9 100644 --- a/decompressed.us.yaml +++ b/decompressed.us.yaml @@ -65,7 +65,7 @@ segments: - [0x5890, c, io/vimgr] - [0x5BA0, c, io/visetmode] #DONE - [0x5C10, bin, dk64_boot_5C10] #??? nops ??? - - [0x5C70, c, dk64_boot_5C70] + - [0x5C70, c, io/aisetfreq] - [0x5DC0, hasm, libc/bzero] #DONE - [0x5E60, hasm, os/invalicache] #DONE - [0x5EE0, hasm, os/writebackdcacheall] #DONE diff --git a/include/functions.h b/include/functions.h index d619ad5..372921c 100644 --- a/include/functions.h +++ b/include/functions.h @@ -90,8 +90,8 @@ void *memcpy(void *dest, void *src, u32 n); // dk64_boot/io/vimgr.c // TODO: viMgrMain has no documented signature -// dk64_boot/dk64_boot_5C70.c -s32 func_dk64_boot_80005070(u32 frequency); //s32 osAiSetFrequency(u32 frequency) +// dk64_boot/io/aisetfreq.c +s32 osAiSetFrequency(u32 frequency); //s32 osAiSetFrequency(u32 frequency) // TODO: osWriteBackDCacheAll has no documented signature but has been matched // dk64_boot/dk64_boot_61D0.c diff --git a/progress/progress.dk64_boot.csv b/progress/progress.dk64_boot.csv index 4d36beb..1346a7c 100644 --- a/progress/progress.dk64_boot.csv +++ b/progress/progress.dk64_boot.csv @@ -28,7 +28,6 @@ us,boot,__osSpGetStatus,12,yes us,boot,strchr,76,yes us,boot,__ull_rshift,44,yes us,boot,__osSetFpcCsr,16,yes -us,boot,func_dk64_boot_80005070,324,yes us,boot,osCreateMesgQueue,44,yes us,boot,__osEepStatus,428,no us,boot,func_dk64_boot_800024E0,196,yes @@ -143,6 +142,7 @@ us,boot,osSetTimer,212,yes us,boot,__osPackRamWriteDataSafe,128,no us,boot,sqrtf,16,yes us,boot,__osInsertTimer,392,yes +us,boot,osAiSetFrequency,324,yes us,boot,func_dk64_boot_800073D0,132,yes us,boot,func_dk64_boot_800004B4,64,yes us,boot,__osPackEepReadData,140,no @@ -198,7 +198,7 @@ us,boot,__osPopThread,16,yes us,boot,func_dk64_boot_800023F4,232,yes us,boot,func_dk64_boot_8000320C,4884,no us,boot,__ll_mul,48,yes -us,boot,__osContAddressCrc,208,no +us,boot,__osContAddressCrc,208,yes us,boot,__ll_div,92,yes us,boot,osGetTime,132,yes us,boot,func_dk64_boot_80000EEC,320,no @@ -225,7 +225,7 @@ us,boot,func_dk64_boot_80005A70,12,yes us,boot,__cosf,360,yes us,boot,guOrtho,104,yes us,boot,__osGetSR,16,yes -us,boot,__osContDataCrc,160,no +us,boot,__osContDataCrc,148,yes us,boot,osInvalDCache,176,yes us,boot,__osSpRawStartDma,140,yes us,boot,osMapTLBRdb,96,yes diff --git a/progress/progress.total.csv b/progress/progress.total.csv index 6eed130..4850a8b 100644 --- a/progress/progress.total.csv +++ b/progress/progress.total.csv @@ -4303,7 +4303,6 @@ us,boot,__osSpGetStatus,12,yes us,boot,strchr,76,yes us,boot,__ull_rshift,44,yes us,boot,__osSetFpcCsr,16,yes -us,boot,func_dk64_boot_80005070,324,yes us,boot,osCreateMesgQueue,44,yes us,boot,__osEepStatus,428,no us,boot,func_dk64_boot_800024E0,196,yes @@ -4418,6 +4417,7 @@ us,boot,osSetTimer,212,yes us,boot,__osPackRamWriteDataSafe,128,no us,boot,sqrtf,16,yes us,boot,__osInsertTimer,392,yes +us,boot,osAiSetFrequency,324,yes us,boot,func_dk64_boot_800073D0,132,yes us,boot,func_dk64_boot_800004B4,64,yes us,boot,__osPackEepReadData,140,no @@ -4473,7 +4473,7 @@ us,boot,__osPopThread,16,yes us,boot,func_dk64_boot_800023F4,232,yes us,boot,func_dk64_boot_8000320C,4884,no us,boot,__ll_mul,48,yes -us,boot,__osContAddressCrc,208,no +us,boot,__osContAddressCrc,208,yes us,boot,__ll_div,92,yes us,boot,osGetTime,132,yes us,boot,func_dk64_boot_80000EEC,320,no @@ -4500,7 +4500,7 @@ us,boot,func_dk64_boot_80005A70,12,yes us,boot,__cosf,360,yes us,boot,guOrtho,104,yes us,boot,__osGetSR,16,yes -us,boot,__osContDataCrc,160,no +us,boot,__osContDataCrc,148,yes us,boot,osInvalDCache,176,yes us,boot,__osSpRawStartDma,140,yes us,boot,osMapTLBRdb,96,yes diff --git a/progress/progress_dk64_boot.svg b/progress/progress_dk64_boot.svg index 4969e36..298475b 100644 --- a/progress/progress_dk64_boot.svg +++ b/progress/progress_dk64_boot.svg @@ -9,7 +9,7 @@ - + @@ -17,7 +17,7 @@ dk64_boot - 61.3787% - 61.3787% + 62.0421% + 62.0421% diff --git a/progress/progress_total.svg b/progress/progress_total.svg index 2599ca1..e88a29a 100644 --- a/progress/progress_total.svg +++ b/progress/progress_total.svg @@ -17,7 +17,7 @@ Donkey Kong 64 (US) - 41.4643% - 41.4643% + 41.4867% + 41.4867% diff --git a/src/dk64_boot/dk64_boot_1050.c b/src/dk64_boot/dk64_boot_1050.c index d10e2f6..c4bf78d 100644 --- a/src/dk64_boot/dk64_boot_1050.c +++ b/src/dk64_boot/dk64_boot_1050.c @@ -88,7 +88,7 @@ void func_dk64_boot_800005A8(void *arg0) { func_dk64_boot_80000A30(); } else { func_dk64_boot_80000450(&D_11320, &D_113F0, 0x805FB000); - D_dk64_boot_8000DCB4 = func_dk64_boot_80005070(22050); // osAiSetFrequency + D_dk64_boot_8000DCB4 = osAiSetFrequency(22050); // osAiSetFrequency bzero(0x805FB300, 0x204D00); sp34 = 0x80020000; sp30 = 0x805FB300; diff --git a/src/dk64_boot/dk64_boot_5C70.c b/src/dk64_boot/io/aisetfreq.c similarity index 86% rename from src/dk64_boot/dk64_boot_5C70.c rename to src/dk64_boot/io/aisetfreq.c index 05ea5da..f903b95 100644 --- a/src/dk64_boot/dk64_boot_5C70.c +++ b/src/dk64_boot/io/aisetfreq.c @@ -4,8 +4,7 @@ #include #include "osint.h" -s32 func_dk64_boot_80005070(u32 frequency) //s32 osAiSetFrequency(u32 frequency) -{ +s32 osAiSetFrequency(u32 frequency) { register unsigned int dacRate; register unsigned char bitRate; register float f; diff --git a/src/dk64_boot/io/crc.c b/src/dk64_boot/io/crc.c index 873e54e..b8aa47a 100644 --- a/src/dk64_boot/io/crc.c +++ b/src/dk64_boot/io/crc.c @@ -1,6 +1,76 @@ #include +#define ADDRESS_CRC_MESSAGE_LENGTH 10 +#define ADDRESS_CRC_LENGTH 5 +#define ADDRESS_CRC_GENERATOR 0x15 +#define ADDRESS_CRC_MASK ((1 << ADDRESS_CRC_LENGTH) - 1) -#pragma GLOBAL_ASM("asm/nonmatchings/dk64_boot/io/crc/__osContAddressCrc.s") +u8 __osContAddressCrc(u16 addr) { + u32 addr32 = addr; + u32 ret = 0; + u32 bit; + s32 i; -#pragma GLOBAL_ASM("asm/nonmatchings/dk64_boot/io/crc/__osContDataCrc.s") + // ret is used as a shift register for the CRC + for (bit = (1 << ADDRESS_CRC_MESSAGE_LENGTH); bit != 0; bit >>= 1) { + ret <<= 1; + if (addr32 & bit) { + if (ret & (1 << ADDRESS_CRC_LENGTH)) { + // Same as ret++; ret ^= 0x15 since last bit always 0 after the shift + ret ^= ADDRESS_CRC_GENERATOR - 1; + } else { + ret++; + } + } else if (ret & (1 << ADDRESS_CRC_LENGTH)) { + ret ^= ADDRESS_CRC_GENERATOR; + } + } + // Acts like 5 bits of 0s are appended to addr + for (i = 0; i < ADDRESS_CRC_LENGTH; i++) { + ret <<= 1; + if (ret & (1 << ADDRESS_CRC_LENGTH)) { + ret ^= ADDRESS_CRC_GENERATOR; + } + } + + // Discard the irrelevant bits above the actual remainder + return ret & ADDRESS_CRC_MASK; +} + +#define DATA_CRC_MESSAGE_BYTES 32 +#define DATA_CRC_LENGTH 8 +#define DATA_CRC_GENERATOR 0x85 + +u8 __osContDataCrc(u8* data) { + s32 ret = 0; + u32 bit; + u32 byte; + + for (byte = DATA_CRC_MESSAGE_BYTES; byte != 0; byte--, data++) { + // Loop over each bit in the byte starting with most significant + for (bit = (1 << (DATA_CRC_LENGTH - 1)); bit != 0; bit >>= 1) { + ret <<= 1; + if (*data & bit) { + if (ret & (1 << DATA_CRC_LENGTH)) { + // Same as ret++; ret ^= 0x85 since last bit always 0 after the shift + ret ^= DATA_CRC_GENERATOR - 1; + } else { + ret++; + } + } else if (ret & (1 << DATA_CRC_LENGTH)) { + ret ^= DATA_CRC_GENERATOR; + } + } + } + // Act like a byte of zeros is appended to data + do { + ret <<= 1; + if (ret & (1 << DATA_CRC_LENGTH)) { + ret ^= DATA_CRC_GENERATOR; + } + byte++; + } while (byte < DATA_CRC_LENGTH); + + // Discarding the excess is done automatically by the return type + return ret; +} \ No newline at end of file diff --git a/symbol_addrs.us.txt b/symbol_addrs.us.txt index ca5bb27..de0a1f1 100644 --- a/symbol_addrs.us.txt +++ b/symbol_addrs.us.txt @@ -93,6 +93,7 @@ __ll_to_d = 0x80007724; // segment:dk64_boot __ll_to_f = 0x8000773C; // segment:dk64_boot __ull_to_d = 0x80007754; // segment:dk64_boot __ull_to_f = 0x80007788; // segment:dk64_boot +osAiSetFrequency = 0x80005070; // segment:dk64_boot osContSetCh = 0x80007360; // segment:dk64_boot osSetTimer = 0x800077C0; // segment:dk64_boot