Core: Add mRTCGenericSource
Jeffrey Pfau jeffrey@endrift.com
Fri, 29 Jan 2016 23:00:49 -0800
6 files changed,
72 insertions(+),
8 deletions(-)
M
src/core/core.h
→
src/core/core.h
@@ -33,6 +33,10 @@ void (*runLoop)(struct mCore*);
void (*step)(struct mCore*); void (*setKeys)(struct mCore*, uint32_t keys); + + int32_t (*frameCounter)(struct mCore*); + int32_t (*frameCycles)(struct mCore*); + int32_t (*frequency)(struct mCore*); }; #endif
A
src/core/interface.c
@@ -0,0 +1,30 @@
+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "interface.h" + +#include "core/core.h" +#include <time.h> + +static time_t _rtcGenericCallback(struct mRTCSource* source) { + struct mRTCGenericSource* rtc = (struct mRTCGenericSource*) source; + switch (rtc->override) { + case RTC_NO_OVERRIDE: + default: + return time(0); + case RTC_FIXED: + return rtc->value; + case RTC_FAKE_EPOCH: + return rtc->value + rtc->p->frameCounter(rtc->p) * (int64_t) rtc->p->frameCycles(rtc->p) / rtc->p->frequency(rtc->p); + } +} + +void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core) { + rtc->p = core; + rtc->override = RTC_NO_OVERRIDE; + rtc->value = 0; + rtc->d.sample = 0; + rtc->d.unixTime = _rtcGenericCallback; +}
M
src/core/interface.h
→
src/core/interface.h
@@ -31,4 +31,19 @@
time_t (*unixTime)(struct mRTCSource*); }; +enum mRTCGenericType { + RTC_NO_OVERRIDE, + RTC_FIXED, + RTC_FAKE_EPOCH +}; + +struct mRTCGenericSource { + struct mRTCSource d; + struct mCore* p; + enum mRTCGenericType override; + int64_t value; +}; + +void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core); + #endif
M
src/gb/core.c
→
src/gb/core.c
@@ -98,6 +98,22 @@ struct GBCore* gbcore = (struct GBCore*) core;
gbcore->keys = keys; } +static int32_t _GBCoreFrameCounter(struct mCore* core) { + struct GB* gb = core->board; + return gb->video.frameCounter; +} + +static int32_t _GBCoreFrameCycles(struct mCore* core) { + UNUSED(core); + return GB_VIDEO_TOTAL_LENGTH; +} + +static int32_t _GBCoreFrequency(struct mCore* core) { + UNUSED(core); + // TODO: GB differences + return DMG_LR35902_FREQUENCY; +} + struct mCore* GBCoreCreate(void) { struct GBCore* gbcore = malloc(sizeof(*gbcore)); struct mCore* core = &gbcore->d;@@ -115,5 +131,8 @@ core->runFrame = _GBCoreRunFrame;
core->runLoop = _GBCoreRunLoop; core->step = _GBCoreStep; core->setKeys = _GBCoreSetKeys; + core->frameCounter = _GBCoreFrameCounter; + core->frameCycles = _GBCoreFrameCycles; + core->frequency = _GBCoreFrequency; return core; }
M
src/gba/hardware.h
→
src/gba/hardware.h
@@ -18,11 +18,7 @@
struct GBARTCGenericSource { struct mRTCSource d; struct GBA* p; - enum { - RTC_NO_OVERRIDE, - RTC_FIXED, - RTC_FAKE_EPOCH - } override; + enum mRTCGenericType override; int64_t value; };
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -952,16 +952,16 @@ setLuminanceValue(value);
} void GameController::setRealTime() { - m_rtc.override = GBARTCGenericSource::RTC_NO_OVERRIDE; + m_rtc.override = RTC_NO_OVERRIDE; } void GameController::setFixedTime(const QDateTime& time) { - m_rtc.override = GBARTCGenericSource::RTC_FIXED; + m_rtc.override = RTC_FIXED; m_rtc.value = time.toMSecsSinceEpoch() / 1000; } void GameController::setFakeEpoch(const QDateTime& time) { - m_rtc.override = GBARTCGenericSource::RTC_FAKE_EPOCH; + m_rtc.override = RTC_FAKE_EPOCH; m_rtc.value = time.toMSecsSinceEpoch() / 1000; }