diff --git a/asm/non_matchings/overlays/actors/ovl_En_Test/func_8085F938.s b/asm/non_matchings/overlays/actors/ovl_En_Test/func_8085F938.s index db4a77fdbd..483b15b024 100644 --- a/asm/non_matchings/overlays/actors/ovl_En_Test/func_8085F938.s +++ b/asm/non_matchings/overlays/actors/ovl_En_Test/func_8085F938.s @@ -26,11 +26,11 @@ glabel func_8085F938 /* 00308 8085F958 3C014F00 */ lui $at, 0x4F00 ## $at = 4F000000 /* 0030C 8085F95C 46040182 */ mul.s $f6, $f0, $f4 /* 00310 8085F960 8FA60018 */ lw $a2, 0x0018($sp) -/* 00314 8085F964 444EF800 */ cfc1 $t6, $f31 -/* 00318 8085F968 44CFF800 */ ctc1 $t7, $f31 +/* 00314 8085F964 444EF800 */ cfc1 $t6, $31 +/* 00318 8085F968 44CFF800 */ ctc1 $t7, $31 /* 0031C 8085F96C 00000000 */ nop /* 00320 8085F970 46003224 */ cvt.w.s $f8, $f6 -/* 00324 8085F974 444FF800 */ cfc1 $t7, $f31 +/* 00324 8085F974 444FF800 */ cfc1 $t7, $31 /* 00328 8085F978 00000000 */ nop /* 0032C 8085F97C 31EF0078 */ andi $t7, $t7, 0x0078 ## $t7 = 00000000 /* 00330 8085F980 51E00013 */ beql $t7, $zero, .L8085F9D0 @@ -38,10 +38,10 @@ glabel func_8085F938 /* 00338 8085F988 44814000 */ mtc1 $at, $f8 ## $f8 = 2147483648.00 /* 0033C 8085F98C 240F0001 */ addiu $t7, $zero, 0x0001 ## $t7 = 00000001 /* 00340 8085F990 46083201 */ sub.s $f8, $f6, $f8 -/* 00344 8085F994 44CFF800 */ ctc1 $t7, $f31 +/* 00344 8085F994 44CFF800 */ ctc1 $t7, $31 /* 00348 8085F998 00000000 */ nop /* 0034C 8085F99C 46004224 */ cvt.w.s $f8, $f8 -/* 00350 8085F9A0 444FF800 */ cfc1 $t7, $f31 +/* 00350 8085F9A0 444FF800 */ cfc1 $t7, $31 /* 00354 8085F9A4 00000000 */ nop /* 00358 8085F9A8 31EF0078 */ andi $t7, $t7, 0x0078 ## $t7 = 00000000 /* 0035C 8085F9AC 15E00005 */ bne $t7, $zero, .L8085F9C4 @@ -59,7 +59,7 @@ glabel func_8085F938 /* 00384 8085F9D4 05E0FFFB */ bltz $t7, .L8085F9C4 /* 00388 8085F9D8 00000000 */ nop .L8085F9DC: -/* 0038C 8085F9DC 44CEF800 */ ctc1 $t6, $f31 +/* 0038C 8085F9DC 44CEF800 */ ctc1 $t6, $31 /* 00390 8085F9E0 2DE1000B */ sltiu $at, $t7, 0x000B /* 00394 8085F9E4 1020002E */ beq $at, $zero, .L8085FAA0 /* 00398 8085F9E8 000F7880 */ sll $t7, $t7, 2 diff --git a/asm/non_matchings/overlays/actors/ovl_En_Test/func_8085FAB0.s b/asm/non_matchings/overlays/actors/ovl_En_Test/func_8085FAB0.s index 92f6d40799..f04bdda35b 100644 --- a/asm/non_matchings/overlays/actors/ovl_En_Test/func_8085FAB0.s +++ b/asm/non_matchings/overlays/actors/ovl_En_Test/func_8085FAB0.s @@ -46,11 +46,11 @@ glabel func_8085FAB0 /* 004C4 8085FB14 46040182 */ mul.s $f6, $f0, $f4 /* 004C8 8085FB18 8FA60020 */ lw $a2, 0x0020($sp) /* 004CC 8085FB1C 8FA70024 */ lw $a3, 0x0024($sp) -/* 004D0 8085FB20 444FF800 */ cfc1 $t7, $f31 -/* 004D4 8085FB24 44D8F800 */ ctc1 $t8, $f31 +/* 004D0 8085FB20 444FF800 */ cfc1 $t7, $31 +/* 004D4 8085FB24 44D8F800 */ ctc1 $t8, $31 /* 004D8 8085FB28 00000000 */ nop /* 004DC 8085FB2C 46003224 */ cvt.w.s $f8, $f6 -/* 004E0 8085FB30 4458F800 */ cfc1 $t8, $f31 +/* 004E0 8085FB30 4458F800 */ cfc1 $t8, $31 /* 004E4 8085FB34 00000000 */ nop /* 004E8 8085FB38 33180078 */ andi $t8, $t8, 0x0078 ## $t8 = 00000000 /* 004EC 8085FB3C 53000013 */ beql $t8, $zero, .L8085FB8C @@ -58,10 +58,10 @@ glabel func_8085FAB0 /* 004F4 8085FB44 44814000 */ mtc1 $at, $f8 ## $f8 = 2147483648.00 /* 004F8 8085FB48 24180001 */ addiu $t8, $zero, 0x0001 ## $t8 = 00000001 /* 004FC 8085FB4C 46083201 */ sub.s $f8, $f6, $f8 -/* 00500 8085FB50 44D8F800 */ ctc1 $t8, $f31 +/* 00500 8085FB50 44D8F800 */ ctc1 $t8, $31 /* 00504 8085FB54 00000000 */ nop /* 00508 8085FB58 46004224 */ cvt.w.s $f8, $f8 -/* 0050C 8085FB5C 4458F800 */ cfc1 $t8, $f31 +/* 0050C 8085FB5C 4458F800 */ cfc1 $t8, $31 /* 00510 8085FB60 00000000 */ nop /* 00514 8085FB64 33180078 */ andi $t8, $t8, 0x0078 ## $t8 = 00000000 /* 00518 8085FB68 17000005 */ bne $t8, $zero, .L8085FB80 @@ -79,7 +79,7 @@ glabel func_8085FAB0 /* 00540 8085FB90 0700FFFB */ bltz $t8, .L8085FB80 /* 00544 8085FB94 00000000 */ nop .L8085FB98: -/* 00548 8085FB98 44CFF800 */ ctc1 $t7, $f31 +/* 00548 8085FB98 44CFF800 */ ctc1 $t7, $31 /* 0054C 8085FB9C 2F01000A */ sltiu $at, $t8, 0x000A /* 00550 8085FBA0 10200087 */ beq $at, $zero, .L8085FDC0 /* 00554 8085FBA4 0018C080 */ sll $t8, $t8, 2 diff --git a/include/functions.h b/include/functions.h index 703bf36417..f44cc19167 100644 --- a/include/functions.h +++ b/include/functions.h @@ -12,10 +12,10 @@ f64 sqrt(f64 d); void cleararena(void); void bootproc(void); -void Main_ThreadEntry(void* arg0); -void Idle_ThreadEntry(void* a0); -void ViConfig_UpdateVi(u32 arg0); -void ViConfig_UpdateBlack(); +void Main_ThreadEntry(void* arg); +void Idle_ThreadEntry(void* arg); +void ViConfig_UpdateVi(u32 mode); +void ViConfig_UpdateBlack(void); s32 DmaMgr_CompareName(const char* name1, const char* name2); s32 DmaMgr_DMARomToRam(u32 rom, u32 ram, u32 size); s32 DmaMgr_DmaCallback0(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction); @@ -27,47 +27,47 @@ void DmaMgr_ProcessMsg(DmaRequest* req); void DmaMgr_ThreadEntry(void* arg0); s32 DmaMgr_SendRequestImpl(DmaRequest* req, u32 ram, u32 vrom, u32 size, u32 unk, OSMesgQueue* queue, OSMesg msg); s32 DmaMgr_SendRequest0(u32 ram, u32 vrom, u32 size); -void DmaMgr_Init(); +void DmaMgr_Init(void); s32 DmaMgr_SendRequest2(DmaRequest* req, u32 ram, u32 vrom, u32 size, u32 unk5, OSMesgQueue* queue, OSMesg msg, const char* file, s32 line); s32 DmaMgr_SendRequest1(void* ram0, u32 vrom, u32 size, const char* file, s32 line); -void* Yaz0_FirstDMA(); +void* Yaz0_FirstDMA(void); void* Yaz0_NextDMA(void* curSrcPos); void Yaz0_DecompressImpl(Yaz0Header* hdr, u8* dst); void Yaz0_Decompress(u32 romStart, void* dst, u32 size); -void Locale_Init(); -void Locale_ResetRegion(); -u32 func_80001F48(); -u32 func_80001F8C(); -u32 Locale_IsRegionNative(); +void Locale_Init(void); +void Locale_ResetRegion(void); +u32 func_80001F48(void); +u32 func_80001F8C(void); +u32 Locale_IsRegionNative(void); void __assert(const char* exp, const char* file, s32 line); -void isPrintfInit(); +void isPrintfInit(void); void osSyncPrintfUnused(const char* fmt, ...); void osSyncPrintf(const char* fmt, ...); void rmonPrintf(const char* fmt, ...); -u32 is_proutSyncPrintf(void* arg0, const char* str, s32 count); +void* is_proutSyncPrintf(void* arg, const char* str, u32 count); void func_80002384(const char* exp, const char* file, u32 line); -OSPiHandle* osDriveRomInit(); +OSPiHandle* osDriveRomInit(void); void Mio0_Decompress(Yaz0Header* hdr, u8* dst); void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 initValue, s32 minSpace, const char* name); void StackCheck_Cleanup(StackEntry* entry); StackStatus StackCheck_GetState(StackEntry* entry); -u32 StackCheck_CheckAll(); +u32 StackCheck_CheckAll(void); u32 StackCheck_Check(StackEntry* entry); -f32 LogUtils_CheckFloatRange(const char* exp, s32 arg1, const char* var1Name, f32 var1, const char* var2Name, f32 var2, - const char* var3Name, f32 var3); -s32 LogUtils_CheckIntRange(const char* exp, s32 arg1, const char* var1Name, s32 var1, const char* var2Name, s32 var2, - const char* var3Name, s32 var3); +f32 LogUtils_CheckFloatRange(const char* exp, s32 line, const char* valueName, f32 value, const char* minName, f32 min, + const char* maxName, f32 max); +s32 LogUtils_CheckIntRange(const char* exp, s32 line, const char* valueName, s32 value, const char* minName, s32 min, + const char* maxName, s32 max); void LogUtils_LogHexDump(void* ptr, s32 size0); void LogUtils_LogPointer(s32 value, u32 max, void* ptr, const char* name, const char* file, s32 line); void LogUtils_CheckBoundary(const char* name, s32 value, s32 unk, const char* file, s32 line); void LogUtils_CheckNullPointer(const char* exp, void* ptr, const char* file, s32 line); -void LogUtils_CheckValidPointer(const char* exp, void* ptr0, const char* file, s32 line); +void LogUtils_CheckValidPointer(const char* exp, void* ptr, const char* file, s32 line); void LogUtils_LogThreadId(const char* name, s32 line); void LogUtils_HungupThread(const char* name, s32 line); -void LogUtils_ResetHungup(); -char* proutSprintf(char* dst, const char* fmt, size_t size); +void LogUtils_ResetHungup(void); +void* proutSprintf(void* dst, const char* fmt, u32 size); s32 vsprintf(char* dst, const char* fmt, va_list args); s32 sprintf(char* dst, const char* fmt, ...); void __osPiCreateAccessQueue(void); @@ -79,7 +79,7 @@ void osViExtendVStart(u32 arg0); s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flag); void __createSpeedParam(void); void __osInitialize_common(void); -void __osInitialize_autodetect(); +void __osInitialize_autodetect(void); void __osExceptionPreamble(); // ? __osException(?); void __osEnqueueAndYield(OSThread**); @@ -95,7 +95,7 @@ void osCreateThread(OSThread* thread, OSId id, void (*entry)(void*), void* arg, void __osSetSR(u32); u32 __osGetSR(); void osWritebackDCache(void* vaddr, s32 nbytes); -void* osViGetNextFramebuffer(); +void* osViGetNextFramebuffer(void); void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt); void __osDevMgrMain(void* arg); s32 __osPiRawStartDma(s32 dir, u32 cartAddr, void* dramAddr, size_t size); @@ -108,16 +108,16 @@ void osViSetMode(OSViMode* mode); u32 __osProbeTLB(void*); u32 osGetMemSize(void); void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg msg); -s32 _Printf(char* (*pfn)(char*, const char*, size_t), char* arg, const char* fmt, va_list ap); +s32 _Printf(PrintCallback, void* arg, const char* fmt, va_list ap); void osUnmapTLBAll(void); s32 osEPiStartDma(OSPiHandle* handle, OSIoMesg* mb, s32 direction); -const u8* strchr(const u8* str, s32 ch); -size_t strlen(const u8* str); -void* memcpy(void* dst, const void* src, size_t size); +const char* strchr(const char* str, s32 ch); +u32 strlen(const char* str); +void* memcpy(void* dst, const void* src, u32 size); void osInvalICache(void* vaddr, s32 nbytes); void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 count); void osInvalDCache(void* vaddr, s32 nbytes); -s32 __osSiDeviceBusy(); +s32 __osSiDeviceBusy(void); s32 osJamMesg(OSMesgQueue* mq, OSMesg mesg, s32 flag); void osSetThreadPri(OSThread* thread, OSPri pri); OSPri osGetThreadPri(OSThread* thread); @@ -126,10 +126,10 @@ void osViSwapBuffer(void* vaddr); s32 __osEPiRawStartDma(OSPiHandle* handle, s32 direction, u32 cartAddr, void* dramAddr, size_t size); u32 bcmp(void* __sl, void* __s2, u32 __n); OSTime osGetTime(void); -void __osTimerServicesInit(); -void __osTimerInterrupt(); -void __osSetTimerIntr(OSTime tim); -OSTime __osInsertTimer(OSTimer* a0); +void __osTimerServicesInit(void); +void __osTimerInterrupt(void); +void __osSetTimerIntr(OSTime time); +OSTime __osInsertTimer(OSTimer* timer); u32 osGetCount(void); void __osSetGlobalIntMask(u32 mask); void __osSetCompare(u32); @@ -137,17 +137,17 @@ void* bcopy(void* __src, void* __dest, u32 __n); void __osResetGlobalIntMask(u32 mask); s32 __osDisableInt(void); void __osRestoreInt(s32); -void __osViInit(); -void __osViSwapContext(); -OSMesgQueue* osPiGetCmdQueue(); +void __osViInit(void); +void __osViSwapContext(void); +OSMesgQueue* osPiGetCmdQueue(void); s32 osEPiReadIo(OSPiHandle* handle, u32 devAddr, u32* data); void osViSetSpecialFeatures(u32 func); -OSPiHandle* osCartRomInit(); +OSPiHandle* osCartRomInit(void); void __osSetFpcCsr(u32); u32 __osGetFpcCsr(); s32 osEPiWriteIo(OSPiHandle* handle, u32 devAddr, u32 data); void osMapTLBRdb(void); -void osYieldThread(); +void osYieldThread(void); u32 __osGetCause(); s32 __osEPiRawWriteIo(OSPiHandle* handle, u32 devAddr, u32 data); void _Litob(_Pft* args, u8 type); @@ -157,7 +157,7 @@ void _Ldtob(_Pft* args, u8 type); s32 __osSiRawWriteIo(void* a0, u32 a1); void osCreateViManager(OSPri pri); void viMgrMain(void* vargs); -OSViContext* __osViGetCurrentContext(); +OSViContext* __osViGetCurrentContext(void); void osStartThread(OSThread* thread); void osViSetYScale(f32 scale); void osViSetXScale(f32 value); @@ -354,6 +354,7 @@ void ActorShadow_DrawHorse(Actor* actor, Lights* lights, GlobalContext* globalCt void ActorShadow_DrawFeet(Actor* actor, Lights* lights, GlobalContext* globalCtx); void Actor_SetFeetPos(Actor* actor, s32 limbIndex, s32 leftFootIndex, Vec3f* leftFootPos, s32 rightFootIndex, Vec3f* rightFootPos); +void func_8002BE04(GlobalContext* globalCtx, Vec3f* arg1, Vec3f* arg2, f32* arg3); void func_8002C124(TargetContext* targetCtx, GlobalContext* globalCtx); s32 Flags_GetSwitch(GlobalContext* globalCtx, s32 flag); void Flags_SetSwitch(GlobalContext* globalCtx, s32 flag); @@ -460,6 +461,8 @@ void func_800304B0(GlobalContext* globalCtx); void func_800304DC(GlobalContext* globalCtx, ActorContext* actorCtx, ActorEntry* actorEntry); void Actor_UpdateAll(GlobalContext* globalCtx, ActorContext* actorCtx); s32 func_800314D4(GlobalContext* globalCtx, Actor* actorB, Vec3f* arg2, f32 arg3); +void func_800315AC(GlobalContext* globalCtx, ActorContext* actorCtx); +void func_80031A28(GlobalContext* globalCtx, ActorContext* actorCtx); void func_80031B14(GlobalContext* globalCtx, ActorContext* actorCtx); void func_80031C3C(ActorContext* actorCtx, GlobalContext* globalCtx); Actor* Actor_Spawn(ActorContext* actorCtx, GlobalContext* globalCtx, s16 actorId, f32 posX, f32 posY, f32 posZ, @@ -664,7 +667,7 @@ void func_8003EBF8(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgI void func_8003EC50(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); void func_8003ECA8(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); s32 DynaPoly_SetBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, Actor* actor, CollisionHeader* colHeader); -Actor* DynaPoly_GetActor(CollisionContext* colCtx, s32 bgId); +DynaPolyActor* DynaPoly_GetActor(CollisionContext* colCtx, s32 bgId); void DynaPoly_DeleteBgActor(GlobalContext* globalCtx, DynaCollisionContext* dyna, s32 bgId); // ? DynaPoly_ExpandSRT(?); void func_8003F8EC(GlobalContext* globalCtx, DynaCollisionContext* dyna, Actor* actor); @@ -751,7 +754,7 @@ s32 func_80043548(DynaPolyActor* dynaActor); s32 func_8004356C(DynaPolyActor* dynaActor); s32 func_80043590(DynaPolyActor* dynaActor); s32 func_800435B4(DynaPolyActor* dynaActor); -s32 func_800435D8(GlobalContext* globalCtx, DynaPolyActor* dyna, s16 arg2, s16 arg3, s16 arg4); +s32 func_800435D8(GlobalContext* globalCtx, DynaPolyActor* dynaActor, s16 arg2, s16 arg3, s16 arg4); void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, GlobalContext* globalCtx); void Camera_InitPlayerSettings(Camera* camera, Player* player); s16 Camera_ChangeStatus(Camera* camera, s16 status); @@ -872,7 +875,7 @@ s32 CollisionCheck_CylSideVsLineSeg(f32 radius, f32 height, f32 offset, Vec3f* a Vec3f* itemProjPos, Vec3f* out1, Vec3f* out2); u8 CollisionCheck_GetSwordDamage(s32 dmgFlags); void SaveContext_Init(void); -// ? func_800636C0(?); +void func_800636C0(void); void func_8006375C(s32 arg0, s32 arg1, const char* text); void func_8006376C(u8 x, u8 y, u8 colorId, const char* text); // ? func_8006376C(?); @@ -940,37 +943,38 @@ u8 func_8006F140(GlobalContext*, EnvironmentContext*, UNK_TYPE); f32 func_8006F93C(u16, u16, u16); f32 func_8006F9BC(u16 endFrame, u16 startFrame, u16 frames, u16, u16); // ? func_8006FB94(?); -// ? func_8006FC88(?); +void func_8006FC88(s16 skyboxId, EnvironmentContext* envCtx, SkyboxContext* skyboxCtx); void func_80070600(GlobalContext* globalCtx, s32 waterboxProperties); void func_800706A0(GlobalContext* globalCtx); // ? func_80070718(?); -// ? func_80070C24(?); -// ? func_800730DC(?); +void func_80070C24(GlobalContext* globalCtx, EnvironmentContext* envCtx, LightContext* lightCtx, PauseContext* pauseCtx, + MessageContext* msgCtx, u16*, GraphicsContext* gfxCtx); +void func_800730DC(GlobalContext*); void func_80073988(GlobalContext*, EnvironmentContext*, View*, GraphicsContext*, Vec3f, UNK_TYPE); // ? func_80073A5C(?); f32 func_800746DC(); -// ? func_80074704(?); +void func_80074704(GlobalContext*, View*, GraphicsContext*); void func_80074CE8(GlobalContext* globalCtx, s32 arg1); -// ? func_80074D6C(?); +void func_80074D6C(GlobalContext*); // ? func_80074FF4(?); -// ? func_800750C0(?); -void func_800753C4(GlobalContext* globalCtx, u8 arg1); -// ? func_8007542C(?); -// ? func_800758AC(?); +void func_800750C0(GlobalContext*); +void func_800753C4(GlobalContext*, u8); +void func_8007542C(GlobalContext*, u8); +void func_800758AC(GlobalContext* globalCtx); // ? func_80075B44(?); -// ? func_80075E68(?); +void func_80075E68(GlobalContext* globalCtx); // ? func_80075F14(?); // ? func_800760F4(?); // ? func_800763A8(?); // ? func_800766C4(?); void func_8007672C(GraphicsContext*, u8, u8, u8, u8, UNK_TYPE); -// ? func_80076934(?); +void func_80076934(GlobalContext* globalCtx); void func_800773A8(GlobalContext* globalCtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4); s32 func_800775CC(); void func_800775D8(); s32 func_800775E4(); void func_800775F0(u16); -// ? func_80077600(?); +s32 func_80077600(void); void func_80077624(GlobalContext* globalCtx); void func_80077684(GlobalContext* globalCtx); void func_800776E4(GlobalContext* globalCtx); @@ -1057,7 +1061,7 @@ void MapMark_DrawConditionally(GlobalContext* globalCtx); void PreNmiBuff_Init(PreNmiBuff* this); void PreNmiBuff_SetReset(PreNmiBuff* this); u32 PreNmiBuff_IsResetting(PreNmiBuff* this); -void MsgEvent_SendNullTask(); +void MsgEvent_SendNullTask(void); f32 OLib_Vec3fDist(Vec3f* a, Vec3f* b); f32 OLib_Vec3fDistXZ(Vec3f* a, Vec3f* b); f32 OLib_ClampMinDist(f32 val, f32 min); @@ -1124,8 +1128,8 @@ void Interface_Update(GlobalContext* globalCtx); Path* Path_GetByIndex(GlobalContext* globalCtx, s16 index, s16 max); f32 Path_OrientAndGetDistSq(Actor* actor, Path* path, s16 waypoint, s16* yaw); void Path_CopyLastPoint(Path* path, Vec3f* dest); -// ? func_8008E6A0(?); -// ? func_8008E6AC(?); +void func_8008E6A0(SubGlobalContext7B8*); +u32 func_8008E6AC(SubGlobalContext7B8* this, Input* input); void Player_SetBootData(GlobalContext* globalCtx, Player* player); s32 Player_InBlockingCsMode(GlobalContext* globalCtx, Player* player); s32 Player_InCsMode(GlobalContext* globalCtx); @@ -1183,7 +1187,7 @@ s16 Quake_Callback3(QuakeRequest* req, ShakeInfo* shake); s16 Quake_Callback4(QuakeRequest* req, ShakeInfo* shake); s16 Quake_Callback5(QuakeRequest* req, ShakeInfo* shake); s16 Quake_Callback6(QuakeRequest* req, ShakeInfo* shake); -s16 Quake_GetFreeIndex(); +s16 Quake_GetFreeIndex(void); QuakeRequest* Quake_AddImpl(Camera* cam, u32 callbackIdx); void Quake_Remove(QuakeRequest* req); QuakeRequest* Quake_GetRequest(s16 idx); @@ -1193,7 +1197,7 @@ u32 Quake_SetCountdown(s16 idx, s16 value); s16 Quake_GetCountdown(s16 idx); u32 Quake_SetQuakeValues(s16 idx, s16 y, s16 x, s16 zoom, s16 rotZ); u32 Quake_SetUnkValues(s16 idx, s16 arg1, SubQuakeRequest14 arg2); -void Quake_Init(); +void Quake_Init(void); s16 Quake_Add(Camera* cam, u32 callbackIdx); u32 Quake_RemoveFromIdx(s16 idx); s16 Quake_Calc(Camera* camera, QuakeCamCalc* camData); @@ -1401,6 +1405,7 @@ void func_800A9F30(PadMgr*, s32); void func_800A9F6C(f32, u8, u8, u8); void func_800AA000(f32, u8, u8, u8); void func_800AA0B4(); +void func_800AA0F0(void); u32 func_800AA148(); void func_800AA15C(); void func_800AA16C(); @@ -1437,10 +1442,10 @@ s32 func_800ABE74(f32 eyeX, f32 eyeY, f32 eyeZ); // ? func_800AC2F4(?); // ? func_800AC89C(?); // ? func_800AC9A4(?); -// ? func_800ACA28(?); -// ? func_800ACA90(?); +void func_800ACA28(unk_80166528*); +void func_800ACA90(unk_80166528*); // ? func_800ACA98(?); -// ? func_800ACAF8(?); +void func_800ACAF8(unk_80166528*, Input*, GraphicsContext*); void func_800ACE70(struct_801664F0* this); void func_800ACE90(struct_801664F0* this); void func_800ACE98(struct_801664F0* this, Gfx** gfxp); @@ -1459,10 +1464,11 @@ void func_800AD958(struct_80166500* this, Gfx** gfxp); // ? func_800AF178(?); // ? func_800AF218(?); // ? func_800B0E50(?); +void func_800B0E50(GlobalContext* globalCtx, SkyboxContext* skyboxCtx, s16 skyboxId); Mtx* SkyboxDraw_UpdateMatrix(SkyboxContext* skyboxCtx, f32 x, f32 y, f32 z); void SkyboxDraw_Draw(SkyboxContext* skyboxCtx, GraphicsContext* gfxCtx, s16 skyboxId, s16 alpha, f32 x, f32 y, f32 z); void SkyboxDraw_Update(SkyboxContext* skyboxCtx); -void PlayerCall_InitFuncPtrs(); +void PlayerCall_InitFuncPtrs(void); void TransitionUnk_InitGraphics(TransitionUnk* this); void TransitionUnk_InitData(TransitionUnk* this); void TransitionUnk_Destroy(TransitionUnk* this); @@ -1470,39 +1476,39 @@ TransitionUnk* TransitionUnk_Init(TransitionUnk* this, s32 row, s32 col); void TransitionUnk_SetData(TransitionUnk* this); void TransitionUnk_Draw(TransitionUnk* this, Gfx**); void func_800B23E8(TransitionUnk* this); -void TransitionTriforce_Start(TransitionTriforce* this); -TransitionTriforce* TransitionTriforce_Init(TransitionTriforce* this); -void TransitionTriforce_Destroy(TransitionTriforce* this); -void TransitionTriforce_Update(TransitionTriforce* this, s32 updateRate); -void TransitionTriforce_SetColor(TransitionTriforce* this, u32 color); -void TransitionTriforce_SetType(TransitionTriforce* this, s32 type); -void TransitionTriforce_Draw(TransitionTriforce* this, Gfx** gfxP); -s32 TransitionTriforce_IsDone(TransitionTriforce* this); -void TransitionWipe_Start(TransitionWipe* this); -TransitionWipe* TransitionWipe_Init(TransitionWipe* this); -void TransitionWipe_Destroy(TransitionWipe* this); -void TransitionWipe_Update(TransitionWipe* this, s32 updateRate); -void TransitionWipe_Draw(TransitionWipe* this, Gfx** gfxP); -s32 TransitionWipe_IsDone(TransitionWipe* this); -void TransitionWipe_SetType(TransitionWipe* this, s32 type); -void TransitionWipe_SetColor(TransitionWipe* this, u32 color); -void TransitionCircle_Start(TransitionCircle* this); -TransitionCircle* TransitionCircle_Init(TransitionCircle* this); -void TransitionCircle_Destroy(TransitionCircle* this); -void TransitionCircle_Update(TransitionCircle* this, s32 updateRate); -void TransitionCircle_Draw(TransitionCircle* this, Gfx** gfxP); -s32 TransitionCircle_IsDone(TransitionCircle* this); -void TransitionCircle_SetType(TransitionCircle* this, s32 type); -void TransitionCircle_SetColor(TransitionCircle* this, u32 color); -void TransitionCircle_SetEnvColor(TransitionCircle* this, u32 color); -void TransitionFade_Start(TransitionFade* this); -TransitionFade* TransitionFade_Init(TransitionFade* this); -void TransitionFade_Destroy(TransitionFade* this); -void TransitionFade_Update(TransitionFade* this, s32 updateRate); -void TransitionFade_Draw(TransitionFade* this, Gfx** gfxP); -s32 TransitionFade_IsDone(TransitionFade* this); -void TransitionFade_SetColor(TransitionFade* this, u32 color); -void TransitionFade_SetType(TransitionFade* this, s32 type); +void TransitionTriforce_Start(void* this); +void* TransitionTriforce_Init(void* this); +void TransitionTriforce_Destroy(void* this); +void TransitionTriforce_Update(void* this, s32 updateRate); +void TransitionTriforce_SetColor(void* this, u32 color); +void TransitionTriforce_SetType(void* this, s32 type); +void TransitionTriforce_Draw(void* this, Gfx** gfxP); +s32 TransitionTriforce_IsDone(void* this); +void TransitionWipe_Start(void* this); +void* TransitionWipe_Init(void* this); +void TransitionWipe_Destroy(void* this); +void TransitionWipe_Update(void* this, s32 updateRate); +void TransitionWipe_Draw(void* this, Gfx** gfxP); +s32 TransitionWipe_IsDone(void* this); +void TransitionWipe_SetType(void* this, s32 type); +void TransitionWipe_SetColor(void* this, u32 color); +void TransitionCircle_Start(void* thisx); +void* TransitionCircle_Init(void* thisx); +void TransitionCircle_Destroy(void* thisx); +void TransitionCircle_Update(void* thisx, s32 updateRate); +void TransitionCircle_Draw(void* thisx, Gfx** gfxP); +s32 TransitionCircle_IsDone(void* thisx); +void TransitionCircle_SetType(void* thisx, s32 type); +void TransitionCircle_SetColor(void* thisx, u32 color); +void TransitionCircle_SetEnvColor(void* thisx, u32 color); +void TransitionFade_Start(void* this); +void* TransitionFade_Init(void* this); +void TransitionFade_Destroy(void* this); +void TransitionFade_Update(void* this, s32 updateRate); +void TransitionFade_Draw(void* this, Gfx** gfxP); +s32 TransitionFade_IsDone(void* this); +void TransitionFade_SetColor(void* this, u32 color); +void TransitionFade_SetType(void* this, s32 type); void ShrinkWindow_SetVal(s32 value); u32 ShrinkWindow_GetVal(void); void ShrinkWindow_SetCurrentVal(s32 nowVal); @@ -1679,8 +1685,8 @@ void GameAlloc_Free(GameAlloc* this, void* data); void GameAlloc_Cleanup(GameAlloc* this); void GameAlloc_Init(GameAlloc* this); void Graph_FaultClient(); -void Graph_DisassembleUCode(void* arg0); -void Graph_UCodeFaultClient(void* arg0); +void Graph_DisassembleUCode(Gfx* workBuf); +void Graph_UCodeFaultClient(Gfx* workBuf); void* Graph_InitTHGA(GraphicsContext* gfxCtx); GameStateOverlay* Graph_GetNextGameState(GameState* gameState); void Graph_Init(GraphicsContext* gfxCtx); @@ -1699,8 +1705,8 @@ ListAlloc* ListAlloc_Init(ListAlloc* this); void* ListAlloc_Alloc(ListAlloc* this, u32 size); void ListAlloc_Free(ListAlloc* this, void* data); void ListAlloc_FreeAll(ListAlloc* this); -void Main_LogSystemHeap(); -void Main(void*); +void Main_LogSystemHeap(void); +void Main(void* arg); OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padmgr); void PadMgr_UnlockSerialMesgQueue(PadMgr* padmgr, OSMesgQueue* ctrlrqueue); void PadMgr_LockPadData(PadMgr* padmgr); @@ -1731,7 +1737,7 @@ void Sched_HandleEntry(SchedContext* sc); void Sched_HandleRetrace(SchedContext* sc); void Sched_HandleRSPDone(SchedContext* sc); void Sched_HandleRDPDone(SchedContext* sc); -void Sched_SendEntryMsg(OSMesgQueue* mq); +void Sched_SendEntryMsg(SchedContext* sc); void Sched_ThreadEntry(void* arg); void Sched_Init(SchedContext* sc, void* stack, OSPri priority, UNK_TYPE arg3, UNK_TYPE arg4, IrqMgr* irqMgr); void SpeedMeter_InitImpl(SpeedMeter* this, u32 arg1, u32 y); @@ -1848,15 +1854,16 @@ void func_800D2264(MtxF* mf, Vec3s* vec, s32 flag); void func_800D23FC(f32 f, Vec3f* vec, u8 mode); MtxF* Matrix_CheckFloats(MtxF* mf, char* file, s32 line); void func_800D2CEC(Mtx* mtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4, f32 arg5, f32 arg6); -u32 SysUcode_GetUCodeBoot(); -u32 SysUcode_GetUCodeBootSize(); -u32 SysUcode_GetUCode(); -u32 SysUcode_GetUCodeData(); +u32 SysUcode_GetUCodeBoot(void); +u32 SysUcode_GetUCodeBootSize(void); +u32 SysUcode_GetUCode(void); +u32 SysUcode_GetUCodeData(void); void func_800D2E30(UnkRumbleStruct* arg0); void func_800D3140(UnkRumbleStruct* arg0); void func_800D3178(UnkRumbleStruct* arg0); -// ? func_800D31F0(?); -// ? func_800D3210(?); +void func_800D31A0(void); +void func_800D31F0(void); +void func_800D3210(void); void IrqMgr_AddClient(IrqMgr* this, IrqMgrClient* c, OSMesgQueue* msgQ); void IrqMgr_RemoveClient(IrqMgr* this, IrqMgrClient* c); void IrqMgr_SendMesgForClient(IrqMgr* this, OSMesg msg); @@ -1879,14 +1886,14 @@ void* DebugArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 line void DebugArena_Free(void* ptr); void DebugArena_FreeDebug(void* ptr, const char* file, s32 line); void* DebugArena_Calloc(u32 num, u32 size); -void DebugArena_Display(); +void DebugArena_Display(void); void DebugArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc); -void DebugArena_Check(); +void DebugArena_Check(void); void DebugArena_Init(void* start, u32 size); -void DebugArena_Cleanup(); -u8 DebugArena_IsInitalized(); +void DebugArena_Cleanup(void); +u8 DebugArena_IsInitalized(void); void Fault_SleepImpl(u32); -void Fault_ClientProcessThread(FaultClientContext*); +void Fault_ClientProcessThread(void* arg); void Fault_ProcessClientContext(FaultClientContext*); u32 Fault_ProcessClient(u32, u32, u32); void Fault_AddClient(FaultClient*, void*, void*, void*); @@ -1938,7 +1945,7 @@ void FaultDrawer_SetFontColor(u16); void FaultDrawer_SetCharPad(s8, s8); void FaultDrawer_SetCursor(s32, s32); void FaultDrawer_FillScreen(); -u32 FaultDrawer_FormatStringFunc(u32, const char*, s32); +void* FaultDrawer_FormatStringFunc(void*, const char*, u32); void FaultDrawer_VPrintf(const char*, char*); void FaultDrawer_Printf(const char*, ...); void FaultDrawer_DrawText(s32, s32, const char*, ...); @@ -1948,15 +1955,15 @@ void FaultDrawer_SetDefault(); // ? UCodeDisas_TranslateAddr(?); // ? UCodeDisas_ParseCombineColor(?); // ? UCodeDisas_ParseCombineAlpha(?); -// ? UCodeDisas_Init(?); -// ? UCodeDisas_Destroy(?); +void UCodeDisas_Init(UCodeDisas*); +void UCodeDisas_Destroy(UCodeDisas*); // ? UCodeDisas_SetCurUCodeImpl(?); // ? UCodeDisas_ParseGeometryMode(?); // ? UCodeDisas_ParseRenderMode(?); // ? UCodeDisas_PrintVertices(?); -// ? UCodeDisas_Disassemble(?); -// ? UCodeDisas_RegisterUCode(?); -// ? UCodeDisas_SetCurUCode(?); +void UCodeDisas_Disassemble(UCodeDisas*, Gfx*); +void UCodeDisas_RegisterUCode(UCodeDisas*, s32, UCodeInfo*); +void UCodeDisas_SetCurUCode(UCodeDisas*, void*); // ? func_800DACC0(?); // ? func_800DB03C(?); // ? func_800DB0C4(?); @@ -2113,7 +2120,7 @@ void func_800E4D94(void); // ? func_800E4EEC(?); // ? func_800E4F58(?); void func_800E4FB0(void); -// ? func_800E4FE0(?); +Sub_AudioMgr_18* func_800E4FE0(void); // ? func_800E5000(?); // ? func_800E5584(?); // ? func_800E5958(?); @@ -2219,11 +2226,11 @@ void func_800ED858(u8); // ? func_800EE57C(?); // ? func_800EE5EC(?); // ? func_800EE6F4(?); -void func_800EE824(CutsceneContext* csCtx); +void func_800EE824(void); // ? func_800EE930(?); // ? func_800EE97C(?); // ? func_800EE9D0(?); -// ? func_800EEA50(?); +void func_800EEA50(GfxPrint* printer); // ? func_800F1BDC(?); // ? func_800F2150(?); // ? func_800F227C(?); @@ -2235,7 +2242,7 @@ void func_800EE824(CutsceneContext* csCtx); // ? func_800F2A04(?); void func_800F2D6C(u8*, u16 sfxId); // ? func_800F2E28(?); -// ? func_800F3054(?); +void func_800F3054(void); // ? func_800F3188(?); // ? func_800F32F0(?); // ? func_800F3468(?); @@ -2283,9 +2290,9 @@ void func_800F5E90(u8); void func_800F6114(f32); void func_800F6268(f32, UNK_TYPE); void func_800F6584(UNK_TYPE); -// ? func_800F64E0(?); +void func_800F64E0(u8); void func_800F6584(UNK_TYPE); -// ? func_800F66C0(?); +void func_800F66C0(s8 echo); void func_800F66DC(s8); void func_800F6700(s8 outputMode); void func_800F67A0(u8); @@ -2299,7 +2306,7 @@ void func_800F6AB0(u8); // ? func_800F6BB8(?); void func_800F6C14(); // ? func_800F6C34(?); -void func_800F6D58(u8 arg0, u8 arg1, u8 arg2); +void func_800F6D58(u8, u8, u8); // ? func_800F6E7C(?); // ? func_800F6FB4(?); void func_800F70F8(); @@ -2369,7 +2376,7 @@ s32 Overlay_Load(u32 vRomStart, u32 vRomEnd, void* vRamStart, void* vRamEnd, voi // ? func_800FCAB4(?); void SystemHeap_Init(void* start, u32 size); void PadUtils_Init(Input* input); -void func_800FCB70(); +void func_800FCB70(void); void PadUtils_ResetPressRel(Input* input); u32 PadUtils_CheckCurExact(Input* input, u16 value); u32 PadUtils_CheckCur(Input* input, u16 key); @@ -2410,12 +2417,12 @@ void* SystemArena_ReallocDebug(void* ptr, u32 newSize, const char* file, s32 lin void SystemArena_Free(void* ptr); void SystemArena_FreeDebug(void* ptr, const char* file, s32 line); void* SystemArena_Calloc(u32 num, u32 size); -void SystemArena_Display(); +void SystemArena_Display(void); void SystemArena_GetSizes(u32* outMaxFree, u32* outFree, u32* outAlloc); -void SystemArena_Check(); +void SystemArena_Check(void); void SystemArena_Init(void* start, u32 size); -void SystemArena_Cleanup(); -u8 SystemArena_IsInitalized(); +void SystemArena_Cleanup(void); +u8 SystemArena_IsInitalized(void); u32 Rand_Next(void); void Rand_Seed(u32 seed); f32 Rand_ZeroOne(void); @@ -2463,8 +2470,8 @@ void __osDisplayArena(Arena* arena); void ArenaImpl_FaultClient(Arena* arena); u32 __osCheckArena(Arena* arena); u8 func_800FF334(Arena* arena); -void PrintUtils_VPrintf(char** arg0, const char* fmt, va_list args); -void PrintUtils_Printf(void* arg0, const char* fmt, ...); +void PrintUtils_VPrintf(PrintCallback* pfn, const char* fmt, va_list args); +void PrintUtils_Printf(PrintCallback* pfn, const char* fmt, ...); void Sleep_Cycles(OSTime cycles); void Sleep_Nsec(u32 nsec); void Sleep_Usec(u32 usec); @@ -2479,8 +2486,8 @@ u32 JpegUtils_ProcessHuffmanTable(u8* dht, JpegHuffmanTable* ht, u8* codesLength void JpegUtils_SetHuffmanTableOld(u8* data, JpegHuffmanTableOld* ht, u8* codesLengths, u16* codes, s16 count, u8 isAc); u32 JpegUtils_ProcessHuffmanTableImplOld(u8* dht, JpegHuffmanTableOld* ht, u8* codesLengths, u16* codes); s32 JpegDecoder_Decode(JpegDecoder* decoder, u16* mcuBuff, s32 count, u8 isFollowing, JpegDecoderState* state); -s32 JpegDecoder_ProcessMcu(JpegHuffmanTable* hTable0, JpegHuffmanTable* hTable1, s16* mcu, s16* unk); -s32 JpegDecoder_ParseNextSymbol(JpegHuffmanTable* hTable, s16* outCoeff, u8* outZeroCount); +s32 JpegDecoder_ProcessMcu(JpegHuffmanTable* hTable0, JpegHuffmanTable* hTable1, u16* mcu, s16* unk); +s32 JpegDecoder_ParseNextSymbol(JpegHuffmanTable* hTable, s16* outCoeff, s8* outZeroCount); u16 JpegDecoder_ReadBits(u8 len); s32 osPfsFreeBlocks(OSPfs* pfs, s32* leftoverBytes); void guScale(Mtx* m, f32 x, f32 y, f32 z); @@ -2492,15 +2499,15 @@ void osSpTaskStartGo(OSTask* task); s32 osSetRumble(OSPfs* pfs, u32 vibrate); void osSetUpMempakWrite(s32 channel, OSPifRam* buf); s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, OSPfs* pfs, u32 channel); -void __osSiCreateAccessQueue(); -void __osSiGetAccess(); -void __osSiRelAccess(); +void __osSiCreateAccessQueue(void); +void __osSiGetAccess(void); +void __osSiRelAccess(void); s32 osContInit(OSMesgQueue* mq, u8* ctl_present_bitfield, OSContStatus* status); void __osContGetInitData(u8* ctl_present_bitfield, OSContStatus* status); void __osPackRequestData(u8 poll); s32 osContStartReadData(OSMesgQueue* mq); void osContGetReadData(OSContPad* pad); -void __osPackReadData(); +void __osPackReadData(void); void guPerspectiveF(f32 mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale); void guPerspective(Mtx* m, u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale); s32 __osSpRawStartDma(s32 direction, void* devAddr, void* dramAddr, u32 size); @@ -2521,7 +2528,7 @@ s32 osStopTimer(OSTimer* timer); u16 __osSumcalc(u8* ptr, s32 length); s32 __osIdCheckSum(u16* ptr, u16* csum, u16* icsum); s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid); -s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp); +s32 __osCheckPackId(OSPfs* pfs, __OSPackId* check); s32 __osGetId(OSPfs* pfs); s32 __osCheckId(OSPfs* pfs); s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank); @@ -2536,15 +2543,15 @@ void guLookAtHiliteF(f32 mf[4][4], LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 void guLookAtHilite(Mtx* m, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 hiliteWidth, s32 hiliteHeight); -u32 __osSpDeviceBusy(); -void guMtxIdent(f32 m[4][4]); +u32 __osSpDeviceBusy(void); +void guMtxIdent(Mtx*); void guPositionF(f32 mf[4][4], f32 rot, f32 pitch, f32 yaw, f32 scale, f32 x, f32 y, f32 z); void guPosition(Mtx*, f32, f32, f32, f32, f32, f32, f32); OSYieldResult osSpTaskYielded(OSTask* task); void guRotateF(f32 m[4][4], f32 a, f32 x, f32 y, f32 z); void guRotate(Mtx*, f32 angle, f32 x, f32 y, f32 z); s32 osAiSetFrequency(u32 frequency); -OSThread* __osGetActiveQueue(); +OSThread* __osGetActiveQueue(void); void guNormalize(f32* x, f32* y, f32* z); u32 osDpGetStatus(void); void osDpSetStatus(u32 status); @@ -2574,10 +2581,10 @@ s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data); u8 __osContAddressCrc(u16 addr); u8 __osContDataCrc(u8* data); s32 osSetTimer(OSTimer* timer, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg); -u32 __osSpGetStatus(); +u32 __osSpGetStatus(void); void __osSpSetStatus(u32 status); void osWritebackDCacheAll(void); -OSThread* __osGetCurrFaultedThread(); +OSThread* __osGetCurrFaultedThread(void); void guMtxF2L(MtxF* m1, Mtx* m2); // ? __d_to_ll(?); // ? __f_to_ll(?); @@ -2621,12 +2628,12 @@ u8 func_8010BDBC(MessageContext* msgCtx); // ? func_8010C39C(?); // ? func_8010F2CC(?); // ? func_8010F494(?); -// ? func_8010F58C(?); -// ? func_8010F6F0(?); +void func_8010F58C(GlobalContext* globalCtx); +void func_8010F6F0(GlobalContext* globalCtx); void func_8011040C(void); -// ? func_80110450(?); -// ? func_80110460(?); -// ? func_801104C8(?); +void func_80110450(GlobalContext* globalCtx); +void func_80110460(GlobalContext* globalCtx); +void func_801104C8(GlobalContext* globalCtx); void func_80110990(GlobalContext* globalCtx); void func_801109B0(GlobalContext* globalCtx); void func_80110F68(GlobalContext* globalCtx); diff --git a/include/macros.h b/include/macros.h index 3a3b61890e..3315dd5e13 100644 --- a/include/macros.h +++ b/include/macros.h @@ -103,6 +103,7 @@ extern GraphicsContext* __gfxCtx; GraphicsContext* __gfxCtx; \ Gfx* dispRefs[4]; \ __gfxCtx = gfxCtx; \ + (void)__gfxCtx; \ Graph_OpenDisps(dispRefs, gfxCtx, file, line) #define CLOSE_DISPS(gfxCtx, file, line) \ diff --git a/include/ultra64/hardware.h b/include/ultra64/hardware.h index ae9e30ce7e..bd006c21db 100644 --- a/include/ultra64/hardware.h +++ b/include/ultra64/hardware.h @@ -1,7 +1,7 @@ #ifndef _ULTRA64_HARDWARE_H_ #define _ULTRA64_HARDWARE_H_ -#define HW_REG(reg, type) *(volatile type*)(reg | 0xa0000000) +#define HW_REG(reg, type) *(volatile type*)((reg) | 0xa0000000) #define AI_DRAM_ADDR_REG 0x04500000 #define AI_LEN_REG 0x04500004 diff --git a/include/ultra64/printf.h b/include/ultra64/printf.h index 23718012a5..6498507822 100644 --- a/include/ultra64/printf.h +++ b/include/ultra64/printf.h @@ -21,6 +21,8 @@ typedef struct { /* 0x34 */ u8 qual; } _Pft; // size = 0x38 +typedef void* (*PrintCallback)(void*, const char*, u32); + #define FLAGS_SPACE 1 #define FLAGS_PLUS 2 #define FLAGS_MINUS 4 diff --git a/include/variables.h b/include/variables.h index 3c6b191405..b4f23c7fa4 100644 --- a/include/variables.h +++ b/include/variables.h @@ -106,7 +106,7 @@ extern DmaEntry gDmaDataTable[0x60C]; //extern ? D_800D7288; extern u8 D_801120C0[]; extern u8 D_80113070[]; -extern u8 D_80114930[]; +extern u64 D_80114930[]; //extern ? D_80115440; //extern ? D_80115760; //extern ? D_80115770; @@ -3165,7 +3165,7 @@ extern s16 gTatumsPerBeat; extern u8 D_80155F50[]; extern u8 D_80157580[]; extern u8 D_801579A0[]; -extern u8 D_80157D30[]; +extern u64 D_80157D30[]; //extern ? D_8015BC30; //extern ? D_8015BC3C; //extern ? D_8015BC48; @@ -3520,7 +3520,7 @@ extern u8 __osMaxControllers; extern OSMesgQueue __osContMesgQueue; extern OSMesg __osContMesgBuff[4]; extern __OSInode __osPfsInodeCache; -extern OSPifRam pifMempakBuf; +extern OSPifRam gPifMempakBuf; //extern ? D_801759A0; //extern ? D_801759A4; //extern ? D_801759A8; diff --git a/include/z64.h b/include/z64.h index 573fde5679..b369e333cb 100644 --- a/include/z64.h +++ b/include/z64.h @@ -719,7 +719,7 @@ typedef struct { TransitionWipe wipe; char data[0x228]; }; - /* 0x228 */ s32 transitionType; + /* 0x228 */ s32 transitionType; /* 0x22C */ void* (*init)(void* transition); /* 0x230 */ void (*destroy)(void* transition); /* 0x234 */ void (*update)(void* transition, s32 updateRate); @@ -1233,7 +1233,7 @@ typedef struct { /* 0x14 */ u16 backColor; /* 0x14 */ u16 cursorX; /* 0x16 */ u16 cursorY; - /* 0x18 */ u32* fontData; + /* 0x18 */ const u32* fontData; /* 0x1C */ u8 charW; /* 0x1D */ u8 charH; /* 0x1E */ s8 charWPad; @@ -1245,7 +1245,7 @@ typedef struct { } FaultDrawer; // size = 0x3C typedef struct GfxPrint { - /* 0x00 */ struct GfxPrint*(*callback)(struct GfxPrint*, const char*, size_t); + /* 0x00 */ struct GfxPrint *(*callback)(struct GfxPrint*, const char*, size_t); /* 0x04 */ Gfx* dlist; /* 0x08 */ u16 posX; /* 0x0A */ u16 posY; @@ -1335,7 +1335,7 @@ typedef struct { /* 0x278 */ OSTime retraceTime; } IrqMgr; // size = 0x280 -typedef struct { +typedef struct PadMgr { /* 0x0000 */ OSContStatus padStatus[4]; /* 0x0010 */ OSMesg serialMsgBuf[1]; /* 0x0014 */ OSMesg lockMsgBuf[1]; @@ -1349,7 +1349,7 @@ typedef struct { /* 0x0230 */ Input inputs[4]; /* 0x0290 */ OSContPad pads[4]; /* 0x02A8 */ vu8 validCtrlrsMask; - /* 0x02A9 */ u8 ncontrollers; + /* 0x02A9 */ u8 nControllers; /* 0x02AA */ u8 ctrlrIsConnected[4]; // "Key_switch" originally /* 0x02AE */ u8 pakType[4]; // 1 if rumble pack, 2 if mempak? /* 0x02B2 */ vu8 rumbleEnable[4]; @@ -1358,7 +1358,7 @@ typedef struct { /* 0x045C */ vu8 rumbleOffFrames; /* 0x045D */ vu8 rumbleOnFrames; /* 0x045E */ u8 preNMIShutdown; - /* 0x0460 */ void (*retraceCallback)(void* padmgr, u32 unk464); + /* 0x0460 */ void (*retraceCallback)(struct PadMgr* padmgr, s32 unk464); /* 0x0464 */ u32 retraceCallbackValue; } PadMgr; // size = 0x468 @@ -1645,6 +1645,13 @@ typedef struct { /* 0x10 */ s16 unk_10; } JpegDecoderState; // size = 0x14 +typedef struct { + /* 0x0000 */ OSViMode viMode; + /* 0x0050 */ char unk_50[0x30]; + /* 0x0080 */ u32 viFeatures; + /* 0x0084 */ char unk_84[4]; +} unk_80166528; + // Vis... typedef struct { /* 0x00 */ u32 type; @@ -1704,7 +1711,7 @@ typedef struct { } SpeedMeterAllocEntry; // size = 0x1C typedef struct { - /* 0x00 */ OSTime* time; + /* 0x00 */ volatile OSTime* time; /* 0x04 */ u8 x; /* 0x05 */ u8 y; /* 0x06 */ u16 color; diff --git a/include/z64camera.h b/include/z64camera.h index cca2a8ff69..0490f3dc35 100644 --- a/include/z64camera.h +++ b/include/z64camera.h @@ -845,7 +845,7 @@ typedef struct { /* 0x000C */ Vec3f norm; /* 0x0018 */ CollisionPoly* poly; /* 0x001C */ VecSph sphNorm; - /* 0x0024 */ u32 bgId; + /* 0x0024 */ s32 bgId; } CamColChk; // size = 0x28 typedef struct { diff --git a/include/z64dma.h b/include/z64dma.h index e540a8633b..f5106438af 100755 --- a/include/z64dma.h +++ b/include/z64dma.h @@ -7,7 +7,7 @@ typedef struct { /* 0x00 */ u32 vromAddr; // VROM address (source) /* 0x04 */ void* dramAddr; // DRAM address (destination) /* 0x08 */ u32 size; // File Transfer size - /* 0x0C */ char* filename; // Filename for debugging + /* 0x0C */ const char* filename; // Filename for debugging /* 0x10 */ s32 line; // Line for debugging /* 0x14 */ s32 unk_14; /* 0x18 */ OSMesgQueue* notifyQueue; // Message queue for the notification message diff --git a/src/boot/assert.c b/src/boot/assert.c index 9ab6df2e12..b7895dddda 100644 --- a/src/boot/assert.c +++ b/src/boot/assert.c @@ -2,6 +2,7 @@ void __assert(const char* exp, const char* file, s32 line) { char msg[256]; + osSyncPrintf("Assertion failed: %s, file %s, line %d, thread %d\n", exp, file, line, osGetThreadId(NULL)); sprintf(msg, "ASSERT: %s:%d(%d)", file, line, osGetThreadId(NULL)); Fault_AddHungupAndCrashImpl(msg, exp); diff --git a/src/boot/boot_main.c b/src/boot/boot_main.c index b6d1ceeb3a..0373f4b396 100644 --- a/src/boot/boot_main.c +++ b/src/boot/boot_main.c @@ -24,6 +24,7 @@ void bootproc(void) { Locale_Init(); StackCheck_Init(&sIdleThreadInfo, sIdleThreadStack, sIdleThreadStack + sizeof(sIdleThreadStack), 0, 256, "idle"); - osCreateThread(&sIdleThread, 1, Idle_ThreadEntry, 0, sIdleThreadStack + sizeof(sIdleThreadStack), Z_PRIORITY_MAIN); + osCreateThread(&sIdleThread, 1, Idle_ThreadEntry, NULL, sIdleThreadStack + sizeof(sIdleThreadStack), + Z_PRIORITY_MAIN); osStartThread(&sIdleThread); } diff --git a/src/boot/idle.c b/src/boot/idle.c index 7723b26333..d9c35be0dd 100644 --- a/src/boot/idle.c +++ b/src/boot/idle.c @@ -16,25 +16,25 @@ u32 gViConfigFeatures = OS_VI_DITHER_FILTER_ON | OS_VI_GAMMA_OFF; f32 gViConfigXScale = 1.0; f32 gViConfigYScale = 1.0; -void Main_ThreadEntry(void* arg0) { - OSTime var1; +void Main_ThreadEntry(void* arg) { + OSTime time; osSyncPrintf("mainx 実行開始\n"); DmaMgr_Init(); osSyncPrintf("codeセグメントロード中..."); - var1 = osGetTime(); + time = osGetTime(); DmaMgr_SendRequest1(_codeSegmentStart, (u32)_codeSegmentRomStart, _codeSegmentRomEnd - _codeSegmentRomStart, "../idle.c", 238); - var1 -= osGetTime(); + time -= osGetTime(); osSyncPrintf("\rcodeセグメントロード中...完了\n"); osSyncPrintf("転送時間 %6.3f\n"); bzero(_codeSegmentBssStart, _codeSegmentBssEnd - _codeSegmentBssStart); osSyncPrintf("codeセグメントBSSクリア完了\n"); - Main(arg0); + Main(arg); osSyncPrintf("mainx 実行終了\n"); } -void Idle_ThreadEntry(void* a0) { +void Idle_ThreadEntry(void* arg) { osSyncPrintf("アイドルスレッド(idleproc)実行開始\n"); osSyncPrintf("作製者 : %s\n", gBuildTeam); osSyncPrintf("作成日時 : %s\n", gBuildDate); @@ -80,7 +80,7 @@ void Idle_ThreadEntry(void* a0) { osViSwapBuffer(0x803DA80); //! @bug Invalid vram address (probably intended to be 0x803DA800) osCreatePiManager(OS_PRIORITY_PIMGR, &gPiMgrCmdQ, sPiMgrCmdBuff, 50); StackCheck_Init(&sMainStackInfo, sMainStack, sMainStack + sizeof(sMainStack), 0, 0x400, "main"); - osCreateThread(&gMainThread, 3, Main_ThreadEntry, a0, sMainStack + sizeof(sMainStack), Z_PRIORITY_MAIN); + osCreateThread(&gMainThread, 3, Main_ThreadEntry, arg, sMainStack + sizeof(sMainStack), Z_PRIORITY_MAIN); osStartThread(&gMainThread); osSetThreadPri(NULL, OS_PRIORITY_IDLE); diff --git a/src/boot/is_debug.c b/src/boot/is_debug.c index d24c5887f0..39544984d3 100644 --- a/src/boot/is_debug.c +++ b/src/boot/is_debug.c @@ -5,7 +5,7 @@ OSPiHandle* sISVHandle; // official name : is_Handle #define gISVDbgPrnAdrs ((ISVDbg*)0xb3ff0000) #define ASCII_TO_U32(a, b, c, d) ((u32)((a << 24) | (b << 16) | (c << 8) | (d << 0))) -void isPrintfInit() { +void isPrintfInit(void) { sISVHandle = osCartRomInit(); osEPiWriteIo(sISVHandle, (u32)&gISVDbgPrnAdrs->put, 0); osEPiWriteIo(sISVHandle, (u32)&gISVDbgPrnAdrs->get, 0); @@ -16,14 +16,14 @@ void osSyncPrintfUnused(const char* fmt, ...) { va_list args; va_start(args, fmt); - _Printf(&is_proutSyncPrintf, NULL, fmt, args); + _Printf(is_proutSyncPrintf, NULL, fmt, args); } void osSyncPrintf(const char* fmt, ...) { va_list args; va_start(args, fmt); - _Printf(&is_proutSyncPrintf, NULL, fmt, args); + _Printf(is_proutSyncPrintf, NULL, fmt, args); } // assumption @@ -31,10 +31,10 @@ void rmonPrintf(const char* fmt, ...) { va_list args; va_start(args, fmt); - _Printf(&is_proutSyncPrintf, NULL, fmt, args); + _Printf(is_proutSyncPrintf, NULL, fmt, args); } -u32 is_proutSyncPrintf(void* arg0, const char* str, s32 count) { +void* is_proutSyncPrintf(void* arg, const char* str, u32 count) { u32 data; s32 pos; s32 start; @@ -75,6 +75,7 @@ u32 is_proutSyncPrintf(void* arg0, const char* str, s32 count) { str++; } osEPiWriteIo(sISVHandle, (u32)&gISVDbgPrnAdrs->put, start); + return 1; } diff --git a/src/boot/logutils.c b/src/boot/logutils.c index e94b60dcc2..3daac5a40b 100644 --- a/src/boot/logutils.c +++ b/src/boot/logutils.c @@ -1,22 +1,22 @@ #include "global.h" #include "vt.h" -f32 LogUtils_CheckFloatRange(const char* exp, s32 arg1, const char* var1Name, f32 var1, const char* var2Name, f32 var2, - const char* var3Name, f32 var3) { - if (var1 < var2 || var3 < var1) { - osSyncPrintf("%s %d: range error %s(%f) < %s(%f) < %s(%f)\n", exp, arg1, var2Name, var2, var1Name, var1, - var3Name, var3); +f32 LogUtils_CheckFloatRange(const char* exp, s32 line, const char* valueName, f32 value, const char* minName, f32 min, + const char* maxName, f32 max) { + if (value < min || max < value) { + osSyncPrintf("%s %d: range error %s(%f) < %s(%f) < %s(%f)\n", exp, line, minName, min, valueName, value, + maxName, max); } - return var1; + return value; } -s32 LogUtils_CheckIntRange(const char* exp, s32 arg1, const char* var1Name, s32 var1, const char* var2Name, s32 var2, - const char* var3Name, s32 var3) { - if (var1 < var2 || var3 < var1) { - osSyncPrintf("%s %d: range error %s(%d) < %s(%d) < %s(%d)\n", exp, arg1, var2Name, var2, var1Name, var1, - var3Name, var3); +s32 LogUtils_CheckIntRange(const char* exp, s32 line, const char* valueName, s32 value, const char* minName, s32 min, + const char* maxName, s32 max) { + if (value < min || max < value) { + osSyncPrintf("%s %d: range error %s(%d) < %s(%d) < %s(%d)\n", exp, line, minName, min, valueName, value, + maxName, max); } - return var1; + return value; } void LogUtils_LogHexDump(void* ptr, s32 size0) { @@ -84,14 +84,13 @@ void LogUtils_CheckBoundary(const char* name, s32 value, s32 unk, const char* fi } void LogUtils_CheckNullPointer(const char* exp, void* ptr, const char* file, s32 line) { - if (!ptr) { + if (ptr == NULL) { osSyncPrintf(VT_COL(RED, WHITE) "%s %d:%s は はヌルポインタです\n" VT_RST, file, line, exp); } } -void LogUtils_CheckValidPointer(const char* exp, void* ptr0, const char* file, s32 line) { - u32 ptr = (u32)ptr0; - if (!ptr || ptr < 0x80000000U || (0x80000000U + osMemSize) <= ptr) { +void LogUtils_CheckValidPointer(const char* exp, void* ptr, const char* file, s32 line) { + if (ptr == NULL || (u32)ptr < 0x80000000 || (0x80000000 + osMemSize) <= (u32)ptr) { osSyncPrintf(VT_COL(RED, WHITE) "%s %d:ポインタ %s(%08x) が異常です\n" VT_RST, file, line, exp, ptr); } } @@ -105,7 +104,7 @@ void LogUtils_HungupThread(const char* name, s32 line) { Fault_AddHungupAndCrash(name, line); } -void LogUtils_ResetHungup() { +void LogUtils_ResetHungup(void) { osSyncPrintf("*** Reset ***\n"); Fault_AddHungupAndCrash("Reset", 0); } diff --git a/src/boot/stackcheck.c b/src/boot/stackcheck.c index fa7e958359..a44adf2540 100644 --- a/src/boot/stackcheck.c +++ b/src/boot/stackcheck.c @@ -9,7 +9,7 @@ void StackCheck_Init(StackEntry* entry, void* stackTop, void* stackBottom, u32 i StackEntry* iter; u32* addr; - if (!entry) { + if (entry == NULL) { sStackInfoListStart = NULL; } else { entry->head = (u32)stackTop; @@ -90,7 +90,7 @@ StackStatus StackCheck_GetState(StackEntry* entry) { if (free == 0) { ret = STACK_STATUS_OVERFLOW; osSyncPrintf(VT_FGCOL(RED)); - } else if (free < entry->minSpace && entry->minSpace != -1) { + } else if (free < (u32)entry->minSpace && entry->minSpace != -1) { ret = STACK_STATUS_WARNING; osSyncPrintf(VT_FGCOL(YELLOW)); } else { @@ -109,10 +109,10 @@ StackStatus StackCheck_GetState(StackEntry* entry) { return ret; } -u32 StackCheck_CheckAll() { +u32 StackCheck_CheckAll(void) { u32 ret = 0; - StackEntry* iter = sStackInfoListStart; + while (iter) { u32 state = StackCheck_GetState(iter); if (state != STACK_STATUS_OK) { @@ -125,7 +125,7 @@ u32 StackCheck_CheckAll() { } u32 StackCheck_Check(StackEntry* entry) { - if (!entry) { + if (entry == NULL) { return StackCheck_CheckAll(); } else { return StackCheck_GetState(entry); diff --git a/src/boot/viconfig.c b/src/boot/viconfig.c index b394833963..5e0b7c9083 100644 --- a/src/boot/viconfig.c +++ b/src/boot/viconfig.c @@ -4,8 +4,8 @@ // this should probably go elsewhere but right now viconfig.o is the only object between idle and z_std_dma OSPiHandle* gCartHandle = 0; -void ViConfig_UpdateVi(u32 arg0) { - if (arg0 != 0) { +void ViConfig_UpdateVi(u32 mode) { + if (mode != 0) { osSyncPrintf(VT_COL(YELLOW, BLACK) "osViSetYScale1(%f);\n" VT_RST, 1.0f); if (osTvType == 0) { @@ -34,10 +34,10 @@ void ViConfig_UpdateVi(u32 arg0) { } } - gViConfigUseDefault = arg0; + gViConfigUseDefault = mode; } -void ViConfig_UpdateBlack() { +void ViConfig_UpdateBlack(void) { if (gViConfigUseDefault != 0) { osViBlack(1); } else { diff --git a/src/boot/yaz0.c b/src/boot/yaz0.c index ee304fce40..dd4458d2ec 100644 --- a/src/boot/yaz0.c +++ b/src/boot/yaz0.c @@ -6,7 +6,7 @@ u32 sYaz0CurRomStart; u32 sYaz0CurSize; u32 sYaz0MaxPtr; -void* Yaz0_FirstDMA() { +void* Yaz0_FirstDMA(void) { u32 pad0; u32 pad1; u32 dmaSize; @@ -29,7 +29,6 @@ void* Yaz0_NextDMA(void* curSrcPos) { u32 dmaSize; restSize = sYaz0CurDataEnd - (u32)curSrcPos; - dst = (restSize & 7) ? (sYaz0DataBuffer - (restSize & 7)) + 8 : sYaz0DataBuffer; bcopy(curSrcPos, dst, restSize); @@ -51,19 +50,15 @@ void* Yaz0_NextDMA(void* curSrcPos) { } void Yaz0_DecompressImpl(Yaz0Header* hdr, u8* dst) { - u32 bitIdx; - u8* src; - u8* dstEnd; + u32 bitIdx = 0; + u8* src = (u8*)hdr->data; + u8* dstEnd = dst + hdr->decSize; u32 chunkHeader; u32 nibble; u8* backPtr; - s32 chunkSize; + u32 chunkSize; u32 off; - bitIdx = 0; - src = (u8*)hdr->data; - dstEnd = dst + hdr->decSize; - do { if (bitIdx == 0) { if ((sYaz0MaxPtr < (u32)src) && (sYaz0CurSize != 0)) { @@ -84,9 +79,9 @@ void Yaz0_DecompressImpl(Yaz0Header* hdr, u8* dst) { backPtr = dst - off; src += 2; - chunkSize = (nibble == 0) // N = chunkSize; B = back offset - ? *src++ + 0x12 // 3 bytes 0B BB NN - : nibble + 2; // 2 bytes NB BB + chunkSize = (nibble == 0) // N = chunkSize; B = back offset + ? (u32)(*src++ + 0x12) // 3 bytes 0B BB NN + : nibble + 2; // 2 bytes NB BB do { *dst++ = *(backPtr++ - 1); diff --git a/src/boot/z_locale.c b/src/boot/z_locale.c index 09fff3b758..0fdf0e2176 100644 --- a/src/boot/z_locale.c +++ b/src/boot/z_locale.c @@ -4,7 +4,7 @@ u32 gCurrentRegion = 0; LocaleCartInfo sCartInfo; -void Locale_Init() { +void Locale_Init(void) { osEPiReadIo(gCartHandle, 0x38, &sCartInfo.mediaFormat); osEPiReadIo(gCartHandle, 0x3C, &sCartInfo.regionInfo); @@ -29,11 +29,11 @@ void Locale_Init() { osSyncPrintf("z_locale_init:日本用かアメリカ用か3コンで判断させる\n"); } -void Locale_ResetRegion() { +void Locale_ResetRegion(void) { gCurrentRegion = REGION_NULL; } -u32 func_80001F48() { +u32 func_80001F48(void) { if (gCurrentRegion == REGION_NATIVE) { return 0; } @@ -45,7 +45,7 @@ u32 func_80001F48() { return 1; } -u32 func_80001F8C() { +u32 func_80001F8C(void) { if (gCurrentRegion == REGION_NATIVE) { return 0; } @@ -58,6 +58,6 @@ u32 func_80001F8C() { } // This function appears to be unused? -u32 Locale_IsRegionNative() { +u32 Locale_IsRegionNative(void) { return gCurrentRegion == REGION_NATIVE; } diff --git a/src/boot/z_std_dma.c b/src/boot/z_std_dma.c index 0ac63c3979..d03ac8d7aa 100644 --- a/src/boot/z_std_dma.c +++ b/src/boot/z_std_dma.c @@ -12,6 +12,7 @@ s32 sDmaMgrCurFileLine; u32 D_80009460 = 0; u32 gDmaMgrDmaBuffSize = 0x2000; u32 sDmaMgrDataExistError = 0; + const char* sDmaMgrFileNames[0x5FC] = { "makerom", "boot", @@ -1573,10 +1574,9 @@ s32 DmaMgr_DMARomToRam(u32 rom, u32 ram, u32 size) { OSMesgQueue queue; OSMesg msg; s32 ret; - u32 buffSize; + u32 buffSize = gDmaMgrDmaBuffSize; s32 pad[2]; - buffSize = gDmaMgrDmaBuffSize; if (buffSize == 0) { buffSize = 0x2000; } @@ -1676,12 +1676,11 @@ s32 DmaMgr_DmaCallback0(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction) { } void DmaMgr_DmaCallback1(u32 ram, u32 rom, u32 size) { - OSPiHandle* handle; + OSPiHandle* handle = osDriveRomInit(); OSMesgQueue queue; OSMesg msg; OSIoMesg ioMsg; - handle = osDriveRomInit(); osInvalICache((void*)ram, size); osInvalDCache((void*)ram, size); osCreateMesgQueue(&queue, &msg, 1); @@ -1694,21 +1693,17 @@ void DmaMgr_DmaCallback1(u32 ram, u32 rom, u32 size) { handle->transferInfo.cmdType = 2; osEPiStartDma(handle, &ioMsg, 0); - osRecvMesg(&queue, NULL, 1); + osRecvMesg(&queue, NULL, OS_MESG_BLOCK); return; } void DmaMgr_Error(DmaRequest* req, const char* file, const char* errorName, const char* errorDesc) { - u32 vrom; - u32 ram; - u32 size; + u32 vrom = req->vromAddr; + u32 ram = (u32)req->dramAddr; + u32 size = req->size; char buff1[80]; char buff2[80]; - vrom = req->vromAddr; - ram = (u32)req->dramAddr; - size = req->size; - osSyncPrintf("%c", 7); osSyncPrintf(VT_FGCOL(RED)); osSyncPrintf("DMA致命的エラー(%s)\nROM:%X RAM:%X SIZE:%X %s\n", @@ -1735,11 +1730,8 @@ void DmaMgr_Error(DmaRequest* req, const char* file, const char* errorName, cons } const char* DmaMgr_GetFileNameImpl(u32 vrom) { - DmaEntry* iter; - const char** name; - - iter = gDmaDataTable; - name = sDmaMgrFileNames; + DmaEntry* iter = gDmaDataTable; + const char** name = sDmaMgrFileNames; while (iter->vromEnd) { if (vrom >= iter->vromStart && vrom < iter->vromEnd) { @@ -1755,7 +1747,8 @@ const char* DmaMgr_GetFileNameImpl(u32 vrom) { const char* DmaMgr_GetFileName(u32 vrom) { const char* ret = DmaMgr_GetFileNameImpl(vrom); - if (!ret) { + + if (ret == NULL) { return "(unknown)"; } @@ -1767,25 +1760,26 @@ const char* DmaMgr_GetFileName(u32 vrom) { } void DmaMgr_ProcessMsg(DmaRequest* req) { - u32 vrom; - void* ram; - u32 size; + u32 vrom = req->vromAddr; + void* ram = req->dramAddr; + u32 size = req->size; u32 romStart; u32 romSize; - u8 found; + u8 found = false; DmaEntry* iter; const char* filename; - vrom = req->vromAddr; - ram = req->dramAddr; - size = req->size; - found = false; + if (0) { + // the string is defined in .rodata but not used, suggesting + // a debug print is here but optimized out in some way + osSyncPrintf("DMA ROM:%08X RAM:%08X SIZE:%08X %s\n"); + // the last arg of this print looks like it may be filename, but + // filename above this block does not match + } + filename = DmaMgr_GetFileName(vrom); iter = gDmaDataTable; - // defined in .rodata but not used - "DMA ROM:%08X RAM:%08X SIZE:%08X %s\n"; - while (iter->vromEnd) { if (vrom >= iter->vromStart && vrom < iter->vromEnd) { if (1) {} // Necessary to match @@ -1799,7 +1793,9 @@ void DmaMgr_ProcessMsg(DmaRequest* req) { DmaMgr_DMARomToRam(iter->romStart + (vrom - iter->vromStart), (u32)ram, size); found = true; - "No Press ROM:%08X RAM:%08X SIZE:%08X\n"; + if (0) { + osSyncPrintf("No Press ROM:%08X RAM:%08X SIZE:%08X\n", vrom, ram, size); + } } else { romStart = iter->romStart; romSize = iter->romEnd - iter->romStart; @@ -1819,7 +1815,9 @@ void DmaMgr_ProcessMsg(DmaRequest* req) { osSetThreadPri(NULL, Z_PRIORITY_DMAMGR); found = true; - " Press ROM:%X RAM:%X SIZE:%X\n"; + if (0) { + osSyncPrintf(" Press ROM:%X RAM:%X SIZE:%X\n", vrom, ram, size); + } } break; } @@ -1834,7 +1832,9 @@ void DmaMgr_ProcessMsg(DmaRequest* req) { DmaMgr_DMARomToRam(vrom, (u32)ram, size); - "No Press ROM:%08X RAM:%08X SIZE:%08X (非公式)\n"; + if (0) { + osSyncPrintf("No Press ROM:%08X RAM:%08X SIZE:%08X (非公式)\n", vrom, ram, size); + } } } @@ -1846,17 +1846,20 @@ void DmaMgr_ThreadEntry(void* arg0) { while (true) { osRecvMesg(&sDmaMgrMsgQueue, &msg, 1); req = (DmaRequest*)msg; - if (!req) { + if (req == NULL) { break; } - // strings present in .rodata but not actually used in the function, probably a removed function - "DMA登録受付 dmap=%08x\n"; + if (0) { + osSyncPrintf("DMA登録受付 dmap=%08x\n", req); + } DmaMgr_ProcessMsg(req); if (req->notifyQueue) { - osSendMesg(req->notifyQueue, req->notifyMsg, 0); - "osSendMesg: dmap=%08x, mq=%08x, m=%08x \n"; + osSendMesg(req->notifyQueue, req->notifyMsg, OS_MESG_NOBLOCK); + if (0) { + osSyncPrintf("osSendMesg: dmap=%08x, mq=%08x, m=%08x \n", req, req->notifyQueue, req->notifyMsg); + } } } osSyncPrintf("DMAマネージャスレッド実行終了\n"); @@ -1889,7 +1892,7 @@ s32 DmaMgr_SendRequestImpl(DmaRequest* req, u32 ram, u32 vrom, u32 size, u32 unk } } - osSendMesg(&sDmaMgrMsgQueue, req, 1); + osSendMesg(&sDmaMgrMsgQueue, req, OS_MESG_BLOCK); return 0; } @@ -1905,19 +1908,17 @@ s32 DmaMgr_SendRequest0(u32 ram, u32 vrom, u32 size) { return ret; } - osRecvMesg(&queue, NULL, 1); + osRecvMesg(&queue, NULL, OS_MESG_BLOCK); return 0; } -void DmaMgr_Init() { +void DmaMgr_Init(void) { const char** name; s32 idx; DmaEntry* iter; - if (_dmadataSegmentRomStart) {} // Necessary to match - DmaMgr_DMARomToRam((u32)_dmadataSegmentRomStart, (u32)_dmadataSegmentStart, - (u32)_dmadataSegmentRomEnd - (u32)_dmadataSegmentRomStart); + (u32)(_dmadataSegmentRomEnd - _dmadataSegmentRomStart)); osSyncPrintf("dma_rom_ad[]\n"); sDmaMgrDataExistError = 0; @@ -1949,7 +1950,7 @@ void DmaMgr_Init() { Fault_AddHungupAndCrash("../z_std_dma.c", 1055); } - osCreateMesgQueue(&sDmaMgrMsgQueue, sDmaMgrMsgs, sizeof(sDmaMgrMsgs) / sizeof(sDmaMgrMsgs[0])); + osCreateMesgQueue(&sDmaMgrMsgQueue, sDmaMgrMsgs, ARRAY_COUNT(sDmaMgrMsgs)); StackCheck_Init(&sDmaMgrStackInfo, sDmaMgrStack, sDmaMgrStack + sizeof(sDmaMgrStack), 0, 0x100, "dmamgr"); osCreateThread(&sDmaMgrThread, 0x12, &DmaMgr_ThreadEntry, 0, sDmaMgrStack + sizeof(sDmaMgrStack), Z_PRIORITY_DMAMGR); @@ -1968,7 +1969,6 @@ s32 DmaMgr_SendRequest1(void* ram0, u32 vrom, u32 size, const char* file, s32 li s32 ret; OSMesgQueue queue; OSMesg msg; - u32 ram = (u32)ram0; req.filename = file; diff --git a/src/code/PreRender.c b/src/code/PreRender.c index 8252572ce1..b5ed96604e 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 5a3fadc16f..fc347c494c 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 5a304171bf..089ee59758 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 2d3a12248d..ebe5307e97 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 e79e9e06be..03cbd6099a 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 dc13c246d7..01fb8e39b1 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; } +void Audio_SequenceChannelProcessScript(SequenceChannel* seqChannel); #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") - 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 1b2f73c480..6b7623b793 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 fe8097eb97..b264837dd8 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 768ece14f3..e3549db8bc 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 47d437e987..a04598b533 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 94e8fa0a1c..a11da6948e 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 17660b74e8..2f295716e5 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 fd8d220e2f..b8f4e1ce8d 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 88e86014a9..e221627779 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 2fbd7c452c..2f60901a10 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 bfe37bdfb2..65402c3e2c 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 ebf03760e2..1c731c9bdf 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 4f6b9f8c0f..7c0b43ac8a 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 d1bb1f36d3..5e2532ae34 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 7478bfe0bb..c89a086544 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 da6f94883b..113a472d8d 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 d290935838..d62a6578ef 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 827f10a40d..d92ec42bf3 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 2dcea2667d..91e5175523 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 32c10cb888..62c5d29167 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 a2bef505a6..76888438db 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 ce0d91c9e2..3efd822590 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 960aeea982..9a4303ad23 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 27fa908ab1..f79dc00504 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 9d568068cb..2ad106782c 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 1a8eeffec9..525a5b9228 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 238ca2439f..908fc675b8 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 c532681b93..e0c128cc10 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 b6aefeee23..d4d24138cf 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; + ListAlloc* ptr = &((ListAlloc*)data)[-1]; - 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 d651ff4e6c..c1ee12079c 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 cf74a8b57b..7e05463735 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 9da4804eb6..e423c6666d 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 a3e32d584c..e180c9f7f9 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 745a324931..e4e8a0d687 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 564cfbf6fb..2f0f571620 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 043ed8782e..a965e18a86 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 68f7ac7d03..c56bc91153 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 5b928cb1d2..9375b965bf 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 c995b7c034..cc68129e2d 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 1dc6d54959..6e43ea2f9d 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 aab3044653..8d3c280401 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 c72d8cbee6..9e65cdaa3e 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 6ca814f36d..608e6cf112 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 d2f1b34670..02f5153273 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 0ce2e74c28..5a926382e1 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 34e7823875..5ead2320c7 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 be55cb76cd..7311ce102b 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 7c333f80aa..ccab8a9f17 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 a03019b723..eccf2e948e 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 c02865a2da..1ab7e228a4 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; + s32 camId = WaterBox_GetCamDataIndex(colCtx, waterBox); + CamData* camData = colCtx->colHeader->cameraDataList; - camId = WaterBox_GetCamDataIndex(colCtx, waterBox); - - 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 33ae1a9777..cfd5152b51 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 30f71cda20..b5a8e9f2e9 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 91137e190e..6cb76f846a 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 d79a17c002..7a3d4d967e 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 7122f5d03b..725bf7b37a 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 78c74b9a2b..480645ea39 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 f035469e04..8bef699ad7 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 381a24f985..24512194d8 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 991d280ec9..4f66f25dfc 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 babfd19f82..90a27368ef 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 69d696ad3c..465175e89a 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 cd41d1dd16..c17f00b3f0 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 f7a62cac17..4fb154c8be 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 8ef9122780..d3326e0535 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 e70c1a81d2..79c922c731 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 d4c3d66558..945b74455d 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]; + TransitionTriforce* this = THIS; + s32 pad; + f32 rotation = this->transPos * 360.0f; - char pad2[4]; - f32 rotation; - - 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 3c0456ccea..68306e84d9 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 e01e0517ef..83938690d3 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 fd6cb3cbb7..db2443033c 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 a672f85262..9bea32d454 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 6f80b3ae1f..194b5988b1 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 54f90bb3bd..c8ffa4fad0 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 08f161c51e..9c4143437e 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 f992755a19..15b5b4c4ca 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 509c95145c..93fbdbd238 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 30752f531b..eaf0d6324b 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 d09ab08d3a..267180e1f1 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 9c1ca88615..72cd6694b1 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 40ac502403..51039feb3c 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 b9331e49df..5d8cc785be 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 d6ed609d21..3f4e11be59 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 3481b30a8a..ab47b67395 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 0a4ed75fbb..9f0d3ad587 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 340309e697..c00d0513c0 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 8bf332420c..f22fc7023d 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 4b802156da..ee49f50c87 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 4adf07ba6c..82ff5b776c 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 05070c2144..4fecad4cf6 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 107611d228..b21b43379b 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 30451a159c..a8c3324a57 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 28ddca1a40..646a26c70e 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; + f32 mx = mf->xx; + f32 my = mf->yx; + f32 mz = mf->zx; + f32 mw = mf->wx; - mx = mf->xx; - my = mf->yx; - mz = mf->zx; - 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 6f929678c8..307f564419 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 3374eeb5e0..974191ac26 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 be0600ba1d..0fb6177021 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 { diff --git a/src/libultra_boot_O1/__osDequeueThread.c b/src/libultra_boot_O1/__osDequeueThread.c index a29f007c90..14e9d346d8 100644 --- a/src/libultra_boot_O1/__osDequeueThread.c +++ b/src/libultra_boot_O1/__osDequeueThread.c @@ -1,10 +1,9 @@ #include "global.h" void __osDequeueThread(OSThread** queue, OSThread* thread) { - register OSThread** a2; - register OSThread* a3; - a2 = queue; - a3 = *a2; + register OSThread** a2 = queue; + register OSThread* a3 = *a2; + while (a3 != NULL) { if (a3 == thread) { *a2 = thread->next; diff --git a/src/libultra_boot_O1/__osResetGlobalIntMask.c b/src/libultra_boot_O1/__osResetGlobalIntMask.c index bf5a2466f3..c2561d712c 100644 --- a/src/libultra_boot_O1/__osResetGlobalIntMask.c +++ b/src/libultra_boot_O1/__osResetGlobalIntMask.c @@ -1,9 +1,8 @@ #include "global.h" void __osResetGlobalIntMask(u32 mask) { - register s32 prevInt; + register s32 prevInt = __osDisableInt(); - prevInt = __osDisableInt(); __OSGlobalIntMask &= ~(mask & ~0x401); __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O1/__osSetGlobalIntMask.c b/src/libultra_boot_O1/__osSetGlobalIntMask.c index 4f46523f28..6b7895d6d4 100644 --- a/src/libultra_boot_O1/__osSetGlobalIntMask.c +++ b/src/libultra_boot_O1/__osSetGlobalIntMask.c @@ -1,9 +1,8 @@ #include "global.h" void __osSetGlobalIntMask(u32 mask) { - register s32 prevInt; + register s32 prevInt = __osDisableInt(); - prevInt = __osDisableInt(); __OSGlobalIntMask |= mask; __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O1/__osSetHWIntrRoutine.c b/src/libultra_boot_O1/__osSetHWIntrRoutine.c index 03b6d974d2..b7ba0066ae 100644 --- a/src/libultra_boot_O1/__osSetHWIntrRoutine.c +++ b/src/libultra_boot_O1/__osSetHWIntrRoutine.c @@ -2,9 +2,7 @@ #include "ultra64/internal.h" void __osSetHWIntrRoutine(s32 idx, OSMesgQueue* queue, OSMesg msg) { - register s32 prevInt; - - prevInt = __osDisableInt(); + register s32 prevInt = __osDisableInt(); __osHwIntTable[idx].queue = queue; __osHwIntTable[idx].msg = msg; diff --git a/src/libultra_boot_O1/initialize.c b/src/libultra_boot_O1/initialize.c index e850919f09..2cbf35e256 100644 --- a/src/libultra_boot_O1/initialize.c +++ b/src/libultra_boot_O1/initialize.c @@ -80,5 +80,5 @@ void __osInitialize_common(void) { HW_REG(AI_BITRATE_REG, u32) = 0xf; } -void __osInitialize_autodetect() { +void __osInitialize_autodetect(void) { } diff --git a/src/libultra_boot_O1/osCreateMesgQueue.c b/src/libultra_boot_O1/osCreateMesgQueue.c index 31f1e2522e..87a4031f30 100644 --- a/src/libultra_boot_O1/osCreateMesgQueue.c +++ b/src/libultra_boot_O1/osCreateMesgQueue.c @@ -1,8 +1,8 @@ #include "global.h" void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 count) { - mq->mtqueue = __osThreadTail; - mq->fullqueue = __osThreadTail; + mq->mtqueue = (OSThread*)__osThreadTail; + mq->fullqueue = (OSThread*)__osThreadTail; mq->validCount = 0; mq->first = 0; mq->msgCount = count; diff --git a/src/libultra_boot_O1/osCreateThread.c b/src/libultra_boot_O1/osCreateThread.c index af14674148..f7cb65f74a 100644 --- a/src/libultra_boot_O1/osCreateThread.c +++ b/src/libultra_boot_O1/osCreateThread.c @@ -1,23 +1,23 @@ #include "global.h" OSThread* __osThreadTail[2] = { NULL, (OSThread*)-1 }; -OSThread* __osRunQueue = __osThreadTail; -OSThread* __osActiveQueue = __osThreadTail; +OSThread* __osRunQueue = (OSThread*)__osThreadTail; +OSThread* __osActiveQueue = (OSThread*)__osThreadTail; OSThread* __osRunningThread = NULL; OSThread* __osFaultedThread = NULL; void osCreateThread(OSThread* thread, OSId id, void (*entry)(void*), void* arg, void* sp, OSPri pri) { - register u32 s0; + register u32 prevInt; u32 t8; thread->id = id; thread->priority = pri; - thread->next = (struct OSThread_s*)NULL; - thread->queue = (struct OSThread_s**)NULL; + thread->next = NULL; + thread->queue = NULL; thread->context.pc = (u32)entry; - thread->context.a0 = (u64)arg; - thread->context.sp = (u64)sp - 16; - thread->context.ra = (u64)__osCleanupThread; + thread->context.a0 = arg; + thread->context.sp = (u64)(s32)sp - 16; + thread->context.ra = __osCleanupThread; t8 = 0x3FFF01; thread->context.sr = (t8 & 0xFF01) | 2; thread->context.rcp = (t8 & 0x3F0000) >> 16; @@ -26,8 +26,8 @@ void osCreateThread(OSThread* thread, OSId id, void (*entry)(void*), void* arg, thread->state = 1; thread->flags = 0; - s0 = __osDisableInt(); + prevInt = __osDisableInt(); thread->tlnext = __osActiveQueue; __osActiveQueue = thread; - __osRestoreInt(s0); + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O1/osDestroyThread.c b/src/libultra_boot_O1/osDestroyThread.c index 079cd78e06..9d8fef2544 100644 --- a/src/libultra_boot_O1/osDestroyThread.c +++ b/src/libultra_boot_O1/osDestroyThread.c @@ -1,13 +1,10 @@ #include "global.h" void osDestroyThread(OSThread* thread) { - register s32 int_disabled; - + register s32 prevInt = __osDisableInt(); register OSThread* s1; register OSThread* s2; - int_disabled = __osDisableInt(); - if (thread == NULL) { thread = __osRunningThread; @@ -33,5 +30,5 @@ void osDestroyThread(OSThread* thread) { __osDispatchThread(); } - __osRestoreInt(int_disabled); + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O1/osGetMemSize.c b/src/libultra_boot_O1/osGetMemSize.c index 00d180dc39..78eac6ebcf 100644 --- a/src/libultra_boot_O1/osGetMemSize.c +++ b/src/libultra_boot_O1/osGetMemSize.c @@ -4,12 +4,10 @@ u32 osGetMemSize(void) { u32* ptr; - u32 size; + u32 size = 0x400000; u32 data0; u32 data1; - size = 0x400000; - while (size < 0x800000) { ptr = (u32*)(0xA0000000 + size); diff --git a/src/libultra_boot_O1/osGetTime.c b/src/libultra_boot_O1/osGetTime.c index f053ba8192..9a42f06119 100644 --- a/src/libultra_boot_O1/osGetTime.c +++ b/src/libultra_boot_O1/osGetTime.c @@ -1,16 +1,15 @@ #include "global.h" OSTime osGetTime(void) { - u32 sp34; - u32 sp30; - u64 t1; - register u32 s0; + u32 count; + u32 base; + u64 t; + register u32 prevInt = __osDisableInt(); - s0 = __osDisableInt(); - sp34 = osGetCount(); - sp30 = sp34 - __osBaseCounter; - t1 = __osCurrentTime; - __osRestoreInt(s0); + count = osGetCount(); + base = count - __osBaseCounter; + t = __osCurrentTime; + __osRestoreInt(prevInt); - return sp30 + t1; + return base + t; } diff --git a/src/libultra_boot_O1/osJamMesg.c b/src/libultra_boot_O1/osJamMesg.c index c0aa9a4b12..997c8fe65f 100644 --- a/src/libultra_boot_O1/osJamMesg.c +++ b/src/libultra_boot_O1/osJamMesg.c @@ -1,14 +1,14 @@ #include "global.h" s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) { - register s32 int_disabled; - int_disabled = __osDisableInt(); + register s32 prevInt = __osDisableInt(); + while (mq->validCount >= mq->msgCount) { if (flag == OS_MESG_BLOCK) { __osRunningThread->state = OS_STATE_WAITING; __osEnqueueAndYield(&mq->fullqueue); } else { - __osRestoreInt(int_disabled); + __osRestoreInt(prevInt); return -1; } } @@ -19,6 +19,6 @@ s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) { if (mq->mtqueue->next != NULL) { osStartThread(__osPopThread(&mq->mtqueue)); } - __osRestoreInt(int_disabled); + __osRestoreInt(prevInt); return 0; } diff --git a/src/libultra_boot_O1/osRecvMesg.c b/src/libultra_boot_O1/osRecvMesg.c index 3cb5a8a47f..d6de78adb7 100644 --- a/src/libultra_boot_O1/osRecvMesg.c +++ b/src/libultra_boot_O1/osRecvMesg.c @@ -1,15 +1,15 @@ #include "global.h" s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flag) { - register s32 s0 = __osDisableInt(); + register s32 prevInt = __osDisableInt(); while (mq->validCount == 0) { if (flag == OS_MESG_NOBLOCK) { - __osRestoreInt(s0); + __osRestoreInt(prevInt); return -1; } __osRunningThread->state = 8; - __osEnqueueAndYield(mq); + __osEnqueueAndYield((OSThread**)mq); } if (msg != NULL) { @@ -23,7 +23,7 @@ s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flag) { osStartThread(__osPopThread(&mq->fullqueue)); } - __osRestoreInt(s0); + __osRestoreInt(prevInt); return 0; } diff --git a/src/libultra_boot_O1/osSendMesg.c b/src/libultra_boot_O1/osSendMesg.c index 617d3bb127..eafd9da8b3 100644 --- a/src/libultra_boot_O1/osSendMesg.c +++ b/src/libultra_boot_O1/osSendMesg.c @@ -1,7 +1,7 @@ #include "global.h" s32 osSendMesg(OSMesgQueue* mq, OSMesg mesg, s32 flag) { - register u32 s0 = __osDisableInt(); + register u32 prevInt = __osDisableInt(); register u32 index; while (mq->validCount >= mq->msgCount) { @@ -9,7 +9,7 @@ s32 osSendMesg(OSMesgQueue* mq, OSMesg mesg, s32 flag) { __osRunningThread->state = 8; __osEnqueueAndYield(&mq->fullqueue); } else { - __osRestoreInt(s0); + __osRestoreInt(prevInt); return -1; } } @@ -22,7 +22,7 @@ s32 osSendMesg(OSMesgQueue* mq, OSMesg mesg, s32 flag) { osStartThread(__osPopThread(&mq->mtqueue)); } - __osRestoreInt(s0); + __osRestoreInt(prevInt); return 0; } diff --git a/src/libultra_boot_O1/osSetEventMesg.c b/src/libultra_boot_O1/osSetEventMesg.c index 615ee24457..e018810b03 100644 --- a/src/libultra_boot_O1/osSetEventMesg.c +++ b/src/libultra_boot_O1/osSetEventMesg.c @@ -6,20 +6,18 @@ __OSEventState __osEventStateTab[OS_NUM_EVENTS + 1]; u32 __osPreNMI = 0; void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg msg) { - register u32 int_disabled; - __OSEventState* msgs; + register u32 prevInt = __osDisableInt(); + __OSEventState* msgs = __osEventStateTab + e; - int_disabled = __osDisableInt(); - msgs = __osEventStateTab + e; msgs->queue = mq; msgs->msg = msg; if (e == OS_EVENT_PRENMI) { if (__osShutdown && !__osPreNMI) { - osSendMesg(mq, msg, 0); + osSendMesg(mq, msg, OS_MESG_NOBLOCK); } __osPreNMI = true; } - __osRestoreInt(int_disabled); + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O1/osSetThreadPri.c b/src/libultra_boot_O1/osSetThreadPri.c index b0134d27f1..572d3495ae 100644 --- a/src/libultra_boot_O1/osSetThreadPri.c +++ b/src/libultra_boot_O1/osSetThreadPri.c @@ -1,7 +1,7 @@ #include "global.h" void osSetThreadPri(OSThread* thread, OSPri pri) { - register u32 s0 = __osDisableInt(); + register u32 prevInt = __osDisableInt(); if (thread == NULL) { thread = __osRunningThread; @@ -19,5 +19,5 @@ void osSetThreadPri(OSThread* thread, OSPri pri) { } } - __osRestoreInt(s0); + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O1/osStartThread.c b/src/libultra_boot_O1/osStartThread.c index 6b4a53de25..80d1f25646 100644 --- a/src/libultra_boot_O1/osStartThread.c +++ b/src/libultra_boot_O1/osStartThread.c @@ -1,7 +1,7 @@ #include "global.h" void osStartThread(OSThread* thread) { - register u32 s0 = __osDisableInt(); + register u32 prevInt = __osDisableInt(); switch (thread->state) { case 8: @@ -29,5 +29,5 @@ void osStartThread(OSThread* thread) { } } - __osRestoreInt(s0); + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O1/osStopThread.c b/src/libultra_boot_O1/osStopThread.c index 5f005d41a9..eebd8ce9b7 100644 --- a/src/libultra_boot_O1/osStopThread.c +++ b/src/libultra_boot_O1/osStopThread.c @@ -1,7 +1,7 @@ #include "global.h" void osStopThread(OSThread* thread) { - register u32 s0 = __osDisableInt(); + register u32 prevInt = __osDisableInt(); register u32 state; if (thread == NULL) { @@ -22,5 +22,5 @@ void osStopThread(OSThread* thread) { break; } - __osRestoreInt(s0); + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O1/osYieldThread.c b/src/libultra_boot_O1/osYieldThread.c index 3c716032db..af9e15a2c1 100644 --- a/src/libultra_boot_O1/osYieldThread.c +++ b/src/libultra_boot_O1/osYieldThread.c @@ -1,9 +1,8 @@ #include "global.h" -void osYieldThread() { - register u32 prevInt; +void osYieldThread(void) { + register u32 prevInt = __osDisableInt(); - prevInt = __osDisableInt(); __osRunningThread->state = OS_STATE_RUNNABLE; __osEnqueueAndYield(&__osRunQueue); __osRestoreInt(prevInt); diff --git a/src/libultra_boot_O1/piacs.c b/src/libultra_boot_O1/piacs.c index 9a28659455..681e5f0aeb 100644 --- a/src/libultra_boot_O1/piacs.c +++ b/src/libultra_boot_O1/piacs.c @@ -22,5 +22,5 @@ void __osPiGetAccess(void) { } void __osPiRelAccess(void) { - osSendMesg(&__osPiAccessQueue, 0, OS_MESG_NOBLOCK); + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); } diff --git a/src/libultra_boot_O1/timerintr.c b/src/libultra_boot_O1/timerintr.c index f2209cc0d8..7afcb13362 100644 --- a/src/libultra_boot_O1/timerintr.c +++ b/src/libultra_boot_O1/timerintr.c @@ -7,7 +7,7 @@ u32 __osViIntrCount; u32 __osTimerCounter; OSTimer* __osTimerList = &__osBaseTimer; -void __osTimerServicesInit() { +void __osTimerServicesInit(void) { __osCurrentTime = 0; __osBaseCounter = 0; __osViIntrCount = 0; @@ -19,76 +19,83 @@ void __osTimerServicesInit() { __osTimerList->msg = NULL; } -void __osTimerInterrupt() { - OSTimer* sp24; +void __osTimerInterrupt(void) { + OSTimer* timer; u32 sp20; u32 sp1c; + if (__osTimerList->next == __osTimerList) { return; } - while (1) { - sp24 = __osTimerList->next; - if (sp24 == __osTimerList) { + + while (true) { + timer = __osTimerList->next; + if (timer == __osTimerList) { __osSetCompare(0); __osTimerCounter = 0; break; } + sp20 = osGetCount(); sp1c = sp20 - __osTimerCounter; __osTimerCounter = sp20; - if (sp1c < sp24->value) { - sp24->value -= sp1c; - __osSetTimerIntr(sp24->value); - return; - } else { - sp24->prev->next = sp24->next; - sp24->next->prev = sp24->prev; - sp24->next = NULL; - sp24->prev = NULL; - if (sp24->mq != NULL) { - osSendMesg(sp24->mq, sp24->msg, OS_MESG_NOBLOCK); - } - if (sp24->interval != 0) { - sp24->value = sp24->interval; - __osInsertTimer(sp24); - } + if (sp1c < timer->value) { + timer->value -= sp1c; + __osSetTimerIntr(timer->value); + break; + } + + timer->prev->next = timer->next; + timer->next->prev = timer->prev; + timer->next = NULL; + timer->prev = NULL; + if (timer->mq != NULL) { + osSendMesg(timer->mq, timer->msg, OS_MESG_NOBLOCK); + } + if (timer->interval != 0) { + timer->value = timer->interval; + __osInsertTimer(timer); } } } -void __osSetTimerIntr(OSTime tim) { - OSTime NewTime; - u32 savedMask; +void __osSetTimerIntr(OSTime time) { + OSTime newTime; + u32 prevInt; - if (tim < 468) { - tim = 468; + if (time < 468) { + time = 468; } - savedMask = __osDisableInt(); + prevInt = __osDisableInt(); __osTimerCounter = osGetCount(); - NewTime = tim + __osTimerCounter; - __osSetCompare((u32)NewTime); - __osRestoreInt(savedMask); + newTime = time + __osTimerCounter; + __osSetCompare((u32)newTime); + __osRestoreInt(prevInt); } -OSTime __osInsertTimer(OSTimer* a0) { - OSTimer* sp34; - u64 sp28; - s32 intDisabled; - intDisabled = __osDisableInt(); - for (sp34 = __osTimerList->next, sp28 = a0->value; sp34 != __osTimerList && sp28 > sp34->value; - sp28 -= sp34->value, sp34 = sp34->next) { +OSTime __osInsertTimer(OSTimer* timer) { + OSTimer* nextTimer; + u64 timerValue; + s32 prevInt = __osDisableInt(); + + for (nextTimer = __osTimerList->next, timerValue = timer->value; + nextTimer != __osTimerList && timerValue > nextTimer->value; + timerValue -= nextTimer->value, nextTimer = nextTimer->next) { ; } - a0->value = sp28; - if (sp34 != __osTimerList) { - sp34->value -= sp28; + + timer->value = timerValue; + if (nextTimer != __osTimerList) { + nextTimer->value -= timerValue; } - a0->next = sp34; - a0->prev = sp34->prev; - sp34->prev->next = a0; - sp34->prev = a0; - __osRestoreInt(intDisabled); - return sp28; + + timer->next = nextTimer; + timer->prev = nextTimer->prev; + nextTimer->prev->next = timer; + nextTimer->prev = timer; + __osRestoreInt(prevInt); + + return timerValue; } diff --git a/src/libultra_boot_O2/_Ldtob.c b/src/libultra_boot_O2/_Ldtob.c index 68a9c5404e..f7a6d1208f 100644 --- a/src/libultra_boot_O2/_Ldtob.c +++ b/src/libultra_boot_O2/_Ldtob.c @@ -42,9 +42,9 @@ const f64 D_800122E0[] = { 10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 1 void _Ldtob(_Pft* args, u8 type) { u8 buff[BUFF_LEN]; - u8* ptr; + u8* ptr = buff; u32 sp70; - f64 val; + f64 val = args->v.ld; /* maybe struct? */ s16 err; s16 nsig; @@ -60,14 +60,10 @@ void _Ldtob(_Pft* args, u8 type) { u8 drop; s32 n2; - ptr = buff; - val = args->v.ld; if (args->prec < 0) { args->prec = 6; - } else { - if (args->prec == 0 && (type == 'g' || type == 'G')) { - args->prec = 1; - } + } else if (args->prec == 0 && (type == 'g' || type == 'G')) { + args->prec = 1; } err = _Ldunscale(&exp, (_Pft*)args); if (err > 0) { @@ -90,18 +86,16 @@ void _Ldtob(_Pft* args, u8 type) { val *= D_800122E0[i]; } } - } else { - if (exp > 0) { - factor = 1; - exp &= ~3; + } else if (exp > 0) { + factor = 1; + exp &= ~3; - for (n = exp, i = 0; n > 0; n >>= 1, i++) { - if ((n & 1) != 0) { - factor *= D_800122E0[i]; - } + for (n = exp, i = 0; n > 0; n >>= 1, i++) { + if ((n & 1) != 0) { + factor *= D_800122E0[i]; } - val /= factor; } + val /= factor; } gen = ((type == 'f') ? exp + 10 : 6) + args->prec; if (gen > 0x13) { @@ -157,27 +151,28 @@ void _Ldtob(_Pft* args, u8 type) { } s16 _Ldunscale(s16* pex, _Pft* px) { - u16* ps = (u16*)px; s16 xchar = (ps[_D0] & _DMASK) >> _DOFF; + if (xchar == _DMAX) { /* NaN or INF */ *pex = 0; return (s16)(ps[_D0] & _DFRAC || ps[_D1] || ps[_D2] || ps[_D3] ? NAN : INF); } else if (0 < xchar) { ps[_D0] = (ps[_D0] & ~_DMASK) | (_DBIAS << _DOFF); *pex = xchar - (_DBIAS - 1); - return (FINITE); + return FINITE; } if (0 > xchar) { return NAN; } else { *pex = 0; - return (0); + return 0; } } void _Genld(_Pft* px, u8 code, u8* p, s16 nsig, s16 xexp) { u8 point = '.'; + if (nsig <= 0) { nsig = 1, diff --git a/src/libultra_boot_O2/_Litob.c b/src/libultra_boot_O2/_Litob.c index 0f9452124f..2f8152a109 100644 --- a/src/libultra_boot_O2/_Litob.c +++ b/src/libultra_boot_O2/_Litob.c @@ -7,20 +7,20 @@ u8 D_8000AF84[] = "0123456789ABCDEF"; void _Litob(_Pft* args, u8 type) { u8 buff[BUFF_LEN]; - const u8* num_map; + const u8* numMap; s32 base; - s32 buff_ind; + s32 idx; u64 num; lldiv_t quotrem; if (type == 'X') { - num_map = D_8000AF84; + numMap = D_8000AF84; } else { - num_map = D_8000AF70; + numMap = D_8000AF70; } base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16); - buff_ind = BUFF_LEN; + idx = BUFF_LEN; num = args->v.ll; if ((type == 'd' || type == 'i') && args->v.ll < 0) { @@ -28,29 +28,29 @@ void _Litob(_Pft* args, u8 type) { } if (num != 0 || args->prec != 0) { - buff[--buff_ind] = num_map[num % base]; + buff[--idx] = numMap[num % base]; } args->v.ll = num / base; - while (args->v.ll > 0 && buff_ind > 0) { + while (args->v.ll > 0 && idx > 0) { quotrem = lldiv(args->v.ll, base); args->v.ll = quotrem.quot; - buff[--buff_ind] = num_map[quotrem.rem]; + buff[--idx] = numMap[quotrem.rem]; } - args->n1 = BUFF_LEN - buff_ind; + args->n1 = BUFF_LEN - idx; - memcpy(args->s, buff + buff_ind, args->n1); + memcpy(args->s, buff + idx, args->n1); if (args->n1 < args->prec) { args->nz0 = args->prec - args->n1; } if (args->prec < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) { - buff_ind = args->width - args->n0 - args->nz0 - args->n1; - if (buff_ind > 0) { - args->nz0 += buff_ind; + idx = args->width - args->n0 - args->nz0 - args->n1; + if (idx > 0) { + args->nz0 += idx; } } } diff --git a/src/libultra_boot_O2/_Printf.c b/src/libultra_boot_O2/_Printf.c index e8fa2c6961..c9ac6c5244 100644 --- a/src/libultra_boot_O2/_Printf.c +++ b/src/libultra_boot_O2/_Printf.c @@ -4,6 +4,7 @@ for (i = 0; *a >= '0' && *a <= '9'; a++) \ if (i < 999) \ i = *a + i * 10 - '0'; + #define _PROUT(fmt, _size) \ if (_size > 0) { \ arg = (void*)pfn(arg, fmt, _size); \ @@ -30,20 +31,19 @@ char zeroes[] = "00000000000000000000000000000000"; void _Putfld(_Pft*, va_list*, u8, u8*); -s32 _Printf(char* (*pfn)(char*, const char*, size_t), char* arg, const char* fmt, va_list ap) { +s32 _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap) { _Pft x; x.nchar = 0; - while (1) { - const u8* s; - u8 c; - u8* t; - static const u8 fchar[] = " +-#0"; + while (true) { + static const char fchar[] = " +-#0"; static const u32 fbit[] = { FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0 }; + const u8* s = (u8*)fmt; + u8 c; + const char* t; u8 ac[0x20]; - s = (u8*)fmt; while ((c = *s) != 0 && c != '%') { s++; } @@ -105,7 +105,6 @@ void _Putfld(_Pft* px, va_list* pap, u8 code, u8* ac) { px->n0 = px->nz0 = px->n1 = px->nz1 = px->n2 = px->nz2 = 0; switch (code) { - case 'c': ac[px->n0++] = va_arg(*pap, u32); break; @@ -136,7 +135,6 @@ void _Putfld(_Pft* px, va_list* pap, u8 code, u8* ac) { _Litob(px, code); break; - case 'x': case 'X': case 'u': @@ -165,7 +163,6 @@ void _Putfld(_Pft* px, va_list* pap, u8 code, u8* ac) { px->s = (char*)&ac[px->n0]; _Litob(px, code); break; - case 'e': case 'f': case 'g': @@ -186,7 +183,6 @@ void _Putfld(_Pft* px, va_list* pap, u8 code, u8* ac) { px->s = (char*)&ac[px->n0]; _Ldtob(px, code); break; - case 'n': if (px->qual == 'h') { *(va_arg(*pap, u16*)) = px->nchar; @@ -200,11 +196,10 @@ void _Putfld(_Pft* px, va_list* pap, u8 code, u8* ac) { break; case 'p': - px->v.ll = (s64)va_arg(*pap, void*); + px->v.ll = va_arg(*pap, void*); px->s = (char*)&ac[px->n0]; _Litob(px, 'x'); break; - case 's': px->s = va_arg(*pap, char*); px->n1 = strlen(px->s); @@ -212,11 +207,9 @@ void _Putfld(_Pft* px, va_list* pap, u8 code, u8* ac) { px->n1 = px->prec; } break; - case '%': ac[px->n0++] = '%'; break; - default: ac[px->n0++] = code; break; diff --git a/src/libultra_boot_O2/__osDevMgrMain.c b/src/libultra_boot_O2/__osDevMgrMain.c index e481c33fb1..0612bbee1e 100644 --- a/src/libultra_boot_O2/__osDevMgrMain.c +++ b/src/libultra_boot_O2/__osDevMgrMain.c @@ -5,14 +5,13 @@ void __osDevMgrMain(void* arg) { OSIoMesg* ioMesg; OSMesg sp70; OSMesg sp6C; - OSMgrArgs* arg0; + OSMgrArgs* arg0 = (OSMgrArgs*)arg; __OSTranxInfo* transfer; __OSBlockInfo* block; s32 phi_s2; s32 phi_s0; u32 sp54; - arg0 = (OSMgrArgs*)arg; ioMesg = NULL; while (true) { diff --git a/src/libultra_boot_O2/__osPiRawStartDma.c b/src/libultra_boot_O2/__osPiRawStartDma.c index d323a66b3b..8fda513516 100644 --- a/src/libultra_boot_O2/__osPiRawStartDma.c +++ b/src/libultra_boot_O2/__osPiRawStartDma.c @@ -1,8 +1,8 @@ #include "global.h" s32 __osPiRawStartDma(s32 dir, u32 cartAddr, void* dramAddr, size_t size) { - register s32 status; - status = HW_REG(PI_STATUS_REG, u32); + register s32 status = HW_REG(PI_STATUS_REG, u32); + while (status & (PI_STATUS_BUSY | PI_STATUS_IOBUSY | PI_STATUS_ERROR)) { status = HW_REG(PI_STATUS_REG, u32); } diff --git a/src/libultra_boot_O2/__osSiDeviceBusy.c b/src/libultra_boot_O2/__osSiDeviceBusy.c index ec2462f83e..7898153124 100644 --- a/src/libultra_boot_O2/__osSiDeviceBusy.c +++ b/src/libultra_boot_O2/__osSiDeviceBusy.c @@ -1,8 +1,8 @@ #include "global.h" -s32 __osSiDeviceBusy() { - register u32 status; - status = HW_REG(SI_STATUS_REG, u32); +s32 __osSiDeviceBusy(void) { + register u32 status = HW_REG(SI_STATUS_REG, u32); + if (status & (SI_STATUS_DMA_BUSY | SI_STATUS_IO_READ_BUSY)) { return true; } else { diff --git a/src/libultra_boot_O2/__osViGetCurrentContext.c b/src/libultra_boot_O2/__osViGetCurrentContext.c index f83a2d0ee0..1e3c6ffa3c 100644 --- a/src/libultra_boot_O2/__osViGetCurrentContext.c +++ b/src/libultra_boot_O2/__osViGetCurrentContext.c @@ -1,5 +1,5 @@ #include "global.h" -OSViContext* __osViGetCurrentContext() { +OSViContext* __osViGetCurrentContext(void) { return __osViCurr; } diff --git a/src/libultra_boot_O2/__osViInit.c b/src/libultra_boot_O2/__osViInit.c index 43f2abb028..91d5759b78 100644 --- a/src/libultra_boot_O2/__osViInit.c +++ b/src/libultra_boot_O2/__osViInit.c @@ -4,7 +4,7 @@ OSViContext vi[2] = { 0 }; OSViContext* __osViCurr = &vi[0]; OSViContext* __osViNext = &vi[1]; -void __osViInit() { +void __osViInit(void) { bzero(vi, sizeof(vi)); __osViCurr = &vi[0]; __osViNext = &vi[1]; diff --git a/src/libultra_boot_O2/__osViSwapContext.c b/src/libultra_boot_O2/__osViSwapContext.c index 8f202d17c3..aeadb75af9 100644 --- a/src/libultra_boot_O2/__osViSwapContext.c +++ b/src/libultra_boot_O2/__osViSwapContext.c @@ -1,8 +1,8 @@ #include "global.h" -void __osViSwapContext() { - register OSViMode* s0; - register OSViContext* s1; +void __osViSwapContext(void) { + register OSViMode* viMode; + register OSViContext* viNext; u32 origin; u32 hStart; u32 vstart; @@ -11,52 +11,52 @@ void __osViSwapContext() { register u32 s2; field = 0; - s1 = __osViNext; - s0 = s1->modep; + viNext = __osViNext; + viMode = viNext->modep; field = HW_REG(VI_V_CURRENT_LINE_REG, u32) & 1; - s2 = osVirtualToPhysical(s1->buffer); - origin = (s0->fldRegs[field].origin) + s2; - if (s1->state & 2) { - s1->x.scale |= s0->comRegs.xScale & ~0xfff; + s2 = osVirtualToPhysical(viNext->buffer); + origin = (viMode->fldRegs[field].origin) + s2; + if (viNext->state & 2) { + viNext->x.scale |= viMode->comRegs.xScale & ~0xfff; } else { - s1->x.scale = s0->comRegs.xScale; + viNext->x.scale = viMode->comRegs.xScale; } - if (s1->state & 4) { - sp34 = (u32)(s0->fldRegs[field].yScale & 0xfff); - s1->y.scale = s1->y.factor * sp34; - s1->y.scale |= s0->fldRegs[field].yScale & ~0xfff; + if (viNext->state & 4) { + sp34 = (u32)(viMode->fldRegs[field].yScale & 0xfff); + viNext->y.scale = viNext->y.factor * sp34; + viNext->y.scale |= viMode->fldRegs[field].yScale & ~0xfff; } else { - s1->y.scale = s0->fldRegs[field].yScale; + viNext->y.scale = viMode->fldRegs[field].yScale; } - vstart = (s0->fldRegs[field].vStart - (__additional_scanline << 0x10)) + __additional_scanline; - hStart = s0->comRegs.hStart; + vstart = (viMode->fldRegs[field].vStart - (__additional_scanline << 0x10)) + __additional_scanline; + hStart = viMode->comRegs.hStart; - if (s1->state & 0x20) { + if (viNext->state & 0x20) { hStart = 0; } - if (s1->state & 0x40) { - s1->y.scale = 0; - origin = osVirtualToPhysical(s1->buffer); + if (viNext->state & 0x40) { + viNext->y.scale = 0; + origin = osVirtualToPhysical(viNext->buffer); } - if (s1->state & 0x80) { - s1->y.scale = (s1->y.offset << 0x10) & 0x3ff0000; - origin = osVirtualToPhysical(s1->buffer); + if (viNext->state & 0x80) { + viNext->y.scale = (viNext->y.offset << 0x10) & 0x3ff0000; + origin = osVirtualToPhysical(viNext->buffer); } HW_REG(VI_ORIGIN_REG, u32) = origin; - HW_REG(VI_WIDTH_REG, u32) = s0->comRegs.width; - HW_REG(VI_BURST_REG, u32) = s0->comRegs.burst; - HW_REG(VI_V_SYNC_REG, u32) = s0->comRegs.vSync; - HW_REG(VI_H_SYNC_REG, u32) = s0->comRegs.hSync; - HW_REG(VI_LEAP_REG, u32) = s0->comRegs.leap; + HW_REG(VI_WIDTH_REG, u32) = viMode->comRegs.width; + HW_REG(VI_BURST_REG, u32) = viMode->comRegs.burst; + HW_REG(VI_V_SYNC_REG, u32) = viMode->comRegs.vSync; + HW_REG(VI_H_SYNC_REG, u32) = viMode->comRegs.hSync; + HW_REG(VI_LEAP_REG, u32) = viMode->comRegs.leap; HW_REG(VI_H_START_REG, u32) = hStart; HW_REG(VI_V_START_REG, u32) = vstart; - HW_REG(VI_V_BURST_REG, u32) = s0->fldRegs[field].vBurst; - HW_REG(VI_INTR_REG, u32) = s0->fldRegs[field].vIntr; - HW_REG(VI_X_SCALE_REG, u32) = s1->x.scale; - HW_REG(VI_Y_SCALE_REG, u32) = s1->y.scale; - HW_REG(VI_CONTROL_REG, u32) = s1->features; + HW_REG(VI_V_BURST_REG, u32) = viMode->fldRegs[field].vBurst; + HW_REG(VI_INTR_REG, u32) = viMode->fldRegs[field].vIntr; + HW_REG(VI_X_SCALE_REG, u32) = viNext->x.scale; + HW_REG(VI_Y_SCALE_REG, u32) = viNext->y.scale; + HW_REG(VI_CONTROL_REG, u32) = viNext->features; __osViNext = __osViCurr; - __osViCurr = s1; + __osViCurr = viNext; *__osViNext = *__osViCurr; } diff --git a/src/libultra_boot_O2/osCartRomInit.c b/src/libultra_boot_O2/osCartRomInit.c index a46e0e09b6..ff5dc82928 100644 --- a/src/libultra_boot_O2/osCartRomInit.c +++ b/src/libultra_boot_O2/osCartRomInit.c @@ -2,7 +2,7 @@ OSPiHandle __CartRomHandle; -OSPiHandle* osCartRomInit() { +OSPiHandle* osCartRomInit(void) { register u32 a; register s32 status; register u32 prevInt; diff --git a/src/libultra_boot_O2/osDriveRomInit.c b/src/libultra_boot_O2/osDriveRomInit.c index 83b3c9fc66..af478f0e93 100644 --- a/src/libultra_boot_O2/osDriveRomInit.c +++ b/src/libultra_boot_O2/osDriveRomInit.c @@ -2,7 +2,7 @@ OSPiHandle __DriveRomHandle; -OSPiHandle* osDriveRomInit() { +OSPiHandle* osDriveRomInit(void) { register s32 status; register u32 a; register s32 prevInt; diff --git a/src/libultra_boot_O2/osEPiStartDma.c b/src/libultra_boot_O2/osEPiStartDma.c index f1dccc8333..7547fb6953 100644 --- a/src/libultra_boot_O2/osEPiStartDma.c +++ b/src/libultra_boot_O2/osEPiStartDma.c @@ -3,6 +3,7 @@ s32 osEPiStartDma(OSPiHandle* handle, OSIoMesg* mb, s32 direction) { s32 ret; + if (!__osPiDevMgr.initialized) { return -1; } @@ -15,9 +16,9 @@ s32 osEPiStartDma(OSPiHandle* handle, OSIoMesg* mb, s32 direction) { } if (mb->hdr.pri == 1) { - ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, 0); + ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); } else { - ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, 0); + ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); } return ret; diff --git a/src/libultra_boot_O2/osPiGetCmdQueue.c b/src/libultra_boot_O2/osPiGetCmdQueue.c index a4454ec825..f0e32ae20b 100644 --- a/src/libultra_boot_O2/osPiGetCmdQueue.c +++ b/src/libultra_boot_O2/osPiGetCmdQueue.c @@ -1,7 +1,7 @@ #include "global.h" #include "ultra64/internal.h" -OSMesgQueue* osPiGetCmdQueue() { +OSMesgQueue* osPiGetCmdQueue(void) { if (!__osPiDevMgr.initialized) { return NULL; } diff --git a/src/libultra_boot_O2/osViBlack.c b/src/libultra_boot_O2/osViBlack.c index 3e877a387c..6571688660 100644 --- a/src/libultra_boot_O2/osViBlack.c +++ b/src/libultra_boot_O2/osViBlack.c @@ -2,11 +2,12 @@ // TODO: name magic constants void osViBlack(u8 active) { - register u32 int_disabled = __osDisableInt(); + register u32 prevInt = __osDisableInt(); + if (active) { __osViNext->state |= 0x20; } else { __osViNext->state &= ~0x20; } - __osRestoreInt(int_disabled); + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O2/osViGetNextFramebuffer.c b/src/libultra_boot_O2/osViGetNextFramebuffer.c index 86f8549ab5..aaf44ce4a9 100644 --- a/src/libultra_boot_O2/osViGetNextFramebuffer.c +++ b/src/libultra_boot_O2/osViGetNextFramebuffer.c @@ -1,8 +1,9 @@ #include "global.h" -void* osViGetNextFramebuffer() { +void* osViGetNextFramebuffer(void) { s32 prevInt = __osDisableInt(); void* buff = __osViNext->buffer; + __osRestoreInt(prevInt); return buff; } diff --git a/src/libultra_boot_O2/osViSetMode.c b/src/libultra_boot_O2/osViSetMode.c index db3e7fc2a6..621b7ca4ac 100644 --- a/src/libultra_boot_O2/osViSetMode.c +++ b/src/libultra_boot_O2/osViSetMode.c @@ -1,9 +1,11 @@ #include "global.h" void osViSetMode(OSViMode* mode) { - register u32 int_disabled = __osDisableInt(); + register u32 prevInt = __osDisableInt(); + __osViNext->modep = mode; __osViNext->state = 1; __osViNext->features = __osViNext->modep->comRegs.ctrl; - __osRestoreInt(int_disabled); + + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O2/osViSetSpecialFeatures.c b/src/libultra_boot_O2/osViSetSpecialFeatures.c index 63e8ab5f31..e5bd21029d 100644 --- a/src/libultra_boot_O2/osViSetSpecialFeatures.c +++ b/src/libultra_boot_O2/osViSetSpecialFeatures.c @@ -1,7 +1,8 @@ #include "global.h" void osViSetSpecialFeatures(u32 func) { - register u32 int_disabled = __osDisableInt(); + register u32 prevInt = __osDisableInt(); + if (func & OS_VI_GAMMA_ON) { __osViNext->features |= OS_VI_GAMMA; } @@ -32,5 +33,6 @@ void osViSetSpecialFeatures(u32 func) { __osViNext->features |= __osViNext->modep->comRegs.ctrl & (OS_VI_UNK200 | OS_VI_UNK100); } __osViNext->state |= 8; - __osRestoreInt(int_disabled); + + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O2/osViSetXScale.c b/src/libultra_boot_O2/osViSetXScale.c index e6a9ec6bb6..21b4f7aeaf 100644 --- a/src/libultra_boot_O2/osViSetXScale.c +++ b/src/libultra_boot_O2/osViSetXScale.c @@ -2,16 +2,13 @@ void osViSetXScale(f32 value) { register u32 nomValue; - register u32 saveMask; - - saveMask = __osDisableInt(); + register u32 prevInt = __osDisableInt(); __osViNext->x.factor = value; - __osViNext->state |= 0x2; nomValue = __osViNext->modep->comRegs.xScale & 0xfff; __osViNext->x.scale = (u32)(__osViNext->x.factor * nomValue) & 0xFFF; - __osRestoreInt(saveMask); + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O2/osViSetYScale.c b/src/libultra_boot_O2/osViSetYScale.c index cde3b56b03..29128af768 100644 --- a/src/libultra_boot_O2/osViSetYScale.c +++ b/src/libultra_boot_O2/osViSetYScale.c @@ -1,10 +1,10 @@ #include "global.h" void osViSetYScale(f32 scale) { - register s32 prevInt; + register s32 prevInt = __osDisableInt(); - prevInt = __osDisableInt(); __osViNext->y.factor = scale; __osViNext->state |= 4; + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O2/osViSwapBuffer.c b/src/libultra_boot_O2/osViSwapBuffer.c index 13995291de..b7ab9f9170 100644 --- a/src/libultra_boot_O2/osViSwapBuffer.c +++ b/src/libultra_boot_O2/osViSwapBuffer.c @@ -1,8 +1,10 @@ #include "global.h" void osViSwapBuffer(void* vaddr) { - u32 int_disabled = __osDisableInt(); + u32 prevInt = __osDisableInt(); + __osViNext->buffer = vaddr; __osViNext->state |= 0x10; // TODO: figure out what this flag means - __osRestoreInt(int_disabled); + + __osRestoreInt(prevInt); } diff --git a/src/libultra_boot_O2/pimgr.c b/src/libultra_boot_O2/pimgr.c index 4239f8f786..32c36e695b 100644 --- a/src/libultra_boot_O2/pimgr.c +++ b/src/libultra_boot_O2/pimgr.c @@ -18,7 +18,7 @@ OSPiHandle* __osCurrentHandle[] = { }; void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) { - u32 int_disabled; + u32 prevInt; OSPri newPri; OSPri currentPri; @@ -36,7 +36,7 @@ void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgC newPri = currentPri; osSetThreadPri(NULL, pri); } - int_disabled = __osDisableInt(); + prevInt = __osDisableInt(); __osPiDevMgr.initialized = true; __osPiDevMgr.cmdQueue = cmdQ; @@ -49,7 +49,7 @@ void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgC osCreateThread(&piThread, 0, __osDevMgrMain, (void*)&__osPiDevMgr, piStackThread + sizeof(piStackThread), pri); osStartThread(&piThread); - __osRestoreInt(int_disabled); + __osRestoreInt(prevInt); if (newPri != -1) { osSetThreadPri(NULL, newPri); diff --git a/src/libultra_boot_O2/sprintf.c b/src/libultra_boot_O2/sprintf.c index 96698b79e1..386d9fa141 100644 --- a/src/libultra_boot_O2/sprintf.c +++ b/src/libultra_boot_O2/sprintf.c @@ -1,11 +1,11 @@ #include "global.h" -char* proutSprintf(char* dst, const char* fmt, size_t size) { - return (char*)memcpy(dst, fmt, size) + size; +void* proutSprintf(void* dst, const char* fmt, u32 size) { + return (void*)((u32)memcpy(dst, fmt, size) + size); } s32 vsprintf(char* dst, const char* fmt, va_list args) { - s32 ret = _Printf(&proutSprintf, dst, fmt, args); + s32 ret = _Printf(proutSprintf, dst, fmt, args); if (ret > -1) { dst[ret] = 0; } @@ -17,7 +17,7 @@ s32 sprintf(char* dst, const char* fmt, ...) { va_list args; va_start(args, fmt); - ret = _Printf(&proutSprintf, dst, fmt, args); + ret = _Printf(proutSprintf, dst, fmt, args); if (ret > -1) { dst[ret] = 0; } diff --git a/src/libultra_boot_O2/string.c b/src/libultra_boot_O2/string.c index cea07c2533..bf059094f7 100644 --- a/src/libultra_boot_O2/string.c +++ b/src/libultra_boot_O2/string.c @@ -1,7 +1,8 @@ #include "global.h" -const u8* strchr(const u8* str, s32 ch) { +const char* strchr(const char* str, s32 ch) { u8 c = ch; + while (*str != c) { if (*str == 0) { return NULL; @@ -11,17 +12,19 @@ const u8* strchr(const u8* str, s32 ch) { return str; } -size_t strlen(const u8* str) { - const u8* ptr = str; +u32 strlen(const char* str) { + const char* ptr = str; + while (*ptr) { ptr++; } return ptr - str; } -void* memcpy(void* dst, const void* src, size_t size) { +void* memcpy(void* dst, const void* src, u32 size) { u8* _dst = dst; const u8* _src = src; + while (size > 0) { *_dst++ = *_src++; size--; diff --git a/src/libultra_boot_O2/vimgr.c b/src/libultra_boot_O2/vimgr.c index 5525ec74f5..c195bbf4c5 100644 --- a/src/libultra_boot_O2/vimgr.c +++ b/src/libultra_boot_O2/vimgr.c @@ -22,9 +22,10 @@ u32 __additional_scanline = 0; void viMgrMain(void*); void osCreateViManager(OSPri pri) { - u32 int_disabled; + u32 prevInt; OSPri newPri; OSPri currentPri; + if (!__osViDevMgr.initialized) { __osTimerServicesInit(); __additional_scanline = 0; @@ -44,7 +45,7 @@ void osCreateViManager(OSPri pri) { osSetThreadPri(NULL, pri); } - int_disabled = __osDisableInt(); + prevInt = __osDisableInt(); __osViDevMgr.initialized = true; __osViDevMgr.mgrThread = &viThread; __osViDevMgr.cmdQueue = &viEventQueue; @@ -56,7 +57,7 @@ void osCreateViManager(OSPri pri) { osCreateThread(&viThread, 0, &viMgrMain, &__osViDevMgr, viThreadStack + sizeof(viThreadStack), pri); __osViInit(); osStartThread(&viThread); - __osRestoreInt(int_disabled); + __osRestoreInt(prevInt); if (newPri != -1) { osSetThreadPri(NULL, newPri); } @@ -68,9 +69,8 @@ void viMgrMain(void* vargs) { static u16 viRetrace; u32 addTime; viMesgStruct* mesg; - u32 temp; // always 0 + u32 temp = 0; // always 0 - temp = 0; mesg = NULL; viRetrace = __osViGetCurrentContext()->retraceCount; if (viRetrace == 0) { @@ -79,7 +79,7 @@ void viMgrMain(void* vargs) { args = (OSMgrArgs*)vargs; - while (1) { + while (true) { osRecvMesg(args->eventQueue, (OSMesg)&mesg, OS_MESG_BLOCK); switch (mesg->unk00) { case 13: @@ -107,9 +107,7 @@ void viMgrMain(void* vargs) { __osBaseCounter = osGetCount(); addTime = __osBaseCounter - addTime; __osCurrentTime = __osCurrentTime + addTime; - break; - case 14: __osTimerInterrupt(); break; diff --git a/src/libultra_code_O1/osSetTimer.c b/src/libultra_code_O1/osSetTimer.c index 90e31ecbeb..a14c9b23b4 100644 --- a/src/libultra_code_O1/osSetTimer.c +++ b/src/libultra_code_O1/osSetTimer.c @@ -10,6 +10,7 @@ s32 osSetTimer(OSTimer* timer, OSTime countdown, OSTime interval, OSMesgQueue* m timer->next = NULL; timer->prev = NULL; timer->interval = interval; + if (countdown != 0) { timer->value = countdown; } else { @@ -20,8 +21,8 @@ s32 osSetTimer(OSTimer* timer, OSTime countdown, OSTime interval, OSMesgQueue* m prevInt = __osDisableInt(); if (__osTimerList->next != __osTimerList) { - if (1) {} + next = __osTimerList->next; count = osGetCount(); value = count - __osTimerCounter; @@ -38,5 +39,7 @@ s32 osSetTimer(OSTimer* timer, OSTime countdown, OSTime interval, OSMesgQueue* m __osRestoreInt(prevInt); + if (time) {} // suppresses set but unused warning + return 0; } diff --git a/src/libultra_code_O2/__osContAddressCrc.c b/src/libultra_code_O2/__osContAddressCrc.c index 9b0c779ec1..d22668d149 100644 --- a/src/libultra_code_O2/__osContAddressCrc.c +++ b/src/libultra_code_O2/__osContAddressCrc.c @@ -17,10 +17,8 @@ u8 __osContAddressCrc(u16 addr) { } else { ++ret; } - } else { - if (ret & 0x20) { - ret ^= 0x15; - } + } else if (ret & 0x20) { + ret ^= 0x15; } } for (i = 0; i < 5; ++i) { @@ -29,15 +27,15 @@ u8 __osContAddressCrc(u16 addr) { ret ^= 0x15; } } + return ret & 0x1f; } u8 __osContDataCrc(u8* data) { - s32 ret; + s32 ret = 0; u32 bit; u32 byte; - ret = 0; for (byte = 0x20; byte; --byte, ++data) { for (bit = 0x80; bit; bit >>= 1) { ret <<= 1; @@ -47,10 +45,8 @@ u8 __osContDataCrc(u8* data) { } else { ++ret; } - } else { - if (ret & 0x100) { - ret ^= 0x85; - } + } else if (ret & 0x100) { + ret ^= 0x85; } } } @@ -61,5 +57,6 @@ u8 __osContDataCrc(u8* data) { } ++byte; } while (byte < 8U); + return ret; } diff --git a/src/libultra_code_O2/__osContRamRead.c b/src/libultra_code_O2/__osContRamRead.c index 07c72e54b0..97d5db651c 100644 --- a/src/libultra_code_O2/__osContRamRead.c +++ b/src/libultra_code_O2/__osContRamRead.c @@ -12,15 +12,15 @@ s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data) { __osSiGetAccess(); do { - bufptr = &pifMempakBuf; - if ((__osContLastPoll != 2) || (__osPfsLastChannel != channel)) { + bufptr = (u8*)&gPifMempakBuf; + if ((__osContLastPoll != 2) || (__osPfsLastChannel != channel)) { __osContLastPoll = 2; __osPfsLastChannel = channel; // clang-format off for (i = 0; i < channel; i++) { *bufptr++ = 0; } // clang-format on - pifMempakBuf.status = 1; + gPifMempakBuf.status = 1; ((__OSContRamHeader*)bufptr)->unk_00 = 0xFF; ((__OSContRamHeader*)bufptr)->txsize = 3; ((__OSContRamHeader*)bufptr)->rxsize = 0x21; @@ -31,12 +31,14 @@ s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data) { } else { bufptr += channel; } + ((__OSContRamHeader*)bufptr)->hi = addr >> 3; // send byte 1 ((__OSContRamHeader*)bufptr)->lo = (s8)(__osContAddressCrc(addr) | (addr << 5)); // send byte 2 - __osSiRawStartDma(OS_WRITE, &pifMempakBuf); + __osSiRawStartDma(OS_WRITE, &gPifMempakBuf); osRecvMesg(ctrlrqueue, NULL, OS_MESG_BLOCK); - __osSiRawStartDma(OS_READ, &pifMempakBuf); + __osSiRawStartDma(OS_READ, &gPifMempakBuf); osRecvMesg(ctrlrqueue, NULL, OS_MESG_BLOCK); + ret = (((__OSContRamHeader*)bufptr)->rxsize & 0xC0) >> 4; if (!ret) { if (((__OSContRamHeader*)bufptr)->datacrc != __osContDataCrc(bufptr + 6)) { @@ -56,5 +58,6 @@ s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data) { } } while (0 <= retryCount--); __osSiRelAccess(); + return ret; } diff --git a/src/libultra_code_O2/__osContRamWrite.c b/src/libultra_code_O2/__osContRamWrite.c index 4c5c166962..d65f86a198 100644 --- a/src/libultra_code_O2/__osContRamWrite.c +++ b/src/libultra_code_O2/__osContRamWrite.c @@ -15,7 +15,7 @@ s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32 __osSiGetAccess(); do { - ptr = (u8*)(&pifMempakBuf); + ptr = (u8*)(&gPifMempakBuf); if (__osContLastPoll != CONT_CMD_WRITE_MEMPACK || __osPfsLastChannel != channel) { __osContLastPoll = CONT_CMD_WRITE_MEMPACK; @@ -25,7 +25,7 @@ s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32 for (i = 0; i < channel; i++) { *ptr++ = 0; } // clang-format on - pifMempakBuf.status = 1; + gPifMempakBuf.status = 1; ((__OSContRamHeader*)ptr)->unk_00 = 0xff; ((__OSContRamHeader*)ptr)->txsize = 35; @@ -42,11 +42,11 @@ s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32 bcopy(buffer, ((__OSContRamHeader*)ptr)->data, BLOCKSIZE); - ret = __osSiRawStartDma(OS_WRITE, &pifMempakBuf); + ret = __osSiRawStartDma(OS_WRITE, &gPifMempakBuf); crc = __osContDataCrc(buffer); osRecvMesg(mq, (OSMesg*)NULL, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &pifMempakBuf); + ret = __osSiRawStartDma(OS_READ, &gPifMempakBuf); osRecvMesg(mq, (OSMesg*)NULL, OS_MESG_BLOCK); ret = ((((__OSContRamHeader*)ptr)->rxsize & 0xC0) >> 4); @@ -63,5 +63,6 @@ s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32 } } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); __osSiRelAccess(); + return ret; } diff --git a/src/libultra_code_O2/__osGetActiveQueue.c b/src/libultra_code_O2/__osGetActiveQueue.c index 36919dc59a..de55d7f041 100644 --- a/src/libultra_code_O2/__osGetActiveQueue.c +++ b/src/libultra_code_O2/__osGetActiveQueue.c @@ -1,5 +1,5 @@ #include "global.h" -OSThread* __osGetActiveQueue() { +OSThread* __osGetActiveQueue(void) { return __osActiveQueue; } diff --git a/src/libultra_code_O2/__osGetCurrFaultedThread.c b/src/libultra_code_O2/__osGetCurrFaultedThread.c index b10b5f5086..f36799b26f 100644 --- a/src/libultra_code_O2/__osGetCurrFaultedThread.c +++ b/src/libultra_code_O2/__osGetCurrFaultedThread.c @@ -1,5 +1,5 @@ #include "global.h" -OSThread* __osGetCurrFaultedThread() { +OSThread* __osGetCurrFaultedThread(void) { return __osFaultedThread; } diff --git a/src/libultra_code_O2/__osPfsGetStatus.c b/src/libultra_code_O2/__osPfsGetStatus.c index aa2b8a6ff0..3a1e962a2e 100644 --- a/src/libultra_code_O2/__osPfsGetStatus.c +++ b/src/libultra_code_O2/__osPfsGetStatus.c @@ -1,7 +1,7 @@ #include "ultra64.h" #include "global.h" -OSPifRam pifMempakBuf; +OSPifRam gPifMempakBuf; s32 __osPfsGetStatus(OSMesgQueue* queue, s32 channel) { s32 ret = 0; @@ -11,10 +11,10 @@ s32 __osPfsGetStatus(OSMesgQueue* queue, s32 channel) { __osPfsInodeCacheBank = 250; __osPfsRequestOneChannel(channel, CONT_CMD_REQUEST_STATUS); - ret = __osSiRawStartDma(OS_WRITE, &pifMempakBuf); + ret = __osSiRawStartDma(OS_WRITE, &gPifMempakBuf); osRecvMesg(queue, &msg, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &pifMempakBuf); + ret = __osSiRawStartDma(OS_READ, &gPifMempakBuf); osRecvMesg(queue, &msg, OS_MESG_BLOCK); __osPfsGetOneChannelData(channel, &data); @@ -34,10 +34,9 @@ void __osPfsRequestOneChannel(s32 channel, u8 poll) { s32 idx; __osContLastPoll = CONT_CMD_END; + gPifMempakBuf.status = CONT_CMD_READ_BUTTON; - pifMempakBuf.status = CONT_CMD_READ_BUTTON; - - bufptr = &pifMempakBuf; + bufptr = (u8*)&gPifMempakBuf; req.txsize = 1; req.rxsize = 3; @@ -56,12 +55,10 @@ void __osPfsRequestOneChannel(s32 channel, u8 poll) { } void __osPfsGetOneChannelData(s32 channel, OSContStatus* contData) { - u8* bufptr; + u8* bufptr = (u8*)&gPifMempakBuf; __OSContRequestHeaderAligned req; s32 idx; - bufptr = &pifMempakBuf; - for (idx = 0; idx < channel; idx++) { bufptr++; } diff --git a/src/libultra_code_O2/__osSiCreateAccessQueue.c b/src/libultra_code_O2/__osSiCreateAccessQueue.c index c46df56f62..90dbe7e5d7 100644 --- a/src/libultra_code_O2/__osSiCreateAccessQueue.c +++ b/src/libultra_code_O2/__osSiCreateAccessQueue.c @@ -4,20 +4,21 @@ OSMesg osSiMesgBuff[SIAccessQueueSize]; OSMesgQueue gOSSiMessageQueue; u32 gOSSiAccessQueueCreated = 0; -void __osSiCreateAccessQueue() { +void __osSiCreateAccessQueue(void) { gOSSiAccessQueueCreated = 1; osCreateMesgQueue(&gOSSiMessageQueue, &osSiMesgBuff[0], SIAccessQueueSize - 1); osSendMesg(&gOSSiMessageQueue, NULL, OS_MESG_NOBLOCK); } -void __osSiGetAccess() { - OSMesg sp1c; +void __osSiGetAccess(void) { + OSMesg mesg; + if (!gOSSiAccessQueueCreated) { __osSiCreateAccessQueue(); } - osRecvMesg(&gOSSiMessageQueue, &sp1c, OS_MESG_BLOCK); + osRecvMesg(&gOSSiMessageQueue, &mesg, OS_MESG_BLOCK); } -void __osSiRelAccess() { +void __osSiRelAccess(void) { osSendMesg(&gOSSiMessageQueue, NULL, OS_MESG_NOBLOCK); } diff --git a/src/libultra_code_O2/__osSpGetStatus.c b/src/libultra_code_O2/__osSpGetStatus.c index 8987b2414a..99a4ad0a18 100644 --- a/src/libultra_code_O2/__osSpGetStatus.c +++ b/src/libultra_code_O2/__osSpGetStatus.c @@ -1,5 +1,5 @@ #include "global.h" -u32 __osSpGetStatus() { +u32 __osSpGetStatus(void) { return HW_REG(SP_STATUS_REG, u32); } diff --git a/src/libultra_code_O2/__osSpSetStatus.c b/src/libultra_code_O2/__osSpSetStatus.c index 670dc1f3bc..b2f97a3ff0 100644 --- a/src/libultra_code_O2/__osSpSetStatus.c +++ b/src/libultra_code_O2/__osSpSetStatus.c @@ -1,5 +1,5 @@ #include "global.h" -void __osSpSetStatus(u32 a0) { - HW_REG(SP_STATUS_REG, u32) = a0; +void __osSpSetStatus(u32 status) { + HW_REG(SP_STATUS_REG, u32) = status; } diff --git a/src/libultra_code_O2/contpfs.c b/src/libultra_code_O2/contpfs.c index a9b2028eee..f111e051d0 100644 --- a/src/libultra_code_O2/contpfs.c +++ b/src/libultra_code_O2/contpfs.c @@ -8,9 +8,8 @@ u8 __osPfsInodeCacheBank = 250; u16 __osSumcalc(u8* ptr, s32 length) { s32 i; u32 sum = 0; - u8* temp; + u8* temp = ptr; - temp = ptr; for (i = 0; i < length; i++) { sum += *temp++; } @@ -18,7 +17,6 @@ u16 __osSumcalc(u8* ptr, s32 length) { } s32 __osIdCheckSum(u16* ptr, u16* checkSum, u16* idSum) { - u16 data = 0; u32 i; @@ -99,14 +97,14 @@ s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) { newid->deviceid = (badid->deviceid & 0xFFFE) | mask; newid->banks = j; newid->version = badid->version; - __osIdCheckSum(newid, &newid->checksum, &newid->invertedChecksum); + __osIdCheckSum((u16*)newid, &newid->checksum, &newid->invertedChecksum); index[0] = PFS_ID_0AREA; index[1] = PFS_ID_1AREA; index[2] = PFS_ID_2AREA; index[3] = PFS_ID_3AREA; for (i = 0; i < 4; i++) { - if ((ret = __osContRamWrite(pfs->queue, pfs->channel, index[i], newid, PFS_FORCE)) != 0) { + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, index[i], (u8*)newid, PFS_FORCE)) != 0) { return ret; } } @@ -121,8 +119,7 @@ s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) { return 0; } -s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp) { - +s32 __osCheckPackId(OSPfs* pfs, __OSPackId* check) { u16 index[4]; s32 ret = 0; u16 sum; @@ -139,11 +136,11 @@ s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp) { index[2] = PFS_ID_2AREA; index[3] = PFS_ID_3AREA; for (i = 1; i < 4; i++) { - if ((ret = __osContRamRead(pfs->queue, pfs->channel, index[i], temp)) != 0) { + if ((ret = __osContRamRead(pfs->queue, pfs->channel, index[i], (u8*)check)) != 0) { return ret; } - __osIdCheckSum(temp, &sum, &idSum); - if ((temp->checksum == sum) && (temp->invertedChecksum == idSum)) { + __osIdCheckSum((u16*)check, &sum, &idSum); + if ((check->checksum == sum) && (check->invertedChecksum == idSum)) { break; } } @@ -153,7 +150,7 @@ s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp) { for (j = 0; j < 4; j++) { if (j != i) { - if ((ret = __osContRamWrite(pfs->queue, pfs->channel, index[j], temp, PFS_FORCE)) != 0) { + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, index[j], (u8*)check, PFS_FORCE)) != 0) { return ret; } } @@ -274,7 +271,7 @@ s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank) { if (flag == PFS_WRITE) { inode->inodePage[0].inode_t.page = - __osSumcalc(inode->inodePage + offset, (PFS_INODE_SIZE_PER_PAGE - offset) * 2); + __osSumcalc((u8*)(inode->inodePage + offset), (PFS_INODE_SIZE_PER_PAGE - offset) * 2); } for (j = 0; j < PFS_ONE_PAGE; j++) { @@ -297,7 +294,7 @@ s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank) { addr = (u8*)(((u8*)inode) + (j * BLOCKSIZE)); ret = __osContRamRead(pfs->queue, pfs->channel, pfs->minode_table + (bank * PFS_ONE_PAGE) + j, addr); } - sum = __osSumcalc(inode->inodePage + offset, (PFS_INODE_SIZE_PER_PAGE - offset) * 2); + sum = __osSumcalc((u8*)(inode->inodePage + offset), (PFS_INODE_SIZE_PER_PAGE - offset) * 2); if (sum != inode->inodePage[0].inode_t.page) { return PFS_ERR_INCONSISTENT; } @@ -310,5 +307,6 @@ s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank) { __osPfsInodeCacheBank = bank; bcopy(inode, &__osPfsInodeCache, sizeof(__OSInode)); __osPfsInodeCacheChannel = pfs->channel; + return 0; } diff --git a/src/libultra_code_O2/contquery.c b/src/libultra_code_O2/contquery.c index ffcdea0416..21cb884d46 100644 --- a/src/libultra_code_O2/contquery.c +++ b/src/libultra_code_O2/contquery.c @@ -4,11 +4,9 @@ * osContStartQuery: * Starts to read the values for SI device status and type which are connected to the controller port and joyport * connector. - **/ - + */ s32 osContStartQuery(OSMesgQueue* mq) { - s32 ret; - ret = 0; + s32 ret = 0; __osSiGetAccess(); if (__osContLastPoll != CONT_CMD_REQUEST_STATUS) { @@ -25,7 +23,7 @@ s32 osContStartQuery(OSMesgQueue* mq) { /** * osContGetQuery: * Returns the values from osContStartQuery to status. Both functions must be paired for use. - **/ + */ void osContGetQuery(OSContStatus* data) { u8 pattern; __osContGetInitData(&pattern, data); diff --git a/src/libultra_code_O2/cosf.c b/src/libultra_code_O2/cosf.c index 56ef995c78..1d9c7e83d3 100644 --- a/src/libultra_code_O2/cosf.c +++ b/src/libultra_code_O2/cosf.c @@ -22,16 +22,13 @@ f32 cosf(f32 x) { f64 dn; s32 n; f64 result; - s32 ix, xpt; + s32 ix = *(s32*)&x; + s32 xpt = (ix >> 22); - ix = *(s32*)&x; - xpt = (ix >> 22); xpt &= 0x1FF; if (xpt < 0x136) { - absx = (x > 0) ? x : -x; - dx = absx; dn = dx * rpi.d + 0.5; @@ -52,10 +49,8 @@ f32 cosf(f32 x) { if (!(n & 1)) { return (f32)result; } - return -(f32)result; } - if (x != x) { return __libm_qnan_f; } diff --git a/src/libultra_code_O2/guLookAt.c b/src/libultra_code_O2/guLookAt.c index ca55602143..5313d3cc3e 100644 --- a/src/libultra_code_O2/guLookAt.c +++ b/src/libultra_code_O2/guLookAt.c @@ -2,8 +2,12 @@ void guLookAtF(f32 mf[4][4], f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp) { f32 length; - f32 xLook, yLook, zLook; - f32 xRight, yRight, zRight; + f32 xLook; + f32 yLook; + f32 zLook; + f32 xRight; + f32 yRight; + f32 zRight; guMtxIdentF(mf); @@ -57,5 +61,5 @@ void guLookAt(Mtx* m, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f guLookAtF(mf, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp); - guMtxF2L(mf, m); + guMtxF2L((MtxF*)mf, m); } diff --git a/src/libultra_code_O2/guLookAtHilite.c b/src/libultra_code_O2/guLookAtHilite.c index 4af14abae5..ebb9157244 100644 --- a/src/libultra_code_O2/guLookAtHilite.c +++ b/src/libultra_code_O2/guLookAtHilite.c @@ -11,7 +11,16 @@ void guLookAtHiliteF(f32 mf[4][4], LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 f32 xl2, f32 yl2, f32 zl2, /* light 2 direction */ s32 hiliteWidth, s32 hiliteHeight) /* size of hilite texture */ { - f32 length, xLook, yLook, zLook, xRight, yRight, zRight, xHilite, yHilite, zHilite; + f32 length; + f32 xLook; + f32 yLook; + f32 zLook; + f32 xRight; + f32 yRight; + f32 zRight; + f32 xHilite; + f32 yHilite; + f32 zHilite; guMtxIdentF(mf); @@ -148,5 +157,5 @@ void guLookAtHilite(Mtx* m, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, guLookAtHiliteF(mf, l, h, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp, xl1, yl1, zl1, xl2, yl2, zl2, hiliteWidth, hiliteHeight); - guMtxF2L(mf, m); + guMtxF2L((MtxF*)mf, m); } diff --git a/src/libultra_code_O2/guPerspectiveF.c b/src/libultra_code_O2/guPerspectiveF.c index df69888cf6..4418a61222 100644 --- a/src/libultra_code_O2/guPerspectiveF.c +++ b/src/libultra_code_O2/guPerspectiveF.c @@ -4,7 +4,9 @@ void guPerspectiveF(f32 mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near f32 yscale; s32 row; s32 col; + guMtxIdentF(mf); + fovy *= GU_PI / 180.0; yscale = cosf(fovy / 2) / sinf(fovy / 2); mf[0][0] = yscale / aspect; @@ -13,11 +15,13 @@ void guPerspectiveF(f32 mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near mf[2][3] = -1; mf[3][2] = 2 * near * far / (near - far); mf[3][3] = 0.0f; + for (row = 0; row < 4; row++) { for (col = 0; col < 4; col++) { mf[row][col] *= scale; } } + if (perspNorm != NULL) { if (near + far <= 2.0) { *perspNorm = 65535; @@ -30,7 +34,8 @@ void guPerspectiveF(f32 mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near } } void guPerspective(Mtx* m, u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale) { - f32 mat[4][4]; - guPerspectiveF(mat, perspNorm, fovy, aspect, near, far, scale); - guMtxF2L(mat, m); + f32 mf[4][4]; + + guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); + guMtxF2L((MtxF*)mf, m); } diff --git a/src/libultra_code_O2/guPosition.c b/src/libultra_code_O2/guPosition.c index 25dfe5c8ef..2233a72f32 100644 --- a/src/libultra_code_O2/guPosition.c +++ b/src/libultra_code_O2/guPosition.c @@ -3,8 +3,7 @@ /** * guPositionF * Creates a rotation/parallel translation modeling matrix (floating point) - **/ - + */ void guPositionF(f32 mf[4][4], f32 rot, f32 pitch, f32 yaw, f32 scale, f32 x, f32 y, f32 z) { static f32 D_80134D00 = M_PI / 180.0; f32 sinr, sinp, sinh; @@ -51,5 +50,5 @@ void guPosition(Mtx* m, f32 rot, f32 pitch, f32 yaw, f32 scale, f32 x, f32 y, f3 guPositionF(mf, rot, pitch, yaw, scale, x, y, z); - guMtxF2L(mf, m); + guMtxF2L((MtxF*)mf, m); } diff --git a/src/libultra_code_O2/guS2DInitBg.c b/src/libultra_code_O2/guS2DInitBg.c index 0d75648f94..d2e5a2b043 100644 --- a/src/libultra_code_O2/guS2DInitBg.c +++ b/src/libultra_code_O2/guS2DInitBg.c @@ -1,13 +1,10 @@ #include "global.h" void guS2DInitBg(uObjBg* bg) { - u16 shift; u32 size; - s32 tmem; + s32 tmem = (bg->b.imageFmt == G_IM_FMT_CI) ? 0x100 : 0x200; + u16 shift = (6 - bg->b.imageSiz); - tmem = (bg->b.imageFmt == G_IM_FMT_CI) ? 0x100 : 0x200; - - shift = (6 - bg->b.imageSiz); if (bg->b.imageLoad == G_BGLT_LOADBLOCK) { bg->b.tmemW = bg->b.imageW >> shift; bg->b.tmemH = (tmem / bg->b.tmemW) * 4; diff --git a/src/libultra_code_O2/ortho.c b/src/libultra_code_O2/ortho.c index 70e64e9d20..517ba1dccc 100644 --- a/src/libultra_code_O2/ortho.c +++ b/src/libultra_code_O2/ortho.c @@ -21,9 +21,9 @@ void guOrthoF(f32 mf[4][4], f32 left, f32 right, f32 bottom, f32 top, f32 near, } void guOrtho(Mtx* mtx, f32 left, f32 right, f32 bottom, f32 top, f32 near, f32 far, f32 scale) { - MtxF_t mf; + f32 mf[4][4]; guOrthoF(mf, left, right, bottom, top, near, far, scale); - guMtxF2L(mf, mtx); + guMtxF2L((MtxF*)mf, mtx); } diff --git a/src/libultra_code_O2/osAiGetLength.c b/src/libultra_code_O2/osAiGetLength.c index 90be706cbc..58d8db4875 100644 --- a/src/libultra_code_O2/osAiGetLength.c +++ b/src/libultra_code_O2/osAiGetLength.c @@ -1,5 +1,5 @@ #include "global.h" -u32 osAiGetLength() { +u32 osAiGetLength(void) { return HW_REG(AI_LEN_REG, u32); } diff --git a/src/libultra_code_O2/osAiSetFrequency.c b/src/libultra_code_O2/osAiSetFrequency.c index f0606809e4..8702941b9a 100644 --- a/src/libultra_code_O2/osAiSetFrequency.c +++ b/src/libultra_code_O2/osAiSetFrequency.c @@ -1,12 +1,9 @@ #include "global.h" s32 osAiSetFrequency(u32 frequency) { - u32 dacRate; u8 bitrate; - f32 dacRateF; - - dacRateF = ((f32)osViClock / frequency) + 0.5f; - dacRate = dacRateF; + f32 dacRateF = ((f32)osViClock / frequency) + 0.5f; + u32 dacRate = dacRateF; if (dacRate < 132) { return -1; diff --git a/src/libultra_code_O2/osContInit.c b/src/libultra_code_O2/osContInit.c index 8f10e854df..5b44e01123 100644 --- a/src/libultra_code_O2/osContInit.c +++ b/src/libultra_code_O2/osContInit.c @@ -11,6 +11,7 @@ OSMesg __osEepromTimerMsg; u32 gOSContInitialized = 0; #define HALF_SECOND OS_USEC_TO_CYCLES(500000) + s32 osContInit(OSMesgQueue* mq, u8* ctlBitfield, OSContStatus* status) { OSMesg mesg; s32 ret = 0; @@ -21,6 +22,7 @@ s32 osContInit(OSMesgQueue* mq, u8* ctlBitfield, OSContStatus* status) { if (gOSContInitialized) { return 0; } + gOSContInitialized = 1; currentTime = osGetTime(); if (HALF_SECOND > currentTime) { @@ -38,6 +40,7 @@ s32 osContInit(OSMesgQueue* mq, u8* ctlBitfield, OSContStatus* status) { __osContLastPoll = CONT_CMD_REQUEST_STATUS; __osSiCreateAccessQueue(); osCreateMesgQueue(&__osEepromTimerMsgQ, &__osEepromTimerMsg, 1); + return ret; } @@ -46,7 +49,9 @@ void __osContGetInitData(u8* ctlBitfield, OSContStatus* status) { __OSContRequestHeader req; s32 i; u8 bitfieldTemp = 0; + bufptr = (u8*)(&__osPifInternalBuff); + for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(req), status++) { req = *((__OSContRequestHeader*)bufptr); status->errno = (req.rxsize & 0xC0) >> 4; @@ -64,12 +69,13 @@ void __osPackRequestData(u8 poll) { u8* bufptr; __OSContRequestHeader req; s32 i; + for (i = 0; i < 0xF; i++) { __osPifInternalBuff.ram[i] = 0; } __osPifInternalBuff.status = 1; - bufptr = &__osPifInternalBuff; + bufptr = (u8*)(&__osPifInternalBuff); req.align = 0xFF; req.txsize = 1; diff --git a/src/libultra_code_O2/osContQuery.c b/src/libultra_code_O2/osContQuery.c index ffcdea0416..ff7cd43851 100644 --- a/src/libultra_code_O2/osContQuery.c +++ b/src/libultra_code_O2/osContQuery.c @@ -4,8 +4,7 @@ * osContStartQuery: * Starts to read the values for SI device status and type which are connected to the controller port and joyport * connector. - **/ - + */ s32 osContStartQuery(OSMesgQueue* mq) { s32 ret; ret = 0; @@ -25,7 +24,7 @@ s32 osContStartQuery(OSMesgQueue* mq) { /** * osContGetQuery: * Returns the values from osContStartQuery to status. Both functions must be paired for use. - **/ + */ void osContGetQuery(OSContStatus* data) { u8 pattern; __osContGetInitData(&pattern, data); diff --git a/src/libultra_code_O2/osContStartReadData.c b/src/libultra_code_O2/osContStartReadData.c index 59ead072c8..a85a3337bd 100644 --- a/src/libultra_code_O2/osContStartReadData.c +++ b/src/libultra_code_O2/osContStartReadData.c @@ -2,6 +2,7 @@ s32 osContStartReadData(OSMesgQueue* mq) { s32 ret; + __osSiGetAccess(); if (__osContLastPoll != 1) { __osPackReadData(); @@ -15,10 +16,10 @@ s32 osContStartReadData(OSMesgQueue* mq) { } void osContGetReadData(OSContPad* contData) { - u8* bufptr; + u8* bufptr = (u8*)(&__osPifInternalBuff); __OSContReadHeader read; s32 i; - bufptr = (u8*)(&__osPifInternalBuff); + for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(read), contData++) { read = *((__OSContReadHeader*)bufptr); contData->errno = (read.rxsize & 0xC0) >> 4; @@ -30,11 +31,11 @@ void osContGetReadData(OSContPad* contData) { }; } -void __osPackReadData() { - u8* bufptr; +void __osPackReadData(void) { + u8* bufptr = (u8*)(&__osPifInternalBuff); __OSContReadHeader read; s32 i; - bufptr = (u8*)(&__osPifInternalBuff); + for (i = 0; i < 0xF; i++) { __osPifInternalBuff.ram[i] = 0; } diff --git a/src/libultra_code_O2/osPfsDeleteFile.c b/src/libultra_code_O2/osPfsDeleteFile.c index b9ec018c20..573af6a724 100644 --- a/src/libultra_code_O2/osPfsDeleteFile.c +++ b/src/libultra_code_O2/osPfsDeleteFile.c @@ -2,7 +2,6 @@ #include "global.h" s32 osPfsDeleteFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName) { - s32 file_no; s32 ret; __OSInode inode; @@ -24,6 +23,7 @@ s32 osPfsDeleteFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)) != 0) { return ret; } + startpage = dir.start_page.inode_t.page; for (bank = dir.start_page.inode_t.bank; bank < pfs->banks;) { if ((ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank)) != 0) { @@ -48,6 +48,7 @@ s32 osPfsDeleteFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* bzero(&dir, sizeof(__OSDir)); ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir, 0); + return ret; } diff --git a/src/libultra_code_O2/osPfsFileState.c b/src/libultra_code_O2/osPfsFileState.c index aa7cc4f4ab..367a7f27d6 100644 --- a/src/libultra_code_O2/osPfsFileState.c +++ b/src/libultra_code_O2/osPfsFileState.c @@ -21,7 +21,7 @@ s32 osPfsFileState(OSPfs* pfs, s32 fileNo, OSPfsState* state) { if (pfs->activebank != 0 && (ret = __osPfsSelectBank(pfs, 0)) != 0) { return ret; } - if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + fileNo, &dir)) != 0) { + if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + fileNo, (u8*)&dir)) != 0) { return ret; } if (dir.company_code == 0 || dir.game_code == 0) { @@ -53,5 +53,6 @@ s32 osPfsFileState(OSPfs* pfs, s32 fileNo, OSPfsState* state) { state->game_code = dir.game_code; bcopy(&dir.game_name, state->game_name, PFS_FILE_NAME_LEN); bcopy(&dir.ext_name, state->ext_name, PFS_FILE_EXT_LEN); + return __osPfsGetStatus(pfs->queue, pfs->channel); } diff --git a/src/libultra_code_O2/osPfsFindFile.c b/src/libultra_code_O2/osPfsFindFile.c index 0ee5e538d3..d7798e4fb3 100644 --- a/src/libultra_code_O2/osPfsFindFile.c +++ b/src/libultra_code_O2/osPfsFindFile.c @@ -17,7 +17,7 @@ s32 osPfsFindFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* e } for (j = 0; j < pfs->dir_size; j++) { - if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, &dir)) != 0) { + if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)) != 0) { return ret; } if ((ret = __osPfsGetStatus(pfs->queue, pfs->channel)) != 0) { diff --git a/src/libultra_code_O2/osPfsFreeBlocks.c b/src/libultra_code_O2/osPfsFreeBlocks.c index c7e7adcbfe..7210c65815 100644 --- a/src/libultra_code_O2/osPfsFreeBlocks.c +++ b/src/libultra_code_O2/osPfsFreeBlocks.c @@ -13,7 +13,6 @@ s32 osPfsFreeBlocks(OSPfs* pfs, s32* leftoverBytes) { if (!(pfs->status & PFS_INITIALIZED)) { return (PFS_ERR_INVALID); } - if ((ret = __osCheckId(pfs)) != 0) { return ret; } diff --git a/src/libultra_code_O2/osPfsIsPlug.c b/src/libultra_code_O2/osPfsIsPlug.c index 329610ac50..a1b73cf8e7 100644 --- a/src/libultra_code_O2/osPfsIsPlug.c +++ b/src/libultra_code_O2/osPfsIsPlug.c @@ -15,10 +15,10 @@ s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern) { do { __osPfsRequestData(CONT_CMD_REQUEST_STATUS); - ret = __osSiRawStartDma(OS_WRITE, &pifMempakBuf); + ret = __osSiRawStartDma(OS_WRITE, &gPifMempakBuf); osRecvMesg(mq, &msg, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &pifMempakBuf); + ret = __osSiRawStartDma(OS_READ, &gPifMempakBuf); osRecvMesg(mq, &msg, OS_MESG_BLOCK); __osPfsGetInitData(&bitpattern, &contData[0]); @@ -45,13 +45,13 @@ s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern) { } void __osPfsRequestData(u8 poll) { - u8* bufPtr = &pifMempakBuf; + u8* bufPtr = (u8*)&gPifMempakBuf; __OSContRequestHeader req; s32 i; __osContLastPoll = poll; - pifMempakBuf.status = 1; + gPifMempakBuf.status = 1; req.align = 0xFF; req.txsize = 1; @@ -75,7 +75,7 @@ void __osPfsGetInitData(u8* pattern, OSContStatus* contData) { s32 i; u8 bits = 0; - bufptr = &pifMempakBuf; + bufptr = (u8*)&gPifMempakBuf; for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(req), contData++) { req = *((__OSContRequestHeader*)bufptr); diff --git a/src/libultra_code_O2/osReadMempak.c b/src/libultra_code_O2/osReadMempak.c index 07c72e54b0..bcbca66ab1 100644 --- a/src/libultra_code_O2/osReadMempak.c +++ b/src/libultra_code_O2/osReadMempak.c @@ -11,8 +11,10 @@ s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data) { s32 retryCount = 2; __osSiGetAccess(); + do { - bufptr = &pifMempakBuf; + bufptr = (u8*)&gPifMempakBuf; + if ((__osContLastPoll != 2) || (__osPfsLastChannel != channel)) { __osContLastPoll = 2; @@ -20,7 +22,7 @@ s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data) { // clang-format off for (i = 0; i < channel; i++) { *bufptr++ = 0; } // clang-format on - pifMempakBuf.status = 1; + gPifMempakBuf.status = 1; ((__OSContRamHeader*)bufptr)->unk_00 = 0xFF; ((__OSContRamHeader*)bufptr)->txsize = 3; ((__OSContRamHeader*)bufptr)->rxsize = 0x21; @@ -31,12 +33,14 @@ s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data) { } else { bufptr += channel; } + ((__OSContRamHeader*)bufptr)->hi = addr >> 3; // send byte 1 ((__OSContRamHeader*)bufptr)->lo = (s8)(__osContAddressCrc(addr) | (addr << 5)); // send byte 2 - __osSiRawStartDma(OS_WRITE, &pifMempakBuf); + __osSiRawStartDma(OS_WRITE, &gPifMempakBuf); osRecvMesg(ctrlrqueue, NULL, OS_MESG_BLOCK); - __osSiRawStartDma(OS_READ, &pifMempakBuf); + __osSiRawStartDma(OS_READ, &gPifMempakBuf); osRecvMesg(ctrlrqueue, NULL, OS_MESG_BLOCK); + ret = (((__OSContRamHeader*)bufptr)->rxsize & 0xC0) >> 4; if (!ret) { if (((__OSContRamHeader*)bufptr)->datacrc != __osContDataCrc(bufptr + 6)) { @@ -55,6 +59,8 @@ s32 __osContRamRead(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data) { break; } } while (0 <= retryCount--); + __osSiRelAccess(); + return ret; } diff --git a/src/libultra_code_O2/osRumblePak.c b/src/libultra_code_O2/osRumblePak.c index 96e86c4dfa..2aeef88626 100644 --- a/src/libultra_code_O2/osRumblePak.c +++ b/src/libultra_code_O2/osRumblePak.c @@ -5,16 +5,15 @@ OSPifRam osPifBuffers[MAXCONTROLLERS]; -// func_800CF990 in 1.0 s32 osSetRumble(OSPfs* pfs, u32 vibrate) { s32 i; s32 ret; - u8* buf; + u8* buf = (u8*)&osPifBuffers[pfs->channel]; - buf = (u8*)&osPifBuffers[pfs->channel]; if (!(pfs->status & 8)) { return 5; } + __osSiGetAccess(); osPifBuffers[pfs->channel].status = 1; buf += pfs->channel; @@ -27,6 +26,7 @@ s32 osSetRumble(OSPfs* pfs, u32 vibrate) { osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); __osSiRawStartDma(OS_READ, &osPifBuffers[pfs->channel]); osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ret = ((__OSContRamHeader*)buf)->rxsize & 0xC0; if (!ret) { if (!vibrate) { @@ -39,7 +39,9 @@ s32 osSetRumble(OSPfs* pfs, u32 vibrate) { } } } + __osSiRelAccess(); + return ret; } @@ -47,17 +49,20 @@ void osSetUpMempakWrite(s32 channel, OSPifRam* buf) { u8* bufptr = (u8*)buf; __OSContRamHeader mempakwr; s32 i; + mempakwr.unk_00 = 0xFF; mempakwr.txsize = 0x23; mempakwr.rxsize = 1; mempakwr.poll = 3; // write mempak mempakwr.hi = 0x600 >> 3; mempakwr.lo = (u8)(__osContAddressCrc(0x600) | (0x600 << 5)); + if (channel != 0) { for (i = 0; i < channel; ++i) { *bufptr++ = 0; } } + *(__OSContRamHeader*)bufptr = mempakwr; bufptr += sizeof(mempakwr); *bufptr = 0xFE; @@ -80,7 +85,6 @@ s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, OSPfs* pfs, u32 channel) { return ret; } ret = __osContRamRead(ctrlrqueue, channel, BANK_ADDR, sp24); - ret = ret; if (ret == 2) { ret = 4; // "Controller pack communication error" } @@ -111,5 +115,6 @@ s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, OSPfs* pfs, u32 channel) { osSetUpMempakWrite(channel, &osPifBuffers[channel]); } pfs->status = PFS_MOTOR_INITIALIZED; + return 0; // "Recognized rumble pak" } diff --git a/src/libultra_code_O2/osSpTaskYield.c b/src/libultra_code_O2/osSpTaskYield.c index ab852cb71e..a78b7f9ad0 100644 --- a/src/libultra_code_O2/osSpTaskYield.c +++ b/src/libultra_code_O2/osSpTaskYield.c @@ -1,5 +1,5 @@ #include "global.h" -void osSpTaskYield() { +void osSpTaskYield(void) { __osSpSetStatus(SP_STATUS_SIG3); } diff --git a/src/libultra_code_O2/osSpTaskYielded.c b/src/libultra_code_O2/osSpTaskYielded.c index be1dcc09c3..4fec2a6d51 100644 --- a/src/libultra_code_O2/osSpTaskYielded.c +++ b/src/libultra_code_O2/osSpTaskYielded.c @@ -2,9 +2,7 @@ u32 osSpTaskYielded(OSTask* task) { u32 ret; - u32 status; - - status = __osSpGetStatus(); + u32 status = __osSpGetStatus(); if (status & SP_STATUS_YIELDED) { ret = OS_TASK_YIELDED; diff --git a/src/libultra_code_O2/osViGetCurrentFramebuffer.c b/src/libultra_code_O2/osViGetCurrentFramebuffer.c index f605f16836..f0e4c74437 100644 --- a/src/libultra_code_O2/osViGetCurrentFramebuffer.c +++ b/src/libultra_code_O2/osViGetCurrentFramebuffer.c @@ -1,12 +1,10 @@ #include "global.h" -u32* osViGetCurrentFramebuffer() { - register u32 sMask = __osDisableInt(); - u32* var1; +u32* osViGetCurrentFramebuffer(void) { + register u32 prevInt = __osDisableInt(); + u32* var1 = __osViCurr->buffer; - var1 = __osViCurr->buffer; - - __osRestoreInt(sMask); + __osRestoreInt(prevInt); return var1; } diff --git a/src/libultra_code_O2/osViSetEvent.c b/src/libultra_code_O2/osViSetEvent.c index 0f29bc681d..0239c1f7c4 100644 --- a/src/libultra_code_O2/osViSetEvent.c +++ b/src/libultra_code_O2/osViSetEvent.c @@ -3,10 +3,11 @@ extern OSViContext* __osViNext; void osViSetEvent(OSMesgQueue* mq, OSMesg msg, u32 retraceCount) { - register u32 saveMask; - saveMask = __osDisableInt(); + register u32 prevInt = __osDisableInt(); + __osViNext->mq = mq; __osViNext->msg = msg; __osViNext->retraceCount = retraceCount; - __osRestoreInt(saveMask); + + __osRestoreInt(prevInt); } diff --git a/src/libultra_code_O2/pfsallocatefile.c b/src/libultra_code_O2/pfsallocatefile.c index 03a87d0480..c20531224e 100644 --- a/src/libultra_code_O2/pfsallocatefile.c +++ b/src/libultra_code_O2/pfsallocatefile.c @@ -3,11 +3,14 @@ #include "ultra64/pfs.h" s32 osPfsAllocateFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u8* extName, s32 fileSize, s32* fileNo) { - s32 startPage, decleared, prevPage; + s32 startPage; + s32 decleared; + s32 prevPage; s32 oldPrevPage = 0; s32 ret = 0; s32 fileSizeInPages; - __OSInode inode, backup_inode; + __OSInode inode; + __OSInode backupInode; __OSDir dir; u8 bank; u8 prevBank = 0; @@ -58,14 +61,14 @@ s32 osPfsAllocateFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u fpage.inode_t.page = (u8)startPage; fpage.inode_t.bank = bank; } else { /* Writing previous bank inode */ - backup_inode.inodePage[oldPrevPage].inode_t.bank = bank; - backup_inode.inodePage[oldPrevPage].inode_t.page = (u8)startPage; - if ((ret = __osPfsRWInode(pfs, &backup_inode, PFS_WRITE, prevBank)) != 0) { + backupInode.inodePage[oldPrevPage].inode_t.bank = bank; + backupInode.inodePage[oldPrevPage].inode_t.page = (u8)startPage; + if ((ret = __osPfsRWInode(pfs, &backupInode, PFS_WRITE, prevBank)) != 0) { return ret; } } if (fileSizeInPages > decleared) { - bcopy(&inode, &backup_inode, sizeof(__OSInode)); + bcopy(&inode, &backupInode, sizeof(__OSInode)); oldPrevPage = prevPage; prevBank = bank; fileSizeInPages -= decleared; @@ -91,8 +94,7 @@ s32 osPfsAllocateFile(OSPfs* pfs, u16 companyCode, u32 gameCode, u8* gameName, u bcopy(gameName, dir.game_name, PFS_FILE_NAME_LEN); bcopy(extName, dir.ext_name, PFS_FILE_EXT_LEN); - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + *fileNo, &dir, 0); - return ret; + return __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + *fileNo, (u8*)&dir, 0); } s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, s32 fileSizeInPages, s32* startPage, u8 bank, s32* decleared, @@ -100,9 +102,8 @@ s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, s32 fileSizeInPages, s32* s s32 j; s32 spage, prevPage; s32 ret = 0; - s32 offset; + s32 offset = ((bank > PFS_ID_BANK_256K) ? 1 : pfs->inodeStartPage); - offset = ((bank > PFS_ID_BANK_256K) ? 1 : pfs->inodeStartPage); for (j = offset; j < PFS_INODE_SIZE_PER_PAGE; j++) { if (inode->inodePage[j].ipage == PFS_PAGE_NOT_USED) { break; @@ -126,6 +127,7 @@ s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, s32 fileSizeInPages, s32* s } j++; } + *startPage = spage; if ((j == (PFS_INODE_SIZE_PER_PAGE)) && (fileSizeInPages > *decleared)) { *finalPage = prevPage; diff --git a/src/libultra_code_O2/pfschecker.c b/src/libultra_code_O2/pfschecker.c index e4934a17ab..b0a94f1ad4 100644 --- a/src/libultra_code_O2/pfschecker.c +++ b/src/libultra_code_O2/pfschecker.c @@ -14,39 +14,32 @@ s32 osPfsChecker(OSPfs* pfs) { __OSInode tempInode; __OSDir tempDir; __OSInodeUnit nextNodeInFile[16]; - __OSInodeCache cache; - s32 fixed = 0; u8 bank, prevBank = 254; s32 cc, cl; s32 offset; ret = __osCheckId(pfs); - if (ret == PFS_ERR_NEW_PACK) { ret = __osGetId(pfs); } - if (ret) { return ret; } - if ((ret = func_80105788(pfs, &cache)) != 0) { return ret; } for (j = 0; j < pfs->dir_size; j++) { - if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, &tempDir)) != 0) { + if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tempDir)) != 0) { return ret; } - if ((tempDir.company_code != 0) || (tempDir.game_code != 0)) { if ((tempDir.company_code == 0) || (tempDir.game_code == 0)) { cc = -1; } else { next = tempDir.start_page; - cl = cc = 0; bank = 255; @@ -57,21 +50,17 @@ s32 osPfsChecker(OSPfs* pfs) { ret = __osPfsRWInode(pfs, &tempInode, PFS_READ, bank); prevBank = bank; } - if ((ret != 0) && (ret != PFS_ERR_INCONSISTENT)) { return ret; } } - if ((cc = func_80105A60(pfs, next, &cache) - cl) != 0) { break; } cl = 1; - next = tempInode.inodePage[next.inode_t.page]; } } - if ((cc != 0) || (next.ipage != PFS_EOF)) { bzero(&tempDir, sizeof(__OSDir)); if (pfs->activebank != 0) { @@ -79,7 +68,7 @@ s32 osPfsChecker(OSPfs* pfs) { return ret; } } - if ((ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, &tempDir, 0)) != 0) { + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tempDir, 0)) != 0) { return ret; } @@ -87,8 +76,9 @@ s32 osPfsChecker(OSPfs* pfs) { } } } + for (j = 0; j < pfs->dir_size; j++) { - if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, &tempDir)) != 0) { + if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tempDir)) != 0) { return ret; } @@ -184,7 +174,7 @@ s32 func_80105A60(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache) { if ((bank == fpage.inode_t.bank) || (cache->map[n] & (1 << (bank % PFS_BANK_LAPPED_BY))) != 0) { if (bank != cache->bank) { ret = __osPfsRWInode(pfs, &(cache->inode), PFS_READ, bank); - if ((ret) && (ret != PFS_ERR_INCONSISTENT)) { + if (ret && (ret != PFS_ERR_INCONSISTENT)) { return ret; } cache->bank = bank; diff --git a/src/libultra_code_O2/pfsinitpak.c b/src/libultra_code_O2/pfsinitpak.c index 377c4f6a5b..59fb8eda9b 100644 --- a/src/libultra_code_O2/pfsinitpak.c +++ b/src/libultra_code_O2/pfsinitpak.c @@ -26,11 +26,9 @@ s32 osPfsInitPak(OSMesgQueue* queue, OSPfs* pfs, s32 channel) { if ((ret = __osPfsCheckRamArea(pfs)) != 0) { return ret; } - if ((ret = __osPfsSelectBank(pfs, 0)) != 0) { return ret; } - if ((ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, temp)) != 0) { return (ret); } @@ -60,7 +58,7 @@ s32 osPfsInitPak(OSMesgQueue* queue, OSPfs* pfs, s32 channel) { bcopy(id, pfs->id, BLOCKSIZE); - if (0) {} + if (1) {} pfs->version = id->version; pfs->banks = id->banks; @@ -90,9 +88,8 @@ s32 __osPfsCheckRamArea(OSPfs* pfs) { if ((ret = __osPfsSelectBank(pfs, PFS_ID_BANK_256K)) != 0) { return ret; } - if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, saveReg)) != 0) { - return (ret); + return ret; } for (i = 0; i < BLOCKSIZE; i++) { temp1[i] = i; @@ -106,7 +103,5 @@ s32 __osPfsCheckRamArea(OSPfs* pfs) { if (bcmp(temp1, temp2, BLOCKSIZE) != 0) { return PFS_ERR_DEVICE; } - ret = __osContRamWrite(pfs->queue, pfs->channel, 0, saveReg, 0); - - return ret; + return __osContRamWrite(pfs->queue, pfs->channel, 0, saveReg, 0); } diff --git a/src/libultra_code_O2/pfsreadwritefile.c b/src/libultra_code_O2/pfsreadwritefile.c index 4a6d7755c2..9b99c08d2c 100644 --- a/src/libultra_code_O2/pfsreadwritefile.c +++ b/src/libultra_code_O2/pfsreadwritefile.c @@ -50,37 +50,29 @@ s32 osPfsReadWriteFile(OSPfs* pfs, s32 fileNo, u8 flag, s32 offset, s32 size, u8 if (!(pfs->status & PFS_INITIALIZED)) { return PFS_ERR_INVALID; } - if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) { return PFS_ERR_NEW_PACK; } - - if (pfs->activebank != 0) { - if ((ret = __osPfsSelectBank(pfs, 0)) != 0) { - return ret; - } - } - if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + fileNo, &dir)) != 0) { + if (pfs->activebank != 0 && (ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; + } + if ((ret = __osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + fileNo, (u8*)&dir)) != 0) { return ret; } - if ((dir.company_code == 0) || (dir.game_code == 0)) { return PFS_ERR_INVALID; } - if (!CHECK_IPAGE(dir.start_page, *pfs)) { if (dir.start_page.ipage == PFS_EOF) { return PFS_ERR_INVALID; } return PFS_ERR_INCONSISTENT; } - if ((flag == PFS_READ) && ((dir.status & PFS_WRITTEN) == 0)) { return PFS_ERR_BAD_DATA; } bank = 255; - curBlock = offset / BLOCKSIZE; curPage = dir.start_page; @@ -101,11 +93,8 @@ s32 osPfsReadWriteFile(OSPfs* pfs, s32 fileNo, u8 flag, s32 offset, s32 size, u8 } curBlock = 0; } - - if (pfs->activebank != curPage.inode_t.bank) { - if ((ret = __osPfsSelectBank(pfs, curPage.inode_t.bank)) != 0) { - return ret; - } + if (pfs->activebank != curPage.inode_t.bank && (ret = __osPfsSelectBank(pfs, curPage.inode_t.bank)) != 0) { + return ret; } blockno = curPage.inode_t.page * PFS_ONE_PAGE + curBlock; @@ -125,16 +114,13 @@ s32 osPfsReadWriteFile(OSPfs* pfs, s32 fileNo, u8 flag, s32 offset, s32 size, u8 if (flag == PFS_WRITE && !(dir.status & PFS_WRITTEN)) { dir.status |= PFS_WRITTEN; - if (pfs->activebank != 0) { - if ((ret = __osPfsSelectBank(pfs, 0)) != 0) { - return ret; - } + if (pfs->activebank != 0 && (ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; } - if ((ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + fileNo, &dir, 0)) != 0) { + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + fileNo, (u8*)&dir, 0)) != 0) { return ret; } } - ret = __osPfsGetStatus(pfs->queue, pfs->channel); - return ret; + return __osPfsGetStatus(pfs->queue, pfs->channel); } diff --git a/src/libultra_code_O2/rotate.c b/src/libultra_code_O2/rotate.c index a3fd9b978d..64d4bd6ac7 100644 --- a/src/libultra_code_O2/rotate.c +++ b/src/libultra_code_O2/rotate.c @@ -45,6 +45,7 @@ void guRotateF(f32 m[4][4], f32 a, f32 x, f32 y, f32 z) { void guRotate(Mtx* m, f32 a, f32 x, f32 y, f32 z) { f32 mf[4][4]; + guRotateF(mf, a, x, y, z); - guMtxF2L(mf, m); + guMtxF2L((MtxF*)mf, m); } diff --git a/src/libultra_code_O2/sinf.c b/src/libultra_code_O2/sinf.c index 0ebc955ca2..bb7f58e729 100644 --- a/src/libultra_code_O2/sinf.c +++ b/src/libultra_code_O2/sinf.c @@ -21,10 +21,9 @@ f32 sinf(f32 x) { f64 dn; s32 n; f64 result; - s32 ix, xpt; + s32 ix = *(s32*)&x; + s32 xpt = (ix >> 22); - ix = *(s32*)&x; - xpt = (ix >> 22); xpt &= 0x1FF; if (xpt < 0xFF) { @@ -55,7 +54,6 @@ f32 sinf(f32 x) { if (!(n & 1)) { return (f32)result; } - return -(f32)result; } diff --git a/src/libultra_code_O2/sp.c b/src/libultra_code_O2/sp.c index fcfb8880eb..67ccd8939c 100644 --- a/src/libultra_code_O2/sp.c +++ b/src/libultra_code_O2/sp.c @@ -1,11 +1,10 @@ #include "global.h" -u32 __osSpDeviceBusy() { +u32 __osSpDeviceBusy(void) { register u32 status = HW_REG(SP_STATUS_REG, u32); if (status & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL)) { return 1; } - return 0; } diff --git a/src/libultra_code_O2/sptask.c b/src/libultra_code_O2/sptask.c index aecb41d225..84a9624fbd 100644 --- a/src/libultra_code_O2/sptask.c +++ b/src/libultra_code_O2/sptask.c @@ -19,6 +19,7 @@ OSTask* _VirtualToPhysicalTask(OSTask* intp) { _osVirtualToPhysical(tp->t.output_buff_size); _osVirtualToPhysical(tp->t.data_ptr); _osVirtualToPhysical(tp->t.yield_data_ptr); + return tp; } @@ -29,34 +30,31 @@ void osSpTaskLoad(OSTask* intp) { tp->t.ucode_data = tp->t.yield_data_ptr; tp->t.ucode_data_size = tp->t.yield_data_size; intp->t.flags &= ~OS_TASK_YIELDED; + if (tp->t.flags & OS_TASK_LOADABLE) { tp->t.ucode = HW_REG((u32)intp->t.yield_data_ptr + OS_YIELD_DATA_SIZE - 4, u32); } } osWritebackDCache(tp, sizeof(OSTask)); __osSpSetStatus(SP_CLR_SIG0 | SP_CLR_SIG1 | SP_CLR_SIG2 | SP_SET_INTR_BREAK); + while (__osSpSetPc((void*)SP_IMEM_START) == -1) { ; } - while (__osSpRawStartDma(1, (void*)(SP_IMEM_START - sizeof(*tp)), tp, sizeof(OSTask)) == -1) { ; } - while (__osSpDeviceBusy()) { ; } - while (__osSpRawStartDma(1, (void*)SP_IMEM_START, tp->t.ucode_boot, tp->t.ucode_boot_size) == -1) { ; } } void osSpTaskStartGo(OSTask* tp) { - while (__osSpDeviceBusy()) { ; } - __osSpSetStatus(SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT); } diff --git a/src/libultra_code_O2/sqrtf.c b/src/libultra_code_O2/sqrtf.c index 1e0ea1221a..5e5fa233cc 100644 --- a/src/libultra_code_O2/sqrtf.c +++ b/src/libultra_code_O2/sqrtf.c @@ -1,7 +1,6 @@ #include "global.h" #ifndef __GNUC__ -#pragma intrinsic(sqrtf) #define __builtin_sqrtf sqrtf #endif diff --git a/src/libultra_code_O2_g3/sqrt.c b/src/libultra_code_O2_g3/sqrt.c index d280fadd08..0e8cc95d51 100644 --- a/src/libultra_code_O2_g3/sqrt.c +++ b/src/libultra_code_O2_g3/sqrt.c @@ -1,7 +1,6 @@ #include "global.h" #ifndef __GNUC__ -#pragma intrinsic(sqrt) #define __builtin_sqrt sqrt #endif