Skip to content

Commit 039f8e9

Browse files
Improve GBA RTC
Implements various improvements to GBA RTC. Primarily, this allows for RTC to actually be reset and set by games, instead of it being forced into matching host time. Time registers are now just incremented as host time increases, like other RTC implementations in mGBA (e.g. MBC3 / HuC3). "Test mode" is also implemented to the degree it seems to do anything (which just seems to prevent commands from working, except exit test mode and reset commands). It is internally stored in bit 7 of the seconds byte, as documented in spec sheets (although this is impossible to verify it seems, due to get time commands no longer working). Invalid / write-only commands now return a stream of 1-bits (rather than 0-bits), as on hardware. The PM flag is now properly implemented (so software can actually use 12 hour mode fully). Only valid RTC control bits can actually be written now (unused bits are always 0; power-off bit is not settable but it is clearable). The alarm command is "implemented" here as a stub (the alarm registers are just write only here, so nothing to do without alarms actually being implemented with cartridge IRQ; although I haven't verified yet if cartridge IRQ should actually be triggered or whatever).
1 parent 8740f3d commit 039f8e9

3 files changed

Lines changed: 337 additions & 86 deletions

File tree

include/mgba/internal/gba/cart/gpio.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ DECL_BIT(RTCControl, Poweroff, 7);
3636

3737
enum RTCCommand {
3838
RTC_RESET = 0,
39+
RTC_ALARM = 1,
3940
RTC_DATETIME = 2,
40-
RTC_FORCE_IRQ = 3,
41+
RTC_TEST_START = 3,
4142
RTC_CONTROL = 4,
42-
RTC_TIME = 6
43+
RTC_TIME = 6,
44+
RTC_TEST_END = 7
45+
};
46+
47+
enum RTCDateTime {
48+
RTC_YEARS = 0,
49+
RTC_MONTHS = 1,
50+
RTC_DAYS = 2,
51+
RTC_WEEKDAY = 3,
52+
RTC_HOURS = 4,
53+
RTC_MINUTES = 5,
54+
RTC_SECONDS = 6
4355
};
4456

4557
DECL_BITFIELD(RTCCommandData, uint32_t);
@@ -57,7 +69,6 @@ struct GBARTC {
5769
RTCControl control;
5870
uint8_t time[7];
5971
time_t lastLatch;
60-
time_t offset;
6172
};
6273

6374
DECL_BITFIELD(GPIOPin, uint16_t);
@@ -100,6 +111,8 @@ void GBAHardwareGPIOWrite(struct GBACartridgeHardware* gpio, uint32_t address, u
100111
void GBAHardwareTiltWrite(struct GBACartridgeHardware* gpio, uint32_t address, uint8_t value);
101112
uint8_t GBAHardwareTiltRead(struct GBACartridgeHardware* gpio, uint32_t address);
102113

114+
void GBAHardwareRTCSanitize(struct GBACartridgeHardware* gpio);
115+
103116
struct GBASerializedState;
104117
void GBAHardwareSerialize(const struct GBACartridgeHardware* gpio, struct GBASerializedState* state);
105118
void GBAHardwareDeserialize(struct GBACartridgeHardware* gpio, const struct GBASerializedState* state);

0 commit comments

Comments
 (0)