diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2020-05-07 10:04:35 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2020-05-07 10:04:35 -0400 |
commit | 1fe92db5c3fef98e7f1d51f73b65ad83b6178734 (patch) | |
tree | f640337a70ca7706f34286683d896861d3773ea6 /arm9/lib/src | |
parent | a222e198bbdaef7de3931299adc1166dad205428 (diff) | |
parent | 7bd2d6636ba5a34fb0ae984f377f690d51ba97f0 (diff) |
Merge branch 'master' of github.com:martmists/pokediamond into pikalax_work
Diffstat (limited to 'arm9/lib/src')
-rw-r--r-- | arm9/lib/src/FX_cp.c | 48 | ||||
-rw-r--r-- | arm9/lib/src/FX_vec.c | 44 | ||||
-rw-r--r-- | arm9/lib/src/OS_init.c | 1 | ||||
-rw-r--r-- | arm9/lib/src/OS_reset.c | 63 | ||||
-rw-r--r-- | arm9/lib/src/OS_system.c | 1 |
5 files changed, 109 insertions, 48 deletions
diff --git a/arm9/lib/src/FX_cp.c b/arm9/lib/src/FX_cp.c index 2ca9d720..08443dc8 100644 --- a/arm9/lib/src/FX_cp.c +++ b/arm9/lib/src/FX_cp.c @@ -16,8 +16,8 @@ ARM_FUNC fx32 FX_Inv(fx32 x){ ARM_FUNC fx32 FX_Sqrt(fx32 x){ if (x > 0) { - SETREG16(HW_REG_SQRTCNT, 0x1); - SETREG64(HW_REG_SQRT_PARAM, (fx64)x << 32); + reg_CP_SQRTCNT = 0x1; + reg_CP_SQRT_PARAM = (fx64)x << 32; return FX_GetSqrtResult(); } else @@ -27,44 +27,44 @@ ARM_FUNC fx32 FX_Sqrt(fx32 x){ } ARM_FUNC fx64c FX_GetDivResultFx64c(){ - while (READREG16(HW_REG_DIVCNT) & 0x8000); - return READREG64(HW_REG_DIV_RESULT); + while (reg_CP_DIVCNT & 0x8000); + return reg_CP_DIV_RESULT; } ARM_FUNC fx32 FX_GetDivResult(){ - while (READREG16(HW_REG_DIVCNT) & 0x8000); - return (READREG64(HW_REG_DIV_RESULT) + (1 << (0x14 - 1))) >> 0x14; + while (reg_CP_DIVCNT & 0x8000); + return (reg_CP_DIV_RESULT + (1 << (0x14 - 1))) >> 0x14; } ARM_FUNC void FX_InvAsync(fx32 x){ - SETREG16(HW_REG_DIVCNT, 0x1); - SETREG64(HW_REG_DIV_NUMER, (fx64)0x00001000 << 32); - SETREG64(HW_REG_DIV_DENOM, (u32)x); + reg_CP_DIVCNT = 0x1; + reg_CP_DIV_NUMER = (fx64)0x00001000 << 32; + reg_CP_DIV_DENOM = (u32)x; } ARM_FUNC fx32 FX_GetSqrtResult(){ - while (READREG16(HW_REG_SQRTCNT) & 0x8000); - return (READREG32(HW_REG_SQRT_RESULT) + (1 << (0xA - 1))) >> 0xA; + while (reg_CP_SQRTCNT & 0x8000); + return (reg_CP_SQRT_RESULT + (1 << (0xA - 1))) >> 0xA; } ARM_FUNC void FX_DivAsync(fx32 numerator, fx32 denominator){ - SETREG16(HW_REG_DIVCNT, 0x1); - SETREG64(HW_REG_DIV_NUMER, (fx64)numerator << 32); - SETREG64(HW_REG_DIV_DENOM, (u32)denominator); + reg_CP_DIVCNT = 0x1; + reg_CP_DIV_NUMER = (fx64)numerator << 32; + reg_CP_DIV_DENOM = (u32)denominator; } ARM_FUNC fx32 FX_DivS32(fx32 numerator, fx32 denominator){ - SETREG16(HW_REG_DIVCNT, 0x0); - SETREG32(HW_REG_DIV_NUMER, (u32)numerator); //32bit write for some reason - SETREG64(HW_REG_DIV_DENOM, (u32)denominator); - while (READREG16(HW_REG_DIVCNT) & 0x8000); - return READREG32(HW_REG_DIV_RESULT); + reg_CP_DIVCNT = 0x0; + *(REGType32 *)REG_DIV_NUMER_ADDR = (u32)numerator; //32bit write for some reason + reg_CP_DIV_DENOM = (u32)denominator; + while (reg_CP_DIVCNT & 0x8000); + return *(REGType32 *)REG_DIV_RESULT_ADDR; } ARM_FUNC fx32 FX_ModS32(fx32 num, fx32 mod){ - SETREG16(HW_REG_DIVCNT, 0x0); - SETREG32(HW_REG_DIV_NUMER, (u32)num); //32bit write for some reason - SETREG64(HW_REG_DIV_DENOM, (u32)mod); - while (READREG16(HW_REG_DIVCNT) & 0x8000); - return READREG32(HW_REG_DIVREM_RESULT); + reg_CP_DIVCNT = 0x0; + *(REGType32 *)REG_DIV_NUMER_ADDR = (u32)num; //32bit write for some reason + reg_CP_DIV_DENOM = (u32)mod; + while (reg_CP_DIVCNT & 0x8000); + return *(REGType32 *)REG_DIVREM_RESULT_ADDR; } diff --git a/arm9/lib/src/FX_vec.c b/arm9/lib/src/FX_vec.c index af36fe89..95805f33 100644 --- a/arm9/lib/src/FX_vec.c +++ b/arm9/lib/src/FX_vec.c @@ -55,10 +55,10 @@ ARM_FUNC fx32 VEC_Mag(struct Vecx32 *a){ fx64 l2 = (fx64)a->x * a->x; l2 += (fx64)a->y * a->y; l2 += (fx64)a->z * a->z; - SETREG16(HW_REG_SQRTCNT, 0x1); - SETREG64(HW_REG_SQRT_PARAM, l2 * 4); - while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for coprocessor to finish - return ((fx32)READREG32(HW_REG_SQRT_RESULT) + 1) >> 1; + reg_CP_SQRTCNT = 0x1; + reg_CP_SQRT_PARAM = l2 * 4; + while (reg_CP_SQRTCNT & 0x8000); //wait for coprocessor to finish + return ((fx32)reg_CP_SQRT_RESULT + 1) >> 1; } ARM_FUNC void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ @@ -66,15 +66,15 @@ ARM_FUNC void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){ l2 += (fx64)a->y * a->y; l2 += (fx64)a->z * a->z; //1/sqrt(l) is computed by calculating sqrt(l)*(1/l) - SETREG16(HW_REG_DIVCNT, 0x2); - SETREG64(HW_REG_DIV_NUMER, 0x0100000000000000); - SETREG64(HW_REG_DIV_DENOM, l2); - SETREG16(HW_REG_SQRTCNT, 0x1); - SETREG64(HW_REG_SQRT_PARAM, l2 * 4); - while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for sqrt to finish - fx32 sqrtresult = READREG32(HW_REG_SQRT_RESULT); - while (READREG16(HW_REG_DIVCNT) & 0x8000); //wait for division to finish - l2 = READREG64(HW_REG_DIV_RESULT); + reg_CP_DIVCNT = 0x2; + reg_CP_DIV_NUMER = 0x0100000000000000; + reg_CP_DIV_DENOM = l2; + reg_CP_SQRTCNT = 0x1; + reg_CP_SQRT_PARAM = l2 * 4; + while (reg_CP_SQRTCNT & 0x8000); //wait for sqrt to finish + fx32 sqrtresult = reg_CP_SQRT_RESULT; + while (reg_CP_DIVCNT & 0x8000); //wait for division to finish + l2 = reg_CP_DIV_RESULT; l2 = sqrtresult * l2; dst->x = (l2 * a->x + (1LL << (0x2D - 1))) >> 0x2D; dst->y = (l2 * a->y + (1LL << (0x2D - 1))) >> 0x2D; @@ -86,15 +86,15 @@ ARM_FUNC void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){ l2 += a->y * a->y; l2 += a->z * a->z; //1/sqrt(l) is computed by calculating sqrt(l)*(1/l) - SETREG16(HW_REG_DIVCNT, 0x2); - SETREG64(HW_REG_DIV_NUMER, 0x0100000000000000); - SETREG64(HW_REG_DIV_DENOM, l2); - SETREG16(HW_REG_SQRTCNT, 0x1); - SETREG64(HW_REG_SQRT_PARAM, l2 * 4); - while (READREG16(HW_REG_SQRTCNT) & 0x8000); //wait for sqrt to finish - fx32 sqrtresult = READREG32(HW_REG_SQRT_RESULT); - while (READREG16(HW_REG_DIVCNT) & 0x8000); //wait for division to finish - l2 = READREG64(HW_REG_DIV_RESULT); + reg_CP_DIVCNT = 0x2; + reg_CP_DIV_NUMER = 0x0100000000000000; + reg_CP_DIV_DENOM = l2; + reg_CP_SQRTCNT = 0x1; + reg_CP_SQRT_PARAM = l2 * 4; + while (reg_CP_SQRTCNT & 0x8000); //wait for sqrt to finish + fx32 sqrtresult = reg_CP_SQRT_RESULT; + while (reg_CP_DIVCNT & 0x8000); //wait for division to finish + l2 = reg_CP_DIV_RESULT; l2 = sqrtresult * l2; dst->x = (l2 * a->x + (1LL << (0x2D - 1))) >> 0x2D; dst->y = (l2 * a->y + (1LL << (0x2D - 1))) >> 0x2D; diff --git a/arm9/lib/src/OS_init.c b/arm9/lib/src/OS_init.c index 90b01ffa..e2658421 100644 --- a/arm9/lib/src/OS_init.c +++ b/arm9/lib/src/OS_init.c @@ -14,7 +14,6 @@ extern void MI_Init(); extern void OS_InitVAlarm(); extern void OSi_InitVramExclusive(); extern void OS_InitThread(); -extern void OS_InitReset(); extern void CTRDG_Init(); extern void CARD_Init(); extern void PM_Init(); diff --git a/arm9/lib/src/OS_reset.c b/arm9/lib/src/OS_reset.c new file mode 100644 index 00000000..b12703da --- /dev/null +++ b/arm9/lib/src/OS_reset.c @@ -0,0 +1,63 @@ +// +// Created by red031000 on 2020-05-06. +// + +#include "function_target.h" +#include "OS_reset.h" +#include "MB_mb.h" + +extern u16 OSi_IsInitReset; +extern vu16 OSi_IsResetOccurred; +extern void PXI_Init(); +extern u32 PXI_IsCallbackReady(u32 param1, u32 param2); +extern void PXI_SetFifoRecvCallback(u32 param1, void* callback); +extern void OS_Terminate(); +extern u32 PXI_SendWordByFifo(u32 param1, u32 data, u32 param2); +extern void CARD_LockRom(u16 lockId); +extern u32 OS_GetLockID(); +extern void MI_StopDma(u32 dma); +extern void OS_SetIrqMask(u32 mask); +extern void OS_ResetRequestIrqMask(u32 mask); +extern void OSi_DoResetSystem(); + +ARM_FUNC void OS_InitReset() { + if (OSi_IsInitReset) { + return; + } + OSi_IsInitReset = TRUE; + PXI_Init(); + while (!PXI_IsCallbackReady(PXI_FIFO_TAG_OS, PXI_PROC_ARM7)) { } + + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_OS, OSi_CommonCallback); +} + +ARM_FUNC static void OSi_CommonCallback(PXIFifoTag tag, u32 data, BOOL err) { +#pragma unused(tag, err) //needed because otherwise -W all errors + u16 command = (u16)((data & OS_PXI_COMMAND_MASK) >> OS_PXI_COMMAND_SHIFT); + if (command == OS_PXI_COMMAND_RESET) + { + OSi_IsResetOccurred = TRUE; + return; + } + OS_Terminate(); +} + +ARM_FUNC static void OSi_SendToPxi(u16 data) { + while (PXI_SendWordByFifo(PXI_FIFO_TAG_OS, (u32)data << 0x8, FALSE)) {} +} + +ARM_FUNC void OS_ResetSystem(u32 parameter) { + if (MB_IsMultiBootChild()) { + OS_Terminate(); + } + CARD_LockRom((u16)OS_GetLockID()); + MI_StopDma(0); + MI_StopDma(1); + MI_StopDma(2); + MI_StopDma(3); + OS_SetIrqMask(0x40000); + OS_ResetRequestIrqMask((u32)~0); + *(u32 *)HW_RESET_PARAMETER_BUF = parameter; + OSi_SendToPxi(OS_PXI_COMMAND_RESET); + OSi_DoResetSystem(); //oh boy this is in itcm, that's gonna be fun to deal with Kappa +} diff --git a/arm9/lib/src/OS_system.c b/arm9/lib/src/OS_system.c index c2b08681..e5dfcb47 100644 --- a/arm9/lib/src/OS_system.c +++ b/arm9/lib/src/OS_system.c @@ -2,7 +2,6 @@ // Created by mart on 4/23/20. // -#include "function_target.h" #include "OS_system.h" ARM_FUNC asm OSIntrMode OS_EnableInterrupts() { |