Core: Add wallclock offset RTC type

This commit is contained in:
Vicki Pfau 2022-06-16 21:57:45 -07:00
parent a60bc18ad0
commit 4851109027
7 changed files with 71 additions and 23 deletions

View File

@ -64,6 +64,7 @@ Other fixes:
- VFS: Failed file mapping should return NULL on POSIX - VFS: Failed file mapping should return NULL on POSIX
Misc: Misc:
- Core: Suspend runloop when a core crashes - Core: Suspend runloop when a core crashes
- Core: Add wallclock offset RTC type
- Debugger: Save and restore CLI history - Debugger: Save and restore CLI history
- Debugger: GDB now works while the game is paused - Debugger: GDB now works while the game is paused
- Debugger: Add command to load external symbol file (fixes mgba.io/i/2480) - Debugger: Add command to load external symbol file (fixes mgba.io/i/2480)

View File

@ -239,6 +239,7 @@ enum mRTCGenericType {
RTC_NO_OVERRIDE, RTC_NO_OVERRIDE,
RTC_FIXED, RTC_FIXED,
RTC_FAKE_EPOCH, RTC_FAKE_EPOCH,
RTC_WALLCLOCK_OFFSET,
RTC_CUSTOM_START = 0x1000 RTC_CUSTOM_START = 0x1000
}; };

View File

@ -21,6 +21,7 @@ static void _rtcGenericSample(struct mRTCSource* source) {
case RTC_NO_OVERRIDE: case RTC_NO_OVERRIDE:
case RTC_FIXED: case RTC_FIXED:
case RTC_FAKE_EPOCH: case RTC_FAKE_EPOCH:
case RTC_WALLCLOCK_OFFSET:
break; break;
} }
} }
@ -39,6 +40,8 @@ static time_t _rtcGenericCallback(struct mRTCSource* source) {
return rtc->value / 1000LL; return rtc->value / 1000LL;
case RTC_FAKE_EPOCH: case RTC_FAKE_EPOCH:
return (rtc->value + rtc->p->frameCounter(rtc->p) * (rtc->p->frameCycles(rtc->p) * 1000LL) / rtc->p->frequency(rtc->p)) / 1000LL; return (rtc->value + rtc->p->frameCounter(rtc->p) * (rtc->p->frameCycles(rtc->p) * 1000LL) / rtc->p->frequency(rtc->p)) / 1000LL;
case RTC_WALLCLOCK_OFFSET:
return time(0) + rtc->value / 1000LL;
} }
} }

View File

@ -898,6 +898,11 @@ void CoreController::setFakeEpoch(const QDateTime& time) {
m_threadContext.core->rtc.value = time.toMSecsSinceEpoch(); m_threadContext.core->rtc.value = time.toMSecsSinceEpoch();
} }
void CoreController::setTimeOffset(qint64 offset) {
m_threadContext.core->rtc.override = RTC_WALLCLOCK_OFFSET;
m_threadContext.core->rtc.value = offset * 1000LL;
}
void CoreController::scanCard(const QString& path) { void CoreController::scanCard(const QString& path) {
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
QImage image(path); QImage image(path);

View File

@ -174,6 +174,7 @@ public slots:
void setRealTime(); void setRealTime();
void setFixedTime(const QDateTime& time); void setFixedTime(const QDateTime& time);
void setFakeEpoch(const QDateTime& time); void setFakeEpoch(const QDateTime& time);
void setTimeOffset(qint64 offset);
void importSharkport(const QString& path); void importSharkport(const QString& path);
void exportSharkport(const QString& path); void exportSharkport(const QString& path);

View File

@ -69,6 +69,14 @@ void SensorView::setController(std::shared_ptr<CoreController> controller) {
connect(m_ui.timeFakeEpoch, &QRadioButton::clicked, [controller, this] () { connect(m_ui.timeFakeEpoch, &QRadioButton::clicked, [controller, this] () {
controller->setFakeEpoch(m_ui.time->dateTime().toUTC()); controller->setFakeEpoch(m_ui.time->dateTime().toUTC());
}); });
connect(m_ui.timeOffset, &QRadioButton::clicked, [controller, this] () {
controller->setTimeOffset(m_ui.offsetSeconds->value());
});
connect(m_ui.offsetSeconds, qOverload<int>(&QSpinBox::valueChanged), [controller, this] (int value) {
if (m_ui.timeOffset->isChecked()) {
controller->setTimeOffset(value);
}
});
m_ui.timeButtons->checkedButton()->clicked(); m_ui.timeButtons->checkedButton()->clicked();
connect(controller.get(), &CoreController::stopping, [this]() { connect(controller.get(), &CoreController::stopping, [this]() {

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>434</width> <width>448</width>
<height>319</height> <height>332</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -19,28 +19,18 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Sensors</string> <string>Sensors</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum> <enum>QLayout::SetFixedSize</enum>
</property> </property>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Realtime clock</string> <string>Realtime clock</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<item row="1" column="0">
<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 row="0" column="0"> <item row="0" column="0">
<widget class="QRadioButton" name="timeNoOverride"> <widget class="QRadioButton" name="timeNoOverride">
<property name="text"> <property name="text">
@ -54,7 +44,53 @@
</attribute> </attribute>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<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 row="1" column="1">
<widget class="QPushButton" name="timeNow">
<property name="text">
<string>Now</string>
</property>
</widget>
</item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QRadioButton" name="timeOffset">
<property name="text">
<string>Offset time</string>
</property>
<attribute name="buttonGroup">
<string notr="true">timeButtons</string>
</attribute>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="offsetSeconds">
<property name="suffix">
<string> sec</string>
</property>
<property name="minimum">
<number>-99999999</number>
</property>
<property name="maximum">
<number>99999999</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="stepType">
<enum>QAbstractSpinBox::AdaptiveDecimalStepType</enum>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="timeFakeEpoch"> <widget class="QRadioButton" name="timeFakeEpoch">
<property name="text"> <property name="text">
<string>Start time at</string> <string>Start time at</string>
@ -64,14 +100,7 @@
</attribute> </attribute>
</widget> </widget>
</item> </item>
<item row="0" column="1" rowspan="3"> <item row="4" column="0" colspan="2">
<widget class="QPushButton" name="timeNow">
<property name="text">
<string>Now</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QDateTimeEdit" name="time"> <widget class="QDateTimeEdit" name="time">
<property name="wrapping"> <property name="wrapping">
<bool>true</bool> <bool>true</bool>
@ -143,7 +172,7 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QGroupBox" name="tilt"> <widget class="QGroupBox" name="tilt">
<property name="title"> <property name="title">