From d389eda3fb91369418858a4974efec65e7bc933c Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 17 Jan 2022 00:28:29 +0000 Subject: [PATCH 01/17] Un-fake a couple of matches in memory manip functions --- src/code/__osMalloc.c | 2 +- src/code/code_80106860.c | 7 +++---- src/code/code_801068B0.c | 21 ++++++++++----------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c index 0b66eb3539c..d177882a07b 100644 --- a/src/code/__osMalloc.c +++ b/src/code/__osMalloc.c @@ -590,7 +590,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) { } node->next = newNext; node->size = newSize; - func_801068B0(newNext, next, sizeof(ArenaNode)); // memcpy + func_801068B0(newNext, next, sizeof(ArenaNode)); // memmove } else { // "Allocate a new memory block and move the contents" osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n"); diff --git a/src/code/code_80106860.c b/src/code/code_80106860.c index 4c1b8480b56..4550bba2f57 100644 --- a/src/code/code_80106860.c +++ b/src/code/code_80106860.c @@ -2,11 +2,10 @@ // memset used in __osMalloc, z_quake, z_view, and z_camera void* func_80106860(void* ptr, s32 val, size_t size) { - u8* sp4 = ptr; - register s32 a3; + u8* bytePtr = ptr; - for (a3 = size--; a3 != 0; a3 = size--) { - *sp4++ = val; + while (size--) { + *bytePtr++ = val; } return ptr; } diff --git a/src/code/code_801068B0.c b/src/code/code_801068B0.c index d673cc5e0fe..b7086e8cb3d 100644 --- a/src/code/code_801068B0.c +++ b/src/code/code_801068B0.c @@ -2,22 +2,21 @@ // memmove used in __osMalloc.c void* func_801068B0(void* dst, void* src, size_t size) { - u8* spC = dst; - u8* sp8 = src; - register s32 a3; + u8* byteDst = dst; + u8* byteSrc = src; - if (spC == sp8) { + if (byteDst == byteSrc) { return dst; } - if (spC < sp8) { - for (a3 = size--; a3 != 0; a3 = size--) { - *spC++ = *sp8++; + if (byteDst < byteSrc) { + while (size--) { + *byteDst++ = *byteSrc++; } } else { - spC += size - 1; - sp8 += size - 1; - for (a3 = size--; a3 != 0; a3 = size--) { - *spC-- = *sp8--; + byteDst += size - 1; + byteSrc += size - 1; + while (size--) { + *byteDst-- = *byteSrc--; } } return dst; From 14c1ea07ce0de5a52c01676bbd572b7377a131c3 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 17 Jan 2022 03:49:36 +0000 Subject: [PATCH 02/17] Document fmodf --- data/unk_8012ABC0.data.s | 2 +- src/code/code_801067F0.c | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/data/unk_8012ABC0.data.s b/data/unk_8012ABC0.data.s index d4781c3b8c2..31e03580e8c 100644 --- a/data/unk_8012ABC0.data.s +++ b/data/unk_8012ABC0.data.s @@ -11,7 +11,7 @@ # Unused glabel D_8012ABC0 - .word func_801067F0 # fmodf? + .word fmodf .word guScale .word guRotate .word guTranslate diff --git a/src/code/code_801067F0.c b/src/code/code_801067F0.c index ae65e522ba6..e431dff64e6 100644 --- a/src/code/code_801067F0.c +++ b/src/code/code_801067F0.c @@ -1,12 +1,25 @@ #include "global.h" -// fmodf? -f32 func_801067F0(f32 arg0, f32 arg1) { - s32 sp4; +/** + * @brief Computes one \p x modulo \p y for floats. + * + * Acts like the standard C fmodf except does not handle Infinity. See https://en.cppreference.com/w/c/numeric/math/fmod + * for the details. It summarizes this function as follows: + * "The floating-point remainder of the division operation x/y calculated by this function is exactly the value x - n*y, + * where n is x/y with its fractional part truncated. + * + * The returned value has the same sign as x and is less or equal to y in magnitude." + * + * @param x dividend + * @param y modulus + * @return f32 0.0f if y is 0.0f, or the x modulo y if + */ +f32 fmodf(f32 x, f32 y) { + s32 n; - if (arg1 == 0.0f) { + if (y == 0.0f) { return 0.0f; } - sp4 = arg0 / arg1; - return arg0 - (sp4 * arg1); + n = x / y; + return x - (n * y); } From ddd272e4d6f71fdf3051374e737df819b13a6ddb Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 17 Jan 2022 00:28:29 +0000 Subject: [PATCH 03/17] Un-fake a couple of matches in memory manip functions --- src/code/__osMalloc.c | 2 +- src/code/code_80106860.c | 7 +++---- src/code/code_801068B0.c | 21 ++++++++++----------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c index 0b66eb3539c..d177882a07b 100644 --- a/src/code/__osMalloc.c +++ b/src/code/__osMalloc.c @@ -590,7 +590,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) { } node->next = newNext; node->size = newSize; - func_801068B0(newNext, next, sizeof(ArenaNode)); // memcpy + func_801068B0(newNext, next, sizeof(ArenaNode)); // memmove } else { // "Allocate a new memory block and move the contents" osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n"); diff --git a/src/code/code_80106860.c b/src/code/code_80106860.c index 4c1b8480b56..4550bba2f57 100644 --- a/src/code/code_80106860.c +++ b/src/code/code_80106860.c @@ -2,11 +2,10 @@ // memset used in __osMalloc, z_quake, z_view, and z_camera void* func_80106860(void* ptr, s32 val, size_t size) { - u8* sp4 = ptr; - register s32 a3; + u8* bytePtr = ptr; - for (a3 = size--; a3 != 0; a3 = size--) { - *sp4++ = val; + while (size--) { + *bytePtr++ = val; } return ptr; } diff --git a/src/code/code_801068B0.c b/src/code/code_801068B0.c index d673cc5e0fe..b7086e8cb3d 100644 --- a/src/code/code_801068B0.c +++ b/src/code/code_801068B0.c @@ -2,22 +2,21 @@ // memmove used in __osMalloc.c void* func_801068B0(void* dst, void* src, size_t size) { - u8* spC = dst; - u8* sp8 = src; - register s32 a3; + u8* byteDst = dst; + u8* byteSrc = src; - if (spC == sp8) { + if (byteDst == byteSrc) { return dst; } - if (spC < sp8) { - for (a3 = size--; a3 != 0; a3 = size--) { - *spC++ = *sp8++; + if (byteDst < byteSrc) { + while (size--) { + *byteDst++ = *byteSrc++; } } else { - spC += size - 1; - sp8 += size - 1; - for (a3 = size--; a3 != 0; a3 = size--) { - *spC-- = *sp8--; + byteDst += size - 1; + byteSrc += size - 1; + while (size--) { + *byteDst-- = *byteSrc--; } } return dst; From c4f31261c7e2ec136f9fb16a066b880a4e491063 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 17 Jan 2022 03:49:36 +0000 Subject: [PATCH 04/17] Document fmodf --- data/unk_8012ABC0.data.s | 2 +- src/code/code_801067F0.c | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/data/unk_8012ABC0.data.s b/data/unk_8012ABC0.data.s index d4781c3b8c2..31e03580e8c 100644 --- a/data/unk_8012ABC0.data.s +++ b/data/unk_8012ABC0.data.s @@ -11,7 +11,7 @@ # Unused glabel D_8012ABC0 - .word func_801067F0 # fmodf? + .word fmodf .word guScale .word guRotate .word guTranslate diff --git a/src/code/code_801067F0.c b/src/code/code_801067F0.c index ae65e522ba6..e431dff64e6 100644 --- a/src/code/code_801067F0.c +++ b/src/code/code_801067F0.c @@ -1,12 +1,25 @@ #include "global.h" -// fmodf? -f32 func_801067F0(f32 arg0, f32 arg1) { - s32 sp4; +/** + * @brief Computes one \p x modulo \p y for floats. + * + * Acts like the standard C fmodf except does not handle Infinity. See https://en.cppreference.com/w/c/numeric/math/fmod + * for the details. It summarizes this function as follows: + * "The floating-point remainder of the division operation x/y calculated by this function is exactly the value x - n*y, + * where n is x/y with its fractional part truncated. + * + * The returned value has the same sign as x and is less or equal to y in magnitude." + * + * @param x dividend + * @param y modulus + * @return f32 0.0f if y is 0.0f, or the x modulo y if + */ +f32 fmodf(f32 x, f32 y) { + s32 n; - if (arg1 == 0.0f) { + if (y == 0.0f) { return 0.0f; } - sp4 = arg0 / arg1; - return arg0 - (sp4 * arg1); + n = x / y; + return x - (n * y); } From 71c356ffbe344c1505cd3ae3d5e43a217d39b592 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 28 Feb 2022 13:20:08 +0000 Subject: [PATCH 05/17] Rename functions and files --- Makefile | 4 ++-- include/functions.h | 4 ++-- spec | 4 ++-- src/code/__osMalloc.c | 26 ++++++++++----------- src/code/{code_801068B0.c => __osMemmove.c} | 2 +- src/code/{code_80106860.c => __osMemset.c} | 2 +- src/code/z_camera.c | 2 +- src/code/z_quake.c | 2 +- src/code/z_view.c | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) rename src/code/{code_801068B0.c => __osMemmove.c} (88%) rename src/code/{code_80106860.c => __osMemset.c} (76%) diff --git a/Makefile b/Makefile index 7d72161c4e4..824e7909e1d 100644 --- a/Makefile +++ b/Makefile @@ -186,9 +186,9 @@ build/src/code/fault.o: OPTFLAGS := -O2 -g3 build/src/code/fault_drawer.o: CFLAGS += -trapuv build/src/code/fault_drawer.o: OPTFLAGS := -O2 -g3 build/src/code/ucode_disas.o: OPTFLAGS := -O2 -g3 -build/src/code/code_801068B0.o: OPTFLAGS := -g -build/src/code/code_80106860.o: OPTFLAGS := -g build/src/code/code_801067F0.o: OPTFLAGS := -g +build/src/code/__osMemset.o: OPTFLAGS := -g +build/src/code/__osMemmove.o: OPTFLAGS := -g build/src/libultra/libc/absf.o: OPTFLAGS := -O2 -g3 build/src/libultra/libc/sqrt.o: OPTFLAGS := -O2 -g3 diff --git a/include/functions.h b/include/functions.h index e6b721f5d28..d25b8d669b7 100644 --- a/include/functions.h +++ b/include/functions.h @@ -2297,8 +2297,8 @@ void guMtxF2L(MtxF* m1, Mtx* m2); u32* osViGetCurrentFramebuffer(void); s32 __osSpSetPc(void* pc); f32 absf(f32); -void* func_80106860(void* ptr, s32 val, size_t size); -void* func_801068B0(void* dst, void* src, size_t size); +void* __osMemset(void* ptr, s32 val, size_t size); +void* __osMemmove(void* dst, void* src, size_t size); void Message_UpdateOcarinaGame(GlobalContext* globalCtx); u8 Message_ShouldAdvance(GlobalContext* globalCtx); void Message_CloseTextbox(GlobalContext*); diff --git a/spec b/spec index 6a6938d17a5..4b7a6ba4ef9 100644 --- a/spec +++ b/spec @@ -510,8 +510,8 @@ beginseg include "build/src/libultra/libc/sqrt.o" include "build/src/libultra/libc/absf.o" include "build/src/code/code_801067F0.o" - include "build/src/code/code_80106860.o" - include "build/src/code/code_801068B0.o" + include "build/src/code/__osMemset.o" + include "build/src/code/__osMemmove.o" include_data_with_rodata "build/src/code/z_message_PAL.o" include "build/src/code/z_game_over.o" include "build/src/code/z_construct.o" diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c index d177882a07b..fbe67faba8c 100644 --- a/src/code/__osMalloc.c +++ b/src/code/__osMalloc.c @@ -122,7 +122,7 @@ void __osMallocAddBlock(Arena* arena, void* start, s32 size) { size2 = (size - diff) & ~0xF; if (size2 > (s32)sizeof(ArenaNode)) { - func_80106860(firstNode, BLOCK_UNINIT_MAGIC, size2); // memset + __osMemset(firstNode, BLOCK_UNINIT_MAGIC, size2); // memset firstNode->next = NULL; firstNode->prev = NULL; firstNode->size = size2 - sizeof(ArenaNode); @@ -151,7 +151,7 @@ void ArenaImpl_RemoveAllBlocks(Arena* arena) { iter = arena->head; while (iter != NULL) { next = ArenaImpl_GetNextBlock(iter); - func_80106860(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode)); // memset + __osMemset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode)); // memset iter = next; } @@ -228,7 +228,7 @@ void* __osMalloc_NoLockDebug(Arena* arena, u32 size, const char* file, s32 line) ArenaImpl_SetDebugInfo(iter, file, line, arena); alloc = (void*)((u32)iter + sizeof(ArenaNode)); if (arena->flag & FILL_ALLOCBLOCK) { - func_80106860(alloc, BLOCK_ALLOC_MAGIC, size); + __osMemset(alloc, BLOCK_ALLOC_MAGIC, size); } break; @@ -288,7 +288,7 @@ void* __osMallocRDebug(Arena* arena, u32 size, const char* file, s32 line) { ArenaImpl_SetDebugInfo(iter, file, line, arena); allocR = (void*)((u32)iter + sizeof(ArenaNode)); if (arena->flag & FILL_ALLOCBLOCK) { - func_80106860(allocR, BLOCK_ALLOC_MAGIC, size); + __osMemset(allocR, BLOCK_ALLOC_MAGIC, size); } break; @@ -339,7 +339,7 @@ void* __osMalloc_NoLock(Arena* arena, u32 size) { ArenaImpl_SetDebugInfo(iter, NULL, 0, arena); alloc = (void*)((u32)iter + sizeof(ArenaNode)); if (arena->flag & FILL_ALLOCBLOCK) { - func_80106860(alloc, BLOCK_ALLOC_MAGIC, size); + __osMemset(alloc, BLOCK_ALLOC_MAGIC, size); } break; } @@ -398,7 +398,7 @@ void* __osMallocR(Arena* arena, u32 size) { ArenaImpl_SetDebugInfo(iter, NULL, 0, arena); alloc = (void*)((u32)iter + sizeof(ArenaNode)); if (arena->flag & FILL_ALLOCBLOCK) { - func_80106860(alloc, BLOCK_ALLOC_MAGIC, size); + __osMemset(alloc, BLOCK_ALLOC_MAGIC, size); } break; } @@ -442,7 +442,7 @@ void __osFree_NoLock(Arena* arena, void* ptr) { ArenaImpl_SetDebugInfo(node, NULL, 0, arena); if (arena->flag & FILL_FREEBLOCK) { - func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size); + __osMemset((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size); } newNext = next; @@ -454,7 +454,7 @@ void __osFree_NoLock(Arena* arena, void* ptr) { node->size += next->size + sizeof(ArenaNode); if (arena->flag & FILL_FREEBLOCK) { - func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); + __osMemset(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); } node->next = newNext; next = newNext; @@ -467,7 +467,7 @@ void __osFree_NoLock(Arena* arena, void* ptr) { prev->next = next; prev->size += node->size + sizeof(ArenaNode); if (arena->flag & FILL_FREEBLOCK) { - func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); + __osMemset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); } } } @@ -512,7 +512,7 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) { ArenaImpl_SetDebugInfo(node, file, line, arena); if (arena->flag & FILL_FREEBLOCK) { - func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size); + __osMemset((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size); } newNext = node->next; @@ -524,7 +524,7 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) { node->size += next->size + sizeof(ArenaNode); if (arena->flag & FILL_FREEBLOCK) { - func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); + __osMemset(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); } node->next = newNext; next = newNext; @@ -537,7 +537,7 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) { prev->next = next; prev->size += node->size + sizeof(ArenaNode); if (arena->flag & FILL_FREEBLOCK) { - func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); + __osMemset(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); } } } @@ -590,7 +590,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) { } node->next = newNext; node->size = newSize; - func_801068B0(newNext, next, sizeof(ArenaNode)); // memmove + __osMemmove(newNext, next, sizeof(ArenaNode)); // memmove } else { // "Allocate a new memory block and move the contents" osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n"); diff --git a/src/code/code_801068B0.c b/src/code/__osMemmove.c similarity index 88% rename from src/code/code_801068B0.c rename to src/code/__osMemmove.c index b7086e8cb3d..362ad3c01f5 100644 --- a/src/code/code_801068B0.c +++ b/src/code/__osMemmove.c @@ -1,7 +1,7 @@ #include "global.h" // memmove used in __osMalloc.c -void* func_801068B0(void* dst, void* src, size_t size) { +void* __osMemmove(void* dst, void* src, size_t size) { u8* byteDst = dst; u8* byteSrc = src; diff --git a/src/code/code_80106860.c b/src/code/__osMemset.c similarity index 76% rename from src/code/code_80106860.c rename to src/code/__osMemset.c index 4550bba2f57..2b397b81a34 100644 --- a/src/code/code_80106860.c +++ b/src/code/__osMemset.c @@ -1,7 +1,7 @@ #include "global.h" // memset used in __osMalloc, z_quake, z_view, and z_camera -void* func_80106860(void* ptr, s32 val, size_t size) { +void* __osMemset(void* ptr, s32 val, size_t size) { u8* bytePtr = ptr; while (size--) { diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 068b0ddaa60..85286077c30 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -6793,7 +6793,7 @@ void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, GlobalCon s16 curUID; s16 j; - func_80106860(camera, 0, sizeof(*camera)); + __osMemset(camera, 0, sizeof(*camera)); if (sInitRegs) { for (i = 0; i < sOREGInitCnt; i++) { OREG(i) = sOREGInit[i]; diff --git a/src/code/z_quake.c b/src/code/z_quake.c index cd1fac1d1de..28409f48b2e 100644 --- a/src/code/z_quake.c +++ b/src/code/z_quake.c @@ -152,7 +152,7 @@ QuakeRequest* Quake_AddImpl(Camera* cam, u32 callbackIdx) { s16 idx = Quake_GetFreeIndex(); QuakeRequest* req = &sQuakeRequest[idx]; - func_80106860(req, 0, sizeof(QuakeRequest)); // memset + __osMemset(req, 0, sizeof(QuakeRequest)); // memset req->cam = cam; req->camPtrIdx = cam->thisIdx; req->callbackIdx = callbackIdx; diff --git a/src/code/z_view.c b/src/code/z_view.c index 340d15aea0c..df45143c905 100644 --- a/src/code/z_view.c +++ b/src/code/z_view.c @@ -21,7 +21,7 @@ View* View_New(GraphicsContext* gfxCtx) { View* view = SystemArena_MallocDebug(sizeof(View), "../z_view.c", 285); if (view != NULL) { - func_80106860(view, 0, sizeof(View)); // memset + __osMemset(view, 0, sizeof(View)); // memset View_Init(view, gfxCtx); } From b1dcb3b3feb371d93bf3938efddb54f449512a72 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 28 Feb 2022 15:11:27 +0000 Subject: [PATCH 06/17] Document memmove, memsets, memcpys --- include/functions.h | 4 +- src/code/__osMalloc.c | 6 +- src/code/__osMemmove.c | 34 ++++--- src/code/__osMemset.c | 22 ++++- src/code/code_80069420.c | 37 +++++-- src/code/code_801067F0.c | 3 +- src/code/z_demo.c | 46 ++++----- src/code/z_lib.c | 19 +++- src/code/z_message_PAL.c | 4 +- src/code/z_quake.c | 2 +- src/code/z_sram.c | 98 +++++++++---------- src/code/z_view.c | 2 +- .../ovl_file_choose/z_file_choose.c | 2 +- 13 files changed, 172 insertions(+), 107 deletions(-) diff --git a/include/functions.h b/include/functions.h index d25b8d669b7..7ec3b1e4430 100644 --- a/include/functions.h +++ b/include/functions.h @@ -831,7 +831,7 @@ void func_800645A0(GlobalContext* globalCtx, CutsceneContext* csCtx); void Cutscene_HandleEntranceTriggers(GlobalContext* globalCtx); void Cutscene_HandleConditionalTriggers(GlobalContext* globalCtx); void Cutscene_SetSegment(GlobalContext* globalCtx, void* segment); -void* MemCopy(void* dest, void* src, s32 size); +void* MemCpy(void* dest, const void* src, s32 size); void GetItem_Draw(GlobalContext* globalCtx, s16 drawId); void SoundSource_InitAll(GlobalContext* globalCtx); void SoundSource_UpdateAll(GlobalContext* globalCtx); @@ -2298,7 +2298,7 @@ u32* osViGetCurrentFramebuffer(void); s32 __osSpSetPc(void* pc); f32 absf(f32); void* __osMemset(void* ptr, s32 val, size_t size); -void* __osMemmove(void* dst, void* src, size_t size); +void* __osMemmove(void* dest, const void* src, size_t size); void Message_UpdateOcarinaGame(GlobalContext* globalCtx); u8 Message_ShouldAdvance(GlobalContext* globalCtx); void Message_CloseTextbox(GlobalContext*); diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c index fbe67faba8c..9a684b81583 100644 --- a/src/code/__osMalloc.c +++ b/src/code/__osMalloc.c @@ -122,7 +122,7 @@ void __osMallocAddBlock(Arena* arena, void* start, s32 size) { size2 = (size - diff) & ~0xF; if (size2 > (s32)sizeof(ArenaNode)) { - __osMemset(firstNode, BLOCK_UNINIT_MAGIC, size2); // memset + __osMemset(firstNode, BLOCK_UNINIT_MAGIC, size2); firstNode->next = NULL; firstNode->prev = NULL; firstNode->size = size2 - sizeof(ArenaNode); @@ -151,7 +151,7 @@ void ArenaImpl_RemoveAllBlocks(Arena* arena) { iter = arena->head; while (iter != NULL) { next = ArenaImpl_GetNextBlock(iter); - __osMemset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode)); // memset + __osMemset(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode)); iter = next; } @@ -590,7 +590,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) { } node->next = newNext; node->size = newSize; - __osMemmove(newNext, next, sizeof(ArenaNode)); // memmove + __osMemmove(newNext, next, sizeof(ArenaNode)); } else { // "Allocate a new memory block and move the contents" osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n"); diff --git a/src/code/__osMemmove.c b/src/code/__osMemmove.c index 362ad3c01f5..721f5a35dcf 100644 --- a/src/code/__osMemmove.c +++ b/src/code/__osMemmove.c @@ -1,23 +1,33 @@ #include "global.h" -// memmove used in __osMalloc.c -void* __osMemmove(void* dst, void* src, size_t size) { - u8* byteDst = dst; - u8* byteSrc = src; +/** + * @brief memmove: copies @p size bytes from memory starting at @p src to memory starting at @p dest . + * + * Unlike @ref memcpy(), the regions of memory may overlap. + * + * @param[in,out] dest address of start of buffer writing to + * @param[in] src address of start of buffer to read from + * @param[in] size number of bytes to copy. + * + * @return dest + */ +void* __osMemmove(void* dest, const void* src, size_t size) { + u8* destPtr = dest; + const u8* srcPtr = src; - if (byteDst == byteSrc) { - return dst; + if (destPtr == srcPtr) { + return dest; } - if (byteDst < byteSrc) { + if (destPtr < srcPtr) { while (size--) { - *byteDst++ = *byteSrc++; + *destPtr++ = *srcPtr++; } } else { - byteDst += size - 1; - byteSrc += size - 1; + destPtr += size - 1; + srcPtr += size - 1; while (size--) { - *byteDst-- = *byteSrc--; + *destPtr-- = *srcPtr--; } } - return dst; + return dest; } diff --git a/src/code/__osMemset.c b/src/code/__osMemset.c index 2b397b81a34..f0d44f461c8 100644 --- a/src/code/__osMemset.c +++ b/src/code/__osMemset.c @@ -1,11 +1,23 @@ #include "global.h" -// memset used in __osMalloc, z_quake, z_view, and z_camera -void* __osMemset(void* ptr, s32 val, size_t size) { - u8* bytePtr = ptr; +/** + * @brief memset: sets @p size bytes to @p val starting at address @p dest . + * + * There are two other memsets in this codebase, + * @sa Lib_MemSet(), MemSet() + * This one is used in __osMalloc, z_quake, z_view, and z_camera + * + * @param[in,out] dest address to start at + * @param[in] val value to write (s32, but interpreted as u8) + * @param[in] size number of bytes to write + * + * @return dest + */ +void* __osMemset(void* dest, s32 val, size_t size) { + u8* destu = dest; while (size--) { - *bytePtr++ = val; + *destu++ = val; } - return ptr; + return dest; } diff --git a/src/code/code_80069420.c b/src/code/code_80069420.c index 3d656cfb0b9..4dc3862085b 100644 --- a/src/code/code_80069420.c +++ b/src/code/code_80069420.c @@ -1,23 +1,48 @@ #include "global.h" -void* MemCopy(void* dest, void* src, s32 size) { - u8* destu = (u8*)dest; - u8* srcu = (u8*)src; +/** + * @brief memcpy: copies @p size bytes from memory starting at @p src to memory starting at @p dest . Expects the memory + * specified by @p src and @p dest to not overlap. + * + * @sa libultra also has a memcpy(). + * + * @param[in,out] dest address of start of buffer writing to + * @param[in] src address of start of buffer to read from + * @param[in] size number of bytes to copy. Has to be s32: it is not possible to copy more than 2 GB of RAM at once. + * + * @return dest + */ +void* MemCpy(void* dest, const void* src, s32 size) { + u8* destPtr = dest; + const u8* srcPtr = src; while (size > 0) { - *destu++ = *srcu++; + *destPtr++ = *srcPtr++; size--; } return dest; } +/** + * @brief memset: sets @p size bytes to @p val starting at address @p dest . + * + * There are two other memsets in this codebase, + * @sa Lib_MemSet(), __osMemSet() + * This one is unused. + * + * @param[in,out] dest address to start at + * @param[in] val value to write (s32, but interpreted as u8) + * @param[in] size number of bytes to write. Has to be s32: it is not possible to set more than 2 GB of RAM at once. + * + * @return dest + */ void* MemSet(void* dest, s32 val, s32 size) { - u8* destu = (u8*)dest; + u8* destPtr = dest; s32 s = size; while (s > 0) { - *destu++ = val; + *destPtr++ = val; s--; } diff --git a/src/code/code_801067F0.c b/src/code/code_801067F0.c index e431dff64e6..41ac3b1a1f7 100644 --- a/src/code/code_801067F0.c +++ b/src/code/code_801067F0.c @@ -1,7 +1,7 @@ #include "global.h" /** - * @brief Computes one \p x modulo \p y for floats. + * @brief Computes one @p x modulo @p y for floats. * * Acts like the standard C fmodf except does not handle Infinity. See https://en.cppreference.com/w/c/numeric/math/fmod * for the details. It summarizes this function as follows: @@ -12,6 +12,7 @@ * * @param x dividend * @param y modulus + * * @return f32 0.0f if y is 0.0f, or the x modulo y if */ f32 fmodf(f32 x, f32 y) { diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 697618917ea..7cee683546b 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -1562,9 +1562,9 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, s32 cutsceneEndFrame; s16 j; - MemCopy(&totalEntries, cutscenePtr, 4); + MemCpy(&totalEntries, cutscenePtr, 4); cutscenePtr += 4; - MemCopy(&cutsceneEndFrame, cutscenePtr, 4); + MemCpy(&cutsceneEndFrame, cutscenePtr, 4); cutscenePtr += 4; if ((cutsceneEndFrame < csCtx->frames) && (csCtx->state != CS_STATE_UNSKIPPABLE_EXEC)) { @@ -1578,7 +1578,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } for (i = 0; i < totalEntries; i++) { - MemCopy(&cmdType, cutscenePtr, 4); + MemCpy(&cmdType, cutscenePtr, 4); cutscenePtr += 4; if (cmdType == -1) { @@ -1587,7 +1587,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, switch (cmdType) { case CS_CMD_MISC: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { func_80064824(globalCtx, csCtx, (void*)cutscenePtr); @@ -1595,7 +1595,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_SET_LIGHTING: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { Cutscene_Command_SetLighting(globalCtx, csCtx, (void*)cutscenePtr); @@ -1603,7 +1603,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_PLAYBGM: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { Cutscene_Command_PlayBGM(globalCtx, csCtx, (void*)cutscenePtr); @@ -1611,7 +1611,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_STOPBGM: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { Cutscene_Command_StopBGM(globalCtx, csCtx, (void*)cutscenePtr); @@ -1619,7 +1619,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_FADEBGM: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { Cutscene_Command_FadeBGM(globalCtx, csCtx, (void*)cutscenePtr); @@ -1627,7 +1627,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_09: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { Cutscene_Command_09(globalCtx, csCtx, (void*)cutscenePtr); @@ -1635,7 +1635,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_SETTIME: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { func_80065134(globalCtx, csCtx, (void*)cutscenePtr); @@ -1643,7 +1643,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_SET_PLAYER_ACTION: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1671,7 +1671,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, case 138: case 139: case 144: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1699,7 +1699,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, case 125: case 131: case 141: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1723,7 +1723,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, case 121: case 126: case 132: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1746,7 +1746,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, case 108: case 127: case 133: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1765,7 +1765,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, case 83: case 128: case 135: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1782,7 +1782,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, case 90: case 129: case 136: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1800,7 +1800,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, case 115: case 130: case 137: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1817,7 +1817,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, case 114: case 134: case 142: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1828,7 +1828,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_SET_ACTOR_ACTION_9: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1839,7 +1839,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, } break; case CS_CMD_SET_ACTOR_ACTION_10: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1873,7 +1873,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, cutscenePtr += 8; break; case CS_CMD_TEXTBOX: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cmd = (CsCmdBase*)cutscenePtr; @@ -1889,7 +1889,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx, cutscenePtr += 8; break; default: - MemCopy(&cmdEntries, cutscenePtr, 4); + MemCpy(&cmdEntries, cutscenePtr, 4); cutscenePtr += 4; for (j = 0; j < cmdEntries; j++) { cutscenePtr += 0x30; diff --git a/src/code/z_lib.c b/src/code/z_lib.c index 190af64a633..76dfdfc74ae 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -1,7 +1,24 @@ #include "global.h" +/** + * @brief memset: sets @p size bytes to @p val starting at address @p dest . + * + * Unlike normal memset, + * - @p dest is a u8* already, + * - does not return @p dest , + * - the arguments are in a different order, + * - @p val is a u8 instead of the standard s32. + * + * There are two other memsets in this codebase, + * @sa __osMemset(), MemSet() + * This one is used in z_actor and certain actors. + * + * @param[in,out] dest address to start at + * @param[in] size number of bytes to write + * @param[in] val value to write + */ void Lib_MemSet(u8* dest, size_t size, u8 val) { - u32 i; + size_t i; // clang-format off for (i = 0; i < size; i++) { *dest++ = val; } diff --git a/src/code/z_message_PAL.c b/src/code/z_message_PAL.c index f07145ac873..1b0b3ee6592 100644 --- a/src/code/z_message_PAL.c +++ b/src/code/z_message_PAL.c @@ -2592,7 +2592,7 @@ void Message_DrawMain(GlobalContext* globalCtx, Gfx** p) { osSyncPrintf("録音終了!!!!!!!!!録音終了\n"); osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("\n====================================================================\n"); - MemCopy(gSaveContext.scarecrowCustomSong, gScarecrowCustomSongPtr, + MemCpy(gSaveContext.scarecrowCustomSong, gScarecrowCustomSongPtr, sizeof(gSaveContext.scarecrowCustomSong)); for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowCustomSong); i++) { osSyncPrintf("%d, ", gSaveContext.scarecrowCustomSong[i]); @@ -2655,7 +2655,7 @@ void Message_DrawMain(GlobalContext* globalCtx, Gfx** p) { &D_801333E8); osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("\n====================================================================\n"); - MemCopy(gSaveContext.scarecrowSpawnSong, gScarecrowSpawnSongPtr, + MemCpy(gSaveContext.scarecrowSpawnSong, gScarecrowSpawnSongPtr, sizeof(gSaveContext.scarecrowSpawnSong)); for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowSpawnSong); i++) { osSyncPrintf("%d, ", gSaveContext.scarecrowSpawnSong[i]); diff --git a/src/code/z_quake.c b/src/code/z_quake.c index 28409f48b2e..257d6627bdb 100644 --- a/src/code/z_quake.c +++ b/src/code/z_quake.c @@ -152,7 +152,7 @@ QuakeRequest* Quake_AddImpl(Camera* cam, u32 callbackIdx) { s16 idx = Quake_GetFreeIndex(); QuakeRequest* req = &sQuakeRequest[idx]; - __osMemset(req, 0, sizeof(QuakeRequest)); // memset + __osMemset(req, 0, sizeof(QuakeRequest)); req->cam = cam; req->camPtrIdx = cam->thisIdx; req->callbackIdx = callbackIdx; diff --git a/src/code/z_sram.c b/src/code/z_sram.c index f2844a88a29..36e19a647ff 100644 --- a/src/code/z_sram.c +++ b/src/code/z_sram.c @@ -306,7 +306,7 @@ void Sram_OpenSave(SramContext* sramCtx) { i = gSramSlotOffsets[gSaveContext.fileNum]; osSyncPrintf("ぽいんと=%x(%d)\n", i, gSaveContext.fileNum); // "Point=" - MemCopy(&gSaveContext, sramCtx->readBuff + i, sizeof(Save)); + MemCpy(&gSaveContext, sramCtx->readBuff + i, sizeof(Save)); osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("SCENE_DATA_ID = %d SceneNo = %d\n", gSaveContext.savedSceneNum, @@ -381,7 +381,7 @@ void Sram_OpenSave(SramContext* sramCtx) { osSyncPrintf(VT_FGCOL(BLUE)); osSyncPrintf("\n====================================================================\n"); - MemCopy(gScarecrowCustomSongPtr, gSaveContext.scarecrowCustomSong, sizeof(gSaveContext.scarecrowCustomSong)); + MemCpy(gScarecrowCustomSongPtr, gSaveContext.scarecrowCustomSong, sizeof(gSaveContext.scarecrowCustomSong)); ptr = (u8*)gScarecrowCustomSongPtr; for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowCustomSong); i++, ptr++) { @@ -396,7 +396,7 @@ void Sram_OpenSave(SramContext* sramCtx) { osSyncPrintf(VT_FGCOL(GREEN)); osSyncPrintf("\n====================================================================\n"); - MemCopy(gScarecrowSpawnSongPtr, gSaveContext.scarecrowSpawnSong, sizeof(gSaveContext.scarecrowSpawnSong)); + MemCpy(gScarecrowSpawnSongPtr, gSaveContext.scarecrowSpawnSong, sizeof(gSaveContext.scarecrowSpawnSong)); ptr = gScarecrowSpawnSongPtr; for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowSpawnSong); i++, ptr++) { @@ -521,7 +521,7 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s for (slotNum = 0; slotNum < 3; slotNum++) { offset = gSramSlotOffsets[slotNum]; osSyncPrintf("ぽいんと=%x(%d) SAVE_MAX=%d\n", offset, gSaveContext.fileNum, sizeof(Save)); - MemCopy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save)); + MemCpy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save)); oldChecksum = gSaveContext.checksum; gSaveContext.checksum = 0; @@ -539,7 +539,7 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s // checksum didnt match, try backup save osSyncPrintf("ERROR!!! = %x(%d)\n", gSramSlotOffsets[slotNum], slotNum); offset = gSramSlotOffsets[slotNum + 3]; - MemCopy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save)); + MemCpy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save)); oldChecksum = gSaveContext.checksum; gSaveContext.checksum = 0; @@ -619,48 +619,48 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s osSyncPrintf("SAVECT=%x, NAME=%x, LIFE=%x, ITEM=%x, 64DD=%x, HEART=%x\n", DEATHS, NAME, HEALTH_CAP, QUEST, N64DD, DEFENSE); - MemCopy(&fileChooseCtx->deaths[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEATHS, sizeof(fileChooseCtx->deaths[0])); - MemCopy(&fileChooseCtx->deaths[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEATHS, sizeof(fileChooseCtx->deaths[0])); - MemCopy(&fileChooseCtx->deaths[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEATHS, sizeof(fileChooseCtx->deaths[0])); + MemCpy(&fileChooseCtx->deaths[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEATHS, sizeof(fileChooseCtx->deaths[0])); + MemCpy(&fileChooseCtx->deaths[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEATHS, sizeof(fileChooseCtx->deaths[0])); + MemCpy(&fileChooseCtx->deaths[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEATHS, sizeof(fileChooseCtx->deaths[0])); - MemCopy(&fileChooseCtx->fileNames[0], sramCtx->readBuff + SLOT_OFFSET(0) + NAME, + MemCpy(&fileChooseCtx->fileNames[0], sramCtx->readBuff + SLOT_OFFSET(0) + NAME, sizeof(fileChooseCtx->fileNames[0])); - MemCopy(&fileChooseCtx->fileNames[1], sramCtx->readBuff + SLOT_OFFSET(1) + NAME, + MemCpy(&fileChooseCtx->fileNames[1], sramCtx->readBuff + SLOT_OFFSET(1) + NAME, sizeof(fileChooseCtx->fileNames[0])); - MemCopy(&fileChooseCtx->fileNames[2], sramCtx->readBuff + SLOT_OFFSET(2) + NAME, + MemCpy(&fileChooseCtx->fileNames[2], sramCtx->readBuff + SLOT_OFFSET(2) + NAME, sizeof(fileChooseCtx->fileNames[0])); - MemCopy(&fileChooseCtx->healthCapacities[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH_CAP, + MemCpy(&fileChooseCtx->healthCapacities[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH_CAP, sizeof(fileChooseCtx->healthCapacities[0])); - MemCopy(&fileChooseCtx->healthCapacities[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH_CAP, + MemCpy(&fileChooseCtx->healthCapacities[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH_CAP, sizeof(fileChooseCtx->healthCapacities[0])); - MemCopy(&fileChooseCtx->healthCapacities[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH_CAP, + MemCpy(&fileChooseCtx->healthCapacities[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH_CAP, sizeof(fileChooseCtx->healthCapacities[0])); - MemCopy(&fileChooseCtx->questItems[0], sramCtx->readBuff + SLOT_OFFSET(0) + QUEST, + MemCpy(&fileChooseCtx->questItems[0], sramCtx->readBuff + SLOT_OFFSET(0) + QUEST, sizeof(fileChooseCtx->questItems[0])); - MemCopy(&fileChooseCtx->questItems[1], sramCtx->readBuff + SLOT_OFFSET(1) + QUEST, + MemCpy(&fileChooseCtx->questItems[1], sramCtx->readBuff + SLOT_OFFSET(1) + QUEST, sizeof(fileChooseCtx->questItems[0])); - MemCopy(&fileChooseCtx->questItems[2], sramCtx->readBuff + SLOT_OFFSET(2) + QUEST, + MemCpy(&fileChooseCtx->questItems[2], sramCtx->readBuff + SLOT_OFFSET(2) + QUEST, sizeof(fileChooseCtx->questItems[0])); - MemCopy(&fileChooseCtx->n64ddFlags[0], sramCtx->readBuff + SLOT_OFFSET(0) + N64DD, + MemCpy(&fileChooseCtx->n64ddFlags[0], sramCtx->readBuff + SLOT_OFFSET(0) + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - MemCopy(&fileChooseCtx->n64ddFlags[1], sramCtx->readBuff + SLOT_OFFSET(1) + N64DD, + MemCpy(&fileChooseCtx->n64ddFlags[1], sramCtx->readBuff + SLOT_OFFSET(1) + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - MemCopy(&fileChooseCtx->n64ddFlags[2], sramCtx->readBuff + SLOT_OFFSET(2) + N64DD, + MemCpy(&fileChooseCtx->n64ddFlags[2], sramCtx->readBuff + SLOT_OFFSET(2) + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - MemCopy(&fileChooseCtx->defense[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEFENSE, + MemCpy(&fileChooseCtx->defense[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEFENSE, sizeof(fileChooseCtx->defense[0])); - MemCopy(&fileChooseCtx->defense[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEFENSE, + MemCpy(&fileChooseCtx->defense[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEFENSE, sizeof(fileChooseCtx->defense[0])); - MemCopy(&fileChooseCtx->defense[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEFENSE, + MemCpy(&fileChooseCtx->defense[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEFENSE, sizeof(fileChooseCtx->defense[0])); - MemCopy(&fileChooseCtx->health[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH, sizeof(fileChooseCtx->health[0])); - MemCopy(&fileChooseCtx->health[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH, sizeof(fileChooseCtx->health[0])); - MemCopy(&fileChooseCtx->health[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH, sizeof(fileChooseCtx->health[0])); + MemCpy(&fileChooseCtx->health[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH, sizeof(fileChooseCtx->health[0])); + MemCpy(&fileChooseCtx->health[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH, sizeof(fileChooseCtx->health[0])); + MemCpy(&fileChooseCtx->health[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH, sizeof(fileChooseCtx->health[0])); osSyncPrintf("f_64dd=%d, %d, %d\n", fileChooseCtx->n64ddFlags[0], fileChooseCtx->n64ddFlags[1], fileChooseCtx->n64ddFlags[2]); @@ -725,11 +725,11 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { offset = gSramSlotOffsets[gSaveContext.fileNum]; osSyncPrintf("I=%x no=%d\n", offset, gSaveContext.fileNum); - MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); + MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); offset = gSramSlotOffsets[gSaveContext.fileNum + 3]; osSyncPrintf("I=%x no=%d\n", offset, gSaveContext.fileNum + 3); - MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); + MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_WRITE); @@ -739,19 +739,19 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { j = gSramSlotOffsets[gSaveContext.fileNum]; - MemCopy(&fileChooseCtx->deaths[gSaveContext.fileNum], sramCtx->readBuff + j + DEATHS, + MemCpy(&fileChooseCtx->deaths[gSaveContext.fileNum], sramCtx->readBuff + j + DEATHS, sizeof(fileChooseCtx->deaths[0])); - MemCopy(&fileChooseCtx->fileNames[gSaveContext.fileNum], sramCtx->readBuff + j + NAME, + MemCpy(&fileChooseCtx->fileNames[gSaveContext.fileNum], sramCtx->readBuff + j + NAME, sizeof(fileChooseCtx->fileNames[0])); - MemCopy(&fileChooseCtx->healthCapacities[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH_CAP, + MemCpy(&fileChooseCtx->healthCapacities[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH_CAP, sizeof(fileChooseCtx->healthCapacities[0])); - MemCopy(&fileChooseCtx->questItems[gSaveContext.fileNum], sramCtx->readBuff + j + QUEST, + MemCpy(&fileChooseCtx->questItems[gSaveContext.fileNum], sramCtx->readBuff + j + QUEST, sizeof(fileChooseCtx->questItems[0])); - MemCopy(&fileChooseCtx->n64ddFlags[gSaveContext.fileNum], sramCtx->readBuff + j + N64DD, + MemCpy(&fileChooseCtx->n64ddFlags[gSaveContext.fileNum], sramCtx->readBuff + j + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - MemCopy(&fileChooseCtx->defense[gSaveContext.fileNum], sramCtx->readBuff + j + DEFENSE, + MemCpy(&fileChooseCtx->defense[gSaveContext.fileNum], sramCtx->readBuff + j + DEFENSE, sizeof(fileChooseCtx->defense[0])); - MemCopy(&fileChooseCtx->health[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH, + MemCpy(&fileChooseCtx->health[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH, sizeof(fileChooseCtx->health[0])); osSyncPrintf("f_64dd[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->n64ddFlags[gSaveContext.fileNum]); @@ -765,14 +765,14 @@ void Sram_EraseSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { Sram_InitNewSave(); offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex]; - MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); + MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000) + offset, &gSaveContext, SLOT_SIZE, OS_WRITE); - MemCopy(&fileChooseCtx->n64ddFlags[fileChooseCtx->selectedFileIndex], sramCtx->readBuff + offset + N64DD, + MemCpy(&fileChooseCtx->n64ddFlags[fileChooseCtx->selectedFileIndex], sramCtx->readBuff + offset + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex + 3]; - MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); + MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000) + offset, &gSaveContext, SLOT_SIZE, OS_WRITE); osSyncPrintf("CLEAR終了\n"); @@ -786,31 +786,31 @@ void Sram_CopySave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { gSramSlotOffsets[fileChooseCtx->copyDestFileIndex]); offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex]; - MemCopy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save)); + MemCpy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save)); offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex]; - MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); + MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex + 3]; - MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); + MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_WRITE); offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex]; - MemCopy(&fileChooseCtx->deaths[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEATHS, + MemCpy(&fileChooseCtx->deaths[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEATHS, sizeof(fileChooseCtx->deaths[0])); - MemCopy(&fileChooseCtx->fileNames[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + NAME, + MemCpy(&fileChooseCtx->fileNames[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + NAME, sizeof(fileChooseCtx->fileNames[0])); - MemCopy(&fileChooseCtx->healthCapacities[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + HEALTH_CAP, + MemCpy(&fileChooseCtx->healthCapacities[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + HEALTH_CAP, sizeof(fileChooseCtx->healthCapacities[0])); - MemCopy(&fileChooseCtx->questItems[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + QUEST, + MemCpy(&fileChooseCtx->questItems[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + QUEST, sizeof(fileChooseCtx->questItems[0])); - MemCopy(&fileChooseCtx->n64ddFlags[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + N64DD, + MemCpy(&fileChooseCtx->n64ddFlags[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - MemCopy(&fileChooseCtx->defense[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEFENSE, + MemCpy(&fileChooseCtx->defense[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEFENSE, sizeof(fileChooseCtx->defense[0])); - MemCopy(&fileChooseCtx->health[fileChooseCtx->copyDestFileIndex], (sramCtx->readBuff + offset) + HEALTH, + MemCpy(&fileChooseCtx->health[fileChooseCtx->copyDestFileIndex], (sramCtx->readBuff + offset) + HEALTH, sizeof(fileChooseCtx->health[0])); osSyncPrintf("f_64dd[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->n64ddFlags[gSaveContext.fileNum]); @@ -835,7 +835,7 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) { if (sZeldaMagic[i + SRAM_HEADER_MAGIC] != sramCtx->readBuff[i + SRAM_HEADER_MAGIC]) { osSyncPrintf("SRAM破壊!!!!!!\n"); // "SRAM destruction! ! ! ! ! !" gSaveContext.language = sramCtx->readBuff[SRAM_HEADER_LANGUAGE]; - MemCopy(sramCtx->readBuff, sZeldaMagic, sizeof(sZeldaMagic)); + MemCpy(sramCtx->readBuff, sZeldaMagic, sizeof(sZeldaMagic)); sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language; Sram_WriteSramHeader(sramCtx); } diff --git a/src/code/z_view.c b/src/code/z_view.c index df45143c905..44c01399d36 100644 --- a/src/code/z_view.c +++ b/src/code/z_view.c @@ -21,7 +21,7 @@ View* View_New(GraphicsContext* gfxCtx) { View* view = SystemArena_MallocDebug(sizeof(View), "../z_view.c", 285); if (view != NULL) { - __osMemset(view, 0, sizeof(View)); // memset + __osMemset(view, 0, sizeof(View)); View_Init(view, gfxCtx); } diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index 70561ff539a..cd19155d29b 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -192,7 +192,7 @@ void FileChoose_UpdateMainMenu(GameState* thisx) { this->newFileNameCharCount = 0; this->nameEntryBoxPosX = 120; this->nameEntryBoxAlpha = 0; - MemCopy(&this->fileNames[this->buttonIndex][0], &emptyName, 8); + MemCpy(&this->fileNames[this->buttonIndex][0], &emptyName, 8); } else if (this->n64ddFlags[this->buttonIndex] == this->n64ddFlag) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->actionTimer = 8; From c160a555ba06e17df4845c927028fae6649993d7 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 28 Feb 2022 15:14:55 +0000 Subject: [PATCH 07/17] Format --- src/code/__osMemmove.c | 6 ++-- src/code/__osMemset.c | 2 +- src/code/code_80069420.c | 4 +-- src/code/code_801067F0.c | 2 +- src/code/z_lib.c | 2 +- src/code/z_message_PAL.c | 4 +-- src/code/z_sram.c | 63 +++++++++++++++++++--------------------- 7 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/code/__osMemmove.c b/src/code/__osMemmove.c index 721f5a35dcf..01174fd7b2e 100644 --- a/src/code/__osMemmove.c +++ b/src/code/__osMemmove.c @@ -2,13 +2,13 @@ /** * @brief memmove: copies @p size bytes from memory starting at @p src to memory starting at @p dest . - * + * * Unlike @ref memcpy(), the regions of memory may overlap. - * + * * @param[in,out] dest address of start of buffer writing to * @param[in] src address of start of buffer to read from * @param[in] size number of bytes to copy. - * + * * @return dest */ void* __osMemmove(void* dest, const void* src, size_t size) { diff --git a/src/code/__osMemset.c b/src/code/__osMemset.c index f0d44f461c8..885746d67f2 100644 --- a/src/code/__osMemset.c +++ b/src/code/__osMemset.c @@ -3,7 +3,7 @@ /** * @brief memset: sets @p size bytes to @p val starting at address @p dest . * - * There are two other memsets in this codebase, + * There are two other memsets in this codebase, * @sa Lib_MemSet(), MemSet() * This one is used in __osMalloc, z_quake, z_view, and z_camera * diff --git a/src/code/code_80069420.c b/src/code/code_80069420.c index 4dc3862085b..41363687cc7 100644 --- a/src/code/code_80069420.c +++ b/src/code/code_80069420.c @@ -3,11 +3,11 @@ /** * @brief memcpy: copies @p size bytes from memory starting at @p src to memory starting at @p dest . Expects the memory * specified by @p src and @p dest to not overlap. - * + * * @sa libultra also has a memcpy(). * * @param[in,out] dest address of start of buffer writing to - * @param[in] src address of start of buffer to read from + * @param[in] src address of start of buffer to read from * @param[in] size number of bytes to copy. Has to be s32: it is not possible to copy more than 2 GB of RAM at once. * * @return dest diff --git a/src/code/code_801067F0.c b/src/code/code_801067F0.c index 41ac3b1a1f7..69e991113fe 100644 --- a/src/code/code_801067F0.c +++ b/src/code/code_801067F0.c @@ -12,7 +12,7 @@ * * @param x dividend * @param y modulus - * + * * @return f32 0.0f if y is 0.0f, or the x modulo y if */ f32 fmodf(f32 x, f32 y) { diff --git a/src/code/z_lib.c b/src/code/z_lib.c index 76dfdfc74ae..2b1ba595ab4 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -2,7 +2,7 @@ /** * @brief memset: sets @p size bytes to @p val starting at address @p dest . - * + * * Unlike normal memset, * - @p dest is a u8* already, * - does not return @p dest , diff --git a/src/code/z_message_PAL.c b/src/code/z_message_PAL.c index 1b0b3ee6592..69fb1e6d7be 100644 --- a/src/code/z_message_PAL.c +++ b/src/code/z_message_PAL.c @@ -2593,7 +2593,7 @@ void Message_DrawMain(GlobalContext* globalCtx, Gfx** p) { osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("\n====================================================================\n"); MemCpy(gSaveContext.scarecrowCustomSong, gScarecrowCustomSongPtr, - sizeof(gSaveContext.scarecrowCustomSong)); + sizeof(gSaveContext.scarecrowCustomSong)); for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowCustomSong); i++) { osSyncPrintf("%d, ", gSaveContext.scarecrowCustomSong[i]); } @@ -2656,7 +2656,7 @@ void Message_DrawMain(GlobalContext* globalCtx, Gfx** p) { osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("\n====================================================================\n"); MemCpy(gSaveContext.scarecrowSpawnSong, gScarecrowSpawnSongPtr, - sizeof(gSaveContext.scarecrowSpawnSong)); + sizeof(gSaveContext.scarecrowSpawnSong)); for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowSpawnSong); i++) { osSyncPrintf("%d, ", gSaveContext.scarecrowSpawnSong[i]); } diff --git a/src/code/z_sram.c b/src/code/z_sram.c index 36e19a647ff..c679382799f 100644 --- a/src/code/z_sram.c +++ b/src/code/z_sram.c @@ -624,39 +624,36 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s MemCpy(&fileChooseCtx->deaths[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEATHS, sizeof(fileChooseCtx->deaths[0])); MemCpy(&fileChooseCtx->fileNames[0], sramCtx->readBuff + SLOT_OFFSET(0) + NAME, - sizeof(fileChooseCtx->fileNames[0])); + sizeof(fileChooseCtx->fileNames[0])); MemCpy(&fileChooseCtx->fileNames[1], sramCtx->readBuff + SLOT_OFFSET(1) + NAME, - sizeof(fileChooseCtx->fileNames[0])); + sizeof(fileChooseCtx->fileNames[0])); MemCpy(&fileChooseCtx->fileNames[2], sramCtx->readBuff + SLOT_OFFSET(2) + NAME, - sizeof(fileChooseCtx->fileNames[0])); + sizeof(fileChooseCtx->fileNames[0])); MemCpy(&fileChooseCtx->healthCapacities[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH_CAP, - sizeof(fileChooseCtx->healthCapacities[0])); + sizeof(fileChooseCtx->healthCapacities[0])); MemCpy(&fileChooseCtx->healthCapacities[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH_CAP, - sizeof(fileChooseCtx->healthCapacities[0])); + sizeof(fileChooseCtx->healthCapacities[0])); MemCpy(&fileChooseCtx->healthCapacities[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH_CAP, - sizeof(fileChooseCtx->healthCapacities[0])); + sizeof(fileChooseCtx->healthCapacities[0])); MemCpy(&fileChooseCtx->questItems[0], sramCtx->readBuff + SLOT_OFFSET(0) + QUEST, - sizeof(fileChooseCtx->questItems[0])); + sizeof(fileChooseCtx->questItems[0])); MemCpy(&fileChooseCtx->questItems[1], sramCtx->readBuff + SLOT_OFFSET(1) + QUEST, - sizeof(fileChooseCtx->questItems[0])); + sizeof(fileChooseCtx->questItems[0])); MemCpy(&fileChooseCtx->questItems[2], sramCtx->readBuff + SLOT_OFFSET(2) + QUEST, - sizeof(fileChooseCtx->questItems[0])); + sizeof(fileChooseCtx->questItems[0])); MemCpy(&fileChooseCtx->n64ddFlags[0], sramCtx->readBuff + SLOT_OFFSET(0) + N64DD, - sizeof(fileChooseCtx->n64ddFlags[0])); + sizeof(fileChooseCtx->n64ddFlags[0])); MemCpy(&fileChooseCtx->n64ddFlags[1], sramCtx->readBuff + SLOT_OFFSET(1) + N64DD, - sizeof(fileChooseCtx->n64ddFlags[0])); + sizeof(fileChooseCtx->n64ddFlags[0])); MemCpy(&fileChooseCtx->n64ddFlags[2], sramCtx->readBuff + SLOT_OFFSET(2) + N64DD, - sizeof(fileChooseCtx->n64ddFlags[0])); + sizeof(fileChooseCtx->n64ddFlags[0])); - MemCpy(&fileChooseCtx->defense[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEFENSE, - sizeof(fileChooseCtx->defense[0])); - MemCpy(&fileChooseCtx->defense[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEFENSE, - sizeof(fileChooseCtx->defense[0])); - MemCpy(&fileChooseCtx->defense[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEFENSE, - sizeof(fileChooseCtx->defense[0])); + MemCpy(&fileChooseCtx->defense[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEFENSE, sizeof(fileChooseCtx->defense[0])); + MemCpy(&fileChooseCtx->defense[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEFENSE, sizeof(fileChooseCtx->defense[0])); + MemCpy(&fileChooseCtx->defense[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEFENSE, sizeof(fileChooseCtx->defense[0])); MemCpy(&fileChooseCtx->health[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH, sizeof(fileChooseCtx->health[0])); MemCpy(&fileChooseCtx->health[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH, sizeof(fileChooseCtx->health[0])); @@ -740,19 +737,19 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { j = gSramSlotOffsets[gSaveContext.fileNum]; MemCpy(&fileChooseCtx->deaths[gSaveContext.fileNum], sramCtx->readBuff + j + DEATHS, - sizeof(fileChooseCtx->deaths[0])); + sizeof(fileChooseCtx->deaths[0])); MemCpy(&fileChooseCtx->fileNames[gSaveContext.fileNum], sramCtx->readBuff + j + NAME, - sizeof(fileChooseCtx->fileNames[0])); + sizeof(fileChooseCtx->fileNames[0])); MemCpy(&fileChooseCtx->healthCapacities[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH_CAP, - sizeof(fileChooseCtx->healthCapacities[0])); + sizeof(fileChooseCtx->healthCapacities[0])); MemCpy(&fileChooseCtx->questItems[gSaveContext.fileNum], sramCtx->readBuff + j + QUEST, - sizeof(fileChooseCtx->questItems[0])); + sizeof(fileChooseCtx->questItems[0])); MemCpy(&fileChooseCtx->n64ddFlags[gSaveContext.fileNum], sramCtx->readBuff + j + N64DD, - sizeof(fileChooseCtx->n64ddFlags[0])); + sizeof(fileChooseCtx->n64ddFlags[0])); MemCpy(&fileChooseCtx->defense[gSaveContext.fileNum], sramCtx->readBuff + j + DEFENSE, - sizeof(fileChooseCtx->defense[0])); + sizeof(fileChooseCtx->defense[0])); MemCpy(&fileChooseCtx->health[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH, - sizeof(fileChooseCtx->health[0])); + sizeof(fileChooseCtx->health[0])); osSyncPrintf("f_64dd[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->n64ddFlags[gSaveContext.fileNum]); osSyncPrintf("heart_status[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->defense[gSaveContext.fileNum]); @@ -769,7 +766,7 @@ void Sram_EraseSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000) + offset, &gSaveContext, SLOT_SIZE, OS_WRITE); MemCpy(&fileChooseCtx->n64ddFlags[fileChooseCtx->selectedFileIndex], sramCtx->readBuff + offset + N64DD, - sizeof(fileChooseCtx->n64ddFlags[0])); + sizeof(fileChooseCtx->n64ddFlags[0])); offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex + 3]; MemCpy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); @@ -799,19 +796,19 @@ void Sram_CopySave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex]; MemCpy(&fileChooseCtx->deaths[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEATHS, - sizeof(fileChooseCtx->deaths[0])); + sizeof(fileChooseCtx->deaths[0])); MemCpy(&fileChooseCtx->fileNames[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + NAME, - sizeof(fileChooseCtx->fileNames[0])); + sizeof(fileChooseCtx->fileNames[0])); MemCpy(&fileChooseCtx->healthCapacities[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + HEALTH_CAP, - sizeof(fileChooseCtx->healthCapacities[0])); + sizeof(fileChooseCtx->healthCapacities[0])); MemCpy(&fileChooseCtx->questItems[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + QUEST, - sizeof(fileChooseCtx->questItems[0])); + sizeof(fileChooseCtx->questItems[0])); MemCpy(&fileChooseCtx->n64ddFlags[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + N64DD, - sizeof(fileChooseCtx->n64ddFlags[0])); + sizeof(fileChooseCtx->n64ddFlags[0])); MemCpy(&fileChooseCtx->defense[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEFENSE, - sizeof(fileChooseCtx->defense[0])); + sizeof(fileChooseCtx->defense[0])); MemCpy(&fileChooseCtx->health[fileChooseCtx->copyDestFileIndex], (sramCtx->readBuff + offset) + HEALTH, - sizeof(fileChooseCtx->health[0])); + sizeof(fileChooseCtx->health[0])); osSyncPrintf("f_64dd[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->n64ddFlags[gSaveContext.fileNum]); osSyncPrintf("heart_status[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->defense[gSaveContext.fileNum]); From 97f7dadee77f6d354bfe067685b6d63448bade36 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 28 Feb 2022 19:16:59 +0000 Subject: [PATCH 08/17] Sort out some missing sizeofs --- src/code/z_camera.c | 2 +- .../actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c | 40 +++++++++---------- .../actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.h | 7 +++- .../ovl_file_choose/z_file_choose.c | 2 +- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/code/z_camera.c b/src/code/z_camera.c index 85286077c30..bb8c5d55969 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -6793,7 +6793,7 @@ void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, GlobalCon s16 curUID; s16 j; - __osMemset(camera, 0, sizeof(*camera)); + __osMemset(camera, 0, sizeof(Camera)); if (sInitRegs) { for (i = 0; i < sOREGInitCnt; i++) { OREG(i) = sOREGInit[i]; diff --git a/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c b/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c index f13ef94e64d..c53dc1e60b1 100644 --- a/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c +++ b/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c @@ -264,7 +264,7 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) { Vec3f spD4; Vec3f spC8; Vec3f spBC; - u8* temp_s2; + u8* shadowTex; s32 temp_x; s32 temp_z; s32 x; @@ -275,8 +275,8 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) { s32 l; s16 rotY; - temp_s2 = ALIGN16((s32)(&this->shadowTexture)); - Lib_MemSet(temp_s2, 0x1000, 0); + shadowTex = COBRA_SHADOW_TEX_PTR(this); + Lib_MemSet(shadowTex, sizeof(this->shadowTextureBuffer) & ~0xF, 0); Matrix_RotateX((M_PI / 4), MTXMODE_NEW); rotY = !(this->dyna.actor.params & 3) ? (this->dyna.actor.shape.rot.y + 0x4000) @@ -303,7 +303,7 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) { for (l = 0; l < 11; l++) { temp_x = x - 5 + l; if (!(temp_x & ~0x3F)) { - temp_s2[temp_z + temp_x] |= D_8089731C[k][l]; + shadowTex[temp_z + temp_x] |= D_8089731C[k][l]; } if (1) {} } @@ -331,7 +331,7 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) { for (l = 0; l < 3; l++) { temp_x = x - 1 + l; if (!(temp_x & ~0x3F)) { - temp_s2[temp_z + temp_x] |= D_80897398[k][l]; + shadowTex[temp_z + temp_x] |= D_80897398[k][l]; } } } @@ -340,13 +340,13 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) { } for (i = 0; i < 0x40; i++) { - temp_s2[0 * 0x40 + i] = 0; - temp_s2[0x3F * 0x40 + i] = 0; + shadowTex[0 * 0x40 + i] = 0; + shadowTex[0x3F * 0x40 + i] = 0; } for (j = 1; j < 0x3F; j++) { - temp_s2[j * 0x40 + 0] = 0; - temp_s2[j * 0x40 + 0x3F] = 0; + shadowTex[j * 0x40 + 0] = 0; + shadowTex[j * 0x40 + 0x3F] = 0; } if (D_80897398[0][0]) {} } @@ -360,15 +360,15 @@ void BgJyaCobra_UpdateShadowFromTop(BgJyaCobra* this) { s32 j; s32 i_copy; s32 counter; - u8* temp_s0; + u8* shadowTex; u8* sp40; for (i = 0; i < 0x40; i++) { sp58[i] = SQ(i - 31.5f); } - sp40 = temp_s0 = (u8*)ALIGN16((u32)(&this->shadowTexture)); - Lib_MemSet(temp_s0, 0x1000, 0); + sp40 = shadowTex = COBRA_SHADOW_TEX_PTR(this); + Lib_MemSet(shadowTex, sizeof(this->shadowTextureBuffer) & ~0xF, 0); for (i = 0; i != 0x40; i++) { f32 temp_f12 = sp58[i]; @@ -385,12 +385,12 @@ void BgJyaCobra_UpdateShadowFromTop(BgJyaCobra* this) { for (i_copy = 0x780, counter = 0; counter < 4; counter++, i_copy += 0x40) { i = i_copy; for (j = 4; j < 0x3C; j++) { - if (temp_s0[i_copy + j] < D_80897518[counter]) { - temp_s0[i_copy + j] = D_80897518[counter]; + if (shadowTex[i_copy + j] < D_80897518[counter]) { + shadowTex[i_copy + j] = D_80897518[counter]; } } - temp_s0[i + 0x3C] = 0x20; - temp_s0[i + 0x3] = 0x20; + shadowTex[i + 0x3C] = 0x20; + shadowTex[i + 0x3] = 0x20; } } @@ -419,7 +419,7 @@ void BgJyaCobra_Init(Actor* thisx, GlobalContext* globalCtx) { // "(jya cobra)" osSyncPrintf("(jya コブラ)(arg_data 0x%04x)(act %x)(txt %x)(txt16 %x)\n", this->dyna.actor.params, this, - &this->shadowTexture, ALIGN16((s32)(&this->shadowTexture))); + &this->shadowTextureBuffer, COBRA_SHADOW_TEX_PTR(this)); } void BgJyaCobra_Destroy(Actor* thisx, GlobalContext* globalCtx) { @@ -590,9 +590,9 @@ void BgJyaCobra_DrawShadow(BgJyaCobra* this, GlobalContext* globalCtx) { gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_bg_jya_cobra.c", 994), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gDPLoadTextureBlock(POLY_XLU_DISP++, ALIGN16((s32)(&this->shadowTexture)), G_IM_FMT_I, G_IM_SIZ_8b, 0x40, 0x40, 0, - G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, - G_TX_NOLOD); + gDPLoadTextureBlock(POLY_XLU_DISP++, COBRA_SHADOW_TEX_PTR(this), G_IM_FMT_I, G_IM_SIZ_8b, COBRA_SHADOW_TEX_WIDTH, + COBRA_SHADOW_TEX_HEIGHT, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, + G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); gSPDisplayList(POLY_XLU_DISP++, sShadowDL); diff --git a/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.h b/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.h index f9ad1e6c5b1..b7006632f3b 100644 --- a/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.h +++ b/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.h @@ -8,6 +8,11 @@ struct BgJyaCobra; typedef void (*BgJyaCobraActionFunc)(struct BgJyaCobra*, GlobalContext*); +#define COBRA_SHADOW_TEX_WIDTH 64 +#define COBRA_SHADOW_TEX_HEIGHT 64 +#define COBRA_SHADOW_TEX_SIZE (COBRA_SHADOW_TEX_WIDTH * COBRA_SHADOW_TEX_HEIGHT * G_IM_SIZ_8b_BYTES) +#define COBRA_SHADOW_TEX_PTR(this) (u8*)ALIGN16((u32)(&this->shadowTextureBuffer)) + typedef struct BgJyaCobra { /* 0x0000 */ DynaPolyActor dyna; /* 0x0164 */ BgJyaCobraActionFunc actionFunc; @@ -21,7 +26,7 @@ typedef struct BgJyaCobra { /* 0x0180 */ Vec3f unk_180; /* 0x018C */ f32 unk_18C; /* 0x0190 */ f32 unk_190; - /* 0x0194 */ u8 shadowTexture[0x1010]; + /* 0x0194 */ u8 shadowTextureBuffer[COBRA_SHADOW_TEX_SIZE / sizeof(u8) + 0xF]; // Extra space to allow aligning actual texture to 0x10 } BgJyaCobra; // size = 0x11A4 #endif diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index cd19155d29b..4f944d83737 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -192,7 +192,7 @@ void FileChoose_UpdateMainMenu(GameState* thisx) { this->newFileNameCharCount = 0; this->nameEntryBoxPosX = 120; this->nameEntryBoxAlpha = 0; - MemCpy(&this->fileNames[this->buttonIndex][0], &emptyName, 8); + MemCpy(&this->fileNames[this->buttonIndex][0], &emptyName, sizeof(emptyName)); } else if (this->n64ddFlags[this->buttonIndex] == this->n64ddFlag) { Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->actionTimer = 8; From e239738e309ad4e50c8f06f41356821adb92b952 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Mon, 28 Feb 2022 20:15:38 +0000 Subject: [PATCH 09/17] Name fmodf --- Makefile | 2 +- spec | 2 +- src/code/{code_801067F0.c => fmodf.c} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/code/{code_801067F0.c => fmodf.c} (92%) diff --git a/Makefile b/Makefile index 824e7909e1d..d53d97f66cb 100644 --- a/Makefile +++ b/Makefile @@ -186,7 +186,7 @@ build/src/code/fault.o: OPTFLAGS := -O2 -g3 build/src/code/fault_drawer.o: CFLAGS += -trapuv build/src/code/fault_drawer.o: OPTFLAGS := -O2 -g3 build/src/code/ucode_disas.o: OPTFLAGS := -O2 -g3 -build/src/code/code_801067F0.o: OPTFLAGS := -g +build/src/code/fmodf.o: OPTFLAGS := -g build/src/code/__osMemset.o: OPTFLAGS := -g build/src/code/__osMemmove.o: OPTFLAGS := -g diff --git a/spec b/spec index 4b7a6ba4ef9..b5af1449b63 100644 --- a/spec +++ b/spec @@ -509,7 +509,7 @@ beginseg include "build/src/libultra/io/spsetpc.o" include "build/src/libultra/libc/sqrt.o" include "build/src/libultra/libc/absf.o" - include "build/src/code/code_801067F0.o" + include "build/src/code/fmodf.o" include "build/src/code/__osMemset.o" include "build/src/code/__osMemmove.o" include_data_with_rodata "build/src/code/z_message_PAL.o" diff --git a/src/code/code_801067F0.c b/src/code/fmodf.c similarity index 92% rename from src/code/code_801067F0.c rename to src/code/fmodf.c index 69e991113fe..7e690d4feb9 100644 --- a/src/code/code_801067F0.c +++ b/src/code/fmodf.c @@ -13,7 +13,7 @@ * @param x dividend * @param y modulus * - * @return f32 0.0f if y is 0.0f, or the x modulo y if + * @return f32 0.0f if y is 0.0f, or x modulo y otherwise */ f32 fmodf(f32 x, f32 y) { s32 n; From 46d2c8c11b494a09fe7e3aa6da38455ab40c6da1 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Tue, 1 Mar 2022 19:34:01 +0000 Subject: [PATCH 10/17] Rename local variables --- include/functions.h | 10 +++++----- src/code/__osMemmove.c | 22 +++++++++++----------- src/code/__osMemset.c | 12 ++++++------ src/code/code_80069420.c | 28 ++++++++++++++-------------- src/code/z_lib.c | 8 ++++---- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/include/functions.h b/include/functions.h index 7ec3b1e4430..febe242de31 100644 --- a/include/functions.h +++ b/include/functions.h @@ -117,7 +117,7 @@ void osUnmapTLBAll(void); s32 osEPiStartDma(OSPiHandle* handle, OSIoMesg* mb, s32 direction); const char* strchr(const char* str, s32 ch); u32 strlen(const char* str); -void* memcpy(void* dst, const void* src, u32 size); +void* memcpy(void* dst, const void* src, size_t size); void osInvalICache(void* vaddr, s32 nbytes); void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 count); void osInvalDCache(void* vaddr, s32 nbytes); @@ -831,7 +831,7 @@ void func_800645A0(GlobalContext* globalCtx, CutsceneContext* csCtx); void Cutscene_HandleEntranceTriggers(GlobalContext* globalCtx); void Cutscene_HandleConditionalTriggers(GlobalContext* globalCtx); void Cutscene_SetSegment(GlobalContext* globalCtx, void* segment); -void* MemCpy(void* dest, const void* src, s32 size); +void* MemCpy(void* dest, const void* src, s32 len); void GetItem_Draw(GlobalContext* globalCtx, s16 drawId); void SoundSource_InitAll(GlobalContext* globalCtx); void SoundSource_UpdateAll(GlobalContext* globalCtx); @@ -910,7 +910,7 @@ s32 Environment_IsForcedSequenceDisabled(void); void Environment_PlayStormNatureAmbience(GlobalContext* globalCtx); void Environment_StopStormNatureAmbience(GlobalContext* globalCtx); void Environment_WarpSongLeave(GlobalContext* globalCtx); -void Lib_MemSet(u8* dest, size_t size, u8 val); +void Lib_MemSet(u8* dest, size_t len, u8 val); f32 Math_CosS(s16 angle); f32 Math_SinS(s16 angle); s32 Math_ScaledStepToS(s16* pValue, s16 target, s16 step); @@ -2297,8 +2297,8 @@ void guMtxF2L(MtxF* m1, Mtx* m2); u32* osViGetCurrentFramebuffer(void); s32 __osSpSetPc(void* pc); f32 absf(f32); -void* __osMemset(void* ptr, s32 val, size_t size); -void* __osMemmove(void* dest, const void* src, size_t size); +void* __osMemset(void* dest, s32 val, size_t len); +void* __osMemmove(void* dest, const void* src, size_t len); void Message_UpdateOcarinaGame(GlobalContext* globalCtx); u8 Message_ShouldAdvance(GlobalContext* globalCtx); void Message_CloseTextbox(GlobalContext*); diff --git a/src/code/__osMemmove.c b/src/code/__osMemmove.c index 01174fd7b2e..3809e6e3323 100644 --- a/src/code/__osMemmove.c +++ b/src/code/__osMemmove.c @@ -11,22 +11,22 @@ * * @return dest */ -void* __osMemmove(void* dest, const void* src, size_t size) { - u8* destPtr = dest; - const u8* srcPtr = src; +void* __osMemmove(void* dest, const void* src, size_t len) { + u8* d = dest; + const u8* s = src; - if (destPtr == srcPtr) { + if (d == s) { return dest; } - if (destPtr < srcPtr) { - while (size--) { - *destPtr++ = *srcPtr++; + if (d < s) { + while (len--) { + *d++ = *s++; } } else { - destPtr += size - 1; - srcPtr += size - 1; - while (size--) { - *destPtr-- = *srcPtr--; + d += len - 1; + s += len - 1; + while (len--) { + *d-- = *s--; } } return dest; diff --git a/src/code/__osMemset.c b/src/code/__osMemset.c index 885746d67f2..96723540723 100644 --- a/src/code/__osMemset.c +++ b/src/code/__osMemset.c @@ -1,7 +1,7 @@ #include "global.h" /** - * @brief memset: sets @p size bytes to @p val starting at address @p dest . + * @brief memset: sets @p len bytes to @p val starting at address @p dest . * * There are two other memsets in this codebase, * @sa Lib_MemSet(), MemSet() @@ -9,15 +9,15 @@ * * @param[in,out] dest address to start at * @param[in] val value to write (s32, but interpreted as u8) - * @param[in] size number of bytes to write + * @param[in] len number of bytes to write * * @return dest */ -void* __osMemset(void* dest, s32 val, size_t size) { - u8* destu = dest; +void* __osMemset(void* dest, s32 val, size_t len) { + u8* ptr = dest; - while (size--) { - *destu++ = val; + while (len--) { + *ptr++ = val; } return dest; } diff --git a/src/code/code_80069420.c b/src/code/code_80069420.c index 41363687cc7..244533c56b8 100644 --- a/src/code/code_80069420.c +++ b/src/code/code_80069420.c @@ -1,31 +1,31 @@ #include "global.h" /** - * @brief memcpy: copies @p size bytes from memory starting at @p src to memory starting at @p dest . Expects the memory + * @brief memcpy: copies @p len bytes from memory starting at @p src to memory starting at @p dest . Expects the memory * specified by @p src and @p dest to not overlap. * * @sa libultra also has a memcpy(). * * @param[in,out] dest address of start of buffer writing to * @param[in] src address of start of buffer to read from - * @param[in] size number of bytes to copy. Has to be s32: it is not possible to copy more than 2 GB of RAM at once. + * @param[in] len number of bytes to copy. Has to be s32: it is not possible to copy more than 2 GB of RAM at once. * * @return dest */ -void* MemCpy(void* dest, const void* src, s32 size) { - u8* destPtr = dest; - const u8* srcPtr = src; +void* MemCpy(void* dest, const void* src, s32 len) { + u8* d = dest; + const u8* s = src; - while (size > 0) { - *destPtr++ = *srcPtr++; - size--; + while (len > 0) { + *d++ = *s++; + len--; } return dest; } /** - * @brief memset: sets @p size bytes to @p val starting at address @p dest . + * @brief memset: sets @p len bytes to @p val starting at address @p dest . * * There are two other memsets in this codebase, * @sa Lib_MemSet(), __osMemSet() @@ -33,16 +33,16 @@ void* MemCpy(void* dest, const void* src, s32 size) { * * @param[in,out] dest address to start at * @param[in] val value to write (s32, but interpreted as u8) - * @param[in] size number of bytes to write. Has to be s32: it is not possible to set more than 2 GB of RAM at once. + * @param[in] len number of bytes to write. Has to be s32: it is not possible to set more than 2 GB of RAM at once. * * @return dest */ -void* MemSet(void* dest, s32 val, s32 size) { - u8* destPtr = dest; - s32 s = size; +void* MemSet(void* dest, s32 val, s32 len) { + u8* d = dest; + s32 s = len; while (s > 0) { - *destPtr++ = val; + *d++ = val; s--; } diff --git a/src/code/z_lib.c b/src/code/z_lib.c index 2b1ba595ab4..ca8d76da006 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -1,7 +1,7 @@ #include "global.h" /** - * @brief memset: sets @p size bytes to @p val starting at address @p dest . + * @brief memset: sets @p len bytes to @p val starting at address @p dest . * * Unlike normal memset, * - @p dest is a u8* already, @@ -14,14 +14,14 @@ * This one is used in z_actor and certain actors. * * @param[in,out] dest address to start at - * @param[in] size number of bytes to write + * @param[in] len number of bytes to write * @param[in] val value to write */ -void Lib_MemSet(u8* dest, size_t size, u8 val) { +void Lib_MemSet(u8* dest, size_t len, u8 val) { size_t i; // clang-format off - for (i = 0; i < size; i++) { *dest++ = val; } + for (i = 0; i < len; i++) { *dest++ = val; } // clang-format on } From 6101e8c046bc6902435cc5120e1fbdd26fc8c98b Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Tue, 1 Mar 2022 19:46:25 +0000 Subject: [PATCH 11/17] size_t --- src/libultra/libc/string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libultra/libc/string.c b/src/libultra/libc/string.c index bf059094f77..37091ab83aa 100644 --- a/src/libultra/libc/string.c +++ b/src/libultra/libc/string.c @@ -21,7 +21,7 @@ u32 strlen(const char* str) { return ptr - str; } -void* memcpy(void* dst, const void* src, u32 size) { +void* memcpy(void* dst, const void* src, size_t size) { u8* _dst = dst; const u8* _src = src; From 4a78ba027bec9af595f3a3b28a705c573323b381 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Sun, 6 Mar 2022 05:48:07 +0000 Subject: [PATCH 12/17] Use COBRA_SHADOW_TEX_SIZE --- src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c b/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c index c53dc1e60b1..7a011c6cf81 100644 --- a/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c +++ b/src/overlays/actors/ovl_Bg_Jya_Cobra/z_bg_jya_cobra.c @@ -276,7 +276,7 @@ void BgJyaCobra_UpdateShadowFromSide(BgJyaCobra* this) { s16 rotY; shadowTex = COBRA_SHADOW_TEX_PTR(this); - Lib_MemSet(shadowTex, sizeof(this->shadowTextureBuffer) & ~0xF, 0); + Lib_MemSet(shadowTex, COBRA_SHADOW_TEX_SIZE, 0); Matrix_RotateX((M_PI / 4), MTXMODE_NEW); rotY = !(this->dyna.actor.params & 3) ? (this->dyna.actor.shape.rot.y + 0x4000) @@ -368,7 +368,7 @@ void BgJyaCobra_UpdateShadowFromTop(BgJyaCobra* this) { } sp40 = shadowTex = COBRA_SHADOW_TEX_PTR(this); - Lib_MemSet(shadowTex, sizeof(this->shadowTextureBuffer) & ~0xF, 0); + Lib_MemSet(shadowTex, COBRA_SHADOW_TEX_SIZE, 0); for (i = 0; i != 0x40; i++) { f32 temp_f12 = sp58[i]; From 05cdded78cd2e63654d495efdb6188b7f533f732 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Wed, 9 Mar 2022 17:11:54 +0000 Subject: [PATCH 13/17] Review --- src/code/__osMemset.c | 1 - src/code/code_80069420.c | 4 ++-- src/code/z_lib.c | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/code/__osMemset.c b/src/code/__osMemset.c index 96723540723..197925970e4 100644 --- a/src/code/__osMemset.c +++ b/src/code/__osMemset.c @@ -5,7 +5,6 @@ * * There are two other memsets in this codebase, * @sa Lib_MemSet(), MemSet() - * This one is used in __osMalloc, z_quake, z_view, and z_camera * * @param[in,out] dest address to start at * @param[in] val value to write (s32, but interpreted as u8) diff --git a/src/code/code_80069420.c b/src/code/code_80069420.c index 244533c56b8..07442bd1c17 100644 --- a/src/code/code_80069420.c +++ b/src/code/code_80069420.c @@ -8,7 +8,7 @@ * * @param[in,out] dest address of start of buffer writing to * @param[in] src address of start of buffer to read from - * @param[in] len number of bytes to copy. Has to be s32: it is not possible to copy more than 2 GB of RAM at once. + * @param[in] len number of bytes to copy. (s32 rather than the standard size_t) * * @return dest */ @@ -33,7 +33,7 @@ void* MemCpy(void* dest, const void* src, s32 len) { * * @param[in,out] dest address to start at * @param[in] val value to write (s32, but interpreted as u8) - * @param[in] len number of bytes to write. Has to be s32: it is not possible to set more than 2 GB of RAM at once. + * @param[in] len number of bytes to write. (s32 rather than the standard size_t) * * @return dest */ diff --git a/src/code/z_lib.c b/src/code/z_lib.c index ca8d76da006..8fab0c5b62b 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -11,7 +11,6 @@ * * There are two other memsets in this codebase, * @sa __osMemset(), MemSet() - * This one is used in z_actor and certain actors. * * @param[in,out] dest address to start at * @param[in] len number of bytes to write From 25a21a209fd90170fb338060b775c3bd3a194833 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Sun, 1 May 2022 02:07:22 +0100 Subject: [PATCH 14/17] Tweak the Doxyfile to remove @brief requirement --- Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doxyfile b/Doxyfile index 8d98f6bf9b2..08b276377fb 100644 --- a/Doxyfile +++ b/Doxyfile @@ -187,7 +187,7 @@ SHORT_NAMES = NO # description.) # The default value is: NO. -JAVADOC_AUTOBRIEF = NO +JAVADOC_AUTOBRIEF = YES # If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first # line (until the first dot) of a Qt-style comment as the brief description. If From 9234dc469186d76906e0c00b7e2b81e540dfcbe8 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Sun, 1 May 2022 02:08:40 +0100 Subject: [PATCH 15/17] Roman's review --- src/code/__osMemmove.c | 10 +++++----- src/code/__osMemset.c | 11 +++++------ src/code/code_80069420.c | 23 +++++++++++------------ src/code/z_lib.c | 17 ++++++++--------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/code/__osMemmove.c b/src/code/__osMemmove.c index 3809e6e3323..892fee5eeb5 100644 --- a/src/code/__osMemmove.c +++ b/src/code/__osMemmove.c @@ -1,13 +1,13 @@ #include "global.h" /** - * @brief memmove: copies @p size bytes from memory starting at @p src to memory starting at @p dest . + * memmove: copies `len` bytes from memory starting at `src` to memory starting at `dest`. * - * Unlike @ref memcpy(), the regions of memory may overlap. + * Unlike memcpy(), the regions of memory may overlap. * - * @param[in,out] dest address of start of buffer writing to - * @param[in] src address of start of buffer to read from - * @param[in] size number of bytes to copy. + * @param dest address of start of buffer to write to + * @param src address of start of buffer to read from + * @param len number of bytes to copy. * * @return dest */ diff --git a/src/code/__osMemset.c b/src/code/__osMemset.c index 197925970e4..703d3a8c1e3 100644 --- a/src/code/__osMemset.c +++ b/src/code/__osMemset.c @@ -1,14 +1,13 @@ #include "global.h" /** - * @brief memset: sets @p len bytes to @p val starting at address @p dest . + * memset: sets `len` bytes to `val` starting at address `dest`. * - * There are two other memsets in this codebase, - * @sa Lib_MemSet(), MemSet() + * @see There are two other memsets in this codebase, Lib_MemSet(), MemSet() * - * @param[in,out] dest address to start at - * @param[in] val value to write (s32, but interpreted as u8) - * @param[in] len number of bytes to write + * @param dest address to start at + * @param val value to write (s32, but interpreted as u8) + * @param len number of bytes to write * * @return dest */ diff --git a/src/code/code_80069420.c b/src/code/code_80069420.c index 07442bd1c17..6dd0a94f422 100644 --- a/src/code/code_80069420.c +++ b/src/code/code_80069420.c @@ -1,14 +1,14 @@ #include "global.h" /** - * @brief memcpy: copies @p len bytes from memory starting at @p src to memory starting at @p dest . Expects the memory - * specified by @p src and @p dest to not overlap. + * memcpy: copies `len` bytes from memory starting at `src` to memory starting at `dest`. Expects the memory + * specified by `src` and `dest` to not overlap. * - * @sa libultra also has a memcpy(). + * @see libultra also has a memcpy(). * - * @param[in,out] dest address of start of buffer writing to - * @param[in] src address of start of buffer to read from - * @param[in] len number of bytes to copy. (s32 rather than the standard size_t) + * @param dest address of start of buffer writing to + * @param src address of start of buffer to read from + * @param len number of bytes to copy. (`s32` rather than the standard `size_t`) * * @return dest */ @@ -25,15 +25,14 @@ void* MemCpy(void* dest, const void* src, s32 len) { } /** - * @brief memset: sets @p len bytes to @p val starting at address @p dest . + * memset: sets `len` bytes to `val` starting at address `dest`. * - * There are two other memsets in this codebase, - * @sa Lib_MemSet(), __osMemSet() + * @see There are two other memsets in this codebase, Lib_MemSet(), __osMemset(). * This one is unused. * - * @param[in,out] dest address to start at - * @param[in] val value to write (s32, but interpreted as u8) - * @param[in] len number of bytes to write. (s32 rather than the standard size_t) + * @param dest address to start at + * @param val value to write (`s32`, but interpreted as `u8`) + * @param len number of bytes to write. (`s32` rather than the standard `size_t`) * * @return dest */ diff --git a/src/code/z_lib.c b/src/code/z_lib.c index 57abee87d9d..524d58a0aaf 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -1,20 +1,19 @@ #include "global.h" /** - * @brief memset: sets @p len bytes to @p val starting at address @p dest . + * memset: sets `len` bytes to `val` starting at address `dest`. * * Unlike normal memset, - * - @p dest is a u8* already, - * - does not return @p dest , + * - `dest` is a `u8*` already, + * - does not return `dest`, * - the arguments are in a different order, - * - @p val is a u8 instead of the standard s32. + * - `val` is a `u8` instead of the standard `s32`. * - * There are two other memsets in this codebase, - * @sa __osMemset(), MemSet() + * @see There are two other memsets in this codebase, __osMemset(), MemSet() * - * @param[in,out] dest address to start at - * @param[in] len number of bytes to write - * @param[in] val value to write + * @param dest address to start at + * @param len number of bytes to write + * @param val value to write */ void Lib_MemSet(u8* dest, size_t len, u8 val) { size_t i; From a2f952b0254968937ac2a8c1c9f9774dd83a7bb5 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Sun, 1 May 2022 03:05:59 +0100 Subject: [PATCH 16/17] Fix a bug comment --- src/code/audio_heap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/audio_heap.c b/src/code/audio_heap.c index 4ba1cff41aa..3dc51979c50 100644 --- a/src/code/audio_heap.c +++ b/src/code/audio_heap.c @@ -1021,7 +1021,7 @@ void* AudioHeap_AllocPermanent(s32 tableType, s32 id, u32 size) { gAudioContext.permanentCache[index].size = size; //! @bug UB: missing return. "ret" is in v0 at this point, but doing an - // explicit return uses an additional register. + //! explicit return uses an additional register. #ifdef AVOID_UB return ret; #endif From a2b3ff95031205936eca67c8b14368699d805200 Mon Sep 17 00:00:00 2001 From: Elliptic Ellipsis Date: Sun, 1 May 2022 14:53:00 +0100 Subject: [PATCH 17/17] Change fmodf --- src/code/fmodf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/fmodf.c b/src/code/fmodf.c index fcff45a1d35..e1e38622314 100644 --- a/src/code/fmodf.c +++ b/src/code/fmodf.c @@ -1,7 +1,7 @@ #include "global.h" /** - * @brief Computes one @p x modulo @p y for floats. + * Computes one `x` modulo `y` for floats. * * Acts like the standard C fmodf except does not handle Infinity. See https://en.cppreference.com/w/c/numeric/math/fmod * for the details. It summarizes this function as follows: