From 7aa51d17e1b4f937920397bcb83c6247b3bc221c Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Wed, 22 Sep 2021 11:25:24 -0400 Subject: [PATCH] Fix data type for __osCurrentTime to get __osTimerServicesInit to almost match --- include/PR/os_time.h | 17 +-- .../non_matchings/osViMgr_0D2590/viMgrMain.s | 4 +- .../unknown_0D3020/__osTimerServicesInit.s | 6 +- lib/src/os/osTimer.c | 141 +++++++++--------- lib/src/os/osViMgr.c | 2 +- lib/src/unknown_0CE200.c | 7 +- 6 files changed, 87 insertions(+), 90 deletions(-) diff --git a/include/PR/os_time.h b/include/PR/os_time.h index d6b9d923..edd3d258 100644 --- a/include/PR/os_time.h +++ b/include/PR/os_time.h @@ -6,22 +6,21 @@ /* Types */ -typedef struct OSTimer_str -{ - struct OSTimer_str *next; - struct OSTimer_str *prev; - u64 interval; - u64 remaining; +typedef u64 OSTime; + +typedef struct OSTimer_s { + struct OSTimer_s *next; + struct OSTimer_s *prev; + OSTime interval; + OSTime remaining; OSMesgQueue *mq; OSMesg *msg; } OSTimer; -typedef u64 OSTime; - /* Functions */ OSTime osGetTime(void); void osSetTime(OSTime time); -s32 osSetTimer(OSTimer *, OSTime, u64, OSMesgQueue *, OSMesg); +s32 osSetTimer(OSTimer *t, OSTime value, OSTime interval, OSMesgQueue *mq, OSMesg msg); #endif diff --git a/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s b/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s index 9f605f94..0e57bb23 100644 --- a/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s +++ b/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s @@ -21,12 +21,12 @@ glabel viMgrMain /* 0D2754 800D1B54 3C018013 */ lui $at, %hi(D_8012D190) # $at, 0x8013 /* 0D2758 800D1B58 A423D190 */ sh $v1, %lo(D_8012D190)($at) .L800D1B5C: -/* 0D275C 800D1B5C 3C138013 */ lui $s3, %hi(D_8012D22C) # $s3, 0x8013 +/* 0D275C 800D1B5C 3C138013 */ lui $s3, %hi(__osViIntrCount) # $s3, 0x8013 /* 0D2760 800D1B60 3C128013 */ lui $s2, %hi(__osBaseCounter) # $s2, 0x8013 /* 0D2764 800D1B64 3C118013 */ lui $s1, %hi(__osCurrentTime) # $s1, 0x8013 /* 0D2768 800D1B68 2631D220 */ addiu $s1, %lo(__osCurrentTime) # addiu $s1, $s1, -0x2de0 /* 0D276C 800D1B6C 2652D228 */ addiu $s2, %lo(__osBaseCounter) # addiu $s2, $s2, -0x2dd8 -/* 0D2770 800D1B70 2673D22C */ addiu $s3, %lo(D_8012D22C) # addiu $s3, $s3, -0x2dd4 +/* 0D2770 800D1B70 2673D22C */ addiu $s3, %lo(__osViIntrCount) # addiu $s3, $s3, -0x2dd4 /* 0D2774 800D1B74 2415000D */ li $s5, 13 /* 0D2778 800D1B78 27B40044 */ addiu $s4, $sp, 0x44 .L800D1B7C: diff --git a/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s b/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s index 65069c09..34fb800b 100644 --- a/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s +++ b/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s @@ -2,14 +2,14 @@ glabel __osTimerServicesInit /* 0D5AC0 800D4EC0 3C018013 */ lui $at, %hi(__osCurrentTime) # $at, 0x8013 /* 0D5AC4 800D4EC4 240E0000 */ li $t6, 0 /* 0D5AC8 800D4EC8 240F0000 */ li $t7, 0 -/* 0D5ACC 800D4ECC AC2FD224 */ sw $t7, %lo(D_8012D224)($at) +/* 0D5ACC 800D4ECC AC2FD224 */ sw $t7, %lo(__osCurrentTime+4)($at) /* 0D5AD0 800D4ED0 AC2ED220 */ sw $t6, %lo(__osCurrentTime)($at) /* 0D5AD4 800D4ED4 3C018013 */ lui $at, %hi(__osBaseCounter) # $at, 0x8013 /* 0D5AD8 800D4ED8 3C18800E */ lui $t8, %hi(__osTimerList) # $t8, 0x800e /* 0D5ADC 800D4EDC 8F184910 */ lw $t8, %lo(__osTimerList)($t8) /* 0D5AE0 800D4EE0 AC20D228 */ sw $zero, %lo(__osBaseCounter)($at) -/* 0D5AE4 800D4EE4 3C018013 */ lui $at, %hi(D_8012D22C) # $at, 0x8013 -/* 0D5AE8 800D4EE8 AC20D22C */ sw $zero, %lo(D_8012D22C)($at) +/* 0D5AE4 800D4EE4 3C018013 */ lui $at, %hi(__osViIntrCount) # $at, 0x8013 +/* 0D5AE8 800D4EE8 AC20D22C */ sw $zero, %lo(__osViIntrCount)($at) /* 0D5AEC 800D4EEC 3C19800E */ lui $t9, %hi(__osTimerList) # $t9, 0x800e /* 0D5AF0 800D4EF0 AF180004 */ sw $t8, 4($t8) /* 0D5AF4 800D4EF4 8F394910 */ lw $t9, %lo(__osTimerList)($t9) diff --git a/lib/src/os/osTimer.c b/lib/src/os/osTimer.c index 9c42915c..e81ee2d6 100644 --- a/lib/src/os/osTimer.c +++ b/lib/src/os/osTimer.c @@ -9,99 +9,98 @@ OSTimer *__osTimerList = &D_8012D200; extern OSTime __osCurrentTime; extern u32 __osBaseCounter; -extern u32 D_8012D22C; +extern u32 __osViIntrCount; extern u32 D_8012D230; OSTime __osInsertTimer(OSTimer *t); -#if 1 -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s") -#else +#if NON_MATCHING void __osTimerServicesInit(void) { - //D_8012D224 = 0; - __osCurrentTime = 0; + __osCurrentTime = 0; __osBaseCounter = 0; - D_8012D22C = 0; - __osTimerList->prev = __osTimerList; - __osTimerList->next = __osTimerList->prev; - __osTimerList->remaining = 0; - __osTimerList->interval = __osTimerList->remaining; - __osTimerList->mq = NULL; - __osTimerList->msg = 0; + __osViIntrCount = 0; + __osTimerList->prev = __osTimerList; + __osTimerList->next = __osTimerList->prev; + __osTimerList->remaining = 0; + __osTimerList->interval = __osTimerList->remaining; + __osTimerList->mq = NULL; + __osTimerList->msg = 0; } +#else +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s") #endif void __osTimerInterrupt(void) { - OSTimer *t; - u32 count; - u32 elapsed_cycles; + OSTimer *t; + u32 count; + u32 elapsed_cycles; - if (__osTimerList->next == __osTimerList) - return; - while (1) { - t = __osTimerList->next; - if (t == __osTimerList){ - __osSetCompare(0); - D_8012D230 = 0; - break; - } - count = osGetCount(); - elapsed_cycles = count - D_8012D230; - D_8012D230 = count; - if (elapsed_cycles < t->remaining){ - t->remaining -= elapsed_cycles; - __osSetTimerIntr(t->remaining); - return; - } else { - t->prev->next = t->next; - t->next->prev = t->prev; - t->next = NULL; - t->prev = NULL; - if (t->mq != NULL){ - osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); - } - if (t->interval != 0){ - t->remaining = t->interval; - __osInsertTimer(t); - } - } - } + if (__osTimerList->next == __osTimerList) + return; + while (1) { + t = __osTimerList->next; + if (t == __osTimerList){ + __osSetCompare(0); + D_8012D230 = 0; + break; + } + count = osGetCount(); + elapsed_cycles = count - D_8012D230; + D_8012D230 = count; + if (elapsed_cycles < t->remaining){ + t->remaining -= elapsed_cycles; + __osSetTimerIntr(t->remaining); + return; + } else { + t->prev->next = t->next; + t->next->prev = t->prev; + t->next = NULL; + t->prev = NULL; + if (t->mq != NULL){ + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); + } + if (t->interval != 0){ + t->remaining = t->interval; + __osInsertTimer(t); + } + } + } } #if 1 GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetTimerIntr.s") #else void __osSetTimerIntr(OSTime tim) { - OSTime NewTime; - u32 savedMask; - savedMask = __osDisableInt(); - D_8012D230 = osGetCount(); - NewTime = tim + D_8012D230; - __osSetCompare(NewTime); - __osRestoreInt(savedMask); + OSTime NewTime; + u32 savedMask; + savedMask = __osDisableInt(); + D_8012D230 = osGetCount(); + NewTime = tim + D_8012D230; + __osSetCompare(NewTime); + __osRestoreInt(savedMask); } #endif OSTime __osInsertTimer(OSTimer *t) { - OSTimer *timep; - OSTime tim; - u32 savedMask; - savedMask = __osDisableInt(); - for (timep = __osTimerList->next, tim = t->remaining; - timep != __osTimerList && tim > timep->remaining; - tim -= timep->remaining, timep = timep->next) { - ; - } - t->remaining = tim; - if (timep != __osTimerList) - timep->remaining -= tim; - t->next = timep; - t->prev = timep->prev; - timep->prev->next = t; - timep->prev = t; - __osRestoreInt(savedMask); - return tim; + OSTimer *timep; + OSTime tim; + u32 savedMask; + savedMask = __osDisableInt(); + for (timep = __osTimerList->next, tim = t->remaining; + timep != __osTimerList && tim > timep->remaining; + tim -= timep->remaining, timep = timep->next) { + ; + } + t->remaining = tim; + if (timep != __osTimerList) + timep->remaining -= tim; + t->next = timep; + t->prev = timep->prev; + timep->prev->next = t; + timep->prev = t; + __osRestoreInt(savedMask); + return tim; } diff --git a/lib/src/os/osViMgr.c b/lib/src/os/osViMgr.c index fceee4d8..a394acb4 100644 --- a/lib/src/os/osViMgr.c +++ b/lib/src/os/osViMgr.c @@ -8,7 +8,7 @@ extern OSTime __osCurrentTime; extern u32 __osBaseCounter; -extern u32 D_8012D22C; //__osViIntrCount +extern u32 __osViIntrCount; //__osViIntrCount OSDevMgr __osViDevMgr = {0}; diff --git a/lib/src/unknown_0CE200.c b/lib/src/unknown_0CE200.c index 07216280..bf81df96 100644 --- a/lib/src/unknown_0CE200.c +++ b/lib/src/unknown_0CE200.c @@ -22,14 +22,13 @@ s32 viEventBuf[6]; s32 viRetraceMsg[6]; s32 viCounterMsg[6]; s32 D_8012D190[4]; -s32 D_8012D1A0[16]; +s32 D_8012D1A0[16]; s32 D_8012D1E0[2]; s32 piAccessQueue[6]; OSTimer D_8012D200; -s32 __osCurrentTime; -s32 D_8012D224; +OSTime __osCurrentTime; s32 __osBaseCounter; -s32 D_8012D22C; +s32 __osViIntrCount; s32 D_8012D230[4]; s32 D_8012D240[108]; MemoryPoolSlot *gMainMemoryPool;