Added the option of using host (PC) time or guest (GBA) time for the RTC. Checking the "Real time clock" option in the menu uses host time otherwise it uses guest time. Using guest time will mean that the clock speeds up or slows down with the speed of emulation.
This commit is contained in:
parent
3ae673b85d
commit
23cdd50acb
|
@ -3823,6 +3823,8 @@ void CPULoop(int ticks)
|
|||
|
||||
cpuTotalTicks += clockTicks;
|
||||
|
||||
if (rtcIsEnabled())
|
||||
rtcUpdateTime(cpuTotalTicks);
|
||||
|
||||
if(cpuTotalTicks >= cpuNextEvent) {
|
||||
int remainingTicks = cpuTotalTicks - cpuNextEvent;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "../System.h"
|
||||
|
||||
const u64 TICKS_PER_SECOND = 16777216;
|
||||
|
||||
#define SAVE_GAME_VERSION_1 1
|
||||
#define SAVE_GAME_VERSION_2 2
|
||||
#define SAVE_GAME_VERSION_3 3
|
||||
|
|
|
@ -225,8 +225,7 @@ static ConnectionState ConnectUpdateSocket(char * const message, size_t size);
|
|||
static void UpdateCableSocket(int ticks);
|
||||
static void CloseSocket();
|
||||
|
||||
const u64 TICKS_PER_FRAME = 16777216 / 60;
|
||||
const u64 TICKS_PER_SECOND = 16777216;
|
||||
const u64 TICKS_PER_FRAME = TICKS_PER_SECOND / 60;
|
||||
const u64 BITS_PER_SECOND = 115200;
|
||||
const u64 BYTES_PER_SECOND = BITS_PER_SECOND / 8;
|
||||
|
||||
|
|
|
@ -32,10 +32,13 @@ typedef struct {
|
|||
u32 reserved3;
|
||||
} RTCCLOCKDATA;
|
||||
|
||||
struct tm gba_time;
|
||||
static RTCCLOCKDATA rtcClockData;
|
||||
static bool rtcClockEnabled = true;
|
||||
static bool rtcRumbleEnabled = false;
|
||||
|
||||
u32 countTicks = 0;
|
||||
|
||||
void rtcEnable(bool e)
|
||||
{
|
||||
rtcClockEnabled = e;
|
||||
|
@ -98,6 +101,25 @@ static u8 toBCD(u8 value)
|
|||
return h * 16 + l;
|
||||
}
|
||||
|
||||
void SetGBATime()
|
||||
{
|
||||
time_t long_time;
|
||||
|
||||
time(&long_time); /* Get time as long integer. */
|
||||
gba_time = *localtime(&long_time); /* Convert to local time. */
|
||||
countTicks = 0;
|
||||
}
|
||||
|
||||
void rtcUpdateTime(int ticks)
|
||||
{
|
||||
countTicks += ticks;
|
||||
if (countTicks > TICKS_PER_SECOND)
|
||||
{
|
||||
countTicks -= TICKS_PER_SECOND;
|
||||
gba_time.tm_sec++;
|
||||
}
|
||||
}
|
||||
|
||||
bool rtcWrite(u32 address, u16 value)
|
||||
{
|
||||
if(address == 0x80000c8) {
|
||||
|
@ -175,35 +197,27 @@ bool rtcWrite(u32 address, u16 value)
|
|||
break;
|
||||
case 0x65:
|
||||
{
|
||||
struct tm *newtime;
|
||||
time_t long_time;
|
||||
|
||||
time( &long_time ); /* Get time as long integer. */
|
||||
newtime = localtime( &long_time ); /* Convert to local time. */
|
||||
|
||||
if (rtcEnabled)
|
||||
SetGBATime();
|
||||
rtcClockData.dataLen = 7;
|
||||
rtcClockData.data[0] = toBCD(newtime->tm_year);
|
||||
rtcClockData.data[1] = toBCD(newtime->tm_mon+1);
|
||||
rtcClockData.data[2] = toBCD(newtime->tm_mday);
|
||||
rtcClockData.data[3] = toBCD(newtime->tm_wday);
|
||||
rtcClockData.data[4] = toBCD(newtime->tm_hour);
|
||||
rtcClockData.data[5] = toBCD(newtime->tm_min);
|
||||
rtcClockData.data[6] = toBCD(newtime->tm_sec);
|
||||
rtcClockData.data[0] = toBCD(gba_time.tm_year);
|
||||
rtcClockData.data[1] = toBCD(gba_time.tm_mon+1);
|
||||
rtcClockData.data[2] = toBCD(gba_time.tm_mday);
|
||||
rtcClockData.data[3] = toBCD(gba_time.tm_wday);
|
||||
rtcClockData.data[4] = toBCD(gba_time.tm_hour);
|
||||
rtcClockData.data[5] = toBCD(gba_time.tm_min);
|
||||
rtcClockData.data[6] = toBCD(gba_time.tm_sec);
|
||||
rtcClockData.state = DATA;
|
||||
}
|
||||
break;
|
||||
case 0x67:
|
||||
{
|
||||
struct tm *newtime;
|
||||
time_t long_time;
|
||||
|
||||
time( &long_time ); /* Get time as long integer. */
|
||||
newtime = localtime( &long_time ); /* Convert to local time. */
|
||||
|
||||
if (rtcEnabled)
|
||||
SetGBATime();
|
||||
rtcClockData.dataLen = 3;
|
||||
rtcClockData.data[0] = toBCD(newtime->tm_hour);
|
||||
rtcClockData.data[1] = toBCD(newtime->tm_min);
|
||||
rtcClockData.data[2] = toBCD(newtime->tm_sec);
|
||||
rtcClockData.data[0] = toBCD(gba_time.tm_hour);
|
||||
rtcClockData.data[1] = toBCD(gba_time.tm_min);
|
||||
rtcClockData.data[2] = toBCD(gba_time.tm_sec);
|
||||
rtcClockData.state = DATA;
|
||||
}
|
||||
break;
|
||||
|
@ -262,6 +276,8 @@ void rtcReset()
|
|||
rtcClockData.bits = 0;
|
||||
rtcClockData.state = IDLE;
|
||||
rtcClockData.reserved[11] = 0;
|
||||
|
||||
SetGBATime();
|
||||
}
|
||||
|
||||
#ifdef __LIBRETRO__
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define RTC_H
|
||||
|
||||
u16 rtcRead(u32 address);
|
||||
void rtcUpdateTime(int ticks);
|
||||
bool rtcWrite(u32 address, u16 value);
|
||||
void rtcEnable(bool);
|
||||
void rtcEnableRumble(bool e);
|
||||
|
|
Loading…
Reference in New Issue