Skip to content

Commit

Permalink
Fix #261, #263
Browse files Browse the repository at this point in the history
  • Loading branch information
mateoconlechuga authored and jacobly0 committed Oct 18, 2018
1 parent 509d85b commit a06b7c9
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 39 deletions.
1 change: 1 addition & 0 deletions core/debug/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
7 changes: 7 additions & 0 deletions core/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions gui/qt/emuthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -155,7 +159,7 @@ void EmuThread::throttleWait() {
std::unique_lock<std::mutex> 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();
Expand All @@ -167,12 +171,12 @@ void EmuThread::throttleWait() {
(std::chrono::duration<int, std::ratio<1, 60 * 1000000>>(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();
Expand Down
12 changes: 3 additions & 9 deletions gui/qt/emuthread.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef EMUTHREAD_H
#ifndef EMUTHREAD_H
#define EMUTHREAD_H

#include "../../core/asic.h"
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
38 changes: 22 additions & 16 deletions gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<void (QSpinBox::*)(int)>(&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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
6 changes: 2 additions & 4 deletions gui/qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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[];
Expand Down
13 changes: 6 additions & 7 deletions gui/qt/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions tests/autotester/autotester_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {}

Expand Down

0 comments on commit a06b7c9

Please sign in to comment.