Files
Adrian "asie" SiekierkaandSour 22424d7412 WS: Initial cartridge RTC implementation (#98)
* GBA: Separate S3511A RTC emulation code from GBA interface emulation code.

* WS: Initial cartridge RTC implementation.

* WS: Expose cartridge RTC state to register viewer.

* Code: Fix formatting.

* WS: Update Core.vcxproj.

* Fix compilation error, remove unused method

---------

Co-authored-by: Sour <[email protected]>
2026-05-19 05:50:19 -07:00

55 lines
893 B
C++

#include "pch.h"
#include "GBA/Cart/GbaRtc.h"
#include "Shared/Utilities/S3511ARtc.h"
#include "Utilities/Serializer.h"
GbaRtc::GbaRtc(Emulator* emu) : S3511ARtc(emu)
{
}
uint8_t GbaRtc::Read()
{
if(_chipSelect) {
return (_chipSelect << 2) | (_bitOut << 1) | _clk;
} else {
return 0x07;
}
}
void GbaRtc::Write(uint8_t value)
{
uint8_t clk = value & 0x01;
//Writes use the data that was set in bit 1 on the previous write
uint8_t data = (_prevValue & 0x02) >> 1;
_prevValue = value;
bool chipSelect = value & 0x04;
if(!chipSelect || !_chipSelect) {
ResetBus();
_clk = 0;
_bitOut = 1;
_chipSelect = chipSelect;
return;
}
if(clk && !_clk) {
WriteBits(data, 1);
} else if(!clk && _clk) {
_bitOut = ReadBits(1);
}
_clk = clk;
}
void GbaRtc::Serialize(Serializer& s)
{
S3511ARtc::Serialize(s);
SV(_clk);
SV(_bitOut);
SV(_chipSelect);
SV(_prevValue);
}