Qt: Saving of game overrides
@@ -172,6 +172,44 @@ }
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) { if (override->savetype != SAVEDATA_AUTODETECT) { GBASavedataForceType(&gba->memory.savedata, override->savetype);
@@ -19,7 +19,7 @@ };
struct Configuration; 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; void GBAOverrideApply(struct GBA*, const struct GBACartridgeOverride*);
@@ -12,6 +12,7 @@ #include <QDir>
#include <QMenu> extern "C" { +#include "gba-overrides.h" #include "platform/commandline.h" }@@ -155,6 +156,11 @@ if (!group.isNull()) {
m_settings->endGroup(); } return value; +} + +void ConfigController::saveOverride(const GBACartridgeOverride& override) { + GBAOverrideSave(overrides(), &override); + write(); } void ConfigController::setOption(const char* key, bool value) {
@@ -22,6 +22,7 @@ class QAction;
class QMenu; struct GBAArguments; +struct GBACartridgeOverride; namespace QGBA {@@ -76,6 +77,7 @@ QList<QString> getMRU() const;
void setMRU(const QList<QString>& mru); Configuration* overrides() { return &m_config.configTable; } // TODO: Make this not return the whole table + void saveOverride(const GBACartridgeOverride&); public slots: void setOption(const char* key, bool value);
@@ -5,6 +5,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "GamePakView.h" +#include "ConfigController.h" #include "GameController.h" extern "C" {@@ -13,9 +14,10 @@ }
using namespace QGBA; -GamePakView::GamePakView(GameController* controller, QWidget* parent) +GamePakView::GamePakView(GameController* controller, ConfigController* config, QWidget* parent) : QWidget(parent) , m_controller(controller) + , m_config(config) { m_ui.setupUi(this);@@ -54,13 +56,22 @@ connect(m_ui.hwLight, 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.save, SIGNAL(clicked()), this, SLOT(saveOverride())); + if (controller->isLoaded()) { gameStarted(controller->thread()); } } +void GamePakView::saveOverride() { + if (!m_config) { + return; + } + m_config->saveOverride(m_override); +} + void GamePakView::updateOverrides() { - GBACartridgeOverride override = { + m_override = (GBACartridgeOverride) { "", static_cast<SavedataType>(m_ui.savetype->currentIndex() - 1), GPIO_NO_OVERRIDE,@@ -68,26 +79,26 @@ 0xFFFFFFFF
}; if (!m_ui.hwAutodetect->isChecked()) { - override.hardware = GPIO_NONE; + m_override.hardware = GPIO_NONE; if (m_ui.hwRTC->isChecked()) { - override.hardware |= GPIO_RTC; + m_override.hardware |= GPIO_RTC; } if (m_ui.hwGyro->isChecked()) { - override.hardware |= GPIO_GYRO; + m_override.hardware |= GPIO_GYRO; } if (m_ui.hwLight->isChecked()) { - override.hardware |= GPIO_LIGHT_SENSOR; + m_override.hardware |= GPIO_LIGHT_SENSOR; } if (m_ui.hwTilt->isChecked()) { - override.hardware |= GPIO_TILT; + m_override.hardware |= GPIO_TILT; } if (m_ui.hwRumble->isChecked()) { - override.hardware |= GPIO_RUMBLE; + m_override.hardware |= GPIO_RUMBLE; } } - if (override.savetype != SAVEDATA_AUTODETECT || override.hardware != GPIO_NO_OVERRIDE) { - m_controller->setOverride(override); + if (m_override.savetype != SAVEDATA_AUTODETECT || m_override.hardware != GPIO_NO_OVERRIDE) { + m_controller->setOverride(m_override); } else { m_controller->clearOverride(); }@@ -113,6 +124,12 @@ m_ui.hwGyro->setChecked(thread->gba->memory.gpio.gpioDevices & GPIO_GYRO);
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.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() {@@ -131,6 +148,8 @@ m_ui.hwGyro->setChecked(false);
m_ui.hwLight->setChecked(false); m_ui.hwTilt->setChecked(false); m_ui.hwRumble->setChecked(false); + + m_ui.save->setEnabled(false); } void GamePakView::setLuminanceValue(int value) {
@@ -10,17 +10,25 @@ #include <QWidget>
#include "ui_GamePakView.h" +extern "C" { +#include "gba-overrides.h" +} + struct GBAThread; namespace QGBA { +class ConfigController; class GameController; class GamePakView : public QWidget { Q_OBJECT public: - GamePakView(GameController* controller, QWidget* parent = nullptr); + GamePakView(GameController* controller, ConfigController* config, QWidget* parent = nullptr); + +public slots: + void saveOverride(); private slots: void updateOverrides();@@ -32,6 +40,8 @@ private:
Ui::GamePakView m_ui; GameController* m_controller; + ConfigController* m_config; + GBACartridgeOverride m_override; }; }
@@ -7,7 +7,7 @@ <rect>
<x>0</x> <y>0</y> <width>251</width> - <height>391</height> + <height>433</height> </rect> </property> <property name="sizePolicy">@@ -29,6 +29,47 @@ <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy"> <enum>QFormLayout::FieldsStayAtSizeHint</enum> </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"> <widget class="Line" name="line"> <property name="orientation">@@ -93,47 +134,6 @@ <string>Light sensor</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="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Save type</string> - </property> - </widget> - </item> <item row="7" column="1"> <widget class="QCheckBox" name="hwRumble"> <property name="enabled">@@ -143,6 +143,46 @@ <property name="text">
<string>Rumble</string> </property> </widget> + </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> </widget>
@@ -229,7 +229,7 @@ shortcutView->show();
} void Window::openGamePakWindow() { - GamePakView* gamePakWindow = new GamePakView(m_controller); + GamePakView* gamePakWindow = new GamePakView(m_controller, m_config); connect(this, SIGNAL(shutdown()), gamePakWindow, SLOT(close())); gamePakWindow->setAttribute(Qt::WA_DeleteOnClose); gamePakWindow->show();