mirror of
https://github.com/pmret/papermario.git
synced 2024-11-18 00:42:34 +01:00
Decomp Some Libultra (#588)
* Work on KMC Libultra * libultra decomp * fix
This commit is contained in:
parent
7f1c1351f2
commit
bd56f6060f
@ -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);
|
||||
|
||||
|
48
include/PR/osint.h
Normal file
48
include/PR/osint.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef _OSINT_H
|
||||
#define _OSINT_H
|
||||
#include <PR/os_internal.h>
|
||||
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
|
@ -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);
|
||||
|
@ -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[];
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -1,3 +0,0 @@
|
||||
#include "common.h"
|
||||
|
||||
INCLUDE_ASM(f32, "os/3d2f0_len_10", sqrtf, f32 value);
|
@ -1,3 +0,0 @@
|
||||
#include "common.h"
|
||||
|
||||
INCLUDE_ASM(s16, "os/3d300_len_30", coss, u16 angle);
|
@ -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);
|
@ -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);
|
@ -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);
|
@ -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);
|
@ -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);
|
@ -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);
|
@ -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);
|
@ -1,3 +1,3 @@
|
||||
#include "common.h"
|
||||
|
||||
INCLUDE_ASM(s32, "os/41c60_len_c0", osProbeTLB);
|
||||
INCLUDE_ASM(s32, "os/41c60_len_c0", __osProbeTLB);
|
||||
|
9
src/os/coss.c
Normal file
9
src/os/coss.c
Normal file
@ -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
|
@ -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);
|
||||
|
@ -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
|
||||
|
165
src/os/lookathil.c
Normal file
165
src/os/lookathil.c
Normal file
@ -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
|
102
src/os/lookatref.c
Normal file
102
src/os/lookatref.c
Normal file
@ -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
|
@ -1,3 +1,11 @@
|
||||
#include "common.h"
|
||||
#include <PR/osint.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,3 +1,29 @@
|
||||
#include "common.h"
|
||||
#include <PR/osint.h>
|
||||
|
||||
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
|
||||
|
@ -1,3 +1,32 @@
|
||||
#include "common.h"
|
||||
#include <PR/osint.h>
|
||||
|
||||
#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);
|
||||
|
@ -1,11 +1,7 @@
|
||||
#define MOVE_ADDU
|
||||
|
||||
#include "common.h"
|
||||
|
||||
struct __osThreadTail {
|
||||
OSThread* next;
|
||||
OSPri priority;
|
||||
};
|
||||
#include <PR/osint.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
53
src/os/perspective.c
Normal file
53
src/os/perspective.c
Normal file
@ -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
|
56
src/os/position.c
Normal file
56
src/os/position.c
Normal file
@ -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
|
47
src/os/rotateRPY.c
Normal file
47
src/os/rotateRPY.c
Normal file
@ -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
|
37
src/os/sendmesg.c
Normal file
37
src/os/sendmesg.c
Normal file
@ -0,0 +1,37 @@
|
||||
#include "common.h"
|
||||
#include <PR/osint.h>
|
||||
|
||||
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
|
4
src/os/seteventmesg.c
Normal file
4
src/os/seteventmesg.c
Normal file
@ -0,0 +1,4 @@
|
||||
#include "common.h"
|
||||
#include <PR/osint.h>
|
||||
|
||||
INCLUDE_ASM(void, "os/seteventmesg", osSetEventMesg, OSEvent event, OSMesgQueue* queue, OSMesg mesg);
|
@ -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
|
||||
|
25
src/os/sprintf.c
Normal file
25
src/os/sprintf.c
Normal file
@ -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;
|
||||
}
|
5
src/os/sqrtf.c
Normal file
5
src/os/sqrtf.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include "common.h"
|
||||
|
||||
f32 sqrtf(f32 f) {
|
||||
return __builtin_sqrtf(f);
|
||||
}
|
41
src/os/string.c
Normal file
41
src/os/string.c
Normal file
@ -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
|
@ -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
|
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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)
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user