all repos — mgba @ 8c0f082a83dbf9bc94024f81f385bc8a7c3a807e

mGBA Game Boy Advance Emulator

Qt: RTC overrides
Jeffrey Pfau jeffrey@endrift.com
Thu, 01 Jan 2015 03:01:40 -0800
commit

8c0f082a83dbf9bc94024f81f385bc8a7c3a807e

parent

f5346383425fdf8f013e1c931e3759783840e328

M src/gba/gba-video.csrc/gba/gba-video.c

@@ -53,6 +53,8 @@ video->nextHblankIRQ = 0;

video->nextVblankIRQ = 0; video->nextVcounterIRQ = 0; + video->frameCounter = 0; + if (video->vram) { mappedMemoryFree(video->vram, SIZE_VRAM); }

@@ -115,6 +117,7 @@ if (GBARegisterDISPSTATIsVblankIRQ(video->dispstat)) {

GBARaiseIRQ(video->p, IRQ_VBLANK); } GBASyncPostFrame(video->p->sync); + ++video->frameCounter; break; case VIDEO_VERTICAL_TOTAL_PIXELS - 1: if (video->p->rr) {
M src/gba/gba-video.hsrc/gba/gba-video.h

@@ -190,6 +190,8 @@

uint16_t palette[SIZE_PALETTE_RAM >> 1]; uint16_t* vram; union GBAOAM oam; + + int32_t frameCounter; }; void GBAVideoInit(struct GBAVideo* video);
M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -8,6 +8,7 @@

#include "AudioProcessor.h" #include "InputController.h" +#include <QDateTime> #include <QThread> extern "C" {

@@ -59,10 +60,27 @@ GameControllerLux* lux = static_cast<GameControllerLux*>(context);

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); };

@@ -370,6 +388,20 @@ void GameController::clearAVStream() {

threadInterrupt(); m_threadContext.stream = nullptr; 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() {
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -94,6 +94,10 @@ void setAVStream(GBAAVStream*);

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 @@ GameController* p;

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; }; }
M src/platform/qt/GamePakView.cppsrc/platform/qt/GamePakView.cpp

@@ -24,6 +24,17 @@ connect(controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));

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()); }
M src/platform/qt/GamePakView.uisrc/platform/qt/GamePakView.ui

@@ -151,38 +151,65 @@ <string>RTC</string>

</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> + <widget class="QRadioButton" name="timeFixed"> + <property name="text"> + <string>Fixed time</string> </property> + <attribute name="buttonGroup"> + <string notr="true">timeButtons</string> + </attribute> + </widget> + </item> + <item> + <widget class="QRadioButton" name="timeFakeEpoch"> <property name="text"> - <string>Manual time</string> + <string>Start time at</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="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 @@ </layout>

</widget> <resources/> <connections/> + <buttongroups> + <buttongroup name="timeButtons"/> + </buttongroups> </ui>