o switch to v46

This commit is contained in:
David Voswinkel
2009-05-12 22:17:42 +02:00
parent 7a878eab39
commit 8e877d38d4
217 changed files with 1440 additions and 31284 deletions

View File

@@ -1,94 +1,66 @@
##############################
### platform configuration ###
##############################
objects := main $(if $(call streq,$(platform),win),resource) $(objects)
ifeq ($(platform),mac)
moc = moc
rcc = rcc
link +=-F/Developer/SDKs/Qt/lib \
-L/Developer/SDKs/Qt/lib \
-framework QtOpenGL \
-framework QtGui \
-framework Carbon \
-framework AppKit \
-framework QtCore
qtflags= -I/Developer/SDKs/Qt/include/ \
-I/Developer/SDKs/Qt/include/Qt \
-I/Developer/SDKs/Qt/include/QtCore \
-I/Developer/SDKs/Qt/include/QtGui
ifeq ($(moc),)
moc := moc
endif
ifeq ($(rcc),)
rcc := rcc
endif
ifeq ($(platform),x) # X11
moc = moc-qt4
rcc = rcc
link += $(call mklib,Xtst)
link += `pkg-config --libs QtCore QtGui`
qtflags = `pkg-config --cflags QtCore QtGui`
else ifeq ($(platform),win) # Windows
qtdir = c:/qt450
link += $(call mklibpath,$(qtdir)/lib)
link += $(call mklibpath,$(qtdir)/plugins/imageformats)
ifeq ($(platform),x)
#qtflags = `pkg-config --cflags QtCore QtGui`
link += `pkg-config --libs QtCore QtGui`
qtflags = -I/Developer/SDKs/Qt/include -I/Developer/SDKs/Qt/include/QtCore -I/Developer/SDKs/Qt/include/QtGui -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -I/Developer/SDKs/Qt/include/QtOpenGL
link = -F/Developer/SDKs/Qt/lib -L/Developer/SDKs/Qt/lib -framework QtOpenGL -L/Developer/SDKs/Qt/lib -F/Developer/SDKs/Qt/lib -framework QtGui -framework Carbon -framework AppKit -framework QtCore -lz -lm -framework ApplicationServices -framework OpenGL -framework AGL -L/opt/local/lib -lSDLmain -lSDL -Wl,-framework,Cocoa -lXext -lX11 -lz
link = -F/Developer/SDKs/Qt/lib -L/Developer/SDKs/Qt/lib -framework QtOpenGL -L/Developer/SDKs/Qt/lib -F/Developer/SDKs/Qt/lib -framework QtGui -framework Carbon -framework AppKit -framework QtCore -lz -lm -framework ApplicationServices -framework OpenGL -framework AGL -L/opt/local/lib -lSDL -Wl,-framework,Cocoa -lXext -lX11 -lz -lgl
else ifeq ($(platform),win)
ifeq ($(qtpath),)
# find Qt install directory from PATH environment variable
qtpath := $(foreach path,$(subst ;, ,$(PATH)),$(if $(wildcard $(path)/$(moc).exe),$(path)))
qtpath := $(strip $(qtpath))
qtpath := $(subst \,/,$(qtpath))
qtpath := $(patsubst %/bin,%,$(qtpath))
endif
link += $(call mklib,mingw32)
link += $(call mklib,qtmain)
link += $(call mklib,QtGui)
link += $(call mklib,comdlg32)
link += $(call mklib,oleaut32)
link += $(call mklib,imm32)
link += $(call mklib,winmm)
link += $(call mklib,winspool)
link += $(call mklib,msimg32)
link += $(call mklib,QtCore)
link += $(call mklib,ole32)
link += $(call mklib,advapi32)
link += $(call mklib,ws2_32)
link += $(call mklib,uuid)
link += $(call mklib,gdi32)
qtflags := -I$(qtpath)/include
qtflags += -I$(qtpath)/include/QtCore
qtflags += -I$(qtpath)/include/QtGui
link += -L$(qtpath)/lib
link += -L$(qtpath)/plugins/imageformats
link += -lmingw32 -lqtmain -lQtGui -lcomdlg32 -loleaut32 -limm32 -lwinmm
link += -lwinspool -lmsimg32 -lQtCore -lole32 -ladvapi32 -lws2_32 -luuid -lgdi32
# optional image-file support:
# link += $(call mklib,qjpeg)
# link += $(call mklib,qmng)
qtflags = $(call mkincpath,$(qtdir)/include)
qtflags += $(call mkincpath,$(qtdir)/include/QtCore)
qtflags += $(call mkincpath,$(qtdir)/include/QtGui)
# link += -lqjpeg -lqmng
endif
moc_objects = \
$(ui)/base/main.moc \
$(ui)/base/loader.moc \
$(ui)/base/htmlviewer.moc \
$(ui)/base/about.moc \
$(ui)/settings/settings.moc \
$(ui)/settings/video.moc \
$(ui)/settings/audio.moc \
$(ui)/settings/input.moc \
$(ui)/settings/paths.moc \
$(ui)/settings/cheateditor.moc \
$(ui)/settings/advanced.moc \
$(ui)/settings/utility/inputcapture.moc \
$(ui)/settings/utility/codeeditor.moc \
moc_headers := $(call rwildcard,$(ui)/,%.mh)
moc_objects := $(patsubst %.mh,%.moc,$(moc_headers))
#############
### rules ###
#############
%.moc: $<; $(moc) $(patsubst %.moc,%.hpp,$@) -o $@
$(foreach object,$(moc_objects),$(eval $(object): $(patsubst %.moc,%.hpp,$(object))))
# automatically run moc on all .mh (.MocHeader) files
%.moc: $<; $(moc) -f $< -o $@
$(foreach f,$(moc_objects),$(eval $f: $(patsubst %.moc,%.mh,$f)))
obj/main.$(obj): $(ui)/main.cpp \
$(ui)/* $(ui)/input/* $(ui)/utility/* $(ui)/base/* $(ui)/settings/* $(ui)/settings/utility/* \
data/*
obj/main.o: $(ui)/main.cpp $(call rwildcard,$(ui)/)
$(call compile,$(qtflags))
$(ui)/resource/resource.rcc: $(ui)/resource/resource.qrc data/*
$(rcc) $(ui)/resource/resource.qrc -o $(ui)/resource/resource.rcc
obj/resource.$(obj): $(ui)/resource/resource.rc
windres $(ui)/resource/resource.rc obj/resource.$(obj)
obj/resource.o: $(ui)/resource/resource.rc
windres $(ui)/resource/resource.rc obj/resource.o
###############
### targets ###
@@ -96,5 +68,5 @@ obj/resource.$(obj): $(ui)/resource/resource.rc
ui_build: $(ui)/resource/resource.rcc $(moc_objects);
ui_clean:
-$(foreach object,$(moc_objects),@$(call delete,$(object)))
-$(foreach f,$(moc_objects),@$(call delete,$f))
-@$(call delete,$(ui)/resource/resource.rcc)

View File

@@ -1,16 +0,0 @@
class AboutWindow : public QObject {
Q_OBJECT
public:
QWidget *window;
QVBoxLayout *layout;
struct Logo : public QWidget {
void paintEvent(QPaintEvent*);
} *logo;
QLabel *info;
QWidget *spacer;
void setup();
public slots:
} *winAbout;

View File

@@ -1,13 +0,0 @@
class HtmlViewerWindow : public QObject {
Q_OBJECT
public:
QWidget *window;
QVBoxLayout *layout;
QTextBrowser *document;
void setup();
void show(const char *title, const char *htmlData);
public slots:
} *winHtmlViewer;

View File

@@ -93,7 +93,7 @@ void LoaderWindow::loadBsxSlottedCartridge(const char *filebase, const char *fil
slot1File->setText(fileSlot1);
syncUi();
mode = ModeBsxSlotted;
mode = SNES::Cartridge::ModeBsxSlotted;
showWindow("Load BS-X Slotted Cartridge");
}
@@ -109,7 +109,7 @@ void LoaderWindow::loadBsxCartridge(const char *fileBase, const char *fileSlot1)
slot1File->setText(fileSlot1);
syncUi();
mode = ModeBsx;
mode = SNES::Cartridge::ModeBsx;
showWindow("Load BS-X Cartridge");
}
@@ -127,8 +127,24 @@ void LoaderWindow::loadSufamiTurboCartridge(const char *fileBase, const char *fi
slot2File->setText(fileSlot2);
syncUi();
mode = ModeSufamiTurbo;
mode = SNES::Cartridge::ModeSufamiTurbo;
showWindow("Load Sufami Turbo Cartridge");
}
void LoaderWindow::loadSuperGameBoyCartridge(const char *fileBase, const char *fileSlot1) {
window->hide();
baseLabel->show(), baseFile->show(), baseBrowse->show(), baseClear->show();
slot1Label->show(), slot1File->show(), slot1Browse->show(), slot1Clear->show();
slot2Label->hide(), slot2File->hide(), slot2Browse->hide(), slot2Clear->hide();
slot1Label->setText("Game Boy cartridge:");
baseFile->setText(fileBase);
slot1File->setText(fileSlot1);
syncUi();
mode = SNES::Cartridge::ModeSuperGameBoy;
showWindow("Load Super Game Boy Cartridge");
}
void LoaderWindow::showWindow(const char *title) {
@@ -177,18 +193,23 @@ void LoaderWindow::onLoad() {
string slot2 = slot2File->text().toUtf8().data();
switch(mode) {
case ModeBsxSlotted: {
case SNES::Cartridge::ModeBsxSlotted: {
utility.loadCartridgeBsxSlotted(base, slot1);
} break;
case ModeBsx: {
snes.config.path.bsx = base;
case SNES::Cartridge::ModeBsx: {
config.path.bsx = base;
utility.loadCartridgeBsx(base, slot1);
} break;
case ModeSufamiTurbo: {
snes.config.path.st = base;
case SNES::Cartridge::ModeSufamiTurbo: {
config.path.st = base;
utility.loadCartridgeSufamiTurbo(base, slot1, slot2);
} break;
case SNES::Cartridge::ModeSuperGameBoy: {
config.path.sgb = base;
utility.loadCartridgeSuperGameBoy(base, slot1);
} break;
}
}

View File

@@ -1,45 +0,0 @@
class LoaderWindow : public QObject {
Q_OBJECT
public:
QWidget *window;
QVBoxLayout *layout;
QGridLayout *grid;
QLabel *baseLabel;
QLineEdit *baseFile;
QPushButton *baseBrowse;
QPushButton *baseClear;
QLabel *slot1Label;
QLineEdit *slot1File;
QPushButton *slot1Browse;
QPushButton *slot1Clear;
QLabel *slot2Label;
QLineEdit *slot2File;
QPushButton *slot2Browse;
QPushButton *slot2Clear;
QHBoxLayout *controls;
QPushButton *load;
QPushButton *cancel;
QWidget *spacer;
void setup();
void syncUi();
void loadBsxSlottedCartridge(const char*, const char*);
void loadBsxCartridge(const char*, const char*);
void loadSufamiTurboCartridge(const char*, const char*, const char*);
public slots:
void selectBaseCartridge();
void clearBaseCartridge();
void selectSlot1Cartridge();
void clearSlot1Cartridge();
void selectSlot2Cartridge();
void clearSlot2Cartridge();
void onLoad();
void onCancel();
private:
enum mode_t { ModeBsxSlotted, ModeBsx, ModeSufamiTurbo } mode;
void showWindow(const char *title);
} *winLoader;

View File

@@ -3,7 +3,7 @@ void MainWindow::setup() {
window->setObjectName("main-window");
window->setWindowTitle(BSNES_TITLE);
system = window->menuBar()->addMenu("&System");
system = window->menuBar()->addMenu("System");
system_load = system->addAction("&Load Cartridge ...");
system->addSeparator();
system_power = system->addMenu("&Power");
@@ -41,7 +41,7 @@ void MainWindow::setup() {
system_exit = system->addAction("E&xit");
system_exit->setMenuRole(QAction::QuitRole);
settings = window->menuBar()->addMenu("S&ettings");
settings = window->menuBar()->addMenu("Settings");
settings_videoMode = settings->addMenu("&Video Mode");
settings_videoMode_1x = settings_videoMode->addAction("Scale &1x");
settings_videoMode_1x->setCheckable(true);
@@ -110,7 +110,7 @@ void MainWindow::setup() {
settings_configuration = settings->addAction("&Configuration ...");
settings_configuration->setMenuRole(QAction::PreferencesRole);
help = window->menuBar()->addMenu("&Help");
help = window->menuBar()->addMenu("Help");
help_documentation = help->addAction("Documentation ...");
help_license = help->addAction("License ...");
help->addSeparator();
@@ -195,22 +195,22 @@ void MainWindow::setup() {
}
void MainWindow::syncUi() {
system_power->setEnabled(cartridge.loaded());
system_power->setEnabled(SNES::cartridge.loaded());
system_power_on->setChecked (application.power == true);
system_power_off->setChecked(application.power == false);
system_reset->setEnabled(cartridge.loaded() && application.power);
system_reset->setEnabled(SNES::cartridge.loaded() && application.power);
system_port1_none->setChecked (snes.config.controller_port1 == SNES::Input::DeviceNone);
system_port1_joypad->setChecked (snes.config.controller_port1 == SNES::Input::DeviceJoypad);
system_port1_multitap->setChecked (snes.config.controller_port1 == SNES::Input::DeviceMultitap);
system_port1_mouse->setChecked (snes.config.controller_port1 == SNES::Input::DeviceMouse);
system_port2_none->setChecked (snes.config.controller_port2 == SNES::Input::DeviceNone);
system_port2_joypad->setChecked (snes.config.controller_port2 == SNES::Input::DeviceJoypad);
system_port2_multitap->setChecked (snes.config.controller_port2 == SNES::Input::DeviceMultitap);
system_port2_mouse->setChecked (snes.config.controller_port2 == SNES::Input::DeviceMouse);
system_port2_superscope->setChecked(snes.config.controller_port2 == SNES::Input::DeviceSuperScope);
system_port2_justifier->setChecked (snes.config.controller_port2 == SNES::Input::DeviceJustifier);
system_port2_justifiers->setChecked(snes.config.controller_port2 == SNES::Input::DeviceJustifiers);
system_port1_none->setChecked (SNES::config.controller_port1 == SNES::Input::DeviceNone);
system_port1_joypad->setChecked (SNES::config.controller_port1 == SNES::Input::DeviceJoypad);
system_port1_multitap->setChecked (SNES::config.controller_port1 == SNES::Input::DeviceMultitap);
system_port1_mouse->setChecked (SNES::config.controller_port1 == SNES::Input::DeviceMouse);
system_port2_none->setChecked (SNES::config.controller_port2 == SNES::Input::DeviceNone);
system_port2_joypad->setChecked (SNES::config.controller_port2 == SNES::Input::DeviceJoypad);
system_port2_multitap->setChecked (SNES::config.controller_port2 == SNES::Input::DeviceMultitap);
system_port2_mouse->setChecked (SNES::config.controller_port2 == SNES::Input::DeviceMouse);
system_port2_superscope->setChecked(SNES::config.controller_port2 == SNES::Input::DeviceSuperScope);
system_port2_justifier->setChecked (SNES::config.controller_port2 == SNES::Input::DeviceJustifier);
system_port2_justifiers->setChecked(SNES::config.controller_port2 == SNES::Input::DeviceJustifiers);
settings_videoMode_1x->setChecked (config.video.context->multiplier == 1);
settings_videoMode_2x->setChecked (config.video.context->multiplier == 2);
@@ -252,17 +252,17 @@ void MainWindow::powerOn() { utility.modifySystemState(Utility::PowerOn); }
void MainWindow::powerOff() { utility.modifySystemState(Utility::PowerOff); }
void MainWindow::reset() { utility.modifySystemState(Utility::Reset); }
void MainWindow::setPort1None() { snes.config.controller_port1 = SNES::Input::DeviceNone; utility.updateControllers(); syncUi(); }
void MainWindow::setPort1Joypad() { snes.config.controller_port1 = SNES::Input::DeviceJoypad; utility.updateControllers(); syncUi(); }
void MainWindow::setPort1Multitap() { snes.config.controller_port1 = SNES::Input::DeviceMultitap; utility.updateControllers(); syncUi(); }
void MainWindow::setPort1Mouse() { snes.config.controller_port1 = SNES::Input::DeviceMouse; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2None() { snes.config.controller_port2 = SNES::Input::DeviceNone; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Joypad() { snes.config.controller_port2 = SNES::Input::DeviceJoypad; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Multitap() { snes.config.controller_port2 = SNES::Input::DeviceMultitap; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Mouse() { snes.config.controller_port2 = SNES::Input::DeviceMouse; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2SuperScope() { snes.config.controller_port2 = SNES::Input::DeviceSuperScope; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Justifier() { snes.config.controller_port2 = SNES::Input::DeviceJustifier; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Justifiers() { snes.config.controller_port2 = SNES::Input::DeviceJustifiers; utility.updateControllers(); syncUi(); }
void MainWindow::setPort1None() { SNES::config.controller_port1 = SNES::Input::DeviceNone; utility.updateControllers(); syncUi(); }
void MainWindow::setPort1Joypad() { SNES::config.controller_port1 = SNES::Input::DeviceJoypad; utility.updateControllers(); syncUi(); }
void MainWindow::setPort1Multitap() { SNES::config.controller_port1 = SNES::Input::DeviceMultitap; utility.updateControllers(); syncUi(); }
void MainWindow::setPort1Mouse() { SNES::config.controller_port1 = SNES::Input::DeviceMouse; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2None() { SNES::config.controller_port2 = SNES::Input::DeviceNone; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Joypad() { SNES::config.controller_port2 = SNES::Input::DeviceJoypad; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Multitap() { SNES::config.controller_port2 = SNES::Input::DeviceMultitap; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Mouse() { SNES::config.controller_port2 = SNES::Input::DeviceMouse; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2SuperScope() { SNES::config.controller_port2 = SNES::Input::DeviceSuperScope; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Justifier() { SNES::config.controller_port2 = SNES::Input::DeviceJustifier; utility.updateControllers(); syncUi(); }
void MainWindow::setPort2Justifiers() { SNES::config.controller_port2 = SNES::Input::DeviceJustifiers; utility.updateControllers(); syncUi(); }
void MainWindow::quit() {
application.terminate = true;
@@ -356,7 +356,7 @@ void CanvasObject::dropEvent(QDropEvent *event) {
//custom video render and mouse capture functionality
QPaintEngine* CanvasWidget::paintEngine() const {
if(cartridge.loaded()) return 0;
if(SNES::cartridge.loaded()) return 0;
return QWidget::paintEngine();
}

View File

@@ -1,129 +0,0 @@
class CanvasObject : public QWidget {
public:
void dragEnterEvent(QDragEnterEvent*);
void dropEvent(QDropEvent*);
};
class CanvasWidget : public CanvasObject {
public:
QPaintEngine* paintEngine() const;
void mouseReleaseEvent(QMouseEvent*);
void paintEvent(QPaintEvent*);
};
class MainWindow : public QObject {
Q_OBJECT
public:
struct Window : public QMainWindow {
void closeEvent(QCloseEvent*);
} *window;
QVBoxLayout *layout;
QMenu *system;
QAction *system_load;
QMenu *system_power;
QAction *system_power_on;
QAction *system_power_off;
QAction *system_reset;
QMenu *system_port1;
QAction *system_port1_none;
QAction *system_port1_joypad;
QAction *system_port1_multitap;
QAction *system_port1_mouse;
QMenu *system_port2;
QAction *system_port2_none;
QAction *system_port2_joypad;
QAction *system_port2_multitap;
QAction *system_port2_mouse;
QAction *system_port2_superscope;
QAction *system_port2_justifier;
QAction *system_port2_justifiers;
QAction *system_exit;
QMenu *settings;
QMenu *settings_videoMode;
QAction *settings_videoMode_1x;
QAction *settings_videoMode_2x;
QAction *settings_videoMode_3x;
QAction *settings_videoMode_4x;
QAction *settings_videoMode_max;
QAction *settings_videoMode_correctAspectRatio;
QAction *settings_videoMode_fullscreen;
QAction *settings_videoMode_ntsc;
QAction *settings_videoMode_pal;
QMenu *settings_videoFilter;
QAction *settings_videoFilter_point;
QAction *settings_videoFilter_linear;
QAction *settings_videoFilter_none;
QAction *settings_videoFilter_scanline;
QAction *settings_videoFilter_scale2x;
QAction *settings_videoFilter_hq2x;
QAction *settings_videoFilter_ntsc;
QAction *settings_muteAudio;
QMenu *settings_emulationSpeed;
QAction *settings_emulationSpeed_slowest;
QAction *settings_emulationSpeed_slow;
QAction *settings_emulationSpeed_normal;
QAction *settings_emulationSpeed_fast;
QAction *settings_emulationSpeed_fastest;
QAction *settings_emulationSpeed_syncVideo;
QAction *settings_emulationSpeed_syncAudio;
QAction *settings_configuration;
QMenu *help;
QAction *help_documentation;
QAction *help_license;
QAction *help_about;
//
CanvasObject *canvasContainer;
QVBoxLayout *canvasLayout;
CanvasWidget *canvas;
QLabel *systemState;
void setup();
void syncUi();
public slots:
void loadCartridge();
void powerOn();
void powerOff();
void reset();
void setPort1None();
void setPort1Joypad();
void setPort1Multitap();
void setPort1Mouse();
void setPort2None();
void setPort2Joypad();
void setPort2Multitap();
void setPort2Mouse();
void setPort2SuperScope();
void setPort2Justifier();
void setPort2Justifiers();
void quit();
void setVideoMode1x();
void setVideoMode2x();
void setVideoMode3x();
void setVideoMode4x();
void setVideoModeMax();
void toggleAspectCorrection();
void toggleFullscreen();
void setVideoNtsc();
void setVideoPal();
void setPointFilter();
void setLinearFilter();
void setNoFilter();
void setScanlineFilter();
void setScale2xFilter();
void setHq2xFilter();
void setNtscFilter();
void muteAudio();
void setSpeedSlowest();
void setSpeedSlow();
void setSpeedNormal();
void setSpeedFast();
void setSpeedFastest();
void syncVideo();
void syncAudio();
void showConfigWindow();
void showDocumentation();
void showLicense();
void showAbout();
} *winMain;

View File

@@ -1,10 +1,23 @@
class Configuration : public configuration {
public:
public:
struct System {
string video, audio, input;
bool crashedOnLastRun;
unsigned speed;
} system;
} system;
struct File {
bool autodetect_type;
bool bypass_patch_crc32;
} file;
struct Path {
string base; //binary path
string user; //user profile path (bsnes.cfg, ...)
string current; //current working directory (path to currently loaded cartridge)
string rom, save, patch, cheat, data;
string bsx, st, sgb;
} path;
struct Video {
bool isFullscreen;
@@ -70,34 +83,23 @@ public:
//external
//========
attach(snes.config.controller_port1 = SNES::Input::DeviceJoypad, "snes.controllerPort1");
attach(snes.config.controller_port2 = SNES::Input::DeviceJoypad, "snes.controllerPort2");
attach(snes.config.expansion_port = SNES::ExpansionBSX, "snes.expansionPort");
attach(snes.config.region = SNES::Autodetect, "snes.region");
attach(SNES::config.controller_port1 = SNES::Input::DeviceJoypad, "snes.controllerPort1");
attach(SNES::config.controller_port2 = SNES::Input::DeviceJoypad, "snes.controllerPort2");
attach(SNES::config.expansion_port = SNES::System::ExpansionBSX, "snes.expansionPort");
attach(SNES::config.region = SNES::System::Autodetect, "snes.region");
attach(snes.config.file.autodetect_type = false, "file.autodetectType");
attach(snes.config.file.bypass_patch_crc32 = false, "file.bypassPatchCrc32");
attach(SNES::config.cpu.version = 2, "cpu.version", "Valid version(s) are: 1, 2");
attach(SNES::config.cpu.ntsc_clock_rate = 21477272, "cpu.ntscClockRate");
attach(SNES::config.cpu.pal_clock_rate = 21281370, "cpu.palClockRate");
attach(SNES::config.cpu.alu_mul_delay = 2, "cpu.aluMulDelay");
attach(SNES::config.cpu.alu_div_delay = 2, "cpu.aluDivDelay");
attach(SNES::config.cpu.wram_init_value = 0x55, "cpu.wramInitValue");
attach(snes.config.path.rom = "", "path.rom");
attach(snes.config.path.save = "", "path.save");
attach(snes.config.path.patch = "", "path.patch");
attach(snes.config.path.cheat = "", "path.cheat");
attach(snes.config.path.data = "", "path.data");
attach(snes.config.path.bsx = "", "path.bsx");
attach(snes.config.path.st = "", "path.st");
attach(SNES::config.smp.ntsc_clock_rate = 32041 * 768, "smp.ntscClockRate");
attach(SNES::config.smp.pal_clock_rate = 32041 * 768, "smp.palClockRate");
attach(snes.config.cpu.version = 2, "cpu.version", "Valid version(s) are: 1, 2");
attach(snes.config.cpu.ntsc_clock_rate = 21477272, "cpu.ntscClockRate");
attach(snes.config.cpu.pal_clock_rate = 21281370, "cpu.palClockRate");
attach(snes.config.cpu.alu_mul_delay = 2, "cpu.aluMulDelay");
attach(snes.config.cpu.alu_div_delay = 2, "cpu.aluDivDelay");
attach(snes.config.cpu.wram_init_value = 0x55, "cpu.wramInitValue");
attach(snes.config.smp.ntsc_clock_rate = 32041 * 768, "smp.ntscClockRate");
attach(snes.config.smp.pal_clock_rate = 32041 * 768, "smp.palClockRate");
attach(snes.config.ppu1.version = 1, "ppu1.version", "Valid version(s) are: 1");
attach(snes.config.ppu2.version = 3, "ppu2.version", "Valid version(s) are: 1, 2, 3");
attach(SNES::config.ppu1.version = 1, "ppu1.version", "Valid version(s) are: 1");
attach(SNES::config.ppu2.version = 3, "ppu2.version", "Valid version(s) are: 1, 2, 3");
//========
//internal
@@ -107,7 +109,19 @@ public:
attach(system.audio = "", "system.audio");
attach(system.input = "", "system.input");
attach(system.crashedOnLastRun = false, "system.crashedOnLastRun");
attach(system.speed = 2, "system.speed");
attach(system.speed = 2, "system.speed");
attach(file.autodetect_type = false, "file.autodetectType");
attach(file.bypass_patch_crc32 = false, "file.bypassPatchCrc32");
attach(path.rom = "", "path.rom");
attach(path.save = "", "path.save");
attach(path.patch = "", "path.patch");
attach(path.cheat = "", "path.cheat");
attach(path.data = "", "path.data");
attach(path.bsx = "", "path.bsx");
attach(path.st = "", "path.st");
attach(path.sgb = "", "path.sgb");
video.context = &video.windowed;
attach(video.isFullscreen = false, "video.isFullscreen");

View File

@@ -1,31 +1,27 @@
SNESInterface snesinterface;
void SNESInterface::video_refresh(uint16_t *data, unsigned pitch, unsigned *line, unsigned width, unsigned height) {
uint32_t *output;
unsigned outpitch;
if(video.lock(output, outpitch) == true) {
unsigned outwidth, outheight;
libfilter::filter.render(output, outpitch, outwidth, outheight, data, pitch, line, width, height);
video.unlock();
video.refresh(outwidth, outheight);
class Interface : public SNES::Interface {
public:
void video_refresh(uint16_t *data, unsigned pitch, unsigned *line, unsigned width, unsigned height) {
uint32_t *output;
unsigned outpitch;
if(video.lock(output, outpitch) == true) {
unsigned outwidth, outheight;
libfilter::filter.render(output, outpitch, outwidth, outheight, data, pitch, line, width, height);
video.unlock();
video.refresh(outwidth, outheight);
}
}
}
void SNESInterface::audio_sample(uint16_t left, uint16_t right) {
if(config.audio.mute) left = right = 0;
audio.sample(left, right);
}
void audio_sample(uint16_t left, uint16_t right) {
if(config.audio.mute) left = right = 0;
audio.sample(left, right);
}
void SNESInterface::input_poll() {
inputManager.poll();
}
void input_poll() {
inputManager.poll();
}
int16_t SNESInterface::input_poll(unsigned deviceid, unsigned id) {
return inputManager.getStatus(deviceid, id);
}
void SNESInterface::init() {
}
void SNESInterface::term() {
}
int16_t input_poll(unsigned deviceid, unsigned id) {
return inputManager.getStatus(deviceid, id);
}
} interface;

View File

@@ -51,30 +51,30 @@ void Application::initPaths(const char *basename) {
}
if(strend(temp, "/") == false) strcat(temp, "/");
snes.config.path.base = temp;
config.path.base = temp;
} else {
snes.config.path.base = "";
config.path.base = "";
}
if(userpath(temp)) {
strtr(temp, "\\", "/");
if(strend(temp, "/") == false) strcat(temp, "/");
snes.config.path.user = temp;
config.path.user = temp;
} else {
snes.config.path.user = "";
config.path.user = "";
}
char cwd[PATH_MAX];
snes.config.path.current = getcwd(cwd);
config.path.current = getcwd(cwd);
}
void Application::locateFile(string &filename, bool createDataDirectory) {
//first, check if file exists in executable directory (single-user mode)
string temp = string() << snes.config.path.base << filename;
string temp = string() << config.path.base << filename;
if(file::exists(temp) == false) {
//if not, use user data path (multi-user mode)
temp = snes.config.path.user;
temp = config.path.user;
temp << ".bsnes";
if(createDataDirectory) mkdir(temp); //ensure directory exists
temp << "/" << filename;
@@ -104,7 +104,7 @@ int Application::main(int argc, char **argv) {
config.load(configFilename);
init();
snes.init();
SNES::system.init(&interface);
if(argc == 2) {
//if valid file was specified on the command-line, attempt to load it now
@@ -117,7 +117,8 @@ int Application::main(int argc, char **argv) {
inputManager.refresh();
if(config.input.focusPolicy == Configuration::Input::FocusPolicyPauseEmulation) {
bool inactive = (winMain->window->isActiveWindow() == false);
bool inactive = (winMain->window->isActiveWindow() == false)
|| (winMain->window->isMinimized() == true);
if(!autopause && inactive) {
autopause = true;
audio.clear();
@@ -128,15 +129,31 @@ int Application::main(int argc, char **argv) {
autopause = false;
}
if(cartridge.loaded() && !pause && !autopause) {
snes.runtoframe();
if(SNES::cartridge.loaded() && !pause && !autopause) {
SNES::system.runtoframe();
} else {
usleep(20 * 1000);
}
clock_t currentTime = clock();
autosaveTime += currentTime - clockTime;
screensaverTime += currentTime - clockTime;
clockTime = currentTime;
if(autosaveTime >= CLOCKS_PER_SEC * 60) {
//auto-save RAM once per minute in case of emulator crash
autosaveTime = 0;
utility.saveMemory();
}
if(screensaverTime >= CLOCKS_PER_SEC * 30) {
//supress screen saver every 30 seconds so it will not trigger during gameplay
screensaverTime = 0;
supressScreenSaver();
}
supressScreenSaver();
}
utility.unloadCartridge();
config.save(configFilename);
return 0;
}
@@ -149,7 +166,11 @@ Application::Application() {
terminate = false;
power = false;
pause = false;
autopause = false;
autopause = false;
clockTime = clock();
autosaveTime = 0;
screensaverTime = 0;
}
Application::~Application() {

View File

@@ -10,15 +10,25 @@
//Q_IMPORT_PLUGIN(QMngPlugin)
#include <../base.hpp>
#include <../cart/cart.hpp>
#include <nall/config.hpp>
#include <nall/function.hpp>
#include <nall/input.hpp>
using namespace nall;
#include <ruby/ruby.hpp>
using namespace ruby;
using namespace ruby;
#include <libreader/libreader.hpp>
#include <libreader/filereader.hpp>
#if defined(GZIP_SUPPORT)
#include <libreader/gzreader.hpp>
#include <libreader/zipreader.hpp>
#endif
#if defined(JMA_SUPPORT)
#include <libreader/jmareader.hpp>
#endif
#include <libfilter/libfilter.hpp>
@@ -38,7 +48,11 @@ public:
bool terminate; //set to true to terminate main() loop and exit emulator
bool power;
bool pause;
bool autopause;
bool autopause;
clock_t clockTime;
clock_t autosaveTime;
clock_t screensaverTime;
string configFilename;
string styleSheetFilename;

View File

@@ -53,12 +53,22 @@
void supressScreenSaver() {
//handled by event filter above
}
#else
#else
#define None XNone
#define Window XWindow
#include <X11/extensions/XTest.h>
#include <X11/Xlib.h>
#undef None
#undef Window
#undef Window
struct LibXtst : public library {
function<int (Display*, unsigned int, Bool, unsigned long)> XTestFakeKeyEvent;
LibXtst() {
if(open("Xtst")) {
XTestFakeKeyEvent = sym("XTestFakeKeyEvent");
}
}
} libXtst;
//POSIX-compatible (Linux, BSD, etc.)
char* userpath(char *path) {
@@ -77,12 +87,8 @@
void initargs(int &argc, char **&argv) {
}
void supressScreenSaver() {
static clock_t delta_x = 0, delta_y = 0;
delta_y = clock();
if(delta_y - delta_x < CLOCKS_PER_SEC * 20) return;
delta_x = delta_y;
void supressScreenSaver() {
if(!libXtst.XTestFakeKeyEvent) return;
//XSetScreenSaver(timeout = 0) does not work
//XResetScreenSaver() does not work
@@ -91,9 +97,9 @@
//XSendEvent(KeyPressMask) does not work
//use XTest extension to send fake keypress every ~20 seconds.
//keycode of 255 does not map to any actual key,
//but it will block screensaver and power management.
//but it will block screensaver and power management.
Display *display = XOpenDisplay(0);
//XTestFakeKeyEvent(display, 255, True, 0);
//XTestFakeKeyEvent(display, 255, False, 0);
libXtst.XTestFakeKeyEvent(display, 255, True, 0);
libXtst.XTestFakeKeyEvent(display, 255, False, 0);
}
#endif

View File

@@ -147,12 +147,12 @@ void AdvancedSettingsWindow::initializeUi() {
if(part[i] == config.system.input) inputDriver->setCurrentIndex(i);
}
regionAuto->setChecked(snes.config.region == SNES::Autodetect);
regionNTSC->setChecked(snes.config.region == SNES::NTSC);
regionPAL->setChecked (snes.config.region == SNES::PAL);
regionAuto->setChecked(SNES::config.region == SNES::System::Autodetect);
regionNTSC->setChecked(SNES::config.region == SNES::System::NTSC);
regionPAL->setChecked (SNES::config.region == SNES::System::PAL);
portSatellaview->setChecked(snes.config.expansion_port == SNES::ExpansionBSX);
portNone->setChecked (snes.config.expansion_port == SNES::ExpansionNone);
portSatellaview->setChecked(SNES::config.expansion_port == SNES::System::ExpansionBSX);
portNone->setChecked (SNES::config.expansion_port == SNES::System::ExpansionNone);
focusPause->setChecked (config.input.focusPolicy == Configuration::Input::FocusPolicyPauseEmulation);
focusIgnore->setChecked(config.input.focusPolicy == Configuration::Input::FocusPolicyIgnoreInput);
@@ -171,12 +171,12 @@ void AdvancedSettingsWindow::inputDriverChange(int index) {
if(index >= 0) config.system.input = inputDriver->itemText(index).toUtf8().data();
}
void AdvancedSettingsWindow::setRegionAuto() { snes.config.region = SNES::Autodetect; }
void AdvancedSettingsWindow::setRegionNTSC() { snes.config.region = SNES::NTSC; }
void AdvancedSettingsWindow::setRegionPAL() { snes.config.region = SNES::PAL; }
void AdvancedSettingsWindow::setRegionAuto() { SNES::config.region = SNES::System::Autodetect; }
void AdvancedSettingsWindow::setRegionNTSC() { SNES::config.region = SNES::System::NTSC; }
void AdvancedSettingsWindow::setRegionPAL() { SNES::config.region = SNES::System::PAL; }
void AdvancedSettingsWindow::setPortSatellaview() { snes.config.expansion_port = SNES::ExpansionBSX; }
void AdvancedSettingsWindow::setPortNone() { snes.config.expansion_port = SNES::ExpansionNone; }
void AdvancedSettingsWindow::setPortSatellaview() { SNES::config.expansion_port = SNES::System::ExpansionBSX; }
void AdvancedSettingsWindow::setPortNone() { SNES::config.expansion_port = SNES::System::ExpansionNone; }
void AdvancedSettingsWindow::pauseWithoutFocus() { config.input.focusPolicy = Configuration::Input::FocusPolicyPauseEmulation; }
void AdvancedSettingsWindow::ignoreInputWithoutFocus() { config.input.focusPolicy = Configuration::Input::FocusPolicyIgnoreInput; }

View File

@@ -1,54 +0,0 @@
class AdvancedSettingsWindow : public QObject {
Q_OBJECT
public:
QWidget *panel;
QVBoxLayout *layout;
QLabel *title;
QGridLayout *driverLayout;
QLabel *videoLabel;
QLabel *audioLabel;
QLabel *inputLabel;
QComboBox *videoDriver;
QComboBox *audioDriver;
QComboBox *inputDriver;
QLabel *driverInfo;
QLabel *regionTitle;
QHBoxLayout *regionLayout;
QButtonGroup *regionGroup;
QRadioButton *regionAuto;
QRadioButton *regionNTSC;
QRadioButton *regionPAL;
QLabel *portTitle;
QHBoxLayout *portLayout;
QButtonGroup *portGroup;
QRadioButton *portSatellaview;
QRadioButton *portNone;
QWidget *portSpacer;
QLabel *focusTitle;
QHBoxLayout *focusLayout;
QButtonGroup *focusButtonGroup;
QRadioButton *focusPause;
QRadioButton *focusIgnore;
QRadioButton *focusAllow;
QWidget *spacer;
void setup();
void initializeUi();
public slots:
void videoDriverChange(int index);
void audioDriverChange(int index);
void inputDriverChange(int index);
void setRegionAuto();
void setRegionNTSC();
void setRegionPAL();
void setPortSatellaview();
void setPortNone();
void pauseWithoutFocus();
void ignoreInputWithoutFocus();
void allowInputWithoutFocus();
} *winAdvancedSettings;

View File

@@ -1,28 +0,0 @@
class AudioSettingsWindow : public QObject {
Q_OBJECT
public:
QWidget *panel;
QVBoxLayout *layout;
QLabel *title;
QHBoxLayout *boxes;
QLabel *frequencyLabel;
QComboBox *frequency;
QLabel *latencyLabel;
QComboBox *latency;
QGridLayout *sliders;
QLabel *volumeLabel;
QSlider *volume;
QLabel *frequencySkewLabel;
QSlider *frequencySkew;
QWidget *spacer;
void setup();
void syncUi();
public slots:
void frequencyChange(int value);
void latencyChange(int value);
void volumeAdjust(int value);
void frequencySkewAdjust(int value);
} *winAudioSettings;

View File

@@ -42,10 +42,10 @@ void CheatEditorWindow::setup() {
}
void CheatEditorWindow::syncUi() {
addCode->setEnabled(cartridge.loaded());
addCode->setEnabled(SNES::cartridge.loaded());
QList<QTreeWidgetItem*> itemList = list->selectedItems();
editCode->setEnabled(cartridge.loaded() && itemList.count() == 1);
deleteCode->setEnabled(cartridge.loaded() && itemList.count() == 1);
editCode->setEnabled(SNES::cartridge.loaded() && itemList.count() == 1);
deleteCode->setEnabled(SNES::cartridge.loaded() && itemList.count() == 1);
}
//called when loading a new game, or after adding / deleting a code:
@@ -57,10 +57,10 @@ void CheatEditorWindow::reloadList() {
list->setSortingEnabled(false);
listItem.reset();
if(cartridge.loaded()) {
for(unsigned i = 0; i < cheat.count(); i++) {
Cheat::cheat_t code;
cheat.get(i, code);
if(SNES::cartridge.loaded()) {
for(unsigned i = 0; i < SNES::cheat.count(); i++) {
SNES::Cheat::cheat_t code;
SNES::cheat.get(i, code);
//only want to show one code / description line in list
lstring lcode, ldesc;
@@ -91,8 +91,8 @@ void CheatEditorWindow::updateList() {
disconnect(list, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(itemChanged(QTreeWidgetItem*)));
for(unsigned i = 0; i < listItem.size(); i++) {
Cheat::cheat_t code;
cheat.get(i, code);
SNES::Cheat::cheat_t code;
SNES::cheat.get(i, code);
//only want to show one code / description line in list
lstring lcode, ldesc;
@@ -116,7 +116,7 @@ void CheatEditorWindow::updateList() {
//called when item enabled checkbox was clicked (eg cheat code enable state was toggled on or off)
void CheatEditorWindow::itemChanged(QTreeWidgetItem *item) {
signed i = listItem.find(item);
if(i >= 0) item->checkState(1) == Qt::Checked ? cheat.enable(i) : cheat.disable(i);
if(i >= 0) item->checkState(1) == Qt::Checked ? SNES::cheat.enable(i) : SNES::cheat.disable(i);
}
void CheatEditorWindow::listChanged() {
@@ -124,11 +124,11 @@ void CheatEditorWindow::listChanged() {
}
void CheatEditorWindow::addNewCode() {
if(cartridge.loaded()) winCodeEditor->addCode();
if(SNES::cartridge.loaded()) winCodeEditor->addCode();
}
void CheatEditorWindow::editSelectedCode() {
if(cartridge.loaded()) {
if(SNES::cartridge.loaded()) {
QTreeWidgetItem *item = list->currentItem();
if(item && item->isSelected()) {
signed i = listItem.find(item);
@@ -138,7 +138,7 @@ void CheatEditorWindow::editSelectedCode() {
}
void CheatEditorWindow::deleteSelectedCode() {
if(cartridge.loaded()) {
if(SNES::cartridge.loaded()) {
QTreeWidgetItem *item = list->currentItem();
if(item && item->isSelected()) {
signed i = listItem.find(item);
@@ -148,7 +148,7 @@ void CheatEditorWindow::deleteSelectedCode() {
if(winCodeEditor->activeCode >= 0) winCodeEditor->dismiss();
//remove code, and resync listItem with cheat list
cheat.remove(i);
SNES::cheat.remove(i);
reloadList();
}
}

View File

@@ -1,28 +0,0 @@
class CheatEditorWindow : public QObject {
Q_OBJECT
public:
QWidget *panel;
QVBoxLayout *layout;
QLabel *title;
QTreeWidget *list;
QHBoxLayout *controls;
QPushButton *addCode;
QPushButton *editCode;
QPushButton *deleteCode;
void setup();
void syncUi();
void reloadList();
void updateList();
public slots:
void itemChanged(QTreeWidgetItem *item);
void listChanged();
void addNewCode();
void editSelectedCode();
void deleteSelectedCode();
private:
array<QTreeWidgetItem*> listItem;
} *winCheatEditor;

View File

@@ -1,32 +0,0 @@
class InputSettingsWindow : public QObject {
Q_OBJECT
public:
QWidget *panel;
QVBoxLayout *layout;
QLabel *title;
QHBoxLayout *selection;
QComboBox *port;
QComboBox *device;
QTreeWidget *list;
QHBoxLayout *controls;
QPushButton *assign;
QPushButton *assignAll;
QPushButton *unassign;
void setup();
void syncUi();
public slots:
void portChanged();
void reloadList();
void listChanged();
void updateList();
void assignKey();
void assignAllKeys();
void unassignKey();
private:
array<InputGroup*> deviceItem;
array<QTreeWidgetItem*> listItem;
} *winInputSettings;

View File

@@ -127,74 +127,74 @@ void PathSettingsWindow::setup() {
}
void PathSettingsWindow::syncUi() {
gamePath->setText (snes.config.path.rom == "" ? "<startup path>" : (const char*)snes.config.path.rom);
savePath->setText (snes.config.path.save == "" ? "<same folder as loaded game>" : (const char*)snes.config.path.save);
patchPath->setText(snes.config.path.patch == "" ? "<same folder as loaded game>" : (const char*)snes.config.path.patch);
cheatPath->setText(snes.config.path.cheat == "" ? "<same folder as loaded game>" : (const char*)snes.config.path.cheat);
dataPath->setText (snes.config.path.data == "" ? "<same folder as loaded game>" : (const char*)snes.config.path.data);
gamePath->setText (config.path.rom == "" ? "<startup path>" : (const char*)config.path.rom);
savePath->setText (config.path.save == "" ? "<same folder as loaded game>" : (const char*)config.path.save);
patchPath->setText(config.path.patch == "" ? "<same folder as loaded game>" : (const char*)config.path.patch);
cheatPath->setText(config.path.cheat == "" ? "<same folder as loaded game>" : (const char*)config.path.cheat);
dataPath->setText (config.path.data == "" ? "<same folder as loaded game>" : (const char*)config.path.data);
}
void PathSettingsWindow::selectGamePath() {
string path = utility.selectFolder("Default Game Path");
if(path.length() > 0) {
snes.config.path.rom = path;
config.path.rom = path;
syncUi();
}
}
void PathSettingsWindow::defaultGamePath() {
snes.config.path.rom = "";
config.path.rom = "";
syncUi();
}
void PathSettingsWindow::selectSavePath() {
string path = utility.selectFolder("Default Save RAM Path");
if(path.length() > 0) {
snes.config.path.save = path;
config.path.save = path;
syncUi();
}
}
void PathSettingsWindow::defaultSavePath() {
snes.config.path.save = "";
config.path.save = "";
syncUi();
}
void PathSettingsWindow::selectPatchPath() {
string path = utility.selectFolder("Default UPS Patch Path");
if(path.length() > 0) {
snes.config.path.patch = path;
config.path.patch = path;
syncUi();
}
}
void PathSettingsWindow::defaultPatchPath() {
snes.config.path.patch = "";
config.path.patch = "";
syncUi();
}
void PathSettingsWindow::selectCheatPath() {
string path = utility.selectFolder("Default Cheat File Path");
if(path.length() > 0) {
snes.config.path.cheat = path;
config.path.cheat = path;
syncUi();
}
}
void PathSettingsWindow::defaultCheatPath() {
snes.config.path.cheat = "";
config.path.cheat = "";
syncUi();
}
void PathSettingsWindow::selectDataPath() {
string path = utility.selectFolder("Default Export Data Path");
if(path.length() > 0) {
snes.config.path.data = path;
config.path.data = path;
syncUi();
}
}
void PathSettingsWindow::defaultDataPath() {
snes.config.path.data = "";
config.path.data = "";
syncUi();
}

View File

@@ -1,49 +0,0 @@
class PathSettingsWindow : public QObject {
Q_OBJECT
public:
QWidget *panel;
QVBoxLayout *layout;
QLabel *title;
QLabel *gameLabel;
QHBoxLayout *games;
QLineEdit *gamePath;
QPushButton *gameSelect;
QPushButton *gameDefault;
QLabel *saveLabel;
QHBoxLayout *saves;
QLineEdit *savePath;
QPushButton *saveSelect;
QPushButton *saveDefault;
QLabel *patchLabel;
QHBoxLayout *patches;
QLineEdit *patchPath;
QPushButton *patchSelect;
QPushButton *patchDefault;
QLabel *cheatLabel;
QHBoxLayout *cheats;
QLineEdit *cheatPath;
QPushButton *cheatSelect;
QPushButton *cheatDefault;
QLabel *dataLabel;
QHBoxLayout *data;
QLineEdit *dataPath;
QPushButton *dataSelect;
QPushButton *dataDefault;
QWidget *spacer;
void setup();
void syncUi();
public slots:
void selectGamePath();
void defaultGamePath();
void selectSavePath();
void defaultSavePath();
void selectPatchPath();
void defaultPatchPath();
void selectCheatPath();
void defaultCheatPath();
void selectDataPath();
void defaultDataPath();
} *winPathSettings;

View File

@@ -1,31 +0,0 @@
#include "video.moc"
#include "audio.moc"
#include "input.moc"
#include "paths.moc"
#include "cheateditor.moc"
#include "advanced.moc"
#include "utility/inputcapture.moc"
#include "utility/codeeditor.moc"
class SettingsWindow : public QObject {
Q_OBJECT
public:
QWidget *window;
QHBoxLayout *layout;
QListWidget *list;
QListWidgetItem *video;
QListWidgetItem *audio;
QListWidgetItem *input;
QListWidgetItem *paths;
QListWidgetItem *cheatcodes;
QListWidgetItem *advanced;
QWidget *panel;
QStackedLayout *panelLayout;
void setup();
public slots:
void listChanged();
} *winSettings;

View File

@@ -75,8 +75,8 @@ void CodeEditorWindow::setup() {
void CodeEditorWindow::syncUi() {
//only activate add button when code is valid
string code = codeValue->text().toUtf8().data();
Cheat::cheat_t temp;
bool valid = cheat.decode(code, temp);
SNES::Cheat::cheat_t temp;
bool valid = SNES::cheat.decode(code, temp);
codeAdd->setEnabled(valid);
//only activate delete button when a code is selected
@@ -93,8 +93,8 @@ void CodeEditorWindow::codeChanged() { syncUi(); }
void CodeEditorWindow::addCodeToList() {
string code = codeValue->text().toUtf8().data();
Cheat::cheat_t temp;
if(cheat.decode(code, temp) == true) codeList->addItem(utf8() << code);
SNES::Cheat::cheat_t temp;
if(SNES::cheat.decode(code, temp) == true) codeList->addItem(utf8() << code);
syncUi();
}
@@ -122,15 +122,15 @@ void CodeEditorWindow::accept() {
if(activeCode == -1) {
//adding a new code
cheat.add(enabled->isChecked(), code, desc);
SNES::cheat.add(enabled->isChecked(), code, desc);
winCheatEditor->reloadList();
} else if(codeList->count() > 0) {
//editing an existing code
cheat.edit(activeCode, enabled->isChecked(), code, desc);
SNES::cheat.edit(activeCode, enabled->isChecked(), code, desc);
winCheatEditor->updateList();
} else {
//deleting an existing code
cheat.remove(activeCode);
SNES::cheat.remove(activeCode);
winCheatEditor->reloadList();
}
@@ -156,8 +156,8 @@ void CodeEditorWindow::editCode(unsigned code) {
codeList->clear();
codeValue->setText("");
Cheat::cheat_t item;
cheat.get(activeCode, item);
SNES::Cheat::cheat_t item;
SNES::cheat.get(activeCode, item);
description->setPlainText(utf8() << item.desc);

View File

@@ -1,43 +0,0 @@
class CodeEditorWindow : public QObject {
Q_OBJECT
public:
QWidget *window;
QVBoxLayout *layout;
QLabel *descLabel;
QTextEdit *description;
QLabel *codeLabel;
QHBoxLayout *codeLayout;
QListWidget *codeList;
QVBoxLayout *controls;
QLineEdit *codeValue;
QPushButton *codeAdd;
QPushButton *codeDelete;
QPushButton *codeDeleteAll;
QWidget *spacer;
QCheckBox *enabled;
QHBoxLayout *finishControls;
QPushButton *okButton;
QPushButton *cancelButton;
void setup();
void syncUi();
void addCode();
void editCode(unsigned code);
CodeEditorWindow();
public slots:
void listChanged();
void codeChanged();
void addCodeToList();
void deleteCodeFromList();
void deleteAllCodesFromList();
void accept();
void dismiss();
private:
signed activeCode;
void showWindow(const char *title);
friend class CheatEditorWindow;
} *winCodeEditor;

View File

@@ -37,8 +37,8 @@ void InputCaptureWindow::setup() {
connect(mouseAxes, SIGNAL(released()), this, SLOT(assignMouseAxis()));
connect(mouseButtons, SIGNAL(released()), this, SLOT(assignMouseButton()));
winInputMouseCaptureWindow = new InputMouseCaptureWindow;
winInputMouseCaptureWindow->setup();
winInputMouseCapture = new InputMouseCaptureWindow;
winInputMouseCapture->setup();
winInputCalibration = new InputCalibrationWindow;
winInputCalibration->setup();
@@ -96,8 +96,8 @@ void InputCaptureWindow::inputEvent(uint16_t code, bool forceAssign /* = false *
//input polling is global, need to block mouse actions that may be UI interactions.
//custom controls on window allow mouse assignment instead.
if(forceAssign == false) {
if(winInputMouseCaptureWindow->window->isActiveWindow()) {
winInputMouseCaptureWindow->inputEvent(code);
if(winInputMouseCapture->window->isActiveWindow()) {
winInputMouseCapture->inputEvent(code);
return;
}
if(!window->isActiveWindow()) return;
@@ -205,7 +205,7 @@ void InputCaptureWindow::inputEvent(uint16_t code, bool forceAssign /* = false *
if(!activeGroup) {
window->hide();
winInputMouseCaptureWindow->window->hide();
winInputMouseCapture->window->hide();
} else {
//try and map the next code in this input group
groupIndex++;
@@ -214,7 +214,7 @@ void InputCaptureWindow::inputEvent(uint16_t code, bool forceAssign /* = false *
} else {
//all group codes mapped
window->hide();
winInputMouseCaptureWindow->window->hide();
winInputMouseCapture->window->hide();
activeGroup = 0;
}
}
@@ -224,12 +224,12 @@ void InputCaptureWindow::assignMouseAxis() {
//refresh input state so that mouse release event (from SIGNAL(released())
//is not sent immediately after window is visible.
inputManager.refresh();
winInputMouseCaptureWindow->activate(InputMouseCaptureWindow::AxisMode);
winInputMouseCapture->activate(InputMouseCaptureWindow::AxisMode);
}
void InputCaptureWindow::assignMouseButton() {
inputManager.refresh();
winInputMouseCaptureWindow->activate(InputMouseCaptureWindow::ButtonMode);
winInputMouseCapture->activate(InputMouseCaptureWindow::ButtonMode);
}
InputCaptureWindow::InputCaptureWindow() {
@@ -243,6 +243,9 @@ void InputCaptureWindow::Window::closeEvent(QCloseEvent*) {
//window closed by user, cancel key assignment
winInputCapture->activeObject = 0;
winInputCapture->activeGroup = 0;
winInputMouseCapture->window->hide();
winInputCalibration->dismiss();
}
void InputCaptureWindow::ImageWidget::paintEvent(QPaintEvent*) {
@@ -452,3 +455,7 @@ void InputCalibrationWindow::dismiss() {
void InputCalibrationWindow::Window::closeEvent(QCloseEvent*) {
winInputCalibration->dismiss();
}
InputCalibrationWindow::InputCalibrationWindow() {
activeJoypad = -1;
}

View File

@@ -1,88 +0,0 @@
class InputCaptureWindow : public QObject {
Q_OBJECT
public:
struct Window : public QWidget {
void closeEvent(QCloseEvent*);
} *window;
QVBoxLayout *layout;
QHBoxLayout *hlayout;
QLabel *title;
QPushButton *mouseAxes;
QPushButton *mouseButtons;
QWidget *imageSpacer;
struct ImageWidget : public QWidget {
void paintEvent(QPaintEvent*);
} *imageWidget;
QWidget *spacer;
void setup();
void activate(InputObject *object);
void activate(InputGroup *group);
void inputEvent(uint16_t code, bool forceAssign = false);
InputCaptureWindow();
public slots:
void assignMouseAxis();
void assignMouseButton();
private:
InputObject *activeObject;
InputGroup *activeGroup;
unsigned groupIndex;
bool inputLock;
friend class InputCaptureWindow::Window;
} *winInputCapture;
class InputMouseCaptureWindow : public QObject {
Q_OBJECT
public:
enum Mode { AxisMode, ButtonMode };
QWidget *window;
QVBoxLayout *layout;
QLabel *info;
QLabel *captureBox;
QHBoxLayout *buttonLayout;
QPushButton *xAxis;
QPushButton *yAxis;
QWidget *spacer;
void setup();
void activate(Mode);
void inputEvent(uint16_t code);
public slots:
void assignAxisX();
void assignAxisY();
private:
Mode activeMode;
signed activeMouse;
} *winInputMouseCaptureWindow;
class InputCalibrationWindow : public QObject {
Q_OBJECT
public:
struct Window : public QWidget {
void closeEvent(QCloseEvent*);
} *window;
QVBoxLayout *layout;
QLabel *info;
QPushButton *ok;
QWidget *spacer;
void setup();
void activate(unsigned joy);
public slots:
void dismiss();
private:
int activeJoypad;
friend class InputCalibrationWindow::Window;
} *winInputCalibration;

View File

@@ -1,29 +0,0 @@
class VideoSettingsWindow : public QObject {
Q_OBJECT
public:
QWidget *panel;
QVBoxLayout *layout;
QLabel *title;
QGridLayout *sliders;
QLabel *lcontrast;
QSlider *contrast;
QLabel *lbrightness;
QSlider *brightness;
QLabel *lgamma;
QSlider *gamma;
QHBoxLayout *options;
QCheckBox *enableGammaRamp;
QCheckBox *enableNtscMergeFields;
QWidget *spacer;
void setup();
void syncUi();
public slots:
void gammaRampToggle(int);
void ntscFieldsToggle(int);
void contrastAdjust(int);
void brightnessAdjust(int);
void gammaAdjust(int);
} *winVideoSettings;

View File

@@ -2,7 +2,7 @@ string Utility::selectCartridge() {
audio.clear();
QString filename = QFileDialog::getOpenFileName(0,
"Load Cartridge",
utf8() << (snes.config.path.rom != "" ? snes.config.path.rom : snes.config.path.current),
utf8() << (config.path.rom != "" ? config.path.rom : config.path.current),
"SNES images (*.smc *.sfc *.swc *.fig *.bs *.st"
#if defined(GZIP_SUPPORT)
" *.zip *.gz"
@@ -12,66 +12,150 @@ string Utility::selectCartridge() {
#endif
");;"
"All files (*)"
);
return string() << filename.toUtf8().constData();
);
string name = filename.toUtf8().constData();
if(strlen(name) > 0) config.path.current = basepath(name);
return name;
}
string Utility::selectFolder(const char *title) {
audio.clear();
QString pathname = QFileDialog::getExistingDirectory(0,
title, utf8() << snes.config.path.current,
QFileDialog::ShowDirsOnly);
return string() << pathname.toUtf8().constData();
title, utf8() << config.path.current,
QFileDialog::ShowDirsOnly);
string path = pathname.toUtf8().constData();
strtr(path, "\\", "/");
if(strend(path, "/") == false) path << "/";
return path;
}
void Utility::loadCartridge(const char *filename) {
switch(cartridge.detect_image_type(filename)) {
case Cartridge::TypeNormal: loadCartridgeNormal(filename); break;
case Cartridge::TypeBsxSlotted: winLoader->loadBsxSlottedCartridge(filename, ""); break;
case Cartridge::TypeBsxBios: winLoader->loadBsxCartridge(filename, ""); break;
case Cartridge::TypeBsx: winLoader->loadBsxCartridge(snes.config.path.bsx, filename); break;
case Cartridge::TypeSufamiTurboBios: winLoader->loadSufamiTurboCartridge(filename, "", ""); break;
case Cartridge::TypeSufamiTurbo: winLoader->loadSufamiTurboCartridge(snes.config.path.st, filename, ""); break;
void Utility::loadCartridge(const char *filename) {
SNES::MappedRAM memory;
if(loadCartridge(filename, memory) == false) return;
SNES::Cartridge::Type type = SNES::cartridge.detect_image_type(memory.data(), memory.size());
memory.reset();
switch(type) {
case SNES::Cartridge::TypeNormal: loadCartridgeNormal(filename); break;
case SNES::Cartridge::TypeBsxSlotted: winLoader->loadBsxSlottedCartridge(filename, ""); break;
case SNES::Cartridge::TypeBsxBios: winLoader->loadBsxCartridge(filename, ""); break;
case SNES::Cartridge::TypeBsx: winLoader->loadBsxCartridge(config.path.bsx, filename); break;
case SNES::Cartridge::TypeSufamiTurboBios: winLoader->loadSufamiTurboCartridge(filename, "", ""); break;
case SNES::Cartridge::TypeSufamiTurbo: winLoader->loadSufamiTurboCartridge(config.path.st, filename, ""); break;
case SNES::Cartridge::TypeSuperGameBoyBios: winLoader->loadSuperGameBoyCartridge(filename, ""); break;
case SNES::Cartridge::TypeGameBoy: winLoader->loadSuperGameBoyCartridge(config.path.sgb, filename); break;
}
}
bool Utility::loadCartridgeNormal(const char *base) {
if(!*base) return false;
unloadCartridge();
cartridge.load_normal(base);
bool Utility::loadCartridgeNormal(const char *base) {
unloadCartridge();
if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false;
SNES::cartridge.load(SNES::Cartridge::ModeNormal);
loadMemory(cartridge.baseName, ".srm", SNES::memory::cartram);
loadMemory(cartridge.baseName, ".rtc", SNES::memory::cartrtc);
cartridge.name = basename(base);
modifySystemState(LoadCartridge);
return true;
}
bool Utility::loadCartridgeBsxSlotted(const char *base, const char *slot) {
if(!*base) return false;
unloadCartridge();
cartridge.load_bsx_slotted(base, slot);
bool Utility::loadCartridgeBsxSlotted(const char *base, const char *slot) {
unloadCartridge();
if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false;
loadCartridge(cartridge.slotAName = slot, SNES::memory::bsxflash);
SNES::cartridge.load(SNES::Cartridge::ModeBsxSlotted);
loadMemory(cartridge.baseName, ".srm", SNES::memory::cartram);
loadMemory(cartridge.baseName, ".rtc", SNES::memory::cartrtc);
cartridge.name = basename(base);
if(*slot) cartridge.name << " + " << basename(slot);
modifySystemState(LoadCartridge);
return true;
}
bool Utility::loadCartridgeBsx(const char *base, const char *slot) {
if(!*base) return false;
bool Utility::loadCartridgeBsx(const char *base, const char *slot) {
unloadCartridge();
cartridge.load_bsx(base, slot);
if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false;
loadCartridge(cartridge.slotAName = slot, SNES::memory::bsxflash);
SNES::cartridge.load(SNES::Cartridge::ModeBsx);
loadMemory(cartridge.baseName, ".srm", SNES::memory::bsxram );
loadMemory(cartridge.baseName, ".psr", SNES::memory::bsxpram);
cartridge.name = (*slot ? basename(slot) : basename(base));
modifySystemState(LoadCartridge);
return true;
}
bool Utility::loadCartridgeSufamiTurbo(const char *base, const char *slotA, const char *slotB) {
if(!*base) return false;
unloadCartridge();
cartridge.load_sufami_turbo(base, slotA, slotB);
bool Utility::loadCartridgeSufamiTurbo(const char *base, const char *slotA, const char *slotB) {
unloadCartridge();
if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false;
loadCartridge(cartridge.slotAName = slotA, SNES::memory::stArom);
loadCartridge(cartridge.slotBName = slotB, SNES::memory::stBrom);
SNES::cartridge.load(SNES::Cartridge::ModeSufamiTurbo);
loadMemory(cartridge.slotAName, ".srm", SNES::memory::stAram);
loadMemory(cartridge.slotBName, ".srm", SNES::memory::stBram);
if(!*slotA && !*slotB) cartridge.name = basename(base);
else if(!*slotB) cartridge.name = basename(slotA);
else if(!*slotA) cartridge.name = basename(slotB);
else cartridge.name = string() << basename(slotA) << " + " << basename(slotB);
modifySystemState(LoadCartridge);
return true;
}
}
bool Utility::loadCartridgeSuperGameBoy(const char *base, const char *slot) {
unloadCartridge();
if(loadCartridge(cartridge.baseName = base, SNES::memory::cartrom) == false) return false;
loadCartridge(cartridge.slotAName = slot, SNES::memory::gbrom);
SNES::cartridge.load(SNES::Cartridge::ModeSuperGameBoy);
loadMemory(cartridge.slotAName, ".sav", SNES::memory::gbram);
cartridge.name = (*slot ? basename(slot) : basename(base));
modifySystemState(LoadCartridge);
return true;
}
void Utility::saveMemory() {
if(SNES::cartridge.loaded() == false) return;
switch(SNES::cartridge.mode()) {
case SNES::Cartridge::ModeNormal:
case SNES::Cartridge::ModeBsxSlotted: {
saveMemory(cartridge.baseName, ".srm", SNES::memory::cartram);
saveMemory(cartridge.baseName, ".rtc", SNES::memory::cartrtc);
} break;
case SNES::Cartridge::ModeBsx: {
saveMemory(cartridge.baseName, ".srm", SNES::memory::bsxram );
saveMemory(cartridge.baseName, ".psr", SNES::memory::bsxpram);
} break;
case SNES::Cartridge::ModeSufamiTurbo: {
saveMemory(cartridge.slotAName, ".srm", SNES::memory::stAram);
saveMemory(cartridge.slotBName, ".srm", SNES::memory::stBram);
} break;
case SNES::Cartridge::ModeSuperGameBoy: {
saveMemory(cartridge.slotAName, ".sav", SNES::memory::gbram);
} break;
}
}
void Utility::unloadCartridge() {
if(cartridge.loaded()) {
cartridge.unload();
modifySystemState(UnloadCartridge);
}
if(SNES::cartridge.loaded() == false) return;
saveMemory();
modifySystemState(UnloadCartridge);
}
void Utility::modifySystemState(system_state_t state) {
@@ -81,19 +165,19 @@ void Utility::modifySystemState(system_state_t state) {
switch(state) {
case LoadCartridge: {
//must call cartridge.load_cart_...() before calling modifySystemState(LoadCartridge)
if(cartridge.loaded() == false) break;
if(SNES::cartridge.loaded() == false) break;
loadCheats();
application.power = true;
application.pause = false;
snes.power();
SNES::system.power();
//warn if unsupported hardware detected
string chip;
if(cartridge.has_superfx()) chip = "SuperFX";
else if(cartridge.has_sa1()) chip = "SA-1";
else if(cartridge.has_st011()) chip = "ST011";
else if(cartridge.has_st018()) chip = "ST018";
else if(cartridge.has_dsp3()) chip = "DSP-3";
if(SNES::cartridge.has_superfx()) chip = "SuperFX";
else if(SNES::cartridge.has_st011()) chip = "ST011";
else if(SNES::cartridge.has_st018()) chip = "ST018";
else if(SNES::cartridge.has_dsp3()) chip = "DSP-3"; //unplayable; only partially supported
if(chip != "") {
QMessageBox::warning(winMain->window, "Warning", utf8()
<< "<p><b>Warning:</b><br>Unsupported " << chip << " chip detected. "
@@ -101,34 +185,36 @@ void Utility::modifySystemState(system_state_t state) {
}
showMessage(utf8()
<< "Loaded " << cartridge.name()
<< (cartridge.patched() ? ", and applied UPS patch." : "."));
winMain->window->setWindowTitle(utf8() << BSNES_TITLE << " - " << cartridge.name());
<< "Loaded " << cartridge.name
<< (false ? ", and applied UPS patch." : "."));
winMain->window->setWindowTitle(utf8() << BSNES_TITLE << " - " << cartridge.name);
} break;
case UnloadCartridge: {
if(cartridge.loaded() == false) break; //no cart to unload?
cartridge.unload();
if(SNES::cartridge.loaded() == false) break; //no cart to unload?
saveCheats();
SNES::cartridge.unload();
application.power = false;
application.pause = true;
showMessage(utf8() << "Unloaded " << cartridge.name() << ".");
showMessage(utf8() << "Unloaded " << cartridge.name << ".");
winMain->window->setWindowTitle(utf8() << BSNES_TITLE);
} break;
case PowerOn: {
if(cartridge.loaded() == false || application.power == true) break;
if(SNES::cartridge.loaded() == false || application.power == true) break;
application.power = true;
application.pause = false;
snes.power();
SNES::system.power();
showMessage("Power on.");
} break;
case PowerOff: {
if(cartridge.loaded() == false || application.power == false) break;
if(SNES::cartridge.loaded() == false || application.power == false) break;
application.power = false;
application.pause = true;
@@ -137,20 +223,20 @@ void Utility::modifySystemState(system_state_t state) {
} break;
case PowerCycle: {
if(cartridge.loaded() == false) break;
if(SNES::cartridge.loaded() == false) break;
application.power = true;
application.pause = false;
snes.power();
SNES::system.power();
showMessage("System power was cycled.");
} break;
case Reset: {
if(cartridge.loaded() == false || application.power == false) break;
if(SNES::cartridge.loaded() == false || application.power == false) break;
application.pause = false;
snes.reset();
SNES::system.reset();
showMessage("System was reset.");
} break;
@@ -161,3 +247,182 @@ void Utility::modifySystemState(system_state_t state) {
winCheatEditor->reloadList();
winCheatEditor->syncUi();
}
//
bool Utility::loadCartridge(const char *filename, SNES::MappedRAM &memory) {
if(file::exists(filename) == false) return false;
Reader::Type filetype = Reader::detect(filename, config.file.autodetect_type);
uint8_t *data;
unsigned size;
switch(filetype) { default:
case Reader::Normal: {
FileReader fp(filename);
if(!fp.ready()) return false;
size = fp.size();
data = fp.read();
} break;
#ifdef GZIP_SUPPORT
case Reader::GZIP: {
GZReader fp(filename);
if(!fp.ready()) return false;
size = fp.size();
data = fp.read();
} break;
case Reader::ZIP: {
ZipReader fp(filename);
if(!fp.ready()) return false;
size = fp.size();
data = fp.read();
} break;
#endif
#ifdef JMA_SUPPORT
case Reader::JMA: {
try {
JMAReader fp(filename);
size = fp.size();
data = fp.read();
} catch(JMA::jma_errors) {
return false;
}
} break;
#endif
}
if((size & 0x7fff) == 512) memmove(data, data + 512, size -= 512);
memory.map(data, size);
return true;
}
bool Utility::loadMemory(const char *filename, const char *extension, SNES::MappedRAM &memory) {
if(memory.size() == 0 || memory.size() == -1U) return false;
string name;
name << filepath(basename(filename), config.path.save);
name << extension;
file fp;
if(fp.open(name, file::mode_read) == false) return false;
unsigned size;
uint8_t *data = new uint8_t[size = fp.size()];
fp.read(data, size);
fp.close();
memcpy(memory.data(), data, min(size, memory.size()));
return true;
}
bool Utility::saveMemory(const char *filename, const char *extension, SNES::MappedRAM &memory) {
if(memory.size() == 0 || memory.size() == -1U) return false;
string name;
name << filepath(basename(filename), config.path.save);
name << extension;
file fp;
if(fp.open(name, file::mode_write) == false) return false;
fp.write(memory.data(), memory.size());
fp.close();
return true;
}
void Utility::loadCheats() {
string name, data;
name << filepath(basename(cartridge.baseName), config.path.cheat);
name << ".cht";
SNES::cheat.clear();
if(data.readfile(name)) SNES::cheat.load(data);
}
void Utility::saveCheats() {
string name;
name << filepath(basename(cartridge.baseName), config.path.cheat);
name << ".cht";
file fp;
if(SNES::cheat.count() > 0 || file::exists(name)) {
if(fp.open(name, file::mode_write)) {
fp.print(SNES::cheat.save());
fp.close();
}
}
}
//
//ensure file path is absolute (eg resolve relative paths)
string Utility::filepath(const char *filename, const char *pathname) {
//if no pathname, return filename as-is
string file(filename);
file.replace("\\", "/");
string path = (!pathname || !*pathname) ? (const char*)config.path.current : pathname;
//ensure path ends with trailing '/'
path.replace("\\", "/");
if(!strend(path, "/")) path.append("/");
//replace relative path with absolute path
if(strbegin(path, "./")) {
ltrim(path, "./");
path = string() << config.path.base << path;
}
//remove folder part of filename
lstring part;
part.split("/", file);
return path << part[part.size() - 1];
}
//remove directory information and file extension ("/foo/bar.ext" -> "bar")
string Utility::basename(const char *filename) {
string name(filename);
//remove extension
for(signed i = strlen(name) - 1; i >= 0; i--) {
if(name[i] == '.') {
name[i] = 0;
break;
}
}
//remove directory information
for(signed i = strlen(name) - 1; i >= 0; i--) {
if(name[i] == '/' || name[i] == '\\') {
i++;
char *output = name();
while(true) {
*output++ = name[i];
if(!name[i]) break;
i++;
}
break;
}
}
return name;
}
//remove filename and return path only ("/foo/bar.ext" -> "/foo/")
string Utility::basepath(const char *filename) {
string path(filename);
path.replace("\\", "/");
//remove filename
for(signed i = strlen(path) - 1; i >= 0; i--) {
if(path[i] == '/') {
path[i] = 0;
break;
}
}
if(!strend(path, "/")) path.append("/");
return path;
}

View File

@@ -57,6 +57,7 @@ void Utility::inputEvent(uint16_t code) {
if(isButtonDown(code, inputUiGeneral.pauseEmulation)) {
application.pause = !application.pause;
if(application.pause) audio.clear();
}
if(isButtonDown(code, inputUiGeneral.resetSystem)) {
@@ -80,11 +81,11 @@ void Utility::inputEvent(uint16_t code) {
}
if(isButtonDown(code, inputUiGeneral.toggleCheatSystem)) {
if(cheat.enabled() == false) {
cheat.enable();
if(SNES::cheat.enabled() == false) {
SNES::cheat.enable();
showMessage("Cheat system enabled.");
} else {
cheat.disable();
SNES::cheat.disable();
showMessage("Cheat system disabled.");
}
}
@@ -125,15 +126,15 @@ void Utility::showMessage(const char *message) {
void Utility::updateSystemState() {
string text;
if(cartridge.loaded() == false) {
if(SNES::cartridge.loaded() == false) {
text = "No cartridge loaded";
} else if(application.power == false) {
text = "Power off";
} else if(application.pause == true || application.autopause == true) {
text = "Paused";
} else if(ppu.status.frames_updated == true) {
ppu.status.frames_updated = false;
text << (int)ppu.status.frames_executed;
} else if(SNES::ppu.status.frames_updated == true) {
SNES::ppu.status.frames_updated = false;
text << (int)SNES::ppu.status.frames_executed;
text << " fps";
} else {
//nothing to update
@@ -144,12 +145,12 @@ void Utility::updateSystemState() {
}
void Utility::acquireMouse() {
if(cartridge.loaded()) {
if(snes.config.controller_port1 == SNES::Input::DeviceMouse
|| snes.config.controller_port2 == SNES::Input::DeviceMouse
|| snes.config.controller_port2 == SNES::Input::DeviceSuperScope
|| snes.config.controller_port2 == SNES::Input::DeviceJustifier
|| snes.config.controller_port2 == SNES::Input::DeviceJustifiers
if(SNES::cartridge.loaded()) {
if(SNES::config.controller_port1 == SNES::Input::DeviceMouse
|| SNES::config.controller_port2 == SNES::Input::DeviceMouse
|| SNES::config.controller_port2 == SNES::Input::DeviceSuperScope
|| SNES::config.controller_port2 == SNES::Input::DeviceJustifier
|| SNES::config.controller_port2 == SNES::Input::DeviceJustifiers
) input.acquire();
}
}
@@ -165,9 +166,9 @@ void Utility::updateAvSync() {
void Utility::updateVideoMode() {
if(config.video.context->region == 0) {
snes.video.set_mode(SNES::Video::ModeNTSC);
SNES::video.set_mode(SNES::Video::ModeNTSC);
} else {
snes.video.set_mode(SNES::Video::ModePAL);
SNES::video.set_mode(SNES::Video::ModePAL);
}
}
@@ -213,6 +214,6 @@ void Utility::updateEmulationSpeed() {
}
void Utility::updateControllers() {
snes.input.port_set_device(0, snes.config.controller_port1);
snes.input.port_set_device(1, snes.config.controller_port2);
SNES::input.port_set_device(0, SNES::config.controller_port1);
SNES::input.port_set_device(1, SNES::config.controller_port2);
}

View File

@@ -16,18 +16,34 @@ public:
void updateEmulationSpeed();
void updateControllers();
//cartridge.cpp
//cartridge.cpp
struct Cartridge {
string name, baseName, slotAName, slotBName;
} cartridge;
string selectCartridge();
string selectFolder(const char *title);
void loadCartridge(const char*);
bool loadCartridgeNormal(const char*);
bool loadCartridgeBsxSlotted(const char*, const char*);
bool loadCartridgeBsx(const char*, const char*);
bool loadCartridgeSufamiTurbo(const char*, const char *, const char*);
bool loadCartridgeSufamiTurbo(const char*, const char *, const char*);
bool loadCartridgeSuperGameBoy(const char*, const char*);
void saveMemory();
void unloadCartridge();
enum system_state_t { LoadCartridge, UnloadCartridge, PowerOn, PowerOff, PowerCycle, Reset };
void modifySystemState(system_state_t state);
void modifySystemState(system_state_t state);
bool loadCartridge(const char*, SNES::MappedRAM&);
bool loadMemory(const char*, const char*, SNES::MappedRAM&);
bool saveMemory(const char*, const char*, SNES::MappedRAM&);
void loadCheats();
void saveCheats();
string filepath(const char *filename, const char *pathname);
string basename(const char *filename);
string basepath(const char *filename);
//window.cpp
void showCentered(QWidget *window);

View File

@@ -2,31 +2,39 @@
void Utility::showCentered(QWidget *window) {
QRect deskRect = QApplication::desktop()->availableGeometry(window);
//place window offscreen, so that it can be shown to get proper frameSize()
window->move(std::numeric_limits<signed>::max(), std::numeric_limits<signed>::max());
#ifdef _WIN32
if(window->isMinimized() == false) {
//place window offscreen, so that it can be shown to get proper frameSize()
window->move(std::numeric_limits<signed>::max(), std::numeric_limits<signed>::max());
}
window->showNormal();
//force-resize window to be as small as minimumSize() will allow, and then center it
window->resize(0, 0);
window->move(
deskRect.center().x() - (window->frameSize().width() / 2),
deskRect.center().y() - (window->frameSize().height() / 2)
);
#else
if(window->isVisible() == false) window->showMinimized();
window->resize(0, 0);
#ifndef _WIN32
//Xlib frame size (excluding inside) is QSize(0, 0) at first, wait for it to be valid
//Xlib returns a frame size of 0,0 at first; wait for it to be valid
for(unsigned counter = 0; counter < 4096; counter++) {
if(window->frameSize() != window->size()) break;
application.processEvents();
}
#endif
//in case frame size changed, recenter window
window->move(
deskRect.center().x() - (window->frameSize().width() / 2),
deskRect.center().y() - (window->frameSize().height() / 2)
);
for(unsigned counter = 0; counter < 4096; counter++) {
window->showNormal();
application.processEvents();
if(window->isMinimized() == false) break;
}
#endif
//ensure window has focus
application.processEvents();
window->activateWindow();
@@ -84,6 +92,15 @@ void Utility::resizeMainWindow() {
//get effective desktop work area region (ignore Windows taskbar, OS X doc, etc.)
QRect deskRect = QApplication::desktop()->availableGeometry(winMain->window);
if(winMain->window->isVisible() == false) {
#ifdef _WIN32
winMain->window->move(std::numeric_limits<signed>::max(), std::numeric_limits<signed>::max());
winMain->window->showNormal();
#else
winMain->window->showMinimized();
#endif
}
//calculate frame geometry (window border + menubar + statusbar)
unsigned frameWidth = winMain->window->frameSize().width() - winMain->canvasContainer->size().width();
unsigned frameHeight = winMain->window->frameSize().height() - winMain->canvasContainer->size().height();