From 716572be08ec797a4d23d6c3b86f41ba66678651 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Thu, 21 May 2020 14:22:44 -0400 Subject: Some cleanup --- arm9/lib/src/custom_allocator.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 arm9/lib/src/custom_allocator.c (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/custom_allocator.c b/arm9/lib/src/custom_allocator.c new file mode 100644 index 00000000..869901ce --- /dev/null +++ b/arm9/lib/src/custom_allocator.c @@ -0,0 +1,32 @@ +#include "global.h" + +typedef void * (* AllocFunc)(u32 size); +typedef void (* FreeFunc)(void * ptr); + +static FreeFunc sDestructor; +static AllocFunc sAllocator; + +// Custom allocator +ARM_FUNC void* CallCustomAllocator(u32 size) +{ + if (sAllocator != NULL) + return sAllocator(size); + else + return OS_AllocFromHeap(OS_ARENA_MAIN, -1, size); +} + +// Custom destructor +ARM_FUNC void CallCustomDestructor(void * ptr) +{ + if (sDestructor != NULL) + sDestructor(ptr); + else + OS_FreeToHeap(OS_ARENA_MAIN, -1, ptr); +} + +// Custom alloc/free setter +ARM_FUNC void SetCustomAllocatorAndDestructor(AllocFunc allocator, FreeFunc destructor) +{ + sAllocator = allocator; + sDestructor = destructor; +} -- cgit v1.2.3 From 09eb26569c0c5e9b733a3c4f33bcf876e48dc0be Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 22 May 2020 16:25:42 -0400 Subject: Distribute bss_2 to code files --- arm9/lib/src/GX.c | 9 +++++---- arm9/lib/src/GX_load2d.c | 14 +++++++------- arm9/lib/src/GX_load3d.c | 28 +++++++++++++--------------- arm9/lib/src/GX_state.c | 2 +- arm9/lib/src/OS_arena.c | 5 +++-- arm9/lib/src/OS_emulator.c | 2 +- 6 files changed, 30 insertions(+), 30 deletions(-) (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/GX.c b/arm9/lib/src/GX.c index 28c3cc01..b1d62145 100644 --- a/arm9/lib/src/GX.c +++ b/arm9/lib/src/GX.c @@ -2,10 +2,11 @@ #include "main.h" #include "GX.h" -extern u16 GXi_VRamLockId; -extern u16 sDispMode; -extern u32 GXi_DmaId; -extern u16 sIsDispOn; +u32 GXi_DmaId = 3; +vu16 GXi_VRamLockId = 0; + +static u16 sDispMode = 0; +static u16 sIsDispOn = TRUE; ARM_FUNC void GX_Init(){ reg_GX_POWCNT |= 0x8000; diff --git a/arm9/lib/src/GX_load2d.c b/arm9/lib/src/GX_load2d.c index d4def461..2f7c0242 100644 --- a/arm9/lib/src/GX_load2d.c +++ b/arm9/lib/src/GX_load2d.c @@ -4,13 +4,13 @@ extern u32 GXi_DmaId; -extern s32 sSubOBJExtPltt; -extern s32 sBGExtPltt; -extern u32 sBGExtPlttLCDCBlk; -extern u32 sBGExtPlttLCDCOffset; -extern s32 sOBJExtPltt; -extern u32 sOBJExtPlttLCDCBlk; -extern s32 sSubBGExtPltt; +static s32 sBGExtPltt = 0; +static u32 sBGExtPlttLCDCBlk = 0; +static u32 sBGExtPlttLCDCOffset = 0; +static s32 sOBJExtPltt = 0; +static u32 sOBJExtPlttLCDCBlk = 0; +static s32 sSubBGExtPltt = 0; +static s32 sSubOBJExtPltt = 0; static inline void *_GX_OBJ_PTR(){ diff --git a/arm9/lib/src/GX_load3d.c b/arm9/lib/src/GX_load3d.c index 5aa15581..a407eb59 100644 --- a/arm9/lib/src/GX_load3d.c +++ b/arm9/lib/src/GX_load3d.c @@ -4,26 +4,24 @@ extern u32 GXi_DmaId; -extern u32 sTex; -extern u32 sTexLCDCBlk1; -extern u32 sTexLCDCBlk2; -extern u32 sSzTexBlk1; - -static const struct _TexStartAddrTable +struct _TexStartAddrTable { u16 blk1; // 12 bit shift u16 blk2; // 12 bit shift u16 szBlk1; // 12 bit shift }; -extern struct _TexStartAddrTable sTexStartAddrTable[16]; - - -extern u32 sTexPltt; -extern u32 sTexPlttLCDCBlk; -extern u16 sTexPlttStartAddrTable[8]; - -extern s32 sClrImg; -extern u32 sClrImgLCDCBlk; +extern const struct _TexStartAddrTable sTexStartAddrTable[16]; + +extern const u16 sTexPlttStartAddrTable[8]; + +static u32 sTexLCDCBlk2 = 0; +static s32 sTex = 0; +static u32 sClrImgLCDCBlk = 0; +static s32 sTexPltt = 0; +static u32 sTexPlttLCDCBlk = 0; +static u32 sTexLCDCBlk1 = 0; +static s32 sClrImg = 0; +static u32 sSzTexBlk1 = 0; ARM_FUNC void GX_BeginLoadTex(){ u32 temp = GX_ResetBankForTex(); diff --git a/arm9/lib/src/GX_state.c b/arm9/lib/src/GX_state.c index 3ca3b266..6b216f39 100644 --- a/arm9/lib/src/GX_state.c +++ b/arm9/lib/src/GX_state.c @@ -2,7 +2,7 @@ #include "main.h" #include "GX.h" -extern struct GX_State gGXState; +struct GX_State gGXState; ARM_FUNC void GX_InitGXState(){ gGXState.lcdc = 0x0; diff --git a/arm9/lib/src/OS_arena.c b/arm9/lib/src/OS_arena.c index ae05b49c..31796771 100644 --- a/arm9/lib/src/OS_arena.c +++ b/arm9/lib/src/OS_arena.c @@ -7,8 +7,9 @@ #include "OS_protectionRegion.h" #include "OS_emulator.h" -extern BOOL OSi_MainExArenaEnabled; -extern BOOL OSi_Initialized; // TODO: located at 0x021d36f0 +static BOOL OSi_Initialized = FALSE; +static BOOL OSi_MainExArenaEnabled = FALSE; + void SDK_MAIN_ARENA_LO(); // TODO: technically this should be defined in the lcf extern void SDK_SECTION_ARENA_EX_START(); // TODO: technically this should be defined in the lcf extern void SDK_SECTION_ARENA_ITCM_START(); // TODO: technically this should be defined in the lcf diff --git a/arm9/lib/src/OS_emulator.c b/arm9/lib/src/OS_emulator.c index 1be0e163..c138b2bc 100644 --- a/arm9/lib/src/OS_emulator.c +++ b/arm9/lib/src/OS_emulator.c @@ -5,7 +5,7 @@ #include "OS_emulator.h" #include "function_target.h" -extern u32 OSi_ConsoleTypeCache; //todo fix bss +u32 OSi_ConsoleTypeCache = -1u; //todo fix bss ARM_FUNC BOOL OS_IsRunOnEmulator() { return FALSE; -- cgit v1.2.3 From d382442e45e5aaf4a8c45e40c13f5328e79349d7 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 22 May 2020 16:36:02 -0400 Subject: Distribute bss_3.s among code files --- arm9/lib/src/OS_reset.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/OS_reset.c b/arm9/lib/src/OS_reset.c index d4254ce3..02498962 100644 --- a/arm9/lib/src/OS_reset.c +++ b/arm9/lib/src/OS_reset.c @@ -8,8 +8,9 @@ #include "OS_terminate_proc.h" #include "OS_interrupt.h" -extern u16 OSi_IsInitReset; -extern vu16 OSi_IsResetOccurred; +static u16 OSi_IsInitReset = 0; +vu16 OSi_IsResetOccurred = 0; + extern void PXI_Init(); extern u32 PXI_IsCallbackReady(u32 param1, u32 param2); extern void PXI_SetFifoRecvCallback(u32 param1, void* callback); -- cgit v1.2.3 From d1063c084aeac60c98b40c3ef1ea36c9bfbd273a Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 23 May 2020 16:42:42 -0400 Subject: Finish distributing rom2_2.s --- arm9/lib/src/FX_atan.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++- arm9/lib/src/GX_load3d.c | 45 ++++++++++++---- 2 files changed, 167 insertions(+), 10 deletions(-) (limited to 'arm9/lib/src') diff --git a/arm9/lib/src/FX_atan.c b/arm9/lib/src/FX_atan.c index 979895a8..9a936fa0 100644 --- a/arm9/lib/src/FX_atan.c +++ b/arm9/lib/src/FX_atan.c @@ -2,7 +2,137 @@ #include "main.h" #include "fx.h" -extern fx16 FX_AtanTable_[]; +const fx16 FX_AtanTable_[] = { + FX16_CONST(0.0), + FX16_CONST(0.019775390625), + FX16_CONST(0.039794921875), + FX16_CONST(0.0595703125), + FX16_CONST(0.07958984375), + FX16_CONST(0.099365234375), + FX16_CONST(0.119384765625), + FX16_CONST(0.13916015625), + FX16_CONST(0.158935546875), + FX16_CONST(0.1787109375), + FX16_CONST(0.198486328125), + FX16_CONST(0.21826171875), + FX16_CONST(0.238037109375), + FX16_CONST(0.2578125), + FX16_CONST(0.27734375), + FX16_CONST(0.297119140625), + FX16_CONST(0.316650390625), + FX16_CONST(0.336181640625), + FX16_CONST(0.355712890625), + FX16_CONST(0.375244140625), + FX16_CONST(0.394775390625), + FX16_CONST(0.4140625), + FX16_CONST(0.433349609375), + FX16_CONST(0.45263671875), + FX16_CONST(0.471923828125), + FX16_CONST(0.4912109375), + FX16_CONST(0.51025390625), + FX16_CONST(0.529296875), + FX16_CONST(0.54833984375), + FX16_CONST(0.5673828125), + FX16_CONST(0.586181640625), + FX16_CONST(0.60498046875), + FX16_CONST(0.623779296875), + FX16_CONST(0.642578125), + FX16_CONST(0.6611328125), + FX16_CONST(0.6796875), + FX16_CONST(0.6982421875), + FX16_CONST(0.716552734375), + FX16_CONST(0.73486328125), + FX16_CONST(0.753173828125), + FX16_CONST(0.771240234375), + FX16_CONST(0.789306640625), + FX16_CONST(0.807373046875), + FX16_CONST(0.8251953125), + FX16_CONST(0.843017578125), + FX16_CONST(0.86083984375), + FX16_CONST(0.878662109375), + FX16_CONST(0.89599609375), + FX16_CONST(0.91357421875), + FX16_CONST(0.930908203125), + FX16_CONST(0.9482421875), + FX16_CONST(0.965576171875), + FX16_CONST(0.982666015625), + FX16_CONST(0.999755859375), + FX16_CONST(1.0166015625), + FX16_CONST(1.033447265625), + FX16_CONST(1.05029296875), + FX16_CONST(1.06689453125), + FX16_CONST(1.08349609375), + FX16_CONST(1.099853515625), + FX16_CONST(1.1162109375), + FX16_CONST(1.132568359375), + FX16_CONST(1.148681640625), + FX16_CONST(1.164794921875), + FX16_CONST(1.1806640625), + FX16_CONST(1.196533203125), + FX16_CONST(1.21240234375), + FX16_CONST(1.22802734375), + FX16_CONST(1.24365234375), + FX16_CONST(1.259033203125), + FX16_CONST(1.2744140625), + FX16_CONST(1.28955078125), + FX16_CONST(1.3046875), + FX16_CONST(1.31982421875), + FX16_CONST(1.334716796875), + FX16_CONST(1.349609375), + FX16_CONST(1.364501953125), + FX16_CONST(1.379150390625), + FX16_CONST(1.3935546875), + FX16_CONST(1.408203125), + FX16_CONST(1.42236328125), + FX16_CONST(1.436767578125), + FX16_CONST(1.450927734375), + FX16_CONST(1.46484375), + FX16_CONST(1.47900390625), + FX16_CONST(1.49267578125), + FX16_CONST(1.506591796875), + FX16_CONST(1.520263671875), + FX16_CONST(1.53369140625), + FX16_CONST(1.547119140625), + FX16_CONST(1.560546875), + FX16_CONST(1.57373046875), + FX16_CONST(1.5869140625), + FX16_CONST(1.60009765625), + FX16_CONST(1.613037109375), + FX16_CONST(1.6259765625), + FX16_CONST(1.638671875), + FX16_CONST(1.6513671875), + FX16_CONST(1.663818359375), + FX16_CONST(1.676513671875), + FX16_CONST(1.688720703125), + FX16_CONST(1.701171875), + FX16_CONST(1.71337890625), + FX16_CONST(1.7255859375), + FX16_CONST(1.737548828125), + FX16_CONST(1.74951171875), + FX16_CONST(1.76123046875), + FX16_CONST(1.77294921875), + FX16_CONST(1.78466796875), + FX16_CONST(1.79638671875), + FX16_CONST(1.807861328125), + FX16_CONST(1.819091796875), + FX16_CONST(1.83056640625), + FX16_CONST(1.841796875), + FX16_CONST(1.852783203125), + FX16_CONST(1.864013671875), + FX16_CONST(1.874755859375), + FX16_CONST(1.8857421875), + FX16_CONST(1.896484375), + FX16_CONST(1.9072265625), + FX16_CONST(1.91796875), + FX16_CONST(1.928466796875), + FX16_CONST(1.93896484375), + FX16_CONST(1.94921875), + FX16_CONST(1.95947265625), + FX16_CONST(1.9697265625), + FX16_CONST(1.97998046875), + FX16_CONST(1.989990234375), + FX16_CONST(2.0), +}; ARM_FUNC u16 FX_Atan(fx32 x){ if (x >= 0) diff --git a/arm9/lib/src/GX_load3d.c b/arm9/lib/src/GX_load3d.c index a407eb59..efab53ae 100644 --- a/arm9/lib/src/GX_load3d.c +++ b/arm9/lib/src/GX_load3d.c @@ -4,24 +4,51 @@ extern u32 GXi_DmaId; -struct _TexStartAddrTable +static u32 sTexLCDCBlk1 = 0; +static u32 sSzTexBlk1 = 0; +static u32 sTexLCDCBlk2 = 0; +static s32 sTex = 0; + +static const struct { u16 blk1; // 12 bit shift u16 blk2; // 12 bit shift u16 szBlk1; // 12 bit shift +} sTexStartAddrTable[16] = { + {0, 0, 0}, + {0x06800000 >> 12, 0, 0}, + {0x06820000 >> 12, 0, 0}, + {0x06800000 >> 12, 0, 0}, + {0x06840000 >> 12, 0, 0}, + {0x06800000 >> 12, 0x06840000 >> 12, 0x00020000 >> 12}, + {0x06820000 >> 12, 0, 0}, + {0x06800000 >> 12, 0, 0}, + {0x06860000 >> 12, 0, 0}, + {0x06800000 >> 12, 0x06860000 >> 12, 0x00020000 >> 12}, + {0x06820000 >> 12, 0x06860000 >> 12, 0x00020000 >> 12}, + {0x06800000 >> 12, 0x06860000 >> 12, 0x00040000 >> 12}, + {0x06840000 >> 12, 0, 0}, + {0x06800000 >> 12, 0x06840000 >> 12, 0x00020000 >> 12}, + {0x06820000 >> 12, 0, 0}, + {0x06800000 >> 12, 0, 0}, }; -extern const struct _TexStartAddrTable sTexStartAddrTable[16]; - -extern const u16 sTexPlttStartAddrTable[8]; -static u32 sTexLCDCBlk2 = 0; -static s32 sTex = 0; -static u32 sClrImgLCDCBlk = 0; static s32 sTexPltt = 0; static u32 sTexPlttLCDCBlk = 0; -static u32 sTexLCDCBlk1 = 0; + +static const u16 sTexPlttStartAddrTable[8] = { + 0, + 0x06880000 >> 12, + 0x06890000 >> 12, + 0x06880000 >> 12, + 0x06894000 >> 12, + 0, + 0x06890000 >> 12, + 0x06880000 >> 12 +}; + static s32 sClrImg = 0; -static u32 sSzTexBlk1 = 0; +static u32 sClrImgLCDCBlk = 0; ARM_FUNC void GX_BeginLoadTex(){ u32 temp = GX_ResetBankForTex(); -- cgit v1.2.3