From 9656400f888cbcbe6740d2f445668a34a5cbe0dd Mon Sep 17 00:00:00 2001 From: psf <77138753+pkmnsnfrn@users.noreply.github.com> Date: Fri, 30 May 2025 07:39:01 -0700 Subject: [PATCH] Moved time constants to dedicated files (#7019) --- data/event_scripts.s | 2 + include/constants/rtc.h | 96 +++++++++++++++++++ include/constants/siirtc.h | 43 +++++++++ include/rtc.h | 95 +----------------- include/siirtc.h | 40 +------- .../wild_encounters_to_header.py | 2 +- 6 files changed, 145 insertions(+), 133 deletions(-) create mode 100644 include/constants/rtc.h create mode 100644 include/constants/siirtc.h diff --git a/data/event_scripts.s b/data/event_scripts.s index 84a3011afc..db5d329b67 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -46,9 +46,11 @@ #include "constants/party_menu.h" #include "constants/pokedex.h" #include "constants/pokemon.h" +#include "constants/rtc.h" #include "constants/roulette.h" #include "constants/script_menu.h" #include "constants/secret_bases.h" +#include "constants/siirtc.h" #include "constants/songs.h" #include "constants/sound.h" #include "constants/species.h" diff --git a/include/constants/rtc.h b/include/constants/rtc.h new file mode 100644 index 0000000000..65ee9c35ed --- /dev/null +++ b/include/constants/rtc.h @@ -0,0 +1,96 @@ +#ifndef GUARD_CONSTANTS_RTC_H +#define GUARD_CONSTANTS_RTC_H + +#define RTC_INIT_ERROR 0x0001 +#define RTC_INIT_WARNING 0x0002 + +#define RTC_ERR_12HOUR_CLOCK 0x0010 +#define RTC_ERR_POWER_FAILURE 0x0020 +#define RTC_ERR_INVALID_YEAR 0x0040 +#define RTC_ERR_INVALID_MONTH 0x0080 +#define RTC_ERR_INVALID_DAY 0x0100 +#define RTC_ERR_INVALID_HOUR 0x0200 +#define RTC_ERR_INVALID_MINUTE 0x0400 +#define RTC_ERR_INVALID_SECOND 0x0800 + +#define RTC_ERR_FLAG_MASK 0x0FF0 + +//Morning and evening don't exist in Gen 3 +#if OW_TIMES_OF_DAY == GEN_3 + #define MORNING_HOUR_BEGIN 0 + #define MORNING_HOUR_END 0 + + #define DAY_HOUR_BEGIN 12 + #define DAY_HOUR_END HOURS_PER_DAY + + #define EVENING_HOUR_BEGIN 0 + #define EVENING_HOUR_END 0 + + #define NIGHT_HOUR_BEGIN 0 + #define NIGHT_HOUR_END 12 +//Evening doesn't exist in Gen 4 +#elif OW_TIMES_OF_DAY == GEN_4 + #define MORNING_HOUR_BEGIN 4 + #define MORNING_HOUR_END 10 + + #define DAY_HOUR_BEGIN 10 + #define DAY_HOUR_END 20 + + #define EVENING_HOUR_BEGIN 0 + #define EVENING_HOUR_END 0 + + #define NIGHT_HOUR_BEGIN 20 + #define NIGHT_HOUR_END 4 +//Gen 5 currently not included as the seasons change the times of day +#elif OW_TIMES_OF_DAY <= GEN_6 + #define MORNING_HOUR_BEGIN 4 + #define MORNING_HOUR_END 11 + + #define DAY_HOUR_BEGIN 11 + #define DAY_HOUR_END 18 + + #define EVENING_HOUR_BEGIN 18 + #define EVENING_HOUR_END 21 + + #define NIGHT_HOUR_BEGIN 21 + #define NIGHT_HOUR_END 4 +//These are the Sun/Ultra Sun times +#elif OW_TIMES_OF_DAY == GEN_7 + #define MORNING_HOUR_BEGIN 6 + #define MORNING_HOUR_END 10 + + #define DAY_HOUR_BEGIN 10 + #define DAY_HOUR_END 17 + + #define EVENING_HOUR_BEGIN 17 + #define EVENING_HOUR_END 18 + + #define NIGHT_HOUR_BEGIN 18 + #define NIGHT_HOUR_END 6 +#elif OW_TIMES_OF_DAY >= GEN_8 + #define MORNING_HOUR_BEGIN 6 + #define MORNING_HOUR_END 10 + + #define DAY_HOUR_BEGIN 10 + #define DAY_HOUR_END 19 + + #define EVENING_HOUR_BEGIN 19 + #define EVENING_HOUR_END 20 + + #define NIGHT_HOUR_BEGIN 20 + #define NIGHT_HOUR_END 6 +#endif + +// TIMES_OF_DAY_COUNT must be last +enum TimeOfDay +{ + TIME_MORNING, + TIME_DAY, + TIME_EVENING, + TIME_NIGHT, + TIMES_OF_DAY_COUNT, +}; + +#define TIME_OF_DAY_DEFAULT 0 + +#endif // GUARD_CONSTANTS_RTC_H diff --git a/include/constants/siirtc.h b/include/constants/siirtc.h new file mode 100644 index 0000000000..b806526de9 --- /dev/null +++ b/include/constants/siirtc.h @@ -0,0 +1,43 @@ +#ifndef GUARD_CONSTANTS_SIIRTC_H +#define GUARD_CONSTANTS_SIIRTC_H + +#define SIIRTCINFO_INTFE 0x01 // frequency interrupt enable +#define SIIRTCINFO_INTME 0x02 // per-minute interrupt enable +#define SIIRTCINFO_INTAE 0x04 // alarm interrupt enable +#define SIIRTCINFO_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode +#define SIIRTCINFO_POWER 0x80 // power on or power failure occurred + +#define HOURS_PER_DAY 24 +#define MINUTES_PER_HOUR 60 +#define SECONDS_PER_MINUTE 60 + +enum Weekday +{ + WEEKDAY_SUN, + WEEKDAY_MON, + WEEKDAY_TUE, + WEEKDAY_WED, + WEEKDAY_THU, + WEEKDAY_FRI, + WEEKDAY_SAT, + WEEKDAY_COUNT, +}; + +enum Month +{ + MONTH_JAN = 1, + MONTH_FEB, + MONTH_MAR, + MONTH_APR, + MONTH_MAY, + MONTH_JUN, + MONTH_JUL, + MONTH_AUG, + MONTH_SEP, + MONTH_OCT, + MONTH_NOV, + MONTH_DEC, + MONTH_COUNT = MONTH_DEC, +}; + +#endif // GUARD_CONSTANTS_SIIRTC_H diff --git a/include/rtc.h b/include/rtc.h index 13a1207b56..8ee3071615 100644 --- a/include/rtc.h +++ b/include/rtc.h @@ -4,101 +4,10 @@ #include "global.h" #include "siirtc.h" #include "config/overworld.h" - -#define RTC_INIT_ERROR 0x0001 -#define RTC_INIT_WARNING 0x0002 - -#define RTC_ERR_12HOUR_CLOCK 0x0010 -#define RTC_ERR_POWER_FAILURE 0x0020 -#define RTC_ERR_INVALID_YEAR 0x0040 -#define RTC_ERR_INVALID_MONTH 0x0080 -#define RTC_ERR_INVALID_DAY 0x0100 -#define RTC_ERR_INVALID_HOUR 0x0200 -#define RTC_ERR_INVALID_MINUTE 0x0400 -#define RTC_ERR_INVALID_SECOND 0x0800 - -#define RTC_ERR_FLAG_MASK 0x0FF0 - -//Morning and evening don't exist in Gen 3 -#if OW_TIMES_OF_DAY == GEN_3 - #define MORNING_HOUR_BEGIN 0 - #define MORNING_HOUR_END 0 - - #define DAY_HOUR_BEGIN 12 - #define DAY_HOUR_END HOURS_PER_DAY - - #define EVENING_HOUR_BEGIN 0 - #define EVENING_HOUR_END 0 - - #define NIGHT_HOUR_BEGIN 0 - #define NIGHT_HOUR_END 12 -//Evening doesn't exist in Gen 4 -#elif OW_TIMES_OF_DAY == GEN_4 - #define MORNING_HOUR_BEGIN 4 - #define MORNING_HOUR_END 10 - - #define DAY_HOUR_BEGIN 10 - #define DAY_HOUR_END 20 - - #define EVENING_HOUR_BEGIN 0 - #define EVENING_HOUR_END 0 - - #define NIGHT_HOUR_BEGIN 20 - #define NIGHT_HOUR_END 4 -//Gen 5 currently not included as the seasons change the times of day -#elif OW_TIMES_OF_DAY <= GEN_6 - #define MORNING_HOUR_BEGIN 4 - #define MORNING_HOUR_END 11 - - #define DAY_HOUR_BEGIN 11 - #define DAY_HOUR_END 18 - - #define EVENING_HOUR_BEGIN 18 - #define EVENING_HOUR_END 21 - - #define NIGHT_HOUR_BEGIN 21 - #define NIGHT_HOUR_END 4 -//These are the Sun/Ultra Sun times -#elif OW_TIMES_OF_DAY == GEN_7 - #define MORNING_HOUR_BEGIN 6 - #define MORNING_HOUR_END 10 - - #define DAY_HOUR_BEGIN 10 - #define DAY_HOUR_END 17 - - #define EVENING_HOUR_BEGIN 17 - #define EVENING_HOUR_END 18 - - #define NIGHT_HOUR_BEGIN 18 - #define NIGHT_HOUR_END 6 -#elif OW_TIMES_OF_DAY >= GEN_8 - #define MORNING_HOUR_BEGIN 6 - #define MORNING_HOUR_END 10 - - #define DAY_HOUR_BEGIN 10 - #define DAY_HOUR_END 19 - - #define EVENING_HOUR_BEGIN 19 - #define EVENING_HOUR_END 20 - - #define NIGHT_HOUR_BEGIN 20 - #define NIGHT_HOUR_END 6 -#endif - -// TIMES_OF_DAY_COUNT must be last -enum TimeOfDay -{ - TIME_MORNING, - TIME_DAY, - TIME_EVENING, - TIME_NIGHT, - TIMES_OF_DAY_COUNT, -}; - -#define TIME_OF_DAY_DEFAULT 0 +#include "constants/rtc.h" extern struct Time gLocalTime; -extern const s32 sNumDaysInMonths[12]; +extern const s32 sNumDaysInMonths[MONTH_COUNT]; void RtcDisableInterrupts(void); void RtcRestoreInterrupts(void); diff --git a/include/siirtc.h b/include/siirtc.h index 8e6958ca08..44dabfd11d 100644 --- a/include/siirtc.h +++ b/include/siirtc.h @@ -2,45 +2,7 @@ #define GUARD_RTC_H #include "gba/gba.h" - -#define SIIRTCINFO_INTFE 0x01 // frequency interrupt enable -#define SIIRTCINFO_INTME 0x02 // per-minute interrupt enable -#define SIIRTCINFO_INTAE 0x04 // alarm interrupt enable -#define SIIRTCINFO_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode -#define SIIRTCINFO_POWER 0x80 // power on or power failure occurred - -#define HOURS_PER_DAY 24 -#define MINUTES_PER_HOUR 60 -#define SECONDS_PER_MINUTE 60 - -enum Weekday -{ - WEEKDAY_SUN, - WEEKDAY_MON, - WEEKDAY_TUE, - WEEKDAY_WED, - WEEKDAY_THU, - WEEKDAY_FRI, - WEEKDAY_SAT, - WEEKDAY_COUNT, -}; - -enum Month -{ - MONTH_JAN = 1, - MONTH_FEB, - MONTH_MAR, - MONTH_APR, - MONTH_MAY, - MONTH_JUN, - MONTH_JUL, - MONTH_AUG, - MONTH_SEP, - MONTH_OCT, - MONTH_NOV, - MONTH_DEC, - MONTH_COUNT = MONTH_DEC -}; +#include "constants/siirtc.h" struct SiiRtcInfo { diff --git a/tools/wild_encounters/wild_encounters_to_header.py b/tools/wild_encounters/wild_encounters_to_header.py index cdf3777735..3aab5a2632 100644 --- a/tools/wild_encounters/wild_encounters_to_header.py +++ b/tools/wild_encounters/wild_encounters_to_header.py @@ -533,7 +533,7 @@ def IsConfigEnabled(): def GetTimeEnum(): DEFAULT_TIME_PAT = re.compile(r"enum\s+TimeOfDay\s*\{(?P[\s*\w+,\=\d*]+)\s*\}\s*\;") - with open("./include/rtc.h", "r") as rtc_include_file: + with open("./include/constants/rtc.h", "r") as rtc_include_file: include_rtc = rtc_include_file.read() include_enum = DEFAULT_TIME_PAT.search(include_rtc) return include_enum.group("rtc_val")