summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
Diffstat (limited to 'src/code')
-rw-r--r--src/code/PreRender.c4
-rw-r--r--src/code/TwoHeadArena.c1
-rw-r--r--src/code/__osMalloc.c340
-rw-r--r--src/code/audioMgr.c11
-rw-r--r--src/code/audio_playback.c7
-rw-r--r--src/code/audio_seqplayer.c34
-rw-r--r--src/code/code_800430A0.c2
-rw-r--r--src/code/code_80043480.c31
-rw-r--r--src/code/code_8006BA00.c8
-rw-r--r--src/code/code_8008E6A0.c2
-rw-r--r--src/code/code_80097A00.c4
-rw-r--r--src/code/code_800A9D40.c14
-rw-r--r--src/code/code_800A9F30.c10
-rw-r--r--src/code/code_800ACE70.c4
-rw-r--r--src/code/code_800AD920.c11
-rw-r--r--src/code/code_800C3C20.c2
-rw-r--r--src/code/code_800D2E30.c11
-rw-r--r--src/code/code_800D31A0.c8
-rw-r--r--src/code/code_800FC620.c12
-rw-r--r--src/code/code_800FD970.c8
-rw-r--r--src/code/code_801068B0.c7
-rw-r--r--src/code/db_camera.c5
-rw-r--r--src/code/debug_malloc.c31
-rw-r--r--src/code/fault.c14
-rw-r--r--src/code/fault_drawer.c12
-rw-r--r--src/code/flg_set.c2
-rw-r--r--src/code/game.c19
-rw-r--r--src/code/gamealloc.c15
-rw-r--r--src/code/gfxprint.c2
-rw-r--r--src/code/graph.c41
-rw-r--r--src/code/irqmgr.c42
-rw-r--r--src/code/jpegdecoder.c6
-rw-r--r--src/code/jpegutils.c12
-rw-r--r--src/code/listalloc.c23
-rw-r--r--src/code/loadfragment2.c4
-rw-r--r--src/code/main.c8
-rw-r--r--src/code/mempak.c38
-rw-r--r--src/code/padmgr.c235
-rw-r--r--src/code/padsetup.c1
-rw-r--r--src/code/padutils.c11
-rw-r--r--src/code/printutils.c8
-rw-r--r--src/code/relocation.c3
-rw-r--r--src/code/sched.c46
-rw-r--r--src/code/shrink_window.c2
-rw-r--r--src/code/speed_meter.c8
-rw-r--r--src/code/sys_cfb.c1
-rw-r--r--src/code/sys_math.c2
-rw-r--r--src/code/sys_math3d.c2
-rw-r--r--src/code/sys_math_atan.c4
-rw-r--r--src/code/sys_matrix.c18
-rw-r--r--src/code/sys_ucode.c8
-rw-r--r--src/code/system_malloc.c31
-rw-r--r--src/code/z_actor.c27
-rw-r--r--src/code/z_actor_dlftbls.c2
-rw-r--r--src/code/z_bgcheck.c164
-rw-r--r--src/code/z_camera.c32
-rw-r--r--src/code/z_collision_check.c8
-rw-r--r--src/code/z_debug.c15
-rw-r--r--src/code/z_demo.c2
-rw-r--r--src/code/z_eff_shield_particle.c13
-rw-r--r--src/code/z_eff_spark.c8
-rw-r--r--src/code/z_effect.c6
-rw-r--r--src/code/z_effect_soft_sprite.c3
-rw-r--r--src/code/z_effect_soft_sprite_old_init.c11
-rw-r--r--src/code/z_elf_message.c9
-rw-r--r--src/code/z_en_a_keep.c11
-rw-r--r--src/code/z_en_item00.c52
-rw-r--r--src/code/z_fbdemo.c5
-rw-r--r--src/code/z_fbdemo_circle.c41
-rw-r--r--src/code/z_fbdemo_fade.c38
-rw-r--r--src/code/z_fbdemo_triforce.c44
-rw-r--r--src/code/z_fbdemo_wipe1.c38
-rw-r--r--src/code/z_fcurve_data_skelanime.c7
-rw-r--r--src/code/z_horse.c22
-rw-r--r--src/code/z_jpeg.c34
-rw-r--r--src/code/z_kaleido_manager.c14
-rw-r--r--src/code/z_lib.c17
-rw-r--r--src/code/z_lifemeter.c1
-rw-r--r--src/code/z_malloc.c24
-rw-r--r--src/code/z_map_exp.c11
-rw-r--r--src/code/z_map_mark.c5
-rw-r--r--src/code/z_msgevent.c2
-rw-r--r--src/code/z_olib.c13
-rw-r--r--src/code/z_parameter.c40
-rw-r--r--src/code/z_play.c8
-rw-r--r--src/code/z_player_call.c2
-rw-r--r--src/code/z_player_lib.c21
-rw-r--r--src/code/z_prenmi.c6
-rw-r--r--src/code/z_prenmi_buff.c1
-rw-r--r--src/code/z_quake.c27
-rw-r--r--src/code/z_room.c4
-rw-r--r--src/code/z_sample.c7
-rw-r--r--src/code/z_scene.c28
-rw-r--r--src/code/z_scene_table.c27
-rw-r--r--src/code/z_skelanime.c12
-rw-r--r--src/code/z_skin_matrix.c35
-rw-r--r--src/code/z_ss_sram.c6
-rw-r--r--src/code/z_view.c18
-rw-r--r--src/code/z_vismono.c13
99 files changed, 994 insertions, 1125 deletions
diff --git a/src/code/PreRender.c b/src/code/PreRender.c
index 8252572ce..b5ed96604 100644
--- a/src/code/PreRender.c
+++ b/src/code/PreRender.c
@@ -276,9 +276,7 @@ void func_800C1F20(PreRenderContext* this, Gfx** gfxp) {
}
void func_800C1FA4(PreRenderContext* this, Gfx** gfxp) {
- Gfx* gfx;
-
- gfx = *gfxp;
+ Gfx* gfx = *gfxp;
gDPPipeSync(gfx++);
gDPSetBlendColor(gfx++, 255, 255, 255, 8);
diff --git a/src/code/TwoHeadArena.c b/src/code/TwoHeadArena.c
index 5a3fadc16..fc347c494 100644
--- a/src/code/TwoHeadArena.c
+++ b/src/code/TwoHeadArena.c
@@ -78,6 +78,7 @@ void* THA_GetTail(TwoHeadArena* tha) {
void* THA_AllocStart(TwoHeadArena* tha, u32 size) {
void* start = tha->head;
+
tha->head = (u32)tha->head + size;
return start;
}
diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c
index 5a304171b..089ee5975 100644
--- a/src/code/__osMalloc.c
+++ b/src/code/__osMalloc.c
@@ -68,44 +68,39 @@ void ArenaImpl_Unlock(Arena* arena) {
}
ArenaNode* ArenaImpl_GetNextBlock(ArenaNode* node) {
- ArenaNode* ret;
+ ArenaNode* next = node->next;
- ret = node->next;
- if (ret && (!ret || (ret->magic != NODE_MAGIC))) {
- osSyncPrintf(VT_COL(RED, WHITE) "緊急事態!メモリリーク発見! (block=%08x)\n" VT_RST, ret);
- ret = NULL;
+ if (next != NULL && (next == NULL || (next->magic != NODE_MAGIC))) {
+ osSyncPrintf(VT_COL(RED, WHITE) "緊急事態!メモリリーク発見! (block=%08x)\n" VT_RST, next);
+ next = NULL;
node->next = NULL;
}
-
- return ret;
+ return next;
}
ArenaNode* ArenaImpl_GetPrevBlock(ArenaNode* node) {
- ArenaNode* ret;
+ ArenaNode* prev = node->prev;
- ret = node->prev;
- if (ret && (!ret || (ret->magic != NODE_MAGIC))) {
- osSyncPrintf(VT_COL(RED, WHITE) "緊急事態!メモリリーク発見! (block=%08x)\n" VT_RST, ret);
- ret = NULL;
+ if (prev != NULL && (prev == NULL || (prev->magic != NODE_MAGIC))) {
+ osSyncPrintf(VT_COL(RED, WHITE) "緊急事態!メモリリーク発見! (block=%08x)\n" VT_RST, prev);
+ prev = NULL;
node->prev = NULL;
}
-
- return ret;
+ return prev;
}
ArenaNode* ArenaImpl_GetLastBlock(Arena* arena) {
- ArenaNode* ret = NULL;
+ ArenaNode* last = NULL;
ArenaNode* iter;
- if (arena && arena->head && arena->head->magic == NODE_MAGIC) {
+ if (arena != NULL && arena->head != NULL && arena->head->magic == NODE_MAGIC) {
iter = arena->head;
- while (iter) {
- ret = iter;
+ while (iter != NULL) {
+ last = iter;
iter = ArenaImpl_GetNextBlock(iter);
}
}
-
- return ret;
+ return last;
}
void __osMallocInit(Arena* arena, void* start, u32 size) {
@@ -121,10 +116,11 @@ void __osMallocAddBlock(Arena* arena, void* start, s32 size) {
ArenaNode* firstNode;
ArenaNode* lastNode;
- if (start) {
+ if (start != NULL) {
firstNode = (ArenaNode*)ALIGN16((u32)start);
diff = (s32)firstNode - (s32)start;
size2 = (size - diff) & ~0xF;
+
if (size2 > (s32)sizeof(ArenaNode)) {
func_80106860(firstNode, BLOCK_UNINIT_MAGIC, size2); // memset
firstNode->next = NULL;
@@ -134,7 +130,7 @@ void __osMallocAddBlock(Arena* arena, void* start, s32 size) {
firstNode->magic = NODE_MAGIC;
ArenaImpl_Lock(arena);
lastNode = ArenaImpl_GetLastBlock(arena);
- if (!lastNode) {
+ if (lastNode == NULL) {
arena->head = firstNode;
arena->start = start;
} else {
@@ -151,8 +147,9 @@ void ArenaImpl_RemoveAllBlocks(Arena* arena) {
ArenaNode* next;
ArenaImpl_Lock(arena);
+
iter = arena->head;
- while (iter) {
+ while (iter != NULL) {
next = ArenaImpl_GetNextBlock(iter);
func_80106860(iter, BLOCK_UNINIT_MAGIC, iter->size + sizeof(ArenaNode)); // memset
iter = next;
@@ -171,17 +168,16 @@ u8 __osMallocIsInitalized(Arena* arena) {
}
void __osMalloc_FreeBlockTest(Arena* arena, ArenaNode* node) {
- ArenaNode* node2;
+ ArenaNode* node2 = node;
u32* start;
u32* end;
u32* iter;
- node2 = node;
-
if (__osMalloc_FreeBlockTest_Enable) {
start = (u32*)((u32)node + sizeof(ArenaNode));
end = (u32*)((u32)start + node2->size);
iter = start;
+
while (iter < end) {
if (*iter != BLOCK_UNINIT_MAGIC_32 && *iter != BLOCK_FREE_MAGIC_32) {
osSyncPrintf(
@@ -199,15 +195,14 @@ void* __osMalloc_NoLockDebug(Arena* arena, u32 size, const char* file, s32 line)
ArenaNode* iter;
u32 blockSize;
ArenaNode* newNode;
- void* ret;
+ void* alloc = NULL;
ArenaNode* next;
- ret = NULL;
iter = arena->head;
size = ALIGN16(size);
blockSize = ALIGN16(size) + sizeof(ArenaNode);
- while (iter) {
+ while (iter != NULL) {
if (iter->isFree && iter->size >= size) {
if (arena->flag & CHECK_FREE_BLOCK) {
__osMalloc_FreeBlockTest(arena, iter);
@@ -231,9 +226,9 @@ void* __osMalloc_NoLockDebug(Arena* arena, u32 size, const char* file, s32 line)
iter->isFree = false;
ArenaImpl_SetDebugInfo(iter, file, line, arena);
- ret = (void*)((u32)iter + sizeof(ArenaNode));
+ alloc = (void*)((u32)iter + sizeof(ArenaNode));
if (arena->flag & FILL_ALLOCBLOCK) {
- func_80106860(ret, BLOCK_ALLOC_MAGIC, size);
+ func_80106860(alloc, BLOCK_ALLOC_MAGIC, size);
}
break;
@@ -242,15 +237,17 @@ void* __osMalloc_NoLockDebug(Arena* arena, u32 size, const char* file, s32 line)
iter = ArenaImpl_GetNextBlock(iter);
}
- return ret;
+ return alloc;
}
void* __osMallocDebug(Arena* arena, u32 size, const char* file, s32 line) {
- void* ret;
+ void* alloc;
+
ArenaImpl_Lock(arena);
- ret = __osMalloc_NoLockDebug(arena, size, file, line);
+ alloc = __osMalloc_NoLockDebug(arena, size, file, line);
ArenaImpl_Unlock(arena);
- return ret;
+
+ return alloc;
}
void* __osMallocRDebug(Arena* arena, u32 size, const char* file, s32 line) {
@@ -258,14 +255,13 @@ void* __osMallocRDebug(Arena* arena, u32 size, const char* file, s32 line) {
ArenaNode* newNode;
u32 blockSize;
ArenaNode* next;
- void* ret;
+ void* allocR = NULL;
- ret = NULL;
size = ALIGN16(size);
ArenaImpl_Lock(arena);
iter = ArenaImpl_GetLastBlock(arena);
- while (iter) {
+ while (iter != NULL) {
if (iter->isFree && iter->size >= size) {
if (arena->flag & CHECK_FREE_BLOCK) {
__osMalloc_FreeBlockTest(arena, iter);
@@ -285,15 +281,14 @@ void* __osMallocRDebug(Arena* arena, u32 size, const char* file, s32 line) {
if (next) {
next->prev = newNode;
}
-
iter = newNode;
}
iter->isFree = false;
ArenaImpl_SetDebugInfo(iter, file, line, arena);
- ret = (void*)((u32)iter + sizeof(ArenaNode));
+ allocR = (void*)((u32)iter + sizeof(ArenaNode));
if (arena->flag & FILL_ALLOCBLOCK) {
- func_80106860(ret, BLOCK_ALLOC_MAGIC, size);
+ func_80106860(allocR, BLOCK_ALLOC_MAGIC, size);
}
break;
@@ -301,24 +296,23 @@ void* __osMallocRDebug(Arena* arena, u32 size, const char* file, s32 line) {
iter = ArenaImpl_GetPrevBlock(iter);
}
-
ArenaImpl_Unlock(arena);
- return ret;
+
+ return allocR;
}
void* __osMalloc_NoLock(Arena* arena, u32 size) {
ArenaNode* iter;
u32 blockSize;
ArenaNode* newNode;
- void* ret;
+ void* alloc = NULL;
ArenaNode* next;
- ret = NULL;
iter = arena->head;
size = ALIGN16(size);
blockSize = ALIGN16(size) + sizeof(ArenaNode);
- while (iter) {
+ while (iter != NULL) {
if (iter->isFree && iter->size >= size) {
if (arena->flag & CHECK_FREE_BLOCK) {
@@ -343,26 +337,27 @@ void* __osMalloc_NoLock(Arena* arena, u32 size) {
iter->isFree = false;
ArenaImpl_SetDebugInfo(iter, NULL, 0, arena);
- ret = (void*)((u32)iter + sizeof(ArenaNode));
+ alloc = (void*)((u32)iter + sizeof(ArenaNode));
if (arena->flag & FILL_ALLOCBLOCK) {
- func_80106860(ret, BLOCK_ALLOC_MAGIC, size);
+ func_80106860(alloc, BLOCK_ALLOC_MAGIC, size);
}
-
break;
}
iter = ArenaImpl_GetNextBlock(iter);
}
- return ret;
+ return alloc;
}
void* __osMalloc(Arena* arena, u32 size) {
- void* ret;
+ void* alloc;
+
ArenaImpl_Lock(arena);
- ret = __osMalloc_NoLock(arena, size);
+ alloc = __osMalloc_NoLock(arena, size);
ArenaImpl_Unlock(arena);
- return ret;
+
+ return alloc;
}
void* __osMallocR(Arena* arena, u32 size) {
@@ -370,14 +365,13 @@ void* __osMallocR(Arena* arena, u32 size) {
ArenaNode* newNode;
u32 blockSize;
ArenaNode* next;
- void* ret;
+ void* alloc = NULL;
- ret = NULL;
size = ALIGN16(size);
ArenaImpl_Lock(arena);
iter = ArenaImpl_GetLastBlock(arena);
- while (iter) {
+ while (iter != NULL) {
if (iter->isFree && iter->size >= size) {
if (arena->flag & CHECK_FREE_BLOCK) {
__osMalloc_FreeBlockTest(arena, iter);
@@ -397,25 +391,22 @@ void* __osMallocR(Arena* arena, u32 size) {
if (next) {
next->prev = newNode;
}
-
iter = newNode;
}
iter->isFree = false;
ArenaImpl_SetDebugInfo(iter, NULL, 0, arena);
- ret = (void*)((u32)iter + sizeof(ArenaNode));
+ alloc = (void*)((u32)iter + sizeof(ArenaNode));
if (arena->flag & FILL_ALLOCBLOCK) {
- func_80106860(ret, BLOCK_ALLOC_MAGIC, size);
+ func_80106860(alloc, BLOCK_ALLOC_MAGIC, size);
}
-
break;
}
-
iter = ArenaImpl_GetPrevBlock(iter);
}
-
ArenaImpl_Unlock(arena);
- return ret;
+
+ return alloc;
}
void __osFree_NoLock(Arena* arena, void* ptr) {
@@ -424,56 +415,59 @@ void __osFree_NoLock(Arena* arena, void* ptr) {
ArenaNode* prev;
ArenaNode* newNext;
- if (ptr) {
- node = (ArenaNode*)((u32)ptr - sizeof(ArenaNode));
- if (node == NULL || node->magic != NODE_MAGIC) {
- osSyncPrintf(VT_COL(RED, WHITE) "__osFree:不正解放(%08x)\n" VT_RST,
- ptr); // __osFree: Unauthorized release (%08x)
- return;
- }
- if (node->isFree) {
- osSyncPrintf(VT_COL(RED, WHITE) "__osFree:二重解放(%08x)\n" VT_RST, ptr); // __osFree: Double release (%08x)
- return;
- }
- if (arena != node->arena && arena != NULL) {
- // __osFree:Tried to release in a different way than when it was secured (%08x:%08x)
- osSyncPrintf(VT_COL(RED, WHITE) "__osFree:確保時と違う方法で解放しようとした (%08x:%08x)\n" VT_RST, arena,
- node->arena);
- return;
+ if (ptr == NULL) {
+ return;
+ }
+
+ node = (ArenaNode*)((u32)ptr - sizeof(ArenaNode));
+ if (node == NULL || node->magic != NODE_MAGIC) {
+ osSyncPrintf(VT_COL(RED, WHITE) "__osFree:不正解放(%08x)\n" VT_RST,
+ ptr); // __osFree: Unauthorized release (%08x)
+ return;
+ }
+ if (node->isFree) {
+ osSyncPrintf(VT_COL(RED, WHITE) "__osFree:二重解放(%08x)\n" VT_RST, ptr); // __osFree: Double release (%08x)
+ return;
+ }
+ if (arena != node->arena && arena != NULL) {
+ // __osFree:Tried to release in a different way than when it was secured (%08x:%08x)
+ osSyncPrintf(VT_COL(RED, WHITE) "__osFree:確保時と違う方法で解放しようとした (%08x:%08x)\n" VT_RST, arena,
+ node->arena);
+ return;
+ }
+
+ next = ArenaImpl_GetNextBlock(node);
+ prev = ArenaImpl_GetPrevBlock(node);
+ node->isFree = true;
+ ArenaImpl_SetDebugInfo(node, NULL, 0, arena);
+
+ if (arena->flag & FILL_FREEBLOCK) {
+ func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size);
+ }
+
+ newNext = next;
+ if ((u32)next == (u32)node + sizeof(ArenaNode) + node->size && next->isFree) {
+ newNext = ArenaImpl_GetNextBlock(next);
+ if (newNext != NULL) {
+ newNext->prev = node;
}
- next = ArenaImpl_GetNextBlock(node);
- prev = ArenaImpl_GetPrevBlock(node);
- node->isFree = true;
- ArenaImpl_SetDebugInfo(node, NULL, 0, arena);
+ node->size += next->size + sizeof(ArenaNode);
if (arena->flag & FILL_FREEBLOCK) {
- func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size);
+ func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
}
+ node->next = newNext;
+ next = newNext;
+ }
- newNext = next;
- if ((u32)next == (u32)node + sizeof(ArenaNode) + node->size && next->isFree) {
- newNext = ArenaImpl_GetNextBlock(next);
- if (newNext) {
- newNext->prev = node;
- }
-
- node->size += next->size + sizeof(ArenaNode);
- if (arena->flag & FILL_FREEBLOCK) {
- func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
- }
- node->next = newNext;
- next = newNext;
+ if (prev != NULL && prev->isFree && (u32)node == (u32)prev + sizeof(ArenaNode) + prev->size) {
+ if (next) {
+ next->prev = prev;
}
-
- if (prev && prev->isFree && (u32)node == (u32)prev + sizeof(ArenaNode) + prev->size) {
- if (next) {
- next->prev = prev;
- }
- prev->next = next;
- prev->size += node->size + sizeof(ArenaNode);
- if (arena->flag & FILL_FREEBLOCK) {
- func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
- }
+ prev->next = next;
+ prev->size += node->size + sizeof(ArenaNode);
+ if (arena->flag & FILL_FREEBLOCK) {
+ func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
}
}
}
@@ -490,57 +484,60 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) {
ArenaNode* prev;
ArenaNode* newNext;
- if (ptr) {
- node = (ArenaNode*)((u32)ptr - sizeof(ArenaNode));
- if (node == NULL || node->magic != NODE_MAGIC) {
- osSyncPrintf(VT_COL(RED, WHITE) "__osFree:不正解放(%08x) [%s:%d ]\n" VT_RST, ptr, file,
- line); // __osFree: Unauthorized release (%08x)
- return;
- }
- if (node->isFree) {
- osSyncPrintf(VT_COL(RED, WHITE) "__osFree:二重解放(%08x) [%s:%d ]\n" VT_RST, ptr, file,
- line); // __osFree: Double release (%08x)
- return;
- }
- if (arena != node->arena && arena != NULL) {
- // __osFree:Tried to release in a different way than when it was secured (%08x:%08x)
- osSyncPrintf(VT_COL(RED, WHITE) "__osFree:確保時と違う方法で解放しようとした (%08x:%08x)\n" VT_RST, arena,
- node->arena);
- return;
+ if (ptr == NULL) {
+ return;
+ }
+
+ node = (ArenaNode*)((u32)ptr - sizeof(ArenaNode));
+ if (node == NULL || node->magic != NODE_MAGIC) {
+ osSyncPrintf(VT_COL(RED, WHITE) "__osFree:不正解放(%08x) [%s:%d ]\n" VT_RST, ptr, file,
+ line); // __osFree: Unauthorized release (%08x)
+ return;
+ }
+ if (node->isFree) {
+ osSyncPrintf(VT_COL(RED, WHITE) "__osFree:二重解放(%08x) [%s:%d ]\n" VT_RST, ptr, file,
+ line); // __osFree: Double release (%08x)
+ return;
+ }
+ if (arena != node->arena && arena != NULL) {
+ // __osFree:Tried to release in a different way than when it was secured (%08x:%08x)
+ osSyncPrintf(VT_COL(RED, WHITE) "__osFree:確保時と違う方法で解放しようとした (%08x:%08x)\n" VT_RST, arena,
+ node->arena);
+ return;
+ }
+
+ next = ArenaImpl_GetNextBlock(node);
+ prev = ArenaImpl_GetPrevBlock(node);
+ node->isFree = true;
+ ArenaImpl_SetDebugInfo(node, file, line, arena);
+
+ if (arena->flag & FILL_FREEBLOCK) {
+ func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size);
+ }
+
+ newNext = node->next;
+ if ((u32)next == (u32)node + sizeof(ArenaNode) + node->size && next->isFree) {
+ newNext = ArenaImpl_GetNextBlock(next);
+ if (newNext != NULL) {
+ newNext->prev = node;
}
- next = ArenaImpl_GetNextBlock(node);
- prev = ArenaImpl_GetPrevBlock(node);
- node->isFree = true;
- ArenaImpl_SetDebugInfo(node, file, line, arena);
+ node->size += next->size + sizeof(ArenaNode);
if (arena->flag & FILL_FREEBLOCK) {
- func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size);
+ func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
}
+ node->next = newNext;
+ next = newNext;
+ }
- newNext = node->next;
- if ((u32)next == (u32)node + sizeof(ArenaNode) + node->size && next->isFree) {
- newNext = ArenaImpl_GetNextBlock(next);
- if (newNext) {
- newNext->prev = node;
- }
-
- node->size += next->size + sizeof(ArenaNode);
- if (arena->flag & FILL_FREEBLOCK) {
- func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
- }
- node->next = newNext;
- next = newNext;
+ if (prev != NULL && prev->isFree && (u32)node == (u32)prev + sizeof(ArenaNode) + prev->size) {
+ if (next != NULL) {
+ next->prev = prev;
}
-
- if (prev && prev->isFree && (u32)node == (u32)prev + sizeof(ArenaNode) + prev->size) {
- if (next) {
- next->prev = prev;
- }
- prev->next = next;
- prev->size += node->size + sizeof(ArenaNode);
- if (arena->flag & FILL_FREEBLOCK) {
- func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
- }
+ prev->next = next;
+ prev->size += node->size + sizeof(ArenaNode);
+ if (arena->flag & FILL_FREEBLOCK) {
+ func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode));
}
}
}
@@ -568,9 +565,10 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
newSize = ALIGN16(newSize);
osSyncPrintf("__osRealloc(%08x, %d)\n", ptr, newSize);
ArenaImpl_Lock(arena);
- if (!ptr) {
+
+ if (ptr == NULL) {
ptr = __osMalloc_NoLock(arena, newSize);
- } else if (!newSize) {
+ } else if (newSize == 0) {
__osFree_NoLock(arena, ptr);
ptr = NULL;
} else {
@@ -587,7 +585,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
next->size -= sizeDiff;
overNext = ArenaImpl_GetNextBlock(next);
newNext = (ArenaNode*)((u32)next + sizeDiff);
- if (overNext) {
+ if (overNext != NULL) {
overNext->prev = newNext;
}
node->next = newNext;
@@ -597,7 +595,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
// Allocate a new memory block and move the contents
osSyncPrintf("新たにメモリブロックを確保して内容を移動します\n");
newAlloc = __osMalloc_NoLock(arena, newSize);
- if (newAlloc) {
+ if (newAlloc != NULL) {
bcopy(ptr, newAlloc, node->size);
__osFree_NoLock(arena, ptr);
}
@@ -605,7 +603,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
}
} else if (newSize < node->size) {
next2 = ArenaImpl_GetNextBlock(node);
- if (next2 && next2->isFree) {
+ if (next2 != NULL && next2->isFree) {
blockSize = ALIGN16(newSize) + sizeof(ArenaNode);
// Increased free block behind current memory block
osSyncPrintf("現メモリブロックの後ろのフリーブロックを大きくしました\n");
@@ -616,7 +614,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
node->next = newNext2;
node->size = newSize;
overNext2 = ArenaImpl_GetNextBlock(newNext2);
- if (overNext2) {
+ if (overNext2 != NULL) {
overNext2->prev = newNext2;
}
} else if (newSize + sizeof(ArenaNode) < node->size) {
@@ -632,7 +630,7 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
node->next = newNext2;
node->size = newSize;
overNext2 = ArenaImpl_GetNextBlock(newNext2);
- if (overNext2) {
+ if (overNext2 != NULL) {
overNext2->prev = newNext2;
}
} else {
@@ -642,8 +640,8 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) {
}
}
}
-
ArenaImpl_Unlock(arena);
+
return ptr;
}
@@ -661,7 +659,7 @@ void ArenaImpl_GetSizes(Arena* arena, u32* outMaxFree, u32* outFree, u32* outAll
*outAlloc = 0;
iter = arena->head;
- while (iter) {
+ while (iter != NULL) {
if (iter->isFree) {
*outFree += iter->size;
if (*outMaxFree < iter->size) {
@@ -702,11 +700,11 @@ void __osDisplayArena(Arena* arena) {
osSyncPrintf("メモリブロック範囲 status サイズ [時刻 s ms us ns: TID:src:行]\n");
iter = arena->head;
- while (iter) {
- if (iter && iter->magic == NODE_MAGIC) {
+ while (iter != NULL) {
+ if (iter != NULL && iter->magic == NODE_MAGIC) {
next = iter->next;
osSyncPrintf("%08x-%08x%c %s %08x", iter, ((u32)iter + sizeof(ArenaNode) + iter->size),
- (!next) ? '$' : (iter != next->prev ? '!' : ' '),
+ (next == NULL) ? '$' : (iter != next->prev ? '!' : ' '),
iter->isFree ? "空き" : "確保", //? "Free" : "Secure"
iter->size);
@@ -729,7 +727,6 @@ void __osDisplayArena(Arena* arena) {
osSyncPrintf("%08x Block Invalid\n", iter);
next = NULL;
}
-
iter = next;
}
@@ -760,8 +757,8 @@ void ArenaImpl_FaultClient(Arena* arena) {
FaultDrawer_Printf("Memory Block Region status size\n");
iter = arena->head;
- while (iter) {
- if (iter && iter->magic == NODE_MAGIC) {
+ while (iter != NULL) {
+ if (iter != NULL && iter->magic == NODE_MAGIC) {
next = iter->next;
FaultDrawer_Printf("%08x-%08x%c %s %08x", iter, ((u32)iter + sizeof(ArenaNode) + iter->size),
(!next) ? '$' : (iter != next->prev ? '!' : ' '), iter->isFree ? "F" : "A", iter->size);
@@ -781,7 +778,6 @@ void ArenaImpl_FaultClient(Arena* arena) {
FaultDrawer_Printf("%08x Block Invalid\n", iter);
next = NULL;
}
-
iter = next;
}
@@ -793,14 +789,13 @@ void ArenaImpl_FaultClient(Arena* arena) {
u32 __osCheckArena(Arena* arena) {
ArenaNode* iter;
- u32 error;
+ u32 error = 0;
- error = 0;
ArenaImpl_Lock(arena);
// Checking the contents of the arena. . . (%08x)
osSyncPrintf("アリーナの内容をチェックしています... (%08x)\n", arena);
iter = arena->head;
- while (iter) {
+ while (iter != NULL) {
if (iter && iter->magic == NODE_MAGIC) {
// Oops!! (%08x %08x)
osSyncPrintf(VT_COL(RED, WHITE) "おおっと!! (%08x %08x)\n" VT_RST, iter, iter->magic);
@@ -809,11 +804,12 @@ u32 __osCheckArena(Arena* arena) {
}
iter = ArenaImpl_GetNextBlock(iter);
}
- if (!error) {
+ if (error == 0) {
// The arena is still going well
osSyncPrintf("アリーナはまだ、いけそうです\n");
}
ArenaImpl_Unlock(arena);
+
return error;
}
diff --git a/src/code/audioMgr.c b/src/code/audioMgr.c
index 2d3a12248..ebe5307e9 100644
--- a/src/code/audioMgr.c
+++ b/src/code/audioMgr.c
@@ -1,9 +1,8 @@
#include "global.h"
void func_800C3C80(AudioMgr* audioMgr) {
- Sub_AudioMgr_18* sub;
+ Sub_AudioMgr_18* sub = audioMgr->unk_70;
- sub = audioMgr->unk_70;
if (audioMgr->unk_70->unk_40 != NULL) {
osSendMesg(sub->unk_40, NULL, OS_MESG_BLOCK);
}
@@ -27,6 +26,7 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) {
osSendMesg(&audioMgr->sched->cmdQ, &audioMgr->unk_8, OS_MESG_BLOCK);
Sched_SendEntryMsg(audioMgr->sched);
}
+
D_8016A550 = osGetTime();
if (SREG(20) >= 2) {
sub = NULL;
@@ -35,6 +35,7 @@ void AudioMgr_HandleRetrace(AudioMgr* audioMgr) {
}
D_8016A558 += osGetTime() - D_8016A550;
D_8016A550 = 0;
+
if (audioMgr->unk_70 != NULL) {
osRecvMesg(&audioMgr->unk_AC, NULL, OS_MESG_BLOCK);
func_800C3C80(audioMgr);
@@ -49,12 +50,10 @@ void AudioMgr_HandlePRENMI(AudioMgr* audioMgr) {
}
void AudioMgr_ThreadEntry(void* arg0) {
- AudioMgr* audioMgr;
+ AudioMgr* audioMgr = (AudioMgr*)arg0;
IrqMgrClient irqClient;
- s16* msg;
+ s16* msg = NULL;
- audioMgr = (AudioMgr*)arg0;
- msg = NULL;
// Start running audio manager thread
osSyncPrintf("オーディオマネージャスレッド実行開始\n");
func_800F70F8();
diff --git a/src/code/audio_playback.c b/src/code/audio_playback.c
index e79e9e06b..03cbd6099 100644
--- a/src/code/audio_playback.c
+++ b/src/code/audio_playback.c
@@ -11,8 +11,8 @@ void Audio_NoteSetVelPanReverb(Note* note, NoteSubEu* sub, Reverb* reverb) {
u8 reverbVol;
ReverbBitsData sp24;
s32 stereoHeadsetEffects = note->playbackState.stereoHeadsetEffects;
- vel = reverb->velocity;
+ vel = reverb->velocity;
pan = reverb->pan;
reverbVol = reverb->reverb;
sp24 = reverb->reverbBits.s;
@@ -815,9 +815,10 @@ Note* Audio_AllocNoteFromDecaying(NotePool* pool, SequenceChannelLayer* seqLayer
Note* Audio_AllocNoteFromActive(NotePool* pool, SequenceChannelLayer* seqLayer) {
Note* rNote;
Note* aNote;
- s32 rPriority, aPriority;
- rPriority = aPriority = 0x10;
+ s32 rPriority;
+ s32 aPriority;
+ rPriority = aPriority = 0x10;
rNote = Audio_PopNodeWithValueLessEqual(&pool->releasing, seqLayer->seqChannel->notePriority);
if (rNote != NULL) {
diff --git a/src/code/audio_seqplayer.c b/src/code/audio_seqplayer.c
index dc13c246d..01fb8e39b 100644
--- a/src/code/audio_seqplayer.c
+++ b/src/code/audio_seqplayer.c
@@ -23,6 +23,7 @@ u16 Audio_GetScriptControlFlowArgument(M64ScriptState* state, u8 arg1) {
u8 temp_v0 = D_80130470[arg1];
u8 loBits = temp_v0 & 3;
u16 ret = 0;
+
if (loBits == 1) {
if ((temp_v0 & 0x80) == 0) {
ret = Audio_M64ReadU8(state);
@@ -227,6 +228,7 @@ void Audio_SeqChannelLayerFree(SequenceChannel* seqChannel, s32 layerIdx) {
void Audio_SequenceChannelDisable(SequenceChannel* seqChannel) {
s32 i;
+
for (i = 0; i < 4; i++) {
Audio_SeqChannelLayerFree(seqChannel, i);
}
@@ -290,6 +292,7 @@ void Audio_SequencePlayerDisable(SequencePlayer* seqPlayer) {
if (!seqPlayer->enabled) {
return;
}
+
seqPlayer->enabled = false;
seqPlayer->finished = true;
@@ -320,9 +323,11 @@ void Audio_AudioListPushBack(AudioListItem* list, AudioListItem* item) {
void* Audio_AudioListPopBack(AudioListItem* list) {
AudioListItem* item = list->prev;
+
if (item == list) {
return NULL;
}
+
item->prev->next = list;
list->prev = item->prev;
item->prev = NULL;
@@ -606,7 +611,7 @@ s32 func_800EA0C0(SequenceChannelLayer* layer) {
}
s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
- s32 sameSound;
+ s32 sameSound = 1;
s32 instOrWave;
s32 speed;
f32 temp_f14;
@@ -620,16 +625,13 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
s32 pad;
SequenceChannel* seqChannel;
SequencePlayer* seqPlayer;
- u8 cmd;
+ u8 cmd = arg1;
u16 sfxId;
s32 cmd2;
s32 vel;
f32 time;
f32 tuning;
- sameSound = 1;
- cmd = arg1;
-
instOrWave = layer->instOrWave;
seqChannel = layer->seqChannel;
seqPlayer = seqChannel->seqPlayer;
@@ -803,18 +805,14 @@ s32 func_800EA440(SequenceChannelLayer* layer, s32 arg1) {
}
s32 func_800EAAE0(SequenceChannelLayer* layer, s32 arg1) {
- M64ScriptState* state;
+ M64ScriptState* state = &layer->scriptState;
u16 playPercentage;
s32 velocity;
- SequenceChannel* seqChannel;
- SequencePlayer* seqPlayer;
+ SequenceChannel* seqChannel = layer->seqChannel;
+ SequencePlayer* seqPlayer = seqChannel->seqPlayer;
s32 intDelta;
f32 floatDelta;
- state = &layer->scriptState;
- seqChannel = layer->seqChannel;
- seqPlayer = seqChannel->seqPlayer;
-
if (arg1 == 0xC0) {
layer->delay = Audio_M64ReadCompressedU16(state);
layer->stopSomething = true;
@@ -888,7 +886,7 @@ s32 func_800EAAE0(SequenceChannelLayer* layer, s32 arg1) {
layer->delay = playPercentage;
layer->duration = (layer->noteDuration * playPercentage) >> 8;
if (seqChannel->durationRandomVariance != 0) {
- // @bug should probably be durationRandomVariance
+ //! @bug should probably be durationRandomVariance
intDelta = (layer->duration * (gAudioContext.gAudioRandom % seqChannel->velocityRandomVariance)) / 100;
if ((gAudioContext.gAudioRandom & 0x4000) != 0) {
intDelta = -intDelta;
@@ -924,6 +922,7 @@ void func_800EAEF4(SequenceChannel* seqChannel, u8 arg1) {
u8 Audio_GetInstrument(SequenceChannel* seqChannel, u8 instId, Instrument** instOut, AdsrSettings* adsr) {
Instrument* inst = Audio_GetInstrumentInner(seqChannel->bankId, instId);
+
if (inst == NULL) {
*instOut = NULL;
return 0;
@@ -957,13 +956,11 @@ void Audio_SequenceChannelSetVolume(SequenceChannel* seqChannel, u8 volume) {
seqChannel->volume = (f32)(s32)volume / 127.0f;
}
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/Audio_SequenceChannelProcessScript.s")
-
void Audio_SequenceChannelProcessScript(SequenceChannel* seqChannel);
-
-#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/Audio_SequencePlayerProcessSequence.s")
+#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/Audio_SequenceChannelProcessScript.s")
void Audio_SequencePlayerProcessSequence(SequencePlayer* seqPlayer);
+#pragma GLOBAL_ASM("asm/non_matchings/code/audio_seqplayer/Audio_SequencePlayerProcessSequence.s")
void Audio_ProcessSequences(s32 arg0) {
SequencePlayer* seqPlayer;
@@ -1018,10 +1015,9 @@ void Audio_ResetSequencePlayer(SequencePlayer* seqPlayer) {
void func_800EC734(s32 seqPlayerIdx) {
SequenceChannel* seqChannel;
- SequencePlayer* seqPlayer;
+ SequencePlayer* seqPlayer = &gAudioContext.gSequencePlayers[seqPlayerIdx];
s32 i, j;
- seqPlayer = &gAudioContext.gSequencePlayers[seqPlayerIdx];
for (i = 0; i < 0x10; i++) {
seqPlayer->channels[i] = Audio_AllocZeroed(&gAudioContext.gNotesAndBuffersPool, sizeof(SequenceChannel));
if (seqPlayer->channels[i] == NULL) {
diff --git a/src/code/code_800430A0.c b/src/code/code_800430A0.c
index 1b2f73c48..6b7623b79 100644
--- a/src/code/code_800430A0.c
+++ b/src/code/code_800430A0.c
@@ -85,7 +85,7 @@ s32 func_800433A4(CollisionContext* colCtx, s32 bgId, Actor* actor) {
return false;
}
- dynaActor = (DynaPolyActor*)DynaPoly_GetActor(colCtx, bgId);
+ dynaActor = DynaPoly_GetActor(colCtx, bgId);
if (dynaActor == NULL) {
return false;
diff --git a/src/code/code_80043480.c b/src/code/code_80043480.c
index fe8097eb9..b264837dd 100644
--- a/src/code/code_80043480.c
+++ b/src/code/code_80043480.c
@@ -21,7 +21,7 @@ void func_800434B8(DynaPolyActor* dynaActor) {
}
void func_800434C8(CollisionContext* colCtx, s32 floorBgId) {
- DynaPolyActor* dynaActor = (DynaPolyActor*)DynaPoly_GetActor(colCtx, floorBgId);
+ DynaPolyActor* dynaActor = DynaPoly_GetActor(colCtx, floorBgId);
if (dynaActor != NULL) {
func_800434B8(dynaActor);
@@ -33,7 +33,7 @@ void func_800434F8(DynaPolyActor* dynaActor) {
}
void func_80043508(CollisionContext* colCtx, s32 floorBgId) {
- DynaPolyActor* dynaActor = (DynaPolyActor*)DynaPoly_GetActor(colCtx, floorBgId);
+ DynaPolyActor* dynaActor = DynaPoly_GetActor(colCtx, floorBgId);
if (dynaActor != NULL) {
func_800434F8(dynaActor);
@@ -76,41 +76,38 @@ s32 func_800435B4(DynaPolyActor* dynaActor) {
}
}
-s32 func_800435D8(GlobalContext* globalCtx, DynaPolyActor* actor, s16 arg2, s16 arg3, s16 arg4) {
+s32 func_800435D8(GlobalContext* globalCtx, DynaPolyActor* dynaActor, s16 arg2, s16 arg3, s16 arg4) {
Vec3f posA;
Vec3f posB;
Vec3f posResult;
- f32 sin;
- f32 cos;
+ f32 sin = Math_SinS(dynaActor->unk_158);
+ f32 cos = Math_CosS(dynaActor->unk_158);
s32 bgId;
CollisionPoly* poly;
f32 a2;
f32 a3;
- f32 sign;
-
- sin = Math_SinS(actor->unk_158);
- cos = Math_CosS(actor->unk_158);
- sign = (0.0f <= actor->unk_150) ? 1.0f : -1.0f;
+ f32 sign = (0.0f <= dynaActor->unk_150) ? 1.0f : -1.0f;
a2 = (f32)arg2 - 0.1f;
- posA.x = actor->actor.world.pos.x + (a2 * cos);
- posA.y = actor->actor.world.pos.y + arg4;
- posA.z = actor->actor.world.pos.z - (a2 * sin);
+ posA.x = dynaActor->actor.world.pos.x + (a2 * cos);
+ posA.y = dynaActor->actor.world.pos.y + arg4;
+ posA.z = dynaActor->actor.world.pos.z - (a2 * sin);
a3 = (f32)arg3 - 0.1f;
posB.x = sign * a3 * sin + posA.x;
posB.y = posA.y;
posB.z = sign * a3 * cos + posA.z;
+
if (BgCheck_EntityLineTest3(&globalCtx->colCtx, &posA, &posB, &posResult, &poly, true, false, false, true, &bgId,
- actor, 0.0f)) {
+ &dynaActor->actor, 0.0f)) {
return false;
}
- posA.x = (actor->actor.world.pos.x * 2) - posA.x;
- posA.z = (actor->actor.world.pos.z * 2) - posA.z;
+ posA.x = (dynaActor->actor.world.pos.x * 2) - posA.x;
+ posA.z = (dynaActor->actor.world.pos.z * 2) - posA.z;
posB.x = sign * a3 * sin + posA.x;
posB.z = sign * a3 * cos + posA.z;
if (BgCheck_EntityLineTest3(&globalCtx->colCtx, &posA, &posB, &posResult, &poly, true, false, false, true, &bgId,
- actor, 0.0f)) {
+ &dynaActor->actor, 0.0f)) {
return false;
}
return true;
diff --git a/src/code/code_8006BA00.c b/src/code/code_8006BA00.c
index 768ece14f..e3549db8b 100644
--- a/src/code/code_8006BA00.c
+++ b/src/code/code_8006BA00.c
@@ -10,10 +10,9 @@ void func_8006BA00(GlobalContext* globalCtx) {
}
void func_8006BA30(GlobalContext* globalCtx) {
- SoundSource* source;
+ SoundSource* source = &globalCtx->soundSources[0];
s32 i;
- source = &globalCtx->soundSources[0];
for (i = 0; i < ARRAY_COUNT(globalCtx->soundSources); i++) {
if (source->countdown != 0) {
if (DECR(source->countdown) == 0) {
@@ -30,12 +29,10 @@ void func_8006BA30(GlobalContext* globalCtx) {
void Audio_PlaySoundAtPosition(GlobalContext* globalCtx, Vec3f* pos, s32 duration, u16 sfxId) {
s32 countdown;
SoundSource* source;
- s32 smallestCountdown;
+ s32 smallestCountdown = 0xFFFF;
SoundSource* backupSource;
s32 i;
- smallestCountdown = 0xFFFF;
-
source = &globalCtx->soundSources[0];
for (i = 0; i < ARRAY_COUNT(globalCtx->soundSources); i++) {
if (source->countdown == 0) {
@@ -47,7 +44,6 @@ void Audio_PlaySoundAtPosition(GlobalContext* globalCtx, Vec3f* pos, s32 duratio
smallestCountdown = countdown;
backupSource = source;
}
-
source++;
}
diff --git a/src/code/code_8008E6A0.c b/src/code/code_8008E6A0.c
index 47d437e98..a04598b53 100644
--- a/src/code/code_8008E6A0.c
+++ b/src/code/code_8008E6A0.c
@@ -14,11 +14,9 @@ u32 func_8008E6AC(SubGlobalContext7B8* this, Input* input) {
}
if (CHECK_BTN_ALL(input->cur.button, BTN_Z)) {
-
if (CHECK_BTN_ALL(input->press.button, BTN_R)) {
goto ret_true;
}
-
if (CHECK_BTN_ALL(input->cur.button, BTN_R)) {
this->counter++;
if (this->counter >= 9) {
diff --git a/src/code/code_80097A00.c b/src/code/code_80097A00.c
index 94e8fa0a1..a11da6948 100644
--- a/src/code/code_80097A00.c
+++ b/src/code/code_80097A00.c
@@ -74,9 +74,7 @@ void Inventory_ChangeEquipment(s16 equipment, u16 value) {
u8 Inventory_DeleteEquipment(GlobalContext* globalCtx, s16 equipment) {
Player* player = PLAYER;
s32 pad;
- u16 sp26;
-
- sp26 = gSaveContext.equips.equipment & gEquipMasks[equipment];
+ u16 sp26 = gSaveContext.equips.equipment & gEquipMasks[equipment];
// Translates to: "Erasing equipment item = %d zzz=%d"
osSyncPrintf("装備アイテム抹消 = %d zzz=%d\n", equipment, sp26);
diff --git a/src/code/code_800A9D40.c b/src/code/code_800A9D40.c
index 17660b74e..2f295716e 100644
--- a/src/code/code_800A9D40.c
+++ b/src/code/code_800A9D40.c
@@ -10,9 +10,9 @@ struct_800A9D40 D_8012A690 = { 0 };
void func_800A9D40(u32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration,
u8 handlePulse, u32 handleSpeed) {
- u32 int_disabled;
-
+ u32 prevInt;
OSPiHandle* handle = &D_8012A690.piHandle;
+
if ((u32)OS_PHYSICAL_TO_K1(addr) != (*handle).baseAddress) {
D_8012A690.piHandle.type = handleType;
(*handle).baseAddress = OS_PHYSICAL_TO_K1(addr);
@@ -23,10 +23,12 @@ void func_800A9D40(u32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u
D_8012A690.piHandle.domain = handleDomain;
D_8012A690.piHandle.speed = handleSpeed;
bzero(&D_8012A690.piHandle.transferInfo, sizeof(__OSTranxInfo));
- int_disabled = __osDisableInt();
+
+ prevInt = __osDisableInt();
D_8012A690.piHandle.next = __osPiTable;
- __osPiTable = &D_8012A690;
- __osRestoreInt(int_disabled);
+ __osPiTable = &D_8012A690.piHandle;
+ __osRestoreInt(prevInt);
+
D_8012A690.ioMesg.hdr.pri = 0;
D_8012A690.ioMesg.hdr.retQueue = &D_8012A690.mesgQ;
D_8012A690.ioMesg.devAddr = addr;
@@ -40,7 +42,7 @@ void func_800A9E14(UNK_PTR dramAddr, size_t size, UNK_TYPE arg2) {
D_8012A690.ioMesg.dramAddr = dramAddr;
D_8012A690.ioMesg.size = size;
osWritebackDCache(dramAddr, size);
- osEPiStartDma(&D_8012A690, &D_8012A690.ioMesg, arg2);
+ osEPiStartDma(&D_8012A690.piHandle, &D_8012A690.ioMesg, arg2);
osRecvMesg(&D_8012A690.mesgQ, &mesg, 1);
osInvalDCache(dramAddr, size);
}
diff --git a/src/code/code_800A9F30.c b/src/code/code_800A9F30.c
index fd8d220e2..b8f4e1ce8 100644
--- a/src/code/code_800A9F30.c
+++ b/src/code/code_800A9F30.c
@@ -8,7 +8,8 @@ void func_800A9F30(PadMgr* a, s32 b) {
}
void func_800A9F6C(f32 a, u8 b, u8 c, u8 d) {
- s32 temp1, temp2;
+ s32 temp1;
+ s32 temp2;
if (1000000.0f < a) {
temp1 = 1000;
@@ -30,6 +31,7 @@ void func_800AA000(f32 a, u8 b, u8 c, u8 d) {
s32 temp1;
s32 temp2;
s32 i;
+
if (1000000.0f < a) {
temp1 = 1000;
} else {
@@ -55,16 +57,16 @@ void func_800AA000(f32 a, u8 b, u8 c, u8 d) {
void func_800AA0B4(void) {
func_800D3140(&D_80160FD0);
- gPadMgr.retraceCallback = (void*)func_800A9F30;
+ gPadMgr.retraceCallback = func_800A9F30;
gPadMgr.retraceCallbackValue = 0;
- if (0) {} // Necessary to match
+ if (1) {}
}
void func_800AA0F0(void) {
PadMgr* padmgr = &gPadMgr;
- if (((void*)padmgr->retraceCallback == (void*)func_800A9F30) && (padmgr->retraceCallbackValue == 0)) {
+ if ((padmgr->retraceCallback == func_800A9F30) && (padmgr->retraceCallbackValue == 0)) {
padmgr->retraceCallback = NULL;
padmgr->retraceCallbackValue = 0;
}
diff --git a/src/code/code_800ACE70.c b/src/code/code_800ACE70.c
index 88e86014a..e22162777 100644
--- a/src/code/code_800ACE70.c
+++ b/src/code/code_800ACE70.c
@@ -65,9 +65,7 @@ void func_800ACE90(struct_801664F0* this) {
// Draw
void func_800ACE98(struct_801664F0* this, Gfx** gfxp) {
- Gfx* gfx;
-
- gfx = *gfxp;
+ Gfx* gfx = *gfxp;
gDPPipeSync(gfx++);
gDPSetPrimDepth(gfx++, -1, -1);
diff --git a/src/code/code_800AD920.c b/src/code/code_800AD920.c
index 2fbd7c452..2f60901a1 100644
--- a/src/code/code_800AD920.c
+++ b/src/code/code_800AD920.c
@@ -25,17 +25,12 @@ void func_800AD950(struct_80166500* this) {
// Draw
void func_800AD958(struct_80166500* this, Gfx** gfxp) {
- Gfx* gfx;
- u16* tex;
- s32 fmt;
+ Gfx* gfx = *gfxp;
+ u16* tex = D_0E000000;
+ s32 fmt = this->useRgba == false ? G_IM_FMT_IA : G_IM_FMT_RGBA;
s32 y;
s32 height = 6;
- gfx = *gfxp;
- tex = D_0E000000;
-
- fmt = this->useRgba == false ? G_IM_FMT_IA : G_IM_FMT_RGBA;
-
gDPPipeSync(gfx++);
if (this->setScissor == true) {
gDPSetScissor(gfx++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
diff --git a/src/code/code_800C3C20.c b/src/code/code_800C3C20.c
index bfe37bdfb..65402c3e2 100644
--- a/src/code/code_800C3C20.c
+++ b/src/code/code_800C3C20.c
@@ -7,7 +7,7 @@ u8 D_8012D200[] = {
void func_800C3C20(void) {
s32 i;
- for (i = 0; i < ARRAY_COUNT(D_8012D200) & 0xFFFFFFFFu; i++) {
+ for (i = 0; (i < ARRAY_COUNT(D_8012D200)) & 0xFFFFFFFFu; i++) {
func_800F87A0(D_8012D200[i]);
}
}
diff --git a/src/code/code_800D2E30.c b/src/code/code_800D2E30.c
index ebf03760e..1c731c9bd 100644
--- a/src/code/code_800D2E30.c
+++ b/src/code/code_800D2E30.c
@@ -20,6 +20,7 @@ void func_800D2E30(UnkRumbleStruct* arg0) {
D_8012DBB0 = new_var->unk_105;
return;
}
+
D_8012DBB0 = arg0->unk_105;
if (arg0->unk_104 == 2) {
@@ -38,7 +39,6 @@ void func_800D2E30(UnkRumbleStruct* arg0) {
}
if (arg0->unk_104 != 0) {
for (i = 0; i < 0x40; i++) {
-
if (arg0->unk_04[i] != 0) {
if (arg0->unk_44[i] > 0) {
arg0->unk_44[i]--;
@@ -56,12 +56,9 @@ void func_800D2E30(UnkRumbleStruct* arg0) {
if (index == -1) {
index = i;
arg0->rumbleEnable[0] = (unk_a3 >= 0x100);
- } else {
-
- if (arg0->unk_04[index] < arg0->unk_04[i]) {
- index = i;
- arg0->rumbleEnable[0] = (unk_a3 >= 0x100);
- }
+ } else if (arg0->unk_04[index] < arg0->unk_04[i]) {
+ index = i;
+ arg0->rumbleEnable[0] = (unk_a3 >= 0x100);
}
}
}
diff --git a/src/code/code_800D31A0.c b/src/code/code_800D31A0.c
index 4f6b9f8c0..7c0b43ac8 100644
--- a/src/code/code_800D31A0.c
+++ b/src/code/code_800D31A0.c
@@ -1,21 +1,19 @@
#include "global.h"
#include "vt.h"
-extern PadMgr gPadMgr;
-
u32 D_8012DBC0 = false;
-void func_800D31A0() {
+void func_800D31A0(void) {
osSyncPrintf(VT_FGCOL(RED) "\n**** Freeze!! ****\n" VT_RST);
while (true) {
Sleep_Msec(1000);
}
}
-void func_800D31F0() {
+void func_800D31F0(void) {
D_8012DBC0 = (gPadMgr.validCtrlrsMask & 2) != 0;
}
-void func_800D3210() {
+void func_800D3210(void) {
D_8012DBC0 = false;
}
diff --git a/src/code/code_800FC620.c b/src/code/code_800FC620.c
index d1bb1f36d..5e2532ae3 100644
--- a/src/code/code_800FC620.c
+++ b/src/code/code_800FC620.c
@@ -71,6 +71,7 @@ s32 Overlay_Load(u32 vRomStart, u32 vRomEnd, void* vRamStart, void* vRamEnd, voi
bssSize = size;
bzero((void*)end, bssSize);
relocCnt = ovl->nRelocations;
+ (void)relocCnt; // suppresses set but unused warning
}
size = (u32)&ovl->relocations[ovl->nRelocations] - (u32)ovl;
@@ -126,6 +127,7 @@ void func_800FC8D8(void* blk, u32 nBlk, s32 blkSize, arg3_800FC8D8 arg3) {
void* func_800FC948(void* blk, u32 nBlk, u32 blkSize, arg3_800FC948 arg3) {
u32 pos;
+
if (blk == NULL) {
blk = func_800FC800(nBlk * blkSize);
}
@@ -171,13 +173,9 @@ void func_800FCA18(void* blk, u32 nBlk, u32 blkSize, arg3_800FCA18 arg3, s32 arg
}
void func_800FCB34(void) {
- InitFunc* initFunc;
- u32 nextOffset;
- InitFunc* prev;
-
- initFunc = (InitFunc*)&sInitFuncs;
- nextOffset = initFunc->nextOffset;
- prev = NULL;
+ InitFunc* initFunc = (InitFunc*)&sInitFuncs;
+ u32 nextOffset = initFunc->nextOffset;
+ InitFunc* prev = NULL;
while (nextOffset != 0) {
initFunc = (InitFunc*)((s32)initFunc + nextOffset);
diff --git a/src/code/code_800FD970.c b/src/code/code_800FD970.c
index 7478bfe0b..c89a08654 100644
--- a/src/code/code_800FD970.c
+++ b/src/code/code_800FD970.c
@@ -60,9 +60,7 @@ u32 Rand_Next_Variable(u32* rndNum) {
* 1.0f from the provided rndNum.
*/
f32 Rand_ZeroOne_Variable(u32* rndNum) {
- u32 next;
-
- next = (*rndNum * 1664525) + 1013904223;
+ u32 next = (*rndNum * 1664525) + 1013904223;
// clang-format off
*rndNum = next; sRandFloat = (next >> 9) | 0x3F800000;
// clang-format on
@@ -74,9 +72,7 @@ f32 Rand_ZeroOne_Variable(u32* rndNum) {
* 0.5f from the provided rndNum.
*/
f32 Rand_Centered_Variable(u32* rndNum) {
- u32 next;
-
- next = (*rndNum * 1664525) + 1013904223;
+ u32 next = (*rndNum * 1664525) + 1013904223;
// clang-format off
*rndNum = next; sRandFloat = (next >> 9) | 0x3F800000;
// clang-format on
diff --git a/src/code/code_801068B0.c b/src/code/code_801068B0.c
index da6f94883..113a472d8 100644
--- a/src/code/code_801068B0.c
+++ b/src/code/code_801068B0.c
@@ -2,13 +2,10 @@
// memcpy used in __osMalloc.c
void* func_801068B0(void* dst, void* src, size_t size) {
- u8* spC;
- u8* sp8;
+ u8* spC = dst;
+ u8* sp8 = src;
register s32 a3;
- spC = dst;
- sp8 = src;
-
if (spC == sp8) {
return dst;
}
diff --git a/src/code/db_camera.c b/src/code/db_camera.c
index d29093583..d62a6578e 100644
--- a/src/code/db_camera.c
+++ b/src/code/db_camera.c
@@ -13,7 +13,7 @@ extern s16 D_8016111A;
extern s16 D_8016110C;
typedef struct {
- char state;
+ u8 state;
s16 mode;
CutsceneCameraPoint* eyePoints;
CutsceneCameraPoint* atPoints;
@@ -82,7 +82,7 @@ void func_800B3FF4(PosRot* arg0, Vec3f* arg1, Vec3f* arg2) {
func_800B3F38(arg1, &sp1C);
OLib_Vec3fToVecSphGeo(&sp28, &sp1C);
sp28.yaw += arg0->rot.y;
- func_800B3B50(arg2, arg0, &sp28);
+ func_800B3B50(arg2, &arg0->pos, &sp28);
}
void func_800B404C(s32 arg0, Vec3s* arg1, Vec3f* arg2) {
@@ -92,6 +92,7 @@ void func_800B404C(s32 arg0, Vec3s* arg1, Vec3f* arg2) {
func_800B3FF4(arg0, &sp1C, arg2);
}
+void func_800B4088(DBCamera* dbCamera, Camera* camera);
#pragma GLOBAL_ASM("asm/non_matchings/code/db_camera/func_800B4088.s")
#pragma GLOBAL_ASM("asm/non_matchings/code/db_camera/func_800B41DC.s")
diff --git a/src/code/debug_malloc.c b/src/code/debug_malloc.c
index 827f10a40..d92ec42bf 100644
--- a/src/code/debug_malloc.c
+++ b/src/code/debug_malloc.c
@@ -8,7 +8,7 @@ s32 gDebugArenaLogSeverity = LOG_SEVERITY_ERROR;
Arena sDebugArena;
void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action) {
- if (!ptr) {
+ if (ptr == NULL) {
if (gDebugArenaLogSeverity >= LOG_SEVERITY_ERROR) {
// "%s: %u bytes %s failed\n"
osSyncPrintf("%s: %u バイトの%sに失敗しました\n", name, size, action);
@@ -22,29 +22,29 @@ void DebugArena_CheckPointer(void* ptr, u32 size, const char* name, const char*
}
void* DebugArena_Malloc(u32 size) {
- void* ptr;
- ptr = __osMalloc(&sDebugArena, size);
+ void* ptr = __osMalloc(&sDebugArena, size);
+
DebugArena_CheckPointer(ptr, size, "debug_malloc", "確保"); // Secure
return ptr;
}
void* DebugArena_MallocDebug(u32 size, const char* file, s32 line) {
- void* ptr;
- ptr = __osMallocDebug(&sDebugArena, size, file, line);
+ void* ptr = __osMallocDebug(&sDebugArena, size, file, line);
+
DebugArena_CheckPointer(ptr, size, "debug_malloc_DEBUG", "確保"); // Secure
return ptr;
}
void* DebugArena_MallocR(u32 size) {
- void* ptr;
- ptr = __osMallocR(&sDebugArena, size);
+ void* ptr = __osMallocR(&sDebugArena, size);
+
DebugArena_CheckPointer(ptr, size, "debug_malloc_r", "確保"); // Secure
return ptr;
}
void* DebugArena_MallocRDebug(u32 size, const char* file, s32 line) {
- void* ptr;
- ptr = __osMallocRDebug(&sDebugArena, size, file, line);
+ void* ptr = __osMallocRDebug(&sDebugArena, size, file, line);
+
DebugArena_CheckPointer(ptr, size, "debug_malloc_r_DEBUG", "確保"); // Secure
return ptr;
}
@@ -71,11 +71,10 @@ void DebugArena_FreeDebug(void* ptr, const char* file, s32 line) {
void* DebugArena_Calloc(u32 num, u32 size) {
void* ret;
- u32 n;
+ u32 n = num * size;
- n = num * size;
ret = __osMalloc(&sDebugArena, n);
- if (ret) {
+ if (ret != NULL) {
bzero(ret, n);
}
@@ -83,7 +82,7 @@ void* DebugArena_Calloc(u32 num, u32 size) {
return ret;
}
-void DebugArena_Display() {
+void DebugArena_Display(void) {
// Zelda heap display (devs forgot to change "Zelda" to "Debug" apparently)
osSyncPrintf("ゼルダヒープ表示\n");
__osDisplayArena(&sDebugArena);
@@ -93,7 +92,7 @@ void DebugArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc) {
ArenaImpl_GetSizes(&sDebugArena, outMaxFree, outFree, outAlloc);
}
-void DebugArena_Check() {
+void DebugArena_Check(void) {
__osCheckArena(&sDebugArena);
}
@@ -102,11 +101,11 @@ void DebugArena_Init(void* start, u32 size) {
__osMallocInit(&sDebugArena, start, size);
}
-void DebugArena_Cleanup() {
+void DebugArena_Cleanup(void) {
gDebugArenaLogSeverity = LOG_SEVERITY_NOLOG;
__osMallocCleanup(&sDebugArena);
}
-u8 DebugArena_IsInitalized() {
+u8 DebugArena_IsInitalized(void) {
return __osMallocIsInitalized(&sDebugArena);
}
diff --git a/src/code/fault.c b/src/code/fault.c
index 2dcea2667..91e517552 100644
--- a/src/code/fault.c
+++ b/src/code/fault.c
@@ -42,7 +42,9 @@ void Fault_SleepImpl(u32 duration) {
Sleep_Cycles(value);
}
-void Fault_ClientProcessThread(FaultClientContext* ctx) {
+void Fault_ClientProcessThread(void* arg) {
+ FaultClientContext* ctx = (FaultClientContext*)arg;
+
if (ctx->callback != 0) {
ctx->ret = ctx->callback(ctx->param0, ctx->param1);
}
@@ -251,7 +253,7 @@ u32 Fault_ConvertAddress(FaultAddrConvClient* client) {
while (iter != NULL) {
if (iter->callback != 0) {
ret = Fault_ProcessClient(iter->callback, client, iter->param);
- if (ret == -1) {
+ if ((s32)ret == -1) {
Fault_RemoveAddrConvClient(iter);
} else if (ret != 0) {
return ret;
@@ -1001,7 +1003,7 @@ void Fault_ThreadEntry(void* arg) {
Fault_LogStackTrace(faultedThread, 0x32);
Fault_WaitForInput();
Fault_ProcessClients();
- Fault_DrawMemDump(faultedThread->context.pc - 0x100, (u32*)faultedThread->context.sp, 0, 0);
+ Fault_DrawMemDump(faultedThread->context.pc - 0x100, (u32)faultedThread->context.sp, 0, 0);
Fault_FillScreenRed();
FaultDrawer_DrawText(0x40, 0x50, " CONGRATURATIONS! ");
FaultDrawer_DrawText(0x40, 0x5A, "All Pages are displayed.");
@@ -1052,13 +1054,15 @@ void Fault_HangupFaultClient(const char* arg0, const char* arg1) {
void Fault_AddHungupAndCrashImpl(const char* arg0, const char* arg1) {
FaultClient client;
- char padd[4];
- Fault_AddClient(&client, &Fault_HangupFaultClient, arg0, arg1);
+ s32 pad;
+
+ Fault_AddClient(&client, &Fault_HangupFaultClient, (void*)arg0, (void*)arg1);
*(u32*)0x11111111 = 0; // trigger an exception
}
void Fault_AddHungupAndCrash(const char* filename, u32 line) {
char msg[256];
+
sprintf(msg, "HungUp %s:%d", filename, line);
Fault_AddHungupAndCrashImpl(msg, NULL);
}
diff --git a/src/code/fault_drawer.c b/src/code/fault_drawer.c
index 32c10cb88..62c5d2916 100644
--- a/src/code/fault_drawer.c
+++ b/src/code/fault_drawer.c
@@ -110,11 +110,11 @@ void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 col
void FaultDrawer_DrawChar(char c) {
u16* fb;
s32 x, y;
- u32* dataPtr;
+ const u32* dataPtr;
u32 data;
s32 cursorX = sFaultDrawerStruct.cursorX;
s32 cursorY = sFaultDrawerStruct.cursorY;
- u32** fontData = &sFaultDrawerStruct.fontData;
+ const u32** fontData = &sFaultDrawerStruct.fontData;
s32 shift = c % 4;
dataPtr = &fontData[0][(((c / 8) * 16) + ((c & 4) >> 2))];
@@ -205,8 +205,8 @@ void FaultDrawer_FillScreen() {
FaultDrawer_SetCursor(sFaultDrawerStruct.xStart, sFaultDrawerStruct.yStart);
}
-u32 FaultDrawer_FormatStringFunc(u32 arg0, const char* str, s32 count) {
- for (count; count != 0; count--, str++) {
+void* FaultDrawer_FormatStringFunc(void* arg, const char* str, u32 count) {
+ for (; count != 0; count--, str++) {
s32 curXStart;
s32 curXEnd;
@@ -262,11 +262,11 @@ u32 FaultDrawer_FormatStringFunc(u32 arg0, const char* str, s32 count) {
osWritebackDCacheAll();
- return arg0;
+ return arg;
}
void FaultDrawer_VPrintf(const char* str, char* args) { // va_list
- _Printf(&FaultDrawer_FormatStringFunc, &sFaultDrawerStruct, str, args);
+ _Printf(FaultDrawer_FormatStringFunc, (char*)&sFaultDrawerStruct, str, args);
}
void FaultDrawer_Printf(const char* fmt, ...) {
diff --git a/src/code/flg_set.c b/src/code/flg_set.c
index a2bef505a..76888438d 100644
--- a/src/code/flg_set.c
+++ b/src/code/flg_set.c
@@ -58,7 +58,7 @@ void FlagSet_Update(GlobalContext* globalCtx) {
GfxPrint_SetPos(&printer, 4, 15);
for (bitIdx = 15; bitIdx >= 0; bitIdx--) {
- if (bitIdx == curBit) {
+ if ((u32)bitIdx == curBit) {
GfxPrint_SetColor(&printer, 200, 200, 200, 255);
} else {
GfxPrint_SetColor(&printer, 100, 100, 100, 255);
diff --git a/src/code/game.c b/src/code/game.c
index ce0d91c9e..3efd82259 100644
--- a/src/code/game.c
+++ b/src/code/game.c
@@ -1,13 +1,6 @@
#include "global.h"
#include "vt.h"
-typedef struct {
- /* 0x0000 */ OSViMode viMode;
- /* 0x0050 */ char unk_50[0x30];
- /* 0x0080 */ u32 viFeatures;
- /* 0x0084 */ char unk_84[4];
-} unk_80166528;
-
SpeedMeter D_801664D0;
struct_801664F0 D_801664F0;
struct_80166500 D_80166500;
@@ -32,6 +25,7 @@ void GameState_FaultPrint(void) {
void GameState_SetFBFilter(Gfx** gfx) {
Gfx* gfxP;
gfxP = *gfx;
+
if ((R_FB_FILTER_TYPE > 0) && (R_FB_FILTER_TYPE < 5)) {
D_801664F0.type = R_FB_FILTER_TYPE;
D_801664F0.color.r = R_FB_FILTER_PRIM_COLOR(0);
@@ -75,7 +69,7 @@ void func_800C4344(GameState* gameState) {
}
if (HREG(80) == 0xC) {
- selectedInput = &gameState->input[HREG(81) < 4U ? HREG(81) : 0];
+ selectedInput = &gameState->input[(u32)HREG(81) < 4U ? HREG(81) : 0];
hReg82 = HREG(82);
HREG(83) = selectedInput->cur.button;
HREG(84) = selectedInput->press.button;
@@ -234,8 +228,10 @@ void func_800C49F4(GraphicsContext* gfxCtx) {
CLOSE_DISPS(gfxCtx, "../game.c", 865);
}
+void PadMgr_RequestPadData(PadMgr*, Input*, s32);
+
void GameState_ReqPadData(GameState* gameState) {
- PadMgr_RequestPadData(&gPadMgr, &gameState->input, 1);
+ PadMgr_RequestPadData(&gPadMgr, &gameState->input[0], 1);
}
void GameState_Update(GameState* gameState) {
@@ -346,9 +342,8 @@ void GameState_Realloc(GameState* gameState, size_t size) {
u32 systemMaxFree;
u32 systemFree;
u32 systemAlloc;
- void* thaBufp;
+ void* thaBufp = gameState->tha.bufp;
- thaBufp = gameState->tha.bufp;
THA_Dt(&gameState->tha);
GameAlloc_Free(alloc, thaBufp);
// Hyrule temporarily released !!
@@ -482,7 +477,7 @@ void* GameState_Alloc(GameState* gameState, size_t size, char* file, s32 line) {
if (THA_IsCrash(&gameState->tha)) {
osSyncPrintf("ハイラルは滅亡している\n");
ret = NULL;
- } else if (THA_GetSize(&gameState->tha) < size) {
+ } else if ((u32)THA_GetSize(&gameState->tha) < size) {
// Hyral on the verge of extinction does not have% d bytes left (% d bytes until extinction)
osSyncPrintf("滅亡寸前のハイラルには %d バイトの余力もない(滅亡まであと %d バイト)\n", size,
THA_GetSize(&gameState->tha));
diff --git a/src/code/gamealloc.c b/src/code/gamealloc.c
index 960aeea98..9a4303ad2 100644
--- a/src/code/gamealloc.c
+++ b/src/code/gamealloc.c
@@ -13,10 +13,9 @@ void GameAlloc_Log(GameAlloc* this) {
}
void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, s32 line) {
- GameAllocEntry* ptr;
+ GameAllocEntry* ptr = SystemArena_MallocDebug(size + sizeof(GameAllocEntry), file, line);
- ptr = SystemArena_MallocDebug(size + sizeof(GameAllocEntry), file, line);
- if (ptr) {
+ if (ptr != NULL) {
ptr->size = size;
ptr->prev = this->head;
this->head->next = ptr;
@@ -30,10 +29,9 @@ void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, s32 lin
}
void* GameAlloc_Malloc(GameAlloc* this, u32 size) {
- GameAllocEntry* ptr;
+ GameAllocEntry* ptr = SystemArena_MallocDebug(size + sizeof(GameAllocEntry), "../gamealloc.c", 93);
- ptr = SystemArena_MallocDebug(size + sizeof(GameAllocEntry), "../gamealloc.c", 93);
- if (ptr) {
+ if (ptr != NULL) {
ptr->size = size;
ptr->prev = this->head;
this->head->next = ptr;
@@ -49,7 +47,7 @@ void* GameAlloc_Malloc(GameAlloc* this, u32 size) {
void GameAlloc_Free(GameAlloc* this, void* data) {
GameAllocEntry* ptr;
- if (data) {
+ if (data != NULL) {
ptr = &((GameAllocEntry*)data)[-1];
LogUtils_CheckNullPointer("ptr->prev", ptr->prev, "../gamealloc.c", 120);
LogUtils_CheckNullPointer("ptr->next", ptr->next, "../gamealloc.c", 121);
@@ -61,10 +59,9 @@ void GameAlloc_Free(GameAlloc* this, void* data) {
}
void GameAlloc_Cleanup(GameAlloc* this) {
- GameAllocEntry* next;
+ GameAllocEntry* next = this->base.next;
GameAllocEntry* cur;
- next = this->base.next;
while (&this->base != next) {
cur = next;
next = next->next;
diff --git a/src/code/gfxprint.c b/src/code/gfxprint.c
index 27fa908ab..f79dc0050 100644
--- a/src/code/gfxprint.c
+++ b/src/code/gfxprint.c
@@ -361,7 +361,7 @@ Gfx* GfxPrint_Close(GfxPrint* this) {
}
void GfxPrint_VPrintf(GfxPrint* this, const char* fmt, va_list args) {
- PrintUtils_VPrintf(&this->callback, fmt, args);
+ PrintUtils_VPrintf((PrintCallback*)&this->callback, fmt, args);
}
void GfxPrint_Printf(GfxPrint* this, const char* fmt, ...) {
diff --git a/src/code/graph.c b/src/code/graph.c
index 9d568068c..2ad106782 100644
--- a/src/code/graph.c
+++ b/src/code/graph.c
@@ -25,18 +25,15 @@ UCodeInfo D_8012D248[3] = {
// clang-format on
void Graph_FaultClient() {
- void* nextFb;
- void* newFb;
-
- nextFb = osViGetNextFramebuffer();
- newFb = ((u32)SysCfb_GetFbPtr(0) != (u32)nextFb) ? SysCfb_GetFbPtr(0) : SysCfb_GetFbPtr(1);
+ void* nextFb = osViGetNextFramebuffer();
+ void* newFb = ((u32)SysCfb_GetFbPtr(0) != (u32)nextFb) ? SysCfb_GetFbPtr(0) : SysCfb_GetFbPtr(1);
osViSwapBuffer(newFb);
Fault_WaitForInput();
osViSwapBuffer(nextFb);
}
-void Graph_DisassembleUCode(void* arg0) {
+void Graph_DisassembleUCode(Gfx* workBuf) {
UCodeDisas disassembler;
if (HREG(80) == 7 && HREG(81) != 0) {
@@ -44,7 +41,7 @@ void Graph_DisassembleUCode(void* arg0) {
disassembler.enableLog = HREG(83);
UCodeDisas_RegisterUCode(&disassembler, ARRAY_COUNT(D_8012D230), D_8012D230);
UCodeDisas_SetCurUCode(&disassembler, D_80155F50);
- UCodeDisas_Disassemble(&disassembler, arg0);
+ UCodeDisas_Disassemble(&disassembler, workBuf);
HREG(93) = disassembler.dlCnt;
HREG(84) = disassembler.tri2Cnt * 2 + disassembler.tri1Cnt + (disassembler.quadCnt * 2) + disassembler.lineCnt;
HREG(85) = disassembler.vtxCnt;
@@ -71,21 +68,19 @@ void Graph_DisassembleUCode(void* arg0) {
}
}
-void Graph_UCodeFaultClient(void* arg0) {
+void Graph_UCodeFaultClient(Gfx* workBuf) {
UCodeDisas disassembler;
UCodeDisas_Init(&disassembler);
disassembler.enableLog = true;
UCodeDisas_RegisterUCode(&disassembler, ARRAY_COUNT(D_8012D248), D_8012D248);
UCodeDisas_SetCurUCode(&disassembler, D_80155F50);
- UCodeDisas_Disassemble(&disassembler, arg0);
+ UCodeDisas_Disassemble(&disassembler, workBuf);
UCodeDisas_Destroy(&disassembler);
}
void* Graph_InitTHGA(GraphicsContext* gfxCtx) {
- GfxPool* pool;
-
- pool = &gGfxPools[gfxCtx->gfxPoolIdx & 1];
+ GfxPool* pool = &gGfxPools[gfxCtx->gfxPoolIdx & 1];
pool->headMagic = GFXPOOL_HEAD_MAGIC;
pool->tailMagic = GFXPOOL_TAIL_MAGIC;
@@ -104,9 +99,8 @@ void* Graph_InitTHGA(GraphicsContext* gfxCtx) {
}
GameStateOverlay* Graph_GetNextGameState(GameState* gameState) {
- void* gameStateInitFunc;
+ void* gameStateInitFunc = GameState_GetInit(gameState);
- gameStateInitFunc = GameState_GetInit(gameState);
if (gameStateInitFunc == TitleSetup_Init) {
return &gGameStateOverlayTable[0];
}
@@ -149,20 +143,17 @@ void Graph_Destroy(GraphicsContext* gfxCtx) {
}
void Graph_TaskSet00(GraphicsContext* gfxCtx) {
- static u32 D_8012D260 = 0;
+ static Gfx* D_8012D260 = NULL;
static s32 sGraphCfbInfoIdx = 0;
OSTime time;
OSTimer timer;
OSMesg msg;
- OSTask_t* task;
- OSScTask* scTask;
+ OSTask_t* task = &gfxCtx->task.list.t;
+ OSScTask* scTask = &gfxCtx->task;
CfbInfo* cfb;
s32 pad1;
- task = &gfxCtx->task.list.t;
- scTask = &gfxCtx->task;
-
D_8016A528 = osGetTime() - sGraphSetTaskTime - D_8016A558;
osSetTimer(&timer, 140625000, 0, &gfxCtx->queue, (OSMesg)666);
@@ -174,8 +165,8 @@ void Graph_TaskSet00(GraphicsContext* gfxCtx) {
osSyncPrintf(VT_FGCOL(RED));
osSyncPrintf("RCPが帰ってきませんでした。"); // "RCP did not return."
osSyncPrintf(VT_RST);
- LogUtils_LogHexDump(&HW_REG(SP_MEM_ADDR_REG, u32), 0x20);
- LogUtils_LogHexDump(&DPC_START_REG, 0x20);
+ LogUtils_LogHexDump((void*)&HW_REG(SP_MEM_ADDR_REG, u32), 0x20);
+ LogUtils_LogHexDump((void*)&DPC_START_REG, 0x20);
LogUtils_LogHexDump(gGfxSPTaskYieldBuffer, sizeof(gGfxSPTaskYieldBuffer));
SREG(6) = -1;
@@ -316,8 +307,8 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
}
if (HREG(81) < 0) {
- LogUtils_LogHexDump(&HW_REG(SP_MEM_ADDR_REG, u32), 0x20);
- LogUtils_LogHexDump(&DPC_START_REG, 0x20);
+ LogUtils_LogHexDump((void*)&HW_REG(SP_MEM_ADDR_REG, u32), 0x20);
+ LogUtils_LogHexDump((void*)&DPC_START_REG, 0x20);
}
if (HREG(81) < 0) {
@@ -521,7 +512,7 @@ void* Graph_DlistAlloc(Gfx** gfx, u32 size) {
size = ((size + 7) & ~7),
- ptr = *gfx + 1;
+ ptr = (u8*)(*gfx + 1);
dst = (Gfx*)(ptr + size);
gSPBranchList(*gfx, dst);
diff --git a/src/code/irqmgr.c b/src/code/irqmgr.c
index 1a8eeffec..525a5b922 100644
--- a/src/code/irqmgr.c
+++ b/src/code/irqmgr.c
@@ -17,19 +17,19 @@ u32 sIrqMgrRetraceCount = 0;
#define STATUS_NMI 2
void IrqMgr_AddClient(IrqMgr* this, IrqMgrClient* c, OSMesgQueue* msgQ) {
- u32 prevMask;
+ u32 prevInt;
LogUtils_CheckNullPointer("this", this, "../irqmgr.c", 96);
LogUtils_CheckNullPointer("c", c, "../irqmgr.c", 97);
LogUtils_CheckNullPointer("msgQ", msgQ, "../irqmgr.c", 98);
- prevMask = osSetIntMask(1);
+ prevInt = osSetIntMask(1);
c->queue = msgQ;
c->prev = this->clients;
this->clients = c;
- osSetIntMask(prevMask);
+ osSetIntMask(prevInt);
if (this->resetStatus > STATUS_IDLE) {
osSendMesg(c->queue, (OSMesg) & this->prenmiMsg, OS_MESG_NOBLOCK);
@@ -41,19 +41,16 @@ void IrqMgr_AddClient(IrqMgr* this, IrqMgrClient* c, OSMesgQueue* msgQ) {
}
void IrqMgr_RemoveClient(IrqMgr* this, IrqMgrClient* c) {
- IrqMgrClient* iter;
- IrqMgrClient* lastIter;
- u32 prevMask;
-
- iter = this->clients;
- lastIter = NULL;
+ IrqMgrClient* iter = this->clients;
+ IrqMgrClient* lastIter = NULL;
+ u32 prevInt;
LogUtils_CheckNullPointer("this", this, "../irqmgr.c", 129);
LogUtils_CheckNullPointer("c", c, "../irqmgr.c", 130);
- prevMask = osSetIntMask(1);
+ prevInt = osSetIntMask(1);
- while (iter) {
+ while (iter != NULL) {
if (iter == c) {
if (lastIter) {
lastIter->prev = c->prev;
@@ -66,14 +63,13 @@ void IrqMgr_RemoveClient(IrqMgr* this, IrqMgrClient* c) {
iter = iter->prev;
}
- osSetIntMask(prevMask);
+ osSetIntMask(prevInt);
}
void IrqMgr_SendMesgForClient(IrqMgr* this, OSMesg msg) {
- IrqMgrClient* iter;
+ IrqMgrClient* iter = this->clients;
- iter = this->clients;
- while (iter) {
+ while (iter != NULL) {
if (iter->queue->validCount >= iter->queue->msgCount) {
// irqmgr_SendMesgForClient: Message queue is overflowing mq=%08x cnt=%d
osSyncPrintf(
@@ -88,10 +84,9 @@ void IrqMgr_SendMesgForClient(IrqMgr* this, OSMesg msg) {
}
void IrqMgr_JamMesgForClient(IrqMgr* this, OSMesg msg) {
- IrqMgrClient* iter;
+ IrqMgrClient* iter = this->clients;
- iter = this->clients;
- while (iter) {
+ while (iter != NULL) {
if (iter->queue->validCount >= iter->queue->msgCount) {
// irqmgr_JamMesgForClient: Message queue is overflowing mq=%08x cnt=%d
osSyncPrintf(
@@ -101,17 +96,17 @@ void IrqMgr_JamMesgForClient(IrqMgr* this, OSMesg msg) {
// mistake? the function's name suggests it would use osJamMesg
osSendMesg(iter->queue, msg, OS_MESG_NOBLOCK);
}
-
iter = iter->prev;
}
}
void IrqMgr_HandlePreNMI(IrqMgr* this) {
u64 temp = STATUS_PRENMI; // required to match
+
gIrqMgrResetStatus = temp;
this->resetStatus = STATUS_PRENMI;
-
sIrqMgrResetTime = this->resetTime = osGetTime();
+
osSetTimer(&this->timer, OS_USEC_TO_CYCLES(450000), 0ull, &this->queue, (OSMesg)PRENMI450_MSG);
IrqMgr_JamMesgForClient(this, (OSMesg) & this->prenmiMsg);
}
@@ -135,12 +130,14 @@ void IrqMgr_HandlePRENMI450(IrqMgr* this) {
u64 temp = STATUS_NMI; // required to match
gIrqMgrResetStatus = temp;
this->resetStatus = STATUS_NMI;
+
osSetTimer(&this->timer, OS_USEC_TO_CYCLES(30000), 0ull, &this->queue, (OSMesg)PRENMI480_MSG);
IrqMgr_SendMesgForClient(this, (OSMesg) & this->nmiMsg);
}
void IrqMgr_HandlePRENMI480(IrqMgr* this) {
u32 ret;
+
osSetTimer(&this->timer, OS_USEC_TO_CYCLES(20000), 0ull, &this->queue, (OSMesg)PRENMI500_MSG);
ret = osAfterPreNMI();
if (ret) {
@@ -167,10 +164,9 @@ void IrqMgr_HandleRetrace(IrqMgr* this) {
void IrqMgr_ThreadEntry(void* arg0) {
OSMesg msg;
- IrqMgr* this;
+ IrqMgr* this = (IrqMgr*)arg0;
u8 exit;
- this = (IrqMgr*)arg0;
msg = 0;
osSyncPrintf("IRQマネージャスレッド実行開始\n"); // Start IRQ manager thread execution
exit = false;
@@ -215,12 +211,14 @@ void IrqMgr_ThreadEntry(void* arg0) {
void IrqMgr_Init(IrqMgr* this, void* stack, OSPri pri, u8 retraceCount) {
LogUtils_CheckNullPointer("this", this, "../irqmgr.c", 346);
LogUtils_CheckNullPointer("stack", stack, "../irqmgr.c", 347);
+
this->clients = NULL;
this->retraceMsg.type = OS_SC_RETRACE_MSG;
this->prenmiMsg.type = OS_SC_PRE_NMI_MSG;
this->nmiMsg.type = OS_SC_NMI_MSG;
this->resetStatus = STATUS_IDLE;
this->resetTime = 0;
+
osCreateMesgQueue(&this->queue, this->msgBuf, ARRAY_COUNT(this->msgBuf));
osSetEventMesg(OS_EVENT_PRENMI, &this->queue, (OSMesg)PRE_NMI_MSG);
osViSetEvent(&this->queue, (OSMesg)RETRACE_MSG, retraceCount);
diff --git a/src/code/jpegdecoder.c b/src/code/jpegdecoder.c
index 238ca2439..908fc675b 100644
--- a/src/code/jpegdecoder.c
+++ b/src/code/jpegdecoder.c
@@ -13,7 +13,7 @@ s32 JpegDecoder_Decode(JpegDecoder* decoder, u16* mcuBuff, s32 count, u8 isFollo
s16 unk2;
u32 idx;
s32 inc;
- s16 unkCount;
+ u16 unkCount;
JpegHuffmanTable* hTable0;
JpegHuffmanTable* hTable1;
@@ -86,7 +86,7 @@ s32 JpegDecoder_Decode(JpegDecoder* decoder, u16* mcuBuff, s32 count, u8 isFollo
return 0;
}
-s32 JpegDecoder_ProcessMcu(JpegHuffmanTable* hTable0, JpegHuffmanTable* hTable1, s16* mcu, s16* unk) {
+s32 JpegDecoder_ProcessMcu(JpegHuffmanTable* hTable0, JpegHuffmanTable* hTable1, u16* mcu, s16* unk) {
s8 i = 0;
s8 zeroCount;
s16 coeff;
@@ -124,7 +124,7 @@ s32 JpegDecoder_ProcessMcu(JpegHuffmanTable* hTable0, JpegHuffmanTable* hTable1,
return 0;
}
-s32 JpegDecoder_ParseNextSymbol(JpegHuffmanTable* hTable, s16* outCoeff, u8* outZeroCount) {
+s32 JpegDecoder_ParseNextSymbol(JpegHuffmanTable* hTable, s16* outCoeff, s8* outZeroCount) {
u8 codeIdx;
u8 sym;
u16 codeOff = 0;
diff --git a/src/code/jpegutils.c b/src/code/jpegutils.c
index c532681b9..e0c128cc1 100644
--- a/src/code/jpegutils.c
+++ b/src/code/jpegutils.c
@@ -60,9 +60,7 @@ s32 JpegUtils_GetHuffmanCodes(u8* codesLengths, u16* codes) {
s32 JpegUtils_SetHuffmanTable(u8* data, JpegHuffmanTable* ht, u16* codes) {
u8 idx;
- u16 codeOff;
-
- codeOff = 0;
+ u16 codeOff = 0;
for (idx = 0; idx < 0x10; idx++) {
if (data[idx]) {
@@ -81,10 +79,9 @@ s32 JpegUtils_SetHuffmanTable(u8* data, JpegHuffmanTable* ht, u16* codes) {
u32 JpegUtils_ProcessHuffmanTableImpl(u8* data, JpegHuffmanTable* ht, u8* codesLengths, u16* codes, u8 isAc) {
s16 ret;
- s32 count;
+ s32 count = JpegUtils_ParseHuffmanCodesLengths(data, codesLengths);
s32 temp;
- count = JpegUtils_ParseHuffmanCodesLengths(data, codesLengths);
ret = count;
if (count == 0 || (isAc && count > 0x100) || (!isAc && count > 0x10)) {
return 0;
@@ -120,6 +117,7 @@ u32 JpegUtils_ProcessHuffmanTable(u8* dht, JpegHuffmanTable* ht, u8* codesLength
void JpegUtils_SetHuffmanTableOld(u8* data, JpegHuffmanTableOld* ht, u8* codesLengths, u16* codes, s16 count, u8 isAc) {
s16 idx;
u8 a;
+
for (idx = 0; idx < count; idx++) {
a = data[idx];
if (isAc) {
@@ -133,12 +131,10 @@ void JpegUtils_SetHuffmanTableOld(u8* data, JpegHuffmanTableOld* ht, u8* codesLe
}
u32 JpegUtils_ProcessHuffmanTableImplOld(u8* dht, JpegHuffmanTableOld* ht, u8* codesLengths, u16* codes) {
- u8 isAc;
+ u8 isAc = *dht++ >> 4;
s16 count2;
s32 count;
- isAc = *dht++ >> 4;
-
count2 = count = JpegUtils_ParseHuffmanCodesLengths(dht, codesLengths);
if (count == 0 || (isAc && count > 0x100) || (!isAc && count > 0x10)) {
diff --git a/src/code/listalloc.c b/src/code/listalloc.c
index b6aefeee2..d4d24138c 100644
--- a/src/code/listalloc.c
+++ b/src/code/listalloc.c
@@ -7,17 +7,15 @@ ListAlloc* ListAlloc_Init(ListAlloc* this) {
}
void* ListAlloc_Alloc(ListAlloc* this, u32 size) {
- ListAlloc* ptr;
+ ListAlloc* ptr = SystemArena_MallocDebug(size + sizeof(ListAlloc), "../listalloc.c", 40);
ListAlloc* next;
- ptr = SystemArena_MallocDebug(size + sizeof(ListAlloc), "../listalloc.c", 40);
- if (!ptr) {
+ if (ptr == NULL) {
return NULL;
}
next = this->next;
-
- if (next) {
+ if (next != NULL) {
next->next = ptr;
}
@@ -25,7 +23,7 @@ void* ListAlloc_Alloc(ListAlloc* this, u32 size) {
ptr->next = NULL;
this->next = ptr;
- if (!this->prev) {
+ if (this->prev == NULL) {
this->prev = ptr;
}
@@ -33,15 +31,13 @@ void* ListAlloc_Alloc(ListAlloc* this, u32 size) {
}
void ListAlloc_Free(ListAlloc* this, void* data) {
- ListAlloc* ptr;
-
- ptr = &((ListAlloc*)data)[-1];
+ ListAlloc* ptr = &((ListAlloc*)data)[-1];
- if (ptr->prev) {
+ if (ptr->prev != NULL) {
ptr->prev->next = ptr->next;
}
- if (ptr->next) {
+ if (ptr->next != NULL) {
ptr->next->prev = ptr->prev;
}
@@ -57,10 +53,9 @@ void ListAlloc_Free(ListAlloc* this, void* data) {
}
void ListAlloc_FreeAll(ListAlloc* this) {
- ListAlloc* iter;
+ ListAlloc* iter = this->prev;
- iter = this->prev;
- while (iter) {
+ while (iter != NULL) {
ListAlloc_Free(this, (u8*)iter + sizeof(ListAlloc));
iter = this->prev;
}
diff --git a/src/code/loadfragment2.c b/src/code/loadfragment2.c
index d651ff4e6..c1ee12079 100644
--- a/src/code/loadfragment2.c
+++ b/src/code/loadfragment2.c
@@ -1,9 +1,7 @@
#include "global.h"
void* Overlay_AllocateAndLoad(u32 vRomStart, u32 vRomEnd, void* vRamStart, void* vRamEnd) {
- void* allocatedVRamAddr;
-
- allocatedVRamAddr = SystemArena_MallocRDebug((s32)vRamEnd - (s32)vRamStart, "../loadfragment2.c", 31);
+ void* allocatedVRamAddr = SystemArena_MallocRDebug((s32)vRamEnd - (s32)vRamStart, "../loadfragment2.c", 31);
if (gOverlayLogSeverity >= 3) {
osSyncPrintf("OVL:SPEC(%08x-%08x) REAL(%08x-%08x) OFFSET(%08x)\n", vRamStart, vRamEnd, allocatedVRamAddr,
diff --git a/src/code/main.c b/src/code/main.c
index cf74a8b57..7e0546373 100644
--- a/src/code/main.c
+++ b/src/code/main.c
@@ -25,7 +25,7 @@ AudioMgr gAudioMgr;
OSMesgQueue sSiIntMsgQ;
OSMesg sSiIntMsgBuf[1];
-void Main_LogSystemHeap() {
+void Main_LogSystemHeap(void) {
osSyncPrintf(VT_FGCOL(GREEN));
// System heap size% 08x (% dKB) Start address% 08x
osSyncPrintf("システムヒープサイズ %08x(%dKB) 開始アドレス %08x\n", gSystemHeapSize, gSystemHeapSize / 1024,
@@ -33,7 +33,7 @@ void Main_LogSystemHeap() {
osSyncPrintf(VT_RST);
}
-void Main(void* arg0) {
+void Main(void* arg) {
IrqMgrClient irqClient;
OSMesgQueue irqMgrMsgQ;
OSMesg irqMgrMsgBuf[60];
@@ -92,13 +92,13 @@ void Main(void* arg0) {
AudioMgr_Unlock(&gAudioMgr);
StackCheck_Init(&sGraphStackInfo, sGraphStack, sGraphStack + sizeof(sGraphStack), 0, 0x100, "graph");
- osCreateThread(&sGraphThread, 4, Graph_ThreadEntry, arg0, sGraphStack + sizeof(sGraphStack), Z_PRIORITY_GRAPH);
+ osCreateThread(&sGraphThread, 4, Graph_ThreadEntry, arg, sGraphStack + sizeof(sGraphStack), Z_PRIORITY_GRAPH);
osStartThread(&sGraphThread);
osSetThreadPri(0, Z_PRIORITY_SCHED);
while (true) {
msg = NULL;
- osRecvMesg(&irqMgrMsgQ, &msg, OS_MESG_BLOCK);
+ osRecvMesg(&irqMgrMsgQ, (OSMesg)&msg, OS_MESG_BLOCK);
if (msg == NULL) {
break;
}
diff --git a/src/code/mempak.c b/src/code/mempak.c
index 9da4804eb..e423c6666 100644
--- a/src/code/mempak.c
+++ b/src/code/mempak.c
@@ -15,9 +15,8 @@ u8 sMempakExtName[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
s32 Mempak_Init(s32 controllerNb) {
OSMesgQueue* mq;
s32 pad;
- s32 ret;
+ s32 ret = false;
- ret = false;
mq = PadMgr_LockSerialMesgQueue(&gPadMgr);
if (!osPfsInitPak(mq, &sMempakPfsHandle, controllerNb)) {
@@ -35,17 +34,14 @@ s32 Mempak_GetFreeBytes(s32 controllerNb) {
}
s32 Mempak_FindFile(s32 controllerNb, char start, char end) {
-
OSMesgQueue* mq;
s32 error;
char idx;
- u32 bit;
- s32 flag;
-
- bit = 1;
- flag = 0;
+ u32 bit = 1;
+ s32 flag = 0;
mq = PadMgr_LockSerialMesgQueue(&gPadMgr);
+
for (idx = start; idx <= end; idx++) {
sMempakExtName[0] = idx - 0x27;
@@ -70,11 +66,11 @@ s32 Mempak_FindFile(s32 controllerNb, char start, char end) {
s32 Mempak_Write(s32 controllerNb, char idx, void* buffer, s32 offset, s32 size) {
OSMesgQueue* mq;
s32 error;
- s32 ret;
+ s32 ret = false;
s32 pad;
- ret = false;
mq = PadMgr_LockSerialMesgQueue(&gPadMgr);
+
if (size < sMempakFreeBytes) {
error = osPfsReadWriteFile(&sMempakPfsHandle, sMempakFiles[idx - 'A'], 1, offset, size, buffer);
if (error == 0) {
@@ -83,17 +79,18 @@ s32 Mempak_Write(s32 controllerNb, char idx, void* buffer, s32 offset, s32 size)
osSyncPrintf("mempak: write %d byte '%c' (%d)->%d\n", size, idx, sMempakFiles[idx - 'A'], error);
}
PadMgr_UnlockSerialMesgQueue(&gPadMgr, mq);
+
return ret;
}
s32 Mempak_Read(s32 controllerNb, char idx, void* buffer, s32 offset, s32 size) {
OSMesgQueue* mq;
s32 error;
- s32 ret;
+ s32 ret = false;
s32 pad;
- ret = false;
mq = PadMgr_LockSerialMesgQueue(&gPadMgr);
+
if (size < sMempakFreeBytes) {
error = osPfsReadWriteFile(&sMempakPfsHandle, sMempakFiles[idx - 'A'], 0, offset, size, buffer);
if (error == 0) {
@@ -108,12 +105,12 @@ s32 Mempak_Read(s32 controllerNb, char idx, void* buffer, s32 offset, s32 size)
s32 Mempak_Alloc(s32 controllerNb, char* idx, s32 size) {
OSMesgQueue* mq;
s32 error;
- s32 ret;
+ s32 ret = 0;
s32 i;
s32 pad;
- ret = 0;
mq = PadMgr_LockSerialMesgQueue(&gPadMgr);
+
if (*idx >= 'A' && *idx < 'L') {
sMempakExtName[0] = *idx - 0x27;
if (-1 == sMempakFiles[*idx - 'A']) {
@@ -153,16 +150,17 @@ s32 Mempak_Alloc(s32 controllerNb, char* idx, s32 size) {
}
}
PadMgr_UnlockSerialMesgQueue(&gPadMgr, mq);
+
return ret;
}
s32 Mempak_DeleteFile(s32 controllerNb, char idx) {
OSMesgQueue* mq;
s32 error;
- s32 ret;
+ s32 ret = false;
- ret = false;
mq = PadMgr_LockSerialMesgQueue(&gPadMgr);
+
sMempakExtName[0] = idx - 0x27;
error = osPfsDeleteFile(&sMempakPfsHandle, sMempakCompanyCode, sMempakGameCode, sMempakGameName, sMempakExtName);
if (error == 0) {
@@ -170,18 +168,18 @@ s32 Mempak_DeleteFile(s32 controllerNb, char idx) {
}
osSyncPrintf("mempak: delete '%c' (%d)\n", idx, error);
PadMgr_UnlockSerialMesgQueue(&gPadMgr, mq);
+
return ret;
}
s32 Mempak_GetFileSize(s32 controllerNb, char idx) {
- OSMesgQueue* mq;
+ OSMesgQueue* mq = PadMgr_LockSerialMesgQueue(&gPadMgr);
OSPfsState state;
- s32 error;
+ s32 error = osPfsFileState(&sMempakPfsHandle, sMempakFiles[idx - 'A'], &state);
s32 pad;
- mq = PadMgr_LockSerialMesgQueue(&gPadMgr);
- error = osPfsFileState(&sMempakPfsHandle, sMempakFiles[idx - 'A'], &state);
PadMgr_UnlockSerialMesgQueue(&gPadMgr, mq);
+
if (error != 0) {
return 0;
}
diff --git a/src/code/padmgr.c b/src/code/padmgr.c
index a3e32d584..e180c9f7f 100644
--- a/src/code/padmgr.c
+++ b/src/code/padmgr.c
@@ -3,69 +3,67 @@
s32 D_8012D280 = 1;
-OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padmgr) {
+OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padMgr) {
OSMesgQueue* ctrlrQ = NULL;
if (D_8012D280 > 2) {
// "serialMsgQ Waiting for lock"
osSyncPrintf("%2d %d serialMsgQロック待ち %08x %08x %08x\n", osGetThreadId(NULL),
- padmgr->serialMsgQ.validCount, padmgr, &padmgr->serialMsgQ, &ctrlrQ);
+ padMgr->serialMsgQ.validCount, padMgr, &padMgr->serialMsgQ, &ctrlrQ);
}
- osRecvMesg(&padmgr->serialMsgQ, &ctrlrQ, OS_MESG_BLOCK);
+ osRecvMesg(&padMgr->serialMsgQ, (OSMesg)&ctrlrQ, OS_MESG_BLOCK);
if (D_8012D280 > 2) {
// "serialMsgQ Locked"
osSyncPrintf("%2d %d serialMsgQをロックしました %08x\n", osGetThreadId(NULL),
- padmgr->serialMsgQ.validCount, ctrlrQ);
+ padMgr->serialMsgQ.validCount, ctrlrQ);
}
return ctrlrQ;
}
-void PadMgr_UnlockSerialMesgQueue(PadMgr* padmgr, OSMesgQueue* ctrlrQ) {
+void PadMgr_UnlockSerialMesgQueue(PadMgr* padMgr, OSMesgQueue* ctrlrQ) {
if (D_8012D280 > 2) {
// "serialMsgQ Unlock"
osSyncPrintf("%2d %d serialMsgQロック解除します %08x %08x %08x\n", osGetThreadId(NULL),
- padmgr->serialMsgQ.validCount, padmgr, &padmgr->serialMsgQ, ctrlrQ);
+ padMgr->serialMsgQ.validCount, padMgr, &padMgr->serialMsgQ, ctrlrQ);
}
- osSendMesg(&padmgr->serialMsgQ, ctrlrQ, OS_MESG_BLOCK);
+ osSendMesg(&padMgr->serialMsgQ, ctrlrQ, OS_MESG_BLOCK);
if (D_8012D280 > 2) {
// "serialMsgQ Unlocked"
osSyncPrintf("%2d %d serialMsgQロック解除しました %08x %08x %08x\n", osGetThreadId(NULL),
- padmgr->serialMsgQ.validCount, padmgr, &padmgr->serialMsgQ, ctrlrQ);
+ padMgr->serialMsgQ.validCount, padMgr, &padMgr->serialMsgQ, ctrlrQ);
}
}
-void PadMgr_LockPadData(PadMgr* padmgr) {
- osRecvMesg(&padmgr->lockMsgQ, NULL, OS_MESG_BLOCK);
+void PadMgr_LockPadData(PadMgr* padMgr) {
+ osRecvMesg(&padMgr->lockMsgQ, NULL, OS_MESG_BLOCK);
}
-void PadMgr_UnlockPadData(PadMgr* padmgr) {
- osSendMesg(&padmgr->lockMsgQ, NULL, OS_MESG_BLOCK);
+void PadMgr_UnlockPadData(PadMgr* padMgr) {
+ osSendMesg(&padMgr->lockMsgQ, NULL, OS_MESG_BLOCK);
}
-void PadMgr_RumbleControl(PadMgr* padmgr) {
+void PadMgr_RumbleControl(PadMgr* padMgr) {
static u32 errcnt = 0;
static u32 frame;
- s32 temp;
+ s32 temp = 1;
s32 triedRumbleComm;
- OSMesgQueue* ctrlrQ;
+ OSMesgQueue* ctrlrQ = PadMgr_LockSerialMesgQueue(padMgr);
s32 var4;
s32 i;
- temp = 1;
- ctrlrQ = PadMgr_LockSerialMesgQueue(padmgr);
triedRumbleComm = 0;
for (i = 0; i < 4; i++) {
- if (padmgr->ctrlrIsConnected[i]) {
- if (padmgr->padStatus[i].status & 1) {
- if (padmgr->pakType[i] == temp) {
- if (padmgr->rumbleEnable[i] != 0) {
- if (padmgr->rumbleCounter[i] < 3) {
+ if (padMgr->ctrlrIsConnected[i]) {
+ if (padMgr->padStatus[i].status & 1) {
+ if (padMgr->pakType[i] == temp) {
+ if (padMgr->rumbleEnable[i] != 0) {
+ if (padMgr->rumbleCounter[i] < 3) {
// clang-format off
if (1) {} osSyncPrintf(VT_FGCOL(YELLOW));
// clang-format on
@@ -74,20 +72,20 @@ void PadMgr_RumbleControl(PadMgr* padmgr) {
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック ぶるぶるぶるぶる");
osSyncPrintf(VT_RST);
- if (osSetRumble(&padmgr->pfs[i], temp) != 0) {
- padmgr->pakType[i] = 0;
+ if (osSetRumble(&padMgr->pfs[i], temp) != 0) {
+ padMgr->pakType[i] = 0;
osSyncPrintf(VT_FGCOL(YELLOW));
// "A communication error has occurred with the vibraton pack"
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックで通信エラーが発生しました");
osSyncPrintf(VT_RST);
} else {
- padmgr->rumbleCounter[i] = 3;
+ padMgr->rumbleCounter[i] = 3;
}
triedRumbleComm = 1;
}
} else {
- if (padmgr->rumbleCounter[i] != 0) {
+ if (padMgr->rumbleCounter[i] != 0) {
// clang-format off
if (1) {} osSyncPrintf(VT_FGCOL(YELLOW));
// clang-format on
@@ -96,14 +94,14 @@ void PadMgr_RumbleControl(PadMgr* padmgr) {
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止");
osSyncPrintf(VT_RST);
- if (osSetRumble(&padmgr->pfs[i], 0) != 0) {
- padmgr->pakType[i] = 0;
+ if (osSetRumble(&padMgr->pfs[i], 0) != 0) {
+ padMgr->pakType[i] = 0;
osSyncPrintf(VT_FGCOL(YELLOW));
// "A communication error has occurred with the vibration pack"
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックで通信エラーが発生しました");
osSyncPrintf(VT_RST);
} else {
- padmgr->rumbleCounter[i]--;
+ padMgr->rumbleCounter[i]--;
}
triedRumbleComm = 1;
@@ -111,20 +109,20 @@ void PadMgr_RumbleControl(PadMgr* padmgr) {
}
}
} else {
- if (padmgr->pakType[i] != 0) {
- if (padmgr->pakType[i] == 1) {
+ if (padMgr->pakType[i] != 0) {
+ if (padMgr->pakType[i] == 1) {
osSyncPrintf(VT_FGCOL(YELLOW));
// "It seems that a vibration pack was pulled out"
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックが抜かれたようです");
osSyncPrintf(VT_RST);
- padmgr->pakType[i] = 0;
+ padMgr->pakType[i] = 0;
} else {
osSyncPrintf(VT_FGCOL(YELLOW));
// "It seems that a controller pack that is not a vibration pack was pulled out"
osSyncPrintf("padmgr: %dコン: %s\n", i + 1,
"振動パックではないコントローラパックが抜かれたようです");
osSyncPrintf(VT_RST);
- padmgr->pakType[i] = 0;
+ padMgr->pakType[i] = 0;
}
}
}
@@ -134,19 +132,19 @@ void PadMgr_RumbleControl(PadMgr* padmgr) {
if (!triedRumbleComm) {
i = frame % 4;
- if (padmgr->ctrlrIsConnected[i] && (padmgr->padStatus[i].status & 1) && (padmgr->pakType[i] != 1)) {
- var4 = osProbeRumblePak(ctrlrQ, &padmgr->pfs[i], i);
+ if (padMgr->ctrlrIsConnected[i] && (padMgr->padStatus[i].status & 1) && (padMgr->pakType[i] != 1)) {
+ var4 = osProbeRumblePak(ctrlrQ, &padMgr->pfs[i], i);
if (var4 == 0) {
- padmgr->pakType[i] = 1;
- osSetRumble(&padmgr->pfs[i], 1);
- osSetRumble(&padmgr->pfs[i], 0);
+ padMgr->pakType[i] = 1;
+ osSetRumble(&padMgr->pfs[i], 1);
+ osSetRumble(&padMgr->pfs[i], 0);
osSyncPrintf(VT_FGCOL(YELLOW));
// "Recognized vibration pack"
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックを認識しました");
osSyncPrintf(VT_RST);
} else if (var4 == 11) {
- padmgr->pakType[i] = 2;
+ padMgr->pakType[i] = 2;
} else if (var4 == 4) {
LOG_NUM("++errcnt", ++errcnt, "../padmgr.c", 282);
osSyncPrintf(VT_FGCOL(YELLOW));
@@ -158,61 +156,59 @@ void PadMgr_RumbleControl(PadMgr* padmgr) {
}
frame++;
- PadMgr_UnlockSerialMesgQueue(padmgr, ctrlrQ);
+ PadMgr_UnlockSerialMesgQueue(padMgr, ctrlrQ);
}
-void PadMgr_RumbleStop(PadMgr* padmgr) {
+void PadMgr_RumbleStop(PadMgr* padMgr) {
s32 i;
- OSMesgQueue* ctrlrQ;
-
- ctrlrQ = PadMgr_LockSerialMesgQueue(padmgr);
+ OSMesgQueue* ctrlrQ = PadMgr_LockSerialMesgQueue(padMgr);
for (i = 0; i < 4; i++) {
- if (osProbeRumblePak(ctrlrQ, &padmgr->pfs[i], i) == 0) {
- if ((gFaultStruct.msgId == 0) && (padmgr->rumbleOnFrames != 0)) {
+ if (osProbeRumblePak(ctrlrQ, &padMgr->pfs[i], i) == 0) {
+ if ((gFaultStruct.msgId == 0) && (padMgr->rumbleOnFrames != 0)) {
osSyncPrintf(VT_FGCOL(YELLOW));
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止"); // "Stop vibration pack"
osSyncPrintf(VT_RST);
}
- osSetRumble(&padmgr->pfs[i], 0);
+ osSetRumble(&padMgr->pfs[i], 0);
}
}
- PadMgr_UnlockSerialMesgQueue(padmgr, ctrlrQ);
+ PadMgr_UnlockSerialMesgQueue(padMgr, ctrlrQ);
}
-void PadMgr_RumbleReset(PadMgr* padmgr) {
- padmgr->rumbleOffFrames = 3;
+void PadMgr_RumbleReset(PadMgr* padMgr) {
+ padMgr->rumbleOffFrames = 3;
}
-void PadMgr_RumbleSetSingle(PadMgr* padmgr, u32 ctrlr, u32 rumble) {
- padmgr->rumbleEnable[ctrlr] = rumble;
- padmgr->rumbleOnFrames = 240;
+void PadMgr_RumbleSetSingle(PadMgr* padMgr, u32 ctrlr, u32 rumble) {
+ padMgr->rumbleEnable[ctrlr] = rumble;
+ padMgr->rumbleOnFrames = 240;
}
-void PadMgr_RumbleSet(PadMgr* padmgr, u8* ctrlrRumbles) {
+void PadMgr_RumbleSet(PadMgr* padMgr, u8* ctrlrRumbles) {
s32 i;
for (i = 0; i < 4; i++) {
- padmgr->rumbleEnable[i] = ctrlrRumbles[i];
+ padMgr->rumbleEnable[i] = ctrlrRumbles[i];
}
- padmgr->rumbleOnFrames = 240;
+ padMgr->rumbleOnFrames = 240;
}
-void PadMgr_ProcessInputs(PadMgr* padmgr) {
+void PadMgr_ProcessInputs(PadMgr* padMgr) {
s32 i;
Input* input;
OSContPad* padnow1; // original name
s32 buttonDiff;
- PadMgr_LockPadData(padmgr);
+ PadMgr_LockPadData(padMgr);
- input = &padmgr->inputs[0];
- padnow1 = &padmgr->pads[0];
+ input = &padMgr->inputs[0];
+ padnow1 = &padMgr->pads[0];
- for (i = 0; i < padmgr->ncontrollers; i++, input++, padnow1++) {
+ for (i = 0; i < padMgr->nControllers; i++, input++, padnow1++) {
input->prev = input->cur;
if (1) {} // Necessary to match
@@ -220,8 +216,8 @@ void PadMgr_ProcessInputs(PadMgr* padmgr) {
switch (padnow1->errno) {
case 0:
input->cur = *padnow1;
- if (!padmgr->ctrlrIsConnected[i]) {
- padmgr->ctrlrIsConnected[i] = true;
+ if (!padMgr->ctrlrIsConnected[i]) {
+ padMgr->ctrlrIsConnected[i] = true;
osSyncPrintf(VT_FGCOL(YELLOW));
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "認識しました"); // "Recognized"
osSyncPrintf(VT_RST);
@@ -229,7 +225,7 @@ void PadMgr_ProcessInputs(PadMgr* padmgr) {
break;
case 4:
input->cur = input->prev;
- LOG_NUM("this->Key_switch[i]", padmgr->ctrlrIsConnected[i], "../padmgr.c", 380);
+ LOG_NUM("this->Key_switch[i]", padMgr->ctrlrIsConnected[i], "../padmgr.c", 380);
osSyncPrintf(VT_FGCOL(YELLOW));
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "オーバーランエラーが発生"); // "Overrun error occurred"
osSyncPrintf(VT_RST);
@@ -239,10 +235,10 @@ void PadMgr_ProcessInputs(PadMgr* padmgr) {
input->cur.stick_x = 0;
input->cur.stick_y = 0;
input->cur.errno = padnow1->errno;
- if (padmgr->ctrlrIsConnected[i]) {
- padmgr->ctrlrIsConnected[i] = false;
- padmgr->pakType[i] = 0;
- padmgr->rumbleCounter[i] = 0xFF;
+ if (padMgr->ctrlrIsConnected[i]) {
+ padMgr->ctrlrIsConnected[i] = false;
+ padMgr->pakType[i] = 0;
+ padMgr->rumbleCounter[i] = 0xFF;
osSyncPrintf(VT_FGCOL(YELLOW));
osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "応答しません"); // "Do not respond"?
osSyncPrintf(VT_RST);
@@ -261,72 +257,71 @@ void PadMgr_ProcessInputs(PadMgr* padmgr) {
input->press.stick_y += (s8)(input->cur.stick_y - input->prev.stick_y);
}
- PadMgr_UnlockPadData(padmgr);
+ PadMgr_UnlockPadData(padMgr);
}
-void PadMgr_HandleRetraceMsg(PadMgr* padmgr) {
+void PadMgr_HandleRetraceMsg(PadMgr* padMgr) {
s32 i;
- OSMesgQueue* queue;
+ OSMesgQueue* queue = PadMgr_LockSerialMesgQueue(padMgr);
u32 mask;
- queue = PadMgr_LockSerialMesgQueue(padmgr);
osContStartReadData(queue);
- if (padmgr->retraceCallback) {
- padmgr->retraceCallback(padmgr, padmgr->retraceCallbackValue);
+ if (padMgr->retraceCallback) {
+ padMgr->retraceCallback(padMgr, padMgr->retraceCallbackValue);
}
osRecvMesg(queue, NULL, OS_MESG_BLOCK);
- osContGetReadData(padmgr->pads);
- if (padmgr->preNMIShutdown) {
- bzero(padmgr->pads, sizeof(padmgr->pads));
+ osContGetReadData(padMgr->pads);
+ if (padMgr->preNMIShutdown) {
+ bzero(padMgr->pads, sizeof(padMgr->pads));
}
- PadMgr_ProcessInputs(padmgr);
+ PadMgr_ProcessInputs(padMgr);
osContStartQuery(queue);
osRecvMesg(queue, NULL, OS_MESG_BLOCK);
- osContGetQuery(padmgr->padStatus);
- PadMgr_UnlockSerialMesgQueue(padmgr, queue);
+ osContGetQuery(padMgr->padStatus);
+ PadMgr_UnlockSerialMesgQueue(padMgr, queue);
mask = 0;
for (i = 0; i < 4; i++) {
- if (padmgr->padStatus[i].errno == 0) {
- if (padmgr->padStatus[i].type == 5) {
+ if (padMgr->padStatus[i].errno == 0) {
+ if (padMgr->padStatus[i].type == 5) {
mask |= 1 << i;
} else {
- LOG_HEX("this->pad_status[i].type", padmgr->padStatus[i].type, "../padmgr.c", 458);
+ LOG_HEX("this->pad_status[i].type", padMgr->padStatus[i].type, "../padmgr.c", 458);
// "An unknown type of controller is connected"
osSyncPrintf("知らない種類のコントローラが接続されています\n");
}
}
}
- padmgr->validCtrlrsMask = mask;
+ padMgr->validCtrlrsMask = mask;
if (gFaultStruct.msgId) {
- PadMgr_RumbleStop(padmgr);
- } else if (padmgr->rumbleOffFrames > 0) {
- --padmgr->rumbleOffFrames;
- PadMgr_RumbleStop(padmgr);
- } else if (padmgr->rumbleOnFrames == 0) {
- PadMgr_RumbleStop(padmgr);
- } else if (!padmgr->preNMIShutdown) {
- PadMgr_RumbleControl(padmgr);
- --padmgr->rumbleOnFrames;
+ PadMgr_RumbleStop(padMgr);
+ } else if (padMgr->rumbleOffFrames > 0) {
+ --padMgr->rumbleOffFrames;
+ PadMgr_RumbleStop(padMgr);
+ } else if (padMgr->rumbleOnFrames == 0) {
+ PadMgr_RumbleStop(padMgr);
+ } else if (!padMgr->preNMIShutdown) {
+ PadMgr_RumbleControl(padMgr);
+ --padMgr->rumbleOnFrames;
}
}
-void PadMgr_HandlePreNMI(PadMgr* padmgr) {
+void PadMgr_HandlePreNMI(PadMgr* padMgr) {
osSyncPrintf("padmgr_HandlePreNMI()\n");
- padmgr->preNMIShutdown = true;
- PadMgr_RumbleReset(padmgr);
+ padMgr->preNMIShutdown = true;
+ PadMgr_RumbleReset(padMgr);
}
-void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 mode) {
+void PadMgr_RequestPadData(PadMgr* padMgr, Input* inputs, s32 mode) {
s32 i;
Input* ogInput;
Input* newInput;
s32 buttonDiff;
- PadMgr_LockPadData(padmgr);
+ PadMgr_LockPadData(padMgr);
- ogInput = &padmgr->inputs[0];
+ ogInput = &padMgr->inputs[0];
newInput = &inputs[0];
for (i = 0; i < 4; i++) {
if (mode != 0) {
@@ -349,10 +344,10 @@ void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 mode) {
newInput++;
}
- PadMgr_UnlockPadData(padmgr);
+ PadMgr_UnlockPadData(padMgr);
}
-void PadMgr_ThreadEntry(PadMgr* padmgr) {
+void PadMgr_ThreadEntry(PadMgr* padMgr) {
s16* mesg = NULL;
s32 exit;
@@ -361,12 +356,12 @@ void PadMgr_ThreadEntry(PadMgr* padmgr) {
exit = false;
while (!exit) {
- if ((D_8012D280 > 2) && (padmgr->interruptMsgQ.validCount == 0)) {
+ if ((D_8012D280 > 2) && (padMgr->interruptMsgQ.validCount == 0)) {
// "Waiting for controller thread event"
osSyncPrintf("コントローラスレッドイベント待ち %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
}
- osRecvMesg(&padmgr->interruptMsgQ, &mesg, OS_MESG_BLOCK);
+ osRecvMesg(&padMgr->interruptMsgQ, (OSMesg)&mesg, OS_MESG_BLOCK);
LogUtils_CheckNullPointer("msg", mesg, "../padmgr.c", 563);
switch (*mesg) {
@@ -375,7 +370,7 @@ void PadMgr_ThreadEntry(PadMgr* padmgr) {
osSyncPrintf("padmgr_HandleRetraceMsg START %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
}
- PadMgr_HandleRetraceMsg(padmgr);
+ PadMgr_HandleRetraceMsg(padMgr);
if (D_8012D280 > 2) {
osSyncPrintf("padmgr_HandleRetraceMsg END %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
@@ -383,7 +378,7 @@ void PadMgr_ThreadEntry(PadMgr* padmgr) {
break;
case OS_SC_PRE_NMI_MSG:
- PadMgr_HandlePreNMI(padmgr);
+ PadMgr_HandlePreNMI(padMgr);
break;
case OS_SC_NMI_MSG:
exit = true;
@@ -391,30 +386,30 @@ void PadMgr_ThreadEntry(PadMgr* padmgr) {
}
}
- IrqMgr_RemoveClient(padmgr->irqMgr, &padmgr->irqClient);
+ IrqMgr_RemoveClient(padMgr->irqMgr, &padMgr->irqClient);
// "Controller thread execution end"
osSyncPrintf("コントローラスレッド実行終了\n");
}
-void PadMgr_Init(PadMgr* padmgr, OSMesgQueue* siIntMsgQ, IrqMgr* irqMgr, OSId id, OSPri priority, void* stack) {
+void PadMgr_Init(PadMgr* padMgr, OSMesgQueue* siIntMsgQ, IrqMgr* irqMgr, OSId id, OSPri priority, void* stack) {
// "Pad Manager creation"
osSyncPrintf("パッドマネージャ作成 padmgr_Create()\n");
- bzero(padmgr, sizeof(PadMgr));
- padmgr->irqMgr = irqMgr;
+ bzero(padMgr, sizeof(PadMgr));
+ padMgr->irqMgr = irqMgr;
- osCreateMesgQueue(&padmgr->interruptMsgQ, padmgr->interruptMsgBuf, 4);
- IrqMgr_AddClient(padmgr->irqMgr, &padmgr->irqClient, &padmgr->interruptMsgQ);
- osCreateMesgQueue(&padmgr->serialMsgQ, padmgr->serialMsgBuf, 1);
- PadMgr_UnlockSerialMesgQueue(padmgr, siIntMsgQ);
- osCreateMesgQueue(&padmgr->lockMsgQ, padmgr->lockMsgBuf, 1);
- PadMgr_UnlockPadData(padmgr);
- PadSetup_Init(siIntMsgQ, &padmgr->validCtrlrsMask, padmgr->padStatus);
+ osCreateMesgQueue(&padMgr->interruptMsgQ, padMgr->interruptMsgBuf, 4);
+ IrqMgr_AddClient(padMgr->irqMgr, &padMgr->irqClient, &padMgr->interruptMsgQ);
+ osCreateMesgQueue(&padMgr->serialMsgQ, padMgr->serialMsgBuf, 1);
+ PadMgr_UnlockSerialMesgQueue(padMgr, siIntMsgQ);
+ osCreateMesgQueue(&padMgr->lockMsgQ, padMgr->lockMsgBuf, 1);
+ PadMgr_UnlockPadData(padMgr);
+ PadSetup_Init(siIntMsgQ, (u8*)&padMgr->validCtrlrsMask, padMgr->padStatus);
- padmgr->ncontrollers = 4;
- osContSetCh(padmgr->ncontrollers);
+ padMgr->nControllers = 4;
+ osContSetCh(padMgr->nControllers);
- osCreateThread(&padmgr->thread, id, PadMgr_ThreadEntry, padmgr, stack, priority);
- osStartThread(&padmgr->thread);
+ osCreateThread(&padMgr->thread, id, (void (*)(void*))PadMgr_ThreadEntry, padMgr, stack, priority);
+ osStartThread(&padMgr->thread);
}
diff --git a/src/code/padsetup.c b/src/code/padsetup.c
index 745a32493..e4e8a0d68 100644
--- a/src/code/padsetup.c
+++ b/src/code/padsetup.c
@@ -13,6 +13,7 @@ s32 PadSetup_Init(OSMesgQueue* mq, u8* outMask, OSContStatus* status) {
if (osContStartQuery(mq) != 0) {
return 1;
}
+
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
osContGetQuery(status);
diff --git a/src/code/padutils.c b/src/code/padutils.c
index 564cfbf6f..2f0f57162 100644
--- a/src/code/padutils.c
+++ b/src/code/padutils.c
@@ -4,7 +4,7 @@ void PadUtils_Init(Input* input) {
bzero(input, sizeof(Input));
}
-void func_800FCB70() {
+void func_800FCB70(void) {
}
void PadUtils_ResetPressRel(Input* input) {
@@ -66,11 +66,10 @@ s8 PadUtils_GetRelY(Input* input) {
}
void PadUtils_UpdateRelXY(Input* input) {
- s32 curX, curY;
- s32 relX, relY;
-
- curX = PadUtils_GetCurX(input);
- curY = PadUtils_GetCurY(input);
+ s32 curX = PadUtils_GetCurX(input);
+ s32 curY = PadUtils_GetCurY(input);
+ s32 relX;
+ s32 relY;
if (curX > 7) {
relX = (curX < 0x43) ? curX - 7 : 0x43 - 7;
diff --git a/src/code/printutils.c b/src/code/printutils.c
index 043ed8782..a965e18a8 100644
--- a/src/code/printutils.c
+++ b/src/code/printutils.c
@@ -1,12 +1,12 @@
#include "global.h"
-void PrintUtils_VPrintf(char** arg0, const char* fmt, va_list args) {
- _Printf(*arg0, arg0, fmt, args);
+void PrintUtils_VPrintf(PrintCallback* pfn, const char* fmt, va_list args) {
+ _Printf(*pfn, pfn, fmt, args);
}
-void PrintUtils_Printf(void* arg0, const char* fmt, ...) {
+void PrintUtils_Printf(PrintCallback* pfn, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
- PrintUtils_VPrintf(arg0, fmt, args);
+ PrintUtils_VPrintf(pfn, fmt, args);
}
diff --git a/src/code/relocation.c b/src/code/relocation.c
index 68f7ac7d0..c56bc9115 100644
--- a/src/code/relocation.c
+++ b/src/code/relocation.c
@@ -86,7 +86,8 @@ void Overlay_Relocate(void* allocatedVRamAddress, OverlayRelocationSection* over
vaddr = (s16)relocData;
isLoNeg = (((relocOffset + allocu32) & 0x8000) ? 1 : 0);
unrelocatedAddress = (*luiInstRef << 0x10) + vaddr;
- *luiInstRef = *luiInstRef & 0xFFFF0000 | ((((relocOffset + allocu32) >> 0x10) & 0xFFFF) + isLoNeg);
+ *luiInstRef =
+ (*luiInstRef & 0xFFFF0000) | ((((relocOffset + allocu32) >> 0x10) & 0xFFFF) + isLoNeg);
relocatedValue = (*relocDataP & 0xFFFF0000) | ((relocOffset + allocu32) & 0xFFFF);
relocatedAddress = (*luiInstRef << 0x10) + (s16)relocatedValue;
diff --git a/src/code/sched.c b/src/code/sched.c
index 5b928cb1d..9375b965b 100644
--- a/src/code/sched.c
+++ b/src/code/sched.c
@@ -15,16 +15,19 @@ OSTime sRDPStartTime;
void Sched_SwapFrameBuffer(CfbInfo* cfbInfo) {
u16 width;
+
LogUtils_CheckValidPointer("cfbinfo->swapbuffer", cfbInfo->swapBuffer, "../sched.c", 340);
if (cfbInfo->swapBuffer != NULL) {
osViSwapBuffer(cfbInfo->swapBuffer);
cfbInfo->updateRate2 = cfbInfo->updateRate;
+
if (sLogScheduler) {
osSyncPrintf("osViSwapBuffer %08x %08x %08x\n", osViGetCurrentFramebuffer(), osViGetNextFramebuffer(),
(cfbInfo != NULL ? cfbInfo->swapBuffer : NULL));
}
- width = cfbInfo->viMode != NULL ? cfbInfo->viMode->comRegs.width : gScreenWidth;
+ width = cfbInfo->viMode != NULL ? cfbInfo->viMode->comRegs.width : (u32)gScreenWidth;
Fault_SetFB(cfbInfo->swapBuffer, width, 0x10);
+
if (HREG(80) == 0xD && HREG(95) != 0xD) {
HREG(81) = 0;
HREG(82) = 0;
@@ -66,8 +69,10 @@ void func_800C84E4(SchedContext* sc, CfbInfo* cfbInfo) {
void Sched_HandleReset(SchedContext* sc) {
OSTime now;
+
if (sc->curRSPTask != NULL) {
now = osGetTime();
+
if (sc->curRSPTask->framebuffer == NULL) {
LOG_TIME("(((u64)(now - audio_rsp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))",
OS_CYCLES_TO_USEC(now - sRSPAudioStartTime), "../sched.c", 421);
@@ -94,6 +99,7 @@ void Sched_HandleStart(SchedContext* sc) {
void Sched_QueueTask(SchedContext* sc, OSScTask* task) {
s32 type = task->list.t.type;
+
if (!((type == M_AUDTASK) || (type == M_GFXTASK) || (type == M_NJPEGTASK) || (type == M_NULTASK))) {
__assert("(type == M_AUDTASK) || (type == M_GFXTASK) || (type == M_NJPEGTASK) || (type == M_NULTASK)",
"../sched.c", 463);
@@ -244,7 +250,6 @@ u32 Sched_IsComplete(SchedContext* sc, OSScTask* task) {
}
void Sched_RunTask(SchedContext* sc, OSScTask* spTask, OSScTask* dpTask) {
-
if (sc->curRSPTask != NULL) {
__assert("sc->curRSPTask == NULL", "../sched.c", 663);
}
@@ -261,6 +266,7 @@ void Sched_RunTask(SchedContext* sc, OSScTask* spTask, OSScTask* dpTask) {
Sched_IsComplete(sc, spTask);
return;
}
+
spTask->state &= ~(OS_SC_YIELD | OS_SC_YIELDED);
osWritebackDCacheAll();
osSpTaskLoad(&spTask->list);
@@ -280,6 +286,7 @@ void Sched_RunTask(SchedContext* sc, OSScTask* spTask, OSScTask* dpTask) {
(spTask->list.t.type == M_AUDTASK ? "AUDIO" : (spTask->list.t.type == M_GFXTASK ? "GRAPH" : "OTHER")));
}
sc->curRSPTask = spTask;
+
if (spTask == dpTask && sc->curRDPTask == NULL) {
sc->curRDPTask = dpTask;
sRDPStartTime = sRSPGFXStartTime;
@@ -288,14 +295,11 @@ void Sched_RunTask(SchedContext* sc, OSScTask* spTask, OSScTask* dpTask) {
}
void Sched_HandleEntry(SchedContext* sc) {
- OSScTask* nextRSP;
- OSScTask* nextRDP;
- u32 state;
- OSMesg msg;
+ OSScTask* nextRSP = NULL;
+ OSScTask* nextRDP = NULL;
+ s32 state;
+ OSMesg msg = NULL;
- nextRSP = NULL;
- nextRDP = NULL;
- msg = NULL;
while (osRecvMesg(&sc->cmdQ, &msg, OS_MESG_NOBLOCK) != -1) {
Sched_QueueTask(sc, msg);
}
@@ -307,6 +311,7 @@ void Sched_HandleEntry(SchedContext* sc) {
Sched_Yield(sc);
return;
}
+
state = ((sc->curRSPTask == 0) * 2) | (sc->curRDPTask == 0);
if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) {
Sched_RunTask(sc, nextRSP, nextRDP);
@@ -322,6 +327,7 @@ void Sched_HandleRetrace(SchedContext* sc) {
}
ViConfig_UpdateBlack();
sc->retraceCnt++;
+
if (osViGetCurrentFramebuffer() == (u32*)(sc->pendingSwapBuf1 != NULL ? sc->pendingSwapBuf1->swapBuffer : NULL)) {
if (sc->curBuf != NULL) {
sc->curBuf->unk_10 = 0;
@@ -338,7 +344,6 @@ void Sched_HandleRetrace(SchedContext* sc) {
if (sc->curBuf->updateRate2 > 0) {
sc->curBuf->updateRate2--;
}
-
if ((sc->curBuf->updateRate2 <= 0) && (sc->pendingSwapBuf1 != NULL)) {
func_800C84E4(sc, sc->pendingSwapBuf1);
}
@@ -353,12 +358,10 @@ void Sched_HandleRetrace(SchedContext* sc) {
void Sched_HandleRSPDone(SchedContext* sc) {
OSScTask* curRSPTask;
- OSScTask* nextRSP;
- OSScTask* nextRDP;
+ OSScTask* nextRSP = NULL;
+ OSScTask* nextRDP = NULL;
s32 state;
- nextRSP = NULL;
- nextRDP = NULL;
if (sc->curRSPTask == NULL) {
__assert("sc->curRSPTask", "../sched.c", 819);
}
@@ -393,6 +396,7 @@ void Sched_HandleRSPDone(SchedContext* sc) {
curRSPTask->state &= ~OS_SC_SP;
Sched_IsComplete(sc, curRSPTask);
}
+
state = ((sc->curRSPTask == NULL) << 1) | (sc->curRDPTask == NULL);
if (Sched_Schedule(sc, &nextRSP, &nextRDP, state) != state) {
Sched_RunTask(sc, nextRSP, nextRDP);
@@ -404,13 +408,10 @@ void Sched_HandleRSPDone(SchedContext* sc) {
void Sched_HandleRDPDone(SchedContext* sc) {
OSScTask* curTask;
- OSScTask* nextRSP;
- OSScTask* nextRDP;
+ OSScTask* nextRSP = NULL;
+ OSScTask* nextRDP = NULL;
s32 state;
- nextRSP = NULL;
- nextRDP = NULL;
-
gRDPTotalTime = osGetTime() - sRDPStartTime;
if (sc->curRDPTask == NULL) {
__assert("sc->curRDPTask", "../sched.c", 878);
@@ -431,12 +432,12 @@ void Sched_HandleRDPDone(SchedContext* sc) {
}
}
-void Sched_SendEntryMsg(OSMesgQueue* mq) {
+void Sched_SendEntryMsg(SchedContext* sc) {
if (sLogScheduler) {
osSyncPrintf("osScKickEntryMsg\n");
}
- osSendMesg(mq, ENTRY_MSG, OS_MESG_BLOCK);
+ osSendMesg(&sc->interruptQ, ENTRY_MSG, OS_MESG_BLOCK);
}
void Sched_ThreadEntry(void* arg) {
@@ -444,7 +445,8 @@ void Sched_ThreadEntry(void* arg) {
SchedContext* sc = (SchedContext*)arg;
msg = NULL;
- while (1) {
+
+ while (true) {
if (sLogScheduler) {
// %08d: standby
osSyncPrintf("%08d:待機中\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
diff --git a/src/code/shrink_window.c b/src/code/shrink_window.c
index c995b7c03..cc68129e2 100644
--- a/src/code/shrink_window.c
+++ b/src/code/shrink_window.c
@@ -3,11 +3,9 @@
s32 D_8012CED0 = 0;
s32 sShrinkWindowVal = 0;
-
s32 sShrinkWindowCurrentVal = 0;
void ShrinkWindow_SetVal(s32 value) {
-
if (HREG(80) == 0x13 && HREG(81) == 1) {
osSyncPrintf("shrink_window_setval(%d)\n", value);
}
diff --git a/src/code/speed_meter.c b/src/code/speed_meter.c
index 1dc6d5495..6e43ea2f9 100644
--- a/src/code/speed_meter.c
+++ b/src/code/speed_meter.c
@@ -62,9 +62,9 @@ void SpeedMeter_DrawTimeEntries(SpeedMeter* this, GraphicsContext* gfxCtx) {
return;
}
- gSpeedMeterTimeEntryPtr = &sSpeedMeterTimeEntryArray;
+ gSpeedMeterTimeEntryPtr = &sSpeedMeterTimeEntryArray[0];
for (i = 0; i < ARRAY_COUNT(sSpeedMeterTimeEntryArray); i++) {
- temp = ((f64)*gSpeedMeterTimeEntryPtr->time / gIrqMgrRetraceTime) * 64.0;
+ temp = ((f64) * (gSpeedMeterTimeEntryPtr->time) / gIrqMgrRetraceTime) * 64.0;
gSpeedMeterTimeEntryPtr->x = temp + baseX;
gSpeedMeterTimeEntryPtr++;
}
@@ -88,7 +88,7 @@ void SpeedMeter_DrawTimeEntries(SpeedMeter* this, GraphicsContext* gfxCtx) {
DrawRec(gfx++, GPACK_RGBA5551(255, 0, 0, 1), baseX + 64 * 2, uly, baseX + 64 * 3, lry);
DrawRec(gfx++, GPACK_RGBA5551(255, 0, 255, 1), baseX + 64 * 3, uly, baseX + 64 * 4, lry);
- gSpeedMeterTimeEntryPtr = sSpeedMeterTimeEntryArray;
+ gSpeedMeterTimeEntryPtr = &sSpeedMeterTimeEntryArray[0];
for (i = 0; i < ARRAY_COUNT(sSpeedMeterTimeEntryArray); i++) {
DrawRec(gfx++, gSpeedMeterTimeEntryPtr->color, baseX, lry + gSpeedMeterTimeEntryPtr->y,
gSpeedMeterTimeEntryPtr->x, lry + gSpeedMeterTimeEntryPtr->y + 1);
@@ -178,7 +178,7 @@ void SpeedMeter_DrawAllocEntries(SpeedMeter* meter, GraphicsContext* gfxCtx, Gam
}
if (SREG(0) > 1) {
- SystemArena_GetSizes(&sysFreeMax, &sysFree, &sysAlloc);
+ SystemArena_GetSizes((u32*)&sysFreeMax, (u32*)&sysFree, (u32*)&sysAlloc);
SpeedMeter_InitAllocEntry(&entry, sysFree + sysAlloc - state->tha.size, sysAlloc - state->tha.size,
GPACK_RGBA5551(0, 0, 255, 1), GPACK_RGBA5551(255, 128, 128, 1), ulx, lrx, y, y);
SpeedMeter_DrawAllocEntry(&entry, gfxCtx);
diff --git a/src/code/sys_cfb.c b/src/code/sys_cfb.c
index aab304465..8d3c28040 100644
--- a/src/code/sys_cfb.c
+++ b/src/code/sys_cfb.c
@@ -6,6 +6,7 @@ u32 sSysCfbEnd;
void SysCfb_Init(s32 n64dd) {
u32 screenSize;
u32 tmpFbEnd;
+
if (osMemSize >= 0x800000U) {
// 8MB or more memory is installed
osSyncPrintf("8Mバイト以上のメモリが搭載されています\n");
diff --git a/src/code/sys_math.c b/src/code/sys_math.c
index c72d8cbee..9e65cdaa3 100644
--- a/src/code/sys_math.c
+++ b/src/code/sys_math.c
@@ -17,7 +17,7 @@ f32 Math_Factorial(s32 n) {
f32 ret;
s32 i;
- if (n > 12U) {
+ if ((u32)n > 12U) {
ret = sFactorialTbl[12];
for (i = 13; i <= n; i++) {
ret *= i;
diff --git a/src/code/sys_math3d.c b/src/code/sys_math3d.c
index 6ca814f36..608e6cf11 100644
--- a/src/code/sys_math3d.c
+++ b/src/code/sys_math3d.c
@@ -201,7 +201,7 @@ s32 Math3D_PlaneVsPlaneVsLineClosestPoint(f32 planeAA, f32 planeAB, f32 planeAC,
static Linef planeIntersect;
if (!Math3D_PlaneVsPlaneNewLine(planeAA, planeAB, planeAC, planeADist, planeBA, planeBB, planeBC, planeBDist,
- &planeIntersect)) {
+ (InfiniteLine*)&planeIntersect)) {
return false;
}
Math3D_LineClosestToPoint(&planeIntersect, point, closestPoint);
diff --git a/src/code/sys_math_atan.c b/src/code/sys_math_atan.c
index d2f1b3467..02f515327 100644
--- a/src/code/sys_math_atan.c
+++ b/src/code/sys_math_atan.c
@@ -78,11 +78,9 @@ static u16 sATan2Tbl[] = {
};
u16 Math_GetAtan2Tbl(f32 x, f32 y) {
- s32 tblIdx;
+ s32 tblIdx = ((x / y) * 1024.0f) + 0.5f;
u16 ret;
- tblIdx = ((x / y) * 1024.0f) + 0.5f;
-
if (y == 0.0f) {
ret = sATan2Tbl[0];
} else if (tblIdx >= ARRAY_COUNT(sATan2Tbl)) {
diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c
index 0ce2e74c2..5a926382e 100644
--- a/src/code/sys_matrix.c
+++ b/src/code/sys_matrix.c
@@ -294,7 +294,7 @@ void Matrix_RotateZ(f32 z, u8 mode) {
}
}
-/*
+/**
* Rotates the top of the matrix stack by `z` degrees, then
* rotates that matrix by `y` degrees, then rotates that matrix
* by `x` degrees. (roll-pitch-yaw)
@@ -385,19 +385,16 @@ void Matrix_RotateRPY(s16 x, s16 y, s16 z, u8 mode) {
}
}
-/*
+/**
* Roll-pitch-yaw rotation and position
*/
void Matrix_JointPosition(Vec3f* position, Vec3s* rotation) {
MtxF* cmf = sCurrentMatrix;
- f32 sin;
- f32 cos;
+ f32 sin = Math_SinS(rotation->z);
+ f32 cos = Math_CosS(rotation->z);
f32 temp1;
f32 temp2;
- sin = Math_SinS(rotation->z);
- cos = Math_CosS(rotation->z);
-
temp1 = cmf->xx;
temp2 = cmf->yx;
cmf->wx += temp1 * position->x + temp2 * position->y + cmf->zx * position->z;
@@ -475,14 +472,11 @@ void Matrix_JointPosition(Vec3f* position, Vec3s* rotation) {
void func_800D1694(f32 x, f32 y, f32 z, Vec3s* vec) {
MtxF* cmf = sCurrentMatrix;
- f32 sp30;
- f32 sp2C;
+ f32 sp30 = Math_SinS(vec->y);
+ f32 sp2C = Math_CosS(vec->y);
f32 sp28;
f32 sp24;
- sp30 = Math_SinS(vec->y);
- sp2C = Math_CosS(vec->y);
-
cmf->xx = sp2C;
cmf->xz = -sp30;
cmf->wx = x;
diff --git a/src/code/sys_ucode.c b/src/code/sys_ucode.c
index 34e782387..5ead2320c 100644
--- a/src/code/sys_ucode.c
+++ b/src/code/sys_ucode.c
@@ -3,18 +3,18 @@
u32 D_8012DBA0 = (u32)&D_80155F50;
u32 D_8012DBA4 = (u32)&D_80157580;
-u32 SysUcode_GetUCodeBoot() {
+u32 SysUcode_GetUCodeBoot(void) {
return &D_80009320;
}
-u32 SysUcode_GetUCodeBootSize() {
+u32 SysUcode_GetUCodeBootSize(void) {
return (u32)&D_800093F0 - (u32)&D_80009320;
}
-u32 SysUcode_GetUCode() {
+u32 SysUcode_GetUCode(void) {
return D_8012DBA0;
}
-u32 SysUcode_GetUCodeData() {
+u32 SysUcode_GetUCodeData(void) {
return D_8012DBA4;
}
diff --git a/src/code/system_malloc.c b/src/code/system_malloc.c
index be55cb76c..7311ce102 100644
--- a/src/code/system_malloc.c
+++ b/src/code/system_malloc.c
@@ -8,7 +8,7 @@ s32 gSystemArenaLogSeverity = LOG_SEVERITY_NOLOG;
Arena gSystemArena;
void SystemArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action) {
- if (!ptr) {
+ if (ptr == NULL) {
if (gSystemArenaLogSeverity >= LOG_SEVERITY_ERROR) {
// "%s: %u bytes %s failed\n"
osSyncPrintf("%s: %u バイトの%sに失敗しました\n", name, size, action);
@@ -22,29 +22,29 @@ void SystemArena_CheckPointer(void* ptr, u32 size, const char* name, const char*
}
void* SystemArena_Malloc(u32 size) {
- void* ptr;
- ptr = __osMalloc(&gSystemArena, size);
+ void* ptr = __osMalloc(&gSystemArena, size);
+
SystemArena_CheckPointer(ptr, size, "malloc", "確保"); // Secure
return ptr;
}
void* SystemArena_MallocDebug(u32 size, const char* file, s32 line) {
- void* ptr;
- ptr = __osMallocDebug(&gSystemArena, size, file, line);
+ void* ptr = __osMallocDebug(&gSystemArena, size, file, line);
+
SystemArena_CheckPointer(ptr, size, "malloc_DEBUG", "確保"); // Secure
return ptr;
}
void* SystemArena_MallocR(u32 size) {
- void* ptr;
- ptr = __osMallocR(&gSystemArena, size);
+ void* ptr = __osMallocR(&gSystemArena, size);
+
SystemArena_CheckPointer(ptr, size, "malloc_r", "確保"); // Secure
return ptr;
}
void* SystemArena_MallocRDebug(u32 size, const char* file, s32 line) {
- void* ptr;
- ptr = __osMallocRDebug(&gSystemArena, size, file, line);
+ void* ptr = __osMallocRDebug(&gSystemArena, size, file, line);
+
SystemArena_CheckPointer(ptr, size, "malloc_r_DEBUG", "確保"); // Secure
return ptr;
}
@@ -71,11 +71,10 @@ void SystemArena_FreeDebug(void* ptr, const char* file, s32 line) {
void* SystemArena_Calloc(u32 num, u32 size) {
void* ret;
- u32 n;
+ u32 n = num * size;
- n = num * size;
ret = __osMalloc(&gSystemArena, n);
- if (ret) {
+ if (ret != NULL) {
bzero(ret, n);
}
@@ -83,7 +82,7 @@ void* SystemArena_Calloc(u32 num, u32 size) {
return ret;
}
-void SystemArena_Display() {
+void SystemArena_Display(void) {
// System heap display
osSyncPrintf("システムヒープ表示\n");
__osDisplayArena(&gSystemArena);
@@ -93,7 +92,7 @@ void SystemArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc) {
ArenaImpl_GetSizes(&gSystemArena, outMaxFree, outFree, outAlloc);
}
-void SystemArena_Check() {
+void SystemArena_Check(void) {
__osCheckArena(&gSystemArena);
}
@@ -102,11 +101,11 @@ void SystemArena_Init(void* start, u32 size) {
__osMallocInit(&gSystemArena, start, size);
}
-void SystemArena_Cleanup() {
+void SystemArena_Cleanup(void) {
gSystemArenaLogSeverity = LOG_SEVERITY_NOLOG;
__osMallocCleanup(&gSystemArena);
}
-u8 SystemArena_IsInitalized() {
+u8 SystemArena_IsInitalized(void) {
return __osMallocIsInitalized(&gSystemArena);
}
diff --git a/src/code/z_actor.c b/src/code/z_actor.c
index 7c333f80a..ccab8a9f1 100644
--- a/src/code/z_actor.c
+++ b/src/code/z_actor.c
@@ -1278,13 +1278,13 @@ void Actor_UpdateBgCheckInfo(GlobalContext* globalCtx, Actor* actor, f32 arg2, f
}
}
-s32 D_8015BBA8[16];
+Mtx D_8015BBA8;
Gfx* func_8002E830(Vec3f* object, Vec3f* eye, Vec3f* lightDir, GraphicsContext* gfxCtx, Gfx* gfx, Hilite** hilite) {
- Gfx* lookAt;
+ LookAt* lookAt;
f32 correctedEyeX;
- lookAt = Graph_Alloc(gfxCtx, 4 * sizeof(Gfx));
+ lookAt = Graph_Alloc(gfxCtx, sizeof(LookAt));
correctedEyeX = (eye->x == object->x) && (eye->z == object->z) ? eye->x + 0.001f : eye->x;
@@ -1777,8 +1777,8 @@ void func_8002FA60(GlobalContext* globalCtx) {
Vec3f D_80116048 = { 0.0f, -0.05f, 0.0f };
Vec3f D_80116054 = { 0.0f, -0.025f, 0.0f };
-Color_RGB8 D_80116060 = { 255, 255, 255 };
-Color_RGB8 D_80116064 = { 100, 200, 0 };
+Color_RGBA8 D_80116060 = { 255, 255, 255, 0 };
+Color_RGBA8 D_80116064 = { 100, 200, 0, 0 };
#ifdef NON_MATCHING
// saved register, stack usage and minor ordering differences
@@ -2754,7 +2754,7 @@ Actor* Actor_Spawn(ActorContext* actorCtx, GlobalContext* globalCtx, s16 actorId
osSyncPrintf("アクタークライアントは %d 個目です\n", overlayEntry->nbLoaded);
}
- Lib_MemSet(actor, actorInit->instanceSize, 0);
+ Lib_MemSet((u8*)actor, actorInit->instanceSize, 0);
actor->overlayEntry = overlayEntry;
actor->id = actorInit->id;
actor->flags = actorInit->flags;
@@ -2982,7 +2982,7 @@ Actor* func_80032AF0(GlobalContext* globalCtx, ActorContext* actorCtx, Actor** a
}
if (D_8015BBE8 == NULL) {
- for (i; i < ARRAY_COUNT(D_801160A0); i++) {
+ for (; i < ARRAY_COUNT(D_801160A0); i++) {
func_800328D4(globalCtx, actorCtx, player, *entry);
entry++;
}
@@ -3062,9 +3062,9 @@ void func_80032E24(struct_80032E24* arg0, s32 arg1, GlobalContext* globalCtx) {
sp20 = (arg1 * sizeof(*arg0->unk_04)) + sizeof(*arg0->unk_04);
arg0->unk_04 = ZeldaArena_MallocDebug(sp20, "../z_actor.c", 7546);
if (arg0->unk_04 != NULL) {
- Lib_MemSet(arg0->unk_00, sp28, 0);
- Lib_MemSet(arg0->unk_0C, sp24, 0);
- Lib_MemSet(arg0->unk_04, sp20, 0);
+ Lib_MemSet((u8*)arg0->unk_00, sp28, 0);
+ Lib_MemSet((u8*)arg0->unk_0C, sp24, 0);
+ Lib_MemSet((u8*)arg0->unk_04, sp20, 0);
arg0->unk_10 = 1;
return;
}
@@ -3099,7 +3099,7 @@ void func_80032F54(struct_80032E24* arg0, s32 arg1, s32 arg2, s32 arg3, u32 arg4
arg0->unk_08++;
}
- if (arg0->unk_08 >= arg4) {
+ if ((u32)arg0->unk_08 >= arg4) {
arg0->unk_08 = arg0->unk_10 - 1;
arg0->unk_10 = -1;
}
@@ -3964,8 +3964,8 @@ s32 func_800354B4(GlobalContext* globalCtx, Actor* actor, f32 range, s16 arg3, s
}
void func_8003555C(GlobalContext* globalCtx, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3) {
- Color_RGB8 color1;
- Color_RGB8 color2;
+ Color_RGBA8 color1;
+ Color_RGBA8 color2;
color1.r = 200;
color1.g = 160;
@@ -3975,6 +3975,7 @@ void func_8003555C(GlobalContext* globalCtx, Vec3f* arg1, Vec3f* arg2, Vec3f* ar
color2.g = 90;
color2.b = 50;
+ //! @bug color1 and color2 alpha components not set before being passed on
EffectSsKiraKira_SpawnSmall(globalCtx, arg1, arg2, arg3, &color1, &color2);
}
diff --git a/src/code/z_actor_dlftbls.c b/src/code/z_actor_dlftbls.c
index a03019b72..eccf2e948 100644
--- a/src/code/z_actor_dlftbls.c
+++ b/src/code/z_actor_dlftbls.c
@@ -498,7 +498,7 @@ void ActorOverlayTable_LogPrint(void) {
osSyncPrintf("actor_dlftbls %u\n", gMaxActorId);
osSyncPrintf("RomStart RomEnd SegStart SegEnd allocp profile segname\n");
- for (i = 0, overlayEntry = &gActorOverlayTable[0]; i < gMaxActorId; i++, overlayEntry++) {
+ for (i = 0, overlayEntry = &gActorOverlayTable[0]; i < (u32)gMaxActorId; i++, overlayEntry++) {
osSyncPrintf("%08x %08x %08x %08x %08x %08x %s\n", overlayEntry->vromStart, overlayEntry->vromEnd,
overlayEntry->vramStart, overlayEntry->vramEnd, overlayEntry->loadedRamAddr,
&overlayEntry->initInfo->id, overlayEntry->name != NULL ? overlayEntry->name : "?");
diff --git a/src/code/z_bgcheck.c b/src/code/z_bgcheck.c
index c02865a2d..1ab7e228a 100644
--- a/src/code/z_bgcheck.c
+++ b/src/code/z_bgcheck.c
@@ -154,7 +154,9 @@ void BgCheck_Vec3fToVec3s(Vec3s* dst, Vec3f* src) {
* Get CollisionPoly's lowest y point
*/
s16 CollisionPoly_GetMinY(CollisionPoly* poly, Vec3s* vtxList) {
- s32 a, b, c;
+ s32 a;
+ s32 b;
+ s32 c;
s16 min;
if (poly->normal.y == COLPOLY_SNORMAL(1.0f) || poly->normal.y == COLPOLY_SNORMAL(-1.0f)) {
@@ -698,6 +700,7 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
}
(!IS_ZERO(normalXZ)) ? (void)0 : __assert("!IS_ZERO(ac_size)", "../z_bgcheck.c", 2854);
+
invNormalXZ = 1.0f / normalXZ;
temp_f16 = fabsf(nz) * invNormalXZ;
if (temp_f16 < 0.4f) {
@@ -778,6 +781,7 @@ s32 BgCheck_SphVsStaticWall(StaticLookup* lookup, CollisionContext* colCtx, u16
}
(!IS_ZERO(normalXZ)) ? (void)0 : __assert("!IS_ZERO(ac_size)", "../z_bgcheck.c", 2964);
+
invNormalXZ = 1.0f / normalXZ;
temp_f16 = fabsf(nx) * invNormalXZ;
if (temp_f16 < 0.4f) {
@@ -876,9 +880,11 @@ s32 BgCheck_CheckStaticCeiling(StaticLookup* lookup, u16 xpFlags, CollisionConte
}
}
curPoly = &polyList[curPolyId];
+
if (CollisionPoly_CheckYIntersectApprox2(curPoly, vtxList, pos->x, pos->z, &ceilingY)) {
f32 intersectDist = ceilingY - *outY;
f32 ny = COLPOLY_GET_NORMAL(curPoly->normal.y);
+
if (intersectDist > 0.0f && intersectDist < checkHeight && intersectDist * ny <= 0) {
*outY = ceilingY - checkHeight;
*outPoly = curPoly;
@@ -971,6 +977,7 @@ s32 func_8003A5B8(SSList* ssList, CollisionContext* colCtx, u16 xpFlags1, u16 xp
s32 func_8003A7D8(StaticLookup* lookup, CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2, Vec3f* posA, Vec3f* posB,
Vec3f* outPos, CollisionPoly** outPoly, f32 chkDist, f32* outDistSq, u32 bccFlags) {
s32 result = false;
+
if ((bccFlags & BGCHECK_CHECK_FLOOR) && lookup->floor.head != SS_NULL) {
if (func_8003A5B8(&lookup->floor, colCtx, xpFlags1, xpFlags2, posA, posB, outPos, outPoly, outDistSq, chkDist,
bccFlags)) {
@@ -1001,15 +1008,12 @@ s32 func_8003A7D8(StaticLookup* lookup, CollisionContext* colCtx, u16 xpFlags1,
*/
s32 BgCheck_SphVsFirstStaticPolyList(SSNode* node, u16 xpFlags, CollisionContext* colCtx, Vec3f* center, f32 radius,
CollisionPoly** outPoly) {
- CollisionPoly* polyList;
- Vec3s* vtxList;
+ CollisionPoly* polyList = colCtx->colHeader->polyList;
+ Vec3s* vtxList = colCtx->colHeader->vtxList;
CollisionPoly* curPoly;
u16 nextId;
s16 curPolyId;
- polyList = colCtx->colHeader->polyList;
- vtxList = colCtx->colHeader->vtxList;
-
while (true) {
curPolyId = node->polyId;
curPoly = &polyList[curPolyId];
@@ -1027,6 +1031,7 @@ s32 BgCheck_SphVsFirstStaticPolyList(SSNode* node, u16 xpFlags, CollisionContext
center->y + radius < vtxList[curPoly->vIC].y) {
break;
}
+
if (CollisionPoly_SphVsPoly(curPoly, vtxList, center, radius)) {
*outPoly = curPoly;
return true;
@@ -1195,12 +1200,11 @@ void func_8003B218(CollisionContext* colCtx, Vec3s* vtxList, CollisionPoly* poly
f32 z;
Vec3s* vtx;
- s16 vtxId;
-
- vtxId = COLPOLY_VTX_INDEX(polyList[polyId].vtxData[0]);
+ s16 vtxId = COLPOLY_VTX_INDEX(polyList[polyId].vtxData[0]);
Math_Vec3s_ToVec3f(&maxVtx, &vtxList[vtxId]);
Math_Vec3f_Copy(&minVtx, &maxVtx);
+
for (vtxDataTemp = polyList[polyId].vtxData + 1; vtxDataTemp < polyList[polyId].vtxData + 3; vtxDataTemp++) {
vtxId = COLPOLY_VTX_INDEX(*vtxDataTemp);
vtx = &vtxList[vtxId];
@@ -1257,16 +1261,19 @@ s32 func_8003B3C8(Vec3f* min, Vec3f* max, CollisionPoly* polyList, Vec3s* vtxLis
if (flags[0] == 0) {
return true;
}
+
BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)], &vb);
flags[1] = Math3D_PointRelativeToCubeFaces(&vb, min, max);
if (flags[1] == 0) {
return true;
}
+
BgCheck_Vec3sToVec3f(&vtxList[poly->vIC], &vc);
flags[2] = Math3D_PointRelativeToCubeFaces(&vc, min, max);
if (flags[2] == 0) {
return true;
}
+
if (flags[0] & flags[1] & flags[2]) {
return false;
}
@@ -1287,6 +1294,7 @@ s32 func_8003B3C8(Vec3f* min, Vec3f* max, CollisionPoly* polyList, Vec3s* vtxLis
CollisionPoly_GetNormalF(poly, &nx, &ny, &nz);
dist = poly->dist;
+
if (Math3D_TriChkLineSegParaYIntersect(&va, &vb, &vc, nx, ny, nz, dist, min->z, min->x, &intersect, min->y,
max->y) ||
Math3D_TriChkLineSegParaYIntersect(&va, &vb, &vc, nx, ny, nz, dist, max->z, min->x, &intersect, min->y,
@@ -1317,6 +1325,7 @@ s32 func_8003B3C8(Vec3f* min, Vec3f* max, CollisionPoly* polyList, Vec3s* vtxLis
max->x)) {
return true;
}
+
BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)], &va2);
BgCheck_Vec3sToVec3f(&vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)], &vb2);
BgCheck_Vec3sToVec3f(&vtxList[poly->vIC], &vc2);
@@ -1350,7 +1359,7 @@ u32 func_8003BB18(CollisionContext* colCtx, GlobalContext* globalCtx, StaticLook
// subdiv min/max bounds for adding a poly
Vec3f curSubdivMin;
Vec3f curSubdivMax;
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = colCtx->colHeader;
StaticLookup* spA4;
StaticLookup* phi_fp;
StaticLookup* phi_s0;
@@ -1359,14 +1368,13 @@ u32 func_8003BB18(CollisionContext* colCtx, GlobalContext* globalCtx, StaticLook
f32 subdivLengthY;
f32 subdivLengthZ;
- colHeader = colCtx->colHeader;
-
for (spA4 = lookupTbl;
spA4 < (colCtx->subdivAmount.x * colCtx->subdivAmount.y * colCtx->subdivAmount.z + lookupTbl); spA4++) {
spA4->floor.head = SS_NULL;
spA4->wall.head = SS_NULL;
spA4->ceiling.head = SS_NULL;
}
+
polyMax = colHeader->nbPolygons;
vtxList = colHeader->vtxList;
polyList = colHeader->polyList;
@@ -1377,7 +1385,6 @@ u32 func_8003BB18(CollisionContext* colCtx, GlobalContext* globalCtx, StaticLook
for (polyIdx = 0; polyIdx < polyMax; polyIdx++) {
func_8003B218(colCtx, vtxList, polyList, &sxMin, &syMin, &szMin, &sxMax, &syMax, &szMax, polyIdx);
-
spA4 = szMin * sp98 + lookupTbl;
curSubdivMin.z = (colCtx->subdivLength.z * szMin + colCtx->minBounds.z) - BGCHECK_SUBDIV_OVERLAP;
curSubdivMax.z = curSubdivMin.z + subdivLengthZ;
@@ -1446,6 +1453,7 @@ s32 BgCheck_TryGetCustomMemsize(s32 sceneId, u32* memSize) {
{ SCENE_HIDAN, 0x198C8 }, { SCENE_GANON_BOSS, 0x84C8 },
};
s32 i;
+
for (i = 0; i < ARRAY_COUNT(sceneMemList); i++) {
if (sceneId == sceneMemList[i].sceneId) {
*memSize = sceneMemList[i].memSize;
@@ -1493,17 +1501,18 @@ void BgCheck_Allocate(CollisionContext* colCtx, GlobalContext* globalCtx, Collis
colCtx->colHeader = colHeader;
customNodeListMax = -1;
- osSyncPrintf("/*---------------- BGCheck バッファーメモリサイズ -------------*/\n");
+
// /*---------------- BGCheck Buffer Memory Size -------------*/\n
+ osSyncPrintf("/*---------------- BGCheck バッファーメモリサイズ -------------*/\n");
if (YREG(15) == 0x10 || YREG(15) == 0x20 || YREG(15) == 0x30 || YREG(15) == 0x40) {
if (globalCtx->sceneNum == SCENE_MALON_STABLE) {
- osSyncPrintf("/* BGCheck LonLonサイズ %dbyte */\n", 0x3520);
// /* BGCheck LonLon Size %dbyte */\n
+ osSyncPrintf("/* BGCheck LonLonサイズ %dbyte */\n", 0x3520);
colCtx->memSize = 0x3520;
} else {
- osSyncPrintf("/* BGCheck ミニサイズ %dbyte */\n", 0x4E20);
// /* BGCheck Mini Size %dbyte */\n
+ osSyncPrintf("/* BGCheck ミニサイズ %dbyte */\n", 0x4E20);
colCtx->memSize = 0x4E20;
}
colCtx->dyna.polyNodesMax = 500;
@@ -1514,8 +1523,8 @@ void BgCheck_Allocate(CollisionContext* colCtx, GlobalContext* globalCtx, Collis
colCtx->subdivAmount.z = 2;
} else if (BgCheck_IsSpotScene(globalCtx) == true) {
colCtx->memSize = 0xF000;
- osSyncPrintf("/* BGCheck Spot用サイズ %dbyte */\n", 0xF000);
// /* BGCheck Spot Size %dbyte */\n
+ osSyncPrintf("/* BGCheck Spot用サイズ %dbyte */\n", 0xF000);
colCtx->dyna.polyNodesMax = 1000;
colCtx->dyna.polyListMax = 512;
colCtx->dyna.vtxListMax = 512;
@@ -1528,8 +1537,8 @@ void BgCheck_Allocate(CollisionContext* colCtx, GlobalContext* globalCtx, Collis
} else {
colCtx->memSize = 0x1CC00;
}
- osSyncPrintf("/* BGCheck ノーマルサイズ %dbyte */\n", colCtx->memSize);
// /* BGCheck Normal Size %dbyte */\n
+ osSyncPrintf("/* BGCheck ノーマルサイズ %dbyte */\n", colCtx->memSize);
colCtx->dyna.polyNodesMax = 1000;
colCtx->dyna.polyListMax = 512;
colCtx->dyna.vtxListMax = 512;
@@ -1781,6 +1790,7 @@ f32 BgCheck_AnyRaycastFloor1(CollisionContext* colCtx, CollisionPoly* outPoly, V
s32 bgId;
result = BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_NONE, &tempPoly, &bgId, pos, NULL, 0x1C, 1.0f);
+
if (tempPoly != NULL) {
*outPoly = *tempPoly;
}
@@ -1793,9 +1803,8 @@ f32 BgCheck_AnyRaycastFloor1(CollisionContext* colCtx, CollisionPoly* outPoly, V
*/
f32 BgCheck_AnyRaycastFloor2(CollisionContext* colCtx, CollisionPoly* outPoly, s32* bgId, Vec3f* pos) {
CollisionPoly* tempPoly;
- f32 result;
+ f32 result = BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_NONE, &tempPoly, bgId, pos, NULL, 0x1C, 1.0f);
- result = BgCheck_RaycastFloorImpl(NULL, colCtx, COLPOLY_IGNORE_NONE, &tempPoly, bgId, pos, NULL, 0x1C, 1.0f);
if (tempPoly != NULL) {
*outPoly = *tempPoly;
}
@@ -1866,12 +1875,14 @@ s32 BgCheck_SphVsWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
dx = posNext->x - posPrev->x;
dy = posNext->y - posPrev->y;
dz = posNext->z - posPrev->z;
+
if (BgCheck_PosErrorCheck(posNext, "../z_bgcheck.c", 4831) == true ||
BgCheck_PosErrorCheck(posPrev, "../z_bgcheck.c", 4832) == true) {
if (actor != NULL) {
osSyncPrintf("こいつ,pself_actor->name %d\n", actor->id);
}
}
+
// if there's movement on the xz plane, and argA flag is 0,
if ((dx != 0.0f || dz != 0.0f) && (argA & 1) == 0) {
if ((checkHeight + dy) < 5.0f) {
@@ -1934,6 +1945,7 @@ s32 BgCheck_SphVsWallImpl(CollisionContext* colCtx, u16 xpFlags, Vec3f* posResul
}
}
}
+
sphCenter = *posResult;
dynaPolyCollision = false;
sphCenter.y += checkHeight;
@@ -2109,14 +2121,14 @@ s32 BgCheck_EntityCheckCeiling(CollisionContext* colCtx, f32* outY, Vec3f* pos,
s32 BgCheck_LineTestImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2, Vec3f* posA, Vec3f* posB,
Vec3f* posResult, CollisionPoly** outPoly, s32* outBgId, Actor* actor, f32 chkDist,
u32 bccFlags) {
- StaticLookup* lookupTbl;
+ StaticLookup* lookupTbl = colCtx->lookupTbl;
StaticLookup* iLookup;
s32 subdivMin[3];
s32 subdivMax[3];
s32 i;
s32 result;
f32 distSq;
- Vec3f posBTemp;
+ Vec3f posBTemp = *posB;
Vec3f sectorMin;
Vec3f sectorMax;
s32 k;
@@ -2125,8 +2137,6 @@ s32 BgCheck_LineTestImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2, V
StaticLookup* jLookup;
s32 temp_lo;
- lookupTbl = colCtx->lookupTbl;
- posBTemp = *posB;
*outBgId = BGCHECK_SCENE;
if (BgCheck_PosErrorCheck(posA, "../z_bgcheck.c", 5334) == true ||
BgCheck_PosErrorCheck(posB, "../z_bgcheck.c", 5335) == true) {
@@ -2138,8 +2148,8 @@ s32 BgCheck_LineTestImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2, V
}
BgCheck_ResetPolyCheckTbl(&colCtx->polyNodes, colCtx->colHeader->nbPolygons);
- BgCheck_GetStaticLookupIndicesFromPos(colCtx, posA, &subdivMin);
- BgCheck_GetStaticLookupIndicesFromPos(colCtx, &posBTemp, &subdivMax);
+ BgCheck_GetStaticLookupIndicesFromPos(colCtx, posA, (Vec3i*)&subdivMin);
+ BgCheck_GetStaticLookupIndicesFromPos(colCtx, &posBTemp, (Vec3i*)&subdivMax);
*posResult = *posB;
result = false;
distSq = 1.0e38f;
@@ -2209,9 +2219,8 @@ s32 BgCheck_LineTestImpl(CollisionContext* colCtx, u16 xpFlags1, u16 xpFlags2, V
* Get bccFlags
*/
u32 BgCheck_GetBccFlags(s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32 chkDyna) {
- u32 result;
+ u32 result = 0;
- result = 0;
if (chkWall) {
result = BGCHECK_CHECK_WALL;
}
@@ -2345,14 +2354,13 @@ s32 BgCheck_SphVsFirstPolyImpl(CollisionContext* colCtx, u16 xpFlags, CollisionP
osSyncPrintf("こいつ,pself_actor->name %d\n", actor->id);
}
}
+
lookup = BgCheck_GetStaticLookup(colCtx, colCtx->lookupTbl, center);
if (lookup == NULL) {
return false;
- } else {
- if (BgCheck_SphVsFirstStaticPoly(lookup, xpFlags, colCtx, center, radius, outPoly, bciFlags) ||
- BgCheck_SphVsFirstDynaPoly(colCtx, xpFlags, outPoly, outBgId, center, radius, actor, bciFlags)) {
- return true;
- }
+ } else if (BgCheck_SphVsFirstStaticPoly(lookup, xpFlags, colCtx, center, radius, outPoly, bciFlags) ||
+ BgCheck_SphVsFirstDynaPoly(colCtx, xpFlags, outPoly, outBgId, center, radius, actor, bciFlags)) {
+ return true;
}
return false;
}
@@ -2604,9 +2612,8 @@ void DynaPoly_Alloc(GlobalContext* globalCtx, DynaCollisionContext* dyna) {
s32 DynaPoly_SetBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, Actor* actor,
CollisionHeader* colHeader) {
s32 bgId;
- s32 foundSlot;
+ s32 foundSlot = false;
- foundSlot = false;
for (bgId = 0; bgId < BG_ACTOR_MAX; bgId++) {
if (!(dyna->bgActorFlags[bgId] & 1)) {
dyna->bgActorFlags[bgId] |= 1;
@@ -2636,12 +2643,12 @@ s32 DynaPoly_SetBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, Ac
* Gets the actor assigned to `bgId`
* possible orginal name: DynaPolyInfo_getActor
*/
-Actor* DynaPoly_GetActor(CollisionContext* colCtx, s32 bgId) {
+DynaPolyActor* DynaPoly_GetActor(CollisionContext* colCtx, s32 bgId) {
if (!DynaPoly_IsBgIdBgActor(bgId) || !(colCtx->dyna.bgActorFlags[bgId] & 1) ||
colCtx->dyna.bgActorFlags[bgId] & 2) {
return NULL;
}
- return colCtx->dyna.bgActors[bgId].actor;
+ return (DynaPolyActor*)colCtx->dyna.bgActors[bgId].actor;
}
void func_8003EBF8(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId) {
@@ -2700,7 +2707,7 @@ void DynaPoly_DeleteBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna
return;
}
}
- actor = (DynaPolyActor*)DynaPoly_GetActor(&globalCtx->colCtx, bgId);
+ actor = DynaPoly_GetActor(&globalCtx->colCtx, bgId);
if (actor != NULL) {
actor->bgId = BGACTOR_NEG_ONE;
@@ -2768,6 +2775,7 @@ void DynaPoly_ExpandSRT(GlobalContext* globalCtx, DynaCollisionContext* dyna, s3
(dyna->polyListMax >= *polyStartIndex + pbgdata->nbPolygons)
? (void)0
: __assert("pdyna_poly_info->poly_num >= *pstart_poly_index + pbgdata->poly_num", "../z_bgcheck.c", 6687);
+
(dyna->vtxListMax >= *vtxStartIndex + pbgdata->nbVertices)
? (void)0
: __assert("pdyna_poly_info->vert_num >= *pstart_vert_index + pbgdata->vtx_num", "../z_bgcheck.c", 6688);
@@ -2898,13 +2906,13 @@ void DynaPoly_ExpandSRT(GlobalContext* globalCtx, DynaCollisionContext* dyna, s3
}
void func_8003F8EC(GlobalContext* globalCtx, DynaCollisionContext* dyna, Actor* actor) {
- Actor* dynaActor;
+ DynaPolyActor* dynaActor;
s32 i;
for (i = 0; i < BG_ACTOR_MAX; i++) {
if ((dyna->bgActorFlags[i] & 1)) {
dynaActor = DynaPoly_GetActor(&globalCtx->colCtx, i);
- if (dynaActor != NULL && dynaActor == actor) {
+ if (dynaActor != NULL && &dynaActor->actor == actor) {
func_800434A0((DynaPolyActor*)actor);
return;
}
@@ -2943,7 +2951,7 @@ void DynaPoly_Setup(GlobalContext* globalCtx, DynaCollisionContext* dyna) {
osSyncPrintf(VT_FGCOL(GREEN));
osSyncPrintf("DynaPolyInfo_setup():削除 index=%d\n", i);
osSyncPrintf(VT_RST);
- actor = (DynaPolyActor*)DynaPoly_GetActor(&globalCtx->colCtx, i);
+ actor = DynaPoly_GetActor(&globalCtx->colCtx, i);
if (actor == NULL) {
return;
}
@@ -3044,7 +3052,7 @@ f32 BgCheck_RaycastFloorDyna(DynaRaycast* dynaRaycast) {
f32 intersect2;
s32 i2;
s32 pauseState;
- Actor* actor;
+ DynaPolyActor* dynaActor;
s32 pad;
Vec3f polyVtx[3];
Vec3f polyNorm;
@@ -3110,8 +3118,8 @@ f32 BgCheck_RaycastFloorDyna(DynaRaycast* dynaRaycast) {
}
}
- actor = DynaPoly_GetActor(dynaRaycast->colCtx, *dynaRaycast->bgId);
- if ((result != BGCHECK_Y_MIN) && (actor != NULL) && (dynaRaycast->globalCtx != NULL)) {
+ dynaActor = DynaPoly_GetActor(dynaRaycast->colCtx, *dynaRaycast->bgId);
+ if ((result != BGCHECK_Y_MIN) && (dynaActor != NULL) && (dynaRaycast->globalCtx != NULL)) {
pauseState = dynaRaycast->globalCtx->pauseCtx.state != 0;
if (pauseState == 0) {
pauseState = dynaRaycast->globalCtx->pauseCtx.flag != 0;
@@ -3192,6 +3200,7 @@ s32 BgCheck_SphVsDynaWallInBgActor(CollisionContext* colCtx, u16 xpFlags, DynaCo
if (ssList->head == SS_NULL) {
return result;
}
+
resultPos = *pos;
curNode = &dyna->polyNodes.tbl[ssList->head];
@@ -3419,12 +3428,10 @@ s32 BgCheck_CheckDynaCeilingList(CollisionContext* colCtx, u16 xpFlags, DynaColl
f32 nx;
f32 ny;
f32 nz;
- s32 result;
+ s32 result = false;
f32 intersectDist;
u16 padding;
- result = false;
-
if (ssList->head == SS_NULL) {
return false;
}
@@ -3482,11 +3489,10 @@ s32 BgCheck_CheckDynaCeiling(CollisionContext* colCtx, u16 xpFlags, f32* outY, V
s32 i = 0;
s32 result = false;
f32 resultY;
- f32 tempY;
+ f32 tempY = chkDist + pos->y;
BgActor* bgActor;
CollisionPoly* poly;
- tempY = chkDist + pos->y;
resultY = tempY;
for (i = 0; i < BG_ACTOR_MAX; i++) {
@@ -3620,7 +3626,8 @@ s32 func_80041240(CollisionContext* colCtx, u16 xpFlags, Vec3f* posA, Vec3f* pos
s32 i;
s32 result = false;
Linef line;
- f32 ay, by;
+ f32 ay;
+ f32 by;
for (i = 0; i < BG_ACTOR_MAX; i++) {
if (colCtx->dyna.bgActorFlags[i] & 1) {
@@ -3770,11 +3777,10 @@ void CollisionHeader_GetVirtual(void* colHeader, CollisionHeader** dest) {
* SEGMENT_TO_VIRTUAL all active BgActor CollisionHeaders
*/
void func_800418D0(CollisionContext* colCtx, GlobalContext* globalCtx) {
- DynaCollisionContext* dyna;
+ DynaCollisionContext* dyna = &colCtx->dyna;
s32 i;
u16 flag;
- dyna = &colCtx->dyna;
for (i = 0; i < BG_ACTOR_MAX; i++) {
flag = dyna->bgActorFlags[i];
if ((flag & 1) && !(flag & 2)) {
@@ -3842,11 +3848,10 @@ u16 func_80041A4C(CollisionContext* colCtx, u32 camId, s32 bgId) {
* SurfaceType return cameraSType
*/
u16 SurfaceType_GetCameraSType(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
CamData* camData;
SurfaceType* surfaceTypes;
- colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
if (colHeader == NULL) {
return 0;
}
@@ -3865,10 +3870,9 @@ u16 SurfaceType_GetCameraSType(CollisionContext* colCtx, CollisionPoly* poly, s3
* CamData Get number of cameras
*/
u16 func_80041B24(CollisionContext* colCtx, u32 camId, s32 bgId) {
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
CamData* camData;
- colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
if (colHeader == NULL) {
return 0;
}
@@ -3884,11 +3888,10 @@ u16 func_80041B24(CollisionContext* colCtx, u32 camId, s32 bgId) {
* SurfaceType Get number of cameras
*/
u16 SurfaceType_GetNumCameras(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
CamData* camData;
SurfaceType* surfaceTypes;
- colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
if (colHeader == NULL) {
return 0;
}
@@ -3907,10 +3910,9 @@ u16 SurfaceType_GetNumCameras(CollisionContext* colCtx, CollisionPoly* poly, s32
* CamData Get camPosData
*/
Vec3s* func_80041C10(CollisionContext* colCtx, s32 camId, s32 bgId) {
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
CamData* cameraDataList;
- colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
if (colHeader == NULL) {
return NULL;
}
@@ -3925,11 +3927,10 @@ Vec3s* func_80041C10(CollisionContext* colCtx, s32 camId, s32 bgId) {
* SurfaceType Get camPosData
*/
Vec3s* SurfaceType_GetCamPosData(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
CamData* camData;
SurfaceType* surfaceTypes;
- colHeader = BgCheck_GetCollisionHeader(colCtx, bgId);
if (colHeader == NULL) {
return NULL;
}
@@ -4036,9 +4037,8 @@ u32 func_80041F10(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
* SurfaceType Get Poly Sfx
*/
u16 SurfaceType_GetSfx(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
- s32 id;
+ s32 id = func_80041F10(colCtx, poly, bgId);
- id = func_80041F10(colCtx, poly, bgId);
if (id < 0 || id > 13) {
return NA_SE_PL_WALK_GROUND - SFX_FLAG;
}
@@ -4079,6 +4079,7 @@ u32 SurfaceType_IsHookshotSurface(CollisionContext* colCtx, CollisionPoly* poly,
*/
s32 SurfaceType_IsIgnoredByEntities(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
u32 flags;
+
if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) {
return true;
}
@@ -4092,6 +4093,7 @@ s32 SurfaceType_IsIgnoredByEntities(CollisionContext* colCtx, CollisionPoly* pol
*/
s32 SurfaceType_IsIgnoredByProjectiles(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
u32 flags;
+
if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) {
return true;
}
@@ -4105,6 +4107,7 @@ s32 SurfaceType_IsIgnoredByProjectiles(CollisionContext* colCtx, CollisionPoly*
*/
s32 SurfaceType_IsConveyor(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId) {
u32 flags;
+
if (BgCheck_GetCollisionHeader(colCtx, bgId) == NULL) {
return true;
}
@@ -4174,11 +4177,10 @@ s32 WaterBox_GetSurface1(GlobalContext* globalCtx, CollisionContext* colCtx, f32
*/
s32 WaterBox_GetSurfaceImpl(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface,
WaterBox** outWaterBox) {
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = colCtx->colHeader;
u32 room;
WaterBox* curWaterBox;
- colHeader = colCtx->colHeader;
if (colHeader->nbWaterBoxes == 0 || colHeader->waterBoxes == PHYSICAL_TO_VIRTUAL(gSegments[0])) {
return false;
}
@@ -4186,7 +4188,7 @@ s32 WaterBox_GetSurfaceImpl(GlobalContext* globalCtx, CollisionContext* colCtx,
for (curWaterBox = colHeader->waterBoxes; curWaterBox < colHeader->waterBoxes + colHeader->nbWaterBoxes;
curWaterBox++) {
room = (curWaterBox->properties >> 13) & 0x3F;
- if (room == globalCtx->roomCtx.curRoom.num || room == 0x3F) {
+ if (room == (u32)globalCtx->roomCtx.curRoom.num || room == 0x3F) {
if ((curWaterBox->properties & 0x80000) == 0) {
if (curWaterBox->xMin < x && x < curWaterBox->xMin + curWaterBox->xLength) {
if (curWaterBox->zMin < z && z < curWaterBox->zMin + curWaterBox->zLength) {
@@ -4209,14 +4211,12 @@ s32 WaterBox_GetSurfaceImpl(GlobalContext* globalCtx, CollisionContext* colCtx,
*/
s32 WaterBox_GetSurface2(GlobalContext* globalCtx, CollisionContext* colCtx, Vec3f* pos, f32 surfaceChkDist,
WaterBox** outWaterBox) {
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = colCtx->colHeader;
s32 room;
s32 i;
WaterBox* waterBox;
- WaterBox* waterBoxList; // unused, needed for matching
+ WaterBox* waterBoxList = colHeader->waterBoxes; // unused, needed for matching
- colHeader = colCtx->colHeader;
- waterBoxList = colHeader->waterBoxes;
if (colHeader->nbWaterBoxes == 0 || colHeader->waterBoxes == PHYSICAL_TO_VIRTUAL(gSegments[0])) {
*outWaterBox = NULL;
return -1;
@@ -4253,6 +4253,7 @@ s32 WaterBox_GetSurface2(GlobalContext* globalCtx, CollisionContext* colCtx, Vec
*/
u32 WaterBox_GetCamDataIndex(CollisionContext* colCtx, WaterBox* waterBox) {
u32 prop = waterBox->properties >> 0;
+
return prop & 0xFF;
}
@@ -4260,12 +4261,9 @@ u32 WaterBox_GetCamDataIndex(CollisionContext* colCtx, WaterBox* waterBox) {
* WaterBox get CamData cameraSType
*/
u16 WaterBox_GetCameraSType(CollisionContext* colCtx, WaterBox* waterBox) {
- s32 camId;
- CamData* camData;
-
- camId = WaterBox_GetCamDataIndex(colCtx, waterBox);
+ s32 camId = WaterBox_GetCamDataIndex(colCtx, waterBox);
+ CamData* camData = colCtx->colHeader->cameraDataList;
- camData = colCtx->colHeader->cameraDataList;
if (camData == PHYSICAL_TO_VIRTUAL(gSegments[0])) {
return 0;
}
@@ -4289,11 +4287,10 @@ u32 WaterBox_GetLightSettingIndex(CollisionContext* colCtx, WaterBox* waterBox)
*/
s32 func_800425B0(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32 z, f32* ySurface,
WaterBox** outWaterBox) {
- CollisionHeader* colHeader;
+ CollisionHeader* colHeader = colCtx->colHeader;
u32 room;
WaterBox* curWaterBox;
- colHeader = colCtx->colHeader;
if (colHeader->nbWaterBoxes == 0 || colHeader->waterBoxes == PHYSICAL_TO_VIRTUAL(gSegments[0])) {
return false;
}
@@ -4301,7 +4298,7 @@ s32 func_800425B0(GlobalContext* globalCtx, CollisionContext* colCtx, f32 x, f32
for (curWaterBox = colHeader->waterBoxes; curWaterBox < colHeader->waterBoxes + colHeader->nbWaterBoxes;
curWaterBox++) {
room = (curWaterBox->properties >> 0xD) & 0x3F;
- if ((room == globalCtx->roomCtx.curRoom.num) || (room == 0x3F)) {
+ if ((room == (u32)globalCtx->roomCtx.curRoom.num) || (room == 0x3F)) {
if ((curWaterBox->properties & 0x80000) != 0) {
if (curWaterBox->xMin < x && x < (curWaterBox->xMin + curWaterBox->xLength)) {
if (curWaterBox->zMin < z && z < (curWaterBox->zMin + curWaterBox->zLength)) {
@@ -4470,10 +4467,9 @@ void BgCheck_DrawStaticPoly(GlobalContext* globalCtx, CollisionContext* colCtx,
*/
void BgCheck_DrawStaticPolyList(GlobalContext* globalCtx, CollisionContext* colCtx, SSList* ssList, u8 r, u8 g, u8 b) {
SSNode* curNode;
- CollisionPoly* polyList;
+ CollisionPoly* polyList = colCtx->colHeader->polyList;
s16 curPolyId;
- polyList = colCtx->colHeader->polyList;
if (ssList->head != SS_NULL) {
curNode = &colCtx->polyNodes.tbl[ssList->head];
while (true) {
@@ -4491,11 +4487,9 @@ void BgCheck_DrawStaticPolyList(GlobalContext* globalCtx, CollisionContext* colC
* Draw scene collision
*/
void BgCheck_DrawStaticCollision(GlobalContext* globalCtx, CollisionContext* colCtx) {
- Player* player;
- StaticLookup* lookup;
+ Player* player = PLAYER;
+ StaticLookup* lookup = BgCheck_GetNearestStaticLookup(colCtx, colCtx->lookupTbl, &player->actor.world.pos);
- player = PLAYER;
- lookup = BgCheck_GetNearestStaticLookup(colCtx, colCtx->lookupTbl, &player->actor.world.pos);
if (AREG(23) != 0) {
BgCheck_DrawStaticPolyList(globalCtx, colCtx, &lookup->floor, 0, 0, 255);
}
diff --git a/src/code/z_camera.c b/src/code/z_camera.c
index 33ae1a977..cfd5152b5 100644
--- a/src/code/z_camera.c
+++ b/src/code/z_camera.c
@@ -403,7 +403,7 @@ f32 Camera_GetFloorY(Camera* camera, Vec3f* pos) {
* Gets the position of the floor from `pos`, and if the floor is considered not solid,
* it checks the next floor below that up to 3 times. Returns the normal of the floor into `norm`
*/
-f32 Camera_GetFloorYLayer(Camera* camera, Vec3f* norm, Vec3f* pos, u32* bgId) {
+f32 Camera_GetFloorYLayer(Camera* camera, Vec3f* norm, Vec3f* pos, s32* bgId) {
CollisionPoly* floorPoly;
CollisionContext* colCtx = &camera->globalCtx->colCtx;
f32 floorY;
@@ -454,7 +454,7 @@ Vec3s* Camera_GetCamBGData(Camera* camera) {
* Gets the scene's camera index for the poly `poly`, returns -1 if
* there is no camera data for that poly.
*/
-s32 Camera_GetDataIdxForPoly(Camera* camera, u32* bgId, CollisionPoly* poly) {
+s32 Camera_GetDataIdxForPoly(Camera* camera, s32* bgId, CollisionPoly* poly) {
s32 camDataIdx;
PosRot playerPosRot;
s32 ret;
@@ -577,7 +577,7 @@ s16 func_80044ADC(Camera* camera, s16 yaw, s16 arg2) {
f32 phi_f18;
f32 sinYaw;
f32 cosYaw;
- u32 bgId;
+ s32 bgId;
f32 sp30;
f32 sp2C;
f32 phi_f16;
@@ -2576,8 +2576,8 @@ s32 Camera_Jump3(Camera* camera) {
break;
}
- // unused
- spB0 = *eye;
+ spB0 = *eye; // unused
+ (void)spB0; // suppresses set but unused warning
spC4 = PCT(OREG(25)) * camera->speedRatio;
spC0 = camera->speedRatio * PCT(OREG(26));
@@ -3332,7 +3332,7 @@ s32 Camera_KeepOn3(Camera* camera) {
sCameraInterfaceFlags = keep3->flags;
if (camera->animState == 0 || camera->animState == 0xA || camera->animState == 0x14) {
colChkActors[0] = camera->target;
- colChkActors[1] = camera->player;
+ colChkActors[1] = &camera->player->actor;
camera->animState++;
anim->target = camera->target;
temp_f0 = (keep3->maxDist < targetToPlayerDir.r ? 1.0f : targetToPlayerDir.r / keep3->maxDist);
@@ -3383,7 +3383,7 @@ s32 Camera_KeepOn3(Camera* camera) {
if (!(keep3->flags & 0x80)) {
while (i < angleCnt) {
if (!CollisionCheck_LineOCCheck(camera->globalCtx, &camera->globalCtx->colChkCtx, &anim->atTarget,
- &lineChkPointB, &colChkActors, 2) &&
+ &lineChkPointB, colChkActors, 2) &&
!Camera_BGCheck(camera, &anim->atTarget, &lineChkPointB)) {
break;
}
@@ -3770,6 +3770,7 @@ s32 Camera_KeepOn0(Camera* camera) {
*eye = *eyeNext;
sceneCamRot = BGCAM_ROT(sceneCamData); // unused
+ (void)sceneCamRot; // suppresses set but unused warning
fov = BGCAM_FOV(sceneCamData);
if (fov == -1) {
@@ -4949,7 +4950,8 @@ s32 Camera_Unique7(Camera* camera) {
Camera_Vec3sToVec3f(eyeNext, &BGCAM_POS(sceneCamData));
*eye = *eyeNext;
- sceneCamRot = BGCAM_ROT(sceneCamData);
+ sceneCamRot = BGCAM_ROT(sceneCamData); // unused
+ (void)sceneCamRot; // suppresses set but unused warning
OLib_Vec3fDiffToVecSphGeo(&playerPosEyeOffset, eye, &playerPosRot->pos);
@@ -7307,7 +7309,7 @@ Vec3s* Camera_Update(Vec3s* outVec, Camera* camera) {
Vec3f viewUp;
f32 viewFov;
Vec3f spAC;
- u32 bgCheckId;
+ s32 bgId;
f32 playerGroundY;
f32 playerXZSpeed;
VecSph eyeAtAngle;
@@ -7344,14 +7346,14 @@ Vec3s* Camera_Update(Vec3s* outVec, Camera* camera) {
spAC.y += Player_GetHeight(camera->player);
playerGroundY = BgCheck_EntityRaycastFloor5(camera->globalCtx, &camera->globalCtx->colCtx, &playerFloorPoly,
- &bgCheckId, &camera->player->actor, &spAC);
+ &bgId, &camera->player->actor, &spAC);
if (playerGroundY != BGCHECK_Y_MIN) {
// player is above ground.
sOOBTimer = 0;
camera->floorNorm.x = COLPOLY_GET_NORMAL(playerFloorPoly->normal.x);
camera->floorNorm.y = COLPOLY_GET_NORMAL(playerFloorPoly->normal.y);
camera->floorNorm.z = COLPOLY_GET_NORMAL(playerFloorPoly->normal.z);
- camera->bgCheckId = bgCheckId;
+ camera->bgCheckId = bgId;
camera->playerGroundY = playerGroundY;
} else {
// player is not above ground.
@@ -7376,10 +7378,10 @@ Vec3s* Camera_Update(Vec3s* outVec, Camera* camera) {
if ((camera->unk_14C & 1) && (camera->unk_14C & 4) && (!(camera->unk_14C & 0x400)) &&
(!(camera->unk_14C & 0x200) || (player->currentBoots == PLAYER_BOOTS_IRON)) &&
(!(camera->unk_14C & (s16)0x8000)) && (playerGroundY != BGCHECK_Y_MIN)) {
- camDataIdx = Camera_GetDataIdxForPoly(camera, &bgCheckId, playerFloorPoly);
+ camDataIdx = Camera_GetDataIdxForPoly(camera, &bgId, playerFloorPoly);
if (camDataIdx != -1) {
- camera->nextBGCheckId = bgCheckId;
- if (bgCheckId == BGCHECK_SCENE) {
+ camera->nextBGCheckId = bgId;
+ if (bgId == BGCHECK_SCENE) {
camera->nextCamDataIdx = camDataIdx;
}
}
@@ -7481,7 +7483,7 @@ Vec3s* Camera_Update(Vec3s* outVec, Camera* camera) {
// setting bgCheckId to the ret of Quake_Calc, and checking that
// is required, it doesn't make too much sense though.
- if ((bgCheckId = Quake_Calc(camera, &quake), bgCheckId != 0) && (camera->setting != CAM_SET_ITEM2)) {
+ if ((bgId = Quake_Calc(camera, &quake), bgId != 0) && (camera->setting != CAM_SET_ITEM2)) {
viewAt.x = camera->at.x + quake.atOffset.x;
viewAt.y = camera->at.y + quake.atOffset.y;
viewAt.z = camera->at.z + quake.atOffset.z;
diff --git a/src/code/z_collision_check.c b/src/code/z_collision_check.c
index 30f71cda2..b5a8e9f2e 100644
--- a/src/code/z_collision_check.c
+++ b/src/code/z_collision_check.c
@@ -1293,7 +1293,6 @@ s32 CollisionCheck_SetAC(GlobalContext* globalCtx, CollisionCheckContext* colChk
*/
s32 CollisionCheck_SetAC_SAC(GlobalContext* globalCtx, CollisionCheckContext* colChkCtx, Collider* collider,
s32 index) {
-
if (!(collider->shape <= COLSHAPE_QUAD)) {
__assert("pcl_obj->data_type <= CL_DATA_LBL_SWRD", "../z_collision_check.c", 3153);
}
@@ -1367,7 +1366,6 @@ s32 CollisionCheck_SetOC(GlobalContext* globalCtx, CollisionCheckContext* colChk
*/
s32 CollisionCheck_SetOC_SAC(GlobalContext* globalCtx, CollisionCheckContext* colChkCtx, Collider* collider,
s32 index) {
-
if (func_800C0D28(globalCtx) == 1) {
return -1;
}
@@ -1591,9 +1589,8 @@ void CollisionCheck_RedBloodUnused(GlobalContext* globalCtx, Collider* collider,
* Plays sound effects and displays hitmarks for solid-type AC colliders (METAL, WOOD, HARD, and TREE)
*/
void CollisionCheck_HitSolid(GlobalContext* globalCtx, ColliderInfo* info, Collider* collider, Vec3f* hitPos) {
- s32 flags;
+ s32 flags = info->toucherFlags & TOUCH_SFX_NONE;
- flags = info->toucherFlags & TOUCH_SFX_NONE;
if (flags == TOUCH_SFX_NORMAL && collider->colType != COLTYPE_METAL) {
EffectSsHitMark_SpawnFixedScale(globalCtx, EFFECT_HITMARK_WHITE, hitPos);
if (collider->actor == NULL) {
@@ -1715,7 +1712,6 @@ void CollisionCheck_SetBounce(Collider* at, Collider* ac) {
*/
s32 CollisionCheck_SetATvsAC(GlobalContext* globalCtx, Collider* at, ColliderInfo* atInfo, Vec3f* atPos, Collider* ac,
ColliderInfo* acInfo, Vec3f* acPos, Vec3f* hitPos) {
-
if (ac->acFlags & AC_HARD && at->actor != NULL && ac->actor != NULL) {
CollisionCheck_SetBounce(at, ac);
}
@@ -2477,10 +2473,12 @@ void CollisionCheck_AC_QuadVsQuad(GlobalContext* globalCtx, CollisionCheckContex
if (CollisionCheck_NoSharedFlags(&at->info, &ac->info) == 1) {
return;
}
+
Math3D_TriNorm(&D_8015E5A8[0], &at->dim.quad[2], &at->dim.quad[3], &at->dim.quad[1]);
Math3D_TriNorm(&D_8015E5A8[1], &at->dim.quad[2], &at->dim.quad[1], &at->dim.quad[0]);
Math3D_TriNorm(&D_8015E530[0], &ac->dim.quad[2], &ac->dim.quad[3], &ac->dim.quad[1]);
Math3D_TriNorm(&D_8015E530[1], &ac->dim.quad[2], &ac->dim.quad[1], &ac->dim.quad[0]);
+
for (i = 0; i < 2; i++) {
for (j = 0; j < 2; j++) {
if (Math3D_TriVsTriIntersect(&D_8015E5A8[j], &D_8015E530[i], &D_8015E598) == 1) {
diff --git a/src/code/z_debug.c b/src/code/z_debug.c
index 91137e190..6cb76f846 100644
--- a/src/code/z_debug.c
+++ b/src/code/z_debug.c
@@ -34,7 +34,7 @@ InputCombo inputCombos[REG_GROUPS] = {
char regChar[] = " SOPQMYDUIZCNKXcsiWAVHGmnBdkb";
// initialize GameInfo
-void func_800636C0() {
+void func_800636C0(void) {
s32 i;
gGameInfo = (GameInfo*)SystemArena_MallocDebug(sizeof(GameInfo), "../z_debug.c", 260);
@@ -67,7 +67,7 @@ void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) {
i = 0;
bufText = buf->text;
- while (*bufText++ = *text++) {
+ while ((*bufText++ = *text++)) {
if (i++ > 0x14) {
break;
}
@@ -188,14 +188,11 @@ void func_8006390C(Input* input) {
// Draw Memory Viewer
void func_80063C04(GfxPrint* gfxPrint) {
s32 i;
- s32 page;
- s32 regGroup;
- s32 test; // removing affects stack
+ s32 page = (gGameInfo->regPage * REG_PER_PAGE) - REG_PER_PAGE;
+ s32 regGroup = (gGameInfo->regGroup * REG_PAGES + gGameInfo->regPage) * REG_PER_PAGE - REG_PER_PAGE;
+ s32 pad;
char name[3];
- page = (gGameInfo->regPage * REG_PER_PAGE) - REG_PER_PAGE;
- regGroup = (gGameInfo->regGroup * REG_PAGES + gGameInfo->regPage) * REG_PER_PAGE - REG_PER_PAGE;
-
// set up register name string
name[0] = 'R';
name[1] = regChar[gGameInfo->regGroup]; // r_group type char
@@ -242,7 +239,7 @@ void func_80063D7C(GraphicsContext* gfxCtx) {
Graph_BranchDlist(sp78, sp7C);
POLY_OPA_DISP = sp7C;
- if (0) {}
+ if (1) {}
CLOSE_DISPS(gfxCtx, "../z_debug.c", 664);
diff --git a/src/code/z_demo.c b/src/code/z_demo.c
index d79a17c00..7a3d4d967 100644
--- a/src/code/z_demo.c
+++ b/src/code/z_demo.c
@@ -372,7 +372,7 @@ void func_80064824(GlobalContext* globalCtx, CutsceneContext* csCtx, CsCmdBase*
}
break;
case 35:
- func_800EE824(csCtx);
+ func_800EE824();
csCtx->frames = cmd->startFrame - 1;
break;
}
diff --git a/src/code/z_eff_shield_particle.c b/src/code/z_eff_shield_particle.c
index 7122f5d03..725bf7b37 100644
--- a/src/code/z_eff_shield_particle.c
+++ b/src/code/z_eff_shield_particle.c
@@ -113,10 +113,9 @@ s32 EffectShieldParticle_Update(void* thisx) {
}
void EffectShieldParticle_GetColors(EffectShieldParticle* this, Color_RGBA8* primColor, Color_RGBA8* envColor) {
- s32 halfDuration;
+ s32 halfDuration = this->duration * 0.5f;
f32 ratio;
- halfDuration = this->duration * 0.5f;
if (halfDuration == 0) {
primColor->r = this->primColorStart.r;
primColor->g = this->primColorStart.g;
@@ -186,14 +185,10 @@ void EffectShieldParticle_Draw(void* thisx, GraphicsContext* gfxCtx) {
MtxF sp104;
MtxF spC4;
MtxF sp84;
- f32 temp1;
- f32 temp2;
- f32 temp3;
+ f32 temp1 = (s16)((elem->endX + elem->startX) * 0.5f);
+ f32 temp2 = elem->endX - elem->startX;
+ f32 temp3 = (s16)((temp2 * (1.0f / 64.0f)) / 0.02f);
- temp1 = (s16)((elem->endX + elem->startX) * 0.5f);
-
- temp2 = elem->endX - elem->startX;
- temp3 = (s16)((temp2 * (1.0f / 64.0f)) / 0.02f);
if (temp3 < 1.0f) {
temp3 = 1.0f;
}
diff --git a/src/code/z_eff_spark.c b/src/code/z_eff_spark.c
index 78c74b9a2..480645ea3 100644
--- a/src/code/z_eff_spark.c
+++ b/src/code/z_eff_spark.c
@@ -132,7 +132,7 @@ s32 EffectSpark_Update(void* thisx) {
void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) {
Vtx* vertices;
EffectSpark* this = (EffectSpark*)thisx;
- GlobalContext* globalCtx;
+ GlobalContext* globalCtx = Effect_GetGlobalCtx();
s32 i;
s32 j;
u8 sp1D3;
@@ -153,8 +153,6 @@ void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) {
u8 sp1C4;
f32 ratio;
- globalCtx = Effect_GetGlobalCtx();
-
if (1) {}
OPEN_DISPS(gfxCtx, "../z_eff_spark.c", 293);
@@ -208,12 +206,10 @@ void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) {
MtxF spEC;
MtxF spAC;
MtxF sp6C;
- EffectSparkElement* elem;
+ EffectSparkElement* elem = &this->elements[i];
Mtx* mtx;
f32 temp;
- elem = &this->elements[i];
-
SkinMatrix_SetTranslate(&spEC, elem->position.x, elem->position.y, elem->position.z);
temp = ((Rand_ZeroOne() * 2.5f) + 1.5f) * 0.015625f;
SkinMatrix_SetScale(&spAC, temp, temp, 1.0f);
diff --git a/src/code/z_effect.c b/src/code/z_effect.c
index f035469e0..8bef699ad 100644
--- a/src/code/z_effect.c
+++ b/src/code/z_effect.c
@@ -99,11 +99,9 @@ void Effect_InitContext(GlobalContext* globalCtx) {
void Effect_Add(GlobalContext* globalCtx, s32* pIndex, s32 type, u8 arg3, u8 arg4, void* initParams) {
s32 i;
u32 slotFound;
- void* effect;
- EffectStatus* status;
+ void* effect = NULL;
+ EffectStatus* status = NULL;
- effect = NULL;
- status = NULL;
*pIndex = TOTAL_EFFECT_COUNT;
if (func_800C0D28(globalCtx) != 1) {
diff --git a/src/code/z_effect_soft_sprite.c b/src/code/z_effect_soft_sprite.c
index 381a24f98..24512194d 100644
--- a/src/code/z_effect_soft_sprite.c
+++ b/src/code/z_effect_soft_sprite.c
@@ -294,10 +294,9 @@ void EffectSs_Draw(GlobalContext* globalCtx, s32 index) {
// original name: "EffectSoftSprite2_disp"
void EffectSs_DrawAll(GlobalContext* globalCtx) {
- Lights* lights;
+ Lights* lights = LightContext_NewLights(&globalCtx->lightCtx, globalCtx->state.gfxCtx);
s32 i;
- lights = LightContext_NewLights(&globalCtx->lightCtx, globalCtx->state.gfxCtx);
Lights_BindAll(lights, globalCtx->lightCtx.listHead, NULL);
Lights_Draw(lights, globalCtx->state.gfxCtx);
diff --git a/src/code/z_effect_soft_sprite_old_init.c b/src/code/z_effect_soft_sprite_old_init.c
index 991d280ec..4f66f25df 100644
--- a/src/code/z_effect_soft_sprite_old_init.c
+++ b/src/code/z_effect_soft_sprite_old_init.c
@@ -49,9 +49,7 @@ void EffectSs_DrawGEffect(GlobalContext* globalCtx, EffectSs* this, void* textur
MtxF mfTrans11DA0;
s32 pad1;
Mtx* mtx;
- void* object;
-
- object = globalCtx->objectCtx.status[this->rgObjBankIdx].segment;
+ void* object = globalCtx->objectCtx.status[this->rgObjBankIdx].segment;
OPEN_DISPS(gfxCtx, "../z_effect_soft_sprite_old_init.c", 196);
@@ -180,9 +178,8 @@ void func_80028858(GlobalContext* globalCtx, Vec3f* pos, Vec3f* velocity, Vec3f*
void func_80028894(Vec3f* srcPos, f32 randScale, Vec3f* newPos, Vec3f* velocity, Vec3f* accel) {
s16 randAngle;
- f32 rand;
+ f32 rand = Rand_ZeroOne() * randScale;
- rand = Rand_ZeroOne() * randScale;
randAngle = (Rand_ZeroOne() * 65536.0f);
*newPos = *srcPos;
@@ -408,9 +405,7 @@ void EffectSsGSpk_SpawnRandColor(GlobalContext* globalCtx, Actor* actor, Vec3f*
s16 scale, s16 scaleStep) {
Color_RGBA8 primColor = { 255, 255, 150, 255 };
Color_RGBA8 envColor = { 255, 0, 0, 0 };
- s32 randOffset;
-
- randOffset = (Rand_ZeroOne() * 20.0f) - 10.0f;
+ s32 randOffset = (Rand_ZeroOne() * 20.0f) - 10.0f;
primColor.r += randOffset;
primColor.g += randOffset;
diff --git a/src/code/z_elf_message.c b/src/code/z_elf_message.c
index babfd19f8..90a27368e 100644
--- a/src/code/z_elf_message.c
+++ b/src/code/z_elf_message.c
@@ -70,15 +70,12 @@ u32 func_8006BE88(ElfMessage** msgp) {
}
u32 func_8006BF1C(ElfMessage** msgp) {
- ElfMessage* msg;
+ ElfMessage* msg = *msgp;
u32 sp44[10];
- s32 temp1;
- s32 temp2;
+ s32 temp1 = 0;
+ s32 temp2 = 0;
s32 temp3;
- msg = *msgp;
- temp1 = 0;
- temp2 = 0;
do {
sp44[temp2] = ElfMessage_CheckCondition(msg);
temp1 += sp44[temp2];
diff --git a/src/code/z_en_a_keep.c b/src/code/z_en_a_keep.c
index 69d696ad3..465175e89 100644
--- a/src/code/z_en_a_keep.c
+++ b/src/code/z_en_a_keep.c
@@ -83,9 +83,7 @@ void EnAObj_Init(Actor* thisx, GlobalContext* globalCtx) {
CollisionHeader* colHeader = NULL;
s32 pad;
EnAObj* this = THIS;
- f32 sp28;
-
- sp28 = 6.0f;
+ f32 sp28 = 6.0f;
this->textId = (thisx->params >> 8) & 0xFF;
thisx->params &= 0xFF;
@@ -276,10 +274,9 @@ void func_8001D4A8(EnAObj* this, GlobalContext* globalCtx) {
this->dyna.actor.shape.rot.z = this->dyna.actor.shape.rot.z + (this->dyna.actor.world.rot.z >> 1);
if ((this->dyna.actor.speedXZ != 0.0f) && (this->dyna.actor.bgCheckFlags & 0x8)) {
- if (1) { // Necessary to match
- this->dyna.actor.world.rot.y =
- ((this->dyna.actor.wallYaw - this->dyna.actor.world.rot.y) + this->dyna.actor.wallYaw) - 0x8000;
- }
+ this->dyna.actor.world.rot.y =
+ ((this->dyna.actor.wallYaw - this->dyna.actor.world.rot.y) + this->dyna.actor.wallYaw) - 0x8000;
+ if (1) {} // Necessary to match
this->dyna.actor.bgCheckFlags &= ~0x8;
}
diff --git a/src/code/z_en_item00.c b/src/code/z_en_item00.c
index cd41d1dd1..c17f00b3f 100644
--- a/src/code/z_en_item00.c
+++ b/src/code/z_en_item00.c
@@ -32,10 +32,10 @@ const ActorInit En_Item00_InitVars = {
// TODO: Define this section of .data here and rename the symbols
extern ColliderCylinderInit D_801154E0; // rename to sCylinderInit when data is moved
extern InitChainEntry D_8011550C[]; // rename to sInitChain when data is moved
-extern Color_RGB8 D_80115510;
-extern Color_RGB8 D_80115514;
-extern UNK_TYPE D_80115518;
-extern UNK_TYPE D_80115524;
+extern Color_RGBA8 D_80115510;
+extern Color_RGBA8 D_80115514;
+extern Vec3f D_80115518;
+extern Vec3f D_80115524;
extern u32 D_80115530[];
extern u32 D_80115544[];
extern u8 D_80115574[];
@@ -50,16 +50,12 @@ void EnItem00_SetupAction(EnItem00* this, EnItem00ActionFunc actionFunc) {
void EnItem00_Init(Actor* thisx, GlobalContext* globalCtx) {
EnItem00* this = THIS;
s32 pad2;
- f32 sp34;
- f32 sp30;
- s32 getItemId;
+ f32 sp34 = 980.0f;
+ f32 sp30 = 6.0f;
+ s32 getItemId = 0;
s16 spawnParam8000;
s32 pad3;
- sp34 = 980.0f;
- sp30 = 6.0f;
- getItemId = 0;
-
spawnParam8000 = this->actor.params & 0x8000;
this->collectibleFlag = (this->actor.params & 0x3F00) >> 8;
@@ -444,14 +440,11 @@ extern s16 D_80157D94;
void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) {
EnItem00* this = THIS;
s16* params;
- s32 getItemId;
- s16 sp3A;
+ s32 getItemId = 0;
+ s16 sp3A = 0;
Actor* dynaActor;
s16 i;
- getItemId = 0;
- sp3A = 0;
-
if (this->unk_15A > 0) {
this->unk_15A--;
}
@@ -469,7 +462,7 @@ void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) {
if (this->actor.gravity) {
if (this->actor.bgCheckFlags & 0x0003) {
// Separate symbols seem to be used here for 0x80157D90 since the loads and stores are completely separate
- if (D_80157D90 != globalCtx->gameplayFrames) {
+ if ((u32)D_80157D90 != globalCtx->gameplayFrames) {
D_80157D90_ = globalCtx->gameplayFrames;
D_80157D94 = 0;
for (i = 0; i < BG_ACTOR_MAX; i++) {
@@ -506,6 +499,7 @@ void EnItem00_Update(Actor* thisx, GlobalContext* globalCtx) {
if ((this->actor.params == ITEM00_SHIELD_DEKU) || (this->actor.params == ITEM00_SHIELD_HYLIAN) ||
(this->actor.params == ITEM00_TUNIC_ZORA) || (this->actor.params == ITEM00_TUNIC_GORON)) {
f32 newUnkBC = Math_CosS(this->actor.shape.rot.x) * 37.0f;
+
this->actor.shape.yOffset = newUnkBC;
if (newUnkBC >= 0.0f) {
this->actor.shape.yOffset = this->actor.shape.yOffset;
@@ -741,13 +735,12 @@ void func_8001EF30(EnItem00* this, GlobalContext* globalCtx) {
func_80093D18(globalCtx->state.gfxCtx);
func_8002EBCC(&this->actor, globalCtx, 0);
- if (1) { // Necessary to match
- if (this->actor.params <= ITEM00_RUPEE_RED) {
- iconNb = this->actor.params;
- } else {
- iconNb = this->actor.params - 0x10;
- }
+ if (this->actor.params <= ITEM00_RUPEE_RED) {
+ iconNb = this->actor.params;
+ } else {
+ iconNb = this->actor.params - 0x10;
}
+ if (1) {} // Necessary to match
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_en_item00.c", 1562),
G_MTX_MODELVIEW | G_MTX_LOAD);
@@ -763,9 +756,7 @@ void func_8001EF30(EnItem00* this, GlobalContext* globalCtx) {
* Draw Function used for most collectible types of En_Item00 (ammo, bombs, sticks, nuts, magic...).
*/
void func_8001F080(EnItem00* this, GlobalContext* globalCtx) {
- s32 iconNb;
-
- iconNb = this->actor.params - 3;
+ s32 iconNb = this->actor.params - 3;
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_en_item00.c", 1594);
@@ -871,7 +862,7 @@ EnItem00* Item_DropCollectible(GlobalContext* globalCtx, Vec3f* spawnPos, s16 pa
s16 param8000 = params & 0x8000;
s16 param3F00 = params & 0x3F00;
- params = params & 0x3FFF;
+ params &= 0x3FFF;
if (((params & 0x00FF) == ITEM00_FLEXIBLE) && !param4000) {
// TODO: Prevent the cast to EnItem00 here since this is a different actor (En_Elf)
@@ -915,7 +906,7 @@ EnItem00* Item_DropCollectible2(GlobalContext* globalCtx, Vec3f* spawnPos, s16 p
s16 param8000 = params & 0x8000;
s16 param3F00 = params & 0x3F00;
- params = params & 0x3FFF;
+ params &= 0x3FFF;
if (((params & 0x00FF) == ITEM00_FLEXIBLE) && !param4000) {
// TODO: Prevent the cast to EnItem00 here since this is a different actor (En_Elf)
@@ -946,12 +937,11 @@ void Item_DropCollectibleRandom(GlobalContext* globalCtx, Actor* fromActor, Vec3
EnItem00* spawnedActor;
s16 dropQuantity;
s16 param8000;
- s16 dropTableIndex;
+ s16 dropTableIndex = Rand_ZeroOne() * 16.0f;
u8 dropId;
- dropTableIndex = Rand_ZeroOne() * 16.0f;
param8000 = params & 0x8000;
- params = params & 0x7FFF;
+ params &= 0x7FFF;
if (fromActor != NULL) {
if (fromActor->dropFlag) {
diff --git a/src/code/z_fbdemo.c b/src/code/z_fbdemo.c
index f7a62cac1..4fb154c8b 100644
--- a/src/code/z_fbdemo.c
+++ b/src/code/z_fbdemo.c
@@ -64,6 +64,7 @@ void TransitionUnk_InitGraphics(TransitionUnk* this) {
}
}
}
+
gfx = this->gfx;
for (colTex = 0, col = 0; col < this->col; colTex += 0x20, col++) {
@@ -83,6 +84,7 @@ void TransitionUnk_InitGraphics(TransitionUnk* this) {
row++;
}
}
+
gDPPipeSync(gfx++);
gSPEndDisplayList(gfx++);
@@ -107,6 +109,7 @@ void TransitionUnk_Destroy(TransitionUnk* this) {
osSyncPrintf("fbdemo_cleanup(%08x)\n", this);
osSyncPrintf("msleep(100);\n");
Sleep_Msec(100);
+
if (this->unk_0C != NULL) {
SystemArena_FreeDebug(this->unk_0C, "../z_fbdemo.c", 180);
this->unk_0C = NULL;
@@ -135,6 +138,7 @@ TransitionUnk* TransitionUnk_Init(TransitionUnk* this, s32 row, s32 col) {
this->vtxFrame1 = SystemArena_MallocDebug((row + 1) * sizeof(Vtx) * (col + 1), "../z_fbdemo.c", 196);
this->vtxFrame2 = SystemArena_MallocDebug((row + 1) * sizeof(Vtx) * (col + 1), "../z_fbdemo.c", 197);
this->gfx = SystemArena_MallocDebug((this->col * (1 + this->row * 9) + 2) * sizeof(Gfx), "../z_fbdemo.c", 198);
+
if (this->unk_0C == NULL || this->vtxFrame1 == NULL || this->vtxFrame2 == NULL || this->gfx == NULL) {
osSyncPrintf("fbdemo_init allocation error\n");
if (this->unk_0C != NULL) {
@@ -158,6 +162,7 @@ TransitionUnk* TransitionUnk_Init(TransitionUnk* this, s32 row, s32 col) {
TransitionUnk_InitGraphics(this);
TransitionUnk_InitData(this);
this->frame = 0;
+
return this;
}
diff --git a/src/code/z_fbdemo_circle.c b/src/code/z_fbdemo_circle.c
index 8ef912278..d3326e053 100644
--- a/src/code/z_fbdemo_circle.c
+++ b/src/code/z_fbdemo_circle.c
@@ -280,8 +280,13 @@ Gfx sCircleDList[] = {
gsSPEndDisplayList(),
};
-void TransitionCircle_Start(TransitionCircle* this) {
+#define THIS ((TransitionCircle*)thisx)
+
+void TransitionCircle_Start(void* thisx) {
+ TransitionCircle* this = THIS;
+
this->isDone = 0;
+
switch (this->effect) {
case 1:
this->texture = sCircleTexWave;
@@ -332,15 +337,18 @@ void TransitionCircle_Start(TransitionCircle* this) {
guLookAt(&this->lookAt, 0.0f, 0.0f, 400.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
}
-TransitionCircle* TransitionCircle_Init(TransitionCircle* this) {
+void* TransitionCircle_Init(void* thisx) {
+ TransitionCircle* this = THIS;
+
bzero(this, sizeof(*this));
return this;
}
-void TransitionCircle_Destroy(TransitionCircle* this) {
+void TransitionCircle_Destroy(void* thisx) {
}
-void TransitionCircle_Update(TransitionCircle* this, s32 updateRate) {
+void TransitionCircle_Update(void* thisx, s32 updateRate) {
+ TransitionCircle* this = THIS;
s32 temp_t2;
s32 temp_t3;
@@ -371,17 +379,18 @@ void TransitionCircle_Update(TransitionCircle* this, s32 updateRate) {
}
}
-void TransitionCircle_Draw(TransitionCircle* this, Gfx** gfxP) {
+void TransitionCircle_Draw(void* thisx, Gfx** gfxP) {
Gfx* gfx = *gfxP;
- Mtx* modelView = this->modelView[this->frame];
- char pad[4];
+ Mtx* modelView;
+ TransitionCircle* this = THIS;
Gfx* texScroll;
-
// These variables are a best guess based on the other transition types.
f32 tPos = 0.0f;
f32 rot = 0.0f;
f32 scale = 14.8f;
+ modelView = this->modelView[this->frame];
+
this->frame ^= 1;
gDPPipeSync(gfx++);
texScroll = Gfx_BranchTexScroll(&gfx, this->texX, this->texY, 0x10, 0x40);
@@ -412,11 +421,15 @@ void TransitionCircle_Draw(TransitionCircle* this, Gfx** gfxP) {
*gfxP = gfx;
}
-s32 TransitionCircle_IsDone(TransitionCircle* this) {
+s32 TransitionCircle_IsDone(void* thisx) {
+ TransitionCircle* this = THIS;
+
return this->isDone;
}
-void TransitionCircle_SetType(TransitionCircle* this, s32 type) {
+void TransitionCircle_SetType(void* thisx, s32 type) {
+ TransitionCircle* this = THIS;
+
if (type & 0x80) {
this->unk_14 = (type >> 5) & 0x1;
this->typeColor = (type >> 3) & 0x3;
@@ -429,10 +442,14 @@ void TransitionCircle_SetType(TransitionCircle* this, s32 type) {
}
}
-void TransitionCircle_SetColor(TransitionCircle* this, u32 color) {
+void TransitionCircle_SetColor(void* thisx, u32 color) {
+ TransitionCircle* this = THIS;
+
this->color.rgba = color;
}
-void TransitionCircle_SetEnvColor(TransitionCircle* this, u32 envColor) {
+void TransitionCircle_SetEnvColor(void* thisx, u32 envColor) {
+ TransitionCircle* this = THIS;
+
this->envColor.rgba = envColor;
}
diff --git a/src/code/z_fbdemo_fade.c b/src/code/z_fbdemo_fade.c
index e70c1a81d..79c922c73 100644
--- a/src/code/z_fbdemo_fade.c
+++ b/src/code/z_fbdemo_fade.c
@@ -12,7 +12,11 @@ static Gfx sRCPSetupFade[] = {
gsSPEndDisplayList(),
};
-void TransitionFade_Start(TransitionFade* this) {
+#define THIS ((TransitionFade*)thisx)
+
+void TransitionFade_Start(void* thisx) {
+ TransitionFade* this = THIS;
+
switch (this->fadeType) {
case 0:
break;
@@ -27,17 +31,20 @@ void TransitionFade_Start(TransitionFade* this) {
this->isDone = 0;
}
-TransitionFade* TransitionFade_Init(TransitionFade* this) {
+void* TransitionFade_Init(void* thisx) {
+ TransitionFade* this = THIS;
+
bzero(this, sizeof(*this));
return this;
}
-void TransitionFade_Destroy(TransitionFade* this) {
+void TransitionFade_Destroy(void* thisx) {
}
-void TransitionFade_Update(TransitionFade* this, s32 updateRate) {
+void TransitionFade_Update(void* thisx, s32 updateRate) {
s32 alpha;
s16 newAlpha;
+ TransitionFade* this = THIS;
switch (this->fadeType) {
case 0:
@@ -53,7 +60,7 @@ void TransitionFade_Update(TransitionFade* this, s32 updateRate) {
osSyncPrintf(VT_COL(RED, WHITE) "0除算! ZCommonGet fade_speed に0がはいってる" VT_RST);
}
- alpha = (255.0f * this->fadeTimer) / (0, gSaveContext.fadeDuration);
+ alpha = (255.0f * this->fadeTimer) / ((void)0, gSaveContext.fadeDuration);
this->fadeColor.a = (this->fadeDirection != 0) ? 255 - alpha : alpha;
break;
case 2:
@@ -76,11 +83,12 @@ void TransitionFade_Update(TransitionFade* this, s32 updateRate) {
}
}
-void TransitionFade_Draw(TransitionFade* this, Gfx** gfxP) {
+void TransitionFade_Draw(void* thisx, Gfx** gfxP) {
+ TransitionFade* this = THIS;
Gfx* gfx;
- Color_RGBA8_u32* color;
- if (this->fadeColor.a > 0) {
- color = &this->fadeColor;
+ Color_RGBA8_u32* color = &this->fadeColor;
+
+ if (color->a > 0) {
gfx = *gfxP;
gSPDisplayList(gfx++, sRCPSetupFade);
gDPSetPrimColor(gfx++, 0, 0, color->r, color->g, color->b, color->a);
@@ -90,15 +98,21 @@ void TransitionFade_Draw(TransitionFade* this, Gfx** gfxP) {
}
}
-s32 TransitionFade_IsDone(TransitionFade* this) {
+s32 TransitionFade_IsDone(void* thisx) {
+ TransitionFade* this = THIS;
+
return this->isDone;
}
-void TransitionFade_SetColor(TransitionFade* this, u32 color) {
+void TransitionFade_SetColor(void* thisx, u32 color) {
+ TransitionFade* this = THIS;
+
this->fadeColor.rgba = color;
}
-void TransitionFade_SetType(TransitionFade* this, s32 type) {
+void TransitionFade_SetType(void* thisx, s32 type) {
+ TransitionFade* this = THIS;
+
if (type == 1) {
this->fadeType = 1;
this->fadeDirection = 1;
diff --git a/src/code/z_fbdemo_triforce.c b/src/code/z_fbdemo_triforce.c
index d4c3d6655..945b74455 100644
--- a/src/code/z_fbdemo_triforce.c
+++ b/src/code/z_fbdemo_triforce.c
@@ -20,7 +20,11 @@ Vtx sTriforceVTX[] = {
VTX(32000, -32000, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF), VTX(-32000, -32000, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF),
};
-void TransitionTriforce_Start(TransitionTriforce* this) {
+#define THIS ((TransitionTriforce*)thisx)
+
+void TransitionTriforce_Start(void* thisx) {
+ TransitionTriforce* this = THIS;
+
switch (this->state) {
case 1:
case 2:
@@ -30,7 +34,9 @@ void TransitionTriforce_Start(TransitionTriforce* this) {
this->transPos = 0.03f;
}
-TransitionTriforce* TransitionTriforce_Init(TransitionTriforce* this) {
+void* TransitionTriforce_Init(void* thisx) {
+ TransitionTriforce* this = THIS;
+
bzero(this, sizeof(*this));
guOrtho(&this->projection, -160.0f, 160.0f, -120.0f, 120.0f, -1000.0f, 1000.0f, 1.0f);
this->transPos = 1.0f;
@@ -40,12 +46,14 @@ TransitionTriforce* TransitionTriforce_Init(TransitionTriforce* this) {
return this;
}
-void TransitionTriforce_Destroy(TransitionTriforce* this) {
+void TransitionTriforce_Destroy(void* thisx) {
}
-void TransitionTriforce_Update(TransitionTriforce* this, s32 updateRate) {
+void TransitionTriforce_Update(void* thisx, s32 updateRate) {
+ TransitionTriforce* this = THIS;
f32 temp_f0;
s32 i;
+
for (i = updateRate; i > 0; i--) {
if (this->state == 1) {
this->transPos = CLAMP_MIN(this->transPos * (1.0f - this->step), 0.03f);
@@ -59,30 +67,33 @@ void TransitionTriforce_Update(TransitionTriforce* this, s32 updateRate) {
}
}
-void TransitionTriforce_SetColor(TransitionTriforce* this, u32 color) {
+void TransitionTriforce_SetColor(void* thisx, u32 color) {
+ TransitionTriforce* this = THIS;
+
this->color.rgba = color;
}
-void TransitionTriforce_SetType(TransitionTriforce* this, s32 type) {
+void TransitionTriforce_SetType(void* thisx, s32 type) {
+ TransitionTriforce* this = THIS;
+
this->fadeDirection = type;
}
// unused
-void TransitionTriforce_SetState(TransitionTriforce* this, s32 state) {
+void TransitionTriforce_SetState(void* thisx, s32 state) {
+ TransitionTriforce* this = THIS;
+
this->state = state;
}
-void TransitionTriforce_Draw(TransitionTriforce* this, Gfx** gfxP) {
-
+void TransitionTriforce_Draw(void* thisx, Gfx** gfxP) {
Gfx* gfx = *gfxP;
Mtx* modelView;
f32 scale;
- char pad[4];
-
- char pad2[4];
- f32 rotation;
+ TransitionTriforce* this = THIS;
+ s32 pad;
+ f32 rotation = this->transPos * 360.0f;
- rotation = this->transPos * 360.0f;
modelView = this->modelView[this->frame];
scale = this->transPos * 0.625f;
this->frame ^= 1;
@@ -125,8 +136,11 @@ void TransitionTriforce_Draw(TransitionTriforce* this, Gfx** gfxP) {
*gfxP = gfx;
}
-s32 TransitionTriforce_IsDone(TransitionTriforce* this) {
+s32 TransitionTriforce_IsDone(void* thisx) {
+ TransitionTriforce* this = THIS;
+
s32 ret = 0;
+
if (this->state == 1 || this->state == 2) {
return this->transPos <= 0.03f;
diff --git a/src/code/z_fbdemo_wipe1.c b/src/code/z_fbdemo_wipe1.c
index 3c0456cce..68306e84d 100644
--- a/src/code/z_fbdemo_wipe1.c
+++ b/src/code/z_fbdemo_wipe1.c
@@ -161,8 +161,13 @@ Gfx sWipeSyncDList[] = {
gsSPEndDisplayList(),
};
-void TransitionWipe_Start(TransitionWipe* this) {
+#define THIS ((TransitionWipe*)thisx)
+
+void TransitionWipe_Start(void* thisx) {
+ TransitionWipe* this = THIS;
+
this->isDone = 0;
+
if (this->direction) {
this->texY = 0x14D;
} else {
@@ -173,15 +178,18 @@ void TransitionWipe_Start(TransitionWipe* this) {
guLookAt(&this->lookAt, 0.0f, 0.0f, 400.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
}
-TransitionWipe* TransitionWipe_Init(TransitionWipe* this) {
+void* TransitionWipe_Init(void* thisx) {
+ TransitionWipe* this = THIS;
+
bzero(this, sizeof(*this));
return this;
}
-void TransitionWipe_Destroy(TransitionWipe* this) {
+void TransitionWipe_Destroy(void* thisx) {
}
-void TransitionWipe_Update(TransitionWipe* this, s32 updateRate) {
+void TransitionWipe_Update(void* thisx, s32 updateRate) {
+ TransitionWipe* this = THIS;
u8 unk1419;
if (this->direction != 0) {
@@ -201,13 +209,15 @@ void TransitionWipe_Update(TransitionWipe* this, s32 updateRate) {
}
}
-void TransitionWipe_Draw(TransitionWipe* this, Gfx** gfxP) {
+void TransitionWipe_Draw(void* thisx, Gfx** gfxP) {
Gfx* gfx = *gfxP;
Mtx* modelView;
- char pad[0x14];
+ TransitionWipe* this = THIS;
+ s32 pad[4];
Gfx* tex;
modelView = this->modelView[this->frame];
+
this->frame ^= 1;
guScale(&modelView[0], 0.56f, 0.56f, 1.0f);
guRotate(&modelView[1], 0.0f, 0.0f, 0.0f, 1.0f);
@@ -227,11 +237,15 @@ void TransitionWipe_Draw(TransitionWipe* this, Gfx** gfxP) {
*gfxP = gfx;
}
-s32 TransitionWipe_IsDone(TransitionWipe* this) {
+s32 TransitionWipe_IsDone(void* thisx) {
+ TransitionWipe* this = THIS;
+
return this->isDone;
}
-void TransitionWipe_SetType(TransitionWipe* this, s32 type) {
+void TransitionWipe_SetType(void* thisx, s32 type) {
+ TransitionWipe* this = THIS;
+
if (type == 1) {
this->direction = 1;
} else {
@@ -245,10 +259,14 @@ void TransitionWipe_SetType(TransitionWipe* this, s32 type) {
}
}
-void TransitionWipe_SetColor(TransitionWipe* this, u32 color) {
+void TransitionWipe_SetColor(void* thisx, u32 color) {
+ TransitionWipe* this = THIS;
+
this->color.rgba = color;
}
-void TransitionWipe_SetEnvColor(TransitionWipe* this, u32 color) {
+void TransitionWipe_SetEnvColor(void* thisx, u32 color) {
+ TransitionWipe* this = THIS;
+
this->envColor.rgba = color;
}
diff --git a/src/code/z_fcurve_data_skelanime.c b/src/code/z_fcurve_data_skelanime.c
index e01e0517e..83938690d 100644
--- a/src/code/z_fcurve_data_skelanime.c
+++ b/src/code/z_fcurve_data_skelanime.c
@@ -51,15 +51,13 @@ s32 SkelCurve_Update(GlobalContext* globalCtx, SkelAnimeCurve* skelCurve) {
TransformUpdateIndex* transformIndex;
u16* transformCopyValues;
s32 i;
- s32 ret;
+ s32 ret = 0;
s32 k;
TransformData* transData;
f32 transformValue;
s32 j;
- ret = 0;
transformIndex = SEGMENTED_TO_VIRTUAL(skelCurve->transUpdIdx);
-
transformRefIdx = SEGMENTED_TO_VIRTUAL(transformIndex->refIndex);
transData = SEGMENTED_TO_VIRTUAL(transformIndex->transformData);
transformCopyValues = SEGMENTED_TO_VIRTUAL(transformIndex->copyValues);
@@ -112,9 +110,8 @@ void SkelCurve_DrawLimb(GlobalContext* globalCtx, s32 limbIndex, SkelAnimeCurve*
Vec3s rot;
Vec3f pos;
Gfx* dList;
- Vec3s* transform;
+ Vec3s* transform = (Vec3s*)&skelCurve->transforms[limbIndex];
- transform = &skelCurve->transforms[limbIndex];
scale.x = transform->x / 1024.0f;
scale.y = transform->y / 1024.0f;
scale.z = transform->z / 1024.0f;
diff --git a/src/code/z_horse.c b/src/code/z_horse.c
index fd6cb3cbb..db2443033 100644
--- a/src/code/z_horse.c
+++ b/src/code/z_horse.c
@@ -69,8 +69,7 @@ void func_8006D0EC(GlobalContext* globalCtx, Player* player) {
Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, 3586.0f, 1413.0f, -402.0f, 0, 0x4000, 0, 1);
horseActor->room = -1;
} else if ((gSaveContext.entranceIndex == 1230) && (gSaveContext.eventChkInf[1] & 0x100)) {
- Actor* horseActor;
- horseActor =
+ Actor* horseActor =
Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, -25.0f, 0.0f, -1600.0f, 0, -0x4000, 0, 1);
if (horseActor == NULL) {
__assert("horse_actor != NULL", "../z_horse.c", 389);
@@ -82,10 +81,9 @@ void func_8006D0EC(GlobalContext* globalCtx, Player* player) {
DREG(1));
if (func_8006CFC0(gSaveContext.horseData.scene)) {
- Actor* horseActor;
- horseActor = Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, gSaveContext.horseData.pos.x,
- gSaveContext.horseData.pos.y, gSaveContext.horseData.pos.z, 0,
- gSaveContext.horseData.angle, 0, 1);
+ Actor* horseActor = Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE,
+ gSaveContext.horseData.pos.x, gSaveContext.horseData.pos.y,
+ gSaveContext.horseData.pos.z, 0, gSaveContext.horseData.angle, 0, 1);
if (horseActor == NULL) {
__assert("horse_actor != NULL", "../z_horse.c", 414);
}
@@ -101,17 +99,16 @@ void func_8006D0EC(GlobalContext* globalCtx, Player* player) {
func_8006D074(globalCtx);
}
} else if ((globalCtx->sceneNum == SCENE_SPOT20) && !Flags_GetEventChkInf(0x18) && (DREG(1) == 0)) {
- Actor* horseActor;
- horseActor = Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, 0.0f, 0.0f, -500.0f, 0, 0, 0, 1);
- if (horseActor == 0) {
+ Actor* horseActor =
+ Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, 0.0f, 0.0f, -500.0f, 0, 0, 0, 1);
+ if (horseActor == NULL) {
__assert("horse_actor != NULL", "../z_horse.c", 443);
}
} else if (Flags_GetEventChkInf(0x18) || (DREG(1) != 0)) {
for (i = 0; i < ARRAY_COUNT(horseSpawns); i++) {
HorseSpawn* horseSpawn = &horseSpawns[i];
if (horseSpawn->scene == globalCtx->sceneNum) {
- Actor* horseActor;
- horseActor =
+ Actor* horseActor =
Actor_Spawn(&globalCtx->actorCtx, globalCtx, ACTOR_EN_HORSE, horseSpawn->pos.x, horseSpawn->pos.y,
horseSpawn->pos.z, 0, horseSpawn->angle, 0, horseSpawn->type);
if (horseActor == NULL) {
@@ -218,9 +215,8 @@ void func_8006D684(GlobalContext* globalCtx, Player* player) {
func_8002DE74(globalCtx, player);
} else if ((D_8011F9B8[i].type == 5) || (D_8011F9B8[i].type == 6) || (D_8011F9B8[i].type == 8)) {
Vec3f sp54;
- s32 temp;
+ s32 temp = 0;
- temp = 0;
if (((gSaveContext.eventInf[0] & 0x10) >> 4) && D_8011F9B8[i].type == 6) {
temp = 0x8000;
}
diff --git a/src/code/z_jpeg.c b/src/code/z_jpeg.c
index a672f8526..9bea32d45 100644
--- a/src/code/z_jpeg.c
+++ b/src/code/z_jpeg.c
@@ -48,8 +48,8 @@ u32 Jpeg_SendTask(JpegContext* ctx) {
sJpegTask.flags = 0;
sJpegTask.ucode_boot = SysUcode_GetUCodeBoot();
sJpegTask.ucode_boot_size = SysUcode_GetUCodeBootSize();
- sJpegTask.yield_data_ptr = &workBuf->yieldData;
- sJpegTask.data_ptr = &workBuf->taskData;
+ sJpegTask.yield_data_ptr = (u64*)&workBuf->yieldData;
+ sJpegTask.data_ptr = (u64*)&workBuf->taskData;
ctx->scTask.next = NULL;
ctx->scTask.flags = OS_SC_NEEDS_RSP;
@@ -64,11 +64,9 @@ u32 Jpeg_SendTask(JpegContext* ctx) {
}
void Jpeg_CopyToZbuffer(u16* src, u16* zbuffer, s32 x, s32 y) {
- u16* dst;
+ u16* dst = zbuffer + (((y * SCREEN_WIDTH) + x) * 16);
s32 i;
- dst = zbuffer + (((y * SCREEN_WIDTH) + x) * 16);
-
for (i = 0; i < 16; i++) {
dst[0] = src[0];
dst[1] = src[1];
@@ -101,9 +99,8 @@ u16 Jpeg_GetU16(u8* ptr) {
}
void Jpeg_ParseMarkers(u8* ptr, JpegContext* ctx) {
- u32 exit;
+ u32 exit = false;
- exit = false;
ctx->dqtCount = 0;
ctx->dhtCount = 0;
@@ -203,9 +200,9 @@ void Jpeg_ParseMarkers(u8* ptr, JpegContext* ctx) {
}
}
+#ifdef NON_MATCHING
// the time diff isn't correct, workBuff->unk_6C0 is kept in a temp register instead of being stored in the stack and
// regalloc differences
-#ifdef NON_MATCHING
s32 Jpeg_Decode(void* data, u16* zbuffer, JpegWork* workBuff, u32 workSize) {
s32 y;
s32 x;
@@ -273,27 +270,22 @@ s32 Jpeg_Decode(void* data, u16* zbuffer, JpegWork* workBuff, u32 workSize) {
switch (ctx.dhtCount) {
case 1: {
- if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[0], &hTables[0], &workBuff->codesLengths, &workBuff->codes,
- 4)) {
+ if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[0], &hTables[0], workBuff->codesLengths, workBuff->codes, 4)) {
osSyncPrintf("Error : Cant' make huffman table.\n");
}
break;
}
case 4: {
- if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[0], &hTables[0], &workBuff->codesLengths, &workBuff->codes,
- 1)) {
+ if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[0], &hTables[0], workBuff->codesLengths, workBuff->codes, 1)) {
osSyncPrintf("Error : Cant' make huffman table.\n");
}
- if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[1], &hTables[1], &workBuff->codesLengths, &workBuff->codes,
- 1)) {
+ if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[1], &hTables[1], workBuff->codesLengths, workBuff->codes, 1)) {
osSyncPrintf("Error : Cant' make huffman table.\n");
}
- if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[2], &hTables[2], &workBuff->codesLengths, &workBuff->codes,
- 1)) {
+ if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[2], &hTables[2], workBuff->codesLengths, workBuff->codes, 1)) {
osSyncPrintf("Error : Cant' make huffman table.\n");
}
- if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[3], &hTables[3], &workBuff->codesLengths, &workBuff->codes,
- 1)) {
+ if (JpegUtils_ProcessHuffmanTable(ctx.dhtPtr[3], &hTables[3], workBuff->codesLengths, workBuff->codes, 1)) {
osSyncPrintf("Error : Cant' make huffman table.\n");
}
break;
@@ -321,7 +313,7 @@ s32 Jpeg_Decode(void* data, u16* zbuffer, JpegWork* workBuff, u32 workSize) {
y = 0;
x = 0;
for (i = 0; i < 300; i += 4) {
- if (JpegDecoder_Decode(&decoder, &workBuff->unk_6C0, 4, i != 0, &state)) {
+ if (JpegDecoder_Decode(&decoder, (u16*)workBuff->unk_6C0, 4, i != 0, &state)) {
osSyncPrintf(VT_FGCOL(RED));
osSyncPrintf("Error : Can't decode jpeg\n");
osSyncPrintf(VT_RST);
@@ -329,9 +321,9 @@ s32 Jpeg_Decode(void* data, u16* zbuffer, JpegWork* workBuff, u32 workSize) {
Jpeg_SendTask(&ctx);
osInvalDCache(&workBuff->unk_6C0, sizeof(workBuff->unk_6C0[0]));
- src = &workBuff->unk_6C0;
+ src = workBuff->unk_6C0;
for (j = 0; j < ARRAY_COUNT(workBuff->unk_6C0); j++) {
- Jpeg_CopyToZbuffer(&src[j], zbuffer, x, y);
+ Jpeg_CopyToZbuffer(src[j], zbuffer, x, y);
x++;
if (x >= 20) {
diff --git a/src/code/z_kaleido_manager.c b/src/code/z_kaleido_manager.c
index 6f80b3ae1..194b5988b 100644
--- a/src/code/z_kaleido_manager.c
+++ b/src/code/z_kaleido_manager.c
@@ -39,11 +39,10 @@ void KaleidoManager_ClearOvl(KaleidoManagerOvl* ovl) {
}
void KaleidoManager_Init(GlobalContext* globalCtx) {
- s32 largestOvl;
+ s32 largestOvl = 0;
s32 vramSize;
u32 idx;
- largestOvl = 0;
for (idx = 0; idx < ARRAY_COUNT(gKaleidoMgrOverlayTable); idx++) {
vramSize = gKaleidoMgrOverlayTable[idx].vramEnd - (u32)gKaleidoMgrOverlayTable[idx].vramStart;
if (largestOvl < vramSize) {
@@ -60,6 +59,7 @@ void KaleidoManager_Init(GlobalContext* globalCtx) {
osSyncPrintf(VT_RST);
gKaleidoMgrCurOvl = 0;
}
+
void KaleidoManager_Destroy() {
if (gKaleidoMgrCurOvl) {
KaleidoManager_ClearOvl(gKaleidoMgrCurOvl);
@@ -70,13 +70,11 @@ void KaleidoManager_Destroy() {
// NOTE: this function looks messed up and probably doesn't work like how the devs wanted it to work
void* KaleidoManager_GetRamAddr(void* vram) {
- KaleidoManagerOvl* iter;
- KaleidoManagerOvl* ovl;
+ KaleidoManagerOvl* iter = gKaleidoMgrCurOvl;
+ KaleidoManagerOvl* ovl = iter;
u32 idx;
- iter = gKaleidoMgrCurOvl;
- ovl = iter;
- if (!ovl) {
+ if (ovl == NULL) {
iter = &gKaleidoMgrOverlayTable[0];
for (idx = 0; idx != ARRAY_COUNT(gKaleidoMgrOverlayTable); idx++) {
if ((u32)vram >= (u32)iter->vramStart && (u32)iter->vramEnd >= (u32)vram) {
@@ -92,7 +90,7 @@ void* KaleidoManager_GetRamAddr(void* vram) {
}
KaleidoManager_GetRamAddr_end:
- if (!ovl || (u32)vram < (u32)ovl->vramStart || (u32)vram >= (u32)ovl->vramEnd) {
+ if (ovl == NULL || (u32)vram < (u32)ovl->vramStart || (u32)vram >= (u32)ovl->vramEnd) {
return NULL;
}
diff --git a/src/code/z_lib.c b/src/code/z_lib.c
index 54f90bb3b..c8ffa4fad 100644
--- a/src/code/z_lib.c
+++ b/src/code/z_lib.c
@@ -345,11 +345,8 @@ void IChain_Apply_f32div1000(u8* ptr, InitChainEntry* ichain) {
}
void IChain_Apply_Vec3f(u8* ptr, InitChainEntry* ichain) {
- Vec3f* vec;
- f32 val;
-
- vec = (Vec3f*)(ptr + ichain->offset);
- val = ichain->value;
+ Vec3f* vec = (Vec3f*)(ptr + ichain->offset);
+ f32 val = ichain->value;
vec->z = val;
vec->y = val;
@@ -357,10 +354,9 @@ void IChain_Apply_Vec3f(u8* ptr, InitChainEntry* ichain) {
}
void IChain_Apply_Vec3fdiv1000(u8* ptr, InitChainEntry* ichain) {
- Vec3f* vec;
+ Vec3f* vec = (Vec3f*)(ptr + ichain->offset);
f32 val;
- vec = (Vec3f*)(ptr + ichain->offset);
osSyncPrintf("pp=%x data=%f\n", vec, ichain->value / 1000.0f);
val = ichain->value / 1000.0f;
@@ -370,11 +366,8 @@ void IChain_Apply_Vec3fdiv1000(u8* ptr, InitChainEntry* ichain) {
}
void IChain_Apply_Vec3s(u8* ptr, InitChainEntry* ichain) {
- Vec3s* vec;
- s16 val;
-
- vec = (Vec3s*)(ptr + ichain->offset);
- val = ichain->value;
+ Vec3s* vec = (Vec3s*)(ptr + ichain->offset);
+ s16 val = ichain->value;
vec->z = val;
vec->y = val;
diff --git a/src/code/z_lifemeter.c b/src/code/z_lifemeter.c
index 08f161c51..9c4143437 100644
--- a/src/code/z_lifemeter.c
+++ b/src/code/z_lifemeter.c
@@ -137,6 +137,7 @@ void HealthMeter_Update(GlobalContext* globalCtx) {
s16 bFactor;
if (interfaceCtx) {}
+
if (interfaceCtx->unk_200 != 0) {
interfaceCtx->unk_1FE--;
if (interfaceCtx->unk_1FE <= 0) {
diff --git a/src/code/z_malloc.c b/src/code/z_malloc.c
index f992755a1..15b5b4c4c 100644
--- a/src/code/z_malloc.c
+++ b/src/code/z_malloc.c
@@ -8,12 +8,11 @@ s32 gZeldaArenaLogSeverity = LOG_SEVERITY_ERROR;
Arena sZeldaArena;
void ZeldaArena_CheckPointer(void* ptr, u32 size, const char* name, const char* action) {
- if (!ptr) {
+ if (ptr == NULL) {
if (gZeldaArenaLogSeverity >= LOG_SEVERITY_ERROR) {
// "%s: %u bytes %s failed\n"
osSyncPrintf("%s: %u バイトの%sに失敗しました\n", name, size, action);
__osDisplayArena(&sZeldaArena);
- return;
}
} else if (gZeldaArenaLogSeverity >= LOG_SEVERITY_VERBOSE) {
// "%s: %u bytes %s succeeded\n"
@@ -22,29 +21,29 @@ void ZeldaArena_CheckPointer(void* ptr, u32 size, const char* name, const char*
}
void* ZeldaArena_Malloc(u32 size) {
- void* ptr;
- ptr = __osMalloc(&sZeldaArena, size);
+ void* ptr = __osMalloc(&sZeldaArena, size);
+
ZeldaArena_CheckPointer(ptr, size, "zelda_malloc", "確保"); // Secure
return ptr;
}
void* ZeldaArena_MallocDebug(u32 size, const char* file, s32 line) {
- void* ptr;
- ptr = __osMallocDebug(&sZeldaArena, size, file, line);
+ void* ptr = __osMallocDebug(&sZeldaArena, size, file, line);
+
ZeldaArena_CheckPointer(ptr, size, "zelda_malloc_DEBUG", "確保"); // Secure
return ptr;
}
void* ZeldaArena_MallocR(u32 size) {
- void* ptr;
- ptr = __osMallocR(&sZeldaArena, size);
+ void* ptr = __osMallocR(&sZeldaArena, size);
+
ZeldaArena_CheckPointer(ptr, size, "zelda_malloc_r", "確保"); // Secure
return ptr;
}
void* ZeldaArena_MallocRDebug(u32 size, const char* file, s32 line) {
- void* ptr;
- ptr = __osMallocRDebug(&sZeldaArena, size, file, line);
+ void* ptr = __osMallocRDebug(&sZeldaArena, size, file, line);
+
ZeldaArena_CheckPointer(ptr, size, "zelda_malloc_r_DEBUG", "確保"); // Secure
return ptr;
}
@@ -71,11 +70,10 @@ void ZeldaArena_FreeDebug(void* ptr, const char* file, s32 line) {
void* ZeldaArena_Calloc(u32 num, u32 size) {
void* ret;
- u32 n;
+ u32 n = num * size;
- n = num * size;
ret = __osMalloc(&sZeldaArena, n);
- if (ret) {
+ if (ret != NULL) {
bzero(ret, n);
}
diff --git a/src/code/z_map_exp.c b/src/code/z_map_exp.c
index 509c95145..93fbdbd23 100644
--- a/src/code/z_map_exp.c
+++ b/src/code/z_map_exp.c
@@ -537,13 +537,12 @@ void Map_Update(GlobalContext* globalCtx) {
}
}
- if (1) { // Appears to be necessary to match
- gSaveContext.sceneFlags[mapIndex].floors |= gBitFlags[floor];
- VREG(30) = floor;
- if (R_MAP_TEX_INDEX != (R_MAP_TEX_INDEX_BASE + Map_GetFloorTextIndexOffset(mapIndex, floor))) {
- R_MAP_TEX_INDEX = R_MAP_TEX_INDEX_BASE + Map_GetFloorTextIndexOffset(mapIndex, floor);
- }
+ gSaveContext.sceneFlags[mapIndex].floors |= gBitFlags[floor];
+ VREG(30) = floor;
+ if (R_MAP_TEX_INDEX != (R_MAP_TEX_INDEX_BASE + Map_GetFloorTextIndexOffset(mapIndex, floor))) {
+ R_MAP_TEX_INDEX = R_MAP_TEX_INDEX_BASE + Map_GetFloorTextIndexOffset(mapIndex, floor);
}
+ if (1) {} // Appears to be necessary to match
if (interfaceCtx->mapRoomNum != sLastRoomNum) {
// Translates to "Current floor = %d Current room = %x Number of rooms = %d"
diff --git a/src/code/z_map_mark.c b/src/code/z_map_mark.c
index 30752f531..eaf0d6324 100644
--- a/src/code/z_map_mark.c
+++ b/src/code/z_map_mark.c
@@ -78,12 +78,11 @@ void MapMark_Draw(GlobalContext* globalCtx) {
MapMarkData* mapMarkData;
MapMarkPoint* markPoint;
MapMarkInfo* markInfo;
- u16 dungeon;
+ u16 dungeon = gSaveContext.mapIndex;
s32 i;
s32 rectLeft;
s32 rectTop;
- dungeon = gSaveContext.mapIndex;
interfaceCtx = &globalCtx->interfaceCtx;
if ((gMapData != NULL) && (globalCtx->interfaceCtx.mapRoomNum >= gMapData->dgnMinimapCount[dungeon])) {
@@ -97,7 +96,7 @@ void MapMark_Draw(GlobalContext* globalCtx) {
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_map_mark.c", 303);
- while (1) {
+ while (true) {
if (mapMarkData->markType == -1) {
break;
}
diff --git a/src/code/z_msgevent.c b/src/code/z_msgevent.c
index d09ab08d3..267180e1f 100644
--- a/src/code/z_msgevent.c
+++ b/src/code/z_msgevent.c
@@ -1,6 +1,6 @@
#include "global.h"
-void MsgEvent_SendNullTask() {
+void MsgEvent_SendNullTask(void) {
s32 pad[4];
OSScTask task;
OSMesgQueue queue;
diff --git a/src/code/z_olib.c b/src/code/z_olib.c
index 9c1ca8861..72cd6694b 100644
--- a/src/code/z_olib.c
+++ b/src/code/z_olib.c
@@ -76,12 +76,10 @@ Vec3f* OLib_Vec3fDistNormalize(Vec3f* dest, Vec3f* a, Vec3f* b) {
Vec3f* OLib_VecSphToVec3f(Vec3f* dest, VecSph* sph) {
Vec3f v;
f32 sinPitch;
- f32 cosPitch;
+ f32 cosPitch = Math_CosS(sph->pitch);
f32 sinYaw;
- f32 cosYaw;
+ f32 cosYaw = Math_CosS(sph->yaw);
- cosPitch = Math_CosS(sph->pitch);
- cosYaw = Math_CosS(sph->yaw);
sinPitch = Math_SinS(sph->pitch);
sinYaw = Math_SinS(sph->yaw);
@@ -113,11 +111,8 @@ Vec3f* OLib_VecSphGeoToVec3f(Vec3f* dest, VecSph* sph) {
VecSph* OLib_Vec3fToVecSph(VecSph* dest, Vec3f* vec) {
VecSph sph;
- f32 distSquared;
- f32 dist;
-
- distSquared = SQ(vec->x) + SQ(vec->z);
- dist = sqrtf(distSquared);
+ f32 distSquared = SQ(vec->x) + SQ(vec->z);
+ f32 dist = sqrtf(distSquared);
if ((dist == 0.0f) && (vec->y == 0.0f)) {
sph.pitch = 0;
diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c
index 40ac50240..51039feb3 100644
--- a/src/code/z_parameter.c
+++ b/src/code/z_parameter.c
@@ -238,9 +238,7 @@ void func_8008277C(GlobalContext* globalCtx, s16 maxAlpha, s16 alpha) {
void func_80082850(GlobalContext* globalCtx, s16 maxAlpha) {
InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx;
- s16 alpha;
-
- alpha = 255 - maxAlpha;
+ s16 alpha = 255 - maxAlpha;
switch (gSaveContext.unk_13E8) {
case 1:
@@ -600,9 +598,7 @@ void func_80083108(GlobalContext* globalCtx) {
Player* player = PLAYER;
InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx;
s16 i;
- s16 sp28;
-
- sp28 = 0;
+ s16 sp28 = 0;
if ((gSaveContext.cutsceneIndex < 0xFFF0) ||
((globalCtx->sceneNum == SCENE_SPOT20) && (gSaveContext.cutsceneIndex == 0xFFF0))) {
@@ -760,22 +756,21 @@ void func_80083108(GlobalContext* globalCtx) {
}
}
} else {
- do {
- sp28 = 1;
+ sp28 = 1;
- if ((gSaveContext.equips.buttonItems[0] == ITEM_NONE) ||
- (gSaveContext.equips.buttonItems[0] == ITEM_BOW)) {
+ if ((gSaveContext.equips.buttonItems[0] == ITEM_NONE) ||
+ (gSaveContext.equips.buttonItems[0] == ITEM_BOW)) {
- if ((gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KOKIRI) &&
- (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_MASTER) &&
- (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_BGS) &&
- (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KNIFE)) {
- gSaveContext.equips.buttonItems[0] = gSaveContext.buttonStatus[0];
- } else {
- gSaveContext.buttonStatus[0] = gSaveContext.equips.buttonItems[0];
- }
+ if ((gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KOKIRI) &&
+ (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_MASTER) &&
+ (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_BGS) &&
+ (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KNIFE)) {
+ gSaveContext.equips.buttonItems[0] = gSaveContext.buttonStatus[0];
+ } else {
+ gSaveContext.buttonStatus[0] = gSaveContext.equips.buttonItems[0];
}
- } while (0); // Necessary to match
+ }
+ if (1) {} // Necessary to match
}
if (sp28) {
@@ -1788,10 +1783,9 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) {
u8 Item_CheckObtainability(u8 item) {
s16 i;
- s16 slot;
+ s16 slot = SLOT(item);
s32 temp;
- slot = SLOT(item);
if (item >= ITEM_STICKS_5) {
slot = SLOT(sExtraItemBases[item - ITEM_STICKS_5]);
}
@@ -2009,12 +2003,10 @@ void Inventory_UpdateBottleItem(GlobalContext* globalCtx, u8 item, u8 button) {
}
s32 Inventory_ConsumeFairy(GlobalContext* globalCtx) {
- s32 bottleSlot;
+ s32 bottleSlot = SLOT(ITEM_FAIRY);
s16 i;
s16 j;
- bottleSlot = SLOT(ITEM_FAIRY);
-
for (i = 0; i < 4; i++) {
if (gSaveContext.inventory.items[bottleSlot + i] == ITEM_FAIRY) {
for (j = 1; j < 4; j++) {
diff --git a/src/code/z_play.c b/src/code/z_play.c
index b9331e49d..5d8cc785b 100644
--- a/src/code/z_play.c
+++ b/src/code/z_play.c
@@ -204,7 +204,7 @@ void Gameplay_Init(GameState* thisx) {
}
SystemArena_Display();
- GameState_Realloc(globalCtx, 0x1D4790);
+ GameState_Realloc(&globalCtx->state, 0x1D4790);
KaleidoManager_Init(globalCtx);
View_Init(&globalCtx->view, gfxCtx);
func_800F6828(0);
@@ -456,7 +456,7 @@ void Gameplay_Update(GlobalContext* globalCtx) {
osSyncPrintf("fbdemo_init呼出し失敗!\n"); // "fbdemo_init call failed!"
gTrnsnUnkState = 0;
} else {
- sTrnsnUnk.zBuffer = gZBuffer;
+ sTrnsnUnk.zBuffer = (u16*)gZBuffer;
gTrnsnUnkState = 3;
R_UPDATE_RATE = 1;
}
@@ -1276,10 +1276,10 @@ void Gameplay_Draw(GlobalContext* globalCtx) {
if ((R_PAUSE_MENU_MODE == 1) || (gTrnsnUnkState == 1)) {
Gfx* sp70 = gfxCtx->overlay.p;
globalCtx->preRenderCtx.fbuf = gfxCtx->curFrameBuffer;
- globalCtx->preRenderCtx.fbufSave = gZBuffer;
+ globalCtx->preRenderCtx.fbufSave = (u16*)gZBuffer;
func_800C1F20(&globalCtx->preRenderCtx, &sp70);
if (R_PAUSE_MENU_MODE == 1) {
- globalCtx->preRenderCtx.cvgSave = gfxCtx->curFrameBuffer;
+ globalCtx->preRenderCtx.cvgSave = (u8*)gfxCtx->curFrameBuffer;
func_800C20B4(&globalCtx->preRenderCtx, &sp70);
R_PAUSE_MENU_MODE = 2;
} else {
diff --git a/src/code/z_player_call.c b/src/code/z_player_call.c
index d6ed609d2..3f4e11be5 100644
--- a/src/code/z_player_call.c
+++ b/src/code/z_player_call.c
@@ -29,7 +29,7 @@ const ActorInit Player_InitVars = {
(ActorFunc)PlayerCall_Draw,
};
-void PlayerCall_InitFuncPtrs() {
+void PlayerCall_InitFuncPtrs(void) {
sPlayerCallInitFunc = KaleidoManager_GetRamAddr(Player_Init);
sPlayerCallDestroyFunc = KaleidoManager_GetRamAddr(Player_Destroy);
sPlayerCallUpdateFunc = KaleidoManager_GetRamAddr(Player_Update);
diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c
index 3481b30a8..ab47b6739 100644
--- a/src/code/z_player_lib.c
+++ b/src/code/z_player_lib.c
@@ -1070,7 +1070,7 @@ void func_80090A28(Player* this, Vec3f* vecs) {
void func_80090AFC(GlobalContext* globalCtx, Player* this, f32 arg2) {
static Vec3f D_801260C8 = { -500.0f, -100.0f, 0.0f };
CollisionPoly* sp9C;
- f32 sp98;
+ s32 bgId;
Vec3f sp8C;
Vec3f sp80;
Vec3f sp74;
@@ -1085,7 +1085,7 @@ void func_80090AFC(GlobalContext* globalCtx, Player* this, f32 arg2) {
if (1) {}
- if (BgCheck_AnyLineTest3(&globalCtx->colCtx, &sp8C, &sp80, &sp74, &sp9C, 1, 1, 1, 1, &sp98)) {
+ if (BgCheck_AnyLineTest3(&globalCtx->colCtx, &sp8C, &sp80, &sp74, &sp9C, 1, 1, 1, 1, &bgId)) {
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_player_lib.c", 2572);
OVERLAY_DISP = Gfx_CallSetupDL(OVERLAY_DISP, 0x07);
@@ -1208,7 +1208,7 @@ void func_80090D20(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s*
gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_player_lib.c", 2712),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gDPSetEnvColor(POLY_XLU_DISP++, bottleColor->r, bottleColor->g, bottleColor->b, 0);
- gSPDisplayList(POLY_XLU_DISP++, sBottleDLists[(0, gSaveContext.linkAge)]);
+ gSPDisplayList(POLY_XLU_DISP++, sBottleDLists[((void)0, gSaveContext.linkAge)]);
CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_player_lib.c", 2717);
}
@@ -1339,7 +1339,7 @@ void func_80090D20(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s*
} else if (limbIndex == PLAYER_LIMB_HEAD) {
Matrix_MultVec3f(&D_801260D4, &this->actor.focus.pos);
} else {
- Vec3f* vec = &D_801261E0[(0, gSaveContext.linkAge)];
+ Vec3f* vec = &D_801261E0[((void)0, gSaveContext.linkAge)];
Actor_SetFeetPos(&this->actor, limbIndex, PLAYER_LIMB_L_FOOT, vec, PLAYER_LIMB_R_FOOT, vec);
}
@@ -1347,12 +1347,10 @@ void func_80090D20(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s*
}
u32 func_80091738(GlobalContext* globalCtx, u8* segment, SkelAnime* skelAnime) {
- s16 linkObjectId;
+ s16 linkObjectId = gLinkObjectIds[(void)0, gSaveContext.linkAge];
u32 size;
void* ptr;
- linkObjectId = gLinkObjectIds[(void)0, gSaveContext.linkAge];
-
size = gObjectTable[OBJECT_GAMEPLAY_KEEP].vromEnd - gObjectTable[OBJECT_GAMEPLAY_KEEP].vromStart;
ptr = segment + 0x3800;
DmaMgr_SendRequest1(ptr, gObjectTable[OBJECT_GAMEPLAY_KEEP].vromStart, size, "../z_player_lib.c", 2982);
@@ -1374,7 +1372,7 @@ u32 func_80091738(GlobalContext* globalCtx, u8* segment, SkelAnime* skelAnime) {
u8 D_801261F8[] = { 2, 2, 5 };
-s32 func_80091880(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s* pos, Vec3s* rot, void* arg) {
+s32 func_80091880(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, void* arg) {
u8* ptr = arg;
u8 modelGroup = D_801261F8[ptr[0] - 1];
s32 type;
@@ -1424,11 +1422,8 @@ void func_80091A24(GlobalContext* globalCtx, void* seg04, void* seg06, SkelAnime
Gfx* opaRef;
Gfx* xluRef;
u16 perspNorm;
- Mtx* perspMtx;
- Mtx* lookAtMtx;
-
- perspMtx = Graph_Alloc(globalCtx->state.gfxCtx, sizeof(Mtx));
- lookAtMtx = Graph_Alloc(globalCtx->state.gfxCtx, sizeof(Mtx));
+ Mtx* perspMtx = Graph_Alloc(globalCtx->state.gfxCtx, sizeof(Mtx));
+ Mtx* lookAtMtx = Graph_Alloc(globalCtx->state.gfxCtx, sizeof(Mtx));
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_player_lib.c", 3129);
diff --git a/src/code/z_prenmi.c b/src/code/z_prenmi.c
index 0a4ed75fb..9f0d3ad58 100644
--- a/src/code/z_prenmi.c
+++ b/src/code/z_prenmi.c
@@ -11,8 +11,10 @@ void PreNMI_Update(PreNMIContext* this) {
osSyncPrintf(VT_COL(YELLOW, BLACK) "prenmi_move\n" VT_RST);
// Strings existing only in rodata
- ("../z_prenmi.c");
- ("(int)volume = %d\n");
+ if (0) {
+ osSyncPrintf("../z_prenmi.c");
+ osSyncPrintf("(int)volume = %d\n");
+ }
if (this->timer == 0) {
ViConfig_UpdateVi(1);
diff --git a/src/code/z_prenmi_buff.c b/src/code/z_prenmi_buff.c
index 340309e69..c00d0513c 100644
--- a/src/code/z_prenmi_buff.c
+++ b/src/code/z_prenmi_buff.c
@@ -5,6 +5,7 @@
void PreNmiBuff_Init(PreNmiBuff* this) {
this->resetting = false;
+
if (osResetType == COLD_RESET) {
this->resetCount = 0;
this->duration = 0;
diff --git a/src/code/z_quake.c b/src/code/z_quake.c
index 8bf332420..f22fc7023 100644
--- a/src/code/z_quake.c
+++ b/src/code/z_quake.c
@@ -63,6 +63,7 @@ void Quake_UpdateShakeInfo(QuakeRequest* req, ShakeInfo* shake, f32 y, f32 x) {
s16 Quake_Callback1(QuakeRequest* req, ShakeInfo* shake) {
s32 pad;
+
if (req->countdown > 0) {
f32 a = Math_SinS(req->speed * req->countdown);
Quake_UpdateShakeInfo(req, shake, a, Rand_ZeroOne() * a);
@@ -117,7 +118,7 @@ s16 Quake_Callback4(QuakeRequest* req, ShakeInfo* shake) {
return req->countdown;
}
-s16 Quake_GetFreeIndex() {
+s16 Quake_GetFreeIndex(void) {
s32 i;
s32 ret;
s32 min = 0x10000;
@@ -178,9 +179,8 @@ QuakeRequest* Quake_GetRequest(s16 idx) {
}
QuakeRequest* Quake_SetValue(s16 idx, s16 valueType, s16 value) {
- QuakeRequest* req;
+ QuakeRequest* req = Quake_GetRequest(idx);
- req = Quake_GetRequest(idx);
if (req == NULL) {
return NULL;
} else {
@@ -222,7 +222,8 @@ QuakeRequest* Quake_SetValue(s16 idx, s16 valueType, s16 value) {
u32 Quake_SetSpeed(s16 idx, s16 value) {
QuakeRequest* req = Quake_GetRequest(idx);
- if (req) {
+
+ if (req != NULL) {
req->speed = value;
return true;
}
@@ -231,7 +232,8 @@ u32 Quake_SetSpeed(s16 idx, s16 value) {
u32 Quake_SetCountdown(s16 idx, s16 value) {
QuakeRequest* req = Quake_GetRequest(idx);
- if (req) {
+
+ if (req != NULL) {
req->countdown = value;
req->countdownMax = req->countdown;
return true;
@@ -241,7 +243,8 @@ u32 Quake_SetCountdown(s16 idx, s16 value) {
s16 Quake_GetCountdown(s16 idx) {
QuakeRequest* req = Quake_GetRequest(idx);
- if (req) {
+
+ if (req != NULL) {
return req->countdown;
}
return 0;
@@ -249,7 +252,8 @@ s16 Quake_GetCountdown(s16 idx) {
u32 Quake_SetQuakeValues(s16 idx, s16 y, s16 x, s16 zoom, s16 rotZ) {
QuakeRequest* req = Quake_GetRequest(idx);
- if (req) {
+
+ if (req != NULL) {
req->y = y;
req->x = x;
req->zoom = zoom;
@@ -261,7 +265,8 @@ u32 Quake_SetQuakeValues(s16 idx, s16 y, s16 x, s16 zoom, s16 rotZ) {
u32 Quake_SetUnkValues(s16 idx, s16 arg1, SubQuakeRequest14 arg2) {
QuakeRequest* req = Quake_GetRequest(idx);
- if (req) {
+
+ if (req != NULL) {
req->unk_1C = arg1;
req->unk_14 = arg2;
@@ -270,8 +275,9 @@ u32 Quake_SetUnkValues(s16 idx, s16 arg1, SubQuakeRequest14 arg2) {
return false;
}
-void Quake_Init() {
+void Quake_Init(void) {
s16 i;
+
for (i = 0; i < ARRAY_COUNT(sQuakeRequest); i++) {
sQuakeRequest[i].callbackIdx = 0;
sQuakeRequest[i].countdown = 0;
@@ -286,7 +292,8 @@ s16 Quake_Add(Camera* cam, u32 callbackIdx) {
u32 Quake_RemoveFromIdx(s16 idx) {
QuakeRequest* req = Quake_GetRequest(idx);
- if (req) {
+
+ if (req != NULL) {
Quake_Remove(req);
return true;
}
diff --git a/src/code/z_room.c b/src/code/z_room.c
index 4b802156d..ee49f50c8 100644
--- a/src/code/z_room.c
+++ b/src/code/z_room.c
@@ -237,7 +237,7 @@ s32 func_80096238(void* data) {
osSyncPrintf("ワークバッファアドレス(Zバッファ)%08x\n", gZBuffer);
time = osGetTime();
- if (!Jpeg_Decode(data, gZBuffer, gGfxSPTaskOutputBuffer, sizeof(gGfxSPTaskOutputBuffer))) {
+ if (!Jpeg_Decode(data, (u16*)gZBuffer, (JpegWork*)gGfxSPTaskOutputBuffer, sizeof(gGfxSPTaskOutputBuffer))) {
time = osGetTime() - time;
// Translates to: "SUCCESS... I THINK. time = %6.3f ms"
@@ -266,7 +266,7 @@ void func_8009638C(Gfx** displayList, u32 source, u32 tlut, u16 width, u16 heigh
displayListHead = *displayList;
func_80096238(SEGMENTED_TO_VIRTUAL(source));
- bg = displayListHead + 1;
+ bg = (uObjBg*)(displayListHead + 1);
gSPBranchList(displayListHead, (u8*)bg + sizeof(uObjBg));
bg->b.imageX = 0;
bg->b.imageW = width * 4;
diff --git a/src/code/z_sample.c b/src/code/z_sample.c
index 4adf07ba6..82ff5b776 100644
--- a/src/code/z_sample.c
+++ b/src/code/z_sample.c
@@ -49,11 +49,8 @@ void Sample_Destroy(GameState* thisx) {
}
void Sample_SetupView(SampleContext* this) {
- View* view;
- GraphicsContext* gfxCtx;
-
- view = &this->view;
- gfxCtx = this->state.gfxCtx;
+ View* view = &this->view;
+ GraphicsContext* gfxCtx = this->state.gfxCtx;
View_Init(view, gfxCtx);
SET_FULLSCREEN_VIEWPORT(view);
diff --git a/src/code/z_scene.c b/src/code/z_scene.c
index 05070c214..4fecad4cf 100644
--- a/src/code/z_scene.c
+++ b/src/code/z_scene.c
@@ -15,7 +15,7 @@ s32 Object_Spawn(ObjectContext* objectCtx, s16 objectId) {
objectCtx->spaceEnd);
if (!((objectCtx->num < OBJECT_EXCHANGE_BANK_MAX) &&
- (((s32)objectCtx->status[objectCtx->num].segment + size) < (s32)objectCtx->spaceEnd))) {
+ (((s32)objectCtx->status[objectCtx->num].segment + size) < (u32)objectCtx->spaceEnd))) {
__assert("this->num < OBJECT_EXCHANGE_BANK_MAX && (this->status[this->num].Segment + size) < this->endSegment",
"../z_scene.c", 142);
}
@@ -79,11 +79,10 @@ void Object_InitBank(GlobalContext* globalCtx, ObjectContext* objectCtx) {
void Object_UpdateBank(ObjectContext* objectCtx) {
s32 i;
- ObjectStatus* status;
+ ObjectStatus* status = &objectCtx->status[0];
RomFile* objectFile;
u32 size;
- status = &objectCtx->status[0];
for (i = 0; i < objectCtx->num; i++) {
if (status->id < 0) {
if (status->dmaRequest.vromAddr == 0) {
@@ -149,9 +148,8 @@ void* func_800982FC(ObjectContext* objectCtx, s32 bankIndex, s16 objectId) {
size = objectFile->vromEnd - objectFile->vromStart;
osSyncPrintf("OBJECT EXCHANGE NO=%2d BANK=%3d SIZE=%8.3fK\n", bankIndex, objectId, size / 1024.0f);
- if (1) { // Necessary to match
- nextPtr = (void*)ALIGN16((s32)status->segment + size);
- }
+ nextPtr = (void*)ALIGN16((s32)status->segment + size);
+ if (1) {} // Necessary to match
if (nextPtr >= objectCtx->spaceEnd) {
__assert("nextptr < this->endSegment", "../z_scene.c", 381);
@@ -166,7 +164,7 @@ void* func_800982FC(ObjectContext* objectCtx, s32 bankIndex, s16 objectId) {
s32 Scene_ExecuteCommands(GlobalContext* globalCtx, SceneCmd* sceneCmd) {
u32 cmdCode;
- while (1) {
+ while (true) {
cmdCode = sceneCmd->base.code;
osSyncPrintf("*** Scene_Word = { code=%d, data1=%02x, data2=%04x } ***\n", cmdCode, sceneCmd->base.data1,
sceneCmd->base.data2);
@@ -183,10 +181,8 @@ s32 Scene_ExecuteCommands(GlobalContext* globalCtx, SceneCmd* sceneCmd) {
osSyncPrintf("code の値が異常です\n");
osSyncPrintf(VT_RST);
}
-
sceneCmd++;
}
-
return 0;
}
@@ -216,9 +212,7 @@ void func_80098630(GlobalContext* globalCtx, SceneCmd* cmd) {
// Scene Command 0x03: Collision Header
void func_80098674(GlobalContext* globalCtx, SceneCmd* cmd) {
- CollisionHeader* colHeader;
-
- colHeader = SEGMENTED_TO_VIRTUAL(cmd->colHeader.segment);
+ CollisionHeader* colHeader = SEGMENTED_TO_VIRTUAL(cmd->colHeader.segment);
colHeader->vtxList = SEGMENTED_TO_VIRTUAL(colHeader->vtxList);
colHeader->polyList = SEGMENTED_TO_VIRTUAL(colHeader->polyList);
@@ -267,14 +261,15 @@ void func_80098958(GlobalContext* globalCtx, SceneCmd* cmd) {
// Scene Command 0x0B: Object List
void func_8009899C(GlobalContext* globalCtx, SceneCmd* cmd) {
- s32 i, j, k;
+ s32 i;
+ s32 j;
+ s32 k;
ObjectStatus* status;
ObjectStatus* status2;
ObjectStatus* firstStatus;
- s16* objectEntry;
+ s16* objectEntry = SEGMENTED_TO_VIRTUAL(cmd->objectList.segment);
void* nextPtr;
- objectEntry = SEGMENTED_TO_VIRTUAL(cmd->objectList.segment);
k = 0;
i = globalCtx->objectCtx.unk_09;
firstStatus = &globalCtx->objectCtx.status[0];
@@ -321,9 +316,8 @@ void func_8009899C(GlobalContext* globalCtx, SceneCmd* cmd) {
// Scene Command 0x0C: Light List
void func_80098B74(GlobalContext* globalCtx, SceneCmd* cmd) {
s32 i;
- LightInfo* lightInfo;
+ LightInfo* lightInfo = SEGMENTED_TO_VIRTUAL(cmd->lightList.segment);
- lightInfo = SEGMENTED_TO_VIRTUAL(cmd->lightList.segment);
for (i = 0; i < cmd->lightList.num; i++) {
LightContext_InsertLight(globalCtx, &globalCtx->lightCtx, lightInfo);
lightInfo++;
diff --git a/src/code/z_scene_table.c b/src/code/z_scene_table.c
index 107611d22..b21b43379 100644
--- a/src/code/z_scene_table.c
+++ b/src/code/z_scene_table.c
@@ -790,11 +790,11 @@ EntranceInfo gEntranceTable[] = {
#define TITLED_SCENE(name, title, unk_10, config, unk_12) \
{ \
(u32) _##name##SegmentRomStart, (u32)_##name##SegmentRomEnd, (u32)_##title##SegmentRomStart, \
- (u32)_##title##SegmentRomEnd, unk_10, config, unk_12 \
+ (u32)_##title##SegmentRomEnd, unk_10, config, unk_12, 0 \
}
#define UNTITLED_SCENE(name, unk_10, config, unk_12) \
- { (u32) _##name##SegmentRomStart, (u32)_##name##SegmentRomEnd, 0, 0, unk_10, config, unk_12 }
+ { (u32) _##name##SegmentRomStart, (u32)_##name##SegmentRomEnd, 0, 0, unk_10, config, unk_12, 0 }
Scene gSceneTable[] = {
TITLED_SCENE(ydan_scene, g_pn_06, 1, 19, 2),
@@ -957,9 +957,7 @@ u32 D_8012A2F8[] = { 0x0200BA18, 0x0200CA18 };
// Scene Draw Config 19
void func_800995DC(GlobalContext* globalCtx) {
- u32 gameplayFrames;
-
- gameplayFrames = globalCtx->gameplayFrames;
+ u32 gameplayFrames = globalCtx->gameplayFrames;
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_scene_table.c", 4763);
@@ -1001,9 +999,7 @@ u32 D_8012A308[] = { 0x02011F78, 0x02014778, 0x02014378, 0x02013F78, 0x02014B78,
void func_80099878(GlobalContext* globalCtx) {
u32 gameplayFrames;
s32 pad;
- Gfx* displayListHead;
-
- displayListHead = Graph_Alloc(globalCtx->state.gfxCtx, 6 * sizeof(Gfx));
+ Gfx* displayListHead = Graph_Alloc(globalCtx->state.gfxCtx, 6 * sizeof(Gfx));
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_scene_table.c", 4905);
@@ -1040,9 +1036,7 @@ void func_80099878(GlobalContext* globalCtx) {
// Scene Draw Config 30
void func_80099BD8(GlobalContext* globalCtx) {
f32 temp;
- Gfx* displayListHead;
-
- displayListHead = Graph_Alloc(globalCtx->state.gfxCtx, 18 * sizeof(Gfx));
+ Gfx* displayListHead = Graph_Alloc(globalCtx->state.gfxCtx, 18 * sizeof(Gfx));
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_scene_table.c", 5069);
@@ -2176,9 +2170,7 @@ void func_8009F40C(GlobalContext* globalCtx) {
// Scene Draw Config 14
void func_8009F5D4(GlobalContext* globalCtx) {
- Gfx* displayListHead;
-
- displayListHead = Graph_Alloc(globalCtx->state.gfxCtx, 3 * sizeof(Gfx));
+ Gfx* displayListHead = Graph_Alloc(globalCtx->state.gfxCtx, 3 * sizeof(Gfx));
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_scene_table.c", 7461);
@@ -2213,13 +2205,10 @@ void func_8009F5D4(GlobalContext* globalCtx) {
// Scene Draw Config 15
void func_8009F7D4(GlobalContext* globalCtx) {
- s8 sp6F;
- s8 sp6E;
+ s8 sp6F = coss((globalCtx->gameplayFrames * 1500) & 0xFFFF) >> 8;
+ s8 sp6E = coss((globalCtx->gameplayFrames * 1500) & 0xFFFF) >> 8;
u32 gameplayFrames;
- sp6F = coss((globalCtx->gameplayFrames * 1500) & 0xFFFF) >> 8;
- sp6E = coss((globalCtx->gameplayFrames * 1500) & 0xFFFF) >> 8;
-
OPEN_DISPS(globalCtx->state.gfxCtx, "../z_scene_table.c", 7512);
gameplayFrames = globalCtx->gameplayFrames;
diff --git a/src/code/z_skelanime.c b/src/code/z_skelanime.c
index 30451a159..a8c3324a5 100644
--- a/src/code/z_skelanime.c
+++ b/src/code/z_skelanime.c
@@ -189,9 +189,7 @@ void SkelAnime_DrawFlexLod(GlobalContext* globalCtx, void** skeleton, Vec3s* joi
Gfx* limbDList;
Vec3f pos;
Vec3s rot;
- Mtx* mtx;
-
- mtx = Graph_Alloc(globalCtx->state.gfxCtx, dListCount * sizeof(Mtx));
+ Mtx* mtx = Graph_Alloc(globalCtx->state.gfxCtx, dListCount * sizeof(Mtx));
if (skeleton == NULL) {
osSyncPrintf(VT_FGCOL(RED));
@@ -410,9 +408,7 @@ void SkelAnime_DrawFlexOpa(GlobalContext* globalCtx, void** skeleton, Vec3s* joi
Gfx* limbDList;
Vec3f pos;
Vec3s rot;
- Mtx* mtx;
-
- mtx = Graph_Alloc(globalCtx->state.gfxCtx, dListCount * sizeof(Mtx));
+ Mtx* mtx = Graph_Alloc(globalCtx->state.gfxCtx, dListCount * sizeof(Mtx));
if (skeleton == NULL) {
osSyncPrintf(VT_FGCOL(RED));
@@ -676,9 +672,8 @@ Gfx* SkelAnime_DrawFlex(GlobalContext* globalCtx, void** skeleton, Vec3s* jointT
Gfx* limbDList;
Vec3f pos;
Vec3s rot;
- Mtx* mtx;
+ Mtx* mtx = Graph_Alloc(globalCtx->state.gfxCtx, dListCount * sizeof(*mtx));
- mtx = Graph_Alloc(globalCtx->state.gfxCtx, dListCount * sizeof(*mtx));
if (skeleton == NULL) {
osSyncPrintf(VT_FGCOL(RED));
// skel is NULL. Returns NULL.
@@ -871,6 +866,7 @@ AnimationEntry* AnimationContext_AddEntry(AnimationContext* animationCtx, Animat
if (index >= ANIMATION_ENTRY_MAX) {
return NULL;
}
+
animationCtx->animationCount = index + 1;
entry = &animationCtx->entries[index];
entry->type = type;
diff --git a/src/code/z_skin_matrix.c b/src/code/z_skin_matrix.c
index 28ddca1a4..646a26c70 100644
--- a/src/code/z_skin_matrix.c
+++ b/src/code/z_skin_matrix.c
@@ -29,15 +29,11 @@ void SkinMatrix_Vec3fMtxFMultXYZW(MtxF* mf, Vec3f* src, Vec3f* xyzDest, f32* wDe
* \f[ [\texttt{dest}, -] = [\texttt{src}, 1] \cdot [mf] \f]
*/
void SkinMatrix_Vec3fMtxFMultXYZ(MtxF* mf, Vec3f* src, Vec3f* dest) {
- f32 mx;
- f32 my;
- f32 mz;
- f32 mw;
-
- mx = mf->xx;
- my = mf->yx;
- mz = mf->zx;
- mw = mf->wx;
+ f32 mx = mf->xx;
+ f32 my = mf->yx;
+ f32 mz = mf->zx;
+ f32 mw = mf->wx;
+
dest->x = mw + ((src->x * mx) + (src->y * my) + (src->z * mz));
mx = mf->xy;
my = mf->yy;
@@ -60,18 +56,13 @@ void SkinMatrix_MtxFMtxFMult(MtxF* mfB, MtxF* mfA, MtxF* dest) {
f32 ry;
f32 rz;
f32 rw;
-
- f32 cx;
- f32 cy;
- f32 cz;
- f32 cw;
-
//---COL1---
- cx = mfB->xx;
- cy = mfB->yx;
- cz = mfB->zx;
- cw = mfB->wx;
+ f32 cx = mfB->xx;
+ f32 cy = mfB->yx;
+ f32 cz = mfB->zx;
+ f32 cw = mfB->wx;
//--------
+
rx = mfA->xx;
ry = mfA->xy;
rz = mfA->xz;
@@ -322,16 +313,14 @@ void SkinMatrix_SetScale(MtxF* mf, f32 x, f32 y, f32 z) {
*/
void SkinMatrix_SetRotateRPY(MtxF* mf, s16 roll, s16 pitch, s16 yaw) {
f32 cos2;
- f32 sin;
- f32 cos;
+ f32 sin = Math_SinS(yaw);
+ f32 cos = Math_CosS(yaw);
f32 yx;
f32 sin2;
f32 zx;
f32 yy;
f32 zy;
- sin = Math_SinS(yaw);
- cos = Math_CosS(yaw);
mf->yy = cos;
mf->yx = -sin;
mf->xw = mf->yw = mf->zw = 0;
diff --git a/src/code/z_ss_sram.c b/src/code/z_ss_sram.c
index 6f929678c..307f56441 100644
--- a/src/code/z_ss_sram.c
+++ b/src/code/z_ss_sram.c
@@ -11,7 +11,7 @@ SsSramContext sSsSramContext = { 0 };
void SsSram_Init(u32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration,
u8 handlePulse, u32 handleSpeed) {
- u32 intDisabled;
+ u32 prevInt;
OSPiHandle* handle = &sSsSramContext.piHandle;
if ((u32)OS_PHYSICAL_TO_K1(addr) != (*handle).baseAddress) {
@@ -24,10 +24,10 @@ void SsSram_Init(u32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8
sSsSramContext.piHandle.domain = handleDomain;
sSsSramContext.piHandle.speed = handleSpeed;
bzero(&sSsSramContext.piHandle.transferInfo, sizeof(__OSTranxInfo));
- intDisabled = __osDisableInt();
+ prevInt = __osDisableInt();
sSsSramContext.piHandle.next = __osPiTable;
__osPiTable = &sSsSramContext.piHandle;
- __osRestoreInt(intDisabled);
+ __osRestoreInt(prevInt);
sSsSramContext.ioMesg.hdr.pri = 0;
sSsSramContext.ioMesg.hdr.retQueue = &sSsSramContext.mesgQ;
sSsSramContext.ioMesg.devAddr = addr;
diff --git a/src/code/z_view.c b/src/code/z_view.c
index 3374eeb5e..974191ac2 100644
--- a/src/code/z_view.c
+++ b/src/code/z_view.c
@@ -52,7 +52,7 @@ void View_Init(View* view, GraphicsContext* gfxCtx) {
view->eye.z = -1.0f;
if (D_8012ABF0) {
- if (&D_8012ABF0) {}
+ if (D_8012ABF0 == 0) {}
osSyncPrintf("\nview: initialize ---\n");
D_8012ABF0 = false;
}
@@ -132,9 +132,7 @@ void func_800AA550(View* view) {
s32 uly;
s32 lrx;
s32 lry;
- GraphicsContext* gfxCtx;
-
- gfxCtx = view->gfxCtx;
+ GraphicsContext* gfxCtx = view->gfxCtx;
varY = ShrinkWindow_GetCurrentVal();
@@ -276,9 +274,7 @@ s32 func_800AAA9C(View* view) {
Vp* vp;
Mtx* projection;
Mtx* viewing;
- GraphicsContext* gfxCtx;
-
- gfxCtx = view->gfxCtx;
+ GraphicsContext* gfxCtx = view->gfxCtx;
OPEN_DISPS(gfxCtx, "../z_view.c", 596);
@@ -377,9 +373,7 @@ s32 func_800AAA9C(View* view) {
s32 func_800AB0A8(View* view) {
Vp* vp;
Mtx* projection;
- GraphicsContext* gfxCtx;
-
- gfxCtx = view->gfxCtx;
+ GraphicsContext* gfxCtx = view->gfxCtx;
OPEN_DISPS(gfxCtx, "../z_view.c", 726);
@@ -456,9 +450,7 @@ s32 func_800AB560(View* view) {
Vp* vp;
Mtx* projection;
Mtx* viewing;
- GraphicsContext* gfxCtx;
-
- gfxCtx = view->gfxCtx;
+ GraphicsContext* gfxCtx = view->gfxCtx;
OPEN_DISPS(gfxCtx, "../z_view.c", 816);
diff --git a/src/code/z_vismono.c b/src/code/z_vismono.c
index be0600ba1..0fb617702 100644
--- a/src/code/z_vismono.c
+++ b/src/code/z_vismono.c
@@ -27,6 +27,7 @@ void VisMono_Destroy(VisMono* this) {
void VisMono_UpdateTexture(VisMono* this, u16* tex) {
s32 i;
+
for (i = 0; i < 256; i++) {
tex[i] = ((((i >> 3 & 0x1F) * 2 + (i << 2 & 0x1F) * 4) * 0xFF / 0xD9) << 8) |
(((i >> 6 & 0x1F) * 4 + (i >> 1 & 0x1F)) * 0xFF / 0xD9);
@@ -36,9 +37,7 @@ void VisMono_UpdateTexture(VisMono* this, u16* tex) {
Gfx* VisMono_DrawTexture(VisMono* this, Gfx* gfx) {
s32 y;
s32 height = 3;
- u16* tex;
-
- tex = D_0F000000;
+ u16* tex = D_0F000000;
gDPPipeSync(gfx++);
gDPSetOtherMode(gfx++,
@@ -55,11 +54,11 @@ Gfx* VisMono_DrawTexture(VisMono* this, Gfx* gfx) {
gDPSetTile(gfx++, G_IM_FMT_CI, G_IM_SIZ_8b, 80, 0x0, G_TX_RENDERTILE, 0, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0,
G_TX_NOMIRROR | G_TX_CLAMP, 0, 0);
- gDPSetTileSize(gfx++, G_TX_RENDERTILE, (2 << 2), 0, (SCREEN_WIDTH * 2 + 1 << 2), (2 << 2));
+ gDPSetTileSize(gfx++, G_TX_RENDERTILE, (2 << 2), 0, ((SCREEN_WIDTH * 2 + 1) << 2), (2 << 2));
gDPSetTile(gfx++, G_IM_FMT_CI, G_IM_SIZ_8b, 80, 0x0, 1, 1, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0,
G_TX_NOMIRROR | G_TX_CLAMP, 0, 0);
- gDPSetTileSize(gfx++, 1, (1 << 2), 0, (SCREEN_WIDTH * 2 << 2), (2 << 2));
+ gDPSetTileSize(gfx++, 1, (1 << 2), 0, ((SCREEN_WIDTH * 2) << 2), (2 << 2));
gSPTextureRectangle(gfx++, 0, (y) << 2, (SCREEN_WIDTH << 2), (y + height) << 2, G_TX_RENDERTILE, 2 << 5, 0,
(2 << 10), (1 << 10));
@@ -72,13 +71,11 @@ Gfx* VisMono_DrawTexture(VisMono* this, Gfx* gfx) {
}
void VisMono_Draw(VisMono* this, Gfx** gfxp) {
- Gfx* gfx;
+ Gfx* gfx = *gfxp;
u16* tlut;
Gfx* monoDL;
Gfx* glistpEnd;
- gfx = *gfxp;
-
if (this->tlut) {
tlut = this->tlut;
} else {