From bd56f6060fd737b5bb6d42a7a408d83c21bf979b Mon Sep 17 00:00:00 2001 From: JoshDuMan <40190173+JoshDuMan@users.noreply.github.com> Date: Wed, 29 Dec 2021 15:14:20 -0500 Subject: [PATCH] Decomp Some Libultra (#588) * Work on KMC Libultra * libultra decomp * fix --- include/PR/os_internal_reg.h | 4 +- include/PR/osint.h | 48 +++++ include/functions.h | 2 +- include/types.h | 2 +- include/variables.h | 3 - src/os/3FEA0.c | 22 --- src/os/3d2f0_len_10.c | 3 - src/os/3d300_len_30.c | 3 - src/os/3dcc0_len_a60.c | 10 -- src/os/3e720_len_5f0.c | 7 - src/os/3ef90_len_600.c | 8 - src/os/3f310_len_3c0.c | 9 - src/os/3f6d0_len_320.c | 7 - src/os/3fa50_len_f60.c | 11 -- src/os/40c20_len_1f0.c | 7 - src/os/41c60_len_c0.c | 2 +- src/os/coss.c | 9 + src/os/guFrustum.c | 42 ++++- src/os/guLookAt.c | 76 +++++++- src/os/lookathil.c | 165 ++++++++++++++++++ src/os/lookatref.c | 102 +++++++++++ src/os/osCreateMesgQueue.c | 10 +- src/os/osJamMesg.c | 28 ++- src/os/osRecvMesg.c | 31 +++- src/os/osSetThreadPri.c | 8 +- src/os/osVirtualToPhysical.c | 14 +- src/os/perspective.c | 53 ++++++ src/os/position.c | 56 ++++++ src/os/rotateRPY.c | 47 +++++ src/os/sendmesg.c | 37 ++++ src/os/seteventmesg.c | 4 + src/os/sins.c | 24 ++- src/os/sprintf.c | 25 +++ src/os/sqrtf.c | 5 + src/os/string.c | 41 +++++ .../asm/nonmatchings/os/3FEA0/proutSprintf.s | 18 -- .../asm/nonmatchings/os/3d2f0_len_10/sqrtf.s | 8 - .../os/41420_len_120/osStartThread.s | 4 +- .../os/41540_len_c0/osStopThread.s | 2 +- .../os/41640_len_50/osYieldThread.s | 2 +- .../{osProbeTLB.s => __osProbeTLB.s} | 2 +- .../os/osCreateMesgQueue/osCreateMesgQueue.s | 16 -- .../osSetEventMesg.s | 0 .../os/3fa50_len_f60 => os}/bcopy.s | 6 + .../os/3fa50_len_f60 => os}/bzero.s | 6 + .../os/3d300_len_30 => os/coss}/coss.s | 0 ver/us/asm/os/exceptasm.s | 8 +- .../os/guFrustum/guFrustum.s | 0 .../os/guFrustum/guFrustumF.s | 0 .../{nonmatchings => }/os/guLookAt/guLookAt.s | 0 .../os/guLookAt/guLookAtF.s | 0 .../lookathil}/guLookAtHilite.s | 0 .../lookathil}/guLookAtHiliteF.s | 0 .../lookatref}/guLookAtReflect.s | 0 .../lookatref}/guLookAtReflectF.s | 0 .../os/osJamMesg/osJamMesg.s | 4 +- .../os/osRecvMesg/osRecvMesg.s | 4 +- .../osVirtualToPhysical/osVirtualToPhysical.s | 2 +- .../perspective}/guPerspective.s | 0 .../perspective}/guPerspectiveF.s | 0 .../position}/guPosition.s | 0 .../position}/guPositionF.s | 0 .../rotateRPY}/guRotateRPY.s | 0 .../rotateRPY}/guRotateRPYF.s | 0 .../sendmesg}/osSendMesg.s | 4 +- ver/us/asm/{nonmatchings => }/os/sins/sins.s | 0 .../os/3fa50_len_f60 => os/string}/memcpy.s | 0 .../os/3fa50_len_f60 => os/string}/strchr.s | 0 .../os/3fa50_len_f60 => os/string}/strlen.s | 0 ver/us/splat.yaml | 48 ++--- ver/us/symbol_addrs.txt | 6 +- 71 files changed, 868 insertions(+), 197 deletions(-) create mode 100644 include/PR/osint.h delete mode 100644 src/os/3d2f0_len_10.c delete mode 100644 src/os/3d300_len_30.c delete mode 100644 src/os/3dcc0_len_a60.c delete mode 100644 src/os/3e720_len_5f0.c delete mode 100644 src/os/3ef90_len_600.c delete mode 100644 src/os/3f310_len_3c0.c delete mode 100644 src/os/3f6d0_len_320.c delete mode 100644 src/os/3fa50_len_f60.c delete mode 100644 src/os/40c20_len_1f0.c create mode 100644 src/os/coss.c create mode 100644 src/os/lookathil.c create mode 100644 src/os/lookatref.c create mode 100644 src/os/perspective.c create mode 100644 src/os/position.c create mode 100644 src/os/rotateRPY.c create mode 100644 src/os/sendmesg.c create mode 100644 src/os/seteventmesg.c create mode 100644 src/os/sprintf.c create mode 100644 src/os/sqrtf.c create mode 100644 src/os/string.c delete mode 100644 ver/us/asm/nonmatchings/os/3FEA0/proutSprintf.s delete mode 100644 ver/us/asm/nonmatchings/os/3d2f0_len_10/sqrtf.s rename ver/us/asm/nonmatchings/os/41c60_len_c0/{osProbeTLB.s => __osProbeTLB.s} (99%) delete mode 100644 ver/us/asm/nonmatchings/os/osCreateMesgQueue/osCreateMesgQueue.s rename ver/us/asm/nonmatchings/os/{40c20_len_1f0 => seteventmesg}/osSetEventMesg.s (100%) rename ver/us/asm/{nonmatchings/os/3fa50_len_f60 => os}/bcopy.s (98%) rename ver/us/asm/{nonmatchings/os/3fa50_len_f60 => os}/bzero.s (94%) rename ver/us/asm/{nonmatchings/os/3d300_len_30 => os/coss}/coss.s (100%) rename ver/us/asm/{nonmatchings => }/os/guFrustum/guFrustum.s (100%) rename ver/us/asm/{nonmatchings => }/os/guFrustum/guFrustumF.s (100%) rename ver/us/asm/{nonmatchings => }/os/guLookAt/guLookAt.s (100%) rename ver/us/asm/{nonmatchings => }/os/guLookAt/guLookAtF.s (100%) rename ver/us/asm/{nonmatchings/os/3dcc0_len_a60 => os/lookathil}/guLookAtHilite.s (100%) rename ver/us/asm/{nonmatchings/os/3dcc0_len_a60 => os/lookathil}/guLookAtHiliteF.s (100%) rename ver/us/asm/{nonmatchings/os/3e720_len_5f0 => os/lookatref}/guLookAtReflect.s (100%) rename ver/us/asm/{nonmatchings/os/3e720_len_5f0 => os/lookatref}/guLookAtReflectF.s (100%) rename ver/us/asm/{nonmatchings => }/os/osJamMesg/osJamMesg.s (97%) rename ver/us/asm/{nonmatchings => }/os/osRecvMesg/osRecvMesg.s (97%) rename ver/us/asm/{nonmatchings => }/os/osVirtualToPhysical/osVirtualToPhysical.s (96%) rename ver/us/asm/{nonmatchings/os/3ef90_len_600 => os/perspective}/guPerspective.s (100%) rename ver/us/asm/{nonmatchings/os/3ef90_len_600 => os/perspective}/guPerspectiveF.s (100%) rename ver/us/asm/{nonmatchings/os/3f310_len_3c0 => os/position}/guPosition.s (100%) rename ver/us/asm/{nonmatchings/os/3f310_len_3c0 => os/position}/guPositionF.s (100%) rename ver/us/asm/{nonmatchings/os/3f6d0_len_320 => os/rotateRPY}/guRotateRPY.s (100%) rename ver/us/asm/{nonmatchings/os/3f6d0_len_320 => os/rotateRPY}/guRotateRPYF.s (100%) rename ver/us/asm/{nonmatchings/os/40c20_len_1f0 => os/sendmesg}/osSendMesg.s (97%) rename ver/us/asm/{nonmatchings => }/os/sins/sins.s (100%) rename ver/us/asm/{nonmatchings/os/3fa50_len_f60 => os/string}/memcpy.s (100%) rename ver/us/asm/{nonmatchings/os/3fa50_len_f60 => os/string}/strchr.s (100%) rename ver/us/asm/{nonmatchings/os/3fa50_len_f60 => os/string}/strlen.s (100%) diff --git a/include/PR/os_internal_reg.h b/include/PR/os_internal_reg.h index cb5e40e4ae..a161998118 100755 --- a/include/PR/os_internal_reg.h +++ b/include/PR/os_internal_reg.h @@ -40,8 +40,8 @@ extern void __osSetConfig(u32); extern void __osSetCount(u32); extern u32 __osGetSR(void); extern void __osSetSR(u32); -extern u32 ____osDisableInt(void); -extern void ____osRestoreInt(u32); +extern u32 __osDisableInt(void); +extern void __osRestoreInt(u32); extern u32 __osGetWatchLo(void); extern void __osSetWatchLo(u32); diff --git a/include/PR/osint.h b/include/PR/osint.h new file mode 100644 index 0000000000..943be14b4a --- /dev/null +++ b/include/PR/osint.h @@ -0,0 +1,48 @@ +#ifndef _OSINT_H +#define _OSINT_H +#include +typedef struct __OSEventState +{ + OSMesgQueue *messageQueue; + OSMesg message; +} __OSEventState; +extern struct __osThreadTail +{ + OSThread *next; + OSPri priority; +} __osThreadTail; + +//maybe should be in exceptasm.h? +extern void __osEnqueueAndYield(OSThread **); +extern void __osDequeueThread(OSThread **, OSThread *); +extern void __osEnqueueThread(OSThread **, OSThread *); +extern OSThread *__osPopThread(OSThread **); +extern void __osDispatchThread(void); + +extern void __osSetTimerIntr(OSTime); +extern OSTime __osInsertTimer(OSTimer *); +extern void __osTimerInterrupt(void); +extern u32 __osProbeTLB(void *); +extern int __osSpDeviceBusy(void); + +extern OSThread *__osRunningThread; +extern OSThread *__osActiveQueue; +extern OSThread *__osFaultedThread; +extern OSThread *__osRunQueue; + +extern OSTimer *__osTimerList; +extern OSTimer __osBaseTimer; +extern OSTime __osCurrentTime; +extern u32 __osBaseCounter; +extern u32 __osViIntrCount; +extern u32 __osTimerCounter; + +extern __OSEventState __osEventStateTab[OS_NUM_EVENTS]; + + +//not sure if this should be here +extern s32 osViClock; +extern void __osTimerServicesInit(void); +extern s32 __osAiDeviceBusy(void); +extern int __osDpDeviceBusy(void); +#endif diff --git a/include/functions.h b/include/functions.h index 1ea2510f66..e3967f804c 100644 --- a/include/functions.h +++ b/include/functions.h @@ -29,7 +29,7 @@ HeapNode* _heap_create(HeapNode* addr, u32 size); s32 dma_copy(Addr romStart, Addr romEnd, void* vramDest); void copy_matrix(Matrix4f src, Matrix4f dest); -s32 _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap); +s32 _Printf(PrintCallback pfn, char* arg, const char* fmt, va_list ap); s32 get_global_byte(s32 index); s32 get_global_flag(s32 index); diff --git a/include/types.h b/include/types.h index 37b7f95fc8..2329818d17 100644 --- a/include/types.h +++ b/include/types.h @@ -12,7 +12,7 @@ typedef void (*StateFunc)(void); -typedef void* (*PrintCallback)(void*, const char*, u32); +typedef char* (*PrintCallback)(void*, const char*, u32); /// Linker symbol address, as in `ld_addrs.h`. typedef u8 Addr[]; diff --git a/include/variables.h b/include/variables.h index afa291564f..c9470bab58 100644 --- a/include/variables.h +++ b/include/variables.h @@ -338,9 +338,6 @@ extern MusicSettings D_8014F6F0; // OS extern OSThread D_800A4270; // idle thread, id 1 extern OSThread D_800A4420; // id 3 -extern OSThread* __osActiveQueue; -extern OSThread* __osRunningThread; -extern OSThread* __osRunQueue; extern OSDevMgr __osPiDevMgr; // gfx diff --git a/src/os/3FEA0.c b/src/os/3FEA0.c index b898c85158..27af5b70c7 100644 --- a/src/os/3FEA0.c +++ b/src/os/3FEA0.c @@ -1,31 +1,9 @@ -#define MOVE_ADDU - #include "common.h" #include "stdlib/stdarg.h" -s32 proutSprintf(); - char spaces[] = " "; char zeroes[] = "00000000000000000000000000000000"; INCLUDE_ASM(s32, "os/3FEA0", _Printf); INCLUDE_ASM(s32, "os/3FEA0", _Putfld); - -int sprintf(char* s, const char* fmt, ...) { - s32 ret; - va_list argp; - va_start(argp, fmt); - - ret = _Printf(&proutSprintf, s, fmt, argp); - - if (ret < 0) { - return ret; - } - - s[ret] = 0; - return ret; -} - - -INCLUDE_ASM(s32, "os/3FEA0", proutSprintf); diff --git a/src/os/3d2f0_len_10.c b/src/os/3d2f0_len_10.c deleted file mode 100644 index 71196fc12d..0000000000 --- a/src/os/3d2f0_len_10.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "common.h" - -INCLUDE_ASM(f32, "os/3d2f0_len_10", sqrtf, f32 value); diff --git a/src/os/3d300_len_30.c b/src/os/3d300_len_30.c deleted file mode 100644 index f5ca895a1f..0000000000 --- a/src/os/3d300_len_30.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "common.h" - -INCLUDE_ASM(s16, "os/3d300_len_30", coss, u16 angle); diff --git a/src/os/3dcc0_len_a60.c b/src/os/3dcc0_len_a60.c deleted file mode 100644 index 72b0a9345c..0000000000 --- a/src/os/3dcc0_len_a60.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "common.h" - -INCLUDE_ASM(void, "os/3dcc0_len_a60", guLookAtHiliteF, float mf[4][4], LookAt* l, Hilite* h, float xEye, - float yEye, - float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp, float xl1, float yl1, - float zl1, float xl2, float yl2, float zl2, int twidth, int theight); - -INCLUDE_ASM(void, "os/3dcc0_len_a60", guLookAtHilite, Mtx* m, LookAt* l, Hilite* h, float xEye, float yEye, - float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp, float xl1, float yl1, - float zl1, float xl2, float yl2, float zl2, int twidth, int theight); diff --git a/src/os/3e720_len_5f0.c b/src/os/3e720_len_5f0.c deleted file mode 100644 index b5f16d2457..0000000000 --- a/src/os/3e720_len_5f0.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "common.h" - -INCLUDE_ASM(void, "os/3e720_len_5f0", guLookAtReflectF, float mf[4][4], LookAt* l, float xEye, float yEye, - float zEye, float xAt, float yAt, float zAt, float xUp, float yUp, float zUp); - -INCLUDE_ASM(void, "os/3e720_len_5f0", guLookAtReflect, Mtx* m, LookAt* l, float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, float xUp, float yUp, float zUp); diff --git a/src/os/3ef90_len_600.c b/src/os/3ef90_len_600.c deleted file mode 100644 index 237a6df992..0000000000 --- a/src/os/3ef90_len_600.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "common.h" - -INCLUDE_ASM(void, "os/3ef90_len_600", guPerspectiveF, float mf[4][4], u16* perspNorm, float fovy, float aspect, - float near, float far, float scale); - -INCLUDE_ASM(void, "os/3ef90_len_600", guPerspective, Mtx* m, u16* perspNorm, float fovy, float aspect, - float near, - float far, float scale); diff --git a/src/os/3f310_len_3c0.c b/src/os/3f310_len_3c0.c deleted file mode 100644 index 681acc6aaf..0000000000 --- a/src/os/3f310_len_3c0.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "common.h" - -f32 dtor = M_DTOR; - -INCLUDE_ASM(void, "os/3f310_len_3c0", guPositionF, float mf[4][4], float r, float p, float h, float s, float x, - float y, float z); - -INCLUDE_ASM(void, "os/3f310_len_3c0", guPosition, Mtx* m, float r, float p, float h, float s, float x, float y, - float z); diff --git a/src/os/3f6d0_len_320.c b/src/os/3f6d0_len_320.c deleted file mode 100644 index 431d600efe..0000000000 --- a/src/os/3f6d0_len_320.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "common.h" - -f32 D_80093DD0 = M_DTOR; - -INCLUDE_ASM(void, "os/3f6d0_len_320", guRotateRPYF, float mf[4][4], f32 x, f32 y, f32 z); - -INCLUDE_ASM(void, "os/3f6d0_len_320", guRotateRPY, Mtx *m, float r, float p, float y); diff --git a/src/os/3fa50_len_f60.c b/src/os/3fa50_len_f60.c deleted file mode 100644 index 7fc8be8a95..0000000000 --- a/src/os/3fa50_len_f60.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "common.h" - -INCLUDE_ASM(void, "os/3fa50_len_f60", bcopy, const void* src, void* dst, int size); - -INCLUDE_ASM(void, "os/3fa50_len_f60", bzero, void* buf, int size); - -INCLUDE_ASM(s32, "os/3fa50_len_f60", strchr); - -INCLUDE_ASM(s32, "os/3fa50_len_f60", strlen); - -INCLUDE_ASM(s32, "os/3fa50_len_f60", memcpy); diff --git a/src/os/40c20_len_1f0.c b/src/os/40c20_len_1f0.c deleted file mode 100644 index ce656a3075..0000000000 --- a/src/os/40c20_len_1f0.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "common.h" - -u32 __osPreNMI = 0; - -INCLUDE_ASM(s32, "os/40c20_len_1f0", osSendMesg, OSMesgQueue* queue, OSMesg mesg, s32 unk); - -INCLUDE_ASM(void, "os/40c20_len_1f0", osSetEventMesg, OSEvent event, OSMesgQueue* queue, OSMesg mesg); diff --git a/src/os/41c60_len_c0.c b/src/os/41c60_len_c0.c index b732af1102..bdeaed24e6 100644 --- a/src/os/41c60_len_c0.c +++ b/src/os/41c60_len_c0.c @@ -1,3 +1,3 @@ #include "common.h" -INCLUDE_ASM(s32, "os/41c60_len_c0", osProbeTLB); +INCLUDE_ASM(s32, "os/41c60_len_c0", __osProbeTLB); diff --git a/src/os/coss.c b/src/os/coss.c new file mode 100644 index 0000000000..d939fcf22f --- /dev/null +++ b/src/os/coss.c @@ -0,0 +1,9 @@ +#include "common.h" + +#ifndef KMC_ASM +s16 coss(u16 angle) { + return sins(angle + 0x4000); +} +#else +INCLUDE_ASM_LIBULTRA(s16, "coss", coss, u16 angle); +#endif diff --git a/src/os/guFrustum.c b/src/os/guFrustum.c index 9e4cddf9cf..315f9aa9ea 100644 --- a/src/os/guFrustum.c +++ b/src/os/guFrustum.c @@ -1,7 +1,41 @@ #include "common.h" -INCLUDE_ASM(void, "os/guFrustum", guFrustumF, float mf[4][4], float l, float r, float b, float t, float n, - float f, float scale); +#ifndef KMC_ASM +void guFrustumF(Matrix4f mf, f32 l, f32 r, f32 b, f32 t, f32 n, f32 f, f32 scale) { + s32 i, j; + + guMtxIdentF(mf); + + mf[0][0] = 2*n/(r-l); + mf[1][1] = 2*n/(t-b); + mf[2][0] = (r+l)/(r-l); + mf[2][1] = (t+b)/(t-b); + mf[2][2] = -(f+n)/(f-n); + mf[2][3] = -1; + mf[3][2] = -2*f*n/(f-n); + mf[3][3] = 0; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + mf[i][j] *= scale; + } + } +} +#else +INCLUDE_ASM_LIBULTRA(void, "guFrustum", guFrustumF, Matrix4f mf, f32 l, f32 r, f32 b, f32 t, f32 n, + f32 f, f32 scale); +#endif + +#ifndef KMC_ASM +void guFrustum(Mtx* m, f32 l, f32 r, f32 b, f32 t, f32 n, f32 f, f32 scale) { + Matrix4f mf; + + guFrustumF(mf, l, r, b, t, n, f, scale); + + guMtxF2L(mf, m); +} +#else +INCLUDE_ASM_LIBULTRA(void, "guFrustum", guFrustum, Mtx* m, f32 l, f32 r, f32 b, f32 t, f32 n, f32 f, + f32 scale); +#endif -INCLUDE_ASM(void, "os/guFrustum", guFrustum, Mtx* m, float l, float r, float b, float t, float n, float f, - float scale); diff --git a/src/os/guLookAt.c b/src/os/guLookAt.c index 63e8423b3d..e052bbfd36 100644 --- a/src/os/guLookAt.c +++ b/src/os/guLookAt.c @@ -1,7 +1,75 @@ #include "common.h" -INCLUDE_ASM(void, "os/guLookAt", guLookAtF, float mf[4][4], float xEye, float yEye, float zEye, float xAt, - float yAt, float zAt, float xUp, float yUp, float zUp); +#ifndef KMC_ASM +void guLookAtF(Matrix4f mf, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, + f32 xUp, f32 yUp, f32 zUp) { + f32 len, xLook, yLook, zLook, xRight, yRight, zRight; -INCLUDE_ASM(void, "os/guLookAt", guLookAt, Mtx* m, float xEye, float yEye, float zEye, float xAt, float yAt, - float zAt, float xUp, float yUp, float zUp); + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + /* Up = Look x Right */ + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); + xUp *= len; + yUp *= len; + zUp *= len; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} +#else +INCLUDE_ASM_LIBULTRA(void, "guLookAt", guLookAtF, f32 mf[4][4], f32 xEye, f32 yEye, f32 zEye, f32 xAt, + f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp); +#endif + +#ifndef KMC_ASM +void guLookAt (Mtx *m, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, + f32 xUp, f32 yUp, f32 zUp) { + Matrix4f mf; + + guLookAtF(mf, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp); + + guMtxF2L(mf, m); +} +#else +INCLUDE_ASM_LIBULTRA(void, "guLookAt", guLookAt, Mtx* m, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, + f32 zAt, f32 xUp, f32 yUp, f32 zUp); +#endif diff --git a/src/os/lookathil.c b/src/os/lookathil.c new file mode 100644 index 0000000000..f030869dc3 --- /dev/null +++ b/src/os/lookathil.c @@ -0,0 +1,165 @@ +#include "common.h" + +#ifndef KMC_ASM +void guLookAtHiliteF(Matrix4f mf, 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, /* light 1 direction */ + f32 xl2, f32 yl2, f32 zl2, /* light 2 direction */ + int twidth, int theight) { /* highlight txtr size*/ + f32 len, xLook, yLook, zLook, xRight, yRight, zRight; + f32 xHilite, yHilite, zHilite; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf (xLook * xLook + yLook * yLook + zLook * zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf (xRight * xRight + yRight * yRight + zRight * zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + /* Up = Look x Right */ + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + len = 1.0 / sqrtf (xUp * xUp + yUp * yUp + zUp * zUp); + xUp *= len; + yUp *= len; + zUp *= len; + + /* hilite vectors */ + len = 1.0 / sqrtf (xl1 * xl1 + yl1 * yl1 + zl1 * zl1); + xl1 *= len; + yl1 *= len; + zl1 *= len; + +#define THRESH2 0.1 + xHilite = xl1 + xLook; + yHilite = yl1 + yLook; + zHilite = zl1 + zLook; + + len = sqrtf (xHilite * xHilite + yHilite * yHilite + zHilite * zHilite); + + if (len>THRESH2) { + len = 1.0 / len; + xHilite *= len; + yHilite *= len; + zHilite *= len; + + h->h.x1 = twidth * 4 + (xHilite * xRight + yHilite * yRight + zHilite * zRight) * twidth * 2; + + h->h.y1 = theight * 4 + (xHilite * xUp + yHilite * yUp + zHilite * zUp) * theight * 2; + } else { + h->h.x1 = twidth * 2; + h->h.y1 = theight * 2; + } + + len = 1.0 / sqrtf (xl2 * xl2 + yl2 * yl2 + zl2 * zl2); + xl2 *= len; + yl2 *= len; + zl2 *= len; + + xHilite = xl2 + xLook; + yHilite = yl2 + yLook; + zHilite = zl2 + zLook; + len = sqrtf (xHilite * xHilite + yHilite * yHilite + zHilite * zHilite); + if (len>THRESH2) { + len = 1.0 / len; + xHilite *= len; + yHilite *= len; + zHilite *= len; + + h->h.x2 = twidth * 4 + (xHilite * xRight + yHilite * yRight + zHilite * zRight) * twidth * 2; + + h->h.y2 = theight * 4 + (xHilite * xUp + yHilite * yUp + zHilite * zUp) * theight * 2; + } else { + h->h.x2 = twidth * 2; + h->h.y2 = theight * 2; + } + + /* reflectance vectors = Up and Right */ + l->l[0].l.dir[0] = FTOFRAC8(xRight); + l->l[0].l.dir[1] = FTOFRAC8(yRight); + l->l[0].l.dir[2] = FTOFRAC8(zRight); + l->l[1].l.dir[0] = FTOFRAC8(xUp); + l->l[1].l.dir[1] = FTOFRAC8(yUp); + l->l[1].l.dir[2] = FTOFRAC8(zUp); + l->l[0].l.col[0] = 0x00; + l->l[0].l.col[1] = 0x00; + l->l[0].l.col[2] = 0x00; + l->l[0].l.pad1 = 0x00; + l->l[0].l.colc[0] = 0x00; + l->l[0].l.colc[1] = 0x00; + l->l[0].l.colc[2] = 0x00; + l->l[0].l.pad2 = 0x00; + l->l[1].l.col[0] = 0x00; + l->l[1].l.col[1] = 0x80; + l->l[1].l.col[2] = 0x00; + l->l[1].l.pad1 = 0x00; + l->l[1].l.colc[0] = 0x00; + l->l[1].l.colc[1] = 0x80; + l->l[1].l.colc[2] = 0x00; + l->l[1].l.pad2 = 0x00; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} +#else +INCLUDE_ASM_LIBULTRA(void, "lookathil", guLookAtHiliteF, Matrix4f mf, 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 twidth, s32 theight); +#endif + +#ifndef KMC_ASM +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, /* light 1 direction */ + f32 xl2, f32 yl2, f32 zl2, /* light 2 direction */ + int twidth, int theight) { /* highlight txtr size*/ + Matrix4f mf; + + guLookAtHiliteF(mf, l, h, xEye, yEye, zEye, xAt, yAt, zAt, + xUp, yUp, zUp, xl1, yl1, zl1, xl2, yl2, zl2, + twidth, theight); + + guMtxF2L(mf, m); +} +#else +INCLUDE_ASM_LIBULTRA(void, "lookathil", 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 twidth, s32 theight); + #endif diff --git a/src/os/lookatref.c b/src/os/lookatref.c new file mode 100644 index 0000000000..4485a5a88e --- /dev/null +++ b/src/os/lookatref.c @@ -0,0 +1,102 @@ +#include "common.h" + +#ifndef KMC_ASM +void guLookAtReflectF(Matrix4f mf, LookAt *l, + f32 xEye, f32 yEye, f32 zEye, + f32 xAt, f32 yAt, f32 zAt, + f32 xUp, f32 yUp, f32 zUp) { + f32 len, xLook, yLook, zLook, xRight, yRight, zRight; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf(xLook*xLook + yLook*yLook + zLook*zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf(xRight * xRight + yRight * yRight + zRight * zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + /* Up = Look x Right */ + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + len = 1.0 / sqrtf(xUp * xUp + yUp * yUp + zUp * zUp); + xUp *= len; + yUp *= len; + zUp *= len; + + /* reflectance vectors = Up and Right */ + l->l[0].l.dir[0] = FTOFRAC8(xRight); + l->l[0].l.dir[1] = FTOFRAC8(yRight); + l->l[0].l.dir[2] = FTOFRAC8(zRight); + l->l[1].l.dir[0] = FTOFRAC8(xUp); + l->l[1].l.dir[1] = FTOFRAC8(yUp); + l->l[1].l.dir[2] = FTOFRAC8(zUp); + l->l[0].l.col[0] = 0x00; + l->l[0].l.col[1] = 0x00; + l->l[0].l.col[2] = 0x00; + l->l[0].l.pad1 = 0x00; + l->l[0].l.colc[0] = 0x00; + l->l[0].l.colc[1] = 0x00; + l->l[0].l.colc[2] = 0x00; + l->l[0].l.pad2 = 0x00; + l->l[1].l.col[0] = 0x00; + l->l[1].l.col[1] = 0x80; + l->l[1].l.col[2] = 0x00; + l->l[1].l.pad1 = 0x00; + l->l[1].l.colc[0] = 0x00; + l->l[1].l.colc[1] = 0x80; + l->l[1].l.colc[2] = 0x00; + l->l[1].l.pad2 = 0x00; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} +#else +INCLUDE_ASM_LIBULTRA(void, "lookatref", guLookAtReflectF, f32 mf[4][4], LookAt* l, f32 xEye, f32 yEye, + f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp); +#endif + +#ifndef KMC_ASM +void guLookAtReflect(Mtx *m, LookAt *l, f32 xEye, f32 yEye, f32 zEye, + f32 xAt, f32 yAt, f32 zAt, + f32 xUp, f32 yUp, f32 zUp) { + Matrix4f mf; + + guLookAtReflectF(mf, l, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp); + + guMtxF2L(mf, m); +} +#else +INCLUDE_ASM_LIBULTRA(void, "lookatref", guLookAtReflect, Mtx* m, LookAt* l, f32 xEye, f32 yEye, f32 zEye, + f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp); +#endif diff --git a/src/os/osCreateMesgQueue.c b/src/os/osCreateMesgQueue.c index 8ea2baa205..55495a4ea0 100644 --- a/src/os/osCreateMesgQueue.c +++ b/src/os/osCreateMesgQueue.c @@ -1,3 +1,11 @@ #include "common.h" +#include -INCLUDE_ASM(void, "os/osCreateMesgQueue", osCreateMesgQueue, OSMesgQueue* queue, OSMesg* mesg, s32 unk); +void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msg, s32 msgCount) { + mq->mtqueue = (OSThread *)&__osThreadTail; + mq->fullqueue = (OSThread *)&__osThreadTail; + mq->validCount = 0; + mq->first = 0; + mq->msgCount = msgCount; + mq->msg = msg; +} diff --git a/src/os/osJamMesg.c b/src/os/osJamMesg.c index 3b7894b6c5..6595409eef 100644 --- a/src/os/osJamMesg.c +++ b/src/os/osJamMesg.c @@ -1,3 +1,29 @@ #include "common.h" +#include -INCLUDE_ASM(s32, "os/osJamMesg", osJamMesg, OSMesgQueue* queue, OSMesg mesg, s32 unk); +#ifndef KMC_ASM +s32 osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag) { + register u32 saveMask = __osDisableInt(); + while (mq->validCount >= mq->msgCount) + { + if (flag == OS_MESG_BLOCK) { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->fullqueue); + } else { + __osRestoreInt(saveMask); + return -1; + } + } + + mq->first = (mq->first + mq->msgCount - 1) % mq->msgCount; + mq->msg[mq->first] = msg; + mq->validCount++; + if (mq->mtqueue->next != NULL) { + osStartThread(__osPopThread(&mq->mtqueue)); + } + __osRestoreInt(saveMask); + return 0; +} +#else +INCLUDE_ASM_LIBULTRA(s32, "osJamMesg", osJamMesg, OSMesgQueue *mq, OSMesg msg, s32 flag); +#endif diff --git a/src/os/osRecvMesg.c b/src/os/osRecvMesg.c index 4114309b68..d10174b6d2 100644 --- a/src/os/osRecvMesg.c +++ b/src/os/osRecvMesg.c @@ -1,3 +1,32 @@ #include "common.h" +#include + +#ifndef KMC_ASM +s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flags) { + register u32 saveMask; + saveMask = __osDisableInt(); + + while (MQ_IS_EMPTY(mq)) { + if (flags == OS_MESG_NOBLOCK) { + __osRestoreInt(saveMask); + return -1; + } + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->mtqueue); + } + + if (msg != NULL) { + *msg = mq->msg[mq->first]; + } + mq->first = (mq->first + 1) % mq->msgCount; + mq->validCount--; + if (mq->fullqueue->next != NULL) { + osStartThread(__osPopThread(&mq->fullqueue)); + } + __osRestoreInt(saveMask); + return 0; +} +#else +INCLUDE_ASM_LIBULTRA(s32, "osRecvMesg", osRecvMesg, OSMesgQueue* queue, OSMesg* mesg, s32 unk); +#endif -INCLUDE_ASM(s32, "os/osRecvMesg", osRecvMesg, OSMesgQueue* queue, OSMesg* mesg, s32 unk); diff --git a/src/os/osSetThreadPri.c b/src/os/osSetThreadPri.c index 73f51f2565..b83a8e6814 100644 --- a/src/os/osSetThreadPri.c +++ b/src/os/osSetThreadPri.c @@ -1,11 +1,7 @@ #define MOVE_ADDU #include "common.h" - -struct __osThreadTail { - OSThread* next; - OSPri priority; -}; +#include struct __osThreadTail __osThreadTail = {0, -1}; OSThread* __osRunQueue = (OSThread*) &__osThreadTail; @@ -28,7 +24,7 @@ void osSetThreadPri(OSThread* thread, OSPri pri) { } if (__osRunningThread->priority < __osRunQueue->priority) { __osRunningThread->state = 2; - osEnqueueAndYield(&__osRunQueue); + __osEnqueueAndYield(&__osRunQueue); } } diff --git a/src/os/osVirtualToPhysical.c b/src/os/osVirtualToPhysical.c index ab2deaa706..23472fb12a 100644 --- a/src/os/osVirtualToPhysical.c +++ b/src/os/osVirtualToPhysical.c @@ -1,3 +1,15 @@ #include "common.h" -INCLUDE_ASM(u32, "os/osVirtualToPhysical", osVirtualToPhysical, void* virt); +#ifndef KMC_ASM +u32 osVirtualToPhysical(void *addr) { + if (IS_KSEG0(addr)) { + return K0_TO_PHYS(addr); + } else if (IS_KSEG1(addr)) { + return K1_TO_PHYS(addr); + } else { + return __osProbeTLB(addr); + } +} +#else +INCLUDE_ASM_LIBULTRA(u32, "osVirtualToPhysical", osVirtualToPhysical, void* virt); +#endif diff --git a/src/os/perspective.c b/src/os/perspective.c new file mode 100644 index 0000000000..c370184574 --- /dev/null +++ b/src/os/perspective.c @@ -0,0 +1,53 @@ +#include "common.h" + +#ifndef KMC_ASM +void guPerspectiveF(Matrix4f mf, u16 *perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale) { + f32 cot; + s32 i, j; + + guMtxIdentF(mf); + + fovy *= 3.1415926 / 180.0; + cot = cos_rad(fovy/2) / sin_rad(fovy/2); + + mf[0][0] = cot / aspect; + mf[1][1] = cot; + mf[2][2] = (near + far) / (near - far); + mf[2][3] = -1; + mf[3][2] = (2 * near * far) / (near - far); + mf[3][3] = 0; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + mf[i][j] *= scale; + } + } + + if (perspNorm != (u16 *) NULL) { + if (near + far <= 2.0) { + *perspNorm = (u16) 0xFFFF; + } else { + *perspNorm = (u16) ((2.0 * 65536.0) / (near + far)); + if (*perspNorm <= 0) { + *perspNorm = (u16) 0x0001; + } + } + } +} +#else +INCLUDE_ASM_LIBULTRA(void, "perspective", guPerspectiveF, Matrix4f mf, u16* perspNorm, f32 fovy, f32 aspect, + f32 near, f32 far, f32 scale); +#endif + +#ifndef KMC_ASM +void guPerspective(Mtx *m, u16 *perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale) { + Matrix4f mf; + + guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); + + guMtxF2L(mf, m); +} +#else +INCLUDE_ASM_LIBULTRA(void, "perspective", guPerspective, Mtx* m, u16* perspNorm, f32 fovy, f32 aspect, + f32 near, f32 far, f32 scale); +#endif diff --git a/src/os/position.c b/src/os/position.c new file mode 100644 index 0000000000..7d48f5ce0a --- /dev/null +++ b/src/os/position.c @@ -0,0 +1,56 @@ +#include "common.h" + +#ifndef KMC_ASM +void guPositionF(Matrix4f mf, f32 r, f32 p, f32 h, f32 s, f32 x, f32 y, f32 z) { + static f32 dtor = 3.1415926 / 180.0; + f32 sinr, sinp, sinh; + f32 cosr, cosp, cosh; + + r *= dtor; + p *= dtor; + h *= dtor; + sinr = sin_rad(r); + cosr = cos_rad(r); + sinp = sin_rad(p); + cosp = cos_rad(p); + sinh = sin_rad(h); + cosh = cos_rad(h); + + mf[0][0] = (cosp * cosh) * s; + mf[0][1] = (cosp * sinh) * s; + mf[0][2] = (-sinp) * s; + mf[0][3] = 0.0; + + mf[1][0] = (sinr * sinp * cosh - cosr * sinh) * s; + mf[1][1] = (sinr * sinp * sinh + cosr * cosh) * s; + mf[1][2] = (sinr * cosp) * s; + mf[1][3] = 0.0; + + mf[2][0] = (cosr * sinp * cosh + sinr * sinh) * s; + mf[2][1] = (cosr * sinp * sinh - sinr * cosh) * s; + mf[2][2] = (cosr * cosp) * s; + mf[2][3] = 0.0; + + mf[3][0] = x; + mf[3][1] = y; + mf[3][2] = z; + mf[3][3] = 1.0; +} +#else +INCLUDE_ASM_LIBULTRA(void, "3f310_len_3c0", guPositionF, f32 mf[4][4], f32 r, f32 p, f32 h, f32 s, f32 x, + f32 y, f32 z); +#endif + +#ifndef KMC_ASM +void guPosition(Mtx* m, f32 r, f32 p, f32 h, f32 s, + f32 x, f32 y, f32 z) { + f32 mf[4][4]; + + guPositionF(mf, r, p, h, s, x, y, z); + + guMtxF2L(mf, m); +} +#else +INCLUDE_ASM_LIBULTRA(void, "3f310_len_3c0", guPosition, Mtx* m, f32 r, f32 p, f32 h, f32 s, f32 x, f32 y, + f32 z); +#endif diff --git a/src/os/rotateRPY.c b/src/os/rotateRPY.c new file mode 100644 index 0000000000..d139906206 --- /dev/null +++ b/src/os/rotateRPY.c @@ -0,0 +1,47 @@ +#include "common.h" + +#ifndef KMC_ASM +void guRotateRPYF(Matrix4f mf, f32 r, f32 p, f32 h) { + static f32 dtor = 3.1415926 / 180.0; + f32 sinr, sinp, sinh; + f32 cosr, cosp, cosh; + + r *= dtor; + p *= dtor; + h *= dtor; + sinr = sin_rad(r); + cosr = cos_rad(r); + sinp = sin_rad(p); + cosp = cos_rad(p); + sinh = sin_rad(h); + cosh = cos_rad(h); + + guMtxIdentF(mf); + + mf[0][0] = cosp * cosh; + mf[0][1] = cosp * sinh; + mf[0][2] = -sinp; + + mf[1][0] = sinr * sinp * cosh - cosr * sinh; + mf[1][1] = sinr * sinp * sinh + cosr * cosh; + mf[1][2] = sinr * cosp; + + mf[2][0] = cosr * sinp * cosh + sinr * sinh; + mf[2][1] = cosr * sinp * sinh - sinr * cosh; + mf[2][2] = cosr * cosp; +} +#else +INCLUDE_ASM_LIBULTRA(void, "3f6d0_len_320", guRotateRPYF, f32 mf[4][4], f32 x, f32 y, f32 z); +#endif + +#ifndef KMC_ASM +void guRotateRPY(Mtx *m, f32 r, f32 p, f32 h) { + Matrix4f mf; + + guRotateRPYF(mf, r, p, h); + + guMtxF2L(mf, m); +} +#else +INCLUDE_ASM_LIBULTRA(void, "3f6d0_len_320", guRotateRPY, Mtx *m, f32 r, f32 p, f32 y); +#endif diff --git a/src/os/sendmesg.c b/src/os/sendmesg.c new file mode 100644 index 0000000000..7dcb35322c --- /dev/null +++ b/src/os/sendmesg.c @@ -0,0 +1,37 @@ +#include "common.h" +#include + +u32 __osPreNMI = 0; + +#ifndef KMC_ASM +s32 osSendMesg(OSMesgQueue *mq, OSMesg msg, s32 flags) +{ + register u32 saveMask; + register s32 last; + saveMask = __osDisableInt(); + while (MQ_IS_FULL(mq)) + { + if (flags == OS_MESG_BLOCK) + { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->fullqueue); + } + else + { + __osRestoreInt(saveMask); + return -1; + } + } + last = (mq->first + mq->validCount) % mq->msgCount; + mq->msg[last] = msg; + mq->validCount++; + if (mq->mtqueue->next != NULL) + { + osStartThread(__osPopThread(&mq->mtqueue)); + } + __osRestoreInt(saveMask); + return 0; +} +#else +INCLUDE_ASM_LIBULTRA(s32, "40c20_len_1f0", osSendMesg, OSMesgQueue* queue, OSMesg mesg, s32 unk); +#endif diff --git a/src/os/seteventmesg.c b/src/os/seteventmesg.c new file mode 100644 index 0000000000..a27cbef52f --- /dev/null +++ b/src/os/seteventmesg.c @@ -0,0 +1,4 @@ +#include "common.h" +#include + +INCLUDE_ASM(void, "os/seteventmesg", osSetEventMesg, OSEvent event, OSMesgQueue* queue, OSMesg mesg); diff --git a/src/os/sins.c b/src/os/sins.c index 5e2db89cd4..c1dd467285 100644 --- a/src/os/sins.c +++ b/src/os/sins.c @@ -2,4 +2,26 @@ #include "sintable.inc.c" -INCLUDE_ASM(s16, "os/sins", sins, u16 angle); +#ifndef KMC_ASM +s16 sins(u16 x) { + /* 0 <= x < 0x10000 ==> 0 <= x < 2PI */ + + s16 val; + + x >>= 4; /* Now range 0 <= x < 0x1000 */ + + if (x & 0x400) { + val = sintable[0x3ff - (x & 0x3ff)]; + } else { + val = sintable[x & 0x3ff]; + } + + if (x & 0x800) { + return -val; + } else { + return val; + } +} +#else +INCLUDE_ASM_LIBULTRA(s16, "os/sins", sins, u16 angle); +#endif diff --git a/src/os/sprintf.c b/src/os/sprintf.c new file mode 100644 index 0000000000..67600751cd --- /dev/null +++ b/src/os/sprintf.c @@ -0,0 +1,25 @@ +#define MOVE_ADDU + +#include "common.h" +#include "stdlib/stdarg.h" + +static char *proutSprintf(char *dst, const char *src, size_t count); + +int sprintf(char* s, const char* fmt, ...) { + s32 ret; + va_list argp; + va_start(argp, fmt); + + ret = _Printf(&proutSprintf, s, fmt, argp); + + if (ret < 0) { + return ret; + } + + s[ret] = 0; + return ret; +} + +static char *proutSprintf(char *dst, const char *src, size_t count) { + return (char *)memcpy((u8 *)dst, (u8 *)src, count) + count; +} diff --git a/src/os/sqrtf.c b/src/os/sqrtf.c new file mode 100644 index 0000000000..04ed5bc029 --- /dev/null +++ b/src/os/sqrtf.c @@ -0,0 +1,5 @@ +#include "common.h" + +f32 sqrtf(f32 f) { + return __builtin_sqrtf(f); +} diff --git a/src/os/string.c b/src/os/string.c new file mode 100644 index 0000000000..82faab393f --- /dev/null +++ b/src/os/string.c @@ -0,0 +1,41 @@ +#include "common.h" + +#ifndef KMC_ASM +char* strchr(const char* s, int c) { + const char ch = c; + while (*s != ch) { + if (*s == 0) + return NULL; + s++; + } + return (char *)s; +} +#else +INCLUDE_ASM_LIBULTRA(s32, "3fa50_len_f60", strchr); +#endif + +#ifndef KMC_ASM +size_t strlen(const char* s) { + const char* sc = s; + while (*sc) { + sc++; + } + return sc - s; +} +#else +INCLUDE_ASM_LIBULTRA(s32, "3fa50_len_f60", strlen); +#endif + +#ifndef KMC_ASM +void* memcpy(void* s1, const void* s2, size_t n) { + char* su1 = (char*)s1; + const char *su2 = (const char*)s2; + while (n > 0) { + *su1++ = *su2++; + n--; + } + return (void*)s1; +} +#else +INCLUDE_ASM_LIBULTRA(s32, "3fa50_len_f60", memcpy); +#endif diff --git a/ver/us/asm/nonmatchings/os/3FEA0/proutSprintf.s b/ver/us/asm/nonmatchings/os/3FEA0/proutSprintf.s deleted file mode 100644 index dfd4d9aca1..0000000000 --- a/ver/us/asm/nonmatchings/os/3FEA0/proutSprintf.s +++ /dev/null @@ -1,18 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel proutSprintf -/* 40948 80065548 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 4094C 8006554C AFB10014 */ sw $s1, 0x14($sp) -/* 40950 80065550 00808821 */ addu $s1, $a0, $zero -/* 40954 80065554 AFB00010 */ sw $s0, 0x10($sp) -/* 40958 80065558 AFBF0018 */ sw $ra, 0x18($sp) -/* 4095C 8006555C 0C01929D */ jal memcpy -/* 40960 80065560 00C08021 */ addu $s0, $a2, $zero -/* 40964 80065564 02301021 */ addu $v0, $s1, $s0 -/* 40968 80065568 8FBF0018 */ lw $ra, 0x18($sp) -/* 4096C 8006556C 8FB10014 */ lw $s1, 0x14($sp) -/* 40970 80065570 8FB00010 */ lw $s0, 0x10($sp) -/* 40974 80065574 03E00008 */ jr $ra -/* 40978 80065578 27BD0020 */ addiu $sp, $sp, 0x20 -/* 4097C 8006557C 00000000 */ nop diff --git a/ver/us/asm/nonmatchings/os/3d2f0_len_10/sqrtf.s b/ver/us/asm/nonmatchings/os/3d2f0_len_10/sqrtf.s deleted file mode 100644 index 05d8d4cb77..0000000000 --- a/ver/us/asm/nonmatchings/os/3d2f0_len_10/sqrtf.s +++ /dev/null @@ -1,8 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel sqrtf -/* 3D2F0 80061EF0 03E00008 */ jr $ra -/* 3D2F4 80061EF4 46006004 */ sqrt.s $f0, $f12 -/* 3D2F8 80061EF8 00000000 */ nop -/* 3D2FC 80061EFC 00000000 */ nop diff --git a/ver/us/asm/nonmatchings/os/41420_len_120/osStartThread.s b/ver/us/asm/nonmatchings/os/41420_len_120/osStartThread.s index 0db501b7c4..bb2336e678 100644 --- a/ver/us/asm/nonmatchings/os/41420_len_120/osStartThread.s +++ b/ver/us/asm/nonmatchings/os/41420_len_120/osStartThread.s @@ -42,7 +42,7 @@ glabel osStartThread /* 414A8 800660A8 0C01AC5D */ jal osEnqueueThread /* 414AC 800660AC A6020010 */ sh $v0, 0x10($s0) /* 414B0 800660B0 8E040008 */ lw $a0, 8($s0) -/* 414B4 800660B4 0C01AC6F */ jal osPopThread +/* 414B4 800660B4 0C01AC6F */ jal __osPopThread /* 414B8 800660B8 00000000 */ nop /* 414BC 800660BC 02202021 */ addu $a0, $s1, $zero /* 414C0 800660C0 00402821 */ addu $a1, $v0, $zero @@ -68,7 +68,7 @@ glabel osStartThread /* 41504 80066104 24020002 */ addiu $v0, $zero, 2 /* 41508 80066108 A4820010 */ sh $v0, 0x10($a0) /* 4150C 8006610C 3C048009 */ lui $a0, %hi(__osRunQueue) -/* 41510 80066110 0C01AC1B */ jal osEnqueueAndYield +/* 41510 80066110 0C01AC1B */ jal __osEnqueueAndYield /* 41514 80066114 24844658 */ addiu $a0, $a0, %lo(__osRunQueue) .L80066118: /* 41518 80066118 0C01ACF4 */ jal __osRestoreInt diff --git a/ver/us/asm/nonmatchings/os/41540_len_c0/osStopThread.s b/ver/us/asm/nonmatchings/os/41540_len_c0/osStopThread.s index 082610c1b0..456ef5107e 100644 --- a/ver/us/asm/nonmatchings/os/41540_len_c0/osStopThread.s +++ b/ver/us/asm/nonmatchings/os/41540_len_c0/osStopThread.s @@ -34,7 +34,7 @@ glabel osStopThread /* 415A8 800661A8 8C634660 */ lw $v1, %lo(__osRunningThread)($v1) /* 415AC 800661AC 00002021 */ addu $a0, $zero, $zero /* 415B0 800661B0 24020001 */ addiu $v0, $zero, 1 -/* 415B4 800661B4 0C01AC1B */ jal osEnqueueAndYield +/* 415B4 800661B4 0C01AC1B */ jal __osEnqueueAndYield /* 415B8 800661B8 A4620010 */ sh $v0, 0x10($v1) /* 415BC 800661BC 08019876 */ j .L800661D8 /* 415C0 800661C0 00000000 */ nop diff --git a/ver/us/asm/nonmatchings/os/41640_len_50/osYieldThread.s b/ver/us/asm/nonmatchings/os/41640_len_50/osYieldThread.s index 8cc115014c..88b11f672c 100644 --- a/ver/us/asm/nonmatchings/os/41640_len_50/osYieldThread.s +++ b/ver/us/asm/nonmatchings/os/41640_len_50/osYieldThread.s @@ -12,7 +12,7 @@ glabel osYieldThread /* 4165C 8006625C 24844658 */ addiu $a0, $a0, %lo(__osRunQueue) /* 41660 80066260 24050002 */ addiu $a1, $zero, 2 /* 41664 80066264 00408021 */ addu $s0, $v0, $zero -/* 41668 80066268 0C01AC1B */ jal osEnqueueAndYield +/* 41668 80066268 0C01AC1B */ jal __osEnqueueAndYield /* 4166C 8006626C A4650010 */ sh $a1, 0x10($v1) /* 41670 80066270 0C01ACF4 */ jal __osRestoreInt /* 41674 80066274 02002021 */ addu $a0, $s0, $zero diff --git a/ver/us/asm/nonmatchings/os/41c60_len_c0/osProbeTLB.s b/ver/us/asm/nonmatchings/os/41c60_len_c0/__osProbeTLB.s similarity index 99% rename from ver/us/asm/nonmatchings/os/41c60_len_c0/osProbeTLB.s rename to ver/us/asm/nonmatchings/os/41c60_len_c0/__osProbeTLB.s index 00ab7a3526..9512dd4d26 100644 --- a/ver/us/asm/nonmatchings/os/41c60_len_c0/osProbeTLB.s +++ b/ver/us/asm/nonmatchings/os/41c60_len_c0/__osProbeTLB.s @@ -1,7 +1,7 @@ .set noat # allow manual use of $at .set noreorder # don't insert nops after branches -glabel osProbeTLB +glabel __osProbeTLB /* 41C60 80066860 40085000 */ mfc0 $t0, $10 /* 41C64 80066864 310900FF */ andi $t1, $t0, 0xff /* 41C68 80066868 2401E000 */ addiu $at, $zero, -0x2000 diff --git a/ver/us/asm/nonmatchings/os/osCreateMesgQueue/osCreateMesgQueue.s b/ver/us/asm/nonmatchings/os/osCreateMesgQueue/osCreateMesgQueue.s deleted file mode 100644 index 8308808c30..0000000000 --- a/ver/us/asm/nonmatchings/os/osCreateMesgQueue/osCreateMesgQueue.s +++ /dev/null @@ -1,16 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel osCreateMesgQueue -/* 40980 80065580 3C028009 */ lui $v0, %hi(__osThreadTail) -/* 40984 80065584 24424650 */ addiu $v0, $v0, %lo(__osThreadTail) -/* 40988 80065588 AC820000 */ sw $v0, ($a0) -/* 4098C 8006558C AC820004 */ sw $v0, 4($a0) -/* 40990 80065590 AC800008 */ sw $zero, 8($a0) -/* 40994 80065594 AC80000C */ sw $zero, 0xc($a0) -/* 40998 80065598 AC860010 */ sw $a2, 0x10($a0) -/* 4099C 8006559C 03E00008 */ jr $ra -/* 409A0 800655A0 AC850014 */ sw $a1, 0x14($a0) -/* 409A4 800655A4 00000000 */ nop -/* 409A8 800655A8 00000000 */ nop -/* 409AC 800655AC 00000000 */ nop diff --git a/ver/us/asm/nonmatchings/os/40c20_len_1f0/osSetEventMesg.s b/ver/us/asm/nonmatchings/os/seteventmesg/osSetEventMesg.s similarity index 100% rename from ver/us/asm/nonmatchings/os/40c20_len_1f0/osSetEventMesg.s rename to ver/us/asm/nonmatchings/os/seteventmesg/osSetEventMesg.s diff --git a/ver/us/asm/nonmatchings/os/3fa50_len_f60/bcopy.s b/ver/us/asm/os/bcopy.s similarity index 98% rename from ver/us/asm/nonmatchings/os/3fa50_len_f60/bcopy.s rename to ver/us/asm/os/bcopy.s index 2dfbd264ac..8733c5fecb 100644 --- a/ver/us/asm/nonmatchings/os/3fa50_len_f60/bcopy.s +++ b/ver/us/asm/os/bcopy.s @@ -1,5 +1,11 @@ +.include "macro.inc" + +# assembler directives .set noat # allow manual use of $at .set noreorder # don't insert nops after branches +.set gp=64 # allow use of 64-bit general purpose registers + +.section .text, "ax" glabel bcopy /* 3FA50 80064650 10C0001B */ beqz $a2, .L800646C0 diff --git a/ver/us/asm/nonmatchings/os/3fa50_len_f60/bzero.s b/ver/us/asm/os/bzero.s similarity index 94% rename from ver/us/asm/nonmatchings/os/3fa50_len_f60/bzero.s rename to ver/us/asm/os/bzero.s index affda4fd6b..d7fbcce0f9 100644 --- a/ver/us/asm/nonmatchings/os/3fa50_len_f60/bzero.s +++ b/ver/us/asm/os/bzero.s @@ -1,5 +1,11 @@ +.include "macro.inc" + +# assembler directives .set noat # allow manual use of $at .set noreorder # don't insert nops after branches +.set gp=64 # allow use of 64-bit general purpose registers + +.section .text, "ax" glabel bzero /* 3FD70 80064970 00041823 */ negu $v1, $a0 diff --git a/ver/us/asm/nonmatchings/os/3d300_len_30/coss.s b/ver/us/asm/os/coss/coss.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3d300_len_30/coss.s rename to ver/us/asm/os/coss/coss.s diff --git a/ver/us/asm/os/exceptasm.s b/ver/us/asm/os/exceptasm.s index 20cfe9d1ec..545d0b4c7e 100644 --- a/ver/us/asm/os/exceptasm.s +++ b/ver/us/asm/os/exceptasm.s @@ -446,7 +446,7 @@ glabel send_mesg /* 46408 8006B008 8D4B0000 */ lw $t3, ($t2) /* 4640C 8006B00C 11600008 */ beqz $t3, .L8006B030 /* 46410 8006B010 00000000 */ nop -/* 46414 8006B014 0C01AC6F */ jal osPopThread +/* 46414 8006B014 0C01AC6F */ jal __osPopThread /* 46418 8006B018 01202021 */ addu $a0, $t1, $zero /* 4641C 8006B01C 00405021 */ addu $t2, $v0, $zero /* 46420 8006B020 01402821 */ addu $a1, $t2, $zero @@ -472,7 +472,7 @@ glabel handle_CPU /* 46464 8006B064 1000FFB3 */ b .L8006AF34 /* 46468 8006B068 AF5B0118 */ sw $k1, 0x118($k0) -glabel osEnqueueAndYield +glabel __osEnqueueAndYield /* 4646C 8006B06C 3C058009 */ lui $a1, %hi(__osRunningThread) /* 46470 8006B070 8CA54660 */ lw $a1, %lo(__osRunningThread)($a1) /* 46474 8006B074 40086000 */ mfc0 $t0, $12 @@ -566,7 +566,7 @@ glabel osEnqueueThread /* 465B4 8006B1B4 03E00008 */ jr $ra /* 465B8 8006B1B8 ACA40008 */ sw $a0, 8($a1) -glabel osPopThread +glabel __osPopThread /* 465BC 8006B1BC 8C820000 */ lw $v0, ($a0) /* 465C0 8006B1C0 8C590000 */ lw $t9, ($v0) /* 465C4 8006B1C4 03E00008 */ jr $ra @@ -576,7 +576,7 @@ glabel osPopThread glabel osDispatchThread /* 465D4 8006B1D4 3C048009 */ lui $a0, %hi(__osRunQueue) -/* 465D8 8006B1D8 0C01AC6F */ jal osPopThread +/* 465D8 8006B1D8 0C01AC6F */ jal __osPopThread /* 465DC 8006B1DC 24844658 */ addiu $a0, $a0, %lo(__osRunQueue) /* 465E0 8006B1E0 3C018009 */ lui $at, %hi(__osRunningThread) /* 465E4 8006B1E4 AC224660 */ sw $v0, %lo(__osRunningThread)($at) diff --git a/ver/us/asm/nonmatchings/os/guFrustum/guFrustum.s b/ver/us/asm/os/guFrustum/guFrustum.s similarity index 100% rename from ver/us/asm/nonmatchings/os/guFrustum/guFrustum.s rename to ver/us/asm/os/guFrustum/guFrustum.s diff --git a/ver/us/asm/nonmatchings/os/guFrustum/guFrustumF.s b/ver/us/asm/os/guFrustum/guFrustumF.s similarity index 100% rename from ver/us/asm/nonmatchings/os/guFrustum/guFrustumF.s rename to ver/us/asm/os/guFrustum/guFrustumF.s diff --git a/ver/us/asm/nonmatchings/os/guLookAt/guLookAt.s b/ver/us/asm/os/guLookAt/guLookAt.s similarity index 100% rename from ver/us/asm/nonmatchings/os/guLookAt/guLookAt.s rename to ver/us/asm/os/guLookAt/guLookAt.s diff --git a/ver/us/asm/nonmatchings/os/guLookAt/guLookAtF.s b/ver/us/asm/os/guLookAt/guLookAtF.s similarity index 100% rename from ver/us/asm/nonmatchings/os/guLookAt/guLookAtF.s rename to ver/us/asm/os/guLookAt/guLookAtF.s diff --git a/ver/us/asm/nonmatchings/os/3dcc0_len_a60/guLookAtHilite.s b/ver/us/asm/os/lookathil/guLookAtHilite.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3dcc0_len_a60/guLookAtHilite.s rename to ver/us/asm/os/lookathil/guLookAtHilite.s diff --git a/ver/us/asm/nonmatchings/os/3dcc0_len_a60/guLookAtHiliteF.s b/ver/us/asm/os/lookathil/guLookAtHiliteF.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3dcc0_len_a60/guLookAtHiliteF.s rename to ver/us/asm/os/lookathil/guLookAtHiliteF.s diff --git a/ver/us/asm/nonmatchings/os/3e720_len_5f0/guLookAtReflect.s b/ver/us/asm/os/lookatref/guLookAtReflect.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3e720_len_5f0/guLookAtReflect.s rename to ver/us/asm/os/lookatref/guLookAtReflect.s diff --git a/ver/us/asm/nonmatchings/os/3e720_len_5f0/guLookAtReflectF.s b/ver/us/asm/os/lookatref/guLookAtReflectF.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3e720_len_5f0/guLookAtReflectF.s rename to ver/us/asm/os/lookatref/guLookAtReflectF.s diff --git a/ver/us/asm/nonmatchings/os/osJamMesg/osJamMesg.s b/ver/us/asm/os/osJamMesg/osJamMesg.s similarity index 97% rename from ver/us/asm/nonmatchings/os/osJamMesg/osJamMesg.s rename to ver/us/asm/os/osJamMesg/osJamMesg.s index 6b7de77f08..c48cb1db07 100644 --- a/ver/us/asm/nonmatchings/os/osJamMesg/osJamMesg.s +++ b/ver/us/asm/os/osJamMesg/osJamMesg.s @@ -31,7 +31,7 @@ glabel osJamMesg .L80065614: /* 40A14 80065614 3C028009 */ lui $v0, %hi(__osRunningThread) /* 40A18 80065618 8C424660 */ lw $v0, %lo(__osRunningThread)($v0) -/* 40A1C 8006561C 0C01AC1B */ jal osEnqueueAndYield +/* 40A1C 8006561C 0C01AC1B */ jal __osEnqueueAndYield /* 40A20 80065620 A4530010 */ sh $s3, 0x10($v0) /* 40A24 80065624 8E020008 */ lw $v0, 8($s0) /* 40A28 80065628 8E030010 */ lw $v1, 0x10($s0) @@ -68,7 +68,7 @@ glabel osJamMesg /* 40A98 80065698 8C620000 */ lw $v0, ($v1) /* 40A9C 8006569C 10400005 */ beqz $v0, .L800656B4 /* 40AA0 800656A0 00000000 */ nop -/* 40AA4 800656A4 0C01AC6F */ jal osPopThread +/* 40AA4 800656A4 0C01AC6F */ jal __osPopThread /* 40AA8 800656A8 02002021 */ addu $a0, $s0, $zero /* 40AAC 800656AC 0C019808 */ jal osStartThread /* 40AB0 800656B0 00402021 */ addu $a0, $v0, $zero diff --git a/ver/us/asm/nonmatchings/os/osRecvMesg/osRecvMesg.s b/ver/us/asm/os/osRecvMesg/osRecvMesg.s similarity index 97% rename from ver/us/asm/nonmatchings/os/osRecvMesg/osRecvMesg.s rename to ver/us/asm/os/osRecvMesg/osRecvMesg.s index 41e1d4379c..52a488d787 100644 --- a/ver/us/asm/nonmatchings/os/osRecvMesg/osRecvMesg.s +++ b/ver/us/asm/os/osRecvMesg/osRecvMesg.s @@ -27,7 +27,7 @@ glabel osRecvMesg .L80065744: /* 40B44 80065744 3C028009 */ lui $v0, %hi(__osRunningThread) /* 40B48 80065748 8C424660 */ lw $v0, %lo(__osRunningThread)($v0) -/* 40B4C 8006574C 0C01AC1B */ jal osEnqueueAndYield +/* 40B4C 8006574C 0C01AC1B */ jal __osEnqueueAndYield /* 40B50 80065750 A4530010 */ sh $s3, 0x10($v0) /* 40B54 80065754 8E020008 */ lw $v0, 8($s0) /* 40B58 80065758 1040FFF4 */ beqz $v0, .L8006572C @@ -66,7 +66,7 @@ glabel osRecvMesg /* 40BCC 800657CC 8C620000 */ lw $v0, ($v1) /* 40BD0 800657D0 10400005 */ beqz $v0, .L800657E8 /* 40BD4 800657D4 00000000 */ nop -/* 40BD8 800657D8 0C01AC6F */ jal osPopThread +/* 40BD8 800657D8 0C01AC6F */ jal __osPopThread /* 40BDC 800657DC 26040004 */ addiu $a0, $s0, 4 /* 40BE0 800657E0 0C019808 */ jal osStartThread /* 40BE4 800657E4 00402021 */ addu $a0, $v0, $zero diff --git a/ver/us/asm/nonmatchings/os/osVirtualToPhysical/osVirtualToPhysical.s b/ver/us/asm/os/osVirtualToPhysical/osVirtualToPhysical.s similarity index 96% rename from ver/us/asm/nonmatchings/os/osVirtualToPhysical/osVirtualToPhysical.s rename to ver/us/asm/os/osVirtualToPhysical/osVirtualToPhysical.s index a5f44a265a..ca74be1b01 100644 --- a/ver/us/asm/nonmatchings/os/osVirtualToPhysical/osVirtualToPhysical.s +++ b/ver/us/asm/os/osVirtualToPhysical/osVirtualToPhysical.s @@ -15,7 +15,7 @@ glabel osVirtualToPhysical /* 3D2B8 80061EB8 0062102B */ sltu $v0, $v1, $v0 /* 3D2BC 80061EBC 10400006 */ beqz $v0, .L80061ED8 /* 3D2C0 80061EC0 00831024 */ and $v0, $a0, $v1 -/* 3D2C4 80061EC4 0C019A18 */ jal osProbeTLB +/* 3D2C4 80061EC4 0C019A18 */ jal __osProbeTLB /* 3D2C8 80061EC8 00000000 */ nop /* 3D2CC 80061ECC 080187B6 */ j .L80061ED8 /* 3D2D0 80061ED0 00000000 */ nop diff --git a/ver/us/asm/nonmatchings/os/3ef90_len_600/guPerspective.s b/ver/us/asm/os/perspective/guPerspective.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3ef90_len_600/guPerspective.s rename to ver/us/asm/os/perspective/guPerspective.s diff --git a/ver/us/asm/nonmatchings/os/3ef90_len_600/guPerspectiveF.s b/ver/us/asm/os/perspective/guPerspectiveF.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3ef90_len_600/guPerspectiveF.s rename to ver/us/asm/os/perspective/guPerspectiveF.s diff --git a/ver/us/asm/nonmatchings/os/3f310_len_3c0/guPosition.s b/ver/us/asm/os/position/guPosition.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3f310_len_3c0/guPosition.s rename to ver/us/asm/os/position/guPosition.s diff --git a/ver/us/asm/nonmatchings/os/3f310_len_3c0/guPositionF.s b/ver/us/asm/os/position/guPositionF.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3f310_len_3c0/guPositionF.s rename to ver/us/asm/os/position/guPositionF.s diff --git a/ver/us/asm/nonmatchings/os/3f6d0_len_320/guRotateRPY.s b/ver/us/asm/os/rotateRPY/guRotateRPY.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3f6d0_len_320/guRotateRPY.s rename to ver/us/asm/os/rotateRPY/guRotateRPY.s diff --git a/ver/us/asm/nonmatchings/os/3f6d0_len_320/guRotateRPYF.s b/ver/us/asm/os/rotateRPY/guRotateRPYF.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3f6d0_len_320/guRotateRPYF.s rename to ver/us/asm/os/rotateRPY/guRotateRPYF.s diff --git a/ver/us/asm/nonmatchings/os/40c20_len_1f0/osSendMesg.s b/ver/us/asm/os/sendmesg/osSendMesg.s similarity index 97% rename from ver/us/asm/nonmatchings/os/40c20_len_1f0/osSendMesg.s rename to ver/us/asm/os/sendmesg/osSendMesg.s index 7f6719215c..88283b2c3f 100644 --- a/ver/us/asm/nonmatchings/os/40c20_len_1f0/osSendMesg.s +++ b/ver/us/asm/os/sendmesg/osSendMesg.s @@ -31,7 +31,7 @@ glabel osSendMesg .L80065884: /* 40C84 80065884 3C028009 */ lui $v0, %hi(__osRunningThread) /* 40C88 80065888 8C424660 */ lw $v0, %lo(__osRunningThread)($v0) -/* 40C8C 8006588C 0C01AC1B */ jal osEnqueueAndYield +/* 40C8C 8006588C 0C01AC1B */ jal __osEnqueueAndYield /* 40C90 80065890 A4530010 */ sh $s3, 0x10($v0) /* 40C94 80065894 8E020008 */ lw $v0, 8($s0) /* 40C98 80065898 8E030010 */ lw $v1, 0x10($s0) @@ -67,7 +67,7 @@ glabel osSendMesg /* 40D04 80065904 8C620000 */ lw $v0, ($v1) /* 40D08 80065908 10400005 */ beqz $v0, .L80065920 /* 40D0C 8006590C 00000000 */ nop -/* 40D10 80065910 0C01AC6F */ jal osPopThread +/* 40D10 80065910 0C01AC6F */ jal __osPopThread /* 40D14 80065914 02002021 */ addu $a0, $s0, $zero /* 40D18 80065918 0C019808 */ jal osStartThread /* 40D1C 8006591C 00402021 */ addu $a0, $v0, $zero diff --git a/ver/us/asm/nonmatchings/os/sins/sins.s b/ver/us/asm/os/sins/sins.s similarity index 100% rename from ver/us/asm/nonmatchings/os/sins/sins.s rename to ver/us/asm/os/sins/sins.s diff --git a/ver/us/asm/nonmatchings/os/3fa50_len_f60/memcpy.s b/ver/us/asm/os/string/memcpy.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3fa50_len_f60/memcpy.s rename to ver/us/asm/os/string/memcpy.s diff --git a/ver/us/asm/nonmatchings/os/3fa50_len_f60/strchr.s b/ver/us/asm/os/string/strchr.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3fa50_len_f60/strchr.s rename to ver/us/asm/os/string/strchr.s diff --git a/ver/us/asm/nonmatchings/os/3fa50_len_f60/strlen.s b/ver/us/asm/os/string/strlen.s similarity index 100% rename from ver/us/asm/nonmatchings/os/3fa50_len_f60/strlen.s rename to ver/us/asm/os/string/strlen.s diff --git a/ver/us/splat.yaml b/ver/us/splat.yaml index 2e7d6d438b..8ba0462c37 100644 --- a/ver/us/splat.yaml +++ b/ver/us/splat.yaml @@ -141,24 +141,28 @@ segments: - [0x3CCD0, hasm, os/osWritebackDCacheAll] - [0x3CD00, c, os/3cd00_len_5f0] # MOVE_ADDU - [0x3CF80, c, os/controller] - - [0x3D290, c, os/osVirtualToPhysical] - - [0x3D2F0, c, os/3d2f0_len_10] - - [0x3D300, c, os/3d300_len_30] - - [0x3D330, c, os/guFrustum] - - [0x3D5B0, c, os/guLookAt] - - [0x3DCC0, c, os/3dcc0_len_a60] - - [0x3E720, c, os/3e720_len_5f0] + - [0x3D290, c, os/osVirtualToPhysical, kmc -O3] + - [0x3D2F0, c, os/sqrtf, -ffast-math] + - [0x3D300, c, os/coss, kmc -O3] + - [0x3D330, c, os/guFrustum, kmc -O3] + - [0x3D5B0, c, os/guLookAt, kmc -O3] + - [0x3DCC0, c, os/lookathil, kmc -O3] + - [0x3E720, c, os/lookatref, kmc -O3] - [0x3ED10, c, os/guOrtho, kmc -O3] - - [0x3EF90, c, os/3ef90_len_600] - - [0x3F310, c, os/3f310_len_3c0] - - [0x3F6D0, c, os/3f6d0_len_320] - - [0x3F9F0, c, os/sins] - - [0x3FA50, c, os/3fa50_len_f60] - - [0x3FEA0, c, os/3FEA0] # MOVE_ADDU + - [0x3EF90, c, os/perspective, kmc -O3] + - [0x3F310, c, os/position, kmc -O3] + - [0x3F6D0, c, os/rotateRPY, kmc -O3] + - [0x3F9F0, c, os/sins, kmc -O3] + - [0x3FA50, hasm, os/bcopy] + - [0x3FD70, hasm, os/bzero] + - [0x3FE10, c, os/string, kmc -O3] + - [0x3FEA0, c, os/3FEA0] + - [0x408EC, c, os/sprintf] # MOVE_ADDU - [0x40980, c, os/osCreateMesgQueue] - - [0x409B0, c, os/osJamMesg] - - [0x40AF0, c, os/osRecvMesg] - - [0x40C20, c, os/40c20_len_1f0] + - [0x409B0, c, os/osJamMesg, kmc -O3] + - [0x40AF0, c, os/osRecvMesg, kmc -O3] + - [0x40C20, c, os/sendmesg, kmc -O3] + - [0x40D50, c, os/seteventmesg] - [0x40E00, hasm, os/osGetCount] - [0x40E10, c, os/40E10] - [0x41050, c, os/osSpTaskYield] @@ -312,11 +316,11 @@ segments: - [0x6F190, .data, os/3c850_len_f0] - [0x6F1A0, .data, os/3ca80_len_a0] - [0x6F1B0, .data, os/controller] - - [0x6F1C0, .data, os/3f310_len_3c0] - - [0x6F1D0, .data, os/3f6d0_len_320] + - [0x6F1C0, .data, os/position] + - [0x6F1D0, .data, os/rotateRPY] - [0x6F1E0, .data, os/sins] - [0x6F9E0, .data, os/3FEA0] - - [0x6FA30, .data, os/40c20_len_1f0] + - [0x6FA30, .data, os/sendmesg] - [0x6FA40, .data, os/41170_len_f0] - [0x6FA50, .data, os/osSetThreadPri] - [0x6FA70, data] # has scripts? @@ -352,9 +356,9 @@ segments: - [0x74F20, .rodata, os/3c490_len_3c0] - [0x74F40, .rodata, os/3c940_len_140] - [0x74F50, .rodata, os/guLookAt] - - [0x74F70, .rodata, os/3dcc0_len_a60] - - [0x74FA0, .rodata, os/3e720_len_5f0] - - [0x74FB0, .rodata, os/3ef90_len_600] + - [0x74F70, .rodata, os/lookathil] + - [0x74FA0, .rodata, os/lookatref] + - [0x74FB0, .rodata, os/perspective] - [0x74FF0, .rodata, os/3FEA0] - [0x75170, .rodata, os/42470_len_310] - [0x75180, .rodata, os/exceptasm] diff --git a/ver/us/symbol_addrs.txt b/ver/us/symbol_addrs.txt index 1348c95ece..0e12fab6cb 100644 --- a/ver/us/symbol_addrs.txt +++ b/ver/us/symbol_addrs.txt @@ -1001,7 +1001,7 @@ osTimerInterrupt = 0x800664D4; // type:func rom:0x418D4 osSetTimerIntr = 0x80066610; // type:func rom:0x41A10 osInsertTimer = 0x80066690; // type:func rom:0x41A90 osMapTLB = 0x800667A0; // type:func rom:0x41BA0 -osProbeTLB = 0x80066860; // type:func rom:0x41C60 +__osProbeTLB = 0x80066860; // type:func rom:0x41C60 osUnmapTLB = 0x80066920; // type:func rom:0x41D20 osUnmapTLBAll = 0x80066960; // type:func rom:0x41D60 osViGetCurrentFramebuffer = 0x800669B0; // type:func rom:0x41DB0 @@ -1067,9 +1067,9 @@ osExceptionPreamble = 0x8006AA00; // type:label rom:0x45E00 func_8006AA34 = 0x8006AA34; // type:func rom:0x45E34 send_mesg = 0x8006AF7C; // rom:0x4637C ! handle_CPU = 0x8006B038; // rom:0x46438 ! -osEnqueueAndYield = 0x8006B06C; // rom:0x4646C ! +__osEnqueueAndYield = 0x8006B06C; // rom:0x4646C ! osEnqueueThread = 0x8006B174; // rom:0x46574 ! -osPopThread = 0x8006B1BC; // rom:0x465BC ! +__osPopThread = 0x8006B1BC; // rom:0x465BC ! osDispatchThread = 0x8006B1D4; // rom:0x465D4 ! osCleanupThread = 0x8006B350; // type:func rom:0x46750 __osDisableInt = 0x8006B360; // rom:0x46760