src/core/interface.c (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include <mgba/core/interface.h>
7
8#include <mgba/core/core.h>
9#include <time.h>
10
11static time_t _rtcGenericCallback(struct mRTCSource* source) {
12 struct mRTCGenericSource* rtc = (struct mRTCGenericSource*) source;
13 switch (rtc->override) {
14 case RTC_NO_OVERRIDE:
15 default:
16 return time(0);
17 case RTC_FIXED:
18 return rtc->value;
19 case RTC_FAKE_EPOCH:
20 return rtc->value + rtc->p->frameCounter(rtc->p) * (int64_t) rtc->p->frameCycles(rtc->p) / rtc->p->frequency(rtc->p);
21 }
22}
23
24void mRTCGenericSourceInit(struct mRTCGenericSource* rtc, struct mCore* core) {
25 rtc->p = core;
26 rtc->override = RTC_NO_OVERRIDE;
27 rtc->value = 0;
28 rtc->d.sample = 0;
29 rtc->d.unixTime = _rtcGenericCallback;
30}