Qt: RTC overrides

This commit is contained in:
Jeffrey Pfau 2015-01-01 03:01:40 -08:00
parent f534638342
commit 8c0f082a83
6 changed files with 107 additions and 15 deletions

View File

@ -53,6 +53,8 @@ void GBAVideoReset(struct GBAVideo* video) {
video->nextVblankIRQ = 0;
video->nextVcounterIRQ = 0;
video->frameCounter = 0;
if (video->vram) {
mappedMemoryFree(video->vram, SIZE_VRAM);
}
@ -115,6 +117,7 @@ int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles) {
GBARaiseIRQ(video->p, IRQ_VBLANK);
}
GBASyncPostFrame(video->p->sync);
++video->frameCounter;
break;
case VIDEO_VERTICAL_TOTAL_PIXELS - 1:
if (video->p->rr) {

View File

@ -190,6 +190,8 @@ struct GBAVideo {
uint16_t palette[SIZE_PALETTE_RAM >> 1];
uint16_t* vram;
union GBAOAM oam;
int32_t frameCounter;
};
void GBAVideoInit(struct GBAVideo* video);

View File

@ -8,6 +8,7 @@
#include "AudioProcessor.h"
#include "InputController.h"
#include <QDateTime>
#include <QThread>
extern "C" {
@ -59,10 +60,27 @@ GameController::GameController(QObject* parent)
return lux->value;
};
m_rtc.p = this;
m_rtc.override = GameControllerRTC::NO_OVERRIDE;
m_rtc.sample = [] (GBARTCSource* context) { };
m_rtc.unixTime = [] (GBARTCSource* context) -> time_t {
GameControllerRTC* rtc = static_cast<GameControllerRTC*>(context);
switch (rtc->override) {
case GameControllerRTC::NO_OVERRIDE:
default:
return time(nullptr);
case GameControllerRTC::FIXED:
return rtc->value;
case GameControllerRTC::FAKE_EPOCH:
return rtc->value + rtc->p->m_threadContext.gba->video.frameCounter * VIDEO_TOTAL_LENGTH / GBA_ARM7TDMI_FREQUENCY;
}
};
m_threadContext.startCallback = [] (GBAThread* context) {
GameController* controller = static_cast<GameController*>(context->userData);
controller->m_audioProcessor->setInput(context);
context->gba->luminanceSource = &controller->m_lux;
context->gba->rtcSource = &controller->m_rtc;
controller->gameStarted(context);
};
@ -372,6 +390,20 @@ void GameController::clearAVStream() {
threadContinue();
}
void GameController::setRealTime() {
m_rtc.override = GameControllerRTC::NO_OVERRIDE;
}
void GameController::setFixedTime(const QDateTime& time) {
m_rtc.override = GameControllerRTC::FIXED;
m_rtc.value = time.toMSecsSinceEpoch() / 1000;
}
void GameController::setFakeEpoch(const QDateTime& time) {
m_rtc.override = GameControllerRTC::FAKE_EPOCH;
m_rtc.value = time.toMSecsSinceEpoch() / 1000;
}
void GameController::updateKeys() {
int activeKeys = m_activeKeys;
#ifdef BUILD_SDL

View File

@ -94,6 +94,10 @@ public slots:
void clearAVStream();
void setLuminanceValue(uint8_t value) { m_luxValue = value; }
void setRealTime();
void setFixedTime(const QDateTime& time);
void setFakeEpoch(const QDateTime& time);
void setLogLevel(int);
void enableLogLevel(int);
void disableLogLevel(int);
@ -144,6 +148,16 @@ private:
uint8_t value;
} m_lux;
uint8_t m_luxValue;
struct GameControllerRTC : GBARTCSource {
GameController* p;
enum {
NO_OVERRIDE,
FIXED,
FAKE_EPOCH
} override;
int64_t value;
} m_rtc;
};
}

View File

@ -24,6 +24,17 @@ GamePakView::GamePakView(GameController* controller, QWidget* parent)
connect(m_ui.lightSpin, SIGNAL(valueChanged(int)), this, SLOT(setLuminanceValue(int)));
connect(m_ui.lightSlide, SIGNAL(valueChanged(int)), this, SLOT(setLuminanceValue(int)));
connect(m_ui.timeNoOverride, SIGNAL(clicked()), controller, SLOT(setRealTime()));
connect(m_ui.timeFixed, &QRadioButton::clicked, [controller, this] () {
controller->setFixedTime(m_ui.time->dateTime());
});
connect(m_ui.timeFakeEpoch, &QRadioButton::clicked, [controller, this] () {
controller->setFakeEpoch(m_ui.time->dateTime());
});
connect(m_ui.time, &QDateTimeEdit::dateTimeChanged, [controller, this] (const QDateTime&) {
m_ui.timeButtons->checkedButton()->clicked();
});
if (controller->isLoaded()) {
gameStarted(controller->thread());
}

View File

@ -151,38 +151,65 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioButton">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QRadioButton" name="timeNoOverride">
<property name="text">
<string>System time</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">timeButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_2">
<property name="enabled">
<bool>false</bool>
</property>
<widget class="QRadioButton" name="timeFixed">
<property name="text">
<string>Manual time</string>
<string>Fixed time</string>
</property>
<attribute name="buttonGroup">
<string notr="true">timeButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QDateTimeEdit" name="dateTimeEdit">
<property name="enabled">
<bool>false</bool>
<widget class="QRadioButton" name="timeFakeEpoch">
<property name="text">
<string>Start time at</string>
</property>
<attribute name="buttonGroup">
<string notr="true">timeButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QDateTimeEdit" name="time">
<property name="wrapping">
<bool>true</bool>
</property>
<property name="maximumDate">
<date>
<year>2099</year>
<month>12</month>
<day>31</day>
</date>
</property>
<property name="minimumDate">
<date>
<year>2000</year>
<month>1</month>
<day>1</day>
</date>
</property>
<property name="currentSection">
<enum>QDateTimeEdit::MonthSection</enum>
</property>
<property name="displayFormat">
<string>M/d/yyyy h:mm AP</string>
<string>MM/dd/yy hh:mm:ss AP</string>
</property>
<property name="calendarPopup">
<bool>false</bool>
<property name="timeSpec">
<enum>Qt::UTC</enum>
</property>
</widget>
</item>
@ -231,4 +258,7 @@
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="timeButtons"/>
</buttongroups>
</ui>