Slight RTC documentation + Evolution times constants

This commit is contained in:
Eduardo Quezada 2023-09-17 13:45:06 -03:00
parent de3493ff0e
commit fb6f45b2c3
3 changed files with 38 additions and 27 deletions

View file

@ -9,6 +9,10 @@
#define SIIRTCINFO_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode #define SIIRTCINFO_24HOUR 0x40 // 0: 12-hour mode, 1: 24-hour mode
#define SIIRTCINFO_POWER 0x80 // power on or power failure occurred #define SIIRTCINFO_POWER 0x80 // power on or power failure occurred
#define DAY_HOURS 24
#define HOUR_MINUTES 60
#define MINUTE_SECONDS 60
enum enum
{ {
MONTH_JAN = 1, MONTH_JAN = 1,
@ -22,7 +26,8 @@ enum
MONTH_SEP, MONTH_SEP,
MONTH_OCT, MONTH_OCT,
MONTH_NOV, MONTH_NOV,
MONTH_DEC MONTH_DEC,
MONTH_COUNT = MONTH_DEC
}; };
struct SiiRtcInfo struct SiiRtcInfo

View file

@ -48,6 +48,12 @@
#include "constants/trainers.h" #include "constants/trainers.h"
#include "constants/union_room.h" #include "constants/union_room.h"
#define DAY_EVO_HOUR_BEGIN 12
#define DAY_EVO_HOUR_END DAY_HOURS
#define NIGHT_EVO_HOUR_BEGIN 0
#define NIGHT_EVO_HOUR_END 12
struct SpeciesItem struct SpeciesItem
{ {
u16 species; u16 species;
@ -5498,12 +5504,12 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem)
break; break;
case EVO_FRIENDSHIP_DAY: case EVO_FRIENDSHIP_DAY:
RtcCalcLocalTime(); RtcCalcLocalTime();
if (gLocalTime.hours >= 12 && gLocalTime.hours < 24 && friendship >= 220) if (gLocalTime.hours >= DAY_EVO_HOUR_BEGIN && gLocalTime.hours < DAY_EVO_HOUR_END && friendship >= 220)
targetSpecies = gEvolutionTable[species][i].targetSpecies; targetSpecies = gEvolutionTable[species][i].targetSpecies;
break; break;
case EVO_FRIENDSHIP_NIGHT: case EVO_FRIENDSHIP_NIGHT:
RtcCalcLocalTime(); RtcCalcLocalTime();
if (gLocalTime.hours >= 0 && gLocalTime.hours < 12 && friendship >= 220) if (gLocalTime.hours >= NIGHT_EVO_HOUR_BEGIN && gLocalTime.hours < NIGHT_EVO_HOUR_END && friendship >= 220)
targetSpecies = gEvolutionTable[species][i].targetSpecies; targetSpecies = gEvolutionTable[species][i].targetSpecies;
break; break;
case EVO_LEVEL: case EVO_LEVEL:

View file

@ -16,20 +16,20 @@ struct Time gLocalTime;
static const struct SiiRtcInfo sRtcDummy = {0, MONTH_JAN, 1}; // 2000 Jan 1 static const struct SiiRtcInfo sRtcDummy = {0, MONTH_JAN, 1}; // 2000 Jan 1
static const s32 sNumDaysInMonths[12] = static const s32 sNumDaysInMonths[MONTH_COUNT] =
{ {
31, [MONTH_JAN - 1] = 31,
28, [MONTH_FEB - 1] = 28,
31, [MONTH_MAR - 1] = 31,
30, [MONTH_APR - 1] = 30,
31, [MONTH_MAY - 1] = 31,
30, [MONTH_JUN - 1] = 30,
31, [MONTH_JUL - 1] = 31,
31, [MONTH_AUG - 1] = 31,
30, [MONTH_SEP - 1] = 30,
31, [MONTH_OCT - 1] = 31,
30, [MONTH_NOV - 1] = 30,
31, [MONTH_DEC - 1] = 31,
}; };
void RtcDisableInterrupts(void) void RtcDisableInterrupts(void)
@ -171,7 +171,7 @@ u16 RtcCheckInfo(struct SiiRtcInfo *rtc)
month = ConvertBcdToBinary(rtc->month); month = ConvertBcdToBinary(rtc->month);
if (month == 0xFF || month == 0 || month > 12) if (month == 0xFF || month == 0 || month > MONTH_COUNT)
errorFlags |= RTC_ERR_INVALID_MONTH; errorFlags |= RTC_ERR_INVALID_MONTH;
value = ConvertBcdToBinary(rtc->day); value = ConvertBcdToBinary(rtc->day);
@ -192,17 +192,17 @@ u16 RtcCheckInfo(struct SiiRtcInfo *rtc)
value = ConvertBcdToBinary(rtc->hour); value = ConvertBcdToBinary(rtc->hour);
if (value > 24) if (value > DAY_HOURS)
errorFlags |= RTC_ERR_INVALID_HOUR; errorFlags |= RTC_ERR_INVALID_HOUR;
value = ConvertBcdToBinary(rtc->minute); value = ConvertBcdToBinary(rtc->minute);
if (value > 60) if (value > HOUR_MINUTES)
errorFlags |= RTC_ERR_INVALID_MINUTE; errorFlags |= RTC_ERR_INVALID_MINUTE;
value = ConvertBcdToBinary(rtc->second); value = ConvertBcdToBinary(rtc->second);
if (value > 60) if (value > MINUTE_SECONDS)
errorFlags |= RTC_ERR_INVALID_SECOND; errorFlags |= RTC_ERR_INVALID_SECOND;
return errorFlags; return errorFlags;
@ -270,19 +270,19 @@ void RtcCalcTimeDifference(struct SiiRtcInfo *rtc, struct Time *result, struct T
if (result->seconds < 0) if (result->seconds < 0)
{ {
result->seconds += 60; result->seconds += MINUTE_SECONDS;
--result->minutes; --result->minutes;
} }
if (result->minutes < 0) if (result->minutes < 0)
{ {
result->minutes += 60; result->minutes += HOUR_MINUTES;
--result->hours; --result->hours;
} }
if (result->hours < 0) if (result->hours < 0)
{ {
result->hours += 24; result->hours += DAY_HOURS;
--result->days; --result->days;
} }
} }
@ -317,19 +317,19 @@ void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2)
if (result->seconds < 0) if (result->seconds < 0)
{ {
result->seconds += 60; result->seconds += MINUTE_SECONDS;
--result->minutes; --result->minutes;
} }
if (result->minutes < 0) if (result->minutes < 0)
{ {
result->minutes += 60; result->minutes += HOUR_MINUTES;
--result->hours; --result->hours;
} }
if (result->hours < 0) if (result->hours < 0)
{ {
result->hours += 24; result->hours += DAY_HOURS;
--result->days; --result->days;
} }
} }
@ -337,7 +337,7 @@ void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2)
u32 RtcGetMinuteCount(void) u32 RtcGetMinuteCount(void)
{ {
RtcGetInfo(&sRtc); RtcGetInfo(&sRtc);
return (24 * 60) * RtcGetDayCount(&sRtc) + 60 * sRtc.hour + sRtc.minute; return (DAY_HOURS * HOUR_MINUTES) * RtcGetDayCount(&sRtc) + HOUR_MINUTES * sRtc.hour + sRtc.minute;
} }
u32 RtcGetLocalDayCount(void) u32 RtcGetLocalDayCount(void)