Skip to content

Commit 0a65c37

Browse files
committed
add RTC sync option (fixes #2589)
also allow to change date/time while game is running
1 parent 1124603 commit 0a65c37

9 files changed

Lines changed: 59 additions & 17 deletions

File tree

src/frontend/qt_sdl/Config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ DefaultList<bool> DefaultBools =
111111
#endif
112112
#endif
113113
{"DSi.DSP.HLE", true},
114+
{"Instance*.RTC.SyncToHost", true},
114115
};
115116

116117
DefaultList<std::string> DefaultStrings =

src/frontend/qt_sdl/DateTimeDialog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ DateTimeDialog::DateTimeDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Da
4646
startTimer(1000);
4747

4848
ui->txtNewCustomTime->setEnabled(ui->chkChangeTime->isChecked());
49+
50+
ui->chkSyncTime->setChecked(cfg.GetBool("RTC.SyncToHost"));
4951
}
5052

5153
DateTimeDialog::~DateTimeDialog()
@@ -73,6 +75,8 @@ void DateTimeDialog::done(int r)
7375
else if (ui->chkResetTime->isChecked())
7476
cfg.SetInt64("RTC.Offset", 0);
7577

78+
cfg.SetBool("RTC.SyncToHost", ui->chkSyncTime->isChecked());
79+
7680
Config::Save();
7781
}
7882

src/frontend/qt_sdl/DateTimeDialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DateTimeDialog : public QDialog
4646
}
4747

4848
currentDlg = new DateTimeDialog(parent);
49-
currentDlg->open();
49+
currentDlg->show();
5050
return currentDlg;
5151
}
5252
static void closeDlg()

src/frontend/qt_sdl/DateTimeDialog.ui

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>357</width>
10-
<height>161</height>
10+
<height>254</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -20,6 +20,13 @@
2020
<string>Date and time</string>
2121
</property>
2222
<layout class="QGridLayout" name="gridLayout_2">
23+
<item row="3" column="0" colspan="2">
24+
<widget class="QCheckBox" name="chkResetTime">
25+
<property name="text">
26+
<string>Reset to system date and time</string>
27+
</property>
28+
</widget>
29+
</item>
2330
<item row="0" column="0">
2431
<widget class="QLabel" name="label">
2532
<property name="text">
@@ -34,13 +41,6 @@
3441
</property>
3542
</widget>
3643
</item>
37-
<item row="1" column="0">
38-
<widget class="QLabel" name="label_2">
39-
<property name="text">
40-
<string/>
41-
</property>
42-
</widget>
43-
</item>
4444
<item row="2" column="0">
4545
<widget class="QCheckBox" name="chkChangeTime">
4646
<property name="text">
@@ -88,10 +88,24 @@
8888
</property>
8989
</widget>
9090
</item>
91-
<item row="3" column="0" colspan="2">
92-
<widget class="QCheckBox" name="chkResetTime">
91+
<item row="5" column="0" colspan="2">
92+
<widget class="QCheckBox" name="chkSyncTime">
9393
<property name="text">
94-
<string>Reset to system date and time</string>
94+
<string>Synchronize to system date and time</string>
95+
</property>
96+
</widget>
97+
</item>
98+
<item row="1" column="0" colspan="2">
99+
<widget class="QLabel" name="label_2">
100+
<property name="text">
101+
<string/>
102+
</property>
103+
</widget>
104+
</item>
105+
<item row="4" column="0" colspan="2">
106+
<widget class="QLabel" name="label_3">
107+
<property name="text">
108+
<string/>
95109
</property>
96110
</widget>
97111
</item>
@@ -101,10 +115,10 @@
101115
<item>
102116
<widget class="QDialogButtonBox" name="buttonBox">
103117
<property name="orientation">
104-
<enum>Qt::Horizontal</enum>
118+
<enum>Qt::Orientation::Horizontal</enum>
105119
</property>
106120
<property name="standardButtons">
107-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
121+
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
108122
</property>
109123
</widget>
110124
</item>

src/frontend/qt_sdl/EmuInstance.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,15 @@ void EmuInstance::setDateTime()
12091209
time.time().hour(), time.time().minute(), time.time().second());
12101210
}
12111211

1212+
void EmuInstance::syncRTC()
1213+
{
1214+
if (!localCfg.GetBool("RTC.SyncToHost"))
1215+
return;
1216+
1217+
setDateTime();
1218+
}
1219+
1220+
12121221
bool EmuInstance::updateConsole() noexcept
12131222
{
12141223
// update the console type

src/frontend/qt_sdl/EmuInstance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class EmuInstance
259259
void loadRTCData();
260260
void saveRTCData();
261261
void setDateTime();
262+
void syncRTC();
262263

263264
bool deleting;
264265

src/frontend/qt_sdl/EmuThread.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ void EmuThread::run()
295295
}
296296
}
297297

298+
// RTC sync
299+
emuInstance->syncRTC();
300+
298301

299302
// emulate
300303
u32 nlines;

src/frontend/qt_sdl/Window.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
725725
actStop->setEnabled(false);
726726
actFrameStep->setEnabled(false);
727727

728-
actDateTime->setEnabled(true);
728+
//actDateTime->setEnabled(true);
729729
actPowerManagement->setEnabled(false);
730730

731731
actEnableCheats->setEnabled(false);
@@ -1721,6 +1721,15 @@ void MainWindow::onFrameStep()
17211721
void MainWindow::onOpenDateTime()
17221722
{
17231723
DateTimeDialog* dlg = DateTimeDialog::openDlg(this);
1724+
connect(dlg, &DateTimeDialog::finished, this, &MainWindow::onDateTimeDialogFinished);
1725+
}
1726+
1727+
void MainWindow::onDateTimeDialogFinished(int res)
1728+
{
1729+
if (!res) return;
1730+
if (!emuThread->emuIsActive()) return;
1731+
1732+
emuInstance->setDateTime();
17241733
}
17251734

17261735
void MainWindow::onOpenPowerManagement()
@@ -2251,7 +2260,7 @@ void MainWindow::onEmuStart()
22512260
actStop->setEnabled(true);
22522261
actFrameStep->setEnabled(true);
22532262

2254-
actDateTime->setEnabled(false);
2263+
//actDateTime->setEnabled(false);
22552264
actPowerManagement->setEnabled(true);
22562265

22572266
actTitleManager->setEnabled(false);
@@ -2273,7 +2282,7 @@ void MainWindow::onEmuStop()
22732282
actStop->setEnabled(false);
22742283
actFrameStep->setEnabled(false);
22752284

2276-
actDateTime->setEnabled(true);
2285+
//actDateTime->setEnabled(true);
22772286
actPowerManagement->setEnabled(false);
22782287

22792288
actTitleManager->setEnabled(!globalCfg.GetString("DSi.NANDPath").empty());

src/frontend/qt_sdl/Window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ private slots:
123123
void onFrameStep();
124124
void onOpenPowerManagement();
125125
void onOpenDateTime();
126+
void onDateTimeDialogFinished(int res);
126127
void onEnableCheats(bool checked);
127128
void onSetupCheats();
128129
void onCheatsDialogFinished(int res);

0 commit comments

Comments
 (0)