summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYamaArashi <shadow962@live.com>2016-02-03 02:11:31 -0800
committerYamaArashi <shadow962@live.com>2016-02-03 02:14:14 -0800
commit33005cef6bd2eb65b997423260ee94a987f076c4 (patch)
treec6d786512fa9efc1a558526b2f0af6c26837e52c
parentd7894a90f4c355a9dd15d5fd7a3e739075103bba (diff)
preliminary revision 2 support (fixing berry glitch)
-rw-r--r--include/global.h4
-rw-r--r--src/rtc_util.c14
2 files changed, 18 insertions, 0 deletions
diff --git a/include/global.h b/include/global.h
index 1747446f3..8987fdf6a 100644
--- a/include/global.h
+++ b/include/global.h
@@ -3,6 +3,10 @@
#include "gba/gba.h"
+#ifndef REVISION
+#define REVISION 0
+#endif
+
extern u8 gStringVar1[];
extern u8 gStringVar2[];
extern u8 gStringVar3[];
diff --git a/src/rtc_util.c b/src/rtc_util.c
index 0149fcdc7..ba69d1d67 100644
--- a/src/rtc_util.c
+++ b/src/rtc_util.c
@@ -61,6 +61,9 @@ u16 ConvertDateToDayCount(u8 year, u8 month, u8 day)
s32 i;
u16 dayCount = 0;
+#if (REVISION < 2)
+ // Revisions 0 and 1 don't add days for the year 2000,
+ // causing the berry glitch.
for (i = year - 1; i > 0; i--)
{
dayCount += 365;
@@ -68,6 +71,17 @@ u16 ConvertDateToDayCount(u8 year, u8 month, u8 day)
if (IsLeapYear(i) == TRUE)
dayCount++;
}
+#else
+ // Revision 2 has "i >= 0" as the condition instead of "i > 0",
+ // which fixes the issue.
+ for (i = year - 1; i >= 0; i--)
+ {
+ dayCount += 365;
+
+ if (IsLeapYear(i) == TRUE)
+ dayCount++;
+ }
+#endif
for (i = 0; i < month - 1; i++)
dayCount += gNumDaysInMonths[i];