summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/data2.s3
-rw-r--r--iwram_syms.txt13
-rw-r--r--ld_script.txt5
-rw-r--r--src/rtc.c78
4 files changed, 52 insertions, 47 deletions
diff --git a/data/data2.s b/data/data2.s
index 1b6f49224..4e171b5ce 100644
--- a/data/data2.s
+++ b/data/data2.s
@@ -5,9 +5,6 @@
.section .rodata
-@ 81E7610
- .include "data/rtc.s"
-
.global gUnknown_081E764C
gUnknown_081E764C: @ 81E764C
.incbin "baserom.gba", 0x001e764c, 0x40
diff --git a/iwram_syms.txt b/iwram_syms.txt
index 1d2b918c7..fa48f9cf1 100644
--- a/iwram_syms.txt
+++ b/iwram_syms.txt
@@ -1,24 +1,11 @@
/* .bss starts at 0x3000000 */
-gRtcErrorStatus = 0x3000458;
-gRtc = 0x3000460;
-gRtcProbeResult = 0x300046C;
-gRtcSavedIme = 0x300046E;
-
gPlayTimeCounterState = 0x300057C;
/* .bss.code starts at 0x3000F60 */
/* COMMON starts at 0x3001760 */
-gUnknownStringVar = 0x3002900;
-
-gUnknown_3002A20 = 0x3002A20;
-gUnknown_3002A60 = 0x3002A60;
-gUnknown_3002F90 = 0x3002F90;
-gUnknown_3003040 = 0x3003040;
-gUnknown_30033A9 = 0x30033A9;
-
gLocalTime = 0x3004038;
gUnknown_3004820 = 0x3004820;
diff --git a/ld_script.txt b/ld_script.txt
index 21b1e9a2f..aea25d62b 100644
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -15,6 +15,7 @@ SECTIONS {
src/string_util.o(ewram_data);
. += 0x2E8; /* big gap */
src/link.o(ewram_data);
+ src/rtc.o(ewram_data);
}
. = 0x3000000;
@@ -27,6 +28,8 @@ SECTIONS {
src/text.o(.bss);
src/string_util.o(.bss);
src/link.o(.bss);
+ src/rtc.o(.bss);
+
. = 0xF28;
src/agb_flash.o(.bss);
. = 0xF36;
@@ -41,6 +44,7 @@ SECTIONS {
src/text.o(iwram_data);
src/string_util.o(iwram_data);
src/link.o(iwram_data);
+ src/rtc.o(iwram_data);
. = 0x5FD0;
src/m4a_2.o(iwram_data);
@@ -110,6 +114,7 @@ SECTIONS {
src/text.o(.rodata);
src/string_util.o(.rodata);
src/link.o(.rodata);
+ src/rtc.o(.rodata);
data/data2.o(.rodata);
src/m4a_tables.o(.rodata);
data/sound_data.o(.rodata);
diff --git a/src/rtc.c b/src/rtc.c
index 39fb23158..ccf8ad078 100644
--- a/src/rtc.c
+++ b/src/rtc.c
@@ -4,16 +4,32 @@
#include "string_util.h"
#include "text.h"
-extern const struct SiiRtcInfo gRtcDummy;
-extern const s32 gNumDaysInMonths[];
-
-extern u16 gRtcErrorStatus;
-extern struct SiiRtcInfo gRtc;
-extern u8 gRtcProbeResult;
-extern u16 gRtcSavedIme;
+static u16 sErrorStatus;
+static struct SiiRtcInfo sRtc;
+static u8 sProbeResult;
+static u16 sSavedIme;
+// TODO: Define this in C. Gas prevents it from working at the moment.
extern struct Time gLocalTime;
+static const struct SiiRtcInfo sRtcDummy = {0, MONTH_JAN, 1}; // 2000 Jan 1
+
+static const s32 sNumDaysInMonths[12] =
+{
+ 31,
+ 28,
+ 31,
+ 30,
+ 31,
+ 30,
+ 31,
+ 31,
+ 30,
+ 31,
+ 30,
+ 31,
+};
+
void RtcDisableInterrupts();
void RtcRestoreInterrupts();
u32 ConvertBcdToBinary(u8 bcd);
@@ -29,13 +45,13 @@ void RtcCalcTimeDifference(struct SiiRtcInfo *rtc, struct Time *result, struct T
void RtcDisableInterrupts()
{
- gRtcSavedIme = REG_IME;
+ sSavedIme = REG_IME;
REG_IME = 0;
}
void RtcRestoreInterrupts()
{
- REG_IME = gRtcSavedIme;
+ REG_IME = sSavedIme;
}
u32 ConvertBcdToBinary(u8 bcd)
@@ -85,7 +101,7 @@ u16 ConvertDateToDayCount(u8 year, u8 month, u8 day)
#endif
for (i = 0; i < month - 1; i++)
- dayCount += gNumDaysInMonths[i];
+ dayCount += sNumDaysInMonths[i];
if (month > MONTH_FEB && IsLeapYear(year) == TRUE)
dayCount++;
@@ -105,37 +121,37 @@ u16 RtcGetDayCount(struct SiiRtcInfo *rtc)
void RtcInit()
{
- gRtcErrorStatus = 0;
+ sErrorStatus = 0;
RtcDisableInterrupts();
SiiRtcUnprotect();
- gRtcProbeResult = SiiRtcProbe();
+ sProbeResult = SiiRtcProbe();
RtcRestoreInterrupts();
- if (!(gRtcProbeResult & 0xF))
+ if (!(sProbeResult & 0xF))
{
- gRtcErrorStatus = RTC_INIT_ERROR;
+ sErrorStatus = RTC_INIT_ERROR;
return;
}
- if (gRtcProbeResult & 0xF0)
- gRtcErrorStatus = RTC_INIT_WARNING;
+ if (sProbeResult & 0xF0)
+ sErrorStatus = RTC_INIT_WARNING;
else
- gRtcErrorStatus = 0;
+ sErrorStatus = 0;
- RtcGetRawInfo(&gRtc);
- gRtcErrorStatus = RtcCheckInfo(&gRtc);
+ RtcGetRawInfo(&sRtc);
+ sErrorStatus = RtcCheckInfo(&sRtc);
}
u16 RtcGetErrorStatus()
{
- return gRtcErrorStatus;
+ return sErrorStatus;
}
void RtcGetInfo(struct SiiRtcInfo *rtc)
{
- if (gRtcErrorStatus & RTC_ERR_FLAG_MASK)
- *rtc = gRtcDummy;
+ if (sErrorStatus & RTC_ERR_FLAG_MASK)
+ *rtc = sRtcDummy;
else
RtcGetRawInfo(rtc);
}
@@ -190,12 +206,12 @@ u16 RtcCheckInfo(struct SiiRtcInfo *rtc)
if (month == MONTH_FEB)
{
- if (value > IsLeapYear(year) + gNumDaysInMonths[month - 1])
+ if (value > IsLeapYear(year) + sNumDaysInMonths[month - 1])
errorFlags |= RTC_ERR_INVALID_DAY;
}
else
{
- if (value > gNumDaysInMonths[month - 1])
+ if (value > sNumDaysInMonths[month - 1])
errorFlags |= RTC_ERR_INVALID_DAY;
}
@@ -246,7 +262,7 @@ void FormatHexTime(u8 *dest, s32 hour, s32 minute, s32 second)
void FormatHexRtcTime(u8 *dest)
{
- FormatHexTime(dest, gRtc.hour, gRtc.minute, gRtc.second);
+ FormatHexTime(dest, sRtc.hour, sRtc.minute, sRtc.second);
}
void FormatDecimalDate(u8 *dest, s32 year, s32 month, s32 day)
@@ -298,8 +314,8 @@ void RtcCalcTimeDifference(struct SiiRtcInfo *rtc, struct Time *result, struct T
void RtcCalcLocalTime()
{
- RtcGetInfo(&gRtc);
- RtcCalcTimeDifference(&gRtc, &gLocalTime, &gSaveBlock2.localTimeOffset);
+ RtcGetInfo(&sRtc);
+ RtcCalcTimeDifference(&sRtc, &gLocalTime, &gSaveBlock2.localTimeOffset);
}
void RtcInitLocalTimeOffset(s32 hour, s32 minute)
@@ -313,8 +329,8 @@ void RtcCalcLocalTimeOffset(s32 days, s32 hours, s32 minutes, s32 seconds)
gLocalTime.hours = hours;
gLocalTime.minutes = minutes;
gLocalTime.seconds = seconds;
- RtcGetInfo(&gRtc);
- RtcCalcTimeDifference(&gRtc, &gSaveBlock2.localTimeOffset, &gLocalTime);
+ RtcGetInfo(&sRtc);
+ RtcCalcTimeDifference(&sRtc, &gSaveBlock2.localTimeOffset, &gLocalTime);
}
void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2)
@@ -345,6 +361,6 @@ void CalcTimeDifference(struct Time *result, struct Time *t1, struct Time *t2)
u32 RtcGetMinuteCount()
{
- RtcGetInfo(&gRtc);
- return (24 * 60) * RtcGetDayCount(&gRtc) + 60 * gRtc.hour + gRtc.minute;
+ RtcGetInfo(&sRtc);
+ return (24 * 60) * RtcGetDayCount(&sRtc) + 60 * sRtc.hour + sRtc.minute;
}