diff options
-rw-r--r-- | asm/rom.s | 2 | ||||
-rw-r--r-- | include/rtc_util.h | 18 | ||||
-rw-r--r-- | iwram_syms.txt | 2 | ||||
-rw-r--r-- | src/rtc_util.c | 54 |
4 files changed, 45 insertions, 31 deletions
@@ -18851,7 +18851,7 @@ sub_8009A64: ; 8009A64 adds r1, 0x4 movs r0, 0x7 strh r0, [r1] - bl RtcGetErrorFlags + bl RtcGetStatus movs r1, 0xFF lsls r1, 4 ands r1, r0 diff --git a/include/rtc_util.h b/include/rtc_util.h index 584b675d6..c92566e94 100644 --- a/include/rtc_util.h +++ b/include/rtc_util.h @@ -3,8 +3,22 @@ #include "global.h" +#define RTC_STAT_INIT_ERROR 0x0001 +#define RTC_STAT_INIT_WARNING 0x0002 + +#define RTC_STAT_ERR_12HOUR_CLOCK 0x0010 +#define RTC_STAT_ERR_POWER_FAILURE 0x0020 +#define RTC_STAT_ERR_INVALID_YEAR 0x0040 +#define RTC_STAT_ERR_INVALID_MONTH 0x0080 +#define RTC_STAT_ERR_INVALID_DAY 0x0100 +#define RTC_STAT_ERR_INVALID_HOUR 0x0200 +#define RTC_STAT_ERR_INVALID_MINUTE 0x0400 +#define RTC_STAT_ERR_INVALID_SECOND 0x0800 + +#define RTC_STAT_ERROR_FLAGS 0x0FF0 + void RtcInit(); -u16 RtcGetErrorFlags(); +u16 RtcGetStatus(); void RtcReset(); void FormatDecimalTime(u8 *dest, s32 hour, s32 minute, s32 second); void FormatHexTime(u8 *dest, s32 hour, s32 minute, s32 second); @@ -12,7 +26,7 @@ void FormatHexRtcTime(u8 *dest); void FormatDecimalDate(u8 *dest, s32 year, s32 month, s32 day); void FormatHexDate(u8 *dest, s32 year, s32 month, s32 day); void RtcCalcLocalTime(); -void RtcInitLocalTimeOffset(s32 hours, s32 minutes); +void RtcInitLocalTimeOffset(s32 hour, s32 minute); void RtcCalcLocalTimeOffset(s32 days, s32 hours, s32 minutes, s32 seconds); void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2); u32 RtcGetMinuteCount(); diff --git a/iwram_syms.txt b/iwram_syms.txt index 5f6e9a8ab..1c14f71f7 100644 --- a/iwram_syms.txt +++ b/iwram_syms.txt @@ -1,4 +1,4 @@ -gRtcErrorFlags = 0x3000458; +gRtcStatus = 0x3000458; gRtcInfo = 0x3000460; gRtcProbeResult = 0x300046C; gRtcSavedIme = 0x300046E; diff --git a/src/rtc_util.c b/src/rtc_util.c index b279ec753..0149fcdc7 100644 --- a/src/rtc_util.c +++ b/src/rtc_util.c @@ -6,7 +6,7 @@ extern const struct RtcInfo gDefaultRtcInfo; extern const s32 gNumDaysInMonths[]; -extern u16 gRtcErrorFlags; +extern u16 gRtcStatus; extern struct RtcInfo gRtcInfo; extern u8 gRtcProbeResult; extern u16 gRtcSavedIme; @@ -90,7 +90,7 @@ u16 RtcGetDayCount(struct RtcInfo *rtc) void RtcInit() { - gRtcErrorFlags = 0; + gRtcStatus = 0; RtcDisableInterrupts(); RTC_Unprotect(); @@ -99,27 +99,27 @@ void RtcInit() if (!(gRtcProbeResult & 0xF)) { - gRtcErrorFlags = 1; + gRtcStatus = RTC_STAT_INIT_ERROR; return; } if (gRtcProbeResult & 0xF0) - gRtcErrorFlags = 2; + gRtcStatus = RTC_STAT_INIT_WARNING; else - gRtcErrorFlags = 0; + gRtcStatus = 0; RtcGetRawInfo(&gRtcInfo); - gRtcErrorFlags = RtcCheckInfo(&gRtcInfo); + gRtcStatus = RtcCheckInfo(&gRtcInfo); } -u16 RtcGetErrorFlags() +u16 RtcGetStatus() { - return gRtcErrorFlags; + return gRtcStatus; } void RtcGetInfo(struct RtcInfo *rtc) { - if (gRtcErrorFlags & 0xFF0) + if (gRtcStatus & RTC_STAT_ERROR_FLAGS) *rtc = gDefaultRtcInfo; else RtcGetRawInfo(rtc); @@ -153,51 +153,51 @@ u16 RtcCheckInfo(struct RtcInfo *rtc) s32 value; if (rtc->control & RTC_INFO_CTRL_POWER_FAILURE) - errorFlags |= 0x20; + errorFlags |= RTC_STAT_ERR_POWER_FAILURE; if (!(rtc->control & RTC_INFO_CTRL_24HOUR)) - errorFlags |= 0x10; + errorFlags |= RTC_STAT_ERR_12HOUR_CLOCK; year = ConvertBcdToBinary(rtc->year); if (year == 0xFF) - errorFlags |= 0x40; + errorFlags |= RTC_STAT_ERR_INVALID_YEAR; month = ConvertBcdToBinary(rtc->month); if (month == 0xFF || month == 0 || month > 12) - errorFlags |= 0x80; + errorFlags |= RTC_STAT_ERR_INVALID_MONTH; value = ConvertBcdToBinary(rtc->day); if (value == 0xFF) - errorFlags |= 0x100; + errorFlags |= RTC_STAT_ERR_INVALID_DAY; if (month == MONTH_FEB) { if (value > IsLeapYear(year) + gNumDaysInMonths[month - 1]) - errorFlags |= 0x100; + errorFlags |= RTC_STAT_ERR_INVALID_DAY; } else { if (value > gNumDaysInMonths[month - 1]) - errorFlags |= 0x100; + errorFlags |= RTC_STAT_ERR_INVALID_DAY; } value = ConvertBcdToBinary(rtc->hour); if (value > 24) - errorFlags |= 0x200; + errorFlags |= RTC_STAT_ERR_INVALID_HOUR; value = ConvertBcdToBinary(rtc->minute); if (value > 60) - errorFlags |= 0x400; + errorFlags |= RTC_STAT_ERR_INVALID_MINUTE; value = ConvertBcdToBinary(rtc->second); if (value > 60) - errorFlags |= 0x800; + errorFlags |= RTC_STAT_ERR_INVALID_SECOND; return errorFlags; } @@ -287,19 +287,19 @@ void RtcCalcLocalTime() RtcCalcTimeDifference(&gRtcInfo, &gLocalTime, &gSaveBlock2.localTimeOffset); } -void RtcInitLocalTimeOffset(s32 hours, s32 minutes) +void RtcInitLocalTimeOffset(s32 hour, s32 minute) { - RtcCalcLocalTimeOffset(0, hours, minutes, 0); + RtcCalcLocalTimeOffset(0, hour, minute, 0); } void RtcCalcLocalTimeOffset(s32 days, s32 hours, s32 minutes, s32 seconds) { - gLocalTime.days = days; - gLocalTime.hours = hours; - gLocalTime.minutes = minutes; - gLocalTime.seconds = seconds; - RtcGetInfo(&gRtcInfo); - RtcCalcTimeDifference(&gRtcInfo, &gSaveBlock2.localTimeOffset, &gLocalTime); + gLocalTime.days = days; + gLocalTime.hours = hours; + gLocalTime.minutes = minutes; + gLocalTime.seconds = seconds; + RtcGetInfo(&gRtcInfo); + RtcCalcTimeDifference(&gRtcInfo, &gSaveBlock2.localTimeOffset, &gLocalTime); } void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2) |