From a06b7c9efe996169e464c7ffa4aa9b3673ef9070 Mon Sep 17 00:00:00 2001 From: MateoConLechuga Date: Wed, 27 Jun 2018 22:10:09 -0600 Subject: [PATCH] Fix #261, #263 --- core/debug/debug.h | 1 + core/emu.h | 1 + core/mem.c | 7 ++++++ gui/qt/emuthread.cpp | 10 +++++--- gui/qt/emuthread.h | 12 +++------ gui/qt/mainwindow.cpp | 38 +++++++++++++++++------------ gui/qt/mainwindow.h | 6 ++--- gui/qt/settings.cpp | 13 +++++----- tests/autotester/autotester_cli.cpp | 1 + 9 files changed, 50 insertions(+), 39 deletions(-) diff --git a/core/debug/debug.h b/core/debug/debug.h index 9fc55747e..8d8cc339a 100644 --- a/core/debug/debug.h +++ b/core/debug/debug.h @@ -93,6 +93,7 @@ bool debug_is_open(void); /* returns the status of th #define DBG_PORT_RANGE 0xFFFF00 #define DBGOUT_PORT_RANGE 0xFB0000 #define DBGERR_PORT_RANGE 0xFC0000 +#define DBGEXT_PORT 0xFD0000 #define DBG_STACK_SIZE 0x100 #define DBG_STACK_MASK (DBG_STACK_SIZE-1) #define DBG_ADDR_SIZE 0x1000000 diff --git a/core/emu.h b/core/emu.h index 969573184..ccd1d6189 100644 --- a/core/emu.h +++ b/core/emu.h @@ -32,6 +32,7 @@ void emu_exit(void); /* exit emulation */ /* if you want debugging support, don't forget about the debug callbacks as well */ void gui_do_stuff(void); /* perform tasks such as sending files, opening debugger */ void gui_throttle(void); /* throttling to get correct emulation speed */ +void gui_console_clear(void); /* sent to clear the console */ void gui_console_printf(const char *format, ...); /* printf from the core to stdout */ void gui_console_err_printf(const char *format, ...); /* printf from the core to stderr */ diff --git a/core/mem.c b/core/mem.c index 544fd8dbd..88e5fbe8f 100644 --- a/core/mem.c +++ b/core/mem.c @@ -587,6 +587,13 @@ void mem_write_cpu(uint32_t addr, uint8_t value) { debug.bufErrPos = 0; } break; + } else if (addr == DBGEXT_PORT) { + switch (value) { + case 1: + gui_console_clear(); + default: + break; + } } } #endif diff --git a/gui/qt/emuthread.cpp b/gui/qt/emuthread.cpp index 13df87e1a..9fd7285cd 100644 --- a/gui/qt/emuthread.cpp +++ b/gui/qt/emuthread.cpp @@ -17,6 +17,10 @@ void gui_do_stuff(void) { emu->doStuff(); } +void gui_console_clear(void) { + emu->consoleClear(); +} + void gui_console_printf(const char *format, ...) { va_list args; va_start(args, format); @@ -155,7 +159,7 @@ void EmuThread::throttleWait() { std::unique_lock lockSpeed(m_mutexSpeed); speed = m_speed; if (!speed) { - setActualSpeed(0); + sendSpeed(0); m_cvSpeed.wait(lockSpeed, [this] { return m_speed != 0; }); speed = m_speed; m_lastTime = std::chrono::steady_clock::now(); @@ -167,12 +171,12 @@ void EmuThread::throttleWait() { (std::chrono::duration>(1000000 * 100 / speed))); std::chrono::steady_clock::time_point cur_time = std::chrono::steady_clock::now(), next_time = m_lastTime + interval; if (throttle && cur_time < next_time) { - setActualSpeed(speed); + sendSpeed(speed); m_lastTime = next_time; std::this_thread::sleep_until(next_time); } else { if (m_lastTime != cur_time) { - setActualSpeed(unit / (cur_time - m_lastTime)); + sendSpeed(unit / (cur_time - m_lastTime)); m_lastTime = cur_time; } std::this_thread::yield(); diff --git a/gui/qt/emuthread.h b/gui/qt/emuthread.h index 8598c3256..2b08b14cb 100644 --- a/gui/qt/emuthread.h +++ b/gui/qt/emuthread.h @@ -1,4 +1,4 @@ -#ifndef EMUTHREAD_H +#ifndef EMUTHREAD_H #define EMUTHREAD_H #include "../../core/asic.h" @@ -59,13 +59,14 @@ class EmuThread : public QThread { signals: // console void consoleStr(); + void consoleClear(); // debug void debugDisable(); void debugCommand(int reason, uint32_t addr); // speed - void actualSpeedChanged(int value); + void sendSpeed(int value); // state void saved(bool success); @@ -86,13 +87,6 @@ public slots: emit sentFile(QString(), LINK_GOOD); } - void setActualSpeed(int value) { - if (m_actualSpeed != value) { - m_actualSpeed = value; - emit actualSpeedChanged(value); - } - } - void req(int req) { m_request = req; } diff --git a/gui/qt/mainwindow.cpp b/gui/qt/mainwindow.cpp index ff054f05f..364e359f7 100644 --- a/gui/qt/mainwindow.cpp +++ b/gui/qt/mainwindow.cpp @@ -103,7 +103,8 @@ MainWindow::MainWindow(CEmuOpts &cliOpts, QWidget *p) : QMainWindow(p), ui(new U // emulator -> gui (Should be queued) connect(&emu, &EmuThread::consoleStr, this, &MainWindow::consoleStr, Qt::UniqueConnection); - connect(&emu, &EmuThread::actualSpeedChanged, this, &MainWindow::showEmuSpeed, Qt::QueuedConnection); + connect(&emu, &EmuThread::consoleClear, this, &MainWindow::consoleClear, Qt::QueuedConnection); + connect(&emu, &EmuThread::sendSpeed, this, &MainWindow::showEmuSpeed, Qt::QueuedConnection); connect(&emu, &EmuThread::debugDisable, this, &MainWindow::debugDisable, Qt::QueuedConnection); connect(&emu, &EmuThread::debugCommand, this, &MainWindow::debugCommand, Qt::QueuedConnection); connect(&emu, &EmuThread::saved, this, &MainWindow::emuSaved, Qt::QueuedConnection); @@ -224,6 +225,8 @@ MainWindow::MainWindow(CEmuOpts &cliOpts, QWidget *p) : QMainWindow(p), ui(new U connect(this, &MainWindow::setLcdMode, ui->lcd, &LCDWidget::setMode); connect(this, &MainWindow::setLcdFrameskip, ui->lcd, &LCDWidget::setFrameskip); connect(ui->statusInterval, static_cast(&QSpinBox::valueChanged), this, &MainWindow::setStatusInterval); + connect(&m_timerEmu, &QTimer::timeout, [this]{ m_timerEmuTriggered = true; }); + connect(&m_timerFps, &QTimer::timeout, [this]{ m_timerFpsTriggered = true; }); // screen capture connect(ui->buttonScreenshot, &QPushButton::clicked, this, &MainWindow::screenshot); @@ -1266,6 +1269,22 @@ void MainWindow::console(int type, const char *str, int size) { } } +void MainWindow::consoleClear() { + if (m_nativeConsole) { + int ret; +#ifdef _WIN32 + ret = system("cls"); +#else + ret = system("clear"); +#endif + if (ret == -1) { + console(QStringLiteral("[CEmu] Error clearing console\n")); + } + } else { + ui->console->clear(); + } +} + void MainWindow::consoleStr() { if (int available = emu.read.available()) { int remaining = CONSOLE_BUFFER_SIZE - emu.readPos; @@ -1307,23 +1326,10 @@ void MainWindow::consoleSubmission() { ui->consoleLine->clear(); } -void MainWindow::emuSync() { - disconnect(&emu, &EmuThread::actualSpeedChanged, this, &MainWindow::showEmuSpeed); - connect(&emu, &EmuThread::actualSpeedChanged, this, &MainWindow::showEmuSpeed, Qt::QueuedConnection); -} - -void MainWindow::fpsSync() { - m_timerFpsTriggered = true; -} - void MainWindow::showEmuSpeed(int speed) { - static int speedPrev = 0; - if (speedPrev != speed) { + if (m_timerEmuTriggered) { m_speedLabel.setText(tr("Emulated Speed: ") + QString::number(speed) + QStringLiteral("%")); - speedPrev = speed; - } - if (m_timerEmuTriggerable) { - disconnect(&emu, &EmuThread::actualSpeedChanged, this, &MainWindow::showEmuSpeed); + m_timerEmuTriggered = !m_timerEmuTriggerable; } } diff --git a/gui/qt/mainwindow.h b/gui/qt/mainwindow.h index 27bdd25d3..940112fbf 100644 --- a/gui/qt/mainwindow.h +++ b/gui/qt/mainwindow.h @@ -71,10 +71,6 @@ class MainWindow : public QMainWindow { virtual void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; virtual void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; -private slots: - void emuSync(); - void fpsSync(); - private: enum { CONSOLE_ESC, @@ -180,6 +176,7 @@ private slots: void console(const QString &str, const QColor &colorFg = Qt::black, const QColor &colorBg = Qt::white, int type = EmuThread::ConsoleNorm); void console(int type, const char *str, int size = -1); void consoleStr(); + void consoleClear(); void consoleSubmission(); void consoleModified(); @@ -619,6 +616,7 @@ private slots: QTimer m_timerFps; bool m_timerEmuTriggerable = true; bool m_timerFpsTriggerable = true; + bool m_timerEmuTriggered = false; bool m_timerFpsTriggered = false; static const char *m_varExtensions[]; diff --git a/gui/qt/settings.cpp b/gui/qt/settings.cpp index 76b578171..d7d1efbcc 100644 --- a/gui/qt/settings.cpp +++ b/gui/qt/settings.cpp @@ -564,7 +564,6 @@ void MainWindow::setUIEditMode(bool mode) { void MainWindow::setThrottle(int mode) { ui->checkThrottle->setChecked(mode == Qt::Checked); - connect(&emu, &EmuThread::actualSpeedChanged, this, &MainWindow::showEmuSpeed, Qt::QueuedConnection); emu.setThrottle(mode == Qt::Checked); } @@ -676,15 +675,11 @@ void MainWindow::setStatusInterval(int value) { ui->statusInterval->setValue(value); m_timerFps.stop(); m_timerEmu.stop(); - connect(&m_timerEmu, SIGNAL(timeout()), this, SLOT(emuSync())); - connect(&m_timerFps, SIGNAL(timeout()), this, SLOT(fpsSync())); + m_timerFpsTriggered = true; + m_timerEmuTriggered = true; m_timerEmuTriggerable = true; m_timerFpsTriggerable = true; if (!value) { - disconnect(&m_timerEmu, SIGNAL(timeout()), this, SLOT(emuSync())); - disconnect(&m_timerFps, SIGNAL(timeout()), this, SLOT(fpsSync())); - connect(&emu, &EmuThread::actualSpeedChanged, this, &MainWindow::showEmuSpeed, Qt::QueuedConnection); - m_timerFpsTriggered = true; m_timerEmuTriggerable = false; m_timerFpsTriggerable = false; } else { @@ -700,6 +695,10 @@ void MainWindow::setEmuSpeed(int value) { ui->emulationSpeedSpin->blockSignals(false); ui->emulationSpeed->setValue(value); emu.setSpeed(value); + if (value == 0) { + m_timerEmuTriggered = true; + showEmuSpeed(0); + } } void MainWindow::keypadChanged() { diff --git a/tests/autotester/autotester_cli.cpp b/tests/autotester/autotester_cli.cpp index 601f62281..58be857b9 100644 --- a/tests/autotester/autotester_cli.cpp +++ b/tests/autotester/autotester_cli.cpp @@ -45,6 +45,7 @@ extern "C" } } + void gui_console_clear() {} void gui_console_printf(const char *format, ...) {} void gui_console_err_printf(const char *format, ...) {}