mirror of
https://github.com/pret/pokediamond.git
synced 2026-10-01 12:56:48 -05:00
@@ -1,152 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "global.inc"
|
||||
|
||||
.section .bss
|
||||
|
||||
.global _03807920
|
||||
_03807920: ;0x03807920
|
||||
.space 0x03807924 - 0x03807920
|
||||
|
||||
.global OSi_NeedResetTimer
|
||||
OSi_NeedResetTimer: ;0x03807924
|
||||
.space 0x03807928 - 0x03807924
|
||||
|
||||
.global OSi_TickCounter
|
||||
OSi_TickCounter: ;0x03807928
|
||||
.space 0x03807930 - 0x03807928
|
||||
|
||||
.section .text
|
||||
|
||||
arm_func_start OS_GetTick
|
||||
OS_GetTick: ; 0x037FA364
|
||||
stmfd sp!, {lr}
|
||||
sub sp, sp, #12
|
||||
bl OS_DisableInterrupts
|
||||
ldr r1, _037FA404 ; =0x04000100
|
||||
ldrh r1, [r1]
|
||||
strh r1, [sp]
|
||||
ldr r1, _037FA408 ; =OSi_TickCounter
|
||||
ldr ip, [r1]
|
||||
ldr r3, [r1, #4]
|
||||
ldr r2, _037FA40C ; =0x0000FFFF
|
||||
mvn r1, #0
|
||||
and r2, r3, r2
|
||||
and r1, ip, r1
|
||||
str r1, [sp, #4]
|
||||
str r2, [sp, #8]
|
||||
ldr r1, _037FA410 ; =0x04000214
|
||||
ldr r1, [r1]
|
||||
ands r1, r1, #8
|
||||
beq _037FA3D8
|
||||
ldrh r1, [sp]
|
||||
ands r1, r1, #32768 ; 0x8000
|
||||
bne _037FA3D8
|
||||
ldr r3, [sp, #4]
|
||||
ldr r2, [sp, #8]
|
||||
mov r1, #1
|
||||
adds r3, r3, r1
|
||||
adc r1, r2, #0
|
||||
str r3, [sp, #4]
|
||||
str r1, [sp, #8]
|
||||
_037FA3D8:
|
||||
bl OS_RestoreInterrupts
|
||||
ldr r2, [sp, #4]
|
||||
ldr r0, [sp, #8]
|
||||
mov r1, r0, lsl #16
|
||||
orr r1, r1, r2, lsr #16
|
||||
ldrh r0, [sp]
|
||||
orr r1, r1, r0, asr #31
|
||||
orr r0, r0, r2, lsl #16
|
||||
add sp, sp, #12
|
||||
ldmia sp!, {lr}
|
||||
bx lr
|
||||
_037FA404: .word 0x04000100
|
||||
_037FA408: .word OSi_TickCounter
|
||||
_037FA40C: .word 0x0000FFFF
|
||||
_037FA410: .word 0x04000214
|
||||
|
||||
arm_func_start OSi_CountUpTick
|
||||
OSi_CountUpTick: ; 0x037FA414
|
||||
stmfd sp!, {lr}
|
||||
sub sp, sp, #4
|
||||
ldr r1, _037FA488 ; =OSi_TickCounter
|
||||
ldr ip, [r1]
|
||||
ldr r2, [r1, #4]
|
||||
mov r3, #0
|
||||
mov r0, #1
|
||||
adds ip, ip, r0
|
||||
adc r0, r2, #0
|
||||
str ip, [r1]
|
||||
str r0, [r1, #4]
|
||||
ldr r0, _037FA48C ; =OSi_NeedResetTimer
|
||||
ldr r1, [r0]
|
||||
cmp r1, #0
|
||||
beq _037FA46C
|
||||
ldr r2, _037FA490 ; =0x04000102
|
||||
strh r3, [r2]
|
||||
ldr r1, _037FA494 ; =0x04000100
|
||||
strh r3, [r1]
|
||||
mov r1, #193 ; 0xc1
|
||||
strh r1, [r2]
|
||||
str r3, [r0]
|
||||
_037FA46C:
|
||||
mov r0, #0
|
||||
ldr r1, _037FA498 ; =OSi_CountUpTick
|
||||
mov r2, r0
|
||||
bl OSi_EnterTimerCallback
|
||||
add sp, sp, #4
|
||||
ldmia sp!, {lr}
|
||||
bx lr
|
||||
_037FA488: .word OSi_TickCounter
|
||||
_037FA48C: .word OSi_NeedResetTimer
|
||||
_037FA490: .word 0x04000102
|
||||
_037FA494: .word 0x04000100
|
||||
_037FA498: .word OSi_CountUpTick
|
||||
|
||||
arm_func_start OS_IsTickAvailable
|
||||
OS_IsTickAvailable: ; 0x037FA49C
|
||||
ldr r0, _037FA4A8 ; =_03807920
|
||||
ldrh r0, [r0]
|
||||
bx lr
|
||||
_037FA4A8: .word _03807920
|
||||
|
||||
arm_func_start OS_InitTick
|
||||
OS_InitTick: ; 0x037FA4AC
|
||||
stmfd sp!, {lr}
|
||||
sub sp, sp, #4
|
||||
ldr r0, _037FA528 ; =_03807920
|
||||
ldrh r1, [r0]
|
||||
cmp r1, #0
|
||||
bne _037FA51C
|
||||
mov r1, #1
|
||||
strh r1, [r0]
|
||||
mov r0, #0
|
||||
bl OSi_SetTimerReserved
|
||||
mov r2, #0
|
||||
ldr r0, _037FA52C ; =OSi_TickCounter
|
||||
str r2, [r0]
|
||||
str r2, [r0, #4]
|
||||
ldr r1, _037FA530 ; =0x04000102
|
||||
strh r2, [r1]
|
||||
ldr r0, _037FA534 ; =0x04000100
|
||||
strh r2, [r0]
|
||||
mov r0, #193 ; 0xc1
|
||||
strh r0, [r1]
|
||||
mov r0, #8
|
||||
ldr r1, _037FA538 ; =OSi_CountUpTick
|
||||
bl OS_SetIrqFunction
|
||||
mov r0, #8
|
||||
bl OS_EnableIrqMask
|
||||
mov r1, #0
|
||||
ldr r0, _037FA53C ; =OSi_NeedResetTimer
|
||||
str r1, [r0]
|
||||
_037FA51C:
|
||||
add sp, sp, #4
|
||||
ldmia sp!, {lr}
|
||||
bx lr
|
||||
_037FA528: .word _03807920
|
||||
_037FA52C: .word OSi_TickCounter
|
||||
_037FA530: .word 0x04000102
|
||||
_037FA534: .word 0x04000100
|
||||
_037FA538: .word OSi_CountUpTick
|
||||
_037FA53C: .word OSi_NeedResetTimer
|
||||
@@ -380,7 +380,7 @@
|
||||
.extern _038078F4
|
||||
.extern OSiHeapInfo
|
||||
.extern _0380791C
|
||||
.extern _03807920
|
||||
.extern OSi_UseTick
|
||||
.extern OSi_NeedResetTimer
|
||||
.extern OSi_TickCounter
|
||||
.extern _03807930
|
||||
|
||||
11
arm7/lib/include/OS_tick.h
Normal file
11
arm7/lib/include/OS_tick.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef POKEDIAMOND_OS_TICK_H
|
||||
#define POKEDIAMOND_OS_TICK_H
|
||||
|
||||
#include "nitro/OS_tick_shared.h"
|
||||
|
||||
void OS_InitTick(void);
|
||||
u16 OS_IsTickAvailable(void);
|
||||
void OSi_CountUpTick(void);
|
||||
OSTick OS_GetTick(void);
|
||||
|
||||
#endif
|
||||
6
arm7/lib/include/OS_timer.h
Normal file
6
arm7/lib/include/OS_timer.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef POKEDIAMOND_OS_TIMER_H
|
||||
#define POKEDIAMOND_OS_TIMER_H
|
||||
|
||||
#include "nitro/OS_timer_shared.h"
|
||||
|
||||
#endif
|
||||
54
arm7/lib/src/OS_tick.c
Normal file
54
arm7/lib/src/OS_tick.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "OS_interrupt.h"
|
||||
#include "OS_system.h"
|
||||
#include "OS_tick.h"
|
||||
#include "OS_timer.h"
|
||||
#include "function_target.h"
|
||||
|
||||
extern void OSi_SetTimerReserved(u32);
|
||||
|
||||
static u16 OSi_UseTick;
|
||||
static OSTick OSi_TickCounter;
|
||||
static BOOL OSi_NeedResetTimer;
|
||||
|
||||
ARM_FUNC void OS_InitTick(void) {
|
||||
if (OSi_UseTick == 0) {
|
||||
OSi_UseTick = 1;
|
||||
OSi_SetTimerReserved(0);
|
||||
OSi_TickCounter = 0;
|
||||
OS_SetTimerControl(OS_TIMER_0, 0);
|
||||
OS_SetTimerCount(OS_TIMER_0, 0);
|
||||
OS_SetTimerControl(OS_TIMER_0, 0xc1);
|
||||
OS_SetIrqFunction(8, OSi_CountUpTick);
|
||||
(void)OS_EnableIrqMask(8);
|
||||
OSi_NeedResetTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ARM_FUNC u16 OS_IsTickAvailable(void) {
|
||||
return OSi_UseTick;
|
||||
}
|
||||
|
||||
ARM_FUNC void OSi_CountUpTick(void) {
|
||||
OSi_TickCounter++;
|
||||
if (OSi_NeedResetTimer != 0) {
|
||||
OS_SetTimerControl(OS_TIMER_0, 0);
|
||||
OS_SetTimerCount(OS_TIMER_0, 0);
|
||||
OS_SetTimerControl(OS_TIMER_0, 0xc1);
|
||||
OSi_NeedResetTimer = 0;
|
||||
}
|
||||
OSi_EnterTimerCallback(0, (void(*)(void*))OSi_CountUpTick, NULL);
|
||||
}
|
||||
|
||||
ARM_FUNC OSTick OS_GetTick(void) {
|
||||
OSIntrMode prev = OS_DisableInterrupts();
|
||||
vu16 countL = *(REGType16 *)((u32)®_OS_TM0CNT_L + OS_TIMER_0 * 4);
|
||||
vu64 countH = OSi_TickCounter & 0xffffffffffffULL;
|
||||
|
||||
if (reg_OS_IF & 8 && !(countL & 0x8000)) {
|
||||
countH++;
|
||||
}
|
||||
|
||||
(void)OS_RestoreInterrupts(prev);
|
||||
|
||||
return (countH << 16) | countL;
|
||||
}
|
||||
@@ -1,32 +1,6 @@
|
||||
#ifndef POKEDIAMOND_OS_TIMER_H
|
||||
#define POKEDIAMOND_OS_TIMER_H
|
||||
|
||||
#include "consts.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OS_TIMER_PRESCALER_1 = (0UL << REG_OS_TM0CNT_H_PS_SHIFT),
|
||||
OS_TIMER_PRESCALER_64 = (1UL << REG_OS_TM0CNT_H_PS_SHIFT),
|
||||
OS_TIMER_PRESCALER_256 = (2UL << REG_OS_TM0CNT_H_PS_SHIFT),
|
||||
OS_TIMER_PRESCALER_1024 = (3UL << REG_OS_TM0CNT_H_PS_SHIFT)
|
||||
} OSTimerPrescaler;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OS_TIMER_0 = 0,
|
||||
OS_TIMER_1 = 1,
|
||||
OS_TIMER_2 = 2,
|
||||
OS_TIMER_3 = 3
|
||||
} OSTimer;
|
||||
|
||||
static inline void OS_SetTimerCount(OSTimer id, u16 count)
|
||||
{
|
||||
*((REGType16 *)((u32)®_OS_TM0CNT_L + id * 4)) = count;
|
||||
}
|
||||
|
||||
static inline void OS_SetTimerControl(OSTimer id, u16 control)
|
||||
{
|
||||
*((REGType16 *)((u32)®_OS_TM0CNT_H + id * 4)) = control;
|
||||
}
|
||||
#include "nitro/OS_timer_shared.h"
|
||||
|
||||
#endif //POKEDIAMOND_OS_TIMER_H
|
||||
|
||||
@@ -73,15 +73,6 @@
|
||||
#define reg_MI_DMA2_CLR_DATA (*(REGType32v *)0x40000e8)
|
||||
#define reg_MI_DMA3_CLR_DATA (*(REGType32v *)0x40000ec)
|
||||
|
||||
#define reg_OS_TM0CNT_L (*(REGType16v *)0x4000100)
|
||||
#define reg_OS_TM0CNT_H (*(REGType16v *)0x4000102)
|
||||
#define reg_OS_TM1CNT_L (*(REGType16v *)0x4000104)
|
||||
#define reg_OS_TM1CNT_H (*(REGType16v *)0x4000106)
|
||||
#define reg_OS_TM2CNT_L (*(REGType16v *)0x4000108)
|
||||
#define reg_OS_TM2CNT_H (*(REGType16v *)0x400010a)
|
||||
#define reg_OS_TM3CNT_L (*(REGType16v *)0x400010c)
|
||||
#define reg_OS_TM3CNT_H (*(REGType16v *)0x400010e)
|
||||
|
||||
#define reg_EXI_SIODATA32 (*(REGType32v *)0x4000120)
|
||||
#define reg_EXI_SIOCNT (*(REGType16v *)0x4000128)
|
||||
#define reg_EXI_SIOSEL (*(REGType32v *)0x400012c)
|
||||
@@ -354,7 +345,6 @@
|
||||
#define reg_MI_MCD1 (*(REGType32v *)0x4100010)
|
||||
#define reg_CARD_DATA (*(REGType32v *)0x4100010) //?
|
||||
|
||||
#define REG_OS_TM0CNT_H_PS_SHIFT 0
|
||||
#define REG_OS_IE_T0_SHIFT 3
|
||||
|
||||
#define REG_OS_TM0CNT_H_I_MASK 0x0040
|
||||
|
||||
32
include/nitro/OS_timer_shared.h
Normal file
32
include/nitro/OS_timer_shared.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef POKEDIAMOND_OS_TIMER_SHARED_H
|
||||
#define POKEDIAMOND_OS_TIMER_SHARED_H
|
||||
|
||||
#include "nitro/consts_shared.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OS_TIMER_PRESCALER_1 = (0UL << REG_OS_TM0CNT_H_PS_SHIFT),
|
||||
OS_TIMER_PRESCALER_64 = (1UL << REG_OS_TM0CNT_H_PS_SHIFT),
|
||||
OS_TIMER_PRESCALER_256 = (2UL << REG_OS_TM0CNT_H_PS_SHIFT),
|
||||
OS_TIMER_PRESCALER_1024 = (3UL << REG_OS_TM0CNT_H_PS_SHIFT)
|
||||
} OSTimerPrescaler;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OS_TIMER_0 = 0,
|
||||
OS_TIMER_1 = 1,
|
||||
OS_TIMER_2 = 2,
|
||||
OS_TIMER_3 = 3
|
||||
} OSTimer;
|
||||
|
||||
static inline void OS_SetTimerCount(OSTimer id, u16 count)
|
||||
{
|
||||
*((REGType16 *)((u32)®_OS_TM0CNT_L + id * 4)) = count;
|
||||
}
|
||||
|
||||
static inline void OS_SetTimerControl(OSTimer id, u16 control)
|
||||
{
|
||||
*((REGType16 *)((u32)®_OS_TM0CNT_H + id * 4)) = control;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -10,8 +10,19 @@
|
||||
|
||||
#include "nitro/types.h"
|
||||
|
||||
#define reg_OS_TM0CNT_L (*(REGType16v *)0x4000100)
|
||||
#define reg_OS_TM0CNT_H (*(REGType16v *)0x4000102)
|
||||
#define reg_OS_TM1CNT_L (*(REGType16v *)0x4000104)
|
||||
#define reg_OS_TM1CNT_H (*(REGType16v *)0x4000106)
|
||||
#define reg_OS_TM2CNT_L (*(REGType16v *)0x4000108)
|
||||
#define reg_OS_TM2CNT_H (*(REGType16v *)0x400010a)
|
||||
#define reg_OS_TM3CNT_L (*(REGType16v *)0x400010c)
|
||||
#define reg_OS_TM3CNT_H (*(REGType16v *)0x400010e)
|
||||
|
||||
#define reg_OS_IME (*(REGType16v *)0x4000208)
|
||||
#define reg_OS_IE (*(REGType32v *)0x4000210)
|
||||
#define reg_OS_IF (*(REGType32v *)0x4000214)
|
||||
|
||||
#define REG_OS_TM0CNT_H_PS_SHIFT 0
|
||||
|
||||
#endif //POKEDIAMOND_REGISTERS_SHARED_H
|
||||
|
||||
Reference in New Issue
Block a user