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
Misc:
- Core: Suspend runloop when a core crashes
- Core: Add wallclock offset RTC type
- Debugger: Save and restore CLI history
- Debugger: GDB now works while the game is paused
- 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_FIXED,
RTC_FAKE_EPOCH,
RTC_WALLCLOCK_OFFSET,
RTC_CUSTOM_START = 0x1000
};

View File

@ -21,6 +21,7 @@ static void _rtcGenericSample(struct mRTCSource* source) {
case RTC_NO_OVERRIDE:
case RTC_FIXED:
case RTC_FAKE_EPOCH:
case RTC_WALLCLOCK_OFFSET:
break;
}
}
@ -39,6 +40,8 @@ static time_t _rtcGenericCallback(struct mRTCSource* source) {
return rtc->value / 1000LL;
case RTC_FAKE_EPOCH:
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();
}
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) {
#ifdef M_CORE_GBA
QImage image(path);

View File

@ -174,6 +174,7 @@ public slots:
void setRealTime();
void setFixedTime(const QDateTime& time);
void setFakeEpoch(const QDateTime& time);
void setTimeOffset(qint64 offset);
void importSharkport(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] () {
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();
connect(controller.get(), &CoreController::stopping, [this]() {

View File

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