mirror of https://github.com/mgba-emu/mgba.git
Core: Add mRTCGenericSource
This commit is contained in:
parent
59f78a05e4
commit
ed176177ce
|
@ -33,6 +33,10 @@ 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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -31,4 +31,19 @@ struct mRTCSource {
|
|||
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
|
||||
|
|
|
@ -98,6 +98,22 @@ static void _GBCoreSetKeys(struct mCore* core, uint32_t keys) {
|
|||
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 @@ struct mCore* GBCoreCreate(void) {
|
|||
core->runLoop = _GBCoreRunLoop;
|
||||
core->step = _GBCoreStep;
|
||||
core->setKeys = _GBCoreSetKeys;
|
||||
core->frameCounter = _GBCoreFrameCounter;
|
||||
core->frameCycles = _GBCoreFrameCycles;
|
||||
core->frequency = _GBCoreFrequency;
|
||||
return core;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -952,16 +952,16 @@ void GameController::setLuminanceLevel(int level) {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue