Qt: Saving of game overrides

This commit is contained in:
Jeffrey Pfau 2015-01-25 16:01:03 -08:00
parent f33e9c060f
commit 6116f730e7
8 changed files with 170 additions and 55 deletions

View File

@ -172,6 +172,44 @@ bool GBAOverrideFind(const struct Configuration* config, struct GBACartridgeOver
return found; return found;
} }
void GBAOverrideSave(struct Configuration* config, const struct GBACartridgeOverride* override) {
char sectionName[16];
snprintf(sectionName, sizeof(sectionName), "override.%c%c%c%c", override->id[0], override->id[1], override->id[2], override->id[3]);
const char* savetype = 0;
switch (override->savetype) {
case SAVEDATA_SRAM:
savetype = "SRAM";
break;
case SAVEDATA_EEPROM:
savetype = "EEPROM";
break;
case SAVEDATA_FLASH512:
savetype = "FLASH512";
break;
case SAVEDATA_FLASH1M:
savetype = "FLASH1M";
break;
case SAVEDATA_FORCE_NONE:
savetype = "NONE";
break;
case SAVEDATA_AUTODETECT:
break;
}
ConfigurationSetValue(config, sectionName, "savetype", savetype);
if (override->hardware != GPIO_NO_OVERRIDE) {
ConfigurationSetIntValue(config, sectionName, "hardware", override->hardware);
} else {
ConfigurationClearValue(config, sectionName, "hardware");
}
if (override->idleLoop != 0xFFFFFFFF) {
ConfigurationSetUIntValue(config, sectionName, "idleLoop", override->idleLoop);
} else {
ConfigurationClearValue(config, sectionName, "idleLoop");
}
}
void GBAOverrideApply(struct GBA* gba, const struct GBACartridgeOverride* override) { void GBAOverrideApply(struct GBA* gba, const struct GBACartridgeOverride* override) {
if (override->savetype != SAVEDATA_AUTODETECT) { if (override->savetype != SAVEDATA_AUTODETECT) {
GBASavedataForceType(&gba->memory.savedata, override->savetype); GBASavedataForceType(&gba->memory.savedata, override->savetype);

View File

@ -19,7 +19,7 @@ struct GBACartridgeOverride {
struct Configuration; struct Configuration;
bool GBAOverrideFind(const struct Configuration*, struct GBACartridgeOverride* override); bool GBAOverrideFind(const struct Configuration*, struct GBACartridgeOverride* override);
bool GBAOverrideSave(struct Configuration*, const struct GBACartridgeOverride* override); void GBAOverrideSave(struct Configuration*, const struct GBACartridgeOverride* override);
struct GBA; struct GBA;
void GBAOverrideApply(struct GBA*, const struct GBACartridgeOverride*); void GBAOverrideApply(struct GBA*, const struct GBACartridgeOverride*);

View File

@ -12,6 +12,7 @@
#include <QMenu> #include <QMenu>
extern "C" { extern "C" {
#include "gba-overrides.h"
#include "platform/commandline.h" #include "platform/commandline.h"
} }
@ -157,6 +158,11 @@ QVariant ConfigController::getQtOption(const QString& key, const QString& group)
return value; return value;
} }
void ConfigController::saveOverride(const GBACartridgeOverride& override) {
GBAOverrideSave(overrides(), &override);
write();
}
void ConfigController::setOption(const char* key, bool value) { void ConfigController::setOption(const char* key, bool value) {
GBAConfigSetIntValue(&m_config, key, value); GBAConfigSetIntValue(&m_config, key, value);
QString optionName(key); QString optionName(key);

View File

@ -22,6 +22,7 @@ class QAction;
class QMenu; class QMenu;
struct GBAArguments; struct GBAArguments;
struct GBACartridgeOverride;
namespace QGBA { namespace QGBA {
@ -76,6 +77,7 @@ public:
void setMRU(const QList<QString>& mru); void setMRU(const QList<QString>& mru);
Configuration* overrides() { return &m_config.configTable; } // TODO: Make this not return the whole table Configuration* overrides() { return &m_config.configTable; } // TODO: Make this not return the whole table
void saveOverride(const GBACartridgeOverride&);
public slots: public slots:
void setOption(const char* key, bool value); void setOption(const char* key, bool value);

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GamePakView.h" #include "GamePakView.h"
#include "ConfigController.h"
#include "GameController.h" #include "GameController.h"
extern "C" { extern "C" {
@ -13,9 +14,10 @@ extern "C" {
using namespace QGBA; using namespace QGBA;
GamePakView::GamePakView(GameController* controller, QWidget* parent) GamePakView::GamePakView(GameController* controller, ConfigController* config, QWidget* parent)
: QWidget(parent) : QWidget(parent)
, m_controller(controller) , m_controller(controller)
, m_config(config)
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
@ -54,13 +56,22 @@ GamePakView::GamePakView(GameController* controller, QWidget* parent)
connect(m_ui.hwTilt, SIGNAL(clicked()), this, SLOT(updateOverrides())); connect(m_ui.hwTilt, SIGNAL(clicked()), this, SLOT(updateOverrides()));
connect(m_ui.hwRumble, SIGNAL(clicked()), this, SLOT(updateOverrides())); connect(m_ui.hwRumble, SIGNAL(clicked()), this, SLOT(updateOverrides()));
connect(m_ui.save, SIGNAL(clicked()), this, SLOT(saveOverride()));
if (controller->isLoaded()) { if (controller->isLoaded()) {
gameStarted(controller->thread()); gameStarted(controller->thread());
} }
} }
void GamePakView::saveOverride() {
if (!m_config) {
return;
}
m_config->saveOverride(m_override);
}
void GamePakView::updateOverrides() { void GamePakView::updateOverrides() {
GBACartridgeOverride override = { m_override = (GBACartridgeOverride) {
"", "",
static_cast<SavedataType>(m_ui.savetype->currentIndex() - 1), static_cast<SavedataType>(m_ui.savetype->currentIndex() - 1),
GPIO_NO_OVERRIDE, GPIO_NO_OVERRIDE,
@ -68,26 +79,26 @@ void GamePakView::updateOverrides() {
}; };
if (!m_ui.hwAutodetect->isChecked()) { if (!m_ui.hwAutodetect->isChecked()) {
override.hardware = GPIO_NONE; m_override.hardware = GPIO_NONE;
if (m_ui.hwRTC->isChecked()) { if (m_ui.hwRTC->isChecked()) {
override.hardware |= GPIO_RTC; m_override.hardware |= GPIO_RTC;
} }
if (m_ui.hwGyro->isChecked()) { if (m_ui.hwGyro->isChecked()) {
override.hardware |= GPIO_GYRO; m_override.hardware |= GPIO_GYRO;
} }
if (m_ui.hwLight->isChecked()) { if (m_ui.hwLight->isChecked()) {
override.hardware |= GPIO_LIGHT_SENSOR; m_override.hardware |= GPIO_LIGHT_SENSOR;
} }
if (m_ui.hwTilt->isChecked()) { if (m_ui.hwTilt->isChecked()) {
override.hardware |= GPIO_TILT; m_override.hardware |= GPIO_TILT;
} }
if (m_ui.hwRumble->isChecked()) { if (m_ui.hwRumble->isChecked()) {
override.hardware |= GPIO_RUMBLE; m_override.hardware |= GPIO_RUMBLE;
} }
} }
if (override.savetype != SAVEDATA_AUTODETECT || override.hardware != GPIO_NO_OVERRIDE) { if (m_override.savetype != SAVEDATA_AUTODETECT || m_override.hardware != GPIO_NO_OVERRIDE) {
m_controller->setOverride(override); m_controller->setOverride(m_override);
} else { } else {
m_controller->clearOverride(); m_controller->clearOverride();
} }
@ -113,6 +124,12 @@ void GamePakView::gameStarted(GBAThread* thread) {
m_ui.hwLight->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_LIGHT_SENSOR); m_ui.hwLight->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_LIGHT_SENSOR);
m_ui.hwTilt->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_TILT); m_ui.hwTilt->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_TILT);
m_ui.hwRumble->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_RUMBLE); m_ui.hwRumble->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_RUMBLE);
GBAGetGameCode(thread->gba, m_override.id);
m_override.hardware = thread->gba->memory.gpio.gpioDevices;
m_override.savetype = thread->gba->memory.savedata.type;
m_ui.save->setEnabled(m_config);
} }
void GamePakView::gameStopped() { void GamePakView::gameStopped() {
@ -131,6 +148,8 @@ void GamePakView::gameStopped() {
m_ui.hwLight->setChecked(false); m_ui.hwLight->setChecked(false);
m_ui.hwTilt->setChecked(false); m_ui.hwTilt->setChecked(false);
m_ui.hwRumble->setChecked(false); m_ui.hwRumble->setChecked(false);
m_ui.save->setEnabled(false);
} }
void GamePakView::setLuminanceValue(int value) { void GamePakView::setLuminanceValue(int value) {

View File

@ -10,17 +10,25 @@
#include "ui_GamePakView.h" #include "ui_GamePakView.h"
extern "C" {
#include "gba-overrides.h"
}
struct GBAThread; struct GBAThread;
namespace QGBA { namespace QGBA {
class ConfigController;
class GameController; class GameController;
class GamePakView : public QWidget { class GamePakView : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
GamePakView(GameController* controller, QWidget* parent = nullptr); GamePakView(GameController* controller, ConfigController* config, QWidget* parent = nullptr);
public slots:
void saveOverride();
private slots: private slots:
void updateOverrides(); void updateOverrides();
@ -32,6 +40,8 @@ private:
Ui::GamePakView m_ui; Ui::GamePakView m_ui;
GameController* m_controller; GameController* m_controller;
ConfigController* m_config;
GBACartridgeOverride m_override;
}; };
} }

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>251</width> <width>251</width>
<height>391</height> <height>433</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -29,6 +29,47 @@
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::FieldsStayAtSizeHint</enum> <enum>QFormLayout::FieldsStayAtSizeHint</enum>
</property> </property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Save type</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="savetype">
<item>
<property name="text">
<string>Autodetect</string>
</property>
</item>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>SRAM</string>
</property>
</item>
<item>
<property name="text">
<string>Flash 512kb</string>
</property>
</item>
<item>
<property name="text">
<string>Flash 1Mb</string>
</property>
</item>
<item>
<property name="text">
<string>EEPROM</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="Line" name="line"> <widget class="Line" name="line">
<property name="orientation"> <property name="orientation">
@ -93,47 +134,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="QComboBox" name="savetype">
<item>
<property name="text">
<string>Autodetect</string>
</property>
</item>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>SRAM</string>
</property>
</item>
<item>
<property name="text">
<string>Flash 512kb</string>
</property>
</item>
<item>
<property name="text">
<string>Flash 1Mb</string>
</property>
</item>
<item>
<property name="text">
<string>EEPROM</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Save type</string>
</property>
</widget>
</item>
<item row="7" column="1"> <item row="7" column="1">
<widget class="QCheckBox" name="hwRumble"> <widget class="QCheckBox" name="hwRumble">
<property name="enabled"> <property name="enabled">
@ -144,6 +144,46 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="save">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Save overrides</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<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>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -229,7 +229,7 @@ void Window::openShortcutWindow() {
} }
void Window::openGamePakWindow() { void Window::openGamePakWindow() {
GamePakView* gamePakWindow = new GamePakView(m_controller); GamePakView* gamePakWindow = new GamePakView(m_controller, m_config);
connect(this, SIGNAL(shutdown()), gamePakWindow, SLOT(close())); connect(this, SIGNAL(shutdown()), gamePakWindow, SLOT(close()));
gamePakWindow->setAttribute(Qt::WA_DeleteOnClose); gamePakWindow->setAttribute(Qt::WA_DeleteOnClose);
gamePakWindow->show(); gamePakWindow->show();