Skip to content

Commit

Permalink
Add keypad ghosting setting to the core and GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
calc84maniac committed Sep 21, 2024
1 parent a4c41c8 commit 2198497
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
11 changes: 9 additions & 2 deletions core/keypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ keypad_state_t keypad;
typedef struct keypad_atomics {
_Atomic(uint16_t) keyMap[KEYPAD_ACTUAL_ROWS];
_Atomic(uint8_t) onKey;
_Atomic(bool) ghosting;
} keypad_atomics_t;

static keypad_atomics_t keypad_atomics;

void emu_set_keypad_ghosting(int enable) {
keypad_atomics.ghosting = enable;
}

static inline void keypad_intrpt_check() {
intrpt_set(INT_KEYPAD, keypad.status & keypad.enable);
}
Expand Down Expand Up @@ -134,7 +139,8 @@ void keypad_any_check(void) {
}
uint16_t dataMask = keypad_data_mask();
/* if not all rows were queried, ghosting is possible */
if (unlikely(queryMask != (1 << KEYPAD_ACTUAL_ROWS) - 1)) {
if (unlikely(queryMask != (1 << KEYPAD_ACTUAL_ROWS) - 1) &&
atomic_load_explicit(&keypad_atomics.ghosting, memory_order_relaxed)) {
/* if at least one key was pressed and not every data bit is filled, ghosting is possible */
if (any != 0 && (any & dataMask) != dataMask) {
any = keypad_handle_ghosting(any, queryMask);
Expand Down Expand Up @@ -229,7 +235,8 @@ static void keypad_scan_event(enum sched_item_id id) {
data = keypad_query_keymap(row);
uint16_t dataMask = keypad_data_mask();
/* if at least one key was pressed and not every data bit is filled, ghosting is possible */
if (data != 0 && (data & dataMask) != dataMask) {
if (atomic_load_explicit(&keypad_atomics.ghosting, memory_order_relaxed) &&
data != 0 && (data & dataMask) != dataMask) {
data = keypad_handle_ghosting(data, 1 << row);
}
data &= dataMask;
Expand Down
1 change: 1 addition & 0 deletions core/keypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ bool keypad_save(FILE *image);

/* api functions */
void emu_keypad_event(unsigned int row, unsigned int col, bool press);
void emu_set_keypad_ghosting(int enable);

#ifdef __cplusplus
}
Expand Down
2 changes: 2 additions & 0 deletions gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ MainWindow::MainWindow(CEmuOpts &cliOpts, QWidget *p) : QMainWindow(p), ui(new U
connect(ui->checkSkin, &QCheckBox::stateChanged, this, &MainWindow::setSkinToggle);
connect(ui->comboBoxAsicRev, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &MainWindow::setAsicRevision);
connect(ui->checkPythonEdition, &QCheckBox::stateChanged, this, &MainWindow::setPythonEdition);
connect(ui->checkKeypadGhosting, &QCheckBox::stateChanged, this, &MainWindow::setKeypadGhosting);
connect(ui->checkDma, &QCheckBox::toggled, this, &MainWindow::setLcdDma);
connect(ui->checkGamma, &QCheckBox::toggled, this, &MainWindow::setLcdGamma);
connect(ui->checkResponse, &QCheckBox::toggled, this, &MainWindow::setLcdResponse);
Expand Down Expand Up @@ -592,6 +593,7 @@ MainWindow::MainWindow(CEmuOpts &cliOpts, QWidget *p) : QMainWindow(p), ui(new U
setLcdGamma(m_config->value(SETTING_SCREEN_GAMMA, true).toBool());
setLcdResponse(m_config->value(SETTING_SCREEN_RESPONSE, true).toBool());
setGuiSkip(m_config->value(SETTING_SCREEN_FRAMESKIP, 0).toInt());
setKeypadGhosting(m_config->value(SETTING_KEYPAD_GHOSTING, true).toBool());
setKeypadHolding(m_config->value(SETTING_KEYPAD_HOLDING, true).toBool());
setEmuSpeed(m_config->value(SETTING_EMUSPEED, 100).toInt());
ui->checkSaveRestore->setChecked(m_config->value(SETTING_SAVE_ON_CLOSE, true).toBool());
Expand Down
2 changes: 2 additions & 0 deletions gui/qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ class MainWindow : public QMainWindow {
void keypadChanged();
void setKeymap(const QString &value);
void setKeypadColor(unsigned int color);
void setKeypadGhosting(bool enabled);
void setKeypadHolding(bool enabled);
void setCalcSkinTopFromType(bool python);

Expand Down Expand Up @@ -750,6 +751,7 @@ class MainWindow : public QMainWindow {
static const QString SETTING_SCREEN_RESPONSE;
static const QString SETTING_KEYPAD_KEYMAP;
static const QString SETTING_KEYPAD_COLOR;
static const QString SETTING_KEYPAD_GHOSTING;
static const QString SETTING_KEYPAD_HOLDING;
static const QString SETTING_WINDOW_FULLSCREEN;
static const QString SETTING_WINDOW_GROUP_DRAG;
Expand Down
40 changes: 32 additions & 8 deletions gui/qt/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9607,14 +9607,38 @@ QPushButton:pressed {
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkPythonEdition">
<property name="text">
<string>Emulate Python Edition</string>
</property>
<property name="tristate">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_31">
<item>
<widget class="QCheckBox" name="checkPythonEdition">
<property name="text">
<string>Emulate Python Edition</string>
</property>
<property name="tristate">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkKeypadGhosting">
<property name="text">
<string>Emulate keypad ghosting</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_30">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_16">
Expand Down
8 changes: 8 additions & 0 deletions gui/qt/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "../../core/cpu.h"
#include "../../core/emu.h"
#include "../../core/keypad.h"
#include "../../core/debug/debug.h"

#include <cmath>
Expand Down Expand Up @@ -65,6 +66,7 @@ const QString MainWindow::SETTING_SCREEN_RESPONSE = QStringLiteral("Sc
const QString MainWindow::SETTING_KEYPAD_KEYMAP = QStringLiteral("Keypad/map");
const QString MainWindow::SETTING_KEYPAD_COLOR = QStringLiteral("Keypad/color");
const QString MainWindow::SETTING_KEYPAD_CUSTOM_PATH = QStringLiteral("Keypad/custom_path");
const QString MainWindow::SETTING_KEYPAD_GHOSTING = QStringLiteral("Keypad/ghosting");
const QString MainWindow::SETTING_KEYPAD_HOLDING = QStringLiteral("Keypad/holding");
const QString MainWindow::SETTING_WINDOW_GROUP_DRAG = QStringLiteral("Window/group_dock_drag");
const QString MainWindow::SETTING_WINDOW_FULLSCREEN = QStringLiteral("Window/fullscreen");
Expand Down Expand Up @@ -495,6 +497,12 @@ void MainWindow::setKeypadColor(unsigned int color) {
m_config->setValue(SETTING_KEYPAD_COLOR, color);
}

void MainWindow::setKeypadGhosting(bool state) {
ui->checkKeypadGhosting->setChecked(state);
emu_set_keypad_ghosting(state);
m_config->setValue(SETTING_KEYPAD_GHOSTING, state);
}

void MainWindow::setKeypadHolding(bool enabled) {
ui->keypadWidget->setHolding(enabled);
m_config->setValue(SETTING_KEYPAD_HOLDING, enabled);
Expand Down

0 comments on commit 2198497

Please sign in to comment.