mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-07 08:24:55 +00:00
libu64 (#2267)
* libu64 * logutils.o -> debug.o in spec * stackcheck.c is part of libu64 * review * add paragraph about Overlay_Load calling an external function * audio code*
This commit is contained in:
parent
012c192f00
commit
5b27899b9f
16 changed files with 97 additions and 29 deletions
|
@ -1,160 +0,0 @@
|
|||
#include "global.h"
|
||||
#include "libc64/os_malloc.h"
|
||||
|
||||
typedef void (*arg3_800FC868)(void*);
|
||||
typedef void (*arg3_800FC8D8)(void*, u32);
|
||||
typedef void (*arg3_800FC948)(void*, u32, u32, u32, u32, u32, u32, u32, u32);
|
||||
typedef void (*arg3_800FCA18)(void*, u32);
|
||||
|
||||
typedef struct InitFunc {
|
||||
s32 nextOffset;
|
||||
void (*func)(void);
|
||||
} InitFunc;
|
||||
|
||||
// .data
|
||||
void* sInitFuncs = NULL;
|
||||
|
||||
#if OOT_DEBUG
|
||||
char sNew[] = "new";
|
||||
#else
|
||||
char sNew[] = "";
|
||||
#endif
|
||||
|
||||
#if !PLATFORM_N64
|
||||
char D_80134488[0x18] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x00, 0x00,
|
||||
0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
|
||||
};
|
||||
#endif
|
||||
|
||||
// possibly some kind of new() function
|
||||
void* func_800FC800(u32 size) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
void* ptr;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
|
||||
if (size == 0) {
|
||||
size = 1;
|
||||
}
|
||||
|
||||
#if OOT_DEBUG
|
||||
ptr = __osMallocDebug(&gSystemArena, size, sNew, 0);
|
||||
#else
|
||||
ptr = __osMalloc(&gSystemArena, size);
|
||||
#endif
|
||||
|
||||
RESTORE_INTERRUPTS();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// possibly some kind of delete() function
|
||||
void func_800FC83C(void* ptr) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
if (ptr != NULL) {
|
||||
__osFree(&gSystemArena, ptr);
|
||||
}
|
||||
RESTORE_INTERRUPTS();
|
||||
}
|
||||
|
||||
void func_800FC868(void* blk, u32 nBlk, u32 blkSize, arg3_800FC868 arg3) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
u32 pos;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
for (pos = ((u32)blk & ~0); pos < (u32)blk + (nBlk * blkSize); pos = (u32)pos + (blkSize & ~0)) {
|
||||
arg3((void*)pos);
|
||||
}
|
||||
RESTORE_INTERRUPTS();
|
||||
}
|
||||
|
||||
void func_800FC8D8(void* blk, u32 nBlk, s32 blkSize, arg3_800FC8D8 arg3) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
u32 pos;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
for (pos = ((u32)blk & ~0); pos < (u32)blk + (nBlk * blkSize); pos = (u32)pos + (blkSize & ~0)) {
|
||||
arg3((void*)pos, 2);
|
||||
}
|
||||
RESTORE_INTERRUPTS();
|
||||
}
|
||||
|
||||
void* func_800FC948(void* blk, u32 nBlk, u32 blkSize, arg3_800FC948 arg3) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
u32 pos;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
|
||||
if (blk == NULL) {
|
||||
blk = func_800FC800(nBlk * blkSize);
|
||||
}
|
||||
|
||||
if (blk != NULL && arg3 != NULL) {
|
||||
pos = (u32)blk;
|
||||
while (pos < (u32)blk + (nBlk * blkSize)) {
|
||||
arg3((void*)pos, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
pos = (u32)pos + (blkSize & ~0);
|
||||
}
|
||||
}
|
||||
|
||||
RESTORE_INTERRUPTS();
|
||||
return blk;
|
||||
}
|
||||
|
||||
void func_800FCA18(void* blk, u32 nBlk, u32 blkSize, arg3_800FCA18 arg3, s32 arg4) {
|
||||
DECLARE_INTERRUPT_MASK
|
||||
u32 pos;
|
||||
u32 end;
|
||||
|
||||
DISABLE_INTERRUPTS();
|
||||
|
||||
if (blk != NULL) {
|
||||
if (arg3 != NULL) {
|
||||
end = (u32)blk;
|
||||
pos = (u32)end + (nBlk * blkSize);
|
||||
|
||||
while (pos > end) {
|
||||
pos -= (s32)(blkSize & ~0);
|
||||
arg3((void*)pos, 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (arg4 != 0) {
|
||||
func_800FC83C(blk);
|
||||
}
|
||||
}
|
||||
|
||||
RESTORE_INTERRUPTS();
|
||||
}
|
||||
|
||||
void func_800FCB34(void) {
|
||||
InitFunc* initFunc = (InitFunc*)&sInitFuncs;
|
||||
u32 nextOffset = initFunc->nextOffset;
|
||||
InitFunc* prev = NULL;
|
||||
|
||||
while (nextOffset != 0) {
|
||||
initFunc = (InitFunc*)((s32)initFunc + nextOffset);
|
||||
|
||||
if (initFunc->func != NULL) {
|
||||
initFunc->func();
|
||||
}
|
||||
|
||||
nextOffset = initFunc->nextOffset;
|
||||
initFunc->nextOffset = (s32)prev;
|
||||
prev = initFunc;
|
||||
}
|
||||
|
||||
sInitFuncs = prev;
|
||||
}
|
||||
|
||||
void SystemHeap_Init(void* start, u32 size) {
|
||||
#if PLATFORM_N64
|
||||
__osMallocInit(&gSystemArena, start, size);
|
||||
#else
|
||||
SystemArena_Init(start, size);
|
||||
#endif
|
||||
|
||||
func_800FCB34();
|
||||
}
|
|
@ -1,418 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
u16 sGfxPrintFontTLUT[64] = {
|
||||
0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000, 0xFFFF, 0x0000,
|
||||
0xFFFF, 0x0000, 0xFFFF, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000,
|
||||
0xFFFF, 0xFFFF, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF,
|
||||
0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
|
||||
};
|
||||
|
||||
u16 sGfxPrintRainbowTLUT[16] = {
|
||||
0xF801, 0xFBC1, 0xFFC1, 0x07C1, 0x0421, 0x003F, 0x803F, 0xF83F,
|
||||
0xF801, 0xFBC1, 0xFFC1, 0x07C1, 0x0421, 0x003F, 0x803F, 0xF83F,
|
||||
};
|
||||
|
||||
u8 sGfxPrintRainbowData[8] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
|
||||
|
||||
u8 sGfxPrintFontData[(16 * 256) / 2] = {
|
||||
0x00, 0xDF, 0xFD, 0x00, 0x0A, 0xEE, 0xFF, 0xA0, 0x0D, 0xF2, 0x2D, 0xD0, 0x06, 0x61, 0x1D, 0xC0, 0x01, 0x12, 0x2D,
|
||||
0xD0, 0x06, 0x71, 0x99, 0x00, 0x01, 0x1E, 0xED, 0x10, 0x07, 0x7E, 0xF7, 0x00, 0x01, 0x56, 0x29, 0x90, 0x05, 0x58,
|
||||
0x97, 0x60, 0x0D, 0xD2, 0x29, 0x90, 0x05, 0x59, 0x97, 0x70, 0x04, 0xDF, 0xFD, 0x40, 0x02, 0x6E, 0xF7, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xBF, 0xFB, 0x00, 0x0E, 0xFF, 0xFF, 0xC0, 0x0B, 0xF0, 0x0F, 0xB0,
|
||||
0x0F, 0xF0, 0x03, 0x30, 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x02, 0x20, 0x0C, 0xFB, 0xBF, 0x60, 0x0F, 0xFC, 0xCE,
|
||||
0x20, 0x0D, 0xD4, 0x4F, 0xF0, 0x0F, 0xF0, 0x02, 0x20, 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x03, 0x30, 0x0C, 0xFB,
|
||||
0xBF, 0x40, 0x0E, 0xF7, 0x77, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDF, 0xFD, 0x00, 0x0A,
|
||||
0xEE, 0xFF, 0xA0, 0x0D, 0xF2, 0x2D, 0xD0, 0x06, 0x61, 0x1D, 0xC0, 0x01, 0x12, 0x2D, 0xD0, 0x06, 0x71, 0x99, 0x00,
|
||||
0x01, 0x1E, 0xED, 0x10, 0x07, 0x7E, 0xF7, 0x00, 0x01, 0x56, 0x29, 0x90, 0x05, 0x58, 0x97, 0x60, 0x0D, 0xD2, 0x29,
|
||||
0x90, 0x05, 0x59, 0x97, 0x70, 0x04, 0xDF, 0xFD, 0x40, 0x02, 0x6E, 0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x08, 0xBF, 0xFB, 0x00, 0x00, 0x0D, 0xE0, 0x00, 0x0B, 0xF0, 0x0F, 0xB0, 0x00, 0x5D, 0xE6, 0x00, 0x0F,
|
||||
0xF0, 0x0F, 0xF0, 0x05, 0x5C, 0xC6, 0x60, 0x0C, 0xFB, 0xBF, 0x60, 0x77, 0x3F, 0xF3, 0x77, 0x0D, 0xD4, 0x4F, 0xF0,
|
||||
0xBB, 0x3F, 0xF3, 0xBB, 0x0F, 0xF0, 0x0F, 0xF0, 0x09, 0x9C, 0xCA, 0xA0, 0x0C, 0xFB, 0xBF, 0x40, 0x00, 0x9D, 0xEA,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0xE0, 0x00, 0x04, 0xC2, 0x2C, 0x40, 0x02, 0x8D, 0x50, 0x20, 0x0C, 0xCA,
|
||||
0xAC, 0xC0, 0x21, 0xF9, 0x17, 0x10, 0x04, 0xC2, 0x2C, 0x40, 0x12, 0x49, 0x34, 0x00, 0x00, 0x82, 0x08, 0x00, 0x01,
|
||||
0x97, 0x51, 0x10, 0x08, 0x8A, 0x88, 0x80, 0x04, 0x61, 0x52, 0x41, 0x00, 0x80, 0x08, 0x00, 0x43, 0x11, 0x75, 0x30,
|
||||
0x00, 0xA2, 0x08, 0x00, 0x60, 0x05, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x40, 0x00, 0x22, 0x11,
|
||||
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x0F, 0xB0, 0x00, 0x00, 0x00, 0x08, 0x80, 0x04, 0x0D, 0xA4, 0x00, 0x00, 0x00,
|
||||
0x88, 0x00, 0x08, 0xCD, 0xE8, 0x80, 0x02, 0x2A, 0xA2, 0x20, 0x08, 0xCD, 0xE8, 0x80, 0x02, 0xAA, 0x22, 0x20, 0x04,
|
||||
0x0D, 0xA4, 0x00, 0x0C, 0xD1, 0x00, 0x00, 0x00, 0x0F, 0xB0, 0x00, 0x8C, 0x51, 0x00, 0x00, 0x00, 0x22, 0x11, 0x00,
|
||||
0x81, 0x10, 0x00, 0x00, 0x00, 0xDF, 0xFD, 0x00, 0x0A, 0xEE, 0xFF, 0xA0, 0x0D, 0xF2, 0x2D, 0xD0, 0x06, 0x61, 0x1D,
|
||||
0xC0, 0x01, 0x12, 0x2D, 0xD0, 0x06, 0x71, 0x99, 0x00, 0x01, 0x1E, 0xED, 0x10, 0x07, 0x7E, 0xF7, 0x00, 0x01, 0x56,
|
||||
0x29, 0x90, 0x05, 0x58, 0x97, 0x60, 0x0D, 0xD2, 0x29, 0x90, 0x05, 0x59, 0x97, 0x70, 0x04, 0xDF, 0xFD, 0x40, 0x02,
|
||||
0x6E, 0xF7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x00, 0x04, 0x48, 0x99, 0x80,
|
||||
0x03, 0x3C, 0xC3, 0x30, 0x00, 0xCD, 0x10, 0x88, 0x03, 0x3C, 0xC3, 0x30, 0x02, 0xBF, 0x62, 0xA8, 0x00, 0x33, 0x33,
|
||||
0x20, 0x01, 0x10, 0x4C, 0x80, 0x01, 0x10, 0x03, 0x30, 0x00, 0x15, 0xC8, 0x00, 0x03, 0x3C, 0xC3, 0x30, 0x02, 0x67,
|
||||
0x32, 0x20, 0x00, 0x3F, 0xF3, 0x00, 0x04, 0x40, 0x99, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
|
||||
0xDF, 0xFD, 0x10, 0x07, 0xFF, 0xFF, 0x60, 0x1C, 0xE0, 0x0E, 0xC1, 0x0F, 0xF0, 0x09, 0x90, 0x1E, 0xE1, 0x16, 0x61,
|
||||
0x0F, 0xF0, 0x01, 0x10, 0x1E, 0xF4, 0x56, 0x21, 0x0F, 0xF6, 0x67, 0x10, 0x1E, 0xF2, 0x36, 0x61, 0x0F, 0xF0, 0x89,
|
||||
0x90, 0x1E, 0xF1, 0x0F, 0xE1, 0x0F, 0xF0, 0x09, 0x90, 0x16, 0xEC, 0xCE, 0x21, 0x07, 0xFB, 0xBB, 0x20, 0x01, 0x11,
|
||||
0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x09, 0xB6, 0x6F, 0xD0, 0x27, 0xD8, 0x8E, 0x60, 0x09, 0x92, 0xED, 0x10, 0x2F,
|
||||
0xF0, 0x2E, 0xE0, 0x09, 0x9A, 0xE5, 0x10, 0x2F, 0xF6, 0x2E, 0xE0, 0x09, 0x9B, 0x75, 0x10, 0x2F, 0xD6, 0x4E, 0xE0,
|
||||
0x0D, 0xDA, 0xE5, 0x10, 0x2F, 0xD0, 0x4E, 0xE0, 0x0D, 0xD2, 0xED, 0x10, 0x2F, 0xD0, 0x0E, 0xE0, 0x09, 0xF6, 0x6F,
|
||||
0x90, 0x27, 0xD9, 0x9F, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xFF, 0xFF, 0x00, 0x8F, 0x71,
|
||||
0x1F, 0xF0, 0x2F, 0xD0, 0x0F, 0xF0, 0x8F, 0x71, 0x1F, 0xF0, 0x2F, 0xD0, 0x07, 0x70, 0x8E, 0x61, 0x1E, 0xE0, 0x27,
|
||||
0xDD, 0xDF, 0x60, 0x8E, 0x69, 0x1E, 0xE0, 0x27, 0x76, 0x4A, 0xA0, 0x8E, 0xE9, 0x9E, 0xE0, 0x2F, 0xD0, 0x6E, 0x80,
|
||||
0x8A, 0xE7, 0xFE, 0xA0, 0x07, 0xFA, 0x8E, 0x60, 0x88, 0x27, 0x7A, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x07, 0x7C, 0xCF, 0xF0, 0x13, 0x26, 0x60, 0x11, 0x07, 0x7C, 0xCF, 0xF0, 0x03, 0x76, 0x65, 0x10, 0x02, 0x39,
|
||||
0xD7, 0x20, 0x04, 0x53, 0x35, 0x40, 0x00, 0x2F, 0xF2, 0x00, 0x01, 0x13, 0x31, 0x10, 0x00, 0x5F, 0xB1, 0x00, 0x00,
|
||||
0x03, 0x30, 0x00, 0x05, 0x5E, 0xE5, 0x50, 0x01, 0x13, 0x31, 0x10, 0x05, 0x5E, 0xED, 0xD0, 0x02, 0x23, 0x30, 0x00,
|
||||
0x00, 0x08, 0x88, 0x80, 0x8A, 0xAB, 0xB8, 0x88, 0x00, 0x00, 0x11, 0x00, 0x00, 0x04, 0x45, 0x10, 0x04, 0x62, 0x33,
|
||||
0x20, 0x00, 0x44, 0x01, 0x10, 0x04, 0xC8, 0x9A, 0xA0, 0x00, 0xEE, 0xAB, 0x10, 0x0C, 0xE6, 0x67, 0x20, 0x0E, 0xF5,
|
||||
0x5F, 0xB0, 0x0E, 0xE0, 0x06, 0x60, 0x0B, 0xF6, 0x2B, 0x90, 0x0E, 0xE0, 0x06, 0x60, 0x03, 0xFC, 0x89, 0x90, 0x04,
|
||||
0xEE, 0xEE, 0xA0, 0x00, 0x77, 0x3B, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x08, 0x88, 0x88, 0x00, 0x09, 0x90, 0x00, 0x00,
|
||||
0x00, 0x11, 0x10, 0x00, 0x09, 0x92, 0x24, 0x40, 0x00, 0x01, 0x10, 0x00, 0x09, 0x90, 0x88, 0x00, 0x26, 0xEF, 0xDE,
|
||||
0x20, 0x09, 0x9B, 0xB5, 0x40, 0x2E, 0xC3, 0x3C, 0xE2, 0x0D, 0x9A, 0x25, 0x50, 0x2E, 0xC3, 0x3C, 0xE2, 0x0D, 0xDA,
|
||||
0xA5, 0x50, 0x2E, 0xC3, 0x3C, 0xE2, 0x09, 0xD6, 0xED, 0x10, 0x26, 0xCB, 0xBC, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00,
|
||||
0x05, 0xFB, 0xFF, 0xE0, 0x8E, 0x61, 0x16, 0xE8, 0x0F, 0xF4, 0x03, 0x30, 0x8F, 0x71, 0x17, 0xF8, 0x07, 0xFC, 0x8B,
|
||||
0x30, 0x8E, 0x69, 0x96, 0xE8, 0x05, 0x73, 0x3B, 0xA0, 0x8A, 0x6D, 0xD6, 0xA8, 0x0D, 0xD8, 0x8A, 0x20, 0x08, 0xA7,
|
||||
0x79, 0xB2, 0x01, 0x10, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x8A, 0x01, 0x10, 0x00, 0x00,
|
||||
0x00, 0x08, 0x00, 0x80, 0xA1, 0x10, 0x00, 0x07, 0x74, 0x4F, 0x70, 0x80, 0xA9, 0x90, 0x00, 0x02, 0x31, 0xDF, 0x20,
|
||||
0x84, 0xE6, 0x00, 0x04, 0x00, 0x27, 0xDA, 0x20, 0xC8, 0xAA, 0x4C, 0x40, 0x00, 0x57, 0x3B, 0x20, 0x00, 0xA1, 0x18,
|
||||
0x00, 0x05, 0x54, 0x6F, 0x50, 0x00, 0xA9, 0x98, 0x00, 0x02, 0x22, 0x20, 0x80, 0x02, 0x00, 0x18, 0x88, 0x00, 0x04,
|
||||
0x44, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x44, 0x40, 0x0C, 0x44, 0x44, 0x00, 0x00, 0x04, 0x40, 0x00, 0x88,
|
||||
0xC0, 0x00, 0x00, 0x00, 0x0C, 0xC0, 0x00, 0x0C, 0x46, 0xA4, 0x40, 0x00, 0x0C, 0xC0, 0x00, 0x08, 0x8E, 0xE0, 0x00,
|
||||
0x02, 0x08, 0x80, 0x00, 0x80, 0xD0, 0x88, 0x00, 0x28, 0xA8, 0x80, 0x00, 0x88, 0xCD, 0x4C, 0x40, 0x0A, 0x88, 0x80,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xE0, 0x08, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x08, 0x88, 0x00, 0x80, 0x01, 0x06, 0x10, 0x00, 0x56, 0xE7, 0x50, 0x80, 0x02, 0x1F, 0xF1, 0x00, 0x38,
|
||||
0x8C, 0xB8, 0x00, 0x0B, 0xF6, 0x0B, 0x00, 0x94, 0xC0, 0x28, 0x00, 0x06, 0x07, 0x6A, 0x00, 0xCB, 0xA6, 0xC8, 0x00,
|
||||
0x00, 0x47, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x80, 0x00, 0x00, 0x39, 0x14,
|
||||
0x20, 0x02, 0x22, 0x24, 0x00, 0x08, 0xAE, 0xA8, 0x60, 0x04, 0x28, 0x99, 0x70, 0x07, 0x75, 0xD1, 0x04, 0x0F, 0xB3,
|
||||
0x33, 0xD0, 0x00, 0xAE, 0xBE, 0xA4, 0x25, 0x15, 0x20, 0xA0, 0x02, 0x61, 0x0C, 0x02, 0x20, 0x42, 0x08, 0x20, 0x2C,
|
||||
0x30, 0x14, 0x02, 0x02, 0x28, 0x82, 0x00, 0x03, 0xAC, 0xC1, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x08, 0x12, 0x00, 0x08, 0x00, 0x28, 0x00, 0x0A, 0xCF, 0xEE, 0x20, 0x0B, 0x62, 0x2E, 0x20, 0x02, 0x10, 0x82,
|
||||
0x40, 0x01, 0x44, 0xE4, 0x40, 0x03, 0x00, 0x0E, 0x00, 0x8D, 0xEA, 0xAC, 0x00, 0x02, 0x10, 0x0A, 0x00, 0x01, 0xE0,
|
||||
0x24, 0x00, 0x0C, 0x21, 0x02, 0x00, 0x09, 0x42, 0x21, 0x00, 0x00, 0xCC, 0xF4, 0x40, 0x02, 0xBF, 0xD4, 0x40, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x44, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x44, 0x40,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x00, 0x0C, 0xCC, 0xC4, 0x40, 0x00, 0x0C, 0xC0, 0x00, 0x00, 0x02, 0xA0,
|
||||
0x40, 0x00, 0x0C, 0xC0, 0x00, 0x04, 0xCE, 0x64, 0x40, 0x02, 0x08, 0x80, 0x00, 0x00, 0x90, 0x00, 0x40, 0x28, 0xA8,
|
||||
0x80, 0x00, 0x08, 0x01, 0x04, 0x00, 0x0A, 0x88, 0x80, 0x00, 0x04, 0x44, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x54, 0x44, 0x00,
|
||||
0xEE, 0xFE, 0xE0, 0x00, 0x09, 0x3B, 0x3F, 0x00, 0x21, 0xD8, 0x20, 0x00, 0x00, 0x54, 0x4F, 0x00, 0x18, 0x58, 0x20,
|
||||
0x00, 0x00, 0x01, 0x86, 0x00, 0xC6, 0x7E, 0x40, 0x00, 0x00, 0xEF, 0x66, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0xC0, 0x20, 0x00, 0xAA, 0xAA, 0xEA, 0x20, 0xEF, 0xFF, 0xFF, 0x00, 0x80,
|
||||
0x44, 0x19, 0x30, 0x00, 0x49, 0x24, 0x00, 0xC5, 0x35, 0x1B, 0x10, 0x00, 0x4B, 0x24, 0x00, 0x01, 0x35, 0xA0, 0x00,
|
||||
0x8C, 0xA9, 0xAC, 0x80, 0x00, 0x2C, 0x00, 0x00, 0x04, 0x21, 0xA4, 0x00, 0x2A, 0x84, 0x00, 0x00, 0x73, 0x11, 0xF1,
|
||||
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x11, 0x19, 0x00, 0x00, 0x40, 0x00, 0x00, 0x8F, 0xEE,
|
||||
0xEF, 0xE0, 0x0B, 0x76, 0x66, 0xD0, 0x1A, 0x00, 0x0B, 0x40, 0x4C, 0x40, 0x02, 0xD0, 0x28, 0x00, 0x1A, 0x40, 0x01,
|
||||
0xD0, 0x2C, 0x10, 0x00, 0x00, 0x38, 0x40, 0x00, 0x40, 0x28, 0x10, 0x00, 0x01, 0xA0, 0x40, 0x00, 0x42, 0x83, 0x00,
|
||||
0x05, 0xFE, 0x44, 0x40, 0x03, 0xFD, 0x54, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x99, 0x9B,
|
||||
0x00, 0x00, 0x10, 0x20, 0x00, 0x07, 0x26, 0x21, 0x40, 0x2A, 0xFE, 0xEE, 0xA0, 0x8D, 0x8C, 0xA9, 0xC0, 0x00, 0x10,
|
||||
0x20, 0x80, 0x32, 0x33, 0xB3, 0x60, 0x00, 0x19, 0x28, 0x00, 0x00, 0x00, 0xA1, 0x40, 0x00, 0x10, 0xB1, 0x00, 0x00,
|
||||
0x08, 0x34, 0x00, 0x00, 0x1A, 0x08, 0x00, 0x05, 0xF7, 0x40, 0x00, 0x8E, 0xF4, 0x44, 0xC0, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x08, 0x14, 0x02, 0x80, 0x00, 0x04, 0x00, 0x00, 0x1D, 0x11, 0xDB, 0x00, 0xDD, 0xFD, 0xDD,
|
||||
0xD0, 0x0C, 0x88, 0x07, 0x00, 0x02, 0x06, 0x00, 0x90, 0x48, 0x00, 0x34, 0x00, 0x2C, 0x04, 0x2C, 0x10, 0x48, 0x11,
|
||||
0x21, 0x40, 0x04, 0x84, 0x83, 0x40, 0x59, 0x03, 0x00, 0x50, 0x40, 0x0C, 0x10, 0x60, 0x42, 0xA9, 0x88, 0xC0, 0x40,
|
||||
0x15, 0x80, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x02, 0x00, 0x40, 0x08, 0x98, 0x88, 0x80,
|
||||
0x08, 0xF9, 0x98, 0xC0, 0x06, 0x77, 0x75, 0x50, 0x02, 0x0C, 0x05, 0x00, 0x19, 0x98, 0xA8, 0xD0, 0x0B, 0x99, 0xCA,
|
||||
0x80, 0x04, 0x54, 0x65, 0xC0, 0x20, 0x08, 0x50, 0x20, 0x00, 0x10, 0x20, 0xC0, 0x31, 0x1C, 0x04, 0x20, 0x00, 0x01,
|
||||
0x28, 0x40, 0x26, 0x63, 0xBB, 0xE0, 0x26, 0xEF, 0xE6, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x02, 0x01, 0x00, 0xC8, 0xC0, 0x00, 0x00, 0x0F, 0x8A, 0x89, 0x80, 0xC3, 0xF3, 0x11, 0x30, 0x0F, 0x02, 0x01, 0x80,
|
||||
0xC9, 0xC0, 0x00, 0x30, 0x0F, 0x02, 0x05, 0xA0, 0x00, 0x00, 0x00, 0x30, 0x0E, 0x02, 0x05, 0xA0, 0x00, 0x00, 0x00,
|
||||
0x30, 0x0E, 0x02, 0x52, 0x80, 0x00, 0x00, 0x03, 0x00, 0x2C, 0xDF, 0xA8, 0x80, 0x02, 0x33, 0x30, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x88, 0x00, 0x01, 0x02, 0x80, 0x00, 0x03, 0xFF, 0xF7, 0x00, 0x0F,
|
||||
0x26, 0xE4, 0x72, 0xCC, 0x38, 0x00, 0x40, 0x0C, 0x38, 0x99, 0x00, 0x03, 0x0A, 0x31, 0x50, 0x0C, 0xB1, 0x82, 0x80,
|
||||
0x03, 0x28, 0x06, 0x00, 0x87, 0x88, 0x2A, 0xA0, 0x01, 0x05, 0xC2, 0x00, 0x85, 0x82, 0xC2, 0x80, 0x10, 0x00, 0x39,
|
||||
0x10, 0x08, 0x51, 0xBF, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x48, 0x9D,
|
||||
0xCC, 0x40, 0xC9, 0xE6, 0x7F, 0x40, 0x40, 0x00, 0x94, 0x00, 0x5B, 0x21, 0x0C, 0xB0, 0x48, 0xAE, 0xCC, 0x40, 0xE1,
|
||||
0x30, 0x0C, 0x30, 0x43, 0x01, 0xA4, 0x00, 0xE1, 0x24, 0x5D, 0x30, 0x78, 0x8C, 0xD6, 0x10, 0xF1, 0x60, 0x94, 0x70,
|
||||
0xD0, 0x40, 0x9C, 0x70, 0x0B, 0x8C, 0x53, 0x00, 0x0C, 0x9D, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x39, 0x50, 0x00, 0x00, 0x88, 0xF0, 0x00, 0x2E, 0xAF, 0xC6, 0x00, 0x03, 0x01, 0x77, 0x60, 0x04, 0xF0,
|
||||
0x41, 0x60, 0x03, 0x92, 0xF8, 0x12, 0x0F, 0xBD, 0x91, 0x40, 0x1B, 0x28, 0x60, 0x92, 0x70, 0xF4, 0x01, 0xF0, 0x0A,
|
||||
0xD4, 0x65, 0x82, 0x53, 0xE0, 0x01, 0xE0, 0x04, 0x10, 0x68, 0x60, 0x04, 0x2A, 0xBE, 0x00, 0x00, 0x4F, 0x80, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3A, 0xEE, 0x00, 0xC8, 0xC0, 0x00, 0x00, 0x0D, 0x84, 0xA5,
|
||||
0x00, 0xC1, 0xC2, 0x11, 0x00, 0x45, 0x0E, 0x27, 0x00, 0xD9, 0xC3, 0x00, 0x10, 0x07, 0xF8, 0x8D, 0x20, 0x01, 0x30,
|
||||
0x00, 0x10, 0xAC, 0x02, 0x25, 0xA0, 0x01, 0x22, 0x00, 0x10, 0x44, 0x20, 0x16, 0xA0, 0x13, 0x02, 0x00, 0x30, 0x04,
|
||||
0x1B, 0xAA, 0x40, 0x21, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
#if !PLATFORM_N64
|
||||
// Can be used to set GFXP_FLAG_ENLARGE by default
|
||||
static u8 sDefaultSpecialFlags;
|
||||
#endif
|
||||
|
||||
void GfxPrint_Setup(GfxPrint* this) {
|
||||
s32 width;
|
||||
s32 height;
|
||||
s32 i;
|
||||
s32 pal;
|
||||
s32 cm;
|
||||
s32 masks;
|
||||
s32 maskt;
|
||||
s32 shift;
|
||||
s32 line;
|
||||
s32 tmem = 0;
|
||||
s32 fmt = G_IM_FMT_CI;
|
||||
|
||||
gDPPipeSync(this->dList++);
|
||||
gDPSetOtherMode(this->dList++,
|
||||
G_AD_DISABLE | G_CD_DISABLE | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_IA16 | G_TL_TILE |
|
||||
G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
|
||||
G_AC_NONE | G_ZS_PRIM | G_RM_XLU_SURF | G_RM_XLU_SURF2);
|
||||
gDPSetCombineMode(this->dList++, G_CC_DECALRGBA, G_CC_DECALRGBA);
|
||||
|
||||
width = 16;
|
||||
height = 256;
|
||||
cm = G_TX_NOMIRROR | G_TX_WRAP;
|
||||
masks = G_TX_NOMASK;
|
||||
maskt = G_TX_NOMASK;
|
||||
shift = G_TX_NOLOD;
|
||||
|
||||
gDPLoadMultiBlock_4b(this->dList++, sGfxPrintFontData, 0, G_TX_RENDERTILE, G_IM_FMT_CI, width, height, 0, cm, cm,
|
||||
masks, maskt, shift, shift);
|
||||
gDPLoadTLUT(this->dList++, 64, 0x100, sGfxPrintFontTLUT);
|
||||
|
||||
for (i = 1; i < 4; i++) {
|
||||
gDPSetTile(this->dList++, G_IM_FMT_CI, G_IM_SIZ_4b, 1, 0, i * 2, i, cm, maskt, shift, cm, masks, shift);
|
||||
gDPSetTileSize(this->dList++, i * 2, 0 << 2, 0 << 2, (width - 1) << 2, (height - 1) << 2);
|
||||
}
|
||||
|
||||
gDPSetColor(this->dList++, G_SETPRIMCOLOR, this->color.rgba);
|
||||
|
||||
width = 2;
|
||||
height = 8;
|
||||
cm = G_TX_NOMIRROR | G_TX_WRAP;
|
||||
masks = 1;
|
||||
maskt = 3;
|
||||
shift = G_TX_NOLOD;
|
||||
pal = 4;
|
||||
line = 1;
|
||||
|
||||
gDPLoadMultiTile_4b(this->dList++, sGfxPrintRainbowData, 0, 1, G_IM_FMT_CI, width, height, 0, 0, width - 1,
|
||||
height - 1, pal, cm, cm, masks, maskt, shift, shift);
|
||||
gDPLoadTLUT(this->dList++, 16, 0x140, sGfxPrintRainbowTLUT);
|
||||
|
||||
for (i = 1; i < 4; i++) {
|
||||
gDPSetTile(this->dList++, fmt, G_IM_SIZ_4b, line, tmem, i * 2 + 1, pal, cm, maskt, shift, cm, masks, shift);
|
||||
gDPSetTileSize(this->dList++, i * 2 + 1, 0 << 2, 0 << 2, (width - 1) << 2, (height - 1) << 2);
|
||||
}
|
||||
}
|
||||
|
||||
void GfxPrint_SetColor(GfxPrint* this, u32 r, u32 g, u32 b, u32 a) {
|
||||
this->color.r = r;
|
||||
this->color.g = g;
|
||||
this->color.b = b;
|
||||
this->color.a = a;
|
||||
gDPPipeSync(this->dList++);
|
||||
gDPSetColor(this->dList++, G_SETPRIMCOLOR, this->color.rgba);
|
||||
}
|
||||
|
||||
void GfxPrint_SetPosPx(GfxPrint* this, s32 x, s32 y) {
|
||||
this->posX = this->baseX + (x << 2);
|
||||
this->posY = this->baseY + (y << 2);
|
||||
}
|
||||
|
||||
void GfxPrint_SetPos(GfxPrint* this, s32 x, s32 y) {
|
||||
GfxPrint_SetPosPx(this, x * GFX_CHAR_X_SPACING, y * GFX_CHAR_Y_SPACING);
|
||||
}
|
||||
|
||||
void GfxPrint_SetBasePosPx(GfxPrint* this, s32 x, s32 y) {
|
||||
this->baseX = x << 2;
|
||||
this->baseY = y << 2;
|
||||
}
|
||||
|
||||
void GfxPrint_PrintCharImpl(GfxPrint* this, u8 c) {
|
||||
u32 tile = (c & 0xFF) * 2;
|
||||
|
||||
if (this->flags & GFXP_FLAG_UPDATE) {
|
||||
this->flags &= ~GFXP_FLAG_UPDATE;
|
||||
|
||||
gDPPipeSync(this->dList++);
|
||||
if (this->flags & GFXP_FLAG_RAINBOW) {
|
||||
gDPSetTextureLUT(this->dList++, G_TT_RGBA16);
|
||||
gDPSetCycleType(this->dList++, G_CYC_2CYCLE);
|
||||
gDPSetRenderMode(this->dList++, G_RM_PASS, G_RM_XLU_SURF2);
|
||||
gDPSetCombineMode(this->dList++, G_CC_INTERFERENCE, G_CC_PASS2);
|
||||
} else {
|
||||
gDPSetTextureLUT(this->dList++, G_TT_IA16);
|
||||
gDPSetCycleType(this->dList++, G_CYC_1CYCLE);
|
||||
gDPSetRenderMode(this->dList++, G_RM_XLU_SURF, G_RM_XLU_SURF2);
|
||||
gDPSetCombineMode(this->dList++, G_CC_MODULATEIDECALA_PRIM, G_CC_MODULATEIDECALA_PRIM);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->flags & GFXP_FLAG_SHADOW) {
|
||||
gDPSetColor(this->dList++, G_SETPRIMCOLOR, 0);
|
||||
|
||||
#if PLATFORM_N64
|
||||
gSPTextureRectangle(this->dList++, this->posX + 4, this->posY + 4, this->posX + 4 + 32, this->posY + 4 + 32,
|
||||
tile, (u16)(c & 4) * 64, (u16)(c >> 3) * 256, 1 << 10, 1 << 10);
|
||||
#else
|
||||
if (this->flags & GFXP_FLAG_ENLARGE) {
|
||||
gSPTextureRectangle(this->dList++, (this->posX + 4) << 1, (this->posY + 4) << 1, (this->posX + 4 + 32) << 1,
|
||||
(this->posY + 4 + 32) << 1, tile, (u16)(c & 4) * 64, (u16)(c >> 3) * 256, 1 << 9,
|
||||
1 << 9);
|
||||
} else {
|
||||
gSPTextureRectangle(this->dList++, this->posX + 4, this->posY + 4, this->posX + 4 + 32, this->posY + 4 + 32,
|
||||
tile, (u16)(c & 4) * 64, (u16)(c >> 3) * 256, 1 << 10, 1 << 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
gDPSetColor(this->dList++, G_SETPRIMCOLOR, this->color.rgba);
|
||||
}
|
||||
|
||||
#if PLATFORM_N64
|
||||
gSPTextureRectangle(this->dList++, this->posX, this->posY, this->posX + 32, this->posY + 32, tile,
|
||||
(u16)(c & 4) * 64, (u16)(c >> 3) * 256, 1 << 10, 1 << 10);
|
||||
#else
|
||||
if (this->flags & GFXP_FLAG_ENLARGE) {
|
||||
gSPTextureRectangle(this->dList++, this->posX << 1, this->posY << 1, (this->posX + 32) << 1,
|
||||
(this->posY + 32) << 1, tile, (u16)(c & 4) * 64, (u16)(c >> 3) * 256, 1 << 9, 1 << 9);
|
||||
} else {
|
||||
gSPTextureRectangle(this->dList++, this->posX, this->posY, this->posX + 32, this->posY + 32, tile,
|
||||
(u16)(c & 4) * 64, (u16)(c >> 3) * 256, 1 << 10, 1 << 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
this->posX += GFX_CHAR_X_SPACING << 2;
|
||||
}
|
||||
|
||||
void GfxPrint_PrintChar(GfxPrint* this, u8 c) {
|
||||
#if PLATFORM_N64
|
||||
#define CHAR_PARAM c
|
||||
#else
|
||||
#define CHAR_PARAM charParam
|
||||
u8 charParam = c;
|
||||
#endif
|
||||
|
||||
if (c == ' ') {
|
||||
this->posX += GFX_CHAR_X_SPACING << 2;
|
||||
} else if (c > ' ' && c < 0x7F) {
|
||||
GfxPrint_PrintCharImpl(this, c);
|
||||
} else if (c >= 0xA0 && c < 0xE0) {
|
||||
if (this->flags & GFXP_FLAG_HIRAGANA) {
|
||||
if (c < 0xC0) {
|
||||
CHAR_PARAM = c - 0x20;
|
||||
} else {
|
||||
CHAR_PARAM = c + 0x20;
|
||||
}
|
||||
}
|
||||
GfxPrint_PrintCharImpl(this, CHAR_PARAM);
|
||||
} else {
|
||||
switch (c) {
|
||||
case '\0':
|
||||
break;
|
||||
case '\n':
|
||||
this->posY += GFX_CHAR_Y_SPACING << 2;
|
||||
FALLTHROUGH;
|
||||
case '\r':
|
||||
this->posX = this->baseX;
|
||||
break;
|
||||
case '\t':
|
||||
do {
|
||||
GfxPrint_PrintCharImpl(this, ' ');
|
||||
} while ((this->posX - this->baseX) % 256);
|
||||
break;
|
||||
case GFXP_HIRAGANA_CHAR:
|
||||
this->flags |= GFXP_FLAG_HIRAGANA;
|
||||
break;
|
||||
case GFXP_KATAKANA_CHAR:
|
||||
this->flags &= ~GFXP_FLAG_HIRAGANA;
|
||||
break;
|
||||
case GFXP_RAINBOW_ON_CHAR:
|
||||
this->flags |= GFXP_FLAG_RAINBOW;
|
||||
this->flags |= GFXP_FLAG_UPDATE;
|
||||
break;
|
||||
case GFXP_RAINBOW_OFF_CHAR:
|
||||
this->flags &= ~GFXP_FLAG_RAINBOW;
|
||||
this->flags |= GFXP_FLAG_UPDATE;
|
||||
break;
|
||||
case GFXP_UNUSED_CHAR:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GfxPrint_PrintStringWithSize(GfxPrint* this, const void* buffer, u32 charSize, u32 charCount) {
|
||||
const char* str = (const char*)buffer;
|
||||
u32 count = charSize * charCount;
|
||||
|
||||
while (count != 0) {
|
||||
GfxPrint_PrintChar(this, *(str++));
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
void GfxPrint_PrintString(GfxPrint* this, const char* str) {
|
||||
while (*str != '\0') {
|
||||
GfxPrint_PrintChar(this, *(str++));
|
||||
}
|
||||
}
|
||||
|
||||
void* GfxPrint_Callback(void* arg, const char* str, size_t size) {
|
||||
GfxPrint* this = arg;
|
||||
|
||||
GfxPrint_PrintStringWithSize(this, str, sizeof(char), size);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void GfxPrint_Init(GfxPrint* this) {
|
||||
this->flags &= ~GFXP_FLAG_OPEN;
|
||||
|
||||
this->callback = GfxPrint_Callback;
|
||||
this->dList = NULL;
|
||||
this->posX = 0;
|
||||
this->posY = 0;
|
||||
this->baseX = 0;
|
||||
this->baseY = 0;
|
||||
this->color.rgba = 0;
|
||||
|
||||
this->flags &= ~GFXP_FLAG_HIRAGANA;
|
||||
this->flags &= ~GFXP_FLAG_RAINBOW;
|
||||
this->flags |= GFXP_FLAG_SHADOW;
|
||||
this->flags |= GFXP_FLAG_UPDATE;
|
||||
|
||||
#if !PLATFORM_N64
|
||||
if (sDefaultSpecialFlags & GFXP_FLAG_ENLARGE) {
|
||||
this->flags |= GFXP_FLAG_ENLARGE;
|
||||
} else {
|
||||
this->flags &= ~GFXP_FLAG_ENLARGE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void GfxPrint_Destroy(GfxPrint* this) {
|
||||
}
|
||||
|
||||
void GfxPrint_Open(GfxPrint* this, Gfx* dList) {
|
||||
if (!(this->flags & GFXP_FLAG_OPEN)) {
|
||||
this->flags |= GFXP_FLAG_OPEN;
|
||||
this->dList = dList;
|
||||
GfxPrint_Setup(this);
|
||||
} else {
|
||||
#if PLATFORM_N64 || OOT_DEBUG
|
||||
osSyncPrintf(T("gfxprint_open:2重オープンです\n", "gfxprint_open: Double open\n"));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Gfx* GfxPrint_Close(GfxPrint* this) {
|
||||
Gfx* ret;
|
||||
|
||||
this->flags &= ~GFXP_FLAG_OPEN;
|
||||
#if !PLATFORM_N64
|
||||
gDPPipeSync(this->dList++);
|
||||
#endif
|
||||
ret = this->dList;
|
||||
this->dList = NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 GfxPrint_VPrintf(GfxPrint* this, const char* fmt, va_list args) {
|
||||
return PrintUtils_VPrintf(&this->callback, fmt, args);
|
||||
}
|
||||
|
||||
s32 GfxPrint_Printf(GfxPrint* this, const char* fmt, ...) {
|
||||
s32 ret;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
ret = GfxPrint_VPrintf(this, fmt, args);
|
||||
|
||||
va_end(args);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr) {
|
||||
s32 pad[3];
|
||||
uintptr_t end;
|
||||
OverlayRelocationSection* ovlRelocs;
|
||||
u32 relocSectionOffset = 0;
|
||||
s32 size = vromEnd - vromStart;
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF(
|
||||
T("\nダイナミックリンクファンクションのロードを開始します\n", "\nStart loading dynamic link function\n"));
|
||||
}
|
||||
|
||||
size = vromEnd - vromStart;
|
||||
end = (uintptr_t)allocatedRamAddr + size;
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF(T("TEXT,DATA,RODATA+relをDMA転送します(%08x-%08x)\n",
|
||||
"DMA transfer of TEXT, DATA, RODATA + rel (%08x-%08x)\n"),
|
||||
allocatedRamAddr, end);
|
||||
}
|
||||
|
||||
// DMA the overlay, wait until transfer completes
|
||||
DmaMgr_RequestSync(allocatedRamAddr, vromStart, size);
|
||||
|
||||
// The overlay file is expected to contain a 32-bit offset from the end of the file to the start of the
|
||||
// relocation section.
|
||||
relocSectionOffset = ((s32*)end)[-1];
|
||||
ovlRelocs = (OverlayRelocationSection*)(end - relocSectionOffset);
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF("TEXT(%08x), DATA(%08x), RODATA(%08x), BSS(%08x)\n", ovlRelocs->textSize, ovlRelocs->dataSize,
|
||||
ovlRelocs->rodataSize, ovlRelocs->bssSize);
|
||||
}
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF(T("リロケーションします\n", "Relocate\n"));
|
||||
}
|
||||
|
||||
// Relocate pointers in overlay code and data
|
||||
Overlay_Relocate(allocatedRamAddr, ovlRelocs, vramStart);
|
||||
|
||||
// Clear bss if present, bss is located immediately following the relocations
|
||||
if (ovlRelocs->bssSize != 0) {
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF(T("BSS領域をクリアします(%08x-%08x)\n", "Clear BSS area (%08x-%08x)\n"), end,
|
||||
end + ovlRelocs->bssSize);
|
||||
}
|
||||
bzero((void*)end, ovlRelocs->bssSize);
|
||||
}
|
||||
|
||||
size = (uintptr_t)(ovlRelocs->relocations + ovlRelocs->nRelocations) - (uintptr_t)ovlRelocs;
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF(T("REL領域をクリアします(%08x-%08x)\n", "Clear REL area (%08x-%08x)\n"), ovlRelocs,
|
||||
(uintptr_t)ovlRelocs + size);
|
||||
}
|
||||
|
||||
// Clear relocations, this space remains allocated and goes unused
|
||||
bzero(ovlRelocs, size);
|
||||
|
||||
// Manually flush caches
|
||||
size = (uintptr_t)vramEnd - (uintptr_t)vramStart;
|
||||
osWritebackDCache(allocatedRamAddr, size);
|
||||
osInvalICache(allocatedRamAddr, size);
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF(
|
||||
T("ダイナミックリンクファンクションのロードを終了します\n\n", "Finish loading dynamic link function\n\n"));
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
void* Overlay_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd) {
|
||||
void* allocatedRamAddr = SYSTEM_ARENA_MALLOC_R((intptr_t)vramEnd - (intptr_t)vramStart, "../loadfragment2.c", 31);
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF("OVL:SPEC(%08x-%08x) REAL(%08x-%08x) OFFSET(%08x)\n", vramStart, vramEnd, allocatedRamAddr,
|
||||
((uintptr_t)vramEnd - (uintptr_t)vramStart) + (uintptr_t)allocatedRamAddr,
|
||||
(uintptr_t)vramStart - (uintptr_t)allocatedRamAddr);
|
||||
}
|
||||
|
||||
if (allocatedRamAddr != NULL) {
|
||||
Overlay_Load(vromStart, vromEnd, vramStart, vramEnd, allocatedRamAddr);
|
||||
}
|
||||
|
||||
return allocatedRamAddr;
|
||||
}
|
|
@ -1,209 +0,0 @@
|
|||
/**
|
||||
* @file loadfragment2_n64.c
|
||||
*
|
||||
* This file contains the routine responsible for runtime relocation of dynamically loadable code segments (overlays),
|
||||
* see the description of Overlay_Relocate for details.
|
||||
*
|
||||
* @see Overlay_Relocate
|
||||
*/
|
||||
#include "global.h"
|
||||
|
||||
s32 gOverlayLogSeverity = 2;
|
||||
|
||||
// Extract MIPS register rs from an instruction word
|
||||
#define MIPS_REG_RS(insn) (((insn) >> 0x15) & 0x1F)
|
||||
|
||||
// Extract MIPS register rt from an instruction word
|
||||
#define MIPS_REG_RT(insn) (((insn) >> 0x10) & 0x1F)
|
||||
|
||||
// Extract MIPS jump target from an instruction word
|
||||
#define MIPS_JUMP_TARGET(insn) (((insn)&0x03FFFFFF) << 2)
|
||||
|
||||
/**
|
||||
* Performs runtime relocation of overlay files, loadable code segments.
|
||||
*
|
||||
* Overlays are expected to be loadable anywhere in direct-mapped cached (KSEG0) memory, with some appropriate
|
||||
* alignment requirements; memory addresses in such code must be updated once loaded to execute properly.
|
||||
* When compiled, overlays are given 'fake' KSEG0 RAM addresses larger than the total possible available main memory
|
||||
* (>= 0x80800000), such addresses are referred to as Virtual RAM (VRAM) to distinguish them. When loading the overlay,
|
||||
* the relocation table produced at compile time is consulted to determine where and how to update these VRAM addresses
|
||||
* to correct RAM addresses based on the location the overlay was loaded at, enabling the code to execute at this
|
||||
* address as if it were compiled to run at this address.
|
||||
*
|
||||
* Each relocation is represented by a packed 32-bit value, formatted in the following way:
|
||||
* - [31:30] 2-bit section id, taking values from the `RelocSectionId` enum.
|
||||
* - [29:24] 6-bit relocation type describing which relocation operation should be performed. Same as ELF32 MIPS.
|
||||
* - [23: 0] 24-bit section-relative offset indicating where in the section to apply this relocation.
|
||||
*
|
||||
* @param allocatedRamAddress Memory address the binary was loaded at.
|
||||
* @param ovlRelocs Overlay relocation section containing overlay section layout and runtime relocations.
|
||||
* @param vramStart Virtual RAM address that the overlay was compiled at.
|
||||
*/
|
||||
void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelocs, void* vramStart) {
|
||||
u32 sections[RELOC_SECTION_MAX];
|
||||
u32* relocDataP;
|
||||
u32 reloc;
|
||||
uintptr_t relocatedAddress;
|
||||
u32 i;
|
||||
u32* luiInstRef;
|
||||
u32 isLoNeg;
|
||||
u32* regValP;
|
||||
//! MIPS ELF relocation does not generally require tracking register values, so at first glance it appears this
|
||||
//! register tracking was an unnecessary complication. However there is a bug in the IDO compiler that can cause
|
||||
//! relocations to be emitted in the wrong order under rare circumstances when the compiler attempts to reuse a
|
||||
//! previous HI16 relocation for a different LO16 relocation as an optimization. This register tracking is likely
|
||||
//! a workaround to prevent improper matching of unrelated HI16 and LO16 relocations that would otherwise arise
|
||||
//! due to the incorrect ordering.
|
||||
u32* luiRefs[32];
|
||||
u32 luiVals[32];
|
||||
uintptr_t allocu32 = (uintptr_t)allocatedRamAddr;
|
||||
uintptr_t vramu32 = (uintptr_t)vramStart;
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf("DoRelocation(%08x, %08x, %08x)\n", allocatedRamAddr, ovlRelocs, vramStart);
|
||||
}
|
||||
|
||||
sections[RELOC_SECTION_NULL] = 0;
|
||||
sections[RELOC_SECTION_TEXT] = allocu32;
|
||||
sections[RELOC_SECTION_DATA] = allocu32 + ovlRelocs->textSize;
|
||||
sections[RELOC_SECTION_RODATA] = sections[RELOC_SECTION_DATA] + ovlRelocs->dataSize;
|
||||
|
||||
for (i = 0; i < ovlRelocs->nRelocations; i++) {
|
||||
// This will always resolve to a 32-bit aligned address as each section
|
||||
// containing code or pointers must be aligned to at least 4 bytes and the
|
||||
// MIPS ABI defines the offset of both 16-bit and 32-bit relocations to be
|
||||
// the start of the 32-bit word containing the target.
|
||||
reloc = ovlRelocs->relocations[i];
|
||||
relocDataP = (u32*)(sections[RELOC_SECTION(reloc)] + RELOC_OFFSET(reloc));
|
||||
|
||||
switch (RELOC_TYPE_MASK(reloc)) {
|
||||
case R_MIPS_32 << RELOC_TYPE_SHIFT:
|
||||
// Handles 32-bit address relocation, used for things such as jump tables and pointers in data.
|
||||
// Just relocate the full address
|
||||
|
||||
// Check address is valid for relocation
|
||||
if ((*relocDataP & 0x0F000000) == 0) {
|
||||
*relocDataP = *relocDataP - vramu32 + allocu32;
|
||||
} else if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf(T("セグメントポインタ32です %08x\n", "Segment pointer 32 %08x\n"),
|
||||
*relocDataP - vramu32);
|
||||
}
|
||||
break;
|
||||
|
||||
case R_MIPS_26 << RELOC_TYPE_SHIFT:
|
||||
// Handles 26-bit address relocation, used for jumps and jals.
|
||||
// Extract the address from the target field of the J-type MIPS instruction.
|
||||
// Relocate the address and update the instruction.
|
||||
|
||||
if (1) {
|
||||
*relocDataP =
|
||||
(*relocDataP & 0xFC000000) |
|
||||
(((PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)) - vramu32 + allocu32) & 0x0FFFFFFF) >> 2);
|
||||
} else if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf(T("セグメントポインタ26です %08x\n", "Segment pointer 26 %08x\n"),
|
||||
PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)) - vramu32);
|
||||
}
|
||||
break;
|
||||
|
||||
case R_MIPS_HI16 << RELOC_TYPE_SHIFT:
|
||||
// Handles relocation for a hi/lo pair, part 1.
|
||||
// Store the reference to the LUI instruction (hi) using the `rt` register of the instruction.
|
||||
// This will be updated later in the `R_MIPS_LO16` section.
|
||||
|
||||
luiRefs[(*relocDataP >> 0x10) & 0x1F] = relocDataP;
|
||||
luiVals[(*relocDataP >> 0x10) & 0x1F] = *relocDataP;
|
||||
break;
|
||||
|
||||
case R_MIPS_LO16 << RELOC_TYPE_SHIFT:
|
||||
// Handles relocation for a hi/lo pair, part 2.
|
||||
// Grab the stored LUI (hi) from the `R_MIPS_HI16` section using the `rs` register of the instruction.
|
||||
// The full address is calculated, relocated, and then used to update both the LUI and lo instructions.
|
||||
// If the lo part is negative, add 1 to the LUI value.
|
||||
// Note: The lo instruction is assumed to have a signed immediate.
|
||||
|
||||
luiInstRef = luiRefs[(*relocDataP >> 0x15) & 0x1F];
|
||||
regValP = &luiVals[(*relocDataP >> 0x15) & 0x1F];
|
||||
|
||||
// Check address is valid for relocation
|
||||
if ((((*luiInstRef << 0x10) + (s16)*relocDataP) & 0x0F000000) == 0) {
|
||||
relocatedAddress = ((*regValP << 0x10) + (s16)*relocDataP) - vramu32 + allocu32;
|
||||
isLoNeg = (relocatedAddress & 0x8000) ? 1 : 0;
|
||||
*luiInstRef = (*luiInstRef & 0xFFFF0000) | (((relocatedAddress >> 0x10) & 0xFFFF) + isLoNeg);
|
||||
*relocDataP = (*relocDataP & 0xFFFF0000) | (relocatedAddress & 0xFFFF);
|
||||
} else if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf(T("セグメントポインタ16です %08x %08x %08x\n", "Segment pointer 16 %08x %08x %08x\n"),
|
||||
((*luiInstRef << 0x10) + (s16)*relocDataP) - vramu32, *luiInstRef, *relocDataP);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr) {
|
||||
s32 pad[2];
|
||||
s32 size = vromEnd - vromStart;
|
||||
uintptr_t end;
|
||||
OverlayRelocationSection* ovlRelocs;
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf(
|
||||
T("\nダイナミックリンクファンクションのロードを開始します\n", "\nStart loading dynamic link function\n"));
|
||||
}
|
||||
|
||||
size = vromEnd - vromStart;
|
||||
end = (uintptr_t)allocatedRamAddr + size;
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf(T("TEXT,DATA,RODATA+relをDMA転送します(%08x-%08x)\n",
|
||||
"DMA transfer TEXT, DATA, RODATA+rel (%08x-%08x)\n"),
|
||||
allocatedRamAddr, end);
|
||||
}
|
||||
|
||||
DmaMgr_RequestSync(allocatedRamAddr, vromStart, size);
|
||||
|
||||
// The overlay file is expected to contain a 32-bit offset from the end of the file to the start of the
|
||||
// relocation section.
|
||||
ovlRelocs = (OverlayRelocationSection*)(end - ((s32*)end)[-1]);
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf("TEXT(%08x), DATA(%08x), RODATA(%08x), BSS(%08x)\n", ovlRelocs->textSize, ovlRelocs->dataSize,
|
||||
ovlRelocs->rodataSize, (s32)ovlRelocs->bssSize);
|
||||
}
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf(T("リロケーションします\n", "I will relocate\n"));
|
||||
}
|
||||
|
||||
Overlay_Relocate(allocatedRamAddr, ovlRelocs, vramStart);
|
||||
|
||||
// Casts suggest bssSize struct variable was an s32, but needs to be a u32 for the GC versions
|
||||
if ((s32)ovlRelocs->bssSize != 0) {
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf(T("BSS領域をクリアします(%08x-%08x)\n", "Clear BSS area (%08x-%08x)\n"), end,
|
||||
end + (s32)ovlRelocs->bssSize);
|
||||
}
|
||||
bzero((void*)end, (s32)ovlRelocs->bssSize);
|
||||
}
|
||||
|
||||
size = (uintptr_t)vramEnd - (uintptr_t)vramStart;
|
||||
|
||||
osWritebackDCache(allocatedRamAddr, size);
|
||||
osInvalICache(allocatedRamAddr, size);
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
osSyncPrintf(T("ダイナミックリンクファンクションのロードを終了します\n\n",
|
||||
"Finish loading the dynamic link function\n\n"));
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void* Overlay_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd) {
|
||||
void* allocatedRamAddr = SYSTEM_ARENA_MALLOC_R((intptr_t)vramEnd - (intptr_t)vramStart, "../loadfragment2.c", 31);
|
||||
|
||||
if (allocatedRamAddr != NULL) {
|
||||
Overlay_Load(vromStart, vromEnd, vramStart, vramEnd, allocatedRamAddr);
|
||||
}
|
||||
|
||||
return allocatedRamAddr;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
s32 gOverlayLogSeverity = 2;
|
|
@ -1,24 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
void MtxConv_F2L(Mtx* m1, MtxF* m2) {
|
||||
s32 i;
|
||||
s32 j;
|
||||
|
||||
LOG_UTILS_CHECK_NULL_POINTER("m1", m1, "../mtxuty-cvt.c", 31);
|
||||
LOG_UTILS_CHECK_NULL_POINTER("m2", m2, "../mtxuty-cvt.c", 32);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
s32 value = (m2->mf[i][j] * 0x10000);
|
||||
|
||||
m1->intPart[i][j] = value >> 16;
|
||||
m1->fracPart[i][j] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MtxConv_L2F(MtxF* m1, Mtx* m2) {
|
||||
LOG_UTILS_CHECK_NULL_POINTER("m1", m1, "../mtxuty-cvt.c", 55);
|
||||
LOG_UTILS_CHECK_NULL_POINTER("m2", m2, "../mtxuty-cvt.c", 56);
|
||||
guMtxL2F(m1->mf, m2);
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
s32 PadSetup_Init(OSMesgQueue* mq, u8* outMask, OSContStatus* status) {
|
||||
s32 ret;
|
||||
s32 i;
|
||||
|
||||
*outMask = 0xFF;
|
||||
ret = osContInit(mq, outMask, status);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (*outMask == 0xFF) {
|
||||
if (osContStartQuery(mq) != 0) {
|
||||
return 1;
|
||||
}
|
||||
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
|
||||
osContGetQuery(status);
|
||||
|
||||
*outMask = 0;
|
||||
for (i = 0; i < MAXCONTROLLERS; i++) {
|
||||
switch (status[i].errno) {
|
||||
case 0:
|
||||
if (status[i].type == CONT_TYPE_NORMAL) {
|
||||
*outMask |= 1 << i;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
void PadUtils_Init(Input* input) {
|
||||
bzero(input, sizeof(Input));
|
||||
}
|
||||
|
||||
void func_800FCB70(void) {
|
||||
}
|
||||
|
||||
void PadUtils_ResetPressRel(Input* input) {
|
||||
input->press.button = 0;
|
||||
#if PLATFORM_N64
|
||||
input->press.stick_x = 0;
|
||||
input->press.stick_y = 0;
|
||||
#endif
|
||||
input->rel.button = 0;
|
||||
}
|
||||
|
||||
u32 PadUtils_CheckCurExact(Input* input, u16 value) {
|
||||
return value == input->cur.button;
|
||||
}
|
||||
|
||||
u32 PadUtils_CheckCur(Input* input, u16 key) {
|
||||
return key == (input->cur.button & key);
|
||||
}
|
||||
|
||||
u32 PadUtils_CheckPressed(Input* input, u16 key) {
|
||||
return key == (input->press.button & key);
|
||||
}
|
||||
|
||||
u32 PadUtils_CheckReleased(Input* input, u16 key) {
|
||||
return key == (input->rel.button & key);
|
||||
}
|
||||
|
||||
u16 PadUtils_GetCurButton(Input* input) {
|
||||
return input->cur.button;
|
||||
}
|
||||
|
||||
u16 PadUtils_GetPressButton(Input* input) {
|
||||
return input->press.button;
|
||||
}
|
||||
|
||||
s8 PadUtils_GetCurX(Input* input) {
|
||||
return input->cur.stick_x;
|
||||
}
|
||||
|
||||
s8 PadUtils_GetCurY(Input* input) {
|
||||
return input->cur.stick_y;
|
||||
}
|
||||
|
||||
void PadUtils_SetRelXY(Input* input, s32 x, s32 y) {
|
||||
input->rel.stick_x = x;
|
||||
input->rel.stick_y = y;
|
||||
}
|
||||
|
||||
s8 PadUtils_GetRelXImpl(Input* input) {
|
||||
return input->rel.stick_x;
|
||||
}
|
||||
|
||||
s8 PadUtils_GetRelYImpl(Input* input) {
|
||||
return input->rel.stick_y;
|
||||
}
|
||||
|
||||
s8 PadUtils_GetRelX(Input* input) {
|
||||
return PadUtils_GetRelXImpl(input);
|
||||
}
|
||||
|
||||
s8 PadUtils_GetRelY(Input* input) {
|
||||
return PadUtils_GetRelYImpl(input);
|
||||
}
|
||||
|
||||
#if PLATFORM_N64
|
||||
s8 PadUtils_GetPressX(Input* input) {
|
||||
return input->press.stick_x;
|
||||
}
|
||||
|
||||
s8 PadUtils_GetPressY(Input* input) {
|
||||
return input->press.stick_y;
|
||||
}
|
||||
#endif
|
||||
|
||||
void PadUtils_UpdateRelXY(Input* input) {
|
||||
s32 curX = PadUtils_GetCurX(input);
|
||||
s32 curY = PadUtils_GetCurY(input);
|
||||
s32 relX;
|
||||
s32 relY;
|
||||
|
||||
if (curX > 7) {
|
||||
relX = (curX < 0x43) ? curX - 7 : 0x43 - 7;
|
||||
} else if (curX < -7) {
|
||||
relX = (curX > -0x43) ? curX + 7 : -0x43 + 7;
|
||||
} else {
|
||||
relX = 0;
|
||||
}
|
||||
|
||||
if (curY > 7) {
|
||||
relY = (curY < 0x43) ? curY - 7 : 0x43 - 7;
|
||||
|
||||
} else if (curY < -7) {
|
||||
relY = (curY > -0x43) ? curY + 7 : -0x43 + 7;
|
||||
} else {
|
||||
relY = 0;
|
||||
}
|
||||
|
||||
PadUtils_SetRelXY(input, relX, relY);
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#include "global.h"
|
||||
|
||||
#if PLATFORM_N64 || OOT_DEBUG
|
||||
#define RCP_UTILS_PRINTF osSyncPrintf
|
||||
#elif IDO_PRINTF_WORKAROUND
|
||||
#define RCP_UTILS_PRINTF(args) (void)0
|
||||
#else
|
||||
#define RCP_UTILS_PRINTF(format, ...) (void)0
|
||||
#endif
|
||||
|
||||
#define printSpStatus(x, name) \
|
||||
if (x & SP_STATUS_##name) \
|
||||
RCP_UTILS_PRINTF(#name " ")
|
||||
|
||||
#define printDpStatus(x, name) \
|
||||
if (x & DPC_STATUS_##name) \
|
||||
RCP_UTILS_PRINTF(#name " ")
|
||||
|
||||
void RcpUtils_PrintRegisterStatus(void) {
|
||||
u32 spStatus = __osSpGetStatus();
|
||||
u32 dpStatus = osDpGetStatus();
|
||||
|
||||
RCP_UTILS_PRINTF("osSpGetStatus=%08x: ", spStatus);
|
||||
printSpStatus(spStatus, HALT);
|
||||
printSpStatus(spStatus, BROKE);
|
||||
printSpStatus(spStatus, DMA_BUSY);
|
||||
printSpStatus(spStatus, DMA_FULL);
|
||||
printSpStatus(spStatus, IO_FULL);
|
||||
printSpStatus(spStatus, SSTEP);
|
||||
printSpStatus(spStatus, INTR_BREAK);
|
||||
printSpStatus(spStatus, YIELD);
|
||||
printSpStatus(spStatus, YIELDED);
|
||||
printSpStatus(spStatus, TASKDONE);
|
||||
printSpStatus(spStatus, SIG3);
|
||||
printSpStatus(spStatus, SIG4);
|
||||
printSpStatus(spStatus, SIG5);
|
||||
printSpStatus(spStatus, SIG6);
|
||||
printSpStatus(spStatus, SIG7);
|
||||
RCP_UTILS_PRINTF("\n");
|
||||
|
||||
RCP_UTILS_PRINTF("osDpGetStatus=%08x:", dpStatus);
|
||||
printDpStatus(dpStatus, XBUS_DMEM_DMA);
|
||||
printDpStatus(dpStatus, FREEZE);
|
||||
printDpStatus(dpStatus, FLUSH);
|
||||
printDpStatus(dpStatus, START_GCLK);
|
||||
printDpStatus(dpStatus, TMEM_BUSY);
|
||||
printDpStatus(dpStatus, PIPE_BUSY);
|
||||
printDpStatus(dpStatus, CMD_BUSY);
|
||||
printDpStatus(dpStatus, CBUF_READY);
|
||||
printDpStatus(dpStatus, DMA_BUSY);
|
||||
printDpStatus(dpStatus, END_VALID);
|
||||
printDpStatus(dpStatus, START_VALID);
|
||||
RCP_UTILS_PRINTF("\n");
|
||||
}
|
||||
|
||||
void RcpUtils_Reset(void) {
|
||||
RcpUtils_PrintRegisterStatus();
|
||||
// Flush the RDP pipeline and freeze clock counter
|
||||
osDpSetStatus(DPC_SET_FREEZE | DPC_SET_FLUSH);
|
||||
// Halt the RSP, disable interrupt on break and set "task done" signal
|
||||
__osSpSetStatus(SP_SET_HALT | SP_SET_TASKDONE | SP_CLR_INTR_BREAK);
|
||||
RcpUtils_PrintRegisterStatus();
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
/**
|
||||
* @file relocation.c
|
||||
*
|
||||
* This file contains the routine responsible for runtime relocation of dynamically loadable code segments (overlays),
|
||||
* see the description of Overlay_Relocate for details.
|
||||
*
|
||||
* @see Overlay_Relocate
|
||||
*/
|
||||
#include "global.h"
|
||||
|
||||
// Extract MIPS register rs from an instruction word
|
||||
#define MIPS_REG_RS(insn) (((insn) >> 0x15) & 0x1F)
|
||||
|
||||
// Extract MIPS register rt from an instruction word
|
||||
#define MIPS_REG_RT(insn) (((insn) >> 0x10) & 0x1F)
|
||||
|
||||
// Extract MIPS jump target from an instruction word
|
||||
#define MIPS_JUMP_TARGET(insn) (((insn)&0x03FFFFFF) << 2)
|
||||
|
||||
/**
|
||||
* Performs runtime relocation of overlay files, loadable code segments.
|
||||
*
|
||||
* Overlays are expected to be loadable anywhere in direct-mapped cached (KSEG0) memory, with some appropriate
|
||||
* alignment requirements; memory addresses in such code must be updated once loaded in order to execute properly.
|
||||
* When compiled, overlays are given 'fake' KSEG0 RAM addresses larger than the total possible available main memory
|
||||
* (>= 0x80800000), such addresses are referred to as Virtual RAM (VRAM) to distinguish them. When loading the overlay
|
||||
* the relocation table produced at compile time is consulted to determine where and how to update these VRAM addresses
|
||||
* to correct RAM addresses based on the location the overlay was loaded at, enabling the code to execute at this
|
||||
* address as if it were compiled to run at this address.
|
||||
*
|
||||
* Each relocation is represented by a packed 32-bit value, formatted in the following way:
|
||||
* - [31:30] 2-bit section id, taking values from the `RelocSectionId` enum.
|
||||
* - [29:24] 6-bit relocation type describing which relocation operation should be performed. Same as ELF32 MIPS.
|
||||
* - [23: 0] 24-bit section-relative offset indicating where in the section to apply this relocation.
|
||||
*
|
||||
* @param allocatedRamAddr Memory address the binary was loaded at.
|
||||
* @param ovlRelocs Overlay relocation section containing overlay section layout and runtime relocations.
|
||||
* @param vramStart Virtual RAM address that the overlay was compiled at.
|
||||
*/
|
||||
void Overlay_Relocate(void* allocatedRamAddr, OverlayRelocationSection* ovlRelocs, void* vramStart) {
|
||||
uintptr_t sections[RELOC_SECTION_MAX];
|
||||
u32* relocDataP;
|
||||
u32 reloc;
|
||||
u32 relocData;
|
||||
u32 isLoNeg;
|
||||
uintptr_t allocu32 = (uintptr_t)allocatedRamAddr;
|
||||
u32 i;
|
||||
u32* regValP;
|
||||
//! MIPS ELF relocation does not generally require tracking register values, so at first glance it appears this
|
||||
//! register tracking was an unnecessary complication. However there is a bug in the IDO compiler that can cause
|
||||
//! relocations to be emitted in the wrong order under rare circumstances when the compiler attempts to reuse a
|
||||
//! previous HI16 relocation for a different LO16 relocation as an optimization. This register tracking is likely
|
||||
//! a workaround to prevent improper matching of unrelated HI16 and LO16 relocations that would otherwise arise
|
||||
//! due to the incorrect ordering.
|
||||
u32* luiRefs[32];
|
||||
u32 luiVals[32];
|
||||
u32* luiInstRef;
|
||||
u32 dbg;
|
||||
s32 relocOffset = 0;
|
||||
u32 relocatedValue = 0;
|
||||
uintptr_t unrelocatedAddress = 0;
|
||||
uintptr_t relocatedAddress = 0;
|
||||
uintptr_t vramu32 = (uintptr_t)vramStart;
|
||||
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF("DoRelocation(%08x, %08x, %08x)\n", allocatedRamAddr, ovlRelocs, vramStart);
|
||||
PRINTF("text=%08x, data=%08x, rodata=%08x, bss=%08x\n", ovlRelocs->textSize, ovlRelocs->dataSize,
|
||||
ovlRelocs->rodataSize, ovlRelocs->bssSize);
|
||||
}
|
||||
|
||||
sections[RELOC_SECTION_NULL] = 0;
|
||||
sections[RELOC_SECTION_TEXT] = allocu32;
|
||||
sections[RELOC_SECTION_DATA] = allocu32 + ovlRelocs->textSize;
|
||||
sections[RELOC_SECTION_RODATA] = sections[RELOC_SECTION_DATA] + ovlRelocs->dataSize;
|
||||
|
||||
for (i = 0; i < ovlRelocs->nRelocations; i++) {
|
||||
reloc = ovlRelocs->relocations[i];
|
||||
// This will always resolve to a 32-bit aligned address as each section containing code or pointers must be
|
||||
// aligned to at least 4 bytes and the MIPS ABI defines the offset of both 16-bit and 32-bit relocations to
|
||||
// be the start of the 32-bit word containing the target.
|
||||
relocDataP = (u32*)(sections[RELOC_SECTION(reloc)] + RELOC_OFFSET(reloc));
|
||||
relocData = *relocDataP;
|
||||
|
||||
switch (RELOC_TYPE_MASK(reloc)) {
|
||||
case R_MIPS_32 << RELOC_TYPE_SHIFT:
|
||||
// Handles 32-bit address relocation, used for things such as jump tables and pointers in data.
|
||||
// Just relocate the full address.
|
||||
|
||||
// Check address is valid for relocation
|
||||
if ((*relocDataP & 0x0F000000) == 0) {
|
||||
relocOffset = *relocDataP - vramu32;
|
||||
relocatedValue = relocOffset + allocu32;
|
||||
relocatedAddress = relocatedValue;
|
||||
unrelocatedAddress = relocData;
|
||||
*relocDataP = relocatedAddress;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_MIPS_26 << RELOC_TYPE_SHIFT:
|
||||
// Handles 26-bit address relocation, used for jumps and jals.
|
||||
// Extract the address from the target field of the J-type MIPS instruction.
|
||||
// Relocate the address and update the instruction.
|
||||
if (1) {
|
||||
relocOffset = PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP)) - vramu32;
|
||||
unrelocatedAddress = PHYS_TO_K0(MIPS_JUMP_TARGET(*relocDataP));
|
||||
relocatedValue = (*relocDataP & 0xFC000000) | (((allocu32 + relocOffset) & 0x0FFFFFFF) >> 2);
|
||||
relocatedAddress = PHYS_TO_K0(MIPS_JUMP_TARGET(relocatedValue));
|
||||
*relocDataP = relocatedValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_MIPS_HI16 << RELOC_TYPE_SHIFT:
|
||||
// Handles relocation for a hi/lo pair, part 1.
|
||||
// Store the reference to the LUI instruction (hi) using the `rt` register of the instruction.
|
||||
// This will be updated later in the `R_MIPS_LO16` section.
|
||||
|
||||
luiRefs[MIPS_REG_RT(*relocDataP)] = relocDataP;
|
||||
luiVals[MIPS_REG_RT(*relocDataP)] = *relocDataP;
|
||||
break;
|
||||
|
||||
case R_MIPS_LO16 << RELOC_TYPE_SHIFT:
|
||||
// Handles relocation for a hi/lo pair, part 2.
|
||||
// Grab the stored LUI (hi) from the `R_MIPS_HI16` section using the `rs` register of the instruction.
|
||||
// The full address is calculated, relocated, and then used to update both the LUI and lo instructions.
|
||||
// If the lo part is negative, add 1 to the LUI value.
|
||||
// Note: The lo instruction is assumed to have a signed immediate.
|
||||
|
||||
luiInstRef = luiRefs[MIPS_REG_RS(*relocDataP)];
|
||||
regValP = &luiVals[MIPS_REG_RS(*relocDataP)];
|
||||
|
||||
// Check address is valid for relocation
|
||||
if ((((*regValP << 0x10) + (s16)*relocDataP) & 0x0F000000) == 0) {
|
||||
relocOffset = ((*regValP << 0x10) + (s16)*relocDataP) - vramu32;
|
||||
isLoNeg = ((relocOffset + allocu32) & 0x8000) ? 1 : 0; // adjust for signed immediate
|
||||
unrelocatedAddress = (*luiInstRef << 0x10) + (s16)relocData;
|
||||
*luiInstRef =
|
||||
(*luiInstRef & 0xFFFF0000) | ((((relocOffset + allocu32) >> 0x10) & 0xFFFF) + isLoNeg);
|
||||
relocatedValue = (*relocDataP & 0xFFFF0000) | ((relocOffset + allocu32) & 0xFFFF);
|
||||
|
||||
relocatedAddress = (*luiInstRef << 0x10) + (s16)relocatedValue;
|
||||
*relocDataP = relocatedValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
dbg = 16;
|
||||
switch (RELOC_TYPE_MASK(reloc)) {
|
||||
case R_MIPS_32 << RELOC_TYPE_SHIFT:
|
||||
dbg += 6;
|
||||
FALLTHROUGH;
|
||||
case R_MIPS_26 << RELOC_TYPE_SHIFT:
|
||||
dbg += 10;
|
||||
FALLTHROUGH;
|
||||
case R_MIPS_LO16 << RELOC_TYPE_SHIFT:
|
||||
if (gOverlayLogSeverity >= 3) {
|
||||
PRINTF("%02d %08x %08x %08x ", dbg, relocDataP, relocatedValue, relocatedAddress);
|
||||
PRINTF(" %08x %08x %08x %08x\n", (uintptr_t)relocDataP + vramu32 - allocu32, relocData,
|
||||
unrelocatedAddress, relocOffset);
|
||||
}
|
||||
// Adding a break prevents matching
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue