From 76eb52ab5277ad69cd0908f8492483ef5881ee75 Mon Sep 17 00:00:00 2001 From: Roman971 Date: Wed, 18 Mar 2020 01:09:21 +0100 Subject: Various fixes/matches - Matched all remaining functions in `__osMalloc.c`, 2 functions in `code_8007BF90.c`, 1 in `code_800A9F30.c`, 2 in `fault.c`, 1 in `fault_drawer.c`, 1 in `gfxprint.c`, 2 in `z_camera.c` - Improved most other remaining non matchings to ensure they are actually equivalent and to get them closer to matching - Added a `alloc.h` header file in the process of working on `fault.c` non matchings - Decompiled `padmgr.c` data/bss in order to improve padmgr non matchings - Removed unused `z_en_wallmas.c` data files - Moved functions confirmed to be in `z_cheap_proc.c` to their own file with that name --- src/code/__osMalloc.c | 195 ++++++++++++++--------------------- src/code/code_8007BF90.c | 71 +++++++------ src/code/code_800A9F30.c | 14 +-- src/code/fault.c | 208 +++++++++++++++++++++----------------- src/code/fault_drawer.c | 111 ++++++++++---------- src/code/gfxprint.c | 258 ++++++++++++++++++++++++++--------------------- src/code/padmgr.c | 82 ++++++++------- src/code/z_actor.c | 32 +----- src/code/z_camera.c | 79 +++++++-------- src/code/z_cheap_proc.c | 30 ++++++ 10 files changed, 539 insertions(+), 541 deletions(-) create mode 100644 src/code/z_cheap_proc.c (limited to 'src/code') diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c index 0d8fec179..34d602f0a 100644 --- a/src/code/__osMalloc.c +++ b/src/code/__osMalloc.c @@ -228,8 +228,6 @@ void __osMalloc_FreeBlockTest(Arena *arena, ArenaNode *node) } } -//single instruction not matching, stack problem -#ifdef NON_MATCHING void* __osMalloc_NoLockDebug(Arena *arena, u32 size, const char *file, s32 line) { ArenaNode *iter; @@ -237,19 +235,19 @@ void* __osMalloc_NoLockDebug(Arena *arena, u32 size, const char *file, s32 line) ArenaNode *newNode; void *ret; ArenaNode *next; - u32 pad; ret = NULL; iter = arena->head; size = ALIGN16(size); + blockSize = ALIGN16(size) + sizeof(ArenaNode); + while (iter) { if (iter->isFree && iter->size >= size) { - if ((arena->flag & CHECK_FREE_BLOCK) != 0) + if (arena->flag & CHECK_FREE_BLOCK) __osMalloc_FreeBlockTest(arena, iter); - blockSize = ALIGN16(size) + sizeof(ArenaNode); if (blockSize < iter->size) { newNode = (ArenaNode *)((u32)iter + blockSize); @@ -269,7 +267,7 @@ 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)); - if ((arena->flag & FILL_ALLOCBLOCK) != 0) + if (arena->flag & FILL_ALLOCBLOCK) func_80106860(ret, BLOCK_ALLOC_MAGIC, size); break; @@ -280,9 +278,6 @@ void* __osMalloc_NoLockDebug(Arena *arena, u32 size, const char *file, s32 line) return ret; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/__osMalloc_NoLockDebug.s") -#endif void* __osMallocDebug(Arena* arena, u32 size, const char* file, s32 line) { @@ -293,13 +288,11 @@ void* __osMallocDebug(Arena* arena, u32 size, const char* file, s32 line) return ret; } -//stack + missing a move -#ifdef NON_MATCHING void* __osMallocRDebug(Arena *arena, u32 size, const char *file, s32 line) { ArenaNode *iter; - u32 blockSize; ArenaNode *newNode; + u32 blockSize; ArenaNode *next; void *ret; @@ -311,7 +304,7 @@ void* __osMallocRDebug(Arena *arena, u32 size, const char *file, s32 line) { if (iter->isFree && iter->size >= size) { - if ((arena->flag & CHECK_FREE_BLOCK) != 0) + if (arena->flag & CHECK_FREE_BLOCK) __osMalloc_FreeBlockTest(arena, iter); blockSize = ALIGN16(size) + sizeof(ArenaNode); @@ -328,12 +321,14 @@ void* __osMallocRDebug(Arena *arena, u32 size, const char *file, s32 line) next = ArenaImpl_GetNextBlock(newNode); if (next) next->prev = newNode; + + iter = newNode; } iter->isFree = false; ArenaImpl_SetDebugInfo(iter, file, line, arena); ret = (void *)((u32)iter + sizeof(ArenaNode)); - if ((arena->flag & FILL_ALLOCBLOCK) != 0) + if (arena->flag & FILL_ALLOCBLOCK) func_80106860(ret, BLOCK_ALLOC_MAGIC, size); break; @@ -345,13 +340,7 @@ void* __osMallocRDebug(Arena *arena, u32 size, const char *file, s32 line) ArenaImpl_Unlock(arena); return ret; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/__osMallocRDebug.s") -#endif - -//same diff as __osMalloc_NoLockDebug -#ifdef NON_MATCHING void* __osMalloc_NoLock(Arena *arena, u32 size) { ArenaNode *iter; @@ -359,19 +348,20 @@ void* __osMalloc_NoLock(Arena *arena, u32 size) ArenaNode *newNode; void *ret; ArenaNode *next; - u32 pad; ret = NULL; iter = arena->head; size = ALIGN16(size); + blockSize = ALIGN16(size) + sizeof(ArenaNode); + while (iter) { + if (iter->isFree && iter->size >= size) { - if ((arena->flag & CHECK_FREE_BLOCK) != 0) + if (arena->flag & CHECK_FREE_BLOCK) __osMalloc_FreeBlockTest(arena, iter); - blockSize = ALIGN16(size) + sizeof(ArenaNode); if (blockSize < iter->size) { newNode = (ArenaNode *)((u32)iter + blockSize); @@ -391,7 +381,7 @@ void* __osMalloc_NoLock(Arena *arena, u32 size) iter->isFree = false; ArenaImpl_SetDebugInfo(iter, NULL, 0, arena); ret = (void *)((u32)iter + sizeof(ArenaNode)); - if ((arena->flag & FILL_ALLOCBLOCK) != 0) + if (arena->flag & FILL_ALLOCBLOCK) func_80106860(ret, BLOCK_ALLOC_MAGIC, size); break; @@ -402,9 +392,6 @@ void* __osMalloc_NoLock(Arena *arena, u32 size) return ret; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/__osMalloc_NoLock.s") -#endif void* __osMalloc(Arena* arena, u32 size) { @@ -415,13 +402,11 @@ void* __osMalloc(Arena* arena, u32 size) return ret; } -//same diff as __osMallocRDebug -#ifdef NON_MATCHING void* __osMallocR(Arena *arena, u32 size) { ArenaNode *iter; - u32 blockSize; ArenaNode *newNode; + u32 blockSize; ArenaNode *next; void *ret; @@ -433,7 +418,7 @@ void* __osMallocR(Arena *arena, u32 size) { if (iter->isFree && iter->size >= size) { - if ((arena->flag & CHECK_FREE_BLOCK) != 0) + if (arena->flag & CHECK_FREE_BLOCK) __osMalloc_FreeBlockTest(arena, iter); blockSize = ALIGN16(size) + sizeof(ArenaNode); @@ -450,12 +435,14 @@ void* __osMallocR(Arena *arena, u32 size) next = ArenaImpl_GetNextBlock(newNode); if (next) next->prev = newNode; + + iter = newNode; } iter->isFree = false; ArenaImpl_SetDebugInfo(iter, NULL, 0, arena); ret = (void *)((u32)iter + sizeof(ArenaNode)); - if ((arena->flag & FILL_ALLOCBLOCK) != 0) + if (arena->flag & FILL_ALLOCBLOCK) func_80106860(ret, BLOCK_ALLOC_MAGIC, size); break; @@ -467,13 +454,7 @@ void* __osMallocR(Arena *arena, u32 size) ArenaImpl_Unlock(arena); return ret; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/__osMallocR.s") -#endif - -//small reordering -#ifdef NON_MATCHING void __osFree_NoLock(Arena* arena, void* ptr) { ArenaNode* node; @@ -486,12 +467,12 @@ void __osFree_NoLock(Arena* arena, void* ptr) node = (ArenaNode*)((u32)ptr - sizeof(ArenaNode)); if (node == NULL || node->magic != NODE_MAGIC) { - osSyncPrintf(VT_COL(RED, WHITE) "__osFree:不正解放(%08x)\n" VT_RST, arena); //__osFree: Unauthorized release (%08x) + 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, arena); //__osFree: Double release (%08x) + osSyncPrintf(VT_COL(RED, WHITE) "__osFree:二重解放(%08x)\n" VT_RST, ptr); //__osFree: Double release (%08x) return; } if (arena != node->arena && arena != NULL) @@ -505,12 +486,12 @@ void __osFree_NoLock(Arena* arena, void* ptr) prev = ArenaImpl_GetPrevBlock(node); node->isFree = true; ArenaImpl_SetDebugInfo(node, NULL, 0, arena); - if ((arena->flag & FILL_FREEBLOCK) != 0) + if (arena->flag & FILL_FREEBLOCK) { func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size); } - newNext = node->next; + newNext = next; if ((u32)next == (u32)node + sizeof(ArenaNode) + node->size && next->isFree) { newNext = ArenaImpl_GetNextBlock(next); @@ -518,26 +499,23 @@ void __osFree_NoLock(Arena* arena, void* ptr) newNext->prev = node; node->size += next->size + sizeof(ArenaNode); - if ((arena->flag & FILL_FREEBLOCK) != 0) + if (arena->flag & FILL_FREEBLOCK) func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); node->next = newNext; + next = newNext; } + if (prev && prev->isFree && (u32)node == (u32)prev + sizeof(ArenaNode) + prev->size) { - if (newNext) - newNext->prev = prev; - prev->next = newNext; + if (next) + next->prev = prev; + prev->next = next; prev->size += node->size + sizeof(ArenaNode); - if ((arena->flag & FILL_FREEBLOCK) != 0) + if (arena->flag & FILL_FREEBLOCK) func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); } - } - } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/__osFree_NoLock.s") -#endif void __osFree(Arena* arena, void* ptr) { @@ -546,8 +524,6 @@ void __osFree(Arena* arena, void* ptr) ArenaImpl_Unlock(arena); } -//small reordering -#ifdef NON_MATCHING void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) { ArenaNode* node; @@ -560,12 +536,12 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) 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, arena, file, line); //__osFree: Unauthorized release (%08x) + 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)\n" VT_RST, arena); //__osFree: Double release (%08x) + 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) @@ -579,7 +555,7 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) prev = ArenaImpl_GetPrevBlock(node); node->isFree = true; ArenaImpl_SetDebugInfo(node, file, line, arena); - if ((arena->flag & FILL_FREEBLOCK) != 0) + if (arena->flag & FILL_FREEBLOCK) { func_80106860((u32)node + sizeof(ArenaNode), BLOCK_FREE_MAGIC, node->size); } @@ -592,26 +568,23 @@ void __osFree_NoLockDebug(Arena* arena, void* ptr, const char* file, s32 line) newNext->prev = node; node->size += next->size + sizeof(ArenaNode); - if ((arena->flag & FILL_FREEBLOCK) != 0) + if (arena->flag & FILL_FREEBLOCK) func_80106860(next, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); node->next = newNext; + next = newNext; } + if (prev && prev->isFree && (u32)node == (u32)prev + sizeof(ArenaNode) + prev->size) { - if (newNext) - newNext->prev = prev; - prev->next = newNext; + if (next) + next->prev = prev; + prev->next = next; prev->size += node->size + sizeof(ArenaNode); - if ((arena->flag & FILL_FREEBLOCK) != 0) + if (arena->flag & FILL_FREEBLOCK) func_80106860(node, BLOCK_FREE_MAGIC, sizeof(ArenaNode)); } - } - } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/__osFree_NoLockDebug.s") -#endif void __osFreeDebug(Arena* arena, void* ptr, const char* file, s32 line) { @@ -620,33 +593,27 @@ void __osFreeDebug(Arena* arena, void* ptr, const char* file, s32 line) ArenaImpl_Unlock(arena); } -//small reordering, stack usage -#ifdef NON_MATCHING void* __osRealloc(Arena* arena, void* ptr, u32 newSize) { + void* newAlloc; ArenaNode* node; ArenaNode* next; - u32 sizeDiff; - ArenaNode* overNext; ArenaNode* newNext; - void* newAlloc; - //----------- - ArenaNode* next2; - ArenaNode unk; + ArenaNode* overNext; ArenaNode* newNext2; + ArenaNode* next2; + u32 sizeDiff; ArenaNode* overNext2; - //---------- - u32 newSize2; - ArenaNode* newNext3; - ArenaNode* overNext3; - + ArenaNode localCopy; + u32 blockSize; + s32 pad; newSize = ALIGN16(newSize); osSyncPrintf("__osRealloc(%08x, %d)\n", ptr, newSize); ArenaImpl_Lock(arena); if (!ptr) { - ptr = __osMalloc(arena, newSize); + ptr = __osMalloc_NoLock(arena, newSize); } else if (!newSize) { @@ -694,13 +661,14 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) else if (newSize < node->size) { next2 = ArenaImpl_GetNextBlock(node); - if (next && next->isFree) + if (next2 && next2->isFree) { + blockSize = ALIGN16(newSize) + sizeof(ArenaNode); //Increased free block behind current memory block osSyncPrintf("現メモリブロックの後ろのフリーブロックを大きくしました\n"); - unk = *next2; - newNext2 = (u32)node + ALIGN16(newSize) + sizeof(ArenaNode); - *newNext2 = unk; + newNext2 = (ArenaNode*)((u32)node + blockSize); + localCopy = *next2; + *newNext2 = localCopy; newNext2->size += node->size - newSize; node->next = newNext2; node->size = newSize; @@ -710,20 +678,20 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) } else if (newSize + sizeof(ArenaNode) < node->size) { + blockSize = ALIGN16(newSize) + sizeof(ArenaNode); //Generated because there is no free block after the current memory block osSyncPrintf("現メモリブロックの後ろにフリーブロックがないので生成します\n"); - newSize2 = ALIGN16(newSize) + sizeof(ArenaNode); - newNext3 = (ArenaNode*)((u32)node + newSize2); - newNext3->next = ArenaImpl_GetNextBlock(node); - newNext3->prev = node; - newNext3->size = node->size - newSize2; - newNext3->isFree = true; - newNext3->magic = NODE_MAGIC; - node->next = newNext3; + newNext2 = (ArenaNode*)((u32)node + blockSize); + newNext2->next = ArenaImpl_GetNextBlock(node); + newNext2->prev = node; + newNext2->size = node->size - blockSize; + newNext2->isFree = true; + newNext2->magic = NODE_MAGIC; + node->next = newNext2; node->size = newSize; - overNext3 = ArenaImpl_GetNextBlock(newNext3); - if (overNext3) - overNext3->prev = newNext3; + overNext2 = ArenaImpl_GetNextBlock(newNext2); + if (overNext2) + overNext2->prev = newNext2; } else { @@ -732,14 +700,11 @@ void* __osRealloc(Arena* arena, void* ptr, u32 newSize) ptr = NULL; } } - } + ArenaImpl_Unlock(arena); return ptr; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/__osRealloc.s") -#endif void* __osReallocDebug(Arena* arena, void* ptr, u32 newSize, const char* file, s32 line) { @@ -757,7 +722,7 @@ void ArenaImpl_GetSizes(Arena* arena, u32* outMaxFree, u32* outFree, u32* outAll *outAlloc = 0; iter = arena->head; - while(iter) + while (iter) { if (iter->isFree) { @@ -774,8 +739,6 @@ void ArenaImpl_GetSizes(Arena* arena, u32* outMaxFree, u32* outFree, u32* outAll ArenaImpl_Unlock(arena); } -//small reordering at the end -#ifdef NON_MATCHING void __osDisplayArena(Arena* arena) { u32 freeSize; @@ -803,7 +766,7 @@ void __osDisplayArena(Arena* arena) osSyncPrintf("メモリブロック範囲 status サイズ [時刻 s ms us ns: TID:src:行]\n"); iter = arena->head; - while(iter) + while (iter) { if (iter && iter->magic == NODE_MAGIC) { @@ -828,14 +791,14 @@ void __osDisplayArena(Arena* arena) { allocatedSize += iter->size; } - - iter = next; } else { osSyncPrintf("%08x Block Invalid\n", iter); - iter = NULL; + next = NULL; } + + iter = next; } osSyncPrintf("確保ブロックサイズの合計 0x%08x バイト\n", allocatedSize); //Total reserved node size 0x%08x bytes @@ -844,12 +807,7 @@ void __osDisplayArena(Arena* arena) ArenaImpl_Unlock(arena); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/__osDisplayArena.s") -#endif -//small reordering -#ifdef NON_MATCHING void ArenaImpl_FaultClient(Arena* arena) { u32 freeSize; @@ -872,7 +830,7 @@ void ArenaImpl_FaultClient(Arena* arena) FaultDrawer_Printf("Memory Block Region status size\n"); iter = arena->head; - while(iter) + while (iter) { if (iter && iter->magic == NODE_MAGIC) { @@ -894,15 +852,15 @@ void ArenaImpl_FaultClient(Arena* arena) { allocatedSize += iter->size; } - - iter = next; } else { FaultDrawer_SetFontColor(0xF801); FaultDrawer_Printf("%08x Block Invalid\n", iter); - iter = NULL; + next = NULL; } + + iter = next; } FaultDrawer_SetFontColor(0x7F1); @@ -910,9 +868,6 @@ void ArenaImpl_FaultClient(Arena* arena) FaultDrawer_Printf("Total Free Block Size %08x\n", freeSize); FaultDrawer_Printf("Largest Free Block Size %08x\n", maxFree); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/__osMalloc/ArenaImpl_FaultClient.s") -#endif u32 __osCheckArena(Arena* arena) { @@ -924,7 +879,7 @@ u32 __osCheckArena(Arena* arena) //Checking the contents of the arena. . . (%08x) osSyncPrintf("アリーナの内容をチェックしています... (%08x)\n", arena); iter = arena->head; - while(iter) + while (iter) { if (iter && iter->magic == NODE_MAGIC) { diff --git a/src/code/code_8007BF90.c b/src/code/code_8007BF90.c index 8c5347971..a7e1cca5b 100644 --- a/src/code/code_8007BF90.c +++ b/src/code/code_8007BF90.c @@ -1,7 +1,7 @@ #include #include -void func_8007C1AC(Vec3f* dest, struct_80045714* arg1); +Vec3f* func_8007C1AC(Vec3f* dest, struct_80045714* arg1); f32 func_8007BF90(Vec3f* a, Vec3f* b) { @@ -33,49 +33,48 @@ f32 func_8007C058(f32 arg0, f32 arg1) #pragma GLOBAL_ASM("asm/non_matchings/code/code_8007BF90/func_8007C0A8.s") -#ifdef NON_MATCHING -void func_8007C0F8(Vec3f* dest, Vec3f* a, Vec3f* b) +Vec3f* func_8007C0F8(Vec3f* dest, Vec3f* a, Vec3f* b) { - f32 fVar1; - Vec3f v; + Vec3f v1; + Vec3f v2; + f32 temp; + + v1.x = b->x - a->x; + v1.y = b->y - a->y; + v1.z = b->z - a->z; + + temp = func_8007C058(sqrtf(SQ(v1.x) + SQ(v1.y) + SQ(v1.z)), 0.01f); - v.x = b->x - a->x; - v.y = b->y - a->y; - v.z = b->z - a->z; + v2.x = v1.x / temp; + v2.y = v1.y / temp; + v2.z = v1.z / temp; - fVar1 = func_8007C058(sqrtf(v.x * v.x + v.y * v.y + v.z * v.z), D_8013CB80); + *dest = v2; - dest->x = v.x / fVar1; - dest->y = v.y / fVar1; - dest->z = v.z / fVar1; + return dest; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/code_8007BF90/func_8007C0F8.s") -#endif -#ifdef NON_MATCHING -void func_8007C1AC(Vec3f* dest, struct_80045714* arg1) +Vec3f* func_8007C1AC(Vec3f* dest, struct_80045714* arg1) { - f32 fVar1; - f32 fVar2; - f32 fVar3; - f32 fVar4; - f32 fVar5; - f32 fVar6; - - fVar1 = Math_Coss(arg1->unk_04); - fVar2 = Math_Coss(arg1->unk_06); - fVar3 = Math_Coss(arg1->unk_04); - fVar4 = Math_Coss(arg1->unk_06); - fVar6 = arg1->unk_00; - fVar5 = arg1->unk_00; - dest->x = arg1->unk_00 * fVar3 * fVar4; - dest->y = fVar6 * fVar1; - dest->z = fVar5 * fVar3 * fVar2; + Vec3f v; + f32 sin4; + f32 cos4; + f32 sin6; + f32 cos6; + + cos4 = Math_Coss(arg1->unk_04); + cos6 = Math_Coss(arg1->unk_06); + sin4 = Math_Sins(arg1->unk_04); + sin6 = Math_Sins(arg1->unk_06); + + v.x = arg1->unk_00 * sin4 * sin6; + v.y = arg1->unk_00 * cos4; + v.z = arg1->unk_00 * sin4 * cos6; + + *dest = v; + + return dest; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/code_8007BF90/func_8007C1AC.s") -#endif void func_8007C3F4(struct_80045714* arg0, Vec3f* arg1); diff --git a/src/code/code_800A9F30.c b/src/code/code_800A9F30.c index c5248faca..ad603fabe 100644 --- a/src/code/code_800A9F30.c +++ b/src/code/code_800A9F30.c @@ -45,22 +45,18 @@ void func_800AA0B4(void) if (0) ; // Necessary to match } -#ifdef NON_MATCHING void func_800AA0F0(void) { - if ((gPadMgr.unk_460 == func_800A9F30) && (gPadMgr.unk_464 == 0)) + PadMgr* padmgr = &gPadMgr; + + if ((padmgr->unk_460 == func_800A9F30) && (padmgr->unk_464 == 0)) { - // asm loads/writes directly to 0x80166D20 and 0x80166D24 - // but the compiler wants to reuse offsets from 0x801668C0 - gPadMgr.unk_460 = NULL; - gPadMgr.unk_464 = 0; + padmgr->unk_460 = NULL; + padmgr->unk_464 = 0; } func_800D3178(&D_80160FD0); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800A9F30/func_800AA0F0.s") -#endif u32 func_800AA148(void) { diff --git a/src/code/fault.c b/src/code/fault.c index 528d8beaf..4af2d6c60 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -1,5 +1,6 @@ #include #include +#include #include //data @@ -55,40 +56,42 @@ void Fault_ClientProcessThread(FaultClientContext* ctx) osSendMesg(ctx->queue, ctx->msg, 1); } -#ifdef NON_MATCHING void Fault_ProcessClientContext(FaultClientContext* ctx) { OSMesgQueue queue; OSMesg msg; - OSThread* t; - OSTimer timer; OSMesg recMsg; + OSThread* thread; + OSTimer timer; + u32 timerMsgVal; + + timerMsgVal = 666; + thread = NULL; osCreateMesgQueue(&queue, &msg, 1); ctx->queue = &queue; ctx->msg = NULL; - if (sFaultStructPtr->currClientThreadSp) + + if (sFaultStructPtr->currClientThreadSp != 0) { - Fault_ClientProcessThread(ctx); - t = NULL; + thread = alloca(sizeof(OSThread)); + osCreateThread(thread, 2, Fault_ClientProcessThread, ctx, sFaultStructPtr->currClientThreadSp, 0x7E); + osStartThread(thread); } else { - OSThread thread; - osCreateThread(&thread, 2, &Fault_ClientProcessThread, ctx, sFaultStructPtr->currClientThreadSp, 0x7E); - osStartThread(&thread); - t = &thread; + Fault_ClientProcessThread(ctx); } - while(true) + while (true) { - osSetTimer(&timer, OS_USEC_TO_CYCLES(1000000), 0, &queue, (OSMesg)0x29A); + osSetTimer(&timer, OS_USEC_TO_CYCLES(1000000), 0, &queue, (OSMesg)timerMsgVal); osRecvMesg(&queue, &recMsg, 1); - if (recMsg == (OSMesg)0x29A) + if (recMsg != (OSMesg)666) break; - if (sFaultIsWaitingForInput) + if (!sFaultIsWaitingForInput) { ctx->ret = -1; break; @@ -96,17 +99,13 @@ void Fault_ProcessClientContext(FaultClientContext* ctx) } osStopTimer(&timer); - if (t) + + if (thread != NULL) { - osStopThread(t); - //osDestroyThread(t); - osDestroyThread(t); + osStopThread(thread); + osDestroyThread(thread); } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/fault/Fault_ProcessClientContext.s") -#endif - u32 Fault_ProcessClient(u32 callback, u32 param0, u32 param1) { @@ -120,16 +119,22 @@ u32 Fault_ProcessClient(u32 callback, u32 param0, u32 param1) } #ifdef NON_MATCHING -void Fault_AddClient(FaultClient *client, void* callback, void* param0, void* param1) +// minor ordering differences +void Fault_AddClient(FaultClient* client, void* callback, void* param0, void* param1) { - bool alreadyExist = false; - OSIntMask mask = osSetIntMask(1); - FaultClient* iter = sFaultStructPtr->clients; + OSIntMask mask; + u32 alreadyExists; + FaultClient* iter; + + alreadyExists = false; + mask = osSetIntMask(1); + + iter = sFaultStructPtr->clients; while (iter) { if (iter == client) { - alreadyExist = true; + alreadyExists = true; goto end; } iter = iter->next; @@ -143,7 +148,7 @@ void Fault_AddClient(FaultClient *client, void* callback, void* param0, void* pa end: osSetIntMask(mask); - if (alreadyExist) + if (alreadyExists) osSyncPrintf(VT_COL(RED, WHITE) "fault_AddClient: %08x は既にリスト中にある\n" VT_RST, client); } #else @@ -187,7 +192,6 @@ void Fault_RemoveClient(FaultClient* client) { osSyncPrintf(VT_COL(RED, WHITE) "fault_RemoveClient: %08x リスト不整合です\n" VT_RST, client); } - #pragma GLOBAL_ASM("asm/non_matchings/code/fault/Fault_AddAddrConvClient.s") void Fault_RemoveAddrConvClient(FaultAddrConvClient* client) { @@ -266,20 +270,23 @@ void Fault_UpdatePadImpl() } #ifdef NON_MATCHING -bool Fault_WaitForInputImpl() +// ordering differences and possibly regalloc +u32 Fault_WaitForInputImpl() { u16 kDown; - bool exitDebugger; - + u32 exitDebugger; s32 count = 600; Input* curInput = &sFaultStructPtr->padInput; + while (true) { while (true) { Fault_Sleep(0x10); Fault_UpdatePadImpl(); + kDown = curInput->padPressed; + if (kDown == 0x20) sFaultStructPtr->faultActive = !sFaultStructPtr->faultActive; @@ -291,14 +298,18 @@ bool Fault_WaitForInputImpl() } if (kDown == 0x8000 || kDown == 0x100) - break; + return false; + if (kDown == 0x200) return true; + if (kDown == 0x800) FaultDrawer_SetOsSyncPrintfEnabled(true); + if (kDown == 0x400) FaultDrawer_SetOsSyncPrintfEnabled(false); } + return false; } #else @@ -338,10 +349,10 @@ void Fault_DrawCornerRec(u16 color) Fault_DrawRec(0x16, 0x10, 8, 1, color); } -void Fault_PrintFReg(s32 idx, f32 *value) +void Fault_PrintFReg(s32 idx, f32* value) { u32 raw = *(u32*)value; - int v0 = ((raw & 0x7f800000) >> 0x17) - 0x7f; + s32 v0 = ((raw & 0x7f800000) >> 0x17) - 0x7f; if ((v0 >= -0x7e && v0 < 0x80) || raw == 0) FaultDrawer_Printf("F%02d:%14.7e ", idx, *value); @@ -349,8 +360,7 @@ void Fault_PrintFReg(s32 idx, f32 *value) FaultDrawer_Printf("F%02d: %08x(16) ", idx, raw); } -#ifdef NON_MATCHING -void Fault_LogFReg(s32 idx, f32 *value) +void Fault_LogFReg(s32 idx, f32* value) { u32 raw = *(u32*)value; s32 v0 = ((raw & 0x7f800000) >> 0x17) - 0x7f; @@ -358,11 +368,8 @@ void Fault_LogFReg(s32 idx, f32 *value) if ((v0 >= -0x7e && v0 < 0x80) || raw == 0) osSyncPrintf("F%02d:%14.7e ", idx, *value); else - osSyncPrintf("F%02d: %08x(16) ", idx, raw); + osSyncPrintf("F%02d: %08x(16) ", idx, *(u32*)value); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/fault/Fault_LogFReg.s") -#endif void Fault_PrintFPCR(u32 value) { @@ -567,14 +574,16 @@ void Fault_DrawMemDumpPage(const char* title, u32* addr, u32 param_3) { FaultDrawer_SetCharPad(0, 0); } - #ifdef NON_MATCHING +// saved register and stack usage differences +// possibly some minor ordering and regalloc differences void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { + Input* curInput = &sFaultStructPtr->padInput; + u32 addr = pc; s32 count; - u16 held; s32 off; - u32 addr = pc; + while (true) { if (addr < 0x80000000) @@ -583,49 +592,54 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) addr = 0x807fff00; addr &= ~0xF; - Fault_DrawMemDumpPage("Dump", (u32*)addr); + Fault_DrawMemDumpPage("Dump", (u32*)addr, 0); count = 600; + while (sFaultStructPtr->faultActive) { - if (count-- == 0) + if (count == 0) return; + + count--; Fault_Sleep(0x10); Fault_UpdatePadImpl(); - if ((sFaultStructPtr->padInput.padPressed | ~0x20) == ~0x20) + if (!~(curInput->padPressed | ~0x20)) sFaultStructPtr->faultActive = false; } + do { Fault_Sleep(0x10); Fault_UpdatePadImpl(); - } while (sFaultStructPtr->padInput.padPressed == 0); + } while (curInput->padPressed == 0); - if ((sFaultStructPtr->padInput.padPressed | ~0x1000) == ~0) + if (!~(curInput->padPressed | ~0x1000)) return; - held = sFaultStructPtr->padInput.status; - if ((held | ~0x8000) == ~0) + + if (!~(curInput->raw.pad | ~0x8000)) return; off = 0x10; - if ((held | ~0x2000) == ~0) + if (!~(curInput->raw.pad | ~0x2000)) off = 0x100; - if ((held | ~0x4000) == ~0) + if (!~(curInput->raw.pad | ~0x4000)) off <<= 8; - if ((held | ~0x800) == ~0) - addr -= off; - if ((held | ~0x400) == ~0) + if (!~(curInput->raw.pad | ~0x800)) addr -= off; - if ((held | ~0x8) == ~0) + if (!~(curInput->raw.pad | ~0x400)) + addr += off; + if (!~(curInput->raw.pad | ~0x8)) addr = pc; - if ((held | ~0x4) == ~0) + if (!~(curInput->raw.pad | ~0x4)) addr = sp; - if ((held | ~0x2) == ~0) + if (!~(curInput->raw.pad | ~0x2)) addr = unk0; - if ((held | ~0x1) == ~0) + if (!~(curInput->raw.pad | ~0x1)) addr = unk1; - if ((held | ~0x20) == ~0) + if (!~(curInput->raw.pad | ~0x20)) break; } + sFaultStructPtr->faultActive = true; } #else @@ -674,6 +688,7 @@ void Fault_ProcessClients(void) { FaultClient* iter = sFaultStructPtr->clients; s32 idx = 0; + while(iter) { if (iter->callback) @@ -696,58 +711,59 @@ void Fault_UpdatePad() } #ifdef NON_MATCHING - -void Fault_ThreadEntry(u32 unused) +// saved register and stack usage differences +void Fault_ThreadEntry(void* arg) { - OSThread *faultedThread; + OSThread* faultedThread; OSMesg msg; - //osSetEventMesg osSetEventMesg(OS_EVENT_CPU_BREAK, &sFaultStructPtr->queue, 1); osSetEventMesg(OS_EVENT_FAULT, &sFaultStructPtr->queue, 2); + while (true) { - osRecvMesg(&sFaultStructPtr->queue, &msg, 1); - - if (msg == (OSMesg)1) - { - sFaultStructPtr->msgId = 1; - osSyncPrintf("フォルトマネージャ:OS_EVENT_CPU_BREAKを受信しました\n"); - } - else if (msg == (OSMesg)2) - { - sFaultStructPtr->msgId = 2; - osSyncPrintf("フォルトマネージャ:OS_EVENT_FAULTを受信しました\n"); - } - else if (msg != (OSMesg)3) + do { - sFaultStructPtr->msgId = (u8)3; - osSyncPrintf("フォルトマネージャ:不明なメッセージを受信しました\n"); - } + osRecvMesg(&sFaultStructPtr->queue, &msg, 1); + + if (msg == (OSMesg)1) + { + sFaultStructPtr->msgId = 1; + osSyncPrintf("フォルトマネージャ:OS_EVENT_CPU_BREAKを受信しました\n"); + } + else if (1 && msg == (OSMesg)2) + { + sFaultStructPtr->msgId = 2; + osSyncPrintf("フォルトマネージャ:OS_EVENT_FAULTを受信しました\n"); + } + else if (msg == (OSMesg)3) + { + Fault_UpdatePad(); + faultedThread = NULL; + continue; + } + else + { + sFaultStructPtr->msgId = 3; + osSyncPrintf("フォルトマネージャ:不明なメッセージを受信しました\n"); + } - if (msg == (OSMesg)3) - { - Fault_UpdatePad(); - faultedThread = NULL; - } - else - { faultedThread = __osGetCurrFaultedThread(); osSyncPrintf("__osGetCurrFaultedThread()=%08x\n", faultedThread); - if (!faultedThread) + + if (faultedThread == NULL) { faultedThread = Fault_FindFaultedThread(); osSyncPrintf("FindFaultedThread()=%08x\n", faultedThread); } - } - - if (!faultedThread) - continue; + } while (faultedThread == NULL); __osSetFpcCsr(__osGetFpcCsr() & -0xf81); sFaultStructPtr->faultedThread = faultedThread; + while (!sFaultStructPtr->faultHandlerEnabled) Fault_Sleep(1000); + Fault_Sleep(500); Fault_CommitFB(); @@ -781,10 +797,12 @@ void Fault_ThreadEntry(u32 unused) FaultDrawer_DrawText(0x40, 0x64, " THANK YOU! "); FaultDrawer_DrawText(0x40, 0x6E, " You are great debugger!"); Fault_WaitForInput(); - } while (!sFaultStructPtr->exitDebugger); - while(!sFaultStructPtr->exitDebugger){} + while (!sFaultStructPtr->exitDebugger) + { + + } Fault_ResumeThread(faultedThread); } diff --git a/src/code/fault_drawer.c b/src/code/fault_drawer.c index 522f0b2ff..392290d8a 100644 --- a/src/code/fault_drawer.c +++ b/src/code/fault_drawer.c @@ -47,7 +47,7 @@ FaultDrawer sFaultDrawerDefault = 22, 297,//xStart, xEnd 0xFFFF, 0x0000, //foreColor, backColor 22, 16, //cursorX, cursorY - &sFaultDrawerFont, //font + sFaultDrawerFont, //font 8, 8, 0, 0, { //printColors 0x0001, 0xF801, 0x07C1, 0xFFC1, @@ -63,7 +63,6 @@ FaultDrawer sFaultDrawerDefault = FaultDrawer sFaultDrawerStruct; char D_8016B6C0[0x20]; //? unused - void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) { sFaultDrawerStruct.osSyncPrintfEnabled = enabled; @@ -75,9 +74,10 @@ void FaultDrawer_DrawRecImpl(s32 xstart, s32 ystart, s32 xend, s32 yend, u16 col if (sFaultDrawerStruct.w - xstart > 0 && sFaultDrawerStruct.h - ystart > 0) { s32 x, y; - for (y = 0; y < yend-ystart+1; y++) - for (x = 0; x < xend-xstart+1; x++) - sFaultDrawerStruct.fb[sFaultDrawerStruct.w*y+x] = color; + + for (y = 0; y <= yend - ystart; y++) + for (x = 0; x <= xend - xstart; x++) + sFaultDrawerStruct.fb[sFaultDrawerStruct.w * y + x] = color; osWritebackDCacheAll(); } @@ -86,35 +86,38 @@ void FaultDrawer_DrawRecImpl(s32 xstart, s32 ystart, s32 xend, s32 yend, u16 col #pragma GLOBAL_ASM("asm/non_matchings/code/fault_drawer/FaultDrawer_DrawRecImpl.s") #endif - #ifdef NON_MATCHING +// regalloc and minor ordering differences void FaultDrawer_DrawChar(char c) { s32 x, y; - u32* dataStart = &sFaultDrawerStruct.fontData[(c >> 3) * 0x10 + (c & 4) >> 2]; - u16* fb = &sFaultDrawerStruct.fb[sFaultDrawerStruct.w * sFaultDrawerStruct.cursorY + sFaultDrawerStruct.cursorX]; - - if (sFaultDrawerStruct.xStart <= sFaultDrawerStruct.cursorX && - sFaultDrawerStruct.charW + sFaultDrawerStruct.cursorX -1 <= sFaultDrawerStruct.xEnd && - sFaultDrawerStruct.yStart <= sFaultDrawerStruct.cursorY && - sFaultDrawerStruct.charH + sFaultDrawerStruct.cursorY -1 <= sFaultDrawerStruct.yEnd && - sFaultDrawerStruct.charH != 0 - ) + u32* dataPtr; + u16* fb; + + dataPtr = &sFaultDrawerStruct.fontData[((c & 4) >> 2) + ((c / 8) * 16)]; + + fb = &sFaultDrawerStruct.fb[sFaultDrawerStruct.cursorY * sFaultDrawerStruct.w]; + fb = &fb[sFaultDrawerStruct.cursorX]; + + if ((sFaultDrawerStruct.xStart <= sFaultDrawerStruct.cursorX) && + ((sFaultDrawerStruct.charW + sFaultDrawerStruct.cursorX - 1) <= sFaultDrawerStruct.xEnd) && + (sFaultDrawerStruct.yStart <= sFaultDrawerStruct.cursorY) && + ((sFaultDrawerStruct.charH + sFaultDrawerStruct.cursorY - 1) <= sFaultDrawerStruct.yEnd)) { for (y = 0; y < sFaultDrawerStruct.charH; y++) { - u32 mask = 0x10000000 << (c & 3); + u32 mask = 0x10000000 << (c % 4); + u32 data = *dataPtr; for (x = 0; x < sFaultDrawerStruct.charW; x++) { - if ((mask & *dataStart)) + if (mask & data) fb[x] = sFaultDrawerStruct.foreColor; - else - if (sFaultDrawerStruct.backColor & 1) - fb[x] = sFaultDrawerStruct.backColor; + else if (sFaultDrawerStruct.backColor & 1) + fb[x] = sFaultDrawerStruct.backColor; mask >>= 4; } fb += sFaultDrawerStruct.w; - dataStart += 2; + dataPtr += 2; } } } @@ -186,58 +189,56 @@ void FaultDrawer_FillScreen() FaultDrawer_SetCursor(sFaultDrawerStruct.xStart, sFaultDrawerStruct.yStart); } -#ifdef NON_MATCHING u32 FaultDrawer_FormatStringFunc(u32 arg0, const char* str, s32 count) { - while (count) + for (count; count != 0; count--, str++) { - s32 curXStart; //s32? + s32 curXStart; s32 curXEnd; if (sFaultDrawerStruct.escCode) { sFaultDrawerStruct.escCode = false; if (*str > 0x30 && *str < 0x3A) - FaultDrawer_SetForeColor(gFaultStruct.colors[*str + 12]); + FaultDrawer_SetForeColor(sFaultDrawerStruct.printColors[*str - 0x30]); curXStart = sFaultDrawerStruct.cursorX; curXEnd = sFaultDrawerStruct.xEnd - sFaultDrawerStruct.charW; } else { - if (*str == '\n') + switch (*str) { - if (sFaultDrawerStruct.osSyncPrintfEnabled) - osSyncPrintf("\n"); - - sFaultDrawerStruct.cursorX = sFaultDrawerStruct.w; - curXStart = sFaultDrawerStruct.w; - curXEnd = sFaultDrawerStruct.xEnd - sFaultDrawerStruct.charW; - } - else if (*str == '\x1a') - { - sFaultDrawerStruct.escCode = true; - curXStart = sFaultDrawerStruct.cursorX; - curXEnd = sFaultDrawerStruct.xEnd - sFaultDrawerStruct.charW; - } - else - { - if (sFaultDrawerStruct.osSyncPrintfEnabled) - osSyncPrintf("%c", *str); - - FaultDrawer_DrawChar(*str); - sFaultDrawerStruct.cursorX += sFaultDrawerStruct.charW + sFaultDrawerStruct.charWPad; - - curXStart = sFaultDrawerStruct.cursorX; - curXEnd = sFaultDrawerStruct.xEnd - sFaultDrawerStruct.charW; + case '\n': + if (sFaultDrawerStruct.osSyncPrintfEnabled) + osSyncPrintf("\n"); + + sFaultDrawerStruct.cursorX = sFaultDrawerStruct.w; + curXStart = sFaultDrawerStruct.cursorX; + curXEnd = sFaultDrawerStruct.xEnd - sFaultDrawerStruct.charW; + break; + case '\x1A': + sFaultDrawerStruct.escCode = true; + curXStart = sFaultDrawerStruct.cursorX; + curXEnd = sFaultDrawerStruct.xEnd - sFaultDrawerStruct.charW; + break; + default: + if (sFaultDrawerStruct.osSyncPrintfEnabled) + osSyncPrintf("%c", *str); + + FaultDrawer_DrawChar(*str); + sFaultDrawerStruct.cursorX += sFaultDrawerStruct.charW + sFaultDrawerStruct.charWPad; + + curXStart = sFaultDrawerStruct.cursorX; + curXEnd = sFaultDrawerStruct.xEnd - sFaultDrawerStruct.charW; } } if (curXEnd <= curXStart) { - sFaultDrawerStruct.cursorY += sFaultDrawerStruct.charH + sFaultDrawerStruct.charHPad; sFaultDrawerStruct.cursorX = sFaultDrawerStruct.xStart; - if (sFaultDrawerStruct.yEnd - sFaultDrawerStruct.charH <= (u16)sFaultDrawerStruct.cursorY) //cast? + sFaultDrawerStruct.cursorY += sFaultDrawerStruct.charH + sFaultDrawerStruct.charHPad; + if (sFaultDrawerStruct.yEnd - sFaultDrawerStruct.charH <= sFaultDrawerStruct.cursorY) { if (sFaultDrawerStruct.inputCallback) { @@ -247,16 +248,12 @@ u32 FaultDrawer_FormatStringFunc(u32 arg0, const char* str, s32 count) sFaultDrawerStruct.cursorY = sFaultDrawerStruct.yStart; } } - - count--; - str++; } + osWritebackDCacheAll(); + return arg0; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/fault_drawer/FaultDrawer_FormatStringFunc.s") -#endif void FaultDrawer_VPrintf(const char* str, char* args) //va_list { diff --git a/src/code/gfxprint.c b/src/code/gfxprint.c index a1aaaced8..340d4702a 100644 --- a/src/code/gfxprint.c +++ b/src/code/gfxprint.c @@ -104,54 +104,92 @@ u8 sGfxPrintFontData[(16*256)/2] = }; -#define gDPSetPrimColorMod(pkt, m, l, rgba) \ -_DW({ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | \ - _SHIFTL(m, 8, 8) | _SHIFTL(l, 0, 8)); \ - _g->words.w1 = (rgba); \ +#define gDPSetPrimColorMod(pkt, m, l, rgba) \ +_DW({ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | \ + _SHIFTL(m, 8, 8) | _SHIFTL(l, 0, 8)); \ + _g->words.w1 = (rgba); \ }) #ifdef NON_MATCHING +// regalloc and minor ordering differences void GfxPrint_InitDlist(GfxPrint* this) { - u32 palette; - u32 tile; + s32 width = 16; + s32 height = 256; + s32 i; gDPPipeSync(this->dlist++); - gDPSetOtherMode(this->dlist++, 0xECF0, 0x504244); - gDPSetCombineLERP(this->dlist++, K5, K5, 0, TEXEL0, 0, 0, 0, TEXEL0, K5, K5, 0, TEXEL0, 0, 0, 0, TEXEL0); - gDPLoadTextureBlock(this->dlist++, sGfxPrintFontData, G_IM_FMT_CI, G_IM_SIZ_4b, 16, 256, 0, 0, 0, 0, 0, 0, 0); //? missmatch here - gDPLoadTLUT(this->dlist++, 64, 0x100, sGfxPrintFontTLUT); - - tile = 2; - palette = 1; - do - { - gDPSetTile(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_4b, 1, 0x0, tile, palette++, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0, G_TX_NOMIRROR | G_TX_CLAMP, 0, 0); - gDPSetTileSize(this->dlist++, tile, 0, 0, 15, 255); - tile+=2; + gDPSetOtherMode(this->dlist++, + G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | + G_TT_IA16 | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE, + G_AC_NONE | G_ZS_PRIM | G_RM_XLU_SURF | G_RM_XLU_SURF2); + gDPSetCombineLERP(this->dlist++, + 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0, + 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0); + + gDPSetTextureImage(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_4b_LOAD_BLOCK, 1, sGfxPrintFontData); + gDPSetTile(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_4b_LOAD_BLOCK, + 0, 0, G_TX_LOADTILE, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); + gDPLoadSync(this->dlist++); + gDPLoadBlock(this->dlist++, G_TX_LOADTILE, 0, 0, + (((width)*(height) + G_IM_SIZ_4b_INCR) >> G_IM_SIZ_4b_SHIFT) - 1, + CALC_DXT(width, G_IM_SIZ_4b_BYTES)); + gDPPipeSync(this->dlist++); + gDPSetTile(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_4b, + 1, 0, G_TX_RENDERTILE, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); + gDPSetTileSize(this->dlist++, G_TX_RENDERTILE, 0, 0, + ((width)-1) << G_TEXTURE_IMAGE_FRAC, + ((height)-1) << G_TEXTURE_IMAGE_FRAC); + + gDPLoadTLUT(this->dlist++, 64, 256, sGfxPrintFontTLUT); - } while (palette < 4); + for (i = 1; i < 4; i++) + { + gDPSetTile(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_4b, + 1, 0, i * 2, i, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD); + gDPSetTileSize(this->dlist++, i * 2, 0, 0, 60, 1020); + } gDPSetPrimColorMod(this->dlist++, 0, 0, *(u32*)&this->color); - gDPLoadTextureTile(this->dlist++, sGfxPrintUnkData, G_IM_FMT_CI, G_IM_SIZ_8b, 1, 0, 0, 0, 0, 7, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 1, 3, 0, 0); - gDPLoadTLUT(this->dlist++, 16, 0x140, sGfxPrintUnkTLUT); - tile = 3; - do + gDPSetTextureImage(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_8b, 1, sGfxPrintUnkData); + gDPSetTile(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_8b, + 1, 0, G_TX_LOADTILE, 0 , + G_TX_NOMIRROR | G_TX_WRAP, 3, G_TX_NOLOD, + G_TX_NOMIRROR | G_TX_WRAP, 1, G_TX_NOLOD); + gDPLoadSync(this->dlist++); + gDPLoadTile(this->dlist++, G_TX_LOADTILE, 0, 0, 2, 28); + gDPPipeSync(this->dlist++); + gDPSetTile(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_8b, + 1, 0, 1, 4, + G_TX_NOMIRROR | G_TX_WRAP, 3, G_TX_NOLOD, + G_TX_NOMIRROR | G_TX_WRAP, 1, G_TX_NOLOD); + gDPSetTileSize(this->dlist++, 1, 0, 0, 4, 28); + + gDPLoadTLUT(this->dlist++, 16, 320, sGfxPrintUnkTLUT); + + for (i = 1; i < 4; i++) { - gDPSetTile(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_4b, tile, 0x0, G_TX_RENDERTILE, 4, G_TX_NOMIRROR | G_TX_WRAP, 3, 0, G_TX_NOMIRROR | G_TX_WRAP, 1, 0); - gDPSetTileSize(this->dlist++, tile, 0, 0, 1, 7); - tile += 2; - } while (tile != 9); + gDPSetTile(this->dlist++, G_IM_FMT_CI, G_IM_SIZ_4b, + 1, 0, i * 2 + 1, 4, + G_TX_NOMIRROR | G_TX_WRAP, 3, G_TX_NOLOD, + G_TX_NOMIRROR | G_TX_WRAP, 1, G_TX_NOLOD); + gDPSetTileSize(this->dlist++, i * 2 + 1, 0, 0, 4, 28); + } } #else #pragma GLOBAL_ASM("asm/non_matchings/code/gfxprint/GfxPrint_InitDlist.s") #endif - void GfxPrint_SetColor(GfxPrint* this, u32 r, u32 g, u32 b, u32 a) { this->color.r = r; @@ -180,71 +218,95 @@ void GfxPrint_SetBasePosPx(GfxPrint* this, s32 x, s32 y) this->baseY = y << 2; } -//close from matching #ifdef NON_MATCHING -void GfxPrint_PrintCharImpl(GfxPrint* this, u8 c) +// regalloc and ordering differences +void GfxPrint_PrintCharImpl(GfxPrint* this, char c) { - u32 test; - u32 test2; - if (this->flag & GFXPRINT_UPDATE_MODE) { this->flag &= ~GFXPRINT_UPDATE_MODE; + gDPPipeSync(this->dlist++); if (this->flag & GFXPRINT_USE_RGBA16) { gDPSetTextureLUT(this->dlist++, G_TT_RGBA16); gDPSetCycleType(this->dlist++, G_CYC_2CYCLE); gDPSetRenderMode(this->dlist++, G_RM_OPA_CI, G_RM_XLU_SURF2); - gDPSetCombineLERP(this->dlist++, TEXEL0, K5, TEXEL1, COMBINED_ALPHA, TEXEL0, 0, TEXEL1, 0, K5, K5, 0, COMBINED, 0, 0, 0, COMBINED); + gDPSetCombineLERP(this->dlist++, + TEXEL0, 0, TEXEL1, 0, TEXEL0, 0, TEXEL1, 0, + 0, 0, 0, COMBINED, 0, 0, 0, COMBINED); } else { gDPSetTextureLUT(this->dlist++, G_TT_IA16); gDPSetCycleType(this->dlist++, G_CYC_1CYCLE); gDPSetRenderMode(this->dlist++, G_RM_XLU_SURF, G_RM_XLU_SURF2); - gDPSetCombineLERP(this->dlist++, TEXEL0, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, TEXEL0, TEXEL0, K5, PRIMITIVE, COMBINED_ALPHA, 0, 0, 0, TEXEL0); + gDPSetCombineLERP(this->dlist++, + TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, TEXEL0, + TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, TEXEL0); } } - test = (c & 4) << 6; - test2 = (c >> 3) << 8; if (this->flag & GFXPRINT_FLAG4) { gDPSetPrimColorMod(this->dlist++, 0, 0, 0); if (this->flag & GFXPRINT_FLAG64) - gSPTextureRectangle(this->dlist++, (this->posX+4)<<1, (this->posY+4)<<1, (this->posX+0x24)<<1, (this->posY+0x24)<<1, c<<1, test, test2, 512, 512); //c*2 ? + gSPTextureRectangle(this->dlist++, + (this->posX + 4) << 1, (this->posY + 4) << 1, + (this->posX + 4 + 32) << 1, (this->posY + 4 + 32) << 1, + c * 2, + (u16)(c & 4) * 64, (u16)(c >> 3) * 256, + 512, 512); else - gSPTextureRectangle(this->dlist++, this->posX+4, this->posY+4, this->posX+0x24, this->posY+0x24, c<<1, test, test2, 1024, 1024); + gSPTextureRectangle(this->dlist++, + this->posX + 4, this->posY + 4, + this->posX + 4 + 32, this->posY + 4 + 32, + c * 2, + (u16)(c & 4) * 64, (u16)(c >> 3) * 256, + 1024, 1024); gDPSetPrimColorMod(this->dlist++, 0, 0, *(u32*)&this->color); } + if (this->flag & GFXPRINT_FLAG64) - gSPTextureRectangle(this->dlist++, (this->posX)<<1, (this->posY)<<1, (this->posX + 0x20)<<1, (this->posY + 0x20)<<1, c << 1, test, test2, 512, 512); + gSPTextureRectangle(this->dlist++, + (this->posX) << 1, (this->posY) << 1, + (this->posX + 32) << 1, (this->posY + 32) << 1, + c * 2, + (u16)(c & 4) * 64, (u16)(c >> 3) * 256, + 512, 512); else - gSPTextureRectangle(this->dlist++, this->posX, this->posY, this->posX + 0x20, this->posY + 0x20, c << 1, test, test2, 1024, 1024); - - this->posX += 0x20; + gSPTextureRectangle(this->dlist++, + this->posX, this->posY, + this->posX + 32, this->posY + 32, + c * 2, + (u16)(c & 4) * 64, (u16)(c >> 3) * 256, + 1024, 1024); + + this->posX += 32; } #else #pragma GLOBAL_ASM("asm/non_matchings/code/gfxprint/GfxPrint_PrintCharImpl.s") #endif - -#ifdef NON_MATCHING -void GfxPrint_PrintChar(GfxPrint *this, char c) +void GfxPrint_PrintChar(GfxPrint* this, u8 c) { + u8 charParam = c; + if (c == ' ') + { this->posX += 0x20; - else if (c > 0x20 && c < 0x7f) - GfxPrint_PrintCharImpl(this, c); - else if (c >= 0xa0 && c < 0xe0) + } + else if (c > 0x20 && c < 0x7F) { - u8 charParam = c; - if ((this->flag & GFXPRINT_FLAG1) != 0) + GfxPrint_PrintCharImpl(this, charParam); + } + else if (c >= 0xA0 && c < 0xE0) + { + if (this->flag & GFXPRINT_FLAG1) { - if (c < 0xc0) + if (c < 0xC0) charParam = c - 0x20; else charParam = c + 0x20; @@ -253,75 +315,41 @@ void GfxPrint_PrintChar(GfxPrint *this, char c) } else { - switch(c) + switch (c) { case 0: - return; - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - return; - //tab - case 9: - { - u32 uVar1; - do { - GfxPrint_PrintCharImpl(this, 0x20); - uVar1 = this->posX - this->baseX; - if (uVar1 < 0 && uVar1 != 0) - uVar1 -= 0x100; - } while (uVar1 != 0); - return; - } - //line feed - case 0xa: - { + break; + case '\n': this->posY += 0x20; + case '\r': this->posX = this->baseX; - return; - } - /* - case 0xb: - case 0xc: - return; - */ - //carriage return - case 0xd: - { - this->posX = this->baseX; - return; - } - case 0x8a: - this->flag &= ~GFXPRINT_USE_RGBA16; - this->flag |= GFXPRINT_UPDATE_MODE; - return; - case 0x8b: + break; + case '\t': + do + { + GfxPrint_PrintCharImpl(this, 0x20); + } while ((this->posX - this->baseX) % 256); + break; + case 0x8D: + this->flag |= GFXPRINT_FLAG1; + break; + case 0x8C: + this->flag &= ~GFXPRINT_FLAG1; + break; + case 0x8B: this->flag |= GFXPRINT_USE_RGBA16; this->flag |= GFXPRINT_UPDATE_MODE; - return; - case 0x8c: - this->flag &= ~GFXPRINT_FLAG1; - return; - case 0x8d: - this->flag |= GFXPRINT_FLAG1; - return; - case 0x8e: + break; + case 0x8A: + this->flag &= ~GFXPRINT_USE_RGBA16; + this->flag |= GFXPRINT_UPDATE_MODE; + break; + case 0x8E: default: - return; + break; } - } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/gfxprint/GfxPrint_PrintChar.s") -#endif - - void GfxPrint_PrintStringWithSize(GfxPrint* this, const void* buffer, size_t charSize, size_t charCount) { @@ -409,4 +437,4 @@ void GfxPrint_Printf(GfxPrint* this, const char* fmt, ...) va_start(args, fmt); GfxPrint_VPrintf(this, fmt, args); -} \ No newline at end of file +} diff --git a/src/code/padmgr.c b/src/code/padmgr.c index 0c0201c63..163e546b1 100644 --- a/src/code/padmgr.c +++ b/src/code/padmgr.c @@ -1,10 +1,13 @@ #include #include +#include #include #include #include +s32 D_8012D280 = 1; + OSMesgQueue* PadMgr_LockGetControllerQueue(PadMgr* padmgr) { OSMesgQueue* ctrlrqueue = NULL; @@ -37,23 +40,28 @@ void PadMgr_UnlockReleaseControllerQueue(PadMgr* padmgr, OSMesgQueue* ctrlrqueue void PadMgr_Lock2(PadMgr* padmgr) { - osRecvMesg(&padmgr->queue2, 0, OS_MESG_BLOCK); + osRecvMesg(&padmgr->queue2, NULL, OS_MESG_BLOCK); } void PadMgr_Unlock2(PadMgr* padmgr) { - osSendMesg(&padmgr->queue2, 0, OS_MESG_BLOCK); + osSendMesg(&padmgr->queue2, NULL, OS_MESG_BLOCK); } #ifdef NON_MATCHING +// regalloc and minor ordering differences void func_800C740C(PadMgr* padmgr) { + static u32 D_8012D284 = 0; + static u32 D_8016A4F0; + s32 temp; s32 var1; OSMesgQueue* ctrlrqueue; s32 var3; s32 var4; s32 i; + temp = 1; ctrlrqueue = PadMgr_LockGetControllerQueue(padmgr); var1 = 0; @@ -63,26 +71,28 @@ void func_800C740C(PadMgr* padmgr) { if (padmgr->pad_status[i].status & 1) { - if (padmgr->unk_2AE[i] == 1) + if (padmgr->unk_2AE[i] == temp) { if (padmgr->unk_2B2[i] != 0) { if (padmgr->unk_2B6[i] < 3) { - osSyncPrintf(D_80145894); //"\x1b[33m" (probably formatting/debugger interface) - osSyncPrintf(D_8014589C, i + 1, D_801458B0); //"padmgr: %d[JPN]Con: ", "[JPN]Vibration pack jumble jumble" - osSyncPrintf(D_801458CC); //"\x1b[m" (probably formatting/debugger interface) - if (osSetVibration(&padmgr->unk_controller[i], 1) != 0) + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック ぶるぶるぶるぶる"); + osSyncPrintf(VT_RST); + + if (osSetVibration(&padmgr->unk_controller[i], temp) != 0) { padmgr->unk_2AE[i] = 0; - osSyncPrintf(D_801458D0); - osSyncPrintf(D_801458D8, i + 1, D_801458EC); //"A communication error has occurred with the vibraton pack" - osSyncPrintf(D_80145914); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックで通信エラーが発生しました"); + osSyncPrintf(VT_RST); } else { padmgr->unk_2B6[i] = 3; } + var1 = 1; } } @@ -90,20 +100,22 @@ void func_800C740C(PadMgr* padmgr) { if (padmgr->unk_2B6[i] != 0) { - osSyncPrintf(D_80145918); - osSyncPrintf(D_80145920, i + 1, D_80145934); //"Stop vibration pack" - osSyncPrintf(D_80145944); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止"); + osSyncPrintf(VT_RST); + if (osSetVibration(&padmgr->unk_controller[i], 0) != 0) { padmgr->unk_2AE[i] = 0; - osSyncPrintf(D_80145948); - osSyncPrintf(D_80145950, i + 1, D_80145964); //"A communication error has occurred with the vibration pack" - osSyncPrintf(D_8014598C); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックで通信エラーが発生しました"); + osSyncPrintf(VT_RST); } else { padmgr->unk_2B6[i]--; } + var1 = 1; } } @@ -115,16 +127,16 @@ void func_800C740C(PadMgr* padmgr) { if (padmgr->unk_2AE[i] == 1) { - osSyncPrintf(D_80145990); - osSyncPrintf(D_80145998, i + 1, D_801459AC); //"Vibration pack seems to be pulled out" - osSyncPrintf(D_801459CC); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックが抜かれたようです"); + osSyncPrintf(VT_RST); padmgr->unk_2AE[i] = 0; } else { - osSyncPrintf(D_801459D0); - osSyncPrintf(D_80145A24); - osSyncPrintf(D_801459D8, i + 1, D_801459EC); //"It seems that a controller pack that is not a vibration pack was pulled out" + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックではないコントローラパックが抜かれたようです"); + osSyncPrintf(VT_RST); padmgr->unk_2AE[i] = 0; } } @@ -145,9 +157,9 @@ void func_800C740C(PadMgr* padmgr) padmgr->unk_2AE[var3] = 1; osSetVibration(&padmgr->unk_controller[var3], 1); osSetVibration(&padmgr->unk_controller[var3], 0); - osSyncPrintf(D_80145A28); - osSyncPrintf(D_80145A30, var3 + 1, D_80145A44); //"Recognized vibration pack" - osSyncPrintf(D_80145A60); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("padmgr: %dコン: %s\n", var3 + 1, "振動パックを認識しました"); + osSyncPrintf(VT_RST); } else if (var4 == 11) { @@ -155,12 +167,11 @@ void func_800C740C(PadMgr* padmgr) } else if (var4 == 4) { - LogUtils_LogThreadId(D_80145A64, 282); - ++D_8012D284; - osSyncPrintf(D_80145A70, D_8012D284); //"++errcnt = %d" - osSyncPrintf(D_80145A80); - osSyncPrintf(D_80145A88, var3 + 1, D_80145A9C); //"Controller pack communication error" - osSyncPrintf(D_80145ABC); + LogUtils_LogThreadId("../padmgr.c", 282); + osSyncPrintf("++errcnt = %d\n", ++D_8012D284); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("padmgr: %dコン: %s\n", var3 + 1, "コントローラパックの通信エラー"); + osSyncPrintf(VT_RST); } } } @@ -169,6 +180,8 @@ void func_800C740C(PadMgr* padmgr) PadMgr_UnlockReleaseControllerQueue(padmgr, ctrlrqueue); } #else +u32 D_8012D284 = 0; +u32 D_8016A4F0; #pragma GLOBAL_ASM("asm/non_matchings/code/padmgr/func_800C740C.s") #endif @@ -186,10 +199,10 @@ void func_800C7818(PadMgr* padmgr) { if ((gFaultStruct.msgId == 0) && (padmgr->unk_45D != 0)) { - osSyncPrintf("\x1b[33m"); + osSyncPrintf(VT_FGCOL(YELLOW)); //EUC-JP: コン | 'Con'? , EUC-JP: 振動パック 停止 | Stop vibration pack osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止"); - osSyncPrintf("\x1b[m"); + osSyncPrintf(VT_RST); } osSetVibration(&padmgr->unk_controller[i], 0); @@ -211,7 +224,8 @@ void func_800C7934(PadMgr* padmgr, u32 a1, u32 a2) } #ifdef NON_MATCHING -//func_800A23CC in 1.0 +// minor ordering difference +// 800A23CC in 1.0 void func_800C7948(PadMgr* padmgr, u8* a1) { padmgr->unk_2B2[0] = a1[0]; diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 3b6698c30..71bba11f2 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -4332,7 +4332,7 @@ s16 func_80034DD4(Actor* actor, GlobalContext* globalCtx, s16 arg2, f32 arg3) if (arg3 < var) { - actor->flags &= ~0x1; + actor->flags &= ~1; Math_SmoothScaleMaxMinS(&arg2, 0, 6, 0x14, 1); } else @@ -4426,35 +4426,7 @@ s32 func_80035124(Actor* actor, GlobalContext* globalCtx) return ret; } -/* z_cheap_proc.c */ - -void Draw_DListOpa(GlobalContext* globalCtx, u32 dlist) -{ - GraphicsContext* gfxCtx = globalCtx->state.gfxCtx; - Gfx* gfxArr[4]; - - func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_cheap_proc.c", 214); - - func_80093D18(globalCtx->state.gfxCtx); - gSPMatrix(gfxCtx->polyOpa.p++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_cheap_proc.c", 216), G_MTX_MODELVIEW | G_MTX_LOAD); - gSPDisplayList(gfxCtx->polyOpa.p++, dlist); - - func_800C6B54(gfxArr, globalCtx->state.gfxCtx, "../z_cheap_proc.c", 219); -} - -void Draw_DListXlu(GlobalContext* globalCtx, u32 dlist) -{ - GraphicsContext* gfxCtx = globalCtx->state.gfxCtx; - Gfx* gfxArr[4]; - - func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_cheap_proc.c", 228); - - func_80093D84(globalCtx->state.gfxCtx); - gSPMatrix(gfxCtx->polyXlu.p++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_cheap_proc.c", 230), G_MTX_MODELVIEW | G_MTX_LOAD); - gSPDisplayList(gfxCtx->polyXlu.p++, dlist); - - func_800C6B54(gfxArr, globalCtx->state.gfxCtx, "../z_cheap_proc.c", 233); -} +#include "z_cheap_proc.c" u8 func_800353E8(GlobalContext* globalCtx) { diff --git a/src/code/z_camera.c b/src/code/z_camera.c index e1bece0fa..89a5e0334 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -232,8 +232,9 @@ void func_80044340(Camera *camera, Vec3f *b, Vec3f *c) *c = sp20.unk_00; } -#ifdef NON_MATCHING f32 func_80038B7C(); + +#ifdef NON_MATCHING // ordering s32 func_800443A0(Camera *camera, Vec3f *b, Vec3f *c) { @@ -449,17 +450,16 @@ f32 func_80045714(Vec3f *a, s16 b, s16 c, f32 arg3); #pragma GLOBAL_ASM("asm/non_matchings/code/z_camera/func_80045714.s") #endif -#ifdef NON_MATCHING f32 func_8007C0A8(f32, f32); -// CLOSE: stack is slightly off, probably a temp var + s32 func_800457A8(Camera *camera, struct_80045714 *b, f32 c, s16 d) { f32 unused; Vec3f sp50; Vec3f sp44; s32 unused2; - f32 temp_ret; PosRot *sp2C; + f32 temp_ret; temp_ret = func_8002DC84(camera->player); @@ -481,13 +481,11 @@ s32 func_800457A8(Camera *camera, struct_80045714 *b, f32 c, s16 d) return 1; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/z_camera/func_800457A8.s") -#endif -#ifdef NON_MATCHING f32 func_8007C028(Vec3f *, Vec3f *); -// CLOSE: regalloc, plus stack is slightly off, probably a temp var + +#ifdef NON_MATCHING +// CLOSE: regalloc s32 func_800458D4(Camera *camera, struct_80045714 *b, f32 c, f32 *d, s16 e) { f32 phi_f2; @@ -496,7 +494,7 @@ s32 func_800458D4(Camera *camera, struct_80045714 *b, f32 c, f32 *d, s16 e) f32 temp_ret; PosRot *temp_s1; f32 sp48; - Vec3f sp3C; // unused + s32 pad[2]; sp60.y = func_8002DC84(camera->player) + c; sp60.x = 0.0f; @@ -631,7 +629,6 @@ s32 func_80045C74(Camera *camera, struct_80045714 *b, f32 c, f32 *d, s16 arg4) phi_f16 = 1.0f - sinf(OREG(33) * (M_PI / 180) - temp_ret_3); else phi_f16 = 1.0f; - } sp70.y -= temp * phi_f16; } @@ -881,51 +878,43 @@ void Camera_Vec3fCopy(Vec3f *src, Vec3f *dst) // 225 lines #pragma GLOBAL_ASM("asm/non_matchings/code/z_camera/func_80057C6C.s") -#ifdef NON_MATCHING -// still needs a bit of work, but should be functionally equivalent +s32 func_8005AD40(Camera *camera, s32 a, s16 b, f32 c, s16 d, s16 e, s16 f); + void func_80057FC4(Camera *camera) { if (camera != &camera->globalCtx->cameraCtx.activeCameras[0]) { - camera->unk_142 = 33; + camera->unk_154 = camera->unk_142 = 33; camera->unk_14C &= ~0x4; - camera->unk_154 = camera->unk_142; // compiler uses the same temp reg, but it should load from 142 right after being saved to - // maybe try camera->unk_154 = camera->unk_142 = 33 and make them have differing signs? - return; } - // try putting these in a bunch of if else statements - if (*camera->globalCtx->roomCtx.curRoom.unk_08 != 1) + else if (camera->globalCtx->roomCtx.curRoom.mesh->polygon.type != 1) { - if (camera->globalCtx->roomCtx.curRoom.unk_03 != 0) + switch (camera->globalCtx->roomCtx.curRoom.unk_03) { - if (camera->globalCtx->roomCtx.curRoom.unk_03 == 1) - { + case 1: func_8005AD40(camera, 0, -99, 0, 0, 18, 10); - camera->unk_142 = 3; - camera->unk_154 = camera->unk_142; - return; - } - osSyncPrintf("camera: room type: default set etc (%d)\n", camera->globalCtx->roomCtx.curRoom.unk_03); - func_8005AD40(camera, 0, -99, 0, 0, 18, 10); - camera->unk_142 = 1; - camera->unk_154 = camera->unk_142; - return; + camera->unk_154 = camera->unk_142 = 3; + break; + case 0: + osSyncPrintf("camera: room type: default set field\n"); + func_8005AD40(camera, 0, -99, 0, 0, 18, 10); + camera->unk_154 = camera->unk_142 = 1; + break; + default: + osSyncPrintf("camera: room type: default set etc (%d)\n", camera->globalCtx->roomCtx.curRoom.unk_03); + func_8005AD40(camera, 0, -99, 0, 0, 18, 10); + camera->unk_154 = camera->unk_142 = 1; + camera->unk_14C |= 4; + break; } - osSyncPrintf("camera: room type: default set field\n"); - func_8005AD40(camera, 0, -99, 0, 0, 18, 10); - camera->unk_142 = 1; - camera->unk_14C |= 4; - camera->unk_154 = camera->unk_142; - return; } - osSyncPrintf("camera: room type: prerender\n"); - camera->unk_142 = 0x21; - camera->unk_14C &= 0xfffb; - camera->unk_154 = camera->unk_142; + else + { + osSyncPrintf("camera: room type: prerender\n"); + camera->unk_154 = camera->unk_142 = 33; + camera->unk_14C &= ~0x4; + } } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/z_camera/func_80057FC4.s") -#endif void Camera_Stub80058140(Camera *camera) { @@ -1093,7 +1082,7 @@ s16 func_8005AD1C(Camera *camera, s16 b) return camera->unk_14C; } -s32 func_8005AD40(Camera *camera, s32 a, s16 b, s16 c, s16 d, s16 e, s16 f) +s32 func_8005AD40(Camera *camera, s32 a, s16 b, f32 c, s16 d, s16 e, s16 f) { if ((camera->unk_142 == 43) || (camera->unk_142 == 29)) return 0; diff --git a/src/code/z_cheap_proc.c b/src/code/z_cheap_proc.c new file mode 100644 index 000000000..48fd9b32a --- /dev/null +++ b/src/code/z_cheap_proc.c @@ -0,0 +1,30 @@ +#include +#include + +void Draw_DListOpa(GlobalContext* globalCtx, u32 dlist) +{ + GraphicsContext* gfxCtx = globalCtx->state.gfxCtx; + Gfx* gfxArr[4]; + + func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_cheap_proc.c", 214); + + func_80093D18(globalCtx->state.gfxCtx); + gSPMatrix(gfxCtx->polyOpa.p++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_cheap_proc.c", 216), G_MTX_MODELVIEW | G_MTX_LOAD); + gSPDisplayList(gfxCtx->polyOpa.p++, dlist); + + func_800C6B54(gfxArr, globalCtx->state.gfxCtx, "../z_cheap_proc.c", 219); +} + +void Draw_DListXlu(GlobalContext* globalCtx, u32 dlist) +{ + GraphicsContext* gfxCtx = globalCtx->state.gfxCtx; + Gfx* gfxArr[4]; + + func_800C6AC4(gfxArr, globalCtx->state.gfxCtx, "../z_cheap_proc.c", 228); + + func_80093D84(globalCtx->state.gfxCtx); + gSPMatrix(gfxCtx->polyXlu.p++, Matrix_NewMtx(globalCtx->state.gfxCtx, "../z_cheap_proc.c", 230), G_MTX_MODELVIEW | G_MTX_LOAD); + gSPDisplayList(gfxCtx->polyXlu.p++, dlist); + + func_800C6B54(gfxArr, globalCtx->state.gfxCtx, "../z_cheap_proc.c", 233); +} -- cgit v1.2.3 From 32fe030b42bc001b71d6edcf0530f60e6ecd73cc Mon Sep 17 00:00:00 2001 From: mzxrules Date: Wed, 18 Mar 2020 10:27:49 -0400 Subject: new repo, OK++ --- src/code/z_debug.c | 282 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 276 insertions(+), 6 deletions(-) (limited to 'src/code') diff --git a/src/code/z_debug.c b/src/code/z_debug.c index b5d078985..74f3965eb 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -1,20 +1,290 @@ #include #include +#include +#include +#include -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug/func_800636C0.s") +#define BUTTON_C_RIGHT 0x0001 +#define BUTTON_C_LEFT 0x0002 +#define BUTTON_C_DOWN 0x0004 +#define BUTTON_C_UP 0x0008 +#define BUTTON_R 0x0010 +#define BUTTON_L 0x0020 +#define BUTTON_D_RIGHT 0x0100 +#define BUTTON_D_LEFT 0x0200 +#define BUTTON_D_DOWN 0x0400 +#define BUTTON_D_UP 0x0800 +#define BUTTON_START 0x1000 +#define BUTTON_Z 0x2000 +#define BUTTON_B 0x4000 +#define BUTTON_A 0x8000 -void func_8006375C(UNK_TYPE arg0, UNK_TYPE arg1, UNK_TYPE arg2) +#define REG_GROUP_TOTAL 29 +#define REG_N 96 +#define PAGE_N 16 + +GameInfo* gGameInfo; +int D_8015FA94; //no known symbols + +typedef struct +{ + u8 x; + u8 y; + u8 colorId; + char text[0x15]; +} PrintTextBuffer; + +PrintTextBuffer D_8015FA98[0x16]; +//s16 D_8011E0B0 //PrintTextBuffer index + +//#define D_8015FC18 D_8015FA98[0x10] +typedef struct +{ + u16 push; + u16 held; +} InputCombo; + +extern InputCombo D_8011E0D4[REG_GROUP_TOTAL]; //register button combos + +extern char D_8011E148[]; + +//initialize GameInfo +void func_800636C0() +{ + s32 i; + + gGameInfo = (GameInfo*)SystemArena_MallocDebug(sizeof(GameInfo), "../z_debug.c", 0x104); + gGameInfo->reg_page = 0; + gGameInfo->reg_group = 0; + gGameInfo->reg_cur = 0; + gGameInfo->dpad_last = 0; + gGameInfo->repeat = 0; + for (i = 0; i < 0xAE0; i++) + { + gGameInfo->data[i] = 0; + } +} + +//Called when free movement is active +void func_8006375C(s32 arg0, s32 arg1, float* d_80855320) { } +//8011D394 enable camera debugger + +#ifdef NON_MATCHING //regalloc +//Copy Camera Debugger Text +void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) +{ + PrintTextBuffer* buf; + char* next_text; + s16 i; //v1 + + buf = &D_8015FA98[D_8011E0B0]; + if (D_8011E0B0 < 0x16) { + + buf->x = x; + buf->y = y; + buf->colorId = colorId; + + i = 0; + next_text = buf->text + 1; + + if (*buf->text = *text++) { + do if (i++ > 0x14) { + break; + } while (*next_text++ = *text++); + } + + *next_text = '\0'; + D_8011E0B0++; + } +} + +#else #pragma GLOBAL_ASM("asm/non_matchings/code/z_debug/func_8006376C.s") +#endif -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug/func_80063828.s") +//Draw Text +void func_80063828(GfxPrint* gfxPrint) +{ + s32 i; + Color_RGBA8* color; + PrintTextBuffer* buffer; + char* text; + + i = 0; + if (D_8011E0B0 > 0) + { + do + { + buffer = &D_8015FA98[i]; + text = buffer->text; + + color = &D_8011E0B4[buffer->colorId]; + GfxPrint_SetColor(gfxPrint, color->r, color->g, color->b, color->a); + GfxPrint_SetPos(gfxPrint, buffer->x, buffer->y); + GfxPrint_Printf(gfxPrint, "%s", text); + i += 1; + } while (i < D_8011E0B0); + } +} + +//Edit REG +void func_8006390C(Input* input) { + + s32 dpad; + s32 reg_group; + s32 increment; + InputCombo* input_combo; + s32 i; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug/func_8006390C.s") + reg_group = (gGameInfo->reg_group * (REG_N / PAGE_N) + gGameInfo->reg_page) * PAGE_N - PAGE_N; + dpad = input->raw.pad & 0xF00; + if (!~(input->raw.pad | ~BUTTON_L) || + !~(input->raw.pad | ~BUTTON_R) || + !~(input->raw.pad | ~BUTTON_START)) { + input_combo = D_8011E0D4; + for (i = 0; i < REG_GROUP_TOTAL; i++) + { + if (~(~input_combo->push | input->raw.pad) || + ~(~input_combo->held | input->padPressed)) { + input_combo++; + } + else + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug/func_80063C04.s") + if (i < REG_GROUP_TOTAL) { + if (i == gGameInfo->reg_group) { + gGameInfo->reg_page = (gGameInfo->reg_page + 1) % 7; + return; + } + gGameInfo->reg_group = i; + gGameInfo->reg_page = 0; + } + } + else { + switch (gGameInfo->reg_page - 1) + { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug/func_80063D7C.s") + if (dpad == gGameInfo->dpad_last) { + gGameInfo->repeat--; + if (gGameInfo->repeat < 0) { + gGameInfo->repeat = 1; + } + else { + dpad ^= gGameInfo->dpad_last; + } + } + else { + gGameInfo->repeat = 0x10; + gGameInfo->dpad_last = dpad; + } + increment = + (dpad & BUTTON_D_RIGHT) ? ( + !~(input->raw.pad | ~(BUTTON_A | BUTTON_B)) ? 1000 : + !~(input->raw.pad | ~BUTTON_A) ? 100 : + !~(input->raw.pad | ~BUTTON_B) ? 10 : 1) : + (dpad & BUTTON_D_LEFT) ? ( + !~(input->raw.pad | ~(BUTTON_A | BUTTON_B)) ? -1000 : + !~(input->raw.pad | ~BUTTON_A) ? -100 : + !~(input->raw.pad | ~BUTTON_B) ? -10 : -1) : + 0; + + gGameInfo->data[gGameInfo->reg_cur + reg_group] += increment; + if (dpad & BUTTON_D_UP) { + gGameInfo->reg_cur--; + if (gGameInfo->reg_cur < 0) { + gGameInfo->reg_cur = PAGE_N - 1; + } + } + else if (dpad & BUTTON_D_DOWN) { + gGameInfo->reg_cur++; + if (gGameInfo->reg_cur >= PAGE_N) { + gGameInfo->reg_cur = 0; + } + } + if (iREG(0)) { + iREG(0) = 0; + func_800AA000(0, iREG(1), iREG(2), iREG(3)); + } + + } + } +} + +//Draw Memory Viewer +void func_80063C04(GfxPrint* gfxPrint) +{ + s32 i; + s32 page; + s32 reg_group; + s32 test; //removing affects stack + char reg_name[3]; + + page = (gGameInfo->reg_page * PAGE_N) - PAGE_N; + reg_group = (gGameInfo->reg_group * (REG_N / PAGE_N) + gGameInfo->reg_page) * PAGE_N - PAGE_N; + + //set up register name string + reg_name[0] = 'R'; + reg_name[1] = D_8011E148[gGameInfo->reg_group]; //r_group type char + reg_name[2] = '\0'; + GfxPrint_SetColor(gfxPrint, 0, 0x80, 0x80, 0x80); + + for (i = 0; i != PAGE_N; i++) + { + if (i == gGameInfo->reg_cur) + { + GfxPrint_SetColor(gfxPrint, 0, 0xff, 0xff, 0xff); + } + GfxPrint_SetPos(gfxPrint, 3, i + 5); + GfxPrint_Printf(gfxPrint, "%s%02d%6d", ®_name, page + i, gGameInfo->data[i + reg_group]); + if (i == gGameInfo->reg_cur) + { + GfxPrint_SetColor(gfxPrint, 0, 0x80, 0x80, 0x80); + } + } +} + +void func_80063D7C(GraphicsContext* gfxCtx) { + Gfx* sp7C; + Gfx* sp78; + Gfx* temp_ret; + void* unk2[6]; + GfxPrint gfxPrint; + void* unk[2]; + Gfx* dl_frame[4];//stores state of GfxCtx next ptrs + + func_800C6AC4(&dl_frame, gfxCtx, "../z_debug.c", 0x274); + GfxPrint_Ctor(&gfxPrint); + sp78 = gfxCtx->polyOpa.p; + temp_ret = func_800C6C20(gfxCtx->polyOpa.p); + gSPDisplayList(gfxCtx->overlay.p++, temp_ret); + GfxPrint_Open(&gfxPrint, temp_ret); + + if ((OREG(0) == 1) || (OREG(0) == 8)) { + func_80063828(&gfxPrint); + } + + if (gGameInfo->reg_page != 0) { + func_80063C04(&gfxPrint); + } + + D_8011E0B0 = 0; + sp7C = GfxPrint_Close(&gfxPrint); + gSPEndDisplayList(sp7C++); + func_800C6C28(sp78, sp7C); + gfxCtx->polyOpa.p = sp7C; + if (0); + func_800C6B54(&dl_frame, gfxCtx, "../z_debug.c", 0x298); + GfxPrint_Dtor(&gfxPrint); +} -- cgit v1.2.3 From dd4f67c3f51eba222060449972783951beedff9b Mon Sep 17 00:00:00 2001 From: mzxrules Date: Wed, 18 Mar 2020 12:31:36 -0400 Subject: convert z_debug.data --- src/code/z_debug.c | 71 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 17 deletions(-) (limited to 'src/code') diff --git a/src/code/z_debug.c b/src/code/z_debug.c index 74f3965eb..f0971cfbf 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -23,9 +23,6 @@ #define REG_N 96 #define PAGE_N 16 -GameInfo* gGameInfo; -int D_8015FA94; //no known symbols - typedef struct { u8 x; @@ -34,19 +31,61 @@ typedef struct char text[0x15]; } PrintTextBuffer; -PrintTextBuffer D_8015FA98[0x16]; -//s16 D_8011E0B0 //PrintTextBuffer index - -//#define D_8015FC18 D_8015FA98[0x10] typedef struct { u16 push; u16 held; } InputCombo; -extern InputCombo D_8011E0D4[REG_GROUP_TOTAL]; //register button combos +GameInfo* gGameInfo; +int D_8015FA94; //no known symbols +PrintTextBuffer D_8015FA98[0x16]; -extern char D_8011E148[]; +s16 D_8011E0B0 = 0; //PrintTextBuffer index +Color_RGBA8 printTextColors[] = { + { 0xFF, 0xFF, 0x20, 0xC0 }, + { 0xFF, 0x96, 0x80, 0xC0 }, + { 0x80, 0x60, 0x00, 0x40 }, + { 0xC0, 0x80, 0x10, 0x80 }, + { 0xFF, 0xC0, 0x20, 0x80 }, + { 0xE6, 0xE6, 0xDC, 0x40 }, + { 0x80, 0x96, 0xFF, 0x80 }, + { 0x80, 0xFF, 0x20, 0x80 }, +}; + +InputCombo inputCombos[REG_GROUP_TOTAL] = { + { BUTTON_L, BUTTON_C_UP }, + { BUTTON_L, BUTTON_C_LEFT }, + { BUTTON_L, BUTTON_C_DOWN }, + { BUTTON_L, BUTTON_A }, + { BUTTON_R, BUTTON_C_DOWN }, + { BUTTON_L, BUTTON_C_RIGHT }, + { BUTTON_L, BUTTON_R }, + { BUTTON_L, BUTTON_D_LEFT }, + { BUTTON_L, BUTTON_D_RIGHT }, + { BUTTON_L, BUTTON_D_UP }, + { BUTTON_L, BUTTON_B }, + { BUTTON_L, BUTTON_Z }, + { BUTTON_L, BUTTON_D_DOWN }, + { BUTTON_R, BUTTON_A }, + { BUTTON_R, BUTTON_B }, + { BUTTON_R, BUTTON_Z }, + { BUTTON_R, BUTTON_L }, + { BUTTON_R, BUTTON_C_UP }, + { BUTTON_R, BUTTON_C_RIGHT }, + { BUTTON_R, BUTTON_D_LEFT }, + { BUTTON_R, BUTTON_C_LEFT }, + { BUTTON_R, BUTTON_START }, + { BUTTON_L, BUTTON_START }, + { BUTTON_R, BUTTON_D_RIGHT }, + { BUTTON_R, BUTTON_D_UP }, + { BUTTON_START, BUTTON_R }, + { BUTTON_START, BUTTON_A }, + { BUTTON_START, BUTTON_B }, + { BUTTON_START, BUTTON_C_RIGHT }, +}; + +char regChar[] = " SOPQMYDUIZCNKXcsiWAVHGmnBdkb"; //initialize GameInfo void func_800636C0() @@ -65,14 +104,13 @@ void func_800636C0() } } -//Called when free movement is active +//Called when free movement is active. +//8011D394 to enable camera debugger void func_8006375C(s32 arg0, s32 arg1, float* d_80855320) { } -//8011D394 enable camera debugger - #ifdef NON_MATCHING //regalloc //Copy Camera Debugger Text void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) @@ -122,7 +160,7 @@ void func_80063828(GfxPrint* gfxPrint) buffer = &D_8015FA98[i]; text = buffer->text; - color = &D_8011E0B4[buffer->colorId]; + color = &printTextColors[buffer->colorId]; GfxPrint_SetColor(gfxPrint, color->r, color->g, color->b, color->a); GfxPrint_SetPos(gfxPrint, buffer->x, buffer->y); GfxPrint_Printf(gfxPrint, "%s", text); @@ -145,7 +183,7 @@ void func_8006390C(Input* input) { if (!~(input->raw.pad | ~BUTTON_L) || !~(input->raw.pad | ~BUTTON_R) || !~(input->raw.pad | ~BUTTON_START)) { - input_combo = D_8011E0D4; + input_combo = inputCombos; for (i = 0; i < REG_GROUP_TOTAL; i++) { if (~(~input_combo->push | input->raw.pad) || @@ -217,7 +255,6 @@ void func_8006390C(Input* input) { iREG(0) = 0; func_800AA000(0, iREG(1), iREG(2), iREG(3)); } - } } } @@ -236,7 +273,7 @@ void func_80063C04(GfxPrint* gfxPrint) //set up register name string reg_name[0] = 'R'; - reg_name[1] = D_8011E148[gGameInfo->reg_group]; //r_group type char + reg_name[1] = regChar[gGameInfo->reg_group]; //r_group type char reg_name[2] = '\0'; GfxPrint_SetColor(gfxPrint, 0, 0x80, 0x80, 0x80); @@ -262,7 +299,7 @@ void func_80063D7C(GraphicsContext* gfxCtx) { void* unk2[6]; GfxPrint gfxPrint; void* unk[2]; - Gfx* dl_frame[4];//stores state of GfxCtx next ptrs + Gfx* dl_frame[4]; //stores state of GfxCtx next ptrs func_800C6AC4(&dl_frame, gfxCtx, "../z_debug.c", 0x274); GfxPrint_Ctor(&gfxPrint); -- cgit v1.2.3 From a01f868a1a562f8d8c7aebdf8caff60eaccf9f1a Mon Sep 17 00:00:00 2001 From: wed <> Date: Fri, 20 Mar 2020 08:48:38 +1100 Subject: Finish z_lib.c --- src/code/z_lib.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'src/code') diff --git a/src/code/z_lib.c b/src/code/z_lib.c index 7b8bcbc2c..51867991a 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -1,20 +1,16 @@ #include #include -#ifdef NON_MATCHING -void Lib_MemSet(void* dest, size_t size, u8 val) +void Lib_MemSet(u8 dest[], size_t size, u8 val) { - u8* destu = dest; - u32 i; + size_t i = 0; - for (i = 0; i < size; i++) - { - *destu++ = val; - } + if (i == size) return; + do { + *dest++ = val; + i++; + } while (i != size); } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/z_lib/Lib_MemSet.s") -#endif f32 Math_Coss(s16 angle) { @@ -559,15 +555,12 @@ f32 func_800784D8(f32* pValue, f32 target, f32 scale, f32 maxStep, f32 minStep) return step; } -#ifdef NON_MATCHING -// regalloc differences s16 Math_SmoothScaleMaxMinS(s16* pValue, s16 target, s16 invScale, s16 maxStep, s16 minStep) { + s16 step = 0; s16 diff = (target - *pValue); - s32 baseStep; - s16 step; - baseStep = diff / invScale; + s32 baseStep = diff / invScale; if (*pValue != target) { @@ -604,9 +597,6 @@ s16 Math_SmoothScaleMaxMinS(s16* pValue, s16 target, s16 invScale, s16 maxStep, return diff; } -#else -#pragma GLOBAL_ASM("asm/non_matchings/code/z_lib/Math_SmoothScaleMaxMinS.s") -#endif void Math_SmoothScaleMaxS(s16* pValue, s16 target, s16 invScale, s16 maxStep) { -- cgit v1.2.3 From 8063249af48736010d909cefd33aa8f194c223ce Mon Sep 17 00:00:00 2001 From: mzxrules Date: Thu, 19 Mar 2020 18:06:41 -0400 Subject: changes --- src/code/z_debug.c | 198 ++++++++++++++++++++++++----------------------------- 1 file changed, 91 insertions(+), 107 deletions(-) (limited to 'src/code') diff --git a/src/code/z_debug.c b/src/code/z_debug.c index f0971cfbf..489636d41 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -3,24 +3,8 @@ #include #include #include +#include -#define BUTTON_C_RIGHT 0x0001 -#define BUTTON_C_LEFT 0x0002 -#define BUTTON_C_DOWN 0x0004 -#define BUTTON_C_UP 0x0008 -#define BUTTON_R 0x0010 -#define BUTTON_L 0x0020 -#define BUTTON_D_RIGHT 0x0100 -#define BUTTON_D_LEFT 0x0200 -#define BUTTON_D_DOWN 0x0400 -#define BUTTON_D_UP 0x0800 -#define BUTTON_START 0x1000 -#define BUTTON_Z 0x2000 -#define BUTTON_B 0x4000 -#define BUTTON_A 0x8000 - -#define REG_GROUP_TOTAL 29 -#define REG_N 96 #define PAGE_N 16 typedef struct @@ -53,36 +37,36 @@ Color_RGBA8 printTextColors[] = { { 0x80, 0xFF, 0x20, 0x80 }, }; -InputCombo inputCombos[REG_GROUP_TOTAL] = { - { BUTTON_L, BUTTON_C_UP }, - { BUTTON_L, BUTTON_C_LEFT }, - { BUTTON_L, BUTTON_C_DOWN }, - { BUTTON_L, BUTTON_A }, - { BUTTON_R, BUTTON_C_DOWN }, - { BUTTON_L, BUTTON_C_RIGHT }, - { BUTTON_L, BUTTON_R }, - { BUTTON_L, BUTTON_D_LEFT }, - { BUTTON_L, BUTTON_D_RIGHT }, - { BUTTON_L, BUTTON_D_UP }, - { BUTTON_L, BUTTON_B }, - { BUTTON_L, BUTTON_Z }, - { BUTTON_L, BUTTON_D_DOWN }, - { BUTTON_R, BUTTON_A }, - { BUTTON_R, BUTTON_B }, - { BUTTON_R, BUTTON_Z }, - { BUTTON_R, BUTTON_L }, - { BUTTON_R, BUTTON_C_UP }, - { BUTTON_R, BUTTON_C_RIGHT }, - { BUTTON_R, BUTTON_D_LEFT }, - { BUTTON_R, BUTTON_C_LEFT }, - { BUTTON_R, BUTTON_START }, - { BUTTON_L, BUTTON_START }, - { BUTTON_R, BUTTON_D_RIGHT }, - { BUTTON_R, BUTTON_D_UP }, - { BUTTON_START, BUTTON_R }, - { BUTTON_START, BUTTON_A }, - { BUTTON_START, BUTTON_B }, - { BUTTON_START, BUTTON_C_RIGHT }, +InputCombo inputCombos[REG_GROUPS] = { + { L_TRIG, U_CBUTTONS }, + { L_TRIG, L_CBUTTONS }, + { L_TRIG, D_CBUTTONS }, + { L_TRIG, A_BUTTON }, + { R_TRIG, D_CBUTTONS }, + { L_TRIG, R_CBUTTONS }, + { L_TRIG, R_TRIG }, + { L_TRIG, L_JPAD }, + { L_TRIG, R_JPAD }, + { L_TRIG, U_JPAD }, + { L_TRIG, B_BUTTON }, + { L_TRIG, Z_TRIG }, + { L_TRIG, D_JPAD }, + { R_TRIG, A_BUTTON }, + { R_TRIG, B_BUTTON }, + { R_TRIG, Z_TRIG }, + { R_TRIG, L_TRIG }, + { R_TRIG, U_CBUTTONS }, + { R_TRIG, R_CBUTTONS }, + { R_TRIG, L_JPAD }, + { R_TRIG, L_CBUTTONS }, + { R_TRIG, START_BUTTON }, + { L_TRIG, START_BUTTON }, + { R_TRIG, R_JPAD }, + { R_TRIG, U_JPAD }, + { START_BUTTON, R_TRIG }, + { START_BUTTON, A_BUTTON }, + { START_BUTTON, B_BUTTON }, + { START_BUTTON, R_CBUTTONS }, }; char regChar[] = " SOPQMYDUIZCNKXcsiWAVHGmnBdkb"; @@ -92,13 +76,13 @@ void func_800636C0() { s32 i; - gGameInfo = (GameInfo*)SystemArena_MallocDebug(sizeof(GameInfo), "../z_debug.c", 0x104); - gGameInfo->reg_page = 0; - gGameInfo->reg_group = 0; - gGameInfo->reg_cur = 0; - gGameInfo->dpad_last = 0; + gGameInfo = (GameInfo*)SystemArena_MallocDebug(sizeof(GameInfo), "../z_debug.c", 260); + gGameInfo->regPage = 0; + gGameInfo->regGroup = 0; + gGameInfo->regCur = 0; + gGameInfo->dpadLast = 0; gGameInfo->repeat = 0; - for (i = 0; i < 0xAE0; i++) + for (i = 0; i < ARRAY_COUNT(gGameInfo->data); i++) { gGameInfo->data[i] = 0; } @@ -116,7 +100,7 @@ void func_8006375C(s32 arg0, s32 arg1, float* d_80855320) void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) { PrintTextBuffer* buf; - char* next_text; + char* bufText; s16 i; //v1 buf = &D_8015FA98[D_8011E0B0]; @@ -127,15 +111,15 @@ void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) buf->colorId = colorId; i = 0; - next_text = buf->text + 1; + bufText = buf->text + 1; if (*buf->text = *text++) { do if (i++ > 0x14) { break; - } while (*next_text++ = *text++); + } while (*bufText++ = *text++); } - *next_text = '\0'; + *bufText = '\0'; D_8011E0B0++; } } @@ -173,18 +157,18 @@ void func_80063828(GfxPrint* gfxPrint) void func_8006390C(Input* input) { s32 dpad; - s32 reg_group; + s32 regGroup; s32 increment; InputCombo* input_combo; s32 i; - reg_group = (gGameInfo->reg_group * (REG_N / PAGE_N) + gGameInfo->reg_page) * PAGE_N - PAGE_N; + regGroup = (gGameInfo->regGroup * (REG_PER_GROUP / PAGE_N) + gGameInfo->regPage) * PAGE_N - PAGE_N; dpad = input->raw.pad & 0xF00; - if (!~(input->raw.pad | ~BUTTON_L) || - !~(input->raw.pad | ~BUTTON_R) || - !~(input->raw.pad | ~BUTTON_START)) { + if (!~(input->raw.pad | ~L_TRIG) || + !~(input->raw.pad | ~R_TRIG) || + !~(input->raw.pad | ~START_BUTTON)) { input_combo = inputCombos; - for (i = 0; i < REG_GROUP_TOTAL; i++) + for (i = 0; i < REG_GROUPS; i++) { if (~(~input_combo->push | input->raw.pad) || ~(~input_combo->held | input->padPressed)) { @@ -194,17 +178,17 @@ void func_8006390C(Input* input) { break; } - if (i < REG_GROUP_TOTAL) { - if (i == gGameInfo->reg_group) { - gGameInfo->reg_page = (gGameInfo->reg_page + 1) % 7; + if (i < REG_GROUPS) { + if (i == gGameInfo->regGroup) { + gGameInfo->regPage = (gGameInfo->regPage + 1) % 7; return; } - gGameInfo->reg_group = i; - gGameInfo->reg_page = 0; + gGameInfo->regGroup = i; + gGameInfo->regPage = 0; } } else { - switch (gGameInfo->reg_page - 1) + switch (gGameInfo->regPage - 1) { case 0: case 1: @@ -213,42 +197,42 @@ void func_8006390C(Input* input) { case 4: case 5: - if (dpad == gGameInfo->dpad_last) { + if (dpad == gGameInfo->dpadLast) { gGameInfo->repeat--; if (gGameInfo->repeat < 0) { gGameInfo->repeat = 1; } else { - dpad ^= gGameInfo->dpad_last; + dpad ^= gGameInfo->dpadLast; } } else { gGameInfo->repeat = 0x10; - gGameInfo->dpad_last = dpad; + gGameInfo->dpadLast = dpad; } increment = - (dpad & BUTTON_D_RIGHT) ? ( - !~(input->raw.pad | ~(BUTTON_A | BUTTON_B)) ? 1000 : - !~(input->raw.pad | ~BUTTON_A) ? 100 : - !~(input->raw.pad | ~BUTTON_B) ? 10 : 1) : - (dpad & BUTTON_D_LEFT) ? ( - !~(input->raw.pad | ~(BUTTON_A | BUTTON_B)) ? -1000 : - !~(input->raw.pad | ~BUTTON_A) ? -100 : - !~(input->raw.pad | ~BUTTON_B) ? -10 : -1) : + (dpad & R_JPAD) ? ( + !~(input->raw.pad | ~(A_BUTTON | B_BUTTON)) ? 1000 : + !~(input->raw.pad | ~A_BUTTON) ? 100 : + !~(input->raw.pad | ~B_BUTTON) ? 10 : 1) : + (dpad & L_JPAD) ? ( + !~(input->raw.pad | ~(A_BUTTON | B_BUTTON)) ? -1000 : + !~(input->raw.pad | ~A_BUTTON) ? -100 : + !~(input->raw.pad | ~B_BUTTON) ? -10 : -1) : 0; - gGameInfo->data[gGameInfo->reg_cur + reg_group] += increment; - if (dpad & BUTTON_D_UP) { - gGameInfo->reg_cur--; - if (gGameInfo->reg_cur < 0) { - gGameInfo->reg_cur = PAGE_N - 1; + gGameInfo->data[gGameInfo->regCur + regGroup] += increment; + if (dpad & U_JPAD) { + gGameInfo->regCur--; + if (gGameInfo->regCur < 0) { + gGameInfo->regCur = PAGE_N - 1; } } - else if (dpad & BUTTON_D_DOWN) { - gGameInfo->reg_cur++; - if (gGameInfo->reg_cur >= PAGE_N) { - gGameInfo->reg_cur = 0; + else if (dpad & D_JPAD) { + gGameInfo->regCur++; + if (gGameInfo->regCur >= PAGE_N) { + gGameInfo->regCur = 0; } } if (iREG(0)) { @@ -264,28 +248,28 @@ void func_80063C04(GfxPrint* gfxPrint) { s32 i; s32 page; - s32 reg_group; + s32 regGroup; s32 test; //removing affects stack - char reg_name[3]; + char name[3]; - page = (gGameInfo->reg_page * PAGE_N) - PAGE_N; - reg_group = (gGameInfo->reg_group * (REG_N / PAGE_N) + gGameInfo->reg_page) * PAGE_N - PAGE_N; + page = (gGameInfo->regPage * PAGE_N) - PAGE_N; + regGroup = (gGameInfo->regGroup * (REG_PER_GROUP / PAGE_N) + gGameInfo->regPage) * PAGE_N - PAGE_N; //set up register name string - reg_name[0] = 'R'; - reg_name[1] = regChar[gGameInfo->reg_group]; //r_group type char - reg_name[2] = '\0'; + name[0] = 'R'; + name[1] = regChar[gGameInfo->regGroup]; //r_group type char + name[2] = '\0'; GfxPrint_SetColor(gfxPrint, 0, 0x80, 0x80, 0x80); for (i = 0; i != PAGE_N; i++) { - if (i == gGameInfo->reg_cur) + if (i == gGameInfo->regCur) { GfxPrint_SetColor(gfxPrint, 0, 0xff, 0xff, 0xff); } GfxPrint_SetPos(gfxPrint, 3, i + 5); - GfxPrint_Printf(gfxPrint, "%s%02d%6d", ®_name, page + i, gGameInfo->data[i + reg_group]); - if (i == gGameInfo->reg_cur) + GfxPrint_Printf(gfxPrint, "%s%02d%6d", &name, page + i, gGameInfo->data[i + regGroup]); + if (i == gGameInfo->regCur) { GfxPrint_SetColor(gfxPrint, 0, 0x80, 0x80, 0x80); } @@ -295,24 +279,24 @@ void func_80063C04(GfxPrint* gfxPrint) void func_80063D7C(GraphicsContext* gfxCtx) { Gfx* sp7C; Gfx* sp78; - Gfx* temp_ret; + Gfx* tempRet; void* unk2[6]; GfxPrint gfxPrint; void* unk[2]; - Gfx* dl_frame[4]; //stores state of GfxCtx next ptrs + Gfx* dlFrame[4]; //stores state of GfxCtx next ptrs - func_800C6AC4(&dl_frame, gfxCtx, "../z_debug.c", 0x274); + func_800C6AC4(&dlFrame, gfxCtx, "../z_debug.c", 628); GfxPrint_Ctor(&gfxPrint); sp78 = gfxCtx->polyOpa.p; - temp_ret = func_800C6C20(gfxCtx->polyOpa.p); - gSPDisplayList(gfxCtx->overlay.p++, temp_ret); - GfxPrint_Open(&gfxPrint, temp_ret); + tempRet = func_800C6C20(gfxCtx->polyOpa.p); + gSPDisplayList(gfxCtx->overlay.p++, tempRet); + GfxPrint_Open(&gfxPrint, tempRet); if ((OREG(0) == 1) || (OREG(0) == 8)) { func_80063828(&gfxPrint); } - if (gGameInfo->reg_page != 0) { + if (gGameInfo->regPage != 0) { func_80063C04(&gfxPrint); } @@ -322,6 +306,6 @@ void func_80063D7C(GraphicsContext* gfxCtx) { func_800C6C28(sp78, sp7C); gfxCtx->polyOpa.p = sp7C; if (0); - func_800C6B54(&dl_frame, gfxCtx, "../z_debug.c", 0x298); + func_800C6B54(&dlFrame, gfxCtx, "../z_debug.c", 664); GfxPrint_Dtor(&gfxPrint); } -- cgit v1.2.3 From c931cd58376a6a9bda2290063974d2cfb371685b Mon Sep 17 00:00:00 2001 From: Random <28494085+Random0666@users.noreply.github.com> Date: Thu, 19 Mar 2020 23:29:33 +0100 Subject: Decompiled z_title.c `z_title.c` : matching --- src/code/title_setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/code') diff --git a/src/code/title_setup.c b/src/code/title_setup.c index 22ee8b181..d7ac9cc87 100644 --- a/src/code/title_setup.c +++ b/src/code/title_setup.c @@ -6,7 +6,7 @@ void TitleSetup_InitImpl(GameState* gameState) osSyncPrintf("ゼルダ共通データ初期化\n"); SaveContext_Init(); gameState->running = false; - gameState->init = func_80800878; gameState->size = sizeof(TitleContext); + gameState->init = Title_Init; gameState->size = sizeof(TitleContext); } void TitleSetup_Destroy(GameState* gameState) -- cgit v1.2.3 From 858e937519558f1de85baecb8630fa60b9cd9387 Mon Sep 17 00:00:00 2001 From: mzxrules Date: Thu, 19 Mar 2020 20:10:32 -0400 Subject: tweak defines --- src/code/z_debug.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/code') diff --git a/src/code/z_debug.c b/src/code/z_debug.c index 489636d41..451443a6b 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -5,8 +5,6 @@ #include #include -#define PAGE_N 16 - typedef struct { u8 x; @@ -162,7 +160,7 @@ void func_8006390C(Input* input) { InputCombo* input_combo; s32 i; - regGroup = (gGameInfo->regGroup * (REG_PER_GROUP / PAGE_N) + gGameInfo->regPage) * PAGE_N - PAGE_N; + regGroup = (gGameInfo->regGroup * REG_PAGES + gGameInfo->regPage) * REG_PER_PAGE - REG_PER_PAGE; dpad = input->raw.pad & 0xF00; if (!~(input->raw.pad | ~L_TRIG) || !~(input->raw.pad | ~R_TRIG) || @@ -180,7 +178,7 @@ void func_8006390C(Input* input) { if (i < REG_GROUPS) { if (i == gGameInfo->regGroup) { - gGameInfo->regPage = (gGameInfo->regPage + 1) % 7; + gGameInfo->regPage = (gGameInfo->regPage + 1) % (REG_PAGES + 1); return; } gGameInfo->regGroup = i; @@ -190,12 +188,12 @@ void func_8006390C(Input* input) { else { switch (gGameInfo->regPage - 1) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: if (dpad == gGameInfo->dpadLast) { gGameInfo->repeat--; @@ -226,12 +224,12 @@ void func_8006390C(Input* input) { if (dpad & U_JPAD) { gGameInfo->regCur--; if (gGameInfo->regCur < 0) { - gGameInfo->regCur = PAGE_N - 1; + gGameInfo->regCur = REG_PER_PAGE - 1; } } else if (dpad & D_JPAD) { gGameInfo->regCur++; - if (gGameInfo->regCur >= PAGE_N) { + if (gGameInfo->regCur >= REG_PER_PAGE) { gGameInfo->regCur = 0; } } @@ -252,8 +250,8 @@ void func_80063C04(GfxPrint* gfxPrint) s32 test; //removing affects stack char name[3]; - page = (gGameInfo->regPage * PAGE_N) - PAGE_N; - regGroup = (gGameInfo->regGroup * (REG_PER_GROUP / PAGE_N) + gGameInfo->regPage) * PAGE_N - PAGE_N; + 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'; @@ -261,7 +259,7 @@ void func_80063C04(GfxPrint* gfxPrint) name[2] = '\0'; GfxPrint_SetColor(gfxPrint, 0, 0x80, 0x80, 0x80); - for (i = 0; i != PAGE_N; i++) + for (i = 0; i != REG_PER_PAGE; i++) { if (i == gGameInfo->regCur) { -- cgit v1.2.3 From 8a7468689046bd6ab3be6f8d47703559c90434de Mon Sep 17 00:00:00 2001 From: wed <> Date: Fri, 20 Mar 2020 11:25:53 +1100 Subject: Changes --- src/code/z_lib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/code') diff --git a/src/code/z_lib.c b/src/code/z_lib.c index 51867991a..a7411c53d 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -1,10 +1,11 @@ #include #include -void Lib_MemSet(u8 dest[], size_t size, u8 val) +void Lib_MemSet(u8* dest, size_t size, u8 val) { - size_t i = 0; + u32 i = 0; + // TODO: Convert this to while/for if possible if (i == size) return; do { *dest++ = val; -- cgit v1.2.3