link most of libultra.a

This commit is contained in:
Prakxo
2024-11-01 16:01:19 +01:00
parent 97487ed354
commit b4d55bae76
42 changed files with 1157 additions and 420 deletions
+4 -4
View File
@@ -516,10 +516,10 @@ libultra/ultra.c:
.text start:0x8005D01C end:0x8005D15C
.bss start:0x80206F60 end:0x80206FA0
libultra/coss.c:
libultra/gu/coss.c:
.text start:0x8005D15C end:0x8005D184
libultra/lookat.c:
libultra/gu/lookat.c:
.text start:0x8005D184 end:0x8005D52C
.sdata2 start:0x80219138 end:0x80219158
@@ -539,11 +539,11 @@ libultra/gu/ortho.c:
.text start:0x8005E218 end:0x8005E414
.sdata2 start:0x802191C8 end:0x802191D8
libultra/perspective.c:
libultra/gu/perspective.c:
.text start:0x8005E414 end:0x8005E654
.sdata2 start:0x802191D8 end:0x80219200
libultra/rotate.c:
libultra/gu/rotate.c:
.text start:0x8005E654 end:0x8005E7D4
.sdata start:0x80217DF0 end:0x80217DF8
.sdata2 start:0x80219200 end:0x80219208
+27 -27
View File
@@ -366,43 +366,43 @@ config.libs = [
{
"lib": "libultra",
"mw_version": config.linker_version,
"cflags": [*cflags_static, "-O4,p", "-inline on"],
"cflags": [*cflags_static, "-O4,p", "-inline auto"],
"progress_category": "library",
"src_dir": "src/static",
"objects": [
Object(NonMatching, "libultra/contquery.c"),
Object(Matching, "libultra/contquery.c"),
Object(NonMatching, "libultra/contreaddata.c"),
Object(NonMatching, "libultra/controller.c"),
Object(NonMatching, "libultra/contsetch.c"),
Object(NonMatching, "libultra/coss.c"),
Object(NonMatching, "libultra/createmesgqueue.c"),
Object(NonMatching, "libultra/createthread.c"),
Object(NonMatching, "libultra/destroythread.c"),
Object(NonMatching, "libultra/getthreadid.c"),
Object(NonMatching, "libultra/gettime.c"),
Object(NonMatching, "libultra/initialize.c"),
Object(NonMatching, "libultra/lookat.c"),
Object(NonMatching, "libultra/gu/lookathil.c"),
Object(NonMatching, "libultra/gu/mtxutil.c"),
Object(Matching, "libultra/controller.c"),
Object(Matching, "libultra/contsetch.c"),
Object(Matching, "libultra/gu/coss.c"),
Object(Matching, "libultra/createmesgqueue.c"),
Object(Matching, "libultra/createthread.c"),
Object(Matching, "libultra/destroythread.c"),
Object(Matching, "libultra/getthreadid.c"),
Object(Matching, "libultra/gettime.c"),
Object(Matching, "libultra/initialize.c"),
Object(Matching, "libultra/gu/lookat.c"),
Object(Matching, "libultra/gu/lookathil.c"),
Object(Matching, "libultra/gu/mtxutil.c"),
Object(Matching, "libultra/gu/normalize.c"),
Object(NonMatching, "libultra/gu/ortho.c"),
Object(NonMatching, "libultra/perspective.c"),
Object(NonMatching, "libultra/recvmesg.c"),
Object(NonMatching, "libultra/rotate.c"),
Object(Matching, "libultra/gu/ortho.c"),
Object(Matching, "libultra/gu/perspective.c"),
Object(Matching, "libultra/recvmesg.c"),
Object(Matching, "libultra/gu/rotate.c"),
Object(Matching, "libultra/gu/scale.c"),
Object(NonMatching, "libultra/sendmesg.c"),
Object(NonMatching, "libultra/setthreadpri.c"),
Object(Matching, "libultra/sendmesg.c"),
Object(Matching, "libultra/setthreadpri.c"),
Object(NonMatching, "libultra/settimer.c"),
Object(NonMatching, "libultra/shutdown.c"),
Object(Matching, "libultra/shutdown.c"),
Object(Matching, "libultra/gu/sins.c"),
Object(NonMatching, "libultra/startthread.c"),
Object(NonMatching, "libultra/stoptimer.c"),
Object(NonMatching, "libultra/timerintr.c"),
Object(Matching, "libultra/startthread.c"),
Object(Matching, "libultra/stoptimer.c"),
Object(Matching, "libultra/timerintr.c"),
Object(Matching, "libultra/gu/translate.c"),
Object(Matching, "libultra/ultra.c"),
Object(NonMatching, "libultra/xldtob.c"),
Object(NonMatching, "libultra/xlitob.c"),
Object(NonMatching, "libultra/xprintf.c"),
Object(Matching, "libultra/xldtob.c"),
Object(Matching, "libultra/xlitob.c"),
Object(Equivalent, "libultra/xprintf.c"),
],
},
{
+1
View File
@@ -60,6 +60,7 @@ extern u8 Na_CheckNeosBoot();
extern void Na_RestartPrepare();
extern u8 Na_CheckRestartReady();
extern void Na_Restart();
extern void Na_Reset();
extern u8 sou_now_bgm_handle;
extern u8 sou_chime_status;
+4
View File
@@ -1,6 +1,7 @@
#ifndef JSYSWRAPPER_H
#define JSYSWRAPPER_H
#include "dolphin/pad.h"
#include "types.h"
#include "JSystem/JKernel/JKREnum.h"
#include "JSystem/JUtility/JUTEnum.h"
@@ -49,6 +50,8 @@ extern s32 JC_JKRHeap_getTotalFreeSize(void* heap);
extern void JC_JKRExpHeap_changeGroupID(void* expheap, u8 groupId);
extern void JC_JUTGamePad_getPadStatus(PADStatus* status, int padId);
extern void* JC__JKRDvdToMainRam_byName(const char* name, u8* buf, JKRExpandSwitch expandSwitch);
extern BOOL JC__JKRDetachResource(void* ptr);
@@ -137,6 +140,7 @@ extern void* JW_Alloc(size_t size, int align);
extern void JW_Free(void* ptr);
extern s32 JW_Resize(void* ptr, size_t new_size);
extern size_t JW_GetMemBlockSize(void* ptr);
extern void JW_JUTXfb_clearIndex(void);
extern void JW_JUTReport(int x, int y, int show_count, const char* fmt, ...);
extern int JC_JKRDecomp_checkCompressed(u8* bufp);
+1
View File
@@ -8,6 +8,7 @@ extern "C" {
#endif
extern u8 __osResetSwitchPressed;
extern u8 __osResetKeyStep;
#ifdef __cplusplus
}
+14
View File
@@ -0,0 +1,14 @@
#ifndef LIBULTRA_CONTROLLER_H
#define LIBULTRA_CONTROLLER_H
#include "libultra/osContPad.h"
#include "libultra/libultra.h"
extern u8 __osMaxControllers;
extern int __osContinitialized;
void __osContGetInitData(u8* p, OSContStatus* s);
#endif
+14
View File
@@ -4,6 +4,17 @@
#include "types.h"
#include "libultra/ultratypes.h"
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#define FTOFIX32(x) (long)((x) * (float)0x00010000)
#define FIX32TOF(x) ((float)(x) * (1.0f / (float)0x00010000))
#define FTOFRAC8(x) ((int) MIN(((x) * (128.0f)), 127.0f) & 0xff)
void guMtxIdentF(float mf[4][4]);
inline void guTranslateF(float m[4][4], float x, float y, float z){
@@ -49,4 +60,7 @@ void guLookAtHilite (Mtx *m, LookAt *l, Hilite *h,
float xl2, float yl2, float zl2, /* light 2 direction */
int twidth, int theight); /* highlight txtr size*/
extern signed short sins (unsigned short angle);
extern signed short coss (unsigned short angle);
#endif
+1
View File
@@ -8,6 +8,7 @@ extern "C" {
#endif
extern void __osInitialize_common();
extern BOOL osIsEnableShutdown(void);
#ifdef __cplusplus
}
-1
View File
@@ -8,7 +8,6 @@ typedef s32 OSPri;
typedef s32 OSId;
OSId osGetThreadId(OSThread*);
#endif
+2 -1
View File
@@ -1,6 +1,7 @@
#ifndef LIBULTRA_OS_THREAD_H
#define LIBULTRA_OS_THREAD_H
#include "libultra/osThread.h"
#include "types.h"
#include "dolphin/os/OSThread.h"
@@ -8,7 +9,7 @@
extern "C" {
#endif
extern void osCreateThread2(OSThread* t, int id, void(*entry)(void*), void* arg, void* stack_pointer, size_t stack_size, OSPriority priority);
extern void osCreateThread2(OSThread* t, OSId id, void(*entry)(void*), void* arg, void* stack_pointer, size_t stack_size, OSPriority priority);
extern void osStartThread(OSThread* t);
extern void osDestroyThread(OSThread* t);
+3
View File
@@ -11,6 +11,9 @@ extern "C" {
#endif
extern int osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMessageQueue* mq, OSMessage msg);
extern void osStopTimerAll(void);
extern OSTimer* __osTimerList;
#ifdef __cplusplus
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef LIBULTRA_TIMERINTR_H
#define LIBULTRA_TIMERINTR_H
#include "types.h"
extern void __osTimerServicesInit(void);
#endif
+2 -2
View File
@@ -35,8 +35,8 @@ typedef void* (*PrintCallback)(void*, const char*, int);
#define FLAGS_HASH 8
#define FLAGS_ZERO 16
static void _Litob(_Pft* args, u8 type);
static void _Ldtob(_Pft* args, u8 type);
extern void _Litob(_Pft* args, u8 type);
extern void _Ldtob(_Pft* args, u8 type);
extern int _Printf(void* (*prout_func)(void*, const char*, int), void* arg,
const char* fmt, va_list ap);
+1 -1
View File
@@ -5,5 +5,5 @@
extern void _dbg_hungup(const char* file, int line) {
char dbg_tbuf[0x100];
sprintf(dbg_tbuf, "*** HungUp in thread %d, [%s:%d] ***\n", osGetThreadId(0), file, line);
sprintf(dbg_tbuf, "*** HungUp in thread %d, [%s:%d] ***\n", osGetThreadId(NULL), file, line);
}
+14
View File
@@ -0,0 +1,14 @@
#include "libultra/libultra.h"
#include "libultra/controller.h"
s32 osContStartQuery(OSMessageQueue* mq){
osSendMesg(mq, NULL, 0);
return 0;
}
void osContGetQuery(OSContStatus *q){
u8 pattern;
__osContGetInitData(&pattern, q);
}
+59
View File
@@ -0,0 +1,59 @@
#include "libultra/libultra.h"
#include "libultra/osContPad.h"
#include "libultra/osMesg.h"
#include "libultra/controller.h"
#include "dolphin/pad.h"
#include "libjsys/jsyswrapper.h"
u8 __osMaxControllers;
int __osContinitialized;
s32 osContInit(OSMessageQueue* mq, u8* p, OSContStatus* s){
if (__osContinitialized != 0){
return 0;
}
__osContinitialized = 1;
__osMaxControllers = 4;
__osContGetInitData(p,s);
return 0;
}
void __osContGetInitData(u8* p, OSContStatus* s){
PADStatus npad;
int i;
u8 success;
for (i = 0, success = 0; i < __osMaxControllers; i++, s++){
JC_JUTGamePad_getPadStatus(&npad, i);
if (npad.err == -3) {
s->errno = 0;
}
else {
switch(npad.err){
case -1:
s->errno = 8;
break;
case -2:
s->errno = 8;
break;
case -3:
s->errno = 4;
break;
default:
s->errno = 0;
break;
}
}
if(s->errno == 0){
s->type = 5;
s->status = 1;
success |= 1 << i;
}
}
*p = success;
}
+14
View File
@@ -0,0 +1,14 @@
#include "dolphin/pad.h"
#include "libultra/libultra.h"
#include "libultra/controller.h"
s32 osContSetCh(u8 cont){
if (PAD_CONTROLLER_NUM >= cont){
__osMaxControllers = cont;
}
else {
__osMaxControllers = PAD_CONTROLLER_NUM;
}
return 0;
}
+6
View File
@@ -0,0 +1,6 @@
#include "dolphin/os/OSMessage.h"
#include "libultra/libultra.h"
void osCreateMesgQueue(OSMessageQueue* mq, OSMessage msg, int msgCount){
OSInitMessageQueue(mq, msg, msgCount);
}
+10
View File
@@ -0,0 +1,10 @@
#include "libultra/libultra.h"
#include "libultra/osThread.h"
#include "_mem.h"
void osCreateThread2(OSThread* t, OSId id, void(*entry)(void*), void* arg, void* stack_pointer, size_t stack_size, OSPriority priority){
memset((void*)((int)stack_pointer - stack_size),0xfd, stack_size);
OSCreateThread(t, (void*)entry, arg, stack_pointer, stack_size, (0x1f - priority), 1);
}
+11
View File
@@ -0,0 +1,11 @@
#include "dolphin/os/OSThread.h"
#include "libultra/libultra.h"
#include "libultra/os_thread.h"
void osDestroyThread(OSThread *t){
if(t == NULL){
t = OSGetCurrentThread();
}
OSCancelThread(t);
}
+11
View File
@@ -0,0 +1,11 @@
#include "dolphin/os/OSThread.h"
#include "libultra/libultra.h"
OSId osGetThreadId(OSThread* t){
if(t == NULL){
t = OSGetCurrentThread();
}
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
#include "libultra/libultra.h"
OSTime __osTimeOffset;
OSTime osGetTime(void){
OSTime val = OSGetTime();
return __osTimeOffset + val;
}
+9
View File
@@ -0,0 +1,9 @@
#include "libultra/gu.h"
signed short
coss( unsigned short x )
{
/* 0 <= x < 0x10000 ==> 0 <= x < 2PI */
return sins ((unsigned short) (x + 0x4000));
}
+76
View File
@@ -0,0 +1,76 @@
#include "libultra/gu.h"
#include "MSL_C/w_math.h"
void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye,
float xAt, float yAt, float zAt,
float xUp, float yUp, float zUp)
{
float 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 = sqrtf (xLook*xLook + yLook*yLook + zLook*zLook);
len = -1.0f/ len;
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 = sqrtf (xRight*xRight + yRight*yRight + zRight*zRight);
len = 1.0f / len;
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 = sqrtf (xUp*xUp + yUp*yUp + zUp*zUp);
len = 1.0f / len;
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;
}
void guLookAt (Mtx *m, float xEye, float yEye, float zEye,
float xAt, float yAt, float zAt,
float xUp, float yUp, float zUp)
{
float mf[4][4];
guLookAtF(mf, xEye, yEye, zEye, xAt, yAt, zAt, xUp, yUp, zUp);
guMtxF2L(mf, m);
}
+156 -1
View File
@@ -1,4 +1,159 @@
#include "libultra/gu.h"
#include "MSL_C/w_math.h"
void 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, /* light 1 direction */
float xl2, float yl2, float zl2, /* light 2 direction */
int twidth, int theight) /* highlight txtr size*/
{
float len, xLook, yLook, zLook, xRight, yRight, zRight;
float xHilite, yHilite, zHilite;
guMtxIdentF(mf);
xLook = xAt - xEye;
yLook = yAt - yEye;
zLook = zAt - zEye;
/* Negate because positive Z is behind us: */
len = -1.0f / 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.0f / 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.0f / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp);
xUp *= len;
yUp *= len;
zUp *= len;
/* hilite vectors */
len = 1.0f / 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.0f / 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.0f / 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.0f / 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;
}
void guLookAtHilite (Mtx *m, LookAt *l, Hilite *h,
float xEye, float yEye, float zEye,
@@ -15,4 +170,4 @@ void guLookAtHilite (Mtx *m, LookAt *l, Hilite *h,
twidth, theight);
guMtxF2L(mf, m);
}
}
+38 -4
View File
@@ -1,7 +1,41 @@
#include "libultra/gu.h"
void guMtxIdent(Mtx *m) {
float mf[4][4];
guMtxIdentF(mf);
guMtxF2L(mf, m);
void guMtxF2L(float mf[4][4], Mtx *m)
{
int i, j;
int e1,e2;
int *ai,*af;
ai=(int *) &m->m[0][0];
af=(int *) &m->m[2][0];
for (i=0; i<4; i++)
for (j=0; j<2; j++) {
e1=FTOFIX32(mf[i][j*2]);
e2=FTOFIX32(mf[i][j*2+1]);
*(ai++) = ( e1 & 0xffff0000 ) | ((e2 >> 16)&0xffff);
*(af++) = ((e1 << 16) & 0xffff0000) | (e2 & 0xffff);
}
}
void guMtxIdentF(float mf[4][4])
{
int i, j;
for (i=0; i<4; i++)
for (j=0; j<4; j++)
if (i == j) mf[i][j] = 1.0;
else mf[i][j] = 0.0;
}
void guMtxIdent(Mtx *m)
{
float mf[4][4];
guMtxIdentF(mf);
guMtxF2L(mf, m);
}
+20 -1
View File
@@ -1,8 +1,27 @@
#include "libultra/gu.h"
void guOrthoF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale)
{
int i, j;
guMtxIdentF(mf);
mf[0][0] = 2/(r-l);
mf[1][1] = 2/(t-b);
mf[2][2] = -2/(f-n);
mf[3][0] = -(r+l)/(r-l);
mf[3][1] = -(t+b)/(t-b);
mf[3][2] = -(f+n)/(f-n);
mf[3][3] = 1;
for (i=0; i<4; i++)
for (j=0; j<4; j++)
mf[i][j] *= scale;
}
void guOrtho(Mtx *m, float l, float r, float b, float t, float n, float f, float scale)
{
float mf[4][4];
guOrthoF(mf, l, r, b, t, n, f, scale);
guMtxF2L(mf, m);
}
}
+44
View File
@@ -0,0 +1,44 @@
#include "libultra/gu.h"
#include "MSL_C/math.h"
void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, float near, float far, float scale)
{
float cot;
int i, j;
guMtxIdentF(mf);
fovy *= 3.1415926 / 180.0;
cot = (float)cos(fovy/2) / (float)sin(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;
}
}
}
void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, float far, float scale)
{
float mf[4][4];
guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale);
guMtxF2L(mf, m);
}
+51
View File
@@ -0,0 +1,51 @@
#include "libultra/gu.h"
#include "MSL_C/math.h"
void guRotateF(float mf[4][4], float a, float x, float y, float z)
{
float xxsine;
float zxsine;
float yxsine;
float cosine;
float sine;
static float dtor = 3.1415926f / 180.0f;
float tmp;
float ab, bc, ca, t;
guNormalize(&x, &y, &z);
tmp = a * dtor;
sine = sin(tmp);
cosine = cos(tmp);
t = (1-cosine);
ab = x*y*t;
bc = y*z*t;
ca = z*x*t;
guMtxIdentF(mf);
xxsine = x * sine;
yxsine = y * sine;
zxsine = z * sine;
t = x*x;
mf[0][0] = t+cosine*(1-t);
mf[2][1] = bc-xxsine;
mf[1][2] = bc+xxsine;
t = y*y;
mf[1][1] = t+cosine*(1-t);
mf[2][0] = ca+yxsine;
mf[0][2] = ca-yxsine;
t = z*z;
mf[2][2] = t+cosine*(1-t);
mf[1][0] = ab-zxsine;
mf[0][1] = ab+zxsine;
}
void guRotate(Mtx *m, float a, float x, float y, float z) {
float mf[4][4];
guRotateF(mf, a, x, y, z);
guMtxF2L(mf, m);
}
+1 -1
View File
@@ -4,4 +4,4 @@ void guScale(Mtx *m, float x, float y, float z) {
float mf[4][4];
guScaleF(mf, x, y, z);
guMtxF2L(mf, m);
}
}
+1 -1
View File
@@ -92,4 +92,4 @@ s16 sins(u16 x) {
}
return val;
}
}
+45 -1
View File
@@ -1,3 +1,47 @@
#include "dolphin/os/OSTime.h"
#include "libultra/libultra.h"
#include "libultra/contreaddata.h"
#include "libultra/controller.h"
#include "libultra/timerintr.h"
#include "types.h"
int osShutdown;
u8 __osInitialized = FALSE;
int osShutdown = FALSE;
OSTime __osShutdownTime;
int __osDisableShutdownLevel;
OSTime __osDisableShutdownTime;
u32 __osShutdown;
int __osShutdownDisable;
u32 __osFinalrom = TRUE;
void __osInitialize_common(void){
__osFinalrom = TRUE;
osShutdown = FALSE;
__osShutdownDisable = FALSE;
__osShutdown = FALSE;
__osResetKeyStep = 0;
__osResetSwitchPressed = FALSE;
if(__osInitialized == FALSE){
__osTimerServicesInit();
__osContinitialized = FALSE;
__osInitialized = TRUE;
}
}
BOOL osIsDisableShutdown(void){
return __osDisableShutdownLevel != FALSE;
}
BOOL osIsEnableShutdown(void){
u32 lev;
return lev = __osDisableShutdownLevel == FALSE;
}
OSTime osGetDisableShutdownTime(void){
return __osDisableShutdownTime;
}
+6
View File
@@ -0,0 +1,6 @@
#include "libultra/libultra.h"
#include "libultra/osMesg.h"
int osRecvMesg(OSMessageQueue* mq, OSMessage* msg, int flags){
return OSReceiveMessage(mq, msg, flags);
}
+7
View File
@@ -0,0 +1,7 @@
#include "dolphin/os/OSMessage.h"
#include "libultra/libultra.h"
#include "libultra/osMesg.h"
int osSendMesg(OSMessageQueue* mq, OSMessage msg, int flags){
return OSSendMessage(mq, msg, flags);
}
+11
View File
@@ -0,0 +1,11 @@
#include "libultra/libultra.h"
void osSetThreadPri(OSThread* t, OSPri pri){
OSPri prio = (0x1f - pri);
if(t == NULL){
t = OSGetCurrentThread();
}
OSSetThreadPriority(t, prio);
}
+72
View File
@@ -0,0 +1,72 @@
#include "libultra/libultra.h"
#include "dolphin/os.h"
#include "dolphin/dvd.h"
#include "dolphin/pad.h"
#include "dolphin/gx.h"
#include "jaudio_NES/game64.h"
#include "libultra/initialize.h"
#include "libjsys/jsyswrapper.h"
#include "libultra/os_timer.h"
#include "boot.h"
#include "m_nmibuf.h"
void osShutdownStart(int val) {
s32 dstat;
OSThread* gthread;
OSThread* cthread;
u32 enable;
OSReport("***osShutdownStart***\n");
dstat = DVDGetDriveStatus();
if (dstat == -1) {
while (TRUE) {}
}
osIsEnableShutdown();
PADRecalibrate(0xF0000000);
Na_Reset();
gthread = GXGetCurrentGXThread();
enable = OSDisableInterrupts();
cthread = OSGetCurrentThread();
if(gthread != cthread){
OSCancelThread(gthread);
GXSetCurrentGXThread();
}
GXFlush();
GXAbortFrame();
GXDrawDone();
OSRestoreInterrupts(enable);
JW_JUTXfb_clearIndex();
VIWaitForRetrace();
VISetBlack(TRUE);
VIFlush();
VIWaitForRetrace();
osStopTimerAll();
LCDisable();
OSReport("リセットしてもこれだけは忘れない。 osAppNMIBuffer[15] = %08x\n", osAppNMIBuffer[15]);
if((val == 2) && (DVDCheckDisk() == 0)){
OSReport("蓋空き。ホットリセットします。\n");
val = 0;
}
if (APPNMI_HOTRESET_GET()) {
OSResetSystem(FALSE, 0, FALSE);
return;
}
switch (val) {
case 0:
OSResetSystem(TRUE,osAppNMIBuffer[15], FALSE);
break;
case 1:
HotResetIplMenu();
break;
case 2:
bcopy(osAppNMIBuffer, (void*)0x811FFFC0, 0x40U);
OSResetSystem(0, 0x80000000, FALSE);
break;;
}
}
+9
View File
@@ -0,0 +1,9 @@
#include "libultra/libultra.h"
void osStartThread(OSThread* t){
if(t == NULL){
t = OSGetCurrentThread();
}
OSResumeThread(t);
}
+22
View File
@@ -0,0 +1,22 @@
#include "libultra/libultra.h"
#include "dolphin/os.h"
void osStopTimerAll(void){
BOOL enable;
OSTimer* prev;
OSTimer* next;
enable = OSDisableInterrupts();
next = __osTimerList->next;
while(next != __osTimerList){
OSCancelAlarm(&next->alarm);
prev = next->next;
prev->prev = next->prev;
next->prev->next = next->next;
next->next = NULL;
next->prev = NULL;
next = prev;
}
OSRestoreInterrupts(enable);
}
+12
View File
@@ -0,0 +1,12 @@
#include "libultra/libultra.h"
OSTimer __osBaseTimer;
OSTimer* __osTimerList = &__osBaseTimer;
void __osTimerServicesInit(void){
__osTimerList->next = __osTimerList->prev = __osTimerList;
__osTimerList->value = 0;
__osTimerList->interval = 0;
__osTimerList->mq = NULL;
__osTimerList->msg = 0;
}
+214 -220
View File
@@ -1,5 +1,5 @@
#include "gcc/stdlib.h" /* ldiv & ldiv_t */
#include "_mem.h" /* memcpy */
#include "_mem.h" /* memcpy */
#include "libultra/xprintf.h"
@@ -8,8 +8,7 @@
s16 _Ldunscale(s16*, _Pft*);
void _Genld(_Pft*, u8, u8*, s16, s16);
const f64 pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L,
10e31L, 10e63L, 10e127L, 10e255L};
const f64 pows[] = { 10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L };
/* float properties */
#define _D0 0
@@ -44,245 +43,240 @@ const f64 pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L,
#define _D3 3
#endif
#pragma optimize_for_size off
void _Ldtob(_Pft* args, u8 type) {
u8 buff[BUFF_LEN];
u8* ptr = buff;
u32 sp70;
f64 val = args->v.ld;
/* maybe struct? */
s16 err;
s16 nsig;
s16 exp;
u8 buff[BUFF_LEN];
u8* ptr = buff;
u32 sp70;
f64 val = args->v.ld;
/* maybe struct? */
s16 err;
s16 nsig;
s16 exp;
int i;
int n;
f64 factor;
int gen;
int j;
int lo;
u8 drop;
int n2;
f64* pows_p;
int i;
int n;
f64 factor;
int gen;
int j;
int lo;
u8 drop;
int n2;
f64* pows_p;
if (args->prec < 0) {
args->prec = 6;
} else if (args->prec == 0 && (type == 'g' || type == 'G')) {
args->prec = 1;
}
err = _Ldunscale(&exp, (_Pft*)args);
if (err > 0) {
memcpy(args->s, err == 2 ? "NaN" : "Inf", args->n1 = 3);
return;
}
if (err == 0) {
nsig = 0;
exp = 0;
} else {
if (val < 0) {
val = -val;
if (args->prec < 0) {
args->prec = 6;
} else if (args->prec == 0 && (type == 'g' || type == 'G')) {
args->prec = 1;
}
if ((exp = (exp * 30103) / 100000 - 4) < 0) {
n = (3 - (int)exp) & ~3;
pows_p = (double*)pows;
exp = -n;
for (; n > 0; n >>= 1, pows_p++) {
if ((n & 1) != 0) {
val *= *pows_p;
err = _Ldunscale(&exp, (_Pft*)args);
if (err > 0) {
memcpy(args->s, err == 2 ? "NaN" : "Inf", args->n1 = 3);
return;
}
if (err == 0) {
nsig = 0;
exp = 0;
} else {
if (val < 0) {
val = -val;
}
}
} else if (exp > 0) {
factor = 1;
exp &= ~3;
if ((exp = (exp * 30103) / 100000 - 4) < 0) {
n = (3 - (int)exp) & ~3;
pows_p = (double*)pows;
exp = -n;
for (; n > 0; n >>= 1, pows_p++) {
if ((n & 1) != 0) {
val *= *pows_p;
}
}
} else if (exp > 0) {
factor = 1;
exp &= ~3;
pows_p = (double*)pows;
for (n = exp; n > 0; n >>= 1, pows_p++) {
if ((n & 1) != 0) {
factor *= *pows_p;
pows_p = (double*)pows;
for (n = exp; n > 0; n >>= 1, pows_p++) {
if ((n & 1) != 0) {
factor *= *pows_p;
}
}
val /= factor;
}
gen = ((type == 'f') ? exp + 10 : 6) + args->prec;
if (gen > 0x13) {
gen = 0x13;
}
*ptr++ = '0';
while (gen > 0 && 0 < val) {
lo = val;
if ((gen -= 8) > 0) {
val = (val - lo) * 1.0e8;
}
ptr = ptr + 8;
for (j = 8; lo > 0 && --j >= 0;) {
const ldiv_t qr = ldiv(lo, 10);
*--ptr = qr.rem + '0';
lo = qr.quot;
}
while (--j >= 0) {
ptr--;
*ptr = '0';
}
ptr += 8;
}
}
val /= factor;
}
gen = ((type == 'f') ? exp + 10 : 6) + args->prec;
if (gen > 0x13) {
gen = 0x13;
}
*ptr++ = '0';
while (gen > 0 && 0 < val) {
lo = val;
if ((gen -= 8) > 0) {
val = (val - lo) * 1.0e8;
}
ptr = ptr + 8;
for (j = 8; lo > 0 && --j >= 0;) {
const ldiv_t qr = ldiv(lo, 10);
*--ptr = qr.rem + '0';
lo = qr.quot;
}
while (--j >= 0) {
ptr--;
*ptr = '0';
}
ptr += 8;
}
gen = ptr - &buff[1];
for (ptr = &buff[1], exp += 7; *ptr == '0'; ptr++) {
--gen, --exp;
gen = ptr - &buff[1];
for (ptr = &buff[1], exp += 7; *ptr == '0'; ptr++) {
--gen, --exp;
}
nsig = ((type == 'f') ? exp + 1 : ((type == 'e' || type == 'E') ? 1 : 0)) + args->prec;
if (gen < nsig) {
nsig = gen;
}
if (nsig > 0) {
char drop = nsig < gen && '5' <= ptr[nsig] ? '9' : '0';
int n;
for (n = nsig; ptr[--n] == drop;) {
--nsig;
}
if (drop == '9') {
++ptr[n];
}
if (n < 0) {
--ptr, ++nsig, ++exp;
}
}
}
nsig = ((type == 'f') ? exp + 1 : ((type == 'e' || type == 'E') ? 1 : 0)) +
args->prec;
if (gen < nsig) {
nsig = gen;
}
if (nsig > 0) {
char drop = nsig < gen && '5' <= ptr[nsig] ? '9' : '0';
int n;
for (n = nsig; ptr[--n] == drop;) {
--nsig;
}
if (drop == '9') {
++ptr[n];
}
if (n < 0) {
--ptr, ++nsig, ++exp;
}
}
}
_Genld((_Pft*)args, type, ptr, nsig, exp);
_Genld((_Pft*)args, type, ptr, nsig, exp);
}
s16 _Ldunscale(s16* pex, _Pft* px) {
u16* ps = (u16*)px;
s16 xchar = (ps[_D0] & _DMASK) >> _DOFF;
u16* ps = (u16*)px;
s16 xchar = (ps[_D0] & _DMASK) >> _DOFF;
if (xchar == _DMAX) { /* NaN or INF */
*pex = 0;
return (s16)(ps[_D0] & _DFRAC || ps[_D1] || ps[_D2] || ps[_D3] ? NAN : INF);
} else if (0 < xchar) {
ps[_D0] = (ps[_D0] & ~_DMASK) | (_DBIAS << _DOFF);
*pex = xchar - (_DBIAS - 1);
return FINITE;
}
if (0 > xchar) {
return NAN;
} else {
*pex = 0;
return 0;
}
if (xchar == _DMAX) { /* NaN or INF */
*pex = 0;
return (s16)(ps[_D0] & _DFRAC || ps[_D1] || ps[_D2] || ps[_D3] ? NAN : INF);
} else if (0 < xchar) {
ps[_D0] = (ps[_D0] & ~_DMASK) | (_DBIAS << _DOFF);
*pex = xchar - (_DBIAS - 1);
return FINITE;
}
if (0 > xchar) {
return NAN;
} else {
*pex = 0;
return 0;
}
}
void _Genld(_Pft* px, u8 code, u8* p, s16 nsig, s16 xexp) {
u8 point = '.';
u8 point = '.';
if (nsig <= 0) {
nsig = 1,
if (nsig <= 0) {
nsig = 1,
p = (u8*)"0";
}
p = (u8*)"0";
}
if (code == 'f' || ((code == 'g' || code == 'G') && (-4 <= xexp) &&
(xexp < px->prec))) { /* 'f' format */
int x;
if (code == 'f' || ((code == 'g' || code == 'G') && (-4 <= xexp) && (xexp < px->prec))) { /* 'f' format */
int x;
++xexp; /* change to leading digit count */
if (code != 'f') { /* fixup for 'g' */
if (!(px->flags & FLAGS_HASH) && nsig < px->prec) {
px->prec = nsig;
}
if ((px->prec -= xexp) < 0) {
px->prec = 0;
}
++xexp; /* change to leading digit count */
if (code != 'f') { /* fixup for 'g' */
if (!(px->flags & FLAGS_HASH) && nsig < px->prec) {
px->prec = nsig;
}
if ((px->prec -= xexp) < 0) {
px->prec = 0;
}
}
if (xexp <= 0) { /* digits only to right of point */
px->s[px->n1++] = '0';
if (0 < px->prec || px->flags & FLAGS_HASH) {
px->s[px->n1++] = point;
}
if (px->prec < -xexp) {
xexp = -px->prec;
}
px->nz1 = -xexp;
px->prec += xexp;
if (px->prec < nsig) {
nsig = px->prec;
}
memcpy(&px->s[px->n1], p, x = px->n2 = nsig);
px->nz2 = px->prec - x;
} else if (nsig < xexp) { /* zeros before point */
memcpy(&px->s[px->n1], p, nsig);
px->n1 += nsig;
px->nz1 = xexp - nsig;
if (0 < px->prec || px->flags & FLAGS_HASH) {
px->s[px->n1] = point, ++px->n2;
}
px->nz2 = px->prec;
} else { /* enough digits before point */
memcpy(&px->s[px->n1], p, xexp);
px->n1 += xexp;
nsig -= xexp;
if (0 < px->prec || px->flags & FLAGS_HASH) {
px->s[px->n1++] = point;
}
if (px->prec < nsig) {
nsig = px->prec;
}
memcpy(&px->s[px->n1], p + (int)xexp, nsig);
px->n1 += nsig;
px->nz1 = px->prec - nsig;
}
} else { /* 'e' format */
if (code == 'g' || code == 'G') { /* fixup for 'g' */
if (nsig < px->prec) {
px->prec = nsig;
}
if (--px->prec < 0) {
px->prec = 0;
}
code = code == 'g' ? 'e' : 'E';
}
px->s[px->n1++] = *p++;
if (0 < px->prec || px->flags & FLAGS_HASH) {
px->s[px->n1++] = point;
}
if (0 < px->prec) { /* put fraction digits */
if (px->prec < --nsig) {
nsig = px->prec;
}
memcpy(&px->s[px->n1], p, nsig);
px->n1 += nsig;
px->nz1 = px->prec - nsig;
}
p = (u8*)&px->s[px->n1]; /* put exponent */
*p++ = code;
if (0 <= xexp) {
*p++ = '+';
} else { /* negative exponent */
*p++ = '-';
xexp = -xexp;
}
if (100 <= xexp) { /* put oversize exponent */
if (1000 <= xexp) {
*p++ = xexp / 1000 + '0', xexp %= 1000;
}
*p++ = xexp / 100 + '0', xexp %= 100;
}
*p++ = xexp / 10 + '0', xexp %= 10;
*p++ = xexp + '0';
px->n2 = p - (u8*)&px->s[px->n1];
}
if (xexp <= 0) { /* digits only to right of point */
px->s[px->n1++] = '0';
if (0 < px->prec || px->flags & FLAGS_HASH) {
px->s[px->n1++] = point;
}
if (px->prec < -xexp) {
xexp = -px->prec;
}
px->nz1 = -xexp;
px->prec += xexp;
if (px->prec < nsig) {
nsig = px->prec;
}
memcpy(&px->s[px->n1], p, x = px->n2 = nsig);
px->nz2 = px->prec - x;
} else if (nsig < xexp) { /* zeros before point */
memcpy(&px->s[px->n1], p, nsig);
px->n1 += nsig;
px->nz1 = xexp - nsig;
if (0 < px->prec || px->flags & FLAGS_HASH) {
px->s[px->n1] = point, ++px->n2;
}
px->nz2 = px->prec;
} else { /* enough digits before point */
memcpy(&px->s[px->n1], p, xexp);
px->n1 += xexp;
nsig -= xexp;
if (0 < px->prec || px->flags & FLAGS_HASH) {
px->s[px->n1++] = point;
}
if (px->prec < nsig) {
nsig = px->prec;
}
memcpy(&px->s[px->n1], p + (int)xexp, nsig);
px->n1 += nsig;
px->nz1 = px->prec - nsig;
}
} else { /* 'e' format */
if (code == 'g' || code == 'G') { /* fixup for 'g' */
if (nsig < px->prec) {
px->prec = nsig;
}
if (--px->prec < 0) {
px->prec = 0;
}
code = code == 'g' ? 'e' : 'E';
}
px->s[px->n1++] = *p++;
if (0 < px->prec || px->flags & FLAGS_HASH) {
px->s[px->n1++] = point;
}
if (0 < px->prec) { /* put fraction digits */
if (px->prec < --nsig) {
nsig = px->prec;
}
memcpy(&px->s[px->n1], p, nsig);
px->n1 += nsig;
px->nz1 = px->prec - nsig;
}
p = (u8*)&px->s[px->n1]; /* put exponent */
*p++ = code;
if (0 <= xexp) {
*p++ = '+';
} else { /* negative exponent */
*p++ = '-';
xexp = -xexp;
}
if (100 <= xexp) { /* put oversize exponent */
if (1000 <= xexp) {
*p++ = xexp / 1000 + '0', xexp %= 1000;
}
*p++ = xexp / 100 + '0', xexp %= 100;
}
*p++ = xexp / 10 + '0', xexp %= 10;
*p++ = xexp + '0';
px->n2 = p - (u8*)&px->s[px->n1];
}
if ((px->flags & (FLAGS_ZERO | FLAGS_MINUS)) ==
FLAGS_ZERO) { /* pad with leading zeros */
s32 n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2;
if ((px->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) { /* pad with leading zeros */
s32 n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2;
if (n < px->width) {
px->nz0 = px->width - n;
if (n < px->width) {
px->nz0 = px->width - n;
}
}
}
}
#pragma optimize_for_size reset
+45 -46
View File
@@ -8,52 +8,51 @@ u8 ldigs[] = "0123456789abcdef";
u8 udigs[] = "0123456789ABCDEF";
extern void _Litob(_Pft* args, u8 type) {
u8* numMap;
int base;
int idx;
u64 num;
lldiv_t test;
char buff[BUFF_LEN];
u8* numMap;
int base;
int idx;
u64 num;
lldiv_t test;
char buff[BUFF_LEN];
if (type == 'X') {
numMap = udigs;
} else {
numMap = ldigs;
}
base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16);
idx = BUFF_LEN;
num = args->v.ll;
if ((type == 'd' || type == 'i') && args->v.ll < 0) {
num = -num;
}
if (num != 0 || args->prec != 0) {
buff[--idx] = numMap[num % base];
}
args->v.ll = num / base;
while (args->v.ll > 0 && idx > 0) {
const lldiv_t quotrem = lldiv(args->v.ll, base);
args->v.ll = quotrem.quot;
buff[--idx] = numMap[quotrem.rem];
}
args->n1 = BUFF_LEN - idx;
memcpy(args->s, buff + idx, args->n1);
if (args->n1 < args->prec) {
args->nz0 = args->prec - args->n1;
}
if (args->prec < 0 &&
(args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) {
idx = args->width - args->n0 - args->nz0 - args->n1;
if (idx > 0) {
args->nz0 += idx;
if (type == 'X') {
numMap = udigs;
} else {
numMap = ldigs;
}
base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16);
idx = BUFF_LEN;
num = args->v.ll;
if ((type == 'd' || type == 'i') && args->v.ll < 0) {
num = -num;
}
if (num != 0 || args->prec != 0) {
buff[--idx] = numMap[num % base];
}
args->v.ll = num / base;
while (args->v.ll > 0 && idx > 0) {
const lldiv_t quotrem = lldiv(args->v.ll, base);
args->v.ll = quotrem.quot;
buff[--idx] = numMap[quotrem.rem];
}
args->n1 = BUFF_LEN - idx;
memcpy(args->s, buff + idx, args->n1);
if (args->n1 < args->prec) {
args->nz0 = args->prec - args->n1;
}
if (args->prec < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) {
idx = args->width - args->n0 - args->nz0 - args->n1;
if (idx > 0) {
args->nz0 += idx;
}
}
}
}
+101 -109
View File
@@ -2,124 +2,117 @@
#include "libultra/xprintf.h"
#define ATOI(i, a) \
for (i = 0; *a >= '0' && *a <= '9'; a++) \
if (i < 999) i = *a + i * 10 - '0';
#define ATOI(i, a) \
for (i = 0; *a >= '0' && *a <= '9'; a++) \
if (i < 999) \
i = *a + i * 10 - '0';
#define _PROUT(fmt, _size) \
if (_size > 0) { \
arg = pfn(arg, fmt, _size); \
if (arg != NULL) \
x.nchar += _size; \
else \
return x.nchar; \
}
#define _PROUT2(fmt, _size) \
if ((u32)(_size) != 0) { \
arg = pfn(arg, fmt, (u32)(_size)); \
if (arg != NULL) \
x.nchar += _size; \
else \
return x.nchar; \
}
#define _PAD(m, src, extracond) \
if (extracond && m > 0) { \
s32 i; \
s32 j; \
for (j = m; j > 0; j -= i) { \
if (j > 32) \
i = 32; \
else \
i = j; \
_PROUT(src, i); \
} \
}
#define _PROUT(fmt, _size) \
if (_size > 0) { \
arg = pfn(arg, fmt, _size); \
if (arg != NULL) \
x.nchar += _size; \
else \
return x.nchar; \
}
#define _PROUT2(fmt, _size) \
if ((u32)(_size) != 0) { \
arg = pfn(arg, fmt, (u32)(_size)); \
if (arg != NULL) \
x.nchar += _size; \
else \
return x.nchar; \
}
#define _PAD(m, src, extracond) \
if (extracond && m > 0) { \
s32 i; \
s32 j; \
for (j = m; j > 0; j -= i) { \
if (j > 32) \
i = 32; \
else \
i = j; \
_PROUT(src, i); \
} \
}
static const char spaces[] = " ";
static const char zeroes[] = "00000000000000000000000000000000";
static char spaces[] = " ";
static char zeroes[] = "00000000000000000000000000000000";
void _Putfld(_Pft*, va_list, u8, u8*);
/* These functions seem to have 04,p enabled */
#pragma optimize_for_size off
int _Printf(void* (*pfn)(void*, const char*, int), void* arg, const char* fmt,
va_list ap) {
/* Unused static variables to match position of locals */
static int unused0;
static int unused1;
static int unused2;
int _Printf(void* (*pfn)(void*, const char*, int), void* arg, const char* fmt, va_list ap) {
static const char fchar[] = " +-#0";
static const u32 fbit[6] = { FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0 };
static char fchar[] = " +-#0";
static u32 fbit[6] = {FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS,
FLAGS_HASH, FLAGS_ZERO, 0};
_Pft x;
x.nchar = 0;
_Pft x;
x.nchar = 0;
while (TRUE) {
u8 qual;
const u8* s = (u8*)fmt;
u8 c;
const char* t;
u8 ac[0x20];
u8* temp;
while (TRUE) {
u8 qual;
const u8* s = (u8*)fmt;
u8 c;
const char* t;
u8 ac[0x20];
u8* temp;
for (c = *s; c != 0 && c != '%';) {
c = *++s;
}
temp = (u8*)fmt;
_PROUT2(fmt, s - temp);
if (c == 0) {
return x.nchar;
}
fmt = (char*)++s;
x.flags = 0;
for (; (t = strchr(fchar, *s)) != NULL; s++) {
x.flags |= fbit[t - fchar];
}
if (*s == '*') {
x.width = va_arg(ap, s32);
if (x.width < 0) {
x.width = -x.width;
x.flags |= FLAGS_MINUS;
}
s++;
} else {
ATOI(x.width, s);
}
if (*s != '.') {
x.prec = -1;
} else {
s++;
if (*s == '*') {
x.prec = va_arg(ap, s32);
s++;
} else {
ATOI(x.prec, s);
}
}
if (strchr("hlL", *s) != NULL) {
qual = *s++;
} else {
qual = 0;
}
x.qual = qual;
for (c = *s; c != 0 && c != '%';) {
c = *++s;
}
temp = (u8*)fmt;
_PROUT2(fmt, s - temp);
if (c == 0) {
return x.nchar;
}
fmt = (char*)++s;
x.flags = 0;
for (; (t = strchr(fchar, *s)) != NULL; s++) {
x.flags |= fbit[t - fchar];
}
if (*s == '*') {
x.width = va_arg(ap, s32);
if (x.width < 0) {
x.width = -x.width;
x.flags |= FLAGS_MINUS;
}
s++;
} else {
ATOI(x.width, s);
}
if (*s != '.') {
x.prec = -1;
} else {
s++;
if (*s == '*') {
x.prec = va_arg(ap, s32);
s++;
} else {
ATOI(x.prec, s);
}
}
if (strchr("hlL", *s) != NULL) {
qual = *s++;
} else {
qual = 0;
}
x.qual = qual;
if (qual == 'l' && *s == 'l') {
x.qual = 'L';
s++;
if (qual == 'l' && *s == 'l') {
x.qual = 'L';
s++;
}
_Putfld(&x, ap, *s, ac);
x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + x.n2 + x.nz2;
_PAD(x.width, spaces, !(x.flags & FLAGS_MINUS));
_PROUT((char*)ac, x.n0);
_PAD(x.nz0, zeroes, 1);
_PROUT(x.s, x.n1);
_PAD(x.nz1, zeroes, 1);
_PROUT((char*)(&x.s[x.n1]), x.n2)
_PAD(x.nz2, zeroes, 1);
_PAD(x.width, spaces, x.flags & FLAGS_MINUS);
fmt = (char*)s + 1;
}
_Putfld(&x, ap, *s, ac);
x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + x.n2 + x.nz2;
_PAD(x.width, spaces, !(x.flags & FLAGS_MINUS));
_PROUT((char*)ac, x.n0);
_PAD(x.nz0, zeroes, 1);
_PROUT(x.s, x.n1);
_PAD(x.nz1, zeroes, 1);
_PROUT((char*)(&x.s[x.n1]), x.n2)
_PAD(x.nz2, zeroes, 1);
_PAD(x.width, spaces, x.flags & FLAGS_MINUS);
fmt = (char*)s + 1;
}
}
void _Putfld(_Pft* px, va_list ap, u8 code, u8* ac) {
@@ -237,4 +230,3 @@ void _Putfld(_Pft* px, va_list ap, u8 code, u8* ac) {
}
}
#pragma optimize_for_size reset