diff options
author | red031000 <rubenru09@aol.com> | 2020-05-24 15:14:47 +0100 |
---|---|---|
committer | red031000 <rubenru09@aol.com> | 2020-05-24 15:14:47 +0100 |
commit | c29ab952787c437b15a70a88dbb07f309a877574 (patch) | |
tree | e49187e81c3ad40578eea0cc54ceb1ec8a6d81ff /arm9/lib/src | |
parent | 77ebfad667ae038119b4413b87c99d0497f2d522 (diff) | |
parent | 8cfbe69596f9d3079d0098f30ea58debd5487271 (diff) |
Merge branch 'master' of https://github.com/martmists/pokediamond
Diffstat (limited to 'arm9/lib/src')
-rw-r--r-- | arm9/lib/src/FX_atan.c | 132 | ||||
-rw-r--r-- | arm9/lib/src/GX.c | 9 | ||||
-rw-r--r-- | arm9/lib/src/GX_load2d.c | 14 | ||||
-rw-r--r-- | arm9/lib/src/GX_load3d.c | 49 | ||||
-rw-r--r-- | arm9/lib/src/GX_state.c | 2 | ||||
-rw-r--r-- | arm9/lib/src/OS_arena.c | 5 | ||||
-rw-r--r-- | arm9/lib/src/OS_emulator.c | 2 | ||||
-rw-r--r-- | arm9/lib/src/OS_reset.c | 5 | ||||
-rw-r--r-- | arm9/lib/src/custom_allocator.c | 32 |
9 files changed, 220 insertions, 30 deletions
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.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..efab53ae 100644 --- a/arm9/lib/src/GX_load3d.c +++ b/arm9/lib/src/GX_load3d.c @@ -4,26 +4,51 @@ extern u32 GXi_DmaId; -extern u32 sTex; -extern u32 sTexLCDCBlk1; -extern u32 sTexLCDCBlk2; -extern u32 sSzTexBlk1; +static u32 sTexLCDCBlk1 = 0; +static u32 sSzTexBlk1 = 0; +static u32 sTexLCDCBlk2 = 0; +static s32 sTex = 0; -static const struct _TexStartAddrTable +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 struct _TexStartAddrTable sTexStartAddrTable[16]; +static s32 sTexPltt = 0; +static u32 sTexPlttLCDCBlk = 0; + +static const u16 sTexPlttStartAddrTable[8] = { + 0, + 0x06880000 >> 12, + 0x06890000 >> 12, + 0x06880000 >> 12, + 0x06894000 >> 12, + 0, + 0x06890000 >> 12, + 0x06880000 >> 12 +}; -extern u32 sTexPltt; -extern u32 sTexPlttLCDCBlk; -extern u16 sTexPlttStartAddrTable[8]; - -extern s32 sClrImg; -extern u32 sClrImgLCDCBlk; +static s32 sClrImg = 0; +static u32 sClrImgLCDCBlk = 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; 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); 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; +} |