From fcc5cf828ded5d362b2e63a8868374a50df405ed Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Fri, 8 Nov 2024 02:27:19 +0100 Subject: libu64 (#1705) * libu64 * libu64 -O2 * Add libu64.md --- include/debug.h | 7 ------ include/gfxprint.h | 52 ------------------------------------------- include/libu64/debug.h | 7 ++++++ include/libu64/gfxprint.h | 52 +++++++++++++++++++++++++++++++++++++++++++ include/libu64/loadfragment.h | 42 ++++++++++++++++++++++++++++++++++ include/libu64/pad.h | 17 ++++++++++++++ include/libu64/padsetup.h | 8 +++++++ include/libu64/stackcheck.h | 26 ++++++++++++++++++++++ include/libu64/system_heap.h | 11 +++++++++ include/loadfragment.h | 42 ---------------------------------- include/padmgr.h | 3 +-- include/padutils.h | 17 -------------- include/stackcheck.h | 26 ---------------------- include/system_heap.h | 11 --------- include/z64.h | 4 ++-- include/z64actor.h | 2 +- include/z64game.h | 2 +- 17 files changed, 168 insertions(+), 161 deletions(-) delete mode 100644 include/debug.h delete mode 100644 include/gfxprint.h create mode 100644 include/libu64/debug.h create mode 100644 include/libu64/gfxprint.h create mode 100644 include/libu64/loadfragment.h create mode 100644 include/libu64/pad.h create mode 100644 include/libu64/padsetup.h create mode 100644 include/libu64/stackcheck.h create mode 100644 include/libu64/system_heap.h delete mode 100644 include/loadfragment.h delete mode 100644 include/padutils.h delete mode 100644 include/stackcheck.h delete mode 100644 include/system_heap.h (limited to 'include') diff --git a/include/debug.h b/include/debug.h deleted file mode 100644 index 96d3d11c7..000000000 --- a/include/debug.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef DEBUG_H -#define DEBUG_H - -void _dbg_hungup(const char* file, int lineNum); -void Reset(void); - -#endif diff --git a/include/gfxprint.h b/include/gfxprint.h deleted file mode 100644 index bcd61221b..000000000 --- a/include/gfxprint.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef GFXPRINT_H -#define GFXPRINT_H - -#include "ultra64.h" - -#include "libc64/aprintf.h" -#include "PR/xstdio.h" - -#include "color.h" -#include "unk.h" - -#define GFXP_UNUSED "\x8E" -#define GFXP_UNUSED_CHAR 0x8E -#define GFXP_HIRAGANA "\x8D" -#define GFXP_HIRAGANA_CHAR 0x8D -#define GFXP_KATAKANA "\x8C" -#define GFXP_KATAKANA_CHAR 0x8C -#define GFXP_RAINBOW_ON "\x8B" -#define GFXP_RAINBOW_ON_CHAR 0x8B -#define GFXP_RAINBOW_OFF "\x8A" -#define GFXP_RAINBOW_OFF_CHAR 0x8A - -typedef struct GfxPrint { - /* 0x00 */ PrintCallback callback; - /* 0x04 */ Gfx* dList; - /* 0x08 */ u16 posX; - /* 0x0A */ u16 posY; - /* 0x0C */ u16 baseX; - /* 0x0E */ u8 baseY; - /* 0x0F */ u8 flags; - /* 0x10 */ Color_RGBA8_u32 color; - /* 0x14 */ UNK_TYPE1 unk_14[0x1C]; // unused -} GfxPrint; // size = 0x30 - -void GfxPrint_Setup(GfxPrint* this); -void GfxPrint_SetColor(GfxPrint* this, u32 r, u32 g, u32 b, u32 a); -void GfxPrint_SetPosPx(GfxPrint* this, s32 x, s32 y); -void GfxPrint_SetPos(GfxPrint* this, s32 x, s32 y); -void GfxPrint_SetBasePosPx(GfxPrint* this, s32 x, s32 y); -void GfxPrint_PrintCharImpl(GfxPrint* this, u8 c); -void GfxPrint_PrintChar(GfxPrint* this, u8 c); -void GfxPrint_PrintStringWithSize(GfxPrint* this, const void* buffer, size_t charSize, size_t charCount); -void GfxPrint_PrintString(GfxPrint* this, const char* str); -void* GfxPrint_Callback(void* arg, const char* str, size_t size); -void GfxPrint_Init(GfxPrint* this); -void GfxPrint_Destroy(GfxPrint* printer); -void GfxPrint_Open(GfxPrint* this, Gfx* dList); -Gfx* GfxPrint_Close(GfxPrint* this); -s32 GfxPrint_VPrintf(GfxPrint* this, const char* fmt, va_list args); -s32 GfxPrint_Printf(GfxPrint* this, const char* fmt, ...); - -#endif diff --git a/include/libu64/debug.h b/include/libu64/debug.h new file mode 100644 index 000000000..5bcae690c --- /dev/null +++ b/include/libu64/debug.h @@ -0,0 +1,7 @@ +#ifndef LIBU64_DEBUG_H +#define LIBU64_DEBUG_H + +void _dbg_hungup(const char* file, int lineNum); +void Reset(void); + +#endif diff --git a/include/libu64/gfxprint.h b/include/libu64/gfxprint.h new file mode 100644 index 000000000..78819151e --- /dev/null +++ b/include/libu64/gfxprint.h @@ -0,0 +1,52 @@ +#ifndef LIBU64_GFXPRINT_H +#define LIBU64_GFXPRINT_H + +#include "ultra64.h" + +#include "libc64/aprintf.h" +#include "PR/xstdio.h" + +#include "color.h" +#include "unk.h" + +#define GFXP_UNUSED "\x8E" +#define GFXP_UNUSED_CHAR 0x8E +#define GFXP_HIRAGANA "\x8D" +#define GFXP_HIRAGANA_CHAR 0x8D +#define GFXP_KATAKANA "\x8C" +#define GFXP_KATAKANA_CHAR 0x8C +#define GFXP_RAINBOW_ON "\x8B" +#define GFXP_RAINBOW_ON_CHAR 0x8B +#define GFXP_RAINBOW_OFF "\x8A" +#define GFXP_RAINBOW_OFF_CHAR 0x8A + +typedef struct GfxPrint { + /* 0x00 */ PrintCallback callback; + /* 0x04 */ Gfx* dList; + /* 0x08 */ u16 posX; + /* 0x0A */ u16 posY; + /* 0x0C */ u16 baseX; + /* 0x0E */ u8 baseY; + /* 0x0F */ u8 flags; + /* 0x10 */ Color_RGBA8_u32 color; + /* 0x14 */ UNK_TYPE1 unk_14[0x1C]; // unused +} GfxPrint; // size = 0x30 + +void GfxPrint_Setup(GfxPrint* this); +void GfxPrint_SetColor(GfxPrint* this, u32 r, u32 g, u32 b, u32 a); +void GfxPrint_SetPosPx(GfxPrint* this, s32 x, s32 y); +void GfxPrint_SetPos(GfxPrint* this, s32 x, s32 y); +void GfxPrint_SetBasePosPx(GfxPrint* this, s32 x, s32 y); +void GfxPrint_PrintCharImpl(GfxPrint* this, u8 c); +void GfxPrint_PrintChar(GfxPrint* this, u8 c); +void GfxPrint_PrintStringWithSize(GfxPrint* this, const void* buffer, size_t charSize, size_t charCount); +void GfxPrint_PrintString(GfxPrint* this, const char* str); +void* GfxPrint_Callback(void* arg, const char* str, size_t size); +void GfxPrint_Init(GfxPrint* this); +void GfxPrint_Destroy(GfxPrint* printer); +void GfxPrint_Open(GfxPrint* this, Gfx* dList); +Gfx* GfxPrint_Close(GfxPrint* this); +s32 GfxPrint_VPrintf(GfxPrint* this, const char* fmt, va_list args); +s32 GfxPrint_Printf(GfxPrint* this, const char* fmt, ...); + +#endif diff --git a/include/libu64/loadfragment.h b/include/libu64/loadfragment.h new file mode 100644 index 000000000..7a3e5a7d9 --- /dev/null +++ b/include/libu64/loadfragment.h @@ -0,0 +1,42 @@ +#ifndef LIBU64_LOADFRAGMENT_H +#define LIBU64_LOADFRAGMENT_H + +#include "PR/ultratypes.h" +#include "stdint.h" +#include "stddef.h" + +extern s32 gOverlayLogSeverity; + +#define RELOC_SECTION(reloc) ((reloc) >> 30) +#define RELOC_OFFSET(reloc) ((reloc) & 0xFFFFFF) +#define RELOC_TYPE_MASK(reloc) ((reloc) & 0x3F000000) +#define RELOC_TYPE_SHIFT 24 + +/* MIPS Relocation Types */ +#define R_MIPS_32 2 +#define R_MIPS_26 4 +#define R_MIPS_HI16 5 +#define R_MIPS_LO16 6 + +typedef enum { + /* 0 */ RELOC_SECTION_NULL, + /* 1 */ RELOC_SECTION_TEXT, + /* 2 */ RELOC_SECTION_DATA, + /* 3 */ RELOC_SECTION_RODATA, + /* 4 */ RELOC_SECTION_MAX +} RelocSectionId; + +typedef struct OverlayRelocationSection { + /* 0x00 */ size_t textSize; + /* 0x04 */ size_t dataSize; + /* 0x08 */ size_t rodataSize; + /* 0x0C */ size_t bssSize; + /* 0x10 */ u32 numRelocations; + /* 0x14 */ u32 relocations[1]; // array count is numRelocations +} OverlayRelocationSection; // size >= 0x18 + +// Fragment overlay load functions +size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr); +void* Overlay_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd); + +#endif diff --git a/include/libu64/pad.h b/include/libu64/pad.h new file mode 100644 index 000000000..db9e6e419 --- /dev/null +++ b/include/libu64/pad.h @@ -0,0 +1,17 @@ +#ifndef LIBU64_PAD_H +#define LIBU64_PAD_H + +#include "PR/os_cont.h" + + +typedef struct Input { + /* 0x00 */ OSContPad cur; + /* 0x06 */ OSContPad prev; + /* 0x0C */ OSContPad press; // X/Y store delta from last frame + /* 0x12 */ OSContPad rel; // X/Y store adjusted +} Input; // size = 0x18 + + +void PadUtils_UpdateRelXY(Input* input); + +#endif diff --git a/include/libu64/padsetup.h b/include/libu64/padsetup.h new file mode 100644 index 000000000..0aab4a729 --- /dev/null +++ b/include/libu64/padsetup.h @@ -0,0 +1,8 @@ +#ifndef LIBU64_PADSETUP_H +#define LIBU64_PADSETUP_H + +#include "ultra64.h" + +s32 PadSetup_Init(OSMesgQueue* mq, u8* outMask, OSContStatus* status); + +#endif diff --git a/include/libu64/stackcheck.h b/include/libu64/stackcheck.h new file mode 100644 index 000000000..7bf5b78fb --- /dev/null +++ b/include/libu64/stackcheck.h @@ -0,0 +1,26 @@ +#ifndef LIBU64_STACKCHECK_H +#define LIBU64_STACKCHECK_H + +#include "ultra64.h" + +typedef enum StackStatus { + /* 0 */ STACK_STATUS_OK, + /* 1 */ STACK_STATUS_WARNING, + /* 2 */ STACK_STATUS_OVERFLOW +} StackStatus; + +typedef struct StackEntry { + /* 0x00 */ struct StackEntry* next; + /* 0x04 */ struct StackEntry* prev; + /* 0x08 */ void* head; + /* 0x0C */ void* tail; + /* 0x10 */ u32 initValue; + /* 0x14 */ s32 minSpace; + /* 0x18 */ const char* name; +} StackEntry; // size = 0x1C + +void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 initValue, s32 minSpace, const char* name); +void StackCheck_Cleanup(StackEntry* entry); +u32 StackCheck_Check(StackEntry* entry); + +#endif diff --git a/include/libu64/system_heap.h b/include/libu64/system_heap.h new file mode 100644 index 000000000..7f8aa9d7e --- /dev/null +++ b/include/libu64/system_heap.h @@ -0,0 +1,11 @@ +#ifndef LIBU64_SYSTEM_HEAP_H +#define LIBU64_SYSTEM_HEAP_H + +#include "stddef.h" +#include "PR/ultratypes.h" + +void* SystemHeap_Malloc(size_t size); +void SystemHeap_Free(void* ptr); +void SystemHeap_Init(void* start, size_t size); + +#endif diff --git a/include/loadfragment.h b/include/loadfragment.h deleted file mode 100644 index 642db25d6..000000000 --- a/include/loadfragment.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef LOADFRAGMENT_H -#define LOADFRAGMENT_H - -#include "PR/ultratypes.h" -#include "stdint.h" -#include "stddef.h" - -extern s32 gOverlayLogSeverity; - -#define RELOC_SECTION(reloc) ((reloc) >> 30) -#define RELOC_OFFSET(reloc) ((reloc) & 0xFFFFFF) -#define RELOC_TYPE_MASK(reloc) ((reloc) & 0x3F000000) -#define RELOC_TYPE_SHIFT 24 - -/* MIPS Relocation Types */ -#define R_MIPS_32 2 -#define R_MIPS_26 4 -#define R_MIPS_HI16 5 -#define R_MIPS_LO16 6 - -typedef enum { - /* 0 */ RELOC_SECTION_NULL, - /* 1 */ RELOC_SECTION_TEXT, - /* 2 */ RELOC_SECTION_DATA, - /* 3 */ RELOC_SECTION_RODATA, - /* 4 */ RELOC_SECTION_MAX -} RelocSectionId; - -typedef struct OverlayRelocationSection { - /* 0x00 */ size_t textSize; - /* 0x04 */ size_t dataSize; - /* 0x08 */ size_t rodataSize; - /* 0x0C */ size_t bssSize; - /* 0x10 */ u32 numRelocations; - /* 0x14 */ u32 relocations[1]; // array count is numRelocations -} OverlayRelocationSection; // size >= 0x18 - -// Fragment overlay load functions -size_t Overlay_Load(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd, void* allocatedRamAddr); -void* Overlay_AllocateAndLoad(uintptr_t vromStart, uintptr_t vromEnd, void* vramStart, void* vramEnd); - -#endif diff --git a/include/padmgr.h b/include/padmgr.h index a012f1450..4f5dac3b3 100644 --- a/include/padmgr.h +++ b/include/padmgr.h @@ -6,7 +6,7 @@ #include "stdbool.h" #include "irqmgr.h" -#include "padutils.h" +#include "libu64/pad.h" typedef enum { /* 0 */ PADMGR_CONT_NONE, @@ -54,7 +54,6 @@ typedef struct PadMgr { // Initialization -s32 PadSetup_Init(OSMesgQueue* mq, u8* outMask, OSContStatus* status); void PadMgr_Init(OSMesgQueue* siEvtQ, IrqMgr* irqMgr, OSId threadId, OSPri pri, void* stack); // Fetching inputs diff --git a/include/padutils.h b/include/padutils.h deleted file mode 100644 index 77d3dc1cd..000000000 --- a/include/padutils.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef PADUTILS_H -#define PADUTILS_H - -#include "PR/os_cont.h" - - -typedef struct Input { - /* 0x00 */ OSContPad cur; - /* 0x06 */ OSContPad prev; - /* 0x0C */ OSContPad press; // X/Y store delta from last frame - /* 0x12 */ OSContPad rel; // X/Y store adjusted -} Input; // size = 0x18 - - -void PadUtils_UpdateRelXY(Input* input); - -#endif diff --git a/include/stackcheck.h b/include/stackcheck.h deleted file mode 100644 index aeb55df28..000000000 --- a/include/stackcheck.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef STACKCHECK_H -#define STACKCHECK_H - -#include "ultra64.h" - -typedef enum StackStatus { - /* 0 */ STACK_STATUS_OK, - /* 1 */ STACK_STATUS_WARNING, - /* 2 */ STACK_STATUS_OVERFLOW -} StackStatus; - -typedef struct StackEntry { - /* 0x00 */ struct StackEntry* next; - /* 0x04 */ struct StackEntry* prev; - /* 0x08 */ void* head; - /* 0x0C */ void* tail; - /* 0x10 */ u32 initValue; - /* 0x14 */ s32 minSpace; - /* 0x18 */ const char* name; -} StackEntry; // size = 0x1C - -void StackCheck_Init(StackEntry* entry, void* stackBottom, void* stackTop, u32 initValue, s32 minSpace, const char* name); -void StackCheck_Cleanup(StackEntry* entry); -u32 StackCheck_Check(StackEntry* entry); - -#endif diff --git a/include/system_heap.h b/include/system_heap.h deleted file mode 100644 index df572b82b..000000000 --- a/include/system_heap.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef SYSTEM_HEAP_H -#define SYSTEM_HEAP_H - -#include "stddef.h" -#include "PR/ultratypes.h" - -void* SystemHeap_Malloc(size_t size); -void SystemHeap_Free(void* ptr); -void SystemHeap_Init(void* start, size_t size); - -#endif diff --git a/include/z64.h b/include/z64.h index 30cf75ed4..9d85ddfab 100644 --- a/include/z64.h +++ b/include/z64.h @@ -16,13 +16,13 @@ #include "controller.h" #include "gfx.h" #include "gfx_setupdl.h" -#include "gfxprint.h" +#include "libu64/gfxprint.h" #include "ichain.h" #include "irqmgr.h" #include "main.h" #include "message_data_static.h" #include "padmgr.h" -#include "padutils.h" +#include "libu64/pad.h" #include "rand.h" #include "regs.h" #include "scheduler.h" diff --git a/include/z64actor.h b/include/z64actor.h index 0fe152ede..47f0c5506 100644 --- a/include/z64actor.h +++ b/include/z64actor.h @@ -4,7 +4,7 @@ #include "PR/ultratypes.h" #include "stdbool.h" #include "color.h" -#include "padutils.h" +#include "libu64/pad.h" #include "z64actor_dlftbls.h" #include "z64math.h" #include "z64animation.h" diff --git a/include/z64game.h b/include/z64game.h index c581ec1ac..21d314c7e 100644 --- a/include/z64game.h +++ b/include/z64game.h @@ -7,7 +7,7 @@ #include "stdint.h" #include "gamealloc.h" #include "padmgr.h" -#include "padutils.h" +#include "libu64/pad.h" #include "romfile.h" #include "tha.h" #include "unk.h" -- cgit v1.2.3