diff options
| author | Random <28494085+Random06457@users.noreply.github.com> | 2020-05-25 23:18:14 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-25 23:18:14 +0200 |
| commit | 3d050f286114de1332781ed951b90d42ac36c8ee (patch) | |
| tree | 0faeff040458535d810d4f7d4ba84643e3bcd134 /src | |
| parent | 13b1dc03bb2f26291c68e7d19e4e42625d3a2ec2 (diff) | |
Decompile a bunch of small files (#160)
* Decompile a bunch of small files
* Rename dacrate to dacRate
* Run format.sh
* Minor fixes in PR #160
Diffstat (limited to 'src')
| -rw-r--r-- | src/code/mtxuty-cvt.c | 23 | ||||
| -rw-r--r-- | src/code/padmgr.c | 4 | ||||
| -rw-r--r-- | src/code/padutils.c | 93 | ||||
| -rw-r--r-- | src/code/sys_matrix.c | 2 | ||||
| -rw-r--r-- | src/code/z_room.c | 2 | ||||
| -rw-r--r-- | src/libultra_boot_O1/initialize.c | 2 | ||||
| -rw-r--r-- | src/libultra_code/absf.c | 5 | ||||
| -rw-r--r-- | src/libultra_code/guS2DInitBg.c | 28 | ||||
| -rw-r--r-- | src/libultra_code/libultra_internal.h | 2 | ||||
| -rw-r--r-- | src/libultra_code/osAiSetFrequency.c | 24 | ||||
| -rw-r--r-- | src/libultra_code/osSetTimer.c | 42 | ||||
| -rw-r--r-- | src/libultra_code/osSpTaskYield.c | 5 | ||||
| -rw-r--r-- | src/libultra_code/osSpTaskYielded.c | 21 | ||||
| -rw-r--r-- | src/libultra_code/osStopTimer.c | 28 | ||||
| -rw-r--r-- | src/libultra_code/rotate.c | 50 | ||||
| -rw-r--r-- | src/libultra_code/sqrt.c | 10 | ||||
| -rw-r--r-- | src/libultra_code/sqrtf.c | 6 | ||||
| -rw-r--r-- | src/overlays/actors/ovl_En_Hintnuts/z_en_hintnuts.c | 2 |
18 files changed, 337 insertions, 12 deletions
diff --git a/src/code/mtxuty-cvt.c b/src/code/mtxuty-cvt.c new file mode 100644 index 000000000..0f1f6a7ff --- /dev/null +++ b/src/code/mtxuty-cvt.c @@ -0,0 +1,23 @@ +#include <global.h> + +void MtxConv_F2L(MatrixInternal* m1, MtxF* m2) { + s32 i; + s32 j; + + LogUtils_CheckNullPointer("m1", m1, "../mtxuty-cvt.c", 31); + LogUtils_CheckNullPointer("m2", m2, "../mtxuty-cvt.c", 32); + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + s32 value = (m2->mf[i][j] * 0x10000); + m1->intPart[i][j] = value >> 16; + m1->fracPart[i][j] = value; + } + } +} + +void MtxConv_L2F(MtxF* m1, Mtx* m2) { + LogUtils_CheckNullPointer("m1", m1, "../mtxuty-cvt.c", 55); + LogUtils_CheckNullPointer("m2", m2, "../mtxuty-cvt.c", 56); + func_80102FA0(m1, m2); // guMtxL2F ? +} diff --git a/src/code/padmgr.c b/src/code/padmgr.c index 745c058e4..b81116e6a 100644 --- a/src/code/padmgr.c +++ b/src/code/padmgr.c @@ -272,7 +272,7 @@ void PadMgr_ProcessInputs(PadMgr* padmgr) { } input->press.in.button = input->cur.in.button & (input->prev.in.button ^ input->cur.in.button); input->rel.in.button = input->prev.in.button & (input->prev.in.button ^ input->cur.in.button); - func_800FCC6C(input); + PadUtils_UpdateRelXY(input); input->press.in.x = (input->cur.in.x - input->prev.in.x) + input->press.in.x; input->press.in.y = (input->cur.in.y - input->prev.in.y) + input->press.in.y; } @@ -360,7 +360,7 @@ void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 mode) { newin->cur = pmInputs->cur; newin->press.in.button = newin->cur.in.button & (newin->prev.in.button ^ newin->cur.in.button); newin->rel.in.button = newin->prev.in.button & (newin->prev.in.button ^ newin->cur.in.button); - func_800FCC6C(newin); + PadUtils_UpdateRelXY(newin); newin->press.in.x = (newin->cur.in.x - newin->prev.in.x) + newin->press.in.x; newin->press.in.y = (newin->cur.in.y - newin->prev.in.y) + newin->press.in.y; } diff --git a/src/code/padutils.c b/src/code/padutils.c new file mode 100644 index 000000000..b19fdbf12 --- /dev/null +++ b/src/code/padutils.c @@ -0,0 +1,93 @@ +#include <global.h> + +void PadUtils_Init(Input* input) { + bzero(input, sizeof(Input)); +} + +void func_800FCB70() { +} + +void PadUtils_ResetPressRel(Input* input) { + input->press.in.button = 0; + input->rel.in.button = 0; +} + +u32 PadUtils_CheckCurExact(Input* input, u16 value) { + return value == input->cur.in.button; +} + +u32 PadUtils_CheckCur(Input* input, u16 key) { + return key == (input->cur.in.button & key); +} + +u32 PadUtils_CheckPressed(Input* input, u16 key) { + return key == (input->press.in.button & key); +} + +u32 PadUtils_CheckReleased(Input* input, u16 key) { + return key == (input->rel.in.button & key); +} + +u16 PadUtils_GetCurButton(Input* input) { + return input->cur.in.button; +} + +u16 PadUtils_GetPressButton(Input* input) { + return input->press.in.button; +} + +s8 PadUtils_GetCurX(Input* input) { + return input->cur.in.x; +} + +s8 PadUtils_GetCurY(Input* input) { + return input->cur.in.y; +} + +void PadUtils_SetRelXY(Input* input, s32 x, s32 y) { + input->rel.in.x = x; + input->rel.in.y = y; +} + +s8 PadUtils_GetRelXImpl(Input* input) { + return input->rel.in.x; +} + +s8 PadUtils_GetRelYImpl(Input* input) { + return input->rel.in.y; +} + +s8 PadUtils_GetRelX(Input* input) { + return PadUtils_GetRelXImpl(input); +} + +s8 PadUtils_GetRelY(Input* input) { + return PadUtils_GetRelYImpl(input); +} + +void PadUtils_UpdateRelXY(Input* input) { + s32 curX, curY; + s32 relX, relY; + + curX = PadUtils_GetCurX(input); + curY = PadUtils_GetCurY(input); + + if (curX > 7) { + relX = (curX < 0x43) ? curX - 7 : 0x43 - 7; + } else if (curX < -7) { + relX = (curX > -0x43) ? curX + 7 : -0x43 + 7; + } else { + relX = 0; + } + + if (curY > 7) { + relY = (curY < 0x43) ? curY - 7 : 0x43 - 7; + + } else if (curY < -7) { + relY = (curY > -0x43) ? curY + 7 : -0x43 + 7; + } else { + relY = 0; + } + + PadUtils_SetRelXY(input, relX, relY); +} diff --git a/src/code/sys_matrix.c b/src/code/sys_matrix.c index f0b3e4005..487e1a841 100644 --- a/src/code/sys_matrix.c +++ b/src/code/sys_matrix.c @@ -935,7 +935,7 @@ void func_800D2A98(Mtx* mtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4) { MtxF mf; func_800D2A34(&mf, arg1, arg2, arg3, arg4); - func_801064E0(&mf, mtx); + guMtxF2L(&mf, mtx); } void func_800D2AE4(Mtx* mtx, f32 arg1, f32 arg2, f32 arg3, f32 arg4) { diff --git a/src/code/z_room.c b/src/code/z_room.c index 233cbdc39..90ca8ce64 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -299,7 +299,7 @@ void func_8009638C(Gfx** displayList, u32 source, u32 tlut, u16 width, u16 heigh if ((fmt == G_IM_FMT_RGBA) && (SREG(26) == 0)) { bg->b.frameW = width * 4; bg->b.frameH = height * 4; - func_80104B00(bg); + guS2DInitBg(bg); gDPSetOtherMode(displayListHead++, mode0 | G_TL_TILE | G_TD_CLAMP | G_TP_NONE | G_CYC_COPY | G_PM_NPRIMITIVE, G_AC_THRESHOLD | G_ZS_PIXEL | G_RM_NOOP | G_RM_NOOP2); gSPBgRectCopy(displayListHead++, bg); diff --git a/src/libultra_boot_O1/initialize.c b/src/libultra_boot_O1/initialize.c index 3683ad3b8..29d484661 100644 --- a/src/libultra_boot_O1/initialize.c +++ b/src/libultra_boot_O1/initialize.c @@ -9,7 +9,7 @@ typedef struct { } struct_exceptionPreamble; u64 osClockRate = OS_CLOCK_RATE; -u32 osViClock = VI_NTSC_CLOCK; +s32 osViClock = VI_NTSC_CLOCK; u32 __osShutdown = 0; u32 __OSGlobalIntMask = 0x003FFF01; diff --git a/src/libultra_code/absf.c b/src/libultra_code/absf.c new file mode 100644 index 000000000..d78355af5 --- /dev/null +++ b/src/libultra_code/absf.c @@ -0,0 +1,5 @@ +#include <global.h> + +f32 absf(f32 a) { + return fabsf(a); +} diff --git a/src/libultra_code/guS2DInitBg.c b/src/libultra_code/guS2DInitBg.c new file mode 100644 index 000000000..32c46f169 --- /dev/null +++ b/src/libultra_code/guS2DInitBg.c @@ -0,0 +1,28 @@ +#include <global.h> + +void guS2DInitBg(uObjBg* bg) { + u16 shift; + u32 size; + s32 tmem; + + 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; + bg->b.tmemSizeW = bg->b.tmemW * 2; + bg->b.tmemSize = bg->b.tmemH * bg->b.tmemSizeW; + bg->b.tmemLoadSH = (bg->b.tmemSize >> 1) - 1; + bg->b.tmemLoadTH = (0x7FF / bg->b.tmemW) + 1; + } else { // G_BGLT_LOADTILE + bg->b.tmemW = (bg->b.frameW >> shift) + 3; + bg->b.tmemH = (tmem / bg->b.tmemW) * 4; + bg->b.tmemSizeW = (bg->b.imageW >> shift) * 2; + + size = bg->b.tmemH * bg->b.tmemSizeW; + bg->b.tmemSize = (size >> 16); + bg->b.tmemLoadSH = (size >> 0) & 0xFFFF; + bg->b.tmemLoadTH = bg->b.tmemH - 1; + } +} diff --git a/src/libultra_code/libultra_internal.h b/src/libultra_code/libultra_internal.h index fe9b29abb..6a6e7caac 100644 --- a/src/libultra_code/libultra_internal.h +++ b/src/libultra_code/libultra_internal.h @@ -4,8 +4,6 @@ // TODO: rename these // SM64 OOT -#define guMtxF2L func_801064E0 // believed to be correct name, needs confirmation. - s32 __osDisableInt(); void __osRestoreInt(s32); void __osEnqueueAndYield(OSThread**); diff --git a/src/libultra_code/osAiSetFrequency.c b/src/libultra_code/osAiSetFrequency.c new file mode 100644 index 000000000..f16d8cec3 --- /dev/null +++ b/src/libultra_code/osAiSetFrequency.c @@ -0,0 +1,24 @@ +#include <global.h> +#include <ultra64/hardware.h> + +s32 osAiSetFrequency(u32 frequency) { + u32 dacRate; + u8 bitrate; + f32 dacRateF; + + dacRateF = ((f32)osViClock / frequency) + 0.5f; + dacRate = dacRateF; + + if (dacRate < 132) { + return -1; + } + + bitrate = (dacRate / 66); + if (bitrate > 16) { + bitrate = 16; + } + + HW_REG(AI_DACRATE_REG, u32) = dacRate - 1; + HW_REG(AI_BITRATE_REG, u32) = bitrate - 1; + return osViClock / (s32)dacRate; +} diff --git a/src/libultra_code/osSetTimer.c b/src/libultra_code/osSetTimer.c new file mode 100644 index 000000000..fd78ba184 --- /dev/null +++ b/src/libultra_code/osSetTimer.c @@ -0,0 +1,42 @@ +#include <global.h> + +s32 osSetTimer(OSTimer* timer, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg) { + OSTime time; + OSTimer* next; + u32 count; + u32 value; + s32 prevInt; + + timer->next = NULL; + timer->prev = NULL; + timer->interval = interval; + if (countdown != 0) { + timer->value = countdown; + } else { + timer->value = interval; + } + timer->mq = mq; + timer->msg = msg; + + prevInt = __osDisableInt(); + if (__osTimerList->next != __osTimerList) { + + if (1) {} + next = __osTimerList->next; + count = osGetCount(); + value = count - __osTimerCounter; + + if (value < next->value) { + next->value -= value; + } else { + next->value = 1; + } + } + + time = __osInsertTimer(timer); + __osSetTimerIntr(__osTimerList->next->value); + + __osRestoreInt(prevInt); + + return 0; +} diff --git a/src/libultra_code/osSpTaskYield.c b/src/libultra_code/osSpTaskYield.c new file mode 100644 index 000000000..ec98ec332 --- /dev/null +++ b/src/libultra_code/osSpTaskYield.c @@ -0,0 +1,5 @@ +#include <global.h> + +void osSpTaskYield() { + __osSpSetStatus(SP_STATUS_SIG3); +} diff --git a/src/libultra_code/osSpTaskYielded.c b/src/libultra_code/osSpTaskYielded.c new file mode 100644 index 000000000..ed151a615 --- /dev/null +++ b/src/libultra_code/osSpTaskYielded.c @@ -0,0 +1,21 @@ +#include <global.h> + +u32 osSpTaskYielded(OSTask* task) { + u32 ret; + u32 status; + + status = __osSpGetStatus(); + + if (status & SP_STATUS_YIELDED) { + ret = OS_TASK_YIELDED; + } else { + ret = 0; + } + + if (status & SP_STATUS_YIELD) { + task->t.flags |= ret; + task->t.flags &= ~OS_TASK_DP_WAIT; + } + + return ret; +} diff --git a/src/libultra_code/osStopTimer.c b/src/libultra_code/osStopTimer.c new file mode 100644 index 000000000..6e8a94fc8 --- /dev/null +++ b/src/libultra_code/osStopTimer.c @@ -0,0 +1,28 @@ +#include <global.h> + +s32 osStopTimer(OSTimer* timer) { + register s32 prevInt; + OSTimer* next; + + if (!timer->next) { + return -1; + } + + prevInt = __osDisableInt(); + + next = timer->next; + if (next != __osTimerList) { + next->value += timer->value; + } + + timer->prev->next = timer->next; + timer->next->prev = timer->prev; + timer->next = NULL; + timer->prev = NULL; + if (__osTimerList->next == __osTimerList) { + __osSetCompare(0); + } + + __osRestoreInt(prevInt); + return 0; +} diff --git a/src/libultra_code/rotate.c b/src/libultra_code/rotate.c new file mode 100644 index 000000000..79752bfa6 --- /dev/null +++ b/src/libultra_code/rotate.c @@ -0,0 +1,50 @@ +#include <global.h> + +void guRotateF(f32 m[4][4], f32 a, f32 x, f32 y, f32 z) { + static f32 D_80134D10 = M_PI / 180.0f; + f32 sine; + f32 cosine; + f32 ab; + f32 bc; + f32 ca; + f32 t; + f32 xs; + f32 ys; + f32 zs; + + guNormalize(&x, &y, &z); + + a = a * D_80134D10; + + sine = sinf(a); + cosine = cosf(a); + + ab = x * y * (1 - cosine); + bc = y * z * (1 - cosine); + ca = z * x * (1 - cosine); + + guMtxIdentF(m); + + xs = x * sine; + ys = y * sine; + zs = z * sine; + + t = x * x; + m[0][0] = (1 - t) * cosine + t; + m[2][1] = bc - xs; + m[1][2] = bc + xs; + t = y * y; + m[1][1] = (1 - t) * cosine + t; + m[2][0] = ca + ys; + m[0][2] = ca - ys; + t = z * z; + m[2][2] = (1 - t) * cosine + t; + m[1][0] = ab - zs; + m[0][1] = ab + zs; +} + +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); +} diff --git a/src/libultra_code/sqrt.c b/src/libultra_code/sqrt.c new file mode 100644 index 000000000..98b338362 --- /dev/null +++ b/src/libultra_code/sqrt.c @@ -0,0 +1,10 @@ +#include <global.h> + +#ifndef __GNUC__ +#pragma intrinsic(sqrt) +#define __builtin_sqrt sqrt +#endif + +f64 sqrt(f64 f) { + return __builtin_sqrt(f); +} diff --git a/src/libultra_code/sqrtf.c b/src/libultra_code/sqrtf.c index c582b7f6d..59ab57ce8 100644 --- a/src/libultra_code/sqrtf.c +++ b/src/libultra_code/sqrtf.c @@ -1,12 +1,10 @@ -#include <math.h> - -float sqrtf(float f); +#include <global.h> #ifndef __GNUC__ #pragma intrinsic(sqrtf) #define __builtin_sqrtf sqrtf #endif -float sqrtf(float f) { +f32 sqrtf(f32 f) { return __builtin_sqrtf(f); } diff --git a/src/overlays/actors/ovl_En_Hintnuts/z_en_hintnuts.c b/src/overlays/actors/ovl_En_Hintnuts/z_en_hintnuts.c index 20a90a02a..aeaa0eb99 100644 --- a/src/overlays/actors/ovl_En_Hintnuts/z_en_hintnuts.c +++ b/src/overlays/actors/ovl_En_Hintnuts/z_en_hintnuts.c @@ -234,7 +234,7 @@ void EnHintnuts_Wait(EnHintnuts* this, GlobalContext* globalCtx) { if (func_800A56C8(&this->skelAnime, 9.0f) != 0) { this->collider.base.acFlags |= 1; } else if (func_800A56C8(&this->skelAnime, 8.0f) != 0) { - Audio_PlayActorSound2(&this->actor, NA_SE_EN_NUTS_UP); + Audio_PlayActorSound2(&this->actor, NA_SE_EN_NUTS_UP); } if (this->skelAnime.animCurrentFrame < 9.0f) { boundedCurrentFrame = 9.0f; |
