Move all configurations to a separate file.
Still not ideal as it is not straightforward to add options to places like the Video class. Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
ea99fb0584
commit
b5e5199eeb
6 changed files with 249 additions and 198 deletions
|
@ -19,6 +19,7 @@ add_executable(qapple
|
|||
gamepadpaddle.cpp
|
||||
video.cpp
|
||||
settings.cpp
|
||||
configuration.cpp
|
||||
|
||||
commands.cpp
|
||||
chunks.cpp
|
||||
|
|
222
source/frontends/qapple/configuration.cpp
Normal file
222
source/frontends/qapple/configuration.cpp
Normal file
|
@ -0,0 +1,222 @@
|
|||
#include "configuration.h"
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "Common.h"
|
||||
#include "Applewin.h"
|
||||
#include "Disk.h"
|
||||
#include "Harddisk.h"
|
||||
#include "Registry.h"
|
||||
#include "SaveState.h"
|
||||
#include "CPU.h"
|
||||
|
||||
#include "linux/paddle.h"
|
||||
|
||||
#include "gamepadpaddle.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QGamepad>
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::vector<size_t> diskIDs = {DRIVE_1, DRIVE_2};
|
||||
const std::vector<size_t> hdIDs = {HARDDISK_1, HARDDISK_2};
|
||||
|
||||
void insertDisk(const QString & filename, const int disk)
|
||||
{
|
||||
if (filename.isEmpty())
|
||||
{
|
||||
DiskEject(disk);
|
||||
}
|
||||
else
|
||||
{
|
||||
const bool createMissingDisk = true;
|
||||
const ImageError_e result = DiskInsert(disk, filename.toStdString().c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, createMissingDisk);
|
||||
if (result != eIMAGE_ERROR_NONE)
|
||||
{
|
||||
const QString message = QString("Error [%1] inserting '%2'").arg(QString::number(result), filename);
|
||||
QMessageBox::warning(NULL, "Disk error", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void insertHD(const QString & filename, const int disk)
|
||||
{
|
||||
if (filename.isEmpty())
|
||||
{
|
||||
HD_Unplug(disk);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!HD_Insert(disk, filename.toStdString().c_str()))
|
||||
{
|
||||
const QString message = QString("Error inserting '%1'").arg(filename);
|
||||
QMessageBox::warning(NULL, "Hard Disk error", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setSlot4(const SS_CARDTYPE newCardType)
|
||||
{
|
||||
g_Slot4 = newCardType;
|
||||
REGSAVE(TEXT(REGVALUE_SLOT4), (DWORD)g_Slot4);
|
||||
}
|
||||
|
||||
void setSlot5(const SS_CARDTYPE newCardType)
|
||||
{
|
||||
g_Slot5 = newCardType;
|
||||
REGSAVE(TEXT(REGVALUE_SLOT5), (DWORD)g_Slot5);
|
||||
}
|
||||
|
||||
const std::vector<eApple2Type> computerTypes = {A2TYPE_APPLE2, A2TYPE_APPLE2PLUS, A2TYPE_APPLE2E, A2TYPE_APPLE2EENHANCED,
|
||||
A2TYPE_PRAVETS82, A2TYPE_PRAVETS8M, A2TYPE_PRAVETS8A, A2TYPE_TK30002E};
|
||||
|
||||
int getApple2ComputerType()
|
||||
{
|
||||
const eApple2Type type = GetApple2Type();
|
||||
const auto it = std::find(computerTypes.begin(), computerTypes.end(), type);
|
||||
if (it != computerTypes.end())
|
||||
{
|
||||
return std::distance(computerTypes.begin(), it);
|
||||
}
|
||||
else
|
||||
{
|
||||
// default to A2E
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
void setScreenshotTemplate(const QString & filenameTemplate)
|
||||
{
|
||||
QSettings().setValue("QApple/Screenshot Template", filenameTemplate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString getScreenshotTemplate()
|
||||
{
|
||||
const QString filenameTemplate = QSettings().value("QApple/Screenshot Template", "/tmp/qapple_%1.png").toString();
|
||||
return filenameTemplate;
|
||||
}
|
||||
|
||||
Preferences::Data getCurrentOptions(const std::shared_ptr<QGamepad> & gamepad)
|
||||
{
|
||||
Preferences::Data currentOptions;
|
||||
|
||||
currentOptions.disks.resize(diskIDs.size());
|
||||
for (size_t i = 0; i < diskIDs.size(); ++i)
|
||||
{
|
||||
const char * diskName = DiskGetFullName(diskIDs[i]);
|
||||
if (diskName)
|
||||
{
|
||||
currentOptions.disks[i] = diskName;
|
||||
}
|
||||
}
|
||||
|
||||
currentOptions.hds.resize(hdIDs.size());
|
||||
for (size_t i = 0; i < hdIDs.size(); ++i)
|
||||
{
|
||||
const char * diskName = HD_GetFullName(hdIDs[i]);
|
||||
if (diskName)
|
||||
{
|
||||
currentOptions.hds[i] = diskName;
|
||||
}
|
||||
}
|
||||
|
||||
currentOptions.mouseInSlot4 = g_Slot4 == CT_MouseInterface;
|
||||
currentOptions.cpmInSlot5 = g_Slot5 == CT_Z80;
|
||||
currentOptions.hdInSlot7 = HD_CardIsEnabled();
|
||||
|
||||
currentOptions.apple2Type = getApple2ComputerType();
|
||||
|
||||
if (gamepad)
|
||||
{
|
||||
currentOptions.joystick = gamepad->name();
|
||||
currentOptions.joystickId = gamepad->deviceId();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentOptions.joystickId = 0;
|
||||
}
|
||||
|
||||
const char* saveState = Snapshot_GetFilename();
|
||||
if (saveState)
|
||||
{
|
||||
currentOptions.saveState = QString::fromUtf8(saveState);;
|
||||
}
|
||||
|
||||
currentOptions.screenshotTemplate = getScreenshotTemplate();
|
||||
|
||||
return currentOptions;
|
||||
}
|
||||
|
||||
void setNewOptions(const Preferences::Data & currentOptions, const Preferences::Data & newOptions, std::shared_ptr<QGamepad> & gamepad)
|
||||
{
|
||||
if (currentOptions.apple2Type != newOptions.apple2Type)
|
||||
{
|
||||
const eApple2Type type = computerTypes[newOptions.apple2Type];
|
||||
SetApple2Type(type);
|
||||
REGSAVE(TEXT(REGVALUE_APPLE2_TYPE), type);
|
||||
const eCpuType cpu = ProbeMainCpuDefault(type);
|
||||
SetMainCpu(cpu);
|
||||
REGSAVE(TEXT(REGVALUE_CPU_TYPE), cpu);
|
||||
}
|
||||
|
||||
if (currentOptions.mouseInSlot4 != newOptions.mouseInSlot4)
|
||||
{
|
||||
const SS_CARDTYPE card = newOptions.mouseInSlot4 ? CT_MouseInterface : CT_Empty;
|
||||
setSlot4(card);
|
||||
}
|
||||
if (currentOptions.cpmInSlot5 != newOptions.cpmInSlot5)
|
||||
{
|
||||
const SS_CARDTYPE card = newOptions.cpmInSlot5 ? CT_Z80 : CT_Empty;
|
||||
setSlot5(card);
|
||||
}
|
||||
if (currentOptions.hdInSlot7 != newOptions.hdInSlot7)
|
||||
{
|
||||
REGSAVE(TEXT(REGVALUE_HDD_ENABLED), newOptions.hdInSlot7 ? 1 : 0);
|
||||
HD_SetEnabled(newOptions.hdInSlot7);
|
||||
}
|
||||
|
||||
if (newOptions.joystick.isEmpty())
|
||||
{
|
||||
gamepad.reset();
|
||||
Paddle::instance() = std::make_shared<Paddle>();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newOptions.joystickId != currentOptions.joystickId)
|
||||
{
|
||||
gamepad.reset(new QGamepad(newOptions.joystickId));
|
||||
Paddle::instance() = std::make_shared<GamepadPaddle>(gamepad);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < diskIDs.size(); ++i)
|
||||
{
|
||||
if (currentOptions.disks[i] != newOptions.disks[i])
|
||||
{
|
||||
insertDisk(newOptions.disks[i], diskIDs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < hdIDs.size(); ++i)
|
||||
{
|
||||
if (currentOptions.hds[i] != newOptions.hds[i])
|
||||
{
|
||||
insertHD(newOptions.hds[i], hdIDs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentOptions.saveState != newOptions.saveState)
|
||||
{
|
||||
const std::string name = newOptions.saveState.toStdString();
|
||||
Snapshot_SetFilename(name);
|
||||
RegSaveString(TEXT(REG_CONFIG), REGVALUE_SAVESTATE_FILENAME, 1, name.c_str());
|
||||
}
|
||||
|
||||
if (currentOptions.screenshotTemplate != newOptions.screenshotTemplate)
|
||||
{
|
||||
setScreenshotTemplate(newOptions.screenshotTemplate);
|
||||
}
|
||||
|
||||
}
|
15
source/frontends/qapple/configuration.h
Normal file
15
source/frontends/qapple/configuration.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef CONFIGURATION_H
|
||||
#define CONFIGURATION_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "preferences.h"
|
||||
|
||||
class QGamepad;
|
||||
|
||||
QString getScreenshotTemplate();
|
||||
Preferences::Data getCurrentOptions(const std::shared_ptr<QGamepad> & gamepad);
|
||||
void setNewOptions(const Preferences::Data & currentOptions, const Preferences::Data & newOptions,
|
||||
std::shared_ptr<QGamepad> & gamepad);
|
||||
|
||||
#endif // CONFIGURATION_H
|
|
@ -132,9 +132,9 @@ void Preferences::setup(const Data & data, QSettings & settings)
|
|||
void Preferences::populateJoysticks()
|
||||
{
|
||||
joystick->clear();
|
||||
const QList<int> gamepads = QGamepadManager::instance()->connectedGamepads();
|
||||
joystick->addItem("None"); // index = 0
|
||||
|
||||
joystick->addItem("None");
|
||||
const QList<int> gamepads = QGamepadManager::instance()->connectedGamepads();
|
||||
|
||||
for (int id : gamepads)
|
||||
{
|
||||
|
@ -194,6 +194,7 @@ Preferences::Data Preferences::getData() const
|
|||
data.cpmInSlot5 = cpm_5->isChecked();
|
||||
data.hdInSlot7 = hd_7->isChecked();
|
||||
|
||||
// because index = 0 is None
|
||||
if (joystick->currentIndex() >= 1)
|
||||
{
|
||||
const QVariant & device = joystick->itemData(joystick->currentIndex());
|
||||
|
@ -216,6 +217,7 @@ void Preferences::browseDisk(const std::vector<QComboBox *> & disks, const size_
|
|||
QFileDialog diskFileDialog(this);
|
||||
diskFileDialog.setFileMode(QFileDialog::AnyFile);
|
||||
|
||||
// because index = 0 is None
|
||||
if (disks[id]->currentIndex() >= 1)
|
||||
{
|
||||
diskFileDialog.selectFile(disks[id]->currentText());
|
||||
|
|
|
@ -12,16 +12,13 @@
|
|||
#include "ParallelPrinter.h"
|
||||
#include "Video.h"
|
||||
#include "SaveState.h"
|
||||
#include "Registry.h"
|
||||
|
||||
#include "linux/data.h"
|
||||
#include "linux/benchmark.h"
|
||||
#include "linux/paddle.h"
|
||||
|
||||
#include "emulator.h"
|
||||
#include "memorycontainer.h"
|
||||
#include "gamepadpaddle.h"
|
||||
#include "settings.h"
|
||||
#include "configuration.h"
|
||||
|
||||
#include <QMdiSubWindow>
|
||||
#include <QMessageBox>
|
||||
|
@ -71,80 +68,6 @@ namespace
|
|||
DiskDestroy();
|
||||
}
|
||||
|
||||
void insertDisk(const QString & filename, const int disk)
|
||||
{
|
||||
if (filename.isEmpty())
|
||||
{
|
||||
DiskEject(disk);
|
||||
}
|
||||
else
|
||||
{
|
||||
const bool createMissingDisk = true;
|
||||
const ImageError_e result = DiskInsert(disk, filename.toStdString().c_str(), IMAGE_USE_FILES_WRITE_PROTECT_STATUS, createMissingDisk);
|
||||
if (result != eIMAGE_ERROR_NONE)
|
||||
{
|
||||
const QString message = QString("Error [%1] inserting '%2'").arg(QString::number(result), filename);
|
||||
QMessageBox::warning(NULL, "Disk error", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void insertHD(const QString & filename, const int disk)
|
||||
{
|
||||
if (filename.isEmpty())
|
||||
{
|
||||
HD_Unplug(disk);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!HD_Insert(disk, filename.toStdString().c_str()))
|
||||
{
|
||||
const QString message = QString("Error inserting '%1'").arg(filename);
|
||||
QMessageBox::warning(NULL, "Hard Disk error", message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setSlot4(const SS_CARDTYPE newCardType)
|
||||
{
|
||||
g_Slot4 = newCardType;
|
||||
REGSAVE(TEXT(REGVALUE_SLOT4), (DWORD)g_Slot4);
|
||||
}
|
||||
|
||||
void setSlot5(const SS_CARDTYPE newCardType)
|
||||
{
|
||||
g_Slot5 = newCardType;
|
||||
REGSAVE(TEXT(REGVALUE_SLOT5), (DWORD)g_Slot5);
|
||||
}
|
||||
|
||||
const std::vector<eApple2Type> computerTypes = {A2TYPE_APPLE2, A2TYPE_APPLE2PLUS, A2TYPE_APPLE2E, A2TYPE_APPLE2EENHANCED,
|
||||
A2TYPE_PRAVETS82, A2TYPE_PRAVETS8M, A2TYPE_PRAVETS8A, A2TYPE_TK30002E};
|
||||
|
||||
int getApple2ComputerType()
|
||||
{
|
||||
const eApple2Type type = GetApple2Type();
|
||||
const auto it = std::find(computerTypes.begin(), computerTypes.end(), type);
|
||||
if (it != computerTypes.end())
|
||||
{
|
||||
return std::distance(computerTypes.begin(), it);
|
||||
}
|
||||
else
|
||||
{
|
||||
// default to A2E
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
QString getScreenshotTemplate()
|
||||
{
|
||||
const QString filenameTemplate = QSettings().value("QApple/Screenshot Template", "/tmp/qapple_%1.png").toString();
|
||||
return filenameTemplate;
|
||||
}
|
||||
|
||||
void setScreenshotTemplate(const QString & filenameTemplate)
|
||||
{
|
||||
QSettings().setValue("QApple/Screenshot Template", filenameTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
void FrameDrawDiskLEDS(HDC)
|
||||
|
@ -334,53 +257,7 @@ void QApple::on_actionMemory_triggered()
|
|||
|
||||
void QApple::on_actionOptions_triggered()
|
||||
{
|
||||
Preferences::Data currentOptions;
|
||||
|
||||
const std::vector<size_t> diskIDs = {DRIVE_1, DRIVE_2};
|
||||
currentOptions.disks.resize(diskIDs.size());
|
||||
for (size_t i = 0; i < diskIDs.size(); ++i)
|
||||
{
|
||||
const char * diskName = DiskGetFullName(diskIDs[i]);
|
||||
if (diskName)
|
||||
{
|
||||
currentOptions.disks[i] = diskName;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<size_t> hdIDs = {HARDDISK_1, HARDDISK_2};
|
||||
currentOptions.hds.resize(hdIDs.size());
|
||||
for (size_t i = 0; i < hdIDs.size(); ++i)
|
||||
{
|
||||
const char * diskName = HD_GetFullName(hdIDs[i]);
|
||||
if (diskName)
|
||||
{
|
||||
currentOptions.hds[i] = diskName;
|
||||
}
|
||||
}
|
||||
|
||||
currentOptions.mouseInSlot4 = g_Slot4 == CT_MouseInterface;
|
||||
currentOptions.cpmInSlot5 = g_Slot5 == CT_Z80;
|
||||
currentOptions.hdInSlot7 = HD_CardIsEnabled();
|
||||
|
||||
currentOptions.apple2Type = getApple2ComputerType();
|
||||
|
||||
if (myGamepad)
|
||||
{
|
||||
currentOptions.joystick = myGamepad->name();
|
||||
currentOptions.joystickId = myGamepad->deviceId();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentOptions.joystickId = 0;
|
||||
}
|
||||
|
||||
const char* saveState = Snapshot_GetFilename();
|
||||
if (saveState)
|
||||
{
|
||||
currentOptions.saveState = QString::fromUtf8(saveState);;
|
||||
}
|
||||
|
||||
currentOptions.screenshotTemplate = getScreenshotTemplate();
|
||||
const Preferences::Data currentOptions = getCurrentOptions(myGamepad);
|
||||
|
||||
QSettings settings; // the function will "modify" it
|
||||
myPreferences.setup(currentOptions, settings);
|
||||
|
@ -388,76 +265,8 @@ void QApple::on_actionOptions_triggered()
|
|||
if (myPreferences.exec())
|
||||
{
|
||||
const Preferences::Data newOptions = myPreferences.getData();
|
||||
|
||||
if (currentOptions.apple2Type != newOptions.apple2Type)
|
||||
{
|
||||
const eApple2Type type = computerTypes[newOptions.apple2Type];
|
||||
SetApple2Type(type);
|
||||
REGSAVE(TEXT(REGVALUE_APPLE2_TYPE), type);
|
||||
const eCpuType cpu = ProbeMainCpuDefault(type);
|
||||
SetMainCpu(cpu);
|
||||
REGSAVE(TEXT(REGVALUE_CPU_TYPE), cpu);
|
||||
setNewOptions(currentOptions, newOptions, myGamepad);
|
||||
}
|
||||
|
||||
if (currentOptions.mouseInSlot4 != newOptions.mouseInSlot4)
|
||||
{
|
||||
const SS_CARDTYPE card = newOptions.mouseInSlot4 ? CT_MouseInterface : CT_Empty;
|
||||
setSlot4(card);
|
||||
}
|
||||
if (currentOptions.cpmInSlot5 != newOptions.cpmInSlot5)
|
||||
{
|
||||
const SS_CARDTYPE card = newOptions.cpmInSlot5 ? CT_Z80 : CT_Empty;
|
||||
setSlot5(card);
|
||||
}
|
||||
if (currentOptions.hdInSlot7 != newOptions.hdInSlot7)
|
||||
{
|
||||
REGSAVE(TEXT(REGVALUE_HDD_ENABLED), newOptions.hdInSlot7 ? 1 : 0);
|
||||
HD_SetEnabled(newOptions.hdInSlot7);
|
||||
}
|
||||
|
||||
if (newOptions.joystick.isEmpty())
|
||||
{
|
||||
myGamepad.reset();
|
||||
Paddle::instance() = std::make_shared<Paddle>();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newOptions.joystickId != currentOptions.joystickId)
|
||||
{
|
||||
myGamepad.reset(new QGamepad(newOptions.joystickId));
|
||||
Paddle::instance() = std::make_shared<GamepadPaddle>(myGamepad);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < diskIDs.size(); ++i)
|
||||
{
|
||||
if (currentOptions.disks[i] != newOptions.disks[i])
|
||||
{
|
||||
insertDisk(newOptions.disks[i], diskIDs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < hdIDs.size(); ++i)
|
||||
{
|
||||
if (currentOptions.hds[i] != newOptions.hds[i])
|
||||
{
|
||||
insertHD(newOptions.hds[i], hdIDs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentOptions.saveState != newOptions.saveState)
|
||||
{
|
||||
const std::string name = newOptions.saveState.toStdString();
|
||||
Snapshot_SetFilename(name);
|
||||
RegSaveString(TEXT(REG_CONFIG), REGVALUE_SAVESTATE_FILENAME, 1, name.c_str());
|
||||
}
|
||||
|
||||
if (currentOptions.screenshotTemplate != newOptions.screenshotTemplate)
|
||||
{
|
||||
setScreenshotTemplate(newOptions.screenshotTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void QApple::on_actionSave_state_triggered()
|
||||
|
|
|
@ -24,7 +24,8 @@ SOURCES += main.cpp\
|
|||
memorycontainer.cpp \
|
||||
preferences.cpp \
|
||||
gamepadpaddle.cpp \
|
||||
settings.cpp
|
||||
settings.cpp \
|
||||
configuration.cpp
|
||||
|
||||
HEADERS += qapple.h \
|
||||
emulator.h \
|
||||
|
@ -36,7 +37,8 @@ HEADERS += qapple.h \
|
|||
memorycontainer.h \
|
||||
preferences.h \
|
||||
gamepadpaddle.h \
|
||||
settings.h
|
||||
settings.h \
|
||||
configuration.h
|
||||
|
||||
FORMS += qapple.ui \
|
||||
emulator.ui \
|
||||
|
|
Loading…
Add table
Reference in a new issue