Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Syncing in the 0.8 release of mythgame.

git-svn-id: http://svn.mythtv.org/svn/trunk@1422 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information...
commit dc89a8c873c5fdf30b88e11050c89c4347971892 1 parent 739176d
Isaac Richards authored
Showing with 2,104 additions and 18 deletions.
  1. +19 −11 mythplugins/mythgame/README
  2. +3 −0  mythplugins/mythgame/UPGRADING
  3. +49 −0 mythplugins/mythgame/gamedb/snesdata.sql
  4. +8 −0 mythplugins/mythgame/gamelist.xml
  5. +2 −0  mythplugins/mythgame/mythgame/.cvsignore
  6. +6 −0 mythplugins/mythgame/mythgame/gamehandler.cpp
  7. +0 −2  mythplugins/mythgame/mythgame/main.cpp
  8. +26 −3 mythplugins/mythgame/mythgame/mythgame-settings.txt
  9. +5 −2 mythplugins/mythgame/mythgame/mythgame.pro
  10. +146 −0 mythplugins/mythgame/mythgame/pchandler.cpp
  11. +31 −0 mythplugins/mythgame/mythgame/pchandler.h
  12. +33 −0 mythplugins/mythgame/mythgame/pcrominfo.cpp
  13. +29 −0 mythplugins/mythgame/mythgame/pcrominfo.h
  14. +177 −0 mythplugins/mythgame/mythgame/pcsettingsdlg.cpp
  15. +65 −0 mythplugins/mythgame/mythgame/pcsettingsdlg.h
  16. +661 −0 mythplugins/mythgame/mythgame/sneshandler.cpp
  17. +58 −0 mythplugins/mythgame/mythgame/sneshandler.h
  18. +37 −0 mythplugins/mythgame/mythgame/snesrominfo.cpp
  19. +69 −0 mythplugins/mythgame/mythgame/snesrominfo.h
  20. +567 −0 mythplugins/mythgame/mythgame/snessettingsdlg.cpp
  21. +113 −0 mythplugins/mythgame/mythgame/snessettingsdlg.h
View
30 mythplugins/mythgame/README
@@ -1,5 +1,5 @@
MythGame
- Release 0.7
+ Release 0.8
There'll be more information here later, but for now:
@@ -7,12 +7,12 @@ There'll be more information here later, but for now:
BUILD/CONFIGURATION INSTRUCTIONS
--------------------------------
-First, you need MythTV to be installed. At the very least, you need MythTV's
-database stuff setup properly. If you don't have that done, don't even bother
-with this, as it won't work.
+First, you need MythTV 0.8 to be installed. At the very least, you need
+MythTV's database stuff setup properly, and libmyth installed.
+If you don't have that done, don't even bother with this, as it won't work.
-You don't need any other software installed, besides xmame. Xmame is currently
-the only emulator supported by MythGame.
+You will need zlib and zlib-dev, however they're named on your distribution of
+choice.
Ok, on to compiling. Just type 'make' in the main distribution directory.
@@ -30,15 +30,20 @@ Follow this by a 'make install'. It'll put a 'mythgame' binary in your
/usr/local/bin directory, and stuff mythgame-settings.txt in your
existing /usr/local/share/mythtv/ directory.
-You'll probably want to edit the mythgame-settings.txt file to set where xmame
-is, your rompath, snapshot path, etc.
+You'll probably want to edit the mythgame-settings.txt file to set where various
+emulators are, your rompaths, etc.
-MythGame will also read the theme.txt and mysql.txt settings files used by
-MythTV, so any changes you made to those will be carried over into this.
+Finally, insert gamedb/metadata.sql, gamedb/nesdb.sql, and gamedb/snesdata.sql
+into your existing MythTV database (in that order).
+
+MythGame will also read the mysql.txt settings files used by MythTV, so any
+changes you made to those will be carried over into this.
If you want to use the screenshot-based selection interface, set the ShotCount
setting to 5. You'll also need MameScreensLocation set to the appropriate
-place as well.
+place as well. If you want NES screenshots, download the screenshots pack from
+the MythTV website, un-tar.gz it, and point the NesScreensLocation to the
+appropriate place.
The first time you run MythGame, it'll search out and insert all games that it
finds into its database, so it may seem to take awhile. Later runs should be
@@ -49,6 +54,9 @@ name (ie, MAME), will take you to a system setup menu. In the screenshot-based
selection menu, just hit tab to switch between navigating the list and the
screenshot section.
+To use the generic PC game stuff, check out the example gamelist.xml file
+in this directory and modify it/add to it as desired.
+
Feel free to subscribe to the development mailing list at:
http://www.snowman.net/mailman/listinfo/mythtv-dev
View
3  mythplugins/mythgame/UPGRADING
@@ -0,0 +1,3 @@
+UPGRADING FROM RELEASE 0.7
+--------------------------
+Insert gamedb/nesdb.sql and gamedb/snesdata.sql into your database.
View
49 mythplugins/mythgame/gamedb/snesdata.sql
@@ -0,0 +1,49 @@
+USE mythconverg;
+
+CREATE TABLE snessettings
+(
+ romname VARCHAR(128) NOT NULL,
+ usedefault BOOL NOT NULL,
+ transparency BOOL NOT NULL,
+ sixteen BOOL NOT NULL,
+ hires BOOL NOT NULL,
+ interpolate TINYINT UNSIGNED NOT NULL,
+ nomodeswitch BOOL NOT NULL,
+ fullscreen BOOL NOT NULL,
+ stretch BOOL NOT NULL,
+ nosound BOOL NOT NULL,
+ soundskip TINYINT NOT NULL,
+ stereo BOOL NOT NULL,
+ soundquality TINYINT UNSIGNED NOT NULL,
+ envx BOOL NOT NULL,
+ threadsound BOOL NOT NULL,
+ syncsound BOOL NOT NULL,
+ interpolatedsound BOOL NOT NULL,
+ buffersize INT UNSIGNED NOT NULL,
+ nosamplecaching BOOL NOT NULL,
+ altsampledecode BOOL NOT NULL,
+ noecho BOOL NOT NULL,
+ nomastervolume BOOL NOT NULL,
+ nojoy BOOL NOT NULL,
+ interleaved BOOL NOT NULL,
+ altinterleaved BOOL NOT NULL,
+ hirom BOOL NOT NULL,
+ lowrom BOOL NOT NULL,
+ header BOOL NOT NULL,
+ noheader BOOL NOT NULL,
+ pal BOOL NOT NULL,
+ ntsc BOOL NOT NULL,
+ layering BOOL NOT NULL,
+ nohdma BOOL NOT NULL,
+ nospeedhacks BOOL NOT NULL,
+ nowindows BOOL NOT NULL,
+ extraoption VARCHAR(128) NOT NULL
+);
+
+INSERT INTO snessettings (romname,usedefault,transparency,sixteen,hires,
+interpolate,nomodeswitch,fullscreen,stretch,
+nosound,soundskip,stereo,soundquality,envx,threadsound,
+syncsound,interpolatedsound,buffersize,nosamplecaching,altsampledecode,
+noecho,nomastervolume,nojoy,interleaved,altinterleaved,hirom,lowrom,header,
+noheader,pal,ntsc,layering,nohdma,nospeedhacks,nowindows,extraoption) VALUES
+("default",1,0,0,0,0,0,0,0,0,0,1,4,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"");
View
8 mythplugins/mythgame/gamelist.xml
@@ -0,0 +1,8 @@
+<gamelist>
+ <game>
+ <name>TuxRacer</name>
+ <command>/usr/bin/tuxracer</command>
+ <genre>penguin themed winter sports</genre>
+ <year>1901</year>
+ </game>
+</gamelist>
View
2  mythplugins/mythgame/mythgame/.cvsignore
@@ -6,4 +6,6 @@ moc_mamesettingsdlg.cpp
moc_screenbox.cpp
moc_selectframe.cpp
moc_nessettingsdlg.cpp
+moc_pcsettingsdlg.cpp
+moc_snessettingsdlg.cpp
mythgame
View
6 mythplugins/mythgame/mythgame/gamehandler.cpp
@@ -1,6 +1,8 @@
#include "gamehandler.h"
#include "mamehandler.h"
#include "neshandler.h"
+#include "sneshandler.h"
+#include "pchandler.h"
#include "constants.h"
#include <qobject.h>
@@ -28,6 +30,10 @@ static void checkHandlers(void)
GameHandler::registerHandler(MameHandler::getHandler());
if (gContext->GetSetting("NesBinary") != "")
GameHandler::registerHandler(NesHandler::getHandler());
+ if (gContext->GetSetting("SnesBinary") != "")
+ GameHandler::registerHandler(SnesHandler::getHandler());
+ if (gContext->GetSetting("PCGameList") != "")
+ GameHandler::registerHandler(PCHandler::getHandler());
}
}
View
2  mythplugins/mythgame/mythgame/main.cpp
@@ -109,7 +109,6 @@ int main(int argc, char *argv[])
systems.append(name);
}
- cout << "Looking for games..\n";
//run through the list of registered systems, and if they're not
//in the database, tell them to scan for games
for (uint i = 0; i < GameHandler::count(); ++i)
@@ -121,7 +120,6 @@ int main(int argc, char *argv[])
handler->processGames();
}
}
- cout << "done\n";
QString paths = gContext->GetSetting("TreeLevels");
View
29 mythplugins/mythgame/mythgame/mythgame-settings.txt
@@ -3,7 +3,7 @@ TreeLevels=system year genre gamename
# Number of screenshots to show per column. if 0 then use game names only.
# default is 0 -- set this to 5 if you want the screenshot selection menu.
-ShotCount=0
+ShotCount=3
### Nes specific settings ###
@@ -20,14 +20,27 @@ NesCRCFile=/home/media/games/nes/nes.crc
# Directory where screenshots are kept
NesScreensLocation=/home/media/games/nes/screens
+### Snes specific settings ###
+
+# Path and name of snes9x binary
+SnesBinary=/usr/X11R6/bin/snes9x
+
+# directory where snes roms are located.
+SnesRomLocation=/snes/roms
+
+# directory where snes screenshots are kept
+# looks for screenshots with file names matching the rom file name.
+# if rom file is myrom.smc, myrom.zip, etc looks for myrom.gif, myrom.bmp etc.
+SnesScreensLocation=/snes/screens
+
### Mame specific settings ###
# Path and name of xmame binary
-XMameBinary=/usr/X11R6/bin/xmame
+XMameBinary=/usr/local/bin/xmame.x11
# Directory where mame roms are located.
-MameRomLocation=/roms
+MameRomLocation=/usr/lib/games/xmame/roms
# path and name of catver file.
XMameCatFile=/home/chuck/catver.ini
@@ -54,3 +67,13 @@ MameCabinetsLocation=/cabs
MameShowDisclaimer=0
MameShowGameInfo=1
+### PC Game Specific settings ###
+
+# Path to the Game List xml file.
+PCGameList=/usr/games/gamelist.xml
+
+# Directory where screenshots are kept
+# looks for screenshots with file names matching the game name in the gamelist.
+# if name value is mygame looks for mygame.gif, mygame.bmp etc.
+PCScreensLocation=/usr/games/screens
+
View
7 mythplugins/mythgame/mythgame/mythgame.pro
@@ -21,10 +21,13 @@ LIBS += -L$${PREFIX}/lib -lmyth-$$LIBVERSION -lz
HEADERS += constants.h databasebox.h gamehandler.h mamehandler.h rominfo.h
HEADERS += mamerominfo.h treeitem.h mamesettingsdlg.h extendedlistview.h
HEADERS += selectframe.h screenbox.h neshandler.h nesrominfo.h nessettingsdlg.h
-HEADERS += unzip.h
+HEADERS += unzip.h sneshandler.h snesrominfo.h snessettingsdlg.h pchandler.h
+HEADERS += pcrominfo.h pcsettingsdlg.h
SOURCES += databasebox.cpp selectframe.cpp screenbox.cpp
SOURCES += main.cpp gamehandler.cpp mamehandler.cpp rominfo.cpp neshandler.cpp
SOURCES += treeitem.cpp mamerominfo.cpp mamesettingsdlg.cpp extendedlistview.cpp
-SOURCES += nesrominfo.cpp nessettingsdlg.cpp unzip.c
+SOURCES += nesrominfo.cpp nessettingsdlg.cpp unzip.c sneshandler.cpp
+SOURCES += snesrominfo.cpp snessettingsdlg.cpp pchandler.cpp pcrominfo.cpp
+SOURCES += pcsettingsdlg.cpp
View
146 mythplugins/mythgame/mythgame/pchandler.cpp
@@ -0,0 +1,146 @@
+#include <iostream>
+#include "pchandler.h"
+
+#include <qobject.h>
+#include <qsqldatabase.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <mythtv/mythcontext.h>
+#include <qfile.h>
+#include <qdom.h>
+#include <string>
+
+#include "pcsettingsdlg.h"
+
+using namespace std;
+
+PCHandler::~PCHandler()
+{
+}
+
+void PCHandler::processGames()
+{
+ QString thequery;
+ QSqlDatabase* db = QSqlDatabase::database();
+
+ thequery = "DELETE FROM gamemetadata WHERE system = \"PC\";";
+ db->exec(thequery);
+
+ QString GameDoc = gContext->GetSetting("PCGameList");
+ if(!QFile::exists(GameDoc))
+ return;
+
+ QDomDocument doc;
+
+ QFile f(GameDoc);
+
+ if (!f.open(IO_ReadOnly))
+ {
+ cout << "Can't open: " << GameDoc << endl;
+ return;
+ }
+
+ QString errorMsg;
+ int errorLine = 0;
+ int errorColumn = 0;
+
+ if (!doc.setContent(&f, false, &errorMsg, &errorLine, &errorColumn))
+ {
+ cout << "Error parsing: " << GameDoc << endl;
+ cout << "at line: " << errorLine << " column: " << errorColumn << endl;
+ cout << errorMsg << endl;
+ f.close();
+ return;
+ }
+
+ f.close();
+
+ QDomElement docElem = doc.documentElement();
+ QDomNode n = docElem.firstChild();
+ while (!n.isNull())
+ {
+ QDomElement e = n.toElement();
+ if (!e.isNull())
+ {
+ if (e.tagName() == "game")
+ {
+ QString GameName = "";
+ QString Command = "";
+ QString Genre = "";
+ int Year = 0;
+ QDomNode i = e.firstChild();
+ while (!i.isNull())
+ {
+ QDomElement setting = i.toElement();
+ if (!setting.isNull())
+ {
+ if (setting.tagName() == "name")
+ GameName = setting.text();
+ else if (setting.tagName() == "command")
+ Command = setting.text();
+ else if (setting.tagName() == "genre")
+ Genre = setting.text();
+ else if (setting.tagName() == "year")
+ Year = setting.text().toInt();
+ }
+ i = i.nextSibling();
+ }
+
+ if(GameName != "" && Command != "")
+ {
+ thequery = QString("INSERT INTO gamemetadata "
+ "(system, romname, gamename, genre, year) "
+ "VALUES (\"PC\", \"%1\", \"%2\", \"%3\", %4);")
+ .arg(Command.latin1())
+ .arg(GameName.latin1()).arg(Genre.latin1())
+ .arg(Year);
+ db->exec(thequery);
+ }
+ }
+ }
+ n = n.nextSibling();
+ }
+}
+
+void PCHandler::start_game(RomInfo * romdata)
+{
+ // Run the game and wait for it to terminate.
+ FILE* command = popen(romdata->Romname(), "w");
+ pclose(command);
+}
+
+void PCHandler::edit_settings(QWidget *parent,RomInfo * romdata)
+{
+ PCRomInfo *pcdata = dynamic_cast<PCRomInfo*>(romdata);
+ PCSettingsDlg settingsdlg(parent, "gamesettings", true);
+ QString ImageFile;
+ if(pcdata->FindImage("screenshot", &ImageFile))
+ settingsdlg.SetScreenshot(ImageFile);
+ settingsdlg.Show(pcdata);
+}
+
+void PCHandler::edit_system_settings(QWidget *parent,RomInfo * romdata)
+{
+ romdata = romdata;
+ PCSettingsDlg settingsDlg(parent, "pcsettings", true, true);
+ settingsDlg.Show(NULL);
+}
+
+PCHandler* PCHandler::getHandler(void)
+{
+ if(!pInstance)
+ {
+ pInstance = new PCHandler();
+ }
+ return pInstance;
+}
+
+PCRomInfo* PCHandler::create_rominfo(RomInfo *parent)
+{
+ return new PCRomInfo(*parent);
+}
+
+PCHandler* PCHandler::pInstance = 0;
+
View
31 mythplugins/mythgame/mythgame/pchandler.h
@@ -0,0 +1,31 @@
+#ifndef PCHANDLER_H_
+#define PCHANDLER_H_
+
+#include "gamehandler.h"
+#include "pcrominfo.h"
+#include <qapplication.h>
+#include <map>
+
+using namespace std;
+
+class PCHandler : public GameHandler
+{
+ public:
+ PCHandler() : GameHandler() {
+ systemname = "PC";
+ }
+ virtual ~PCHandler();
+
+ void start_game(RomInfo *romdata);
+ void edit_settings(QWidget *parent,RomInfo *romdata);
+ void edit_system_settings(QWidget *parent,RomInfo *romdata);
+ PCRomInfo* create_rominfo(RomInfo* parent);
+ void processGames();
+
+ static PCHandler* getHandler(void);
+
+ private:
+ static PCHandler* pInstance;
+};
+
+#endif
View
33 mythplugins/mythgame/mythgame/pcrominfo.cpp
@@ -0,0 +1,33 @@
+#include <qsqldatabase.h>
+#include <qfile.h>
+#include "pcrominfo.h"
+#include <iostream>
+
+using namespace std;
+
+bool PCRomInfo::FindImage(QString type, QString *result)
+{
+ if (type != "screenshot")
+ return false;
+
+ QStringList graphic_formats;
+ graphic_formats.append("png");
+ graphic_formats.append("gif");
+ graphic_formats.append("jpg");
+ graphic_formats.append("jpeg");
+ graphic_formats.append("xpm");
+ graphic_formats.append("bmp");
+ graphic_formats.append("pnm");
+ graphic_formats.append("tif");
+ graphic_formats.append("tiff");
+
+ QString BaseFileName = gContext->GetSetting("PCScreensLocation") + "/" + gamename + ".";
+ for (QStringList::Iterator i = graphic_formats.begin(); i != graphic_formats.end(); i++)
+ {
+ *result = BaseFileName + *i;
+ if(QFile::exists(*result))
+ return true;
+ }
+ return false;
+}
+
View
29 mythplugins/mythgame/mythgame/pcrominfo.h
@@ -0,0 +1,29 @@
+#ifndef PCROMINFO_H_
+#define PCROMINFO_H_
+
+#include <qstring.h>
+#include <mythtv/mythcontext.h>
+#include "rominfo.h"
+
+class QSqlDatabase;
+
+class PCRomInfo : public RomInfo
+{
+ public:
+ PCRomInfo(QString lromname = "",
+ QString lsystem = "",
+ QString lgamename ="",
+ QString lgenre = "",
+ int lyear = 0) :
+ RomInfo(lromname, lsystem, lgamename, lgenre, lyear)
+ {}
+
+ PCRomInfo(const RomInfo &lhs) :
+ RomInfo(lhs) {}
+
+ virtual ~PCRomInfo() {}
+
+ virtual bool FindImage(QString type,QString *result);
+};
+
+#endif
View
177 mythplugins/mythgame/mythgame/pcsettingsdlg.cpp
@@ -0,0 +1,177 @@
+#include "pcsettingsdlg.h"
+
+#include <qapplication.h>
+#include <qvariant.h>
+#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qframe.h>
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qslider.h>
+#include <qtabwidget.h>
+#include <qwidget.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qwhatsthis.h>
+#include <qimage.h>
+
+#include "pchandler.h"
+
+#include <mythtv/mythcontext.h>
+
+using namespace std;
+
+PCSettingsDlg::PCSettingsDlg(QWidget* parent,
+ const char* name, bool modal,
+ bool system, WFlags fl)
+ : QDialog( parent, name, modal, fl ), bSystem(system)
+{
+ setCursor(QCursor(Qt::BlankCursor));
+ if ( !name )
+ setName( "SnesSettings" );
+
+ int screenwidth = 0, screenheight = 0;
+
+ gContext->GetScreenSettings(screenwidth, wmult, screenheight, hmult);
+
+ resize( screenwidth, screenheight );
+ setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, sizePolicy().hasHeightForWidth() ) );
+ setMinimumSize( QSize( screenwidth, screenheight ) );
+ setMaximumSize( QSize( screenwidth, screenheight ) );
+ setCaption( trUtf8( "PC Settings" ) );
+
+ PCTab = new QTabWidget( this, "PCTab" );
+ PCTab->setGeometry( QRect( 0, 0, screenwidth, screenheight ) );
+ PCTab->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, PCTab->sizePolicy().hasHeightForWidth() ) );
+ PCTab->setBackgroundOrigin( QTabWidget::WindowOrigin );
+ QFont PCTab_font( PCTab->font() );
+ PCTab_font.setFamily( "Helvetica [Urw]" );
+ PCTab_font.setPointSize( (int)(gContext->GetMediumFontSize() * wmult));
+ PCTab_font.setBold( TRUE );
+ PCTab->setFont( PCTab_font );
+
+ SettingsTab = new QWidget( PCTab, "SettingsTab" );
+ PCTab->insertTab( SettingsTab, trUtf8( "Settings" ) );
+
+ SettingsFrame = new QFrame( SettingsTab, "SettingsFrame" );
+ SettingsFrame->setGeometry( QRect(0, (int)(33 * hmult),
+ (int)(800 * wmult), (int)(480 * hmult)));
+ SettingsFrame->setFrameShape( QFrame::StyledPanel );
+ SettingsFrame->setFrameShadow( QFrame::Raised );
+
+ if(!bSystem)
+ {
+ ScreenPic = new QLabel( SettingsFrame, "ScreenPic" );
+ ScreenPic->setEnabled( TRUE );
+ ScreenPic->setGeometry( QRect( 200, 100, screenwidth - 300, screenheight - 200 ) );
+ ScreenPic->setScaledContents( TRUE );
+
+ NameLabel = new QLabel( SettingsFrame, "NameLabel" );
+ NameLabel->setGeometry( QRect( (int)(20 * wmult), (int)(330 * hmult),
+ (int)(161 * wmult), (int)(31 * hmult)) );
+ NameLabel->setText( trUtf8( "Game Name: " ) );
+ NameValLabel = new QLabel( SettingsFrame, "NameValLabel" );
+ NameValLabel->setGeometry( QRect( (int)(181 * wmult), (int)(330 * hmult),
+ (int)(400 * wmult), (int)(31 * hmult)) );
+
+ CommandLabel = new QLabel( SettingsFrame, "CommandLabel" );
+ CommandLabel->setGeometry( QRect( (int)(20 * wmult), (int)(365 * hmult),
+ (int)(161 * wmult), (int)(31 * hmult)) );
+ CommandLabel->setText( trUtf8( "Command: " ) );
+ CommandValLabel = new QLabel( SettingsFrame, "CommandValLabel" );
+ CommandValLabel->setGeometry( QRect( (int)(181 * wmult), (int)(365 * hmult),
+ (int)(400 * wmult), (int)(31 * hmult)) );
+
+ GenreLabel = new QLabel( SettingsFrame, "GenreLabel" );
+ GenreLabel->setGeometry( QRect( (int)(20 * wmult), (int)(400 * hmult),
+ (int)(161 * wmult), (int)(31 * hmult)) );
+ GenreLabel->setText( trUtf8( "Genre: " ) );
+ GenreValLabel = new QLabel( SettingsFrame, "GenreValLabel" );
+ GenreValLabel->setGeometry( QRect( (int)(181 * wmult), (int)(400 * hmult),
+ (int)(400 * wmult), (int)(31 * hmult)) );
+
+ YearLabel = new QLabel( SettingsFrame, "YearLabel" );
+ YearLabel->setGeometry( QRect( (int)(20 * wmult), (int)(435 * hmult),
+ (int)(161 * wmult), (int)(31 * hmult)) );
+ YearLabel->setText( trUtf8( "Year: " ) );
+ YearValLabel = new QLabel( SettingsFrame, "YearValLabel" );
+ YearValLabel->setGeometry( QRect( (int)(181 * wmult), (int)(435 * hmult),
+ (int)(400 * wmult), (int)(31 * hmult)) );
+ }
+
+
+ else
+ {
+
+ ListButton = new QPushButton( SettingsFrame, "ListButton" );
+ ListButton->setGeometry( QRect( (int)(100 * wmult), (int)(250 * hmult),
+ (int)(250 * wmult), (int)(40 * hmult)));
+ ListButton->setText( trUtf8( "Reload Game List" ) );
+ connect(ListButton, SIGNAL(pressed()), this,
+ SLOT(loadList()));
+ }
+}
+
+/*
+ * Destroys the object and frees any allocated resources
+ */
+PCSettingsDlg::~PCSettingsDlg()
+{
+ // no need to delete child widgets, Qt does it all for us
+}
+
+void PCSettingsDlg::Show(PCRomInfo* rominfo)
+{
+ if(rominfo && !bSystem)
+ {
+ NameValLabel->setText( trUtf8(rominfo->Gamename()) );
+ CommandValLabel->setText( trUtf8(rominfo->Romname()) );
+ GenreValLabel->setText( trUtf8(rominfo->Genre()) );
+ YearValLabel->setNum(int(rominfo->Year()));
+ }
+ showFullScreen();
+ setActiveWindow();
+ exec();
+}
+
+void PCSettingsDlg::loadList()
+{
+ PCHandler::getHandler()->processGames();
+}
+
+void PCSettingsDlg::SetScreenshot(QString picfile)
+{
+ if(ScreenPic)
+ {
+ Screenshot.load(picfile);
+ ScaleImageLabel(Screenshot,ScreenPic);
+ ScreenPic->setPixmap(Screenshot);
+ }
+}
+
+void PCSettingsDlg::ScaleImageLabel(QPixmap &pixmap, QLabel *label)
+{
+ int FrameWidth = width() / 2;
+ int FrameHeight = (int)(height() - 33 * hmult) / 2;
+ int ImageWidth = pixmap.width();
+ int ImageHeight = pixmap.height();
+ int x = 0, y = 0;
+ if (float(ImageHeight)/float(ImageWidth) < float(FrameHeight)/float(FrameWidth))
+ {
+ int temp = ImageWidth;
+ ImageWidth = FrameWidth;
+ ImageHeight = (ImageWidth * ImageHeight) / temp;
+ y = (FrameHeight - ImageHeight) / 2;
+ }
+ else
+ {
+ int temp = ImageHeight;
+ ImageHeight = FrameHeight;
+ ImageWidth = (ImageHeight * ImageWidth) / temp;
+ x = (FrameWidth - ImageWidth) / 2;
+ }
+ label->setGeometry( QRect( x + 200, y + 25, ImageWidth, ImageHeight ) );
+}
+
View
65 mythplugins/mythgame/mythgame/pcsettingsdlg.h
@@ -0,0 +1,65 @@
+#ifndef PCSETTINGSDLG_H
+#define PCSETTINGSDLG_H
+
+#include <qvariant.h>
+#include <qdialog.h>
+#include <qpixmap.h>
+#include "pcrominfo.h"
+
+class QVBoxLayout;
+class QHBoxLayout;
+class QGridLayout;
+class QCheckBox;
+class QComboBox;
+class QFrame;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QSlider;
+class QTabWidget;
+class QWidget;
+class MythContext;
+
+class PCSettingsDlg : public QDialog
+{
+ Q_OBJECT
+
+public:
+ PCSettingsDlg(QWidget* parent = 0,
+ const char* name = 0, bool modal = FALSE,
+ bool system = false,WFlags fl = 0 );
+ ~PCSettingsDlg();
+
+ QTabWidget* PCTab;
+ QWidget* SettingsTab;
+ QPushButton* ListButton;
+ QFrame* SettingsFrame;
+ QLabel* NameLabel;
+ QLabel* NameValLabel;
+ QLabel* CommandLabel;
+ QLabel* CommandValLabel;
+ QLabel* GenreLabel;
+ QLabel* GenreValLabel;
+ QLabel* YearLabel;
+ QLabel* YearValLabel;
+ QLabel* ScreenPic;
+
+ void SetScreenshot(QString picfile);
+ void Show(PCRomInfo*);
+
+protected slots:
+
+ void loadList();
+
+protected:
+
+ void ScaleImageLabel(QPixmap &pixmap, QLabel *label);
+ bool bSystem;
+ QPixmap Screenshot;
+
+private:
+ float wmult, hmult;
+};
+
+#endif // PCSETTINGSDLG_H
View
661 mythplugins/mythgame/mythgame/sneshandler.cpp
@@ -0,0 +1,661 @@
+#include <fstream>
+#include <iostream>
+#include "sneshandler.h"
+#include "snessettingsdlg.h"
+
+#include <qobject.h>
+#include <qptrlist.h>
+#include <qstringlist.h>
+#include <qsqldatabase.h>
+#include <qdir.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <mythtv/mythcontext.h>
+#include <mythtv/mythwidgets.h>
+
+#include <string>
+#include <math.h>
+
+using namespace std;
+
+#define ONEMBIT 131072
+#define ONEMBYTE 1048576
+
+SnesHandler::~SnesHandler()
+{
+}
+
+bool SnesHandler::IsSnesRom(QString Path, RomHeader* Header, bool bVerifyChecksum)
+{
+ bool SnesRom = false;
+ unsigned int bytesRead = 0;
+ unsigned int start = 0;
+ bool Verified = false; //this holds the value for the Rom Header verification
+ unsigned int Mbit, Low, High, LowTotal, HighTotal, ChkFound, Mult;
+
+ // See if the file is a zip file first
+ unzFile zf;
+ if ((zf = unzOpen(Path)))
+ {
+ // TODO Does this loop check the last file?
+ int FoundFile;
+ for (FoundFile = unzGoToFirstFile(zf); FoundFile == UNZ_OK;
+ FoundFile = unzGoToNextFile(zf))
+ {
+ if (unzOpenCurrentFile(zf) == UNZ_OK)
+ {
+ bytesRead = 0;
+ Verified = VerifyZipRomHeader(zf, 32704, bytesRead, Header);
+ if(!Verified)
+ {
+ start = 512;
+ Verified = VerifyZipRomHeader(zf, 33216, bytesRead, Header);
+ }
+ if(!Verified)
+ {
+ start = 0;
+ Verified = VerifyZipRomHeader(zf, 65472, bytesRead, Header);
+ }
+ if(!Verified)
+ {
+ start = 512;
+ Verified = VerifyZipRomHeader(zf, 65984, bytesRead, Header);
+ }
+ unzCloseCurrentFile(zf);
+ if(!bVerifyChecksum)
+ return Verified;
+ if (Verified)
+ {
+ unz_file_info ZipFileInfo;
+ unzGetCurrentFileInfo(zf,&ZipFileInfo,NULL,0,NULL,0,NULL,0);
+ Mbit = (int) ZipFileInfo.uncompressed_size / ONEMBIT;
+ Low = (unsigned int)pow(2.0, (int)(log10((float)Mbit) / log10(2.0)));
+ High = Mbit - Low;
+ HighTotal = LowTotal = 0;
+ unsigned char current;
+ if (unzOpenCurrentFile(zf) == UNZ_OK)
+ {
+ for(unsigned int i = 0;i < start;i++)
+ unzReadCurrentFile(zf, &current, 1);
+ for(unsigned int i = 0;i < Low * ONEMBIT; i++)
+ {
+ unzReadCurrentFile(zf, &current, 1);
+ LowTotal+= current;
+ }
+ for(unsigned int i = Low * ONEMBIT;i < Mbit * ONEMBIT;i++)
+ {
+ unzReadCurrentFile(zf, &current, 1);
+ HighTotal+= current;
+ }
+ Mult = 0;
+ if(High)
+ Mult = Low / High;
+ ChkFound = (unsigned short)(LowTotal + HighTotal * Mult);
+ if(Header->RomChecksum == ChkFound)
+ SnesRom = true;
+ }
+ }
+ }
+ }
+ unzClose(zf);
+ }
+ else
+ {
+ // Normal file
+ QFile qf(Path);
+ if (qf.open(IO_ReadOnly))
+ {
+ FILE* pFile;
+ if((pFile = fopen(Path, "rb")))
+ {
+ Verified = VerifyRomHeader(pFile,32704,Header);
+ if(!Verified)
+ Verified = VerifyRomHeader(pFile,65472,Header);
+ if(!Verified)
+ {
+ start = 512;
+ Verified = VerifyRomHeader(pFile,33216,Header);
+ }
+ if(!Verified)
+ Verified = VerifyRomHeader(pFile,65984,Header);
+ if(!bVerifyChecksum)
+ return Verified;
+ if(Verified)
+ {
+ fseek(pFile,0,SEEK_END);
+ Mbit = (int) ftell(pFile) / ONEMBIT;
+ Low = (unsigned int)pow(2.0, (int)(log10((float)Mbit) / log10(2.0)) );
+ High = Mbit - Low;
+ HighTotal = LowTotal = 0;
+ unsigned char current;
+ fseek(pFile,start,SEEK_SET);
+ for(unsigned int i = 0;i < Low * ONEMBIT; i++)
+ {
+ fread(&current,1,1,pFile);
+ LowTotal+= current;
+ }
+ for(unsigned int i = Low * ONEMBIT;i < Mbit * ONEMBIT;i++)
+ {
+ fread(&current,1,1,pFile);
+ HighTotal+= current;
+ }
+ Mult = 0;
+ if(High)
+ Mult = Low / High;
+ ChkFound = (unsigned short)(LowTotal + HighTotal * Mult);
+ if(Header->RomChecksum == ChkFound)
+ SnesRom = true;
+ }
+ }
+ fclose(pFile);
+ }
+ }
+
+ return SnesRom;
+}
+
+void SnesHandler::processGames(bool bValidate)
+{
+ if(bValidate)
+ {
+ processGames();
+ }
+ else
+ {
+ QString thequery;
+ QSqlDatabase* db = QSqlDatabase::database();
+
+ thequery = "DELETE FROM gamemetadata WHERE system = \"Snes\";";
+ db->exec(thequery);
+
+ // Search the rom dir for valid new roms.
+ QDir RomDir(gContext->GetSetting("SnesRomLocation"));
+ const QFileInfoList* List = RomDir.entryInfoList();
+
+ if (!List)
+ return;
+
+ RomHeader RHeader;
+
+ QStringList rom_extensions;
+ rom_extensions.append("zip");
+ rom_extensions.append("smc");
+ rom_extensions.append("sfc");
+ rom_extensions.append("fig");
+ rom_extensions.append("1");
+ rom_extensions.append("2");
+
+ QString GameName;
+ QString Genre("Unknown");
+ int Year = 0;
+ bool bRomFound;
+
+ MythProgressDialog pdial("Looking for SNES gams...", List->count());
+ int progress = 0;
+
+ for (QFileInfoListIterator it(*List); it; ++it)
+ {
+ pdial.setProgress(progress);
+ progress++;
+
+ bRomFound = false;
+ QFileInfo Info(*it.current());
+ if (IsSnesRom(Info.filePath(),&RHeader, false))
+ {
+ bRomFound = true;
+ char NameBuffer[22];
+ for(int i = 0;i < 21;i++)
+ {
+ if(RHeader.RomTitle[i] < 32 || RHeader.RomTitle[i] > 126)
+ {
+ NameBuffer[i] = '\0';
+ break;
+ }
+ NameBuffer[i] = RHeader.RomTitle[i];
+ }
+ NameBuffer[21] = '\0';
+ GameName = NameBuffer;
+ }
+ //The file couldn't be verified. Check the extension.
+ else
+ {
+ for (QStringList::Iterator i = rom_extensions.begin(); i != rom_extensions.end(); i++)
+ {
+ if(Info.extension(false).lower() == *i)
+ {
+ GameName = Info.baseName() + " (bad checksum)";
+ bRomFound = true;
+ break;
+ }
+ }
+ }
+
+ cout << GameName << endl;
+
+ if(bRomFound)
+ {
+ // Put the game into the database.
+ thequery = QString("INSERT INTO gamemetadata "
+ "(system, romname, gamename, genre, year) "
+ "VALUES (\"Snes\", \"%1\", \"%2\", \"%3\", %4);")
+ .arg(Info.fileName().latin1())
+ .arg(GameName.latin1()).arg(Genre.latin1())
+ .arg(Year);
+ db->exec(thequery);
+ }
+ }
+
+ pdial.Close();
+ }
+}
+
+void SnesHandler::processGames()
+{
+ QString thequery;
+
+ QSqlDatabase* db = QSqlDatabase::database();
+
+ // Remove all metadata entries from the tables, all correct values will be
+ // added as they are found. This is done so that entries that may no longer be
+ // available or valid are removed each time the game list is remade.
+ thequery = "DELETE FROM gamemetadata WHERE system = \"Snes\";";
+ db->exec(thequery);
+
+ // Search the rom dir for valid new roms.
+ QDir RomDir(gContext->GetSetting("SnesRomLocation"));
+ const QFileInfoList* List = RomDir.entryInfoList();
+
+ if (!List)
+ return;
+
+ RomHeader RHeader;
+
+ MythProgressDialog pdial("Looking for SNES games...", List->count());
+ int progress = 0;
+
+ for (QFileInfoListIterator it(*List); it; ++it)
+ {
+ pdial.setProgress(progress);
+ progress++;
+
+ QFileInfo Info(*it.current());
+ if (IsSnesRom(Info.filePath(),&RHeader, true))
+ {
+ char NameBuffer[22];
+ for(int i = 0;i < 21;i++)
+ {
+ if(RHeader.RomTitle[i] < 32 || RHeader.RomTitle[i] > 126)
+ {
+ NameBuffer[i] = '\0';
+ break;
+ }
+ NameBuffer[i] = RHeader.RomTitle[i];
+ }
+ NameBuffer[21] = '\0';
+ QString GameName(NameBuffer);
+ QString Genre("Unknown");
+ int Year = 0;
+
+ cout << GameName << endl;
+
+ // Put the game into the database.
+ thequery = QString("INSERT INTO gamemetadata "
+ "(system, romname, gamename, genre, year) "
+ "VALUES (\"Snes\", \"%1\", \"%2\", \"%3\", %4);")
+ .arg(Info.fileName().latin1())
+ .arg(GameName.latin1()).arg(Genre.latin1())
+ .arg(Year);
+ db->exec(thequery);
+ }
+ }
+
+ pdial.Close();
+}
+
+void SnesHandler::start_game(RomInfo * romdata)
+{
+ SnesGameSettings game_settings;
+ SnesRomInfo *snesdata = dynamic_cast<SnesRomInfo*>(romdata);
+ SetGameSettings(game_settings, snesdata);
+ QString exec = gContext->GetSetting("SnesBinary") + " ";
+ //bool bNoSound = false;
+ if(game_settings.transparency)
+ exec+= "-tr ";
+ if(game_settings.sixteen)
+ exec+= "-16 ";
+ if(game_settings.hi_res)
+ exec+= "-hi ";
+ if(game_settings.no_mode_switch)
+ exec+= "-nms ";
+ if(game_settings.full_screen)
+ exec+= "-fs ";
+ if(game_settings.stretch)
+ exec+= "-sc ";
+ if(game_settings.no_sound)
+ exec+= "-ns ";
+ else
+ {
+ if(game_settings.stereo)
+ exec+= "-st ";
+ else
+ exec+= " -mono ";
+ if(game_settings.envx)
+ exec+= "-ex ";
+ if(game_settings.thread_sound)
+ exec+= "-ts ";
+ if(game_settings.sound_sync)
+ exec+= "-sy ";
+ if(game_settings.interpolated_sound)
+ exec+= "-is ";
+ if(game_settings.no_sample_caching)
+ exec+= "-nc ";
+ if(game_settings.alt_sample_decode)
+ exec+= "-alt ";
+ if(game_settings.no_echo)
+ exec+= "-ne ";
+ if(game_settings.no_master_volume)
+ exec+= "-nmv ";
+ }
+ if(game_settings.no_joy)
+ exec+= "-j ";
+ if(game_settings.interleaved)
+ exec+= "-i ";
+ if(game_settings.alt_interleaved)
+ exec+= "-i2 ";
+ if(game_settings.hi_rom)
+ exec+= "-hr ";
+ if(game_settings.low_rom)
+ exec+= "-lr ";
+ if(game_settings.header)
+ exec+= "-hd ";
+ if(game_settings.no_header)
+ exec+= "-nhd ";
+ if(game_settings.pal)
+ exec+= "-p ";
+ if(game_settings.ntsc)
+ exec+= "-ntsc ";
+ if(game_settings.layering)
+ exec+= "-l ";
+ if(game_settings.no_hdma)
+ exec+= "-nh ";
+ if(game_settings.no_speed_hacks)
+ exec+= "-nospeedhacks ";
+ if(game_settings.no_windows)
+ exec+= "-nw ";
+ switch(game_settings.interpolate)
+ {
+ case 1:
+ exec+= "-y ";
+ break;
+ case 2:
+ exec+= "-y2 ";
+ break;
+ case 3:
+ exec+= "-y3 ";
+ break;
+ case 4:
+ exec+= "-y4 ";
+ break;
+ case 5:
+ exec+= "-y5";
+ break;
+ default:
+ break;
+ }
+ if(game_settings.sound_skip != 0)
+ {
+ exec+= "-sk ";
+ exec+= QString::number(game_settings.sound_skip);
+ exec+= " ";
+ }
+ if(game_settings.sound_quality != 0)
+ {
+ exec+= "-soundquality ";
+ exec+= QString::number(game_settings.sound_quality);
+ exec+= " ";
+ }
+ if(game_settings.buffer_size != 0)
+ {
+ exec+= "-bs ";
+ exec+= QString::number(game_settings.buffer_size);
+ exec+= " ";
+ }
+ exec+= game_settings.extra_options;
+ exec+= " '" + gContext->GetSetting("SnesRomLocation") + "/" + romdata->Romname() + "'";
+ cout << exec << endl;
+
+ // Run the emulator and wait for it to terminate.
+ FILE* command = popen(exec, "w");
+ pclose(command);
+}
+
+void SnesHandler::edit_settings(QWidget *parent,RomInfo * romdata)
+{
+ SnesGameSettings game_settings;
+ SnesRomInfo *snesdata = dynamic_cast<SnesRomInfo*>(romdata);
+ SetGameSettings(game_settings, snesdata);
+
+ SnesSettingsDlg settingsdlg(parent, "gamesettings", true);
+ QString ImageFile;
+ if(snesdata->FindImage("screenshot", &ImageFile))
+ settingsdlg.SetScreenshot(ImageFile);
+ if(settingsdlg.Show(&game_settings))
+ SaveGameSettings(game_settings, snesdata);
+}
+
+void SnesHandler::edit_system_settings(QWidget *parent,RomInfo * romdata)
+{
+ romdata = romdata;
+ SnesSettingsDlg settingsDlg(parent, "snessettings", true, true);
+ if(settingsDlg.Show(&defaultSettings))
+ SaveGameSettings(defaultSettings, NULL);
+}
+
+SnesHandler* SnesHandler::getHandler(void)
+{
+ if(!pInstance)
+ {
+ pInstance = new SnesHandler();
+ }
+ return pInstance;
+}
+
+RomInfo* SnesHandler::create_rominfo(RomInfo *parent)
+{
+ return new SnesRomInfo(*parent);
+}
+
+bool SnesHandler::VerifyZipRomHeader(unzFile zf, unsigned int offset, unsigned int &bytesRead, RomHeader* Header)
+{
+ char buffer[4];
+ for(;bytesRead < offset;bytesRead+=4)
+ {
+ if(unzReadCurrentFile(zf,buffer,4) != 4)
+ break;
+ }
+ if(unzReadCurrentFile(zf,Header,sizeof(RomHeader)) != sizeof(RomHeader))
+ return false;
+ bytesRead+= sizeof(RomHeader);
+ return ((Header->InverseRomChecksum + Header->RomChecksum) == 0xFFFF);
+}
+
+bool SnesHandler::VerifyRomHeader(FILE* pFile,unsigned int offset, RomHeader* Header)
+{
+ fseek(pFile,offset,SEEK_SET);
+ if(fread(Header,sizeof(RomHeader),1,pFile) != 1)
+ return false;
+ return ((Header->InverseRomChecksum + Header->RomChecksum) == 0xFFFF);
+}
+
+void SnesHandler::SetGameSettings(SnesGameSettings &game_settings, SnesRomInfo *rominfo)
+{
+ game_settings = defaultSettings;
+ if(rominfo)
+ {
+ QSqlDatabase *db = QSqlDatabase::database();
+ QString thequery;
+ thequery = QString("SELECT * FROM snessettings WHERE romname = \"%1\";")
+ .arg(rominfo->Romname().latin1());
+ QSqlQuery query = db->exec(thequery);
+ if (query.isActive() && query.numRowsAffected() > 0)
+ {
+ query.next();
+ if (!query.value(1).toBool())
+ {
+ game_settings.default_options = false;
+ game_settings.transparency = query.value(2).toBool();
+ game_settings.sixteen = query.value(3).toBool();
+ game_settings.hi_res = query.value(4).toBool();
+ game_settings.interpolate = query.value(5).toInt();
+ game_settings.no_mode_switch = query.value(6).toBool();
+ game_settings.full_screen = query.value(7).toBool();
+ game_settings.stretch = query.value(8).toBool();
+ game_settings.no_sound = query.value(9).toBool();
+ game_settings.sound_skip = query.value(10).toInt();
+ game_settings.stereo = query.value(11).toBool();
+ game_settings.sound_quality = query.value(12).toInt();
+ game_settings.envx = query.value(13).toBool();
+ game_settings.thread_sound = query.value(14).toBool();
+ game_settings.sound_sync = query.value(15).toBool();
+ game_settings.interpolated_sound = query.value(16).toBool();
+ game_settings.buffer_size = query.value(17).toInt();
+ game_settings.no_sample_caching = query.value(18).toBool();
+ game_settings.alt_sample_decode = query.value(19).toBool();
+ game_settings.no_echo = query.value(20).toBool();
+ game_settings.no_master_volume = query.value(21).toBool();
+ game_settings.no_joy = query.value(22).toBool();
+ game_settings.interleaved = query.value(23).toBool();
+ game_settings.alt_interleaved = query.value(24).toBool();
+ game_settings.hi_rom = query.value(25).toBool();
+ game_settings.low_rom = query.value(26).toBool();
+ game_settings.header = query.value(27).toBool();
+ game_settings.no_header = query.value(28).toBool();
+ game_settings.pal = query.value(29).toBool();
+ game_settings.ntsc = query.value(30).toBool();
+ game_settings.layering = query.value(31).toBool();
+ game_settings.no_hdma = query.value(32).toBool();
+ game_settings.no_speed_hacks = query.value(33).toBool();
+ game_settings.no_windows = query.value(34).toBool();
+ game_settings.extra_options = query.value(35).toString();
+ }
+ }
+ }
+}
+
+void SnesHandler::SetDefaultSettings()
+{
+ QSqlDatabase *db = QSqlDatabase::database();
+ QSqlQuery query = db->exec("SELECT * FROM snessettings WHERE romname = \"default\";");
+
+ if (query.isActive() && query.numRowsAffected() > 0)
+ {
+ query.next();
+ defaultSettings.default_options = query.value(1).toBool();
+ defaultSettings.transparency = query.value(2).toBool();
+ defaultSettings.sixteen = query.value(3).toBool();
+ defaultSettings.hi_res = query.value(4).toBool();
+ defaultSettings.interpolate = query.value(5).toInt();
+ defaultSettings.no_mode_switch = query.value(6).toBool();
+ defaultSettings.full_screen = query.value(7).toBool();
+ defaultSettings.stretch = query.value(8).toBool();
+ defaultSettings.no_sound = query.value(9).toBool();
+ defaultSettings.sound_skip = query.value(10).toInt();
+ defaultSettings.stereo = query.value(11).toBool();
+ defaultSettings.sound_quality = query.value(12).toInt();
+ defaultSettings.envx = query.value(13).toBool();
+ defaultSettings.thread_sound = query.value(14).toBool();
+ defaultSettings.sound_sync = query.value(15).toBool();
+ defaultSettings.interpolated_sound = query.value(16).toBool();
+ defaultSettings.buffer_size = query.value(17).toInt();
+ defaultSettings.no_sample_caching = query.value(18).toBool();
+ defaultSettings.alt_sample_decode = query.value(19).toBool();
+ defaultSettings.no_echo = query.value(20).toBool();
+ defaultSettings.no_master_volume = query.value(21).toBool();
+ defaultSettings.no_joy = query.value(22).toBool();
+ defaultSettings.interleaved = query.value(23).toBool();
+ defaultSettings.alt_interleaved = query.value(24).toBool();
+ defaultSettings.hi_rom = query.value(25).toBool();
+ defaultSettings.low_rom = query.value(26).toBool();
+ defaultSettings.header = query.value(27).toBool();
+ defaultSettings.no_header = query.value(28).toBool();
+ defaultSettings.pal = query.value(29).toBool();
+ defaultSettings.ntsc = query.value(30).toBool();
+ defaultSettings.layering = query.value(31).toBool();
+ defaultSettings.no_hdma = query.value(32).toBool();
+ defaultSettings.no_speed_hacks = query.value(33).toBool();
+ defaultSettings.no_windows = query.value(34).toBool();
+ defaultSettings.extra_options = query.value(35).toString();
+ }
+}
+
+void SnesHandler::SaveGameSettings(SnesGameSettings &game_settings, SnesRomInfo *rominfo)
+{
+ QSqlDatabase *db = QSqlDatabase::database();
+ QString thequery;
+ QString RomName = "default";
+ if(rominfo)
+ RomName = rominfo->Romname();
+ thequery = QString("SELECT romname FROM snessettings WHERE romname = \"%1\";").arg(RomName.latin1());
+ QSqlQuery query = db->exec(thequery);
+ if (query.isActive() && query.numRowsAffected() > 0)
+ {
+ thequery.sprintf("UPDATE snessettings SET usedefault = %d, transparency = %d, "
+ "sixteen = %d, hires = %d, interpolate = %d, "
+ "nomodeswitch = %d, fullscreen = %d, stretch = %d, nosound = %d, "
+ "soundskip = %d, stereo = %d, soundquality = %d, envx = %d, "
+ "threadsound = %d, syncsound = %d, interpolatedsound = %d, buffersize = %d, "
+ "nosamplecaching = %d, altsampledecode = %d, noecho = %d , "
+ "nomastervolume = %d, nojoy = %d, interleaved = %d, "
+ "altinterleaved = %d, hirom = %d, lowrom = %d, header = %d, "
+ "noheader = %d, pal = %d, ntsc = %d, layering = %d, nohdma = %d, nospeedhacks = %d, "
+ "nowindows = %d, extraoption = \"%s\" WHERE romname = \"%s\";",
+ game_settings.default_options, game_settings.transparency,
+ game_settings.sixteen, game_settings.hi_res,
+ game_settings.interpolate, game_settings.no_mode_switch,
+ game_settings.full_screen, game_settings.stretch,
+ game_settings.no_sound, game_settings.sound_skip, game_settings.stereo,
+ game_settings.sound_quality, game_settings.envx,
+ game_settings.thread_sound, game_settings.sound_sync, game_settings.interpolated_sound,
+ game_settings.buffer_size, game_settings.no_sample_caching,
+ game_settings.alt_sample_decode, game_settings.no_echo,
+ game_settings.no_master_volume, game_settings.no_joy, game_settings.interleaved,
+ game_settings.alt_interleaved, game_settings.hi_rom,
+ game_settings.low_rom, game_settings.header, game_settings.no_header,
+ game_settings.pal, game_settings.ntsc, game_settings.layering,
+ game_settings.no_hdma, game_settings.no_speed_hacks,
+ game_settings.no_windows, game_settings.extra_options.latin1(),
+ RomName.latin1());
+ }
+ else
+ {
+ thequery.sprintf("INSERT INTO snessettings (romname,usedefault,transparency,sixteen,"
+ "hires,interpolate,nomodeswitch,fullscreen,stretch,"
+ "nosound,soundskip,stereo,soundquality,envx,threadsound,syncsound,"
+ "interpolatedsound,buffersize,nosamplecaching,altsampledecode,noecho,nomastervolume,"
+ "nojoy,interleaved,altinterleaved,hirom,lowrom,header,noheader,"
+ "pal,ntsc,layering,nohdma,nospeedhacks,nowindows,extraoption) VALUES "
+ "(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,"
+ "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,\"%s\");",RomName.latin1(),
+ game_settings.default_options, game_settings.transparency,
+ game_settings.sixteen, game_settings.hi_res,
+ game_settings.interpolate, game_settings.no_mode_switch,
+ game_settings.full_screen, game_settings.stretch,
+ game_settings.no_sound, game_settings.sound_skip, game_settings.stereo,
+ game_settings.sound_quality, game_settings.envx,
+ game_settings.thread_sound, game_settings.sound_sync, game_settings.interpolated_sound,
+ game_settings.buffer_size, game_settings.no_sample_caching,
+ game_settings.alt_sample_decode, game_settings.no_echo,
+ game_settings.no_master_volume, game_settings.no_joy, game_settings.interleaved,
+ game_settings.alt_interleaved, game_settings.hi_rom,
+ game_settings.low_rom, game_settings.header, game_settings.no_header,
+ game_settings.pal, game_settings.ntsc, game_settings.layering,
+ game_settings.no_hdma, game_settings.no_speed_hacks,
+ game_settings.no_windows, game_settings.extra_options.latin1());
+ }
+ query = db->exec(thequery);
+}
+
+SnesHandler* SnesHandler::pInstance = 0;
+
View
58 mythplugins/mythgame/mythgame/sneshandler.h
@@ -0,0 +1,58 @@
+#ifndef SNESHANDLER_H_
+#define SNESHANDLER_H_
+
+#include "gamehandler.h"
+#include "snesrominfo.h"
+#include "unzip.h"
+#include <qapplication.h>
+#include <map>
+
+using namespace std;
+
+class RomHeader
+{
+ public:
+ unsigned char RomTitle[21];
+ unsigned char RomMakeup;
+ unsigned char RomType;
+ unsigned char RomSize;
+ unsigned char SramSize;
+ unsigned char Country;
+ unsigned char License;
+ unsigned char GameVersion;
+ unsigned short InverseRomChecksum;
+ unsigned short RomChecksum;
+ unsigned short NonMaskableInterupt;
+ unsigned short ResetVector;
+};
+
+class SnesHandler : public GameHandler
+{
+ public:
+ SnesHandler() : GameHandler() {
+ systemname = "Snes";
+ SetDefaultSettings();
+ }
+ virtual ~SnesHandler();
+
+ void start_game(RomInfo *romdata);
+ void edit_settings(QWidget *parent,RomInfo *romdata);
+ void edit_system_settings(QWidget *parent,RomInfo *romdata);
+ RomInfo* create_rominfo(RomInfo* parent);
+ void processGames();
+ void processGames(bool);
+
+ static SnesHandler* getHandler(void);
+
+ private:
+ static SnesHandler* pInstance;
+ bool IsSnesRom(QString Path,RomHeader* Header, bool bVerifyChecksum);
+ bool VerifyZipRomHeader(unzFile zf, unsigned int offset, unsigned int &bytesRead, RomHeader* Header);
+ bool VerifyRomHeader(FILE* pFile,unsigned int offset, RomHeader* Header);
+ void SetGameSettings(SnesGameSettings &game_settings, SnesRomInfo *rominfo);
+ void SetDefaultSettings();
+ void SaveGameSettings(SnesGameSettings &game_settings, SnesRomInfo *romdata);
+ SnesGameSettings defaultSettings;
+};
+
+#endif
View
37 mythplugins/mythgame/mythgame/snesrominfo.cpp
@@ -0,0 +1,37 @@
+#include <qsqldatabase.h>
+#include <qfile.h>
+#include "snesrominfo.h"
+#include <iostream>
+
+using namespace std;
+
+bool SnesRomInfo::FindImage(QString type, QString *result)
+{
+ if (type != "screenshot")
+ return false;
+
+ QStringList graphic_formats;
+ graphic_formats.append("png");
+ graphic_formats.append("gif");
+ graphic_formats.append("jpg");
+ graphic_formats.append("jpeg");
+ graphic_formats.append("xpm");
+ graphic_formats.append("bmp");
+ graphic_formats.append("pnm");
+ graphic_formats.append("tif");
+ graphic_formats.append("tiff");
+
+ QString BaseFileName = gContext->GetSetting("SnesScreensLocation") + "/" + romname;
+ int dotLocation = BaseFileName.findRev('.');
+ if(dotLocation == -1)
+ return false;
+ BaseFileName.truncate(dotLocation + 1);
+ for (QStringList::Iterator i = graphic_formats.begin(); i != graphic_formats.end(); i++)
+ {
+ *result = BaseFileName + *i;
+ if(QFile::exists(*result))
+ return true;
+ }
+ return false;
+}
+
View
69 mythplugins/mythgame/mythgame/snesrominfo.h
@@ -0,0 +1,69 @@
+#ifndef SNESROMINFO_H_
+#define SNESROMINFO_H_
+
+#include <qstring.h>
+#include <mythtv/mythcontext.h>
+#include "rominfo.h"
+
+class QSqlDatabase;
+
+class SnesGameSettings
+{
+ public:
+ bool default_options;
+ bool transparency;
+ bool sixteen;
+ bool hi_res;
+ unsigned short interpolate;
+ bool no_mode_switch;
+ bool full_screen;
+ bool stretch;
+ bool no_sound;
+ unsigned short sound_skip;
+ bool stereo;
+ unsigned short sound_quality;
+ bool envx;
+ bool thread_sound;
+ bool sound_sync;
+ bool interpolated_sound;
+ unsigned int buffer_size;
+ bool no_sample_caching;
+ bool alt_sample_decode;
+ bool no_echo;
+ bool no_master_volume;
+ bool no_joy;
+ bool interleaved;
+ bool alt_interleaved;
+ bool hi_rom;
+ bool low_rom;
+ bool header;
+ bool no_header;
+ bool pal;
+ bool ntsc;
+ bool layering;
+ bool no_hdma;
+ bool no_speed_hacks;
+ bool no_windows;
+ QString extra_options;
+};
+
+class SnesRomInfo : public RomInfo
+{
+ public:
+ SnesRomInfo(QString lromname = "",
+ QString lsystem = "",
+ QString lgamename ="",
+ QString lgenre = "",
+ int lyear = 0) :
+ RomInfo(lromname, lsystem, lgamename, lgenre, lyear)
+ {}
+
+ SnesRomInfo(const RomInfo &lhs) :
+ RomInfo(lhs) {}
+
+ virtual ~SnesRomInfo() {}
+
+ virtual bool FindImage(QString type,QString *result);
+};
+
+#endif
View
567 mythplugins/mythgame/mythgame/snessettingsdlg.cpp
@@ -0,0 +1,567 @@
+#include "snessettingsdlg.h"
+#include <iostream>
+
+#include <qapplication.h>
+#include <qvariant.h>
+#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qframe.h>
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qslider.h>
+#include <qtabwidget.h>
+#include <qwidget.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qwhatsthis.h>
+#include <qimage.h>
+
+#include "sneshandler.h"
+
+#include <mythtv/mythcontext.h>
+
+using namespace std;
+
+#define SAVE_SETTINGS 1
+#define DONT_SAVE_SETTINGS 0
+
+SnesSettingsDlg::SnesSettingsDlg(QWidget* parent,
+ const char* name, bool modal,
+ bool system, WFlags fl)
+ : QDialog( parent, name, modal, fl ), bSystem(system)
+{
+ setCursor(QCursor(Qt::BlankCursor));
+ if ( !name )
+ setName( "SnesSettings" );
+
+ int screenwidth = 0, screenheight = 0;
+
+ gContext->GetScreenSettings(screenwidth, wmult, screenheight, hmult);
+
+ resize( screenwidth, screenheight );
+ setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, sizePolicy().hasHeightForWidth() ) );
+ setMinimumSize( QSize( screenwidth, screenheight ) );
+ setMaximumSize( QSize( screenwidth, screenheight ) );
+ setCaption( trUtf8( "Snes Settings" ) );
+
+ SnesTab = new QTabWidget( this, "SnesTab" );
+ SnesTab->setGeometry( QRect( 0, 0, screenwidth, screenheight ) );
+ SnesTab->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, 0, 0, SnesTab->sizePolicy().hasHeightForWidth() ) );
+ SnesTab->setBackgroundOrigin( QTabWidget::WindowOrigin );
+ QFont SnesTab_font( SnesTab->font() );
+ SnesTab_font.setFamily( "Helvetica [Urw]" );
+ SnesTab_font.setPointSize( (int)(gContext->GetMediumFontSize() * wmult));
+ SnesTab_font.setBold( TRUE );
+ SnesTab->setFont( SnesTab_font );
+
+ SettingsTab = new QWidget( SnesTab, "SettingsTab" );
+ if(bSystem)
+ SnesTab->insertTab( SettingsTab, trUtf8( "defaults" ) );
+ else
+ SnesTab->insertTab( SettingsTab, trUtf8( "Settings" ) );
+
+ SettingsFrame = new QFrame( SettingsTab, "SettingsFrame" );
+ SettingsFrame->setGeometry( QRect(0, (int)(33 * hmult),
+ (int)(800 * wmult), (int)(480 * hmult)));
+ SettingsFrame->setFrameShape( QFrame::StyledPanel );
+ SettingsFrame->setFrameShadow( QFrame::Raised );
+
+ if(!bSystem)
+ {
+ DefaultCheck = new QCheckBox( SettingsTab, "DefaultCheck" );
+ DefaultCheck->setGeometry(QRect((int)(8 * wmult), (int)(3 * hmult),
+ (int)(190 * wmult), (int)(31 * hmult)));
+ DefaultCheck->setText( trUtf8( "use defaults" ) );
+ }
+
+ DisplayGroup = new QGroupBox( SettingsFrame, "DisplayGroup" );
+ DisplayGroup->setGeometry( QRect(0, (int)(10 * hmult),
+ (int)(420 * wmult), (int)(175 * hmult)));
+ DisplayGroup->setTitle( trUtf8( "Display" ) );
+
+ TransCheck = new QCheckBox( DisplayGroup, "TransCheck" );
+ TransCheck->setGeometry( QRect((int)(11 * wmult), (int)(31 * hmult),
+ (int)(190 * wmult), (int)(31 * hmult)));
+ TransCheck->setText( trUtf8( "Transparency" ) );
+
+ SixteenCheck = new QCheckBox( DisplayGroup, "SixteenCheck" );
+ SixteenCheck->setGeometry( QRect( (int)(225 * wmult), (int)(31 * hmult),
+ (int)(184 * wmult), (int)(31 * hmult)));
+ SixteenCheck->setText( trUtf8( "16 Bit" ) );
+
+ HiResCheck = new QCheckBox( DisplayGroup, "HiResCheck" );
+ HiResCheck->setGeometry( QRect( (int)(11 * wmult), (int)(60 * hmult),
+ (int)(150 * wmult), (int)(31 * hmult) ) );
+ HiResCheck->setText( trUtf8( "Use Hi-res" ) );
+
+ NoModeSwitchCheck = new QCheckBox( DisplayGroup, "NoModeSwitchCheck" );
+ NoModeSwitchCheck->setGeometry( QRect( (int)(175 * wmult), (int)(60 * hmult),
+ (int)(210 * wmult), (int)(31 * hmult) ) );
+ NoModeSwitchCheck->setText( trUtf8( "no modeswitch" ) );
+
+ FullScreenCheck = new QCheckBox( DisplayGroup, "FullScreenCheck" );
+ FullScreenCheck->setGeometry( QRect( (int)(11 * wmult), (int)(89 * hmult),
+ (int)(178 * wmult), (int)(31 * hmult)));
+ FullScreenCheck->setText( trUtf8( "Full Screen" ) );
+
+ StretchCheck = new QCheckBox( DisplayGroup, "StretchCheck" );
+ StretchCheck->setGeometry( QRect( (int)(195 * wmult), (int)(89 * hmult),
+ (int)(180 * wmult), (int)(31 * hmult)));
+ StretchCheck->setText( trUtf8( "Stretch to fit" ) );
+
+ InterpolateBox = new QComboBox( FALSE, DisplayGroup, "InterpolateBox" );
+ InterpolateBox->setGeometry( QRect( (int)(170 * wmult), (int)(126 * hmult),
+ (int)(210 * wmult), (int)(40 * hmult) ) );
+ InterpolateBox->setFocusPolicy( QComboBox::TabFocus );
+ InterpolateBox->setAcceptDrops( TRUE );
+ InterpolateBox->setMaxCount( 6 );
+ InterpolateBox->insertItem(trUtf8("None"));
+ InterpolateBox->insertItem(trUtf8("Interpolate 1"));
+ InterpolateBox->insertItem(trUtf8("Interpolate 2"));
+ InterpolateBox->insertItem(trUtf8("Interpolate 3"));
+ InterpolateBox->insertItem(trUtf8("Interpolate 4"));
+ InterpolateBox->insertItem(trUtf8("Interpolate 5"));
+
+ InterpolateLabel = new QLabel( DisplayGroup, "InterpolateLabel" );
+ InterpolateLabel->setGeometry( QRect( (int)(10 * wmult), (int)(126 * hmult),
+ (int)(150 * wmult), (int)(31 * hmult) ) );
+ InterpolateLabel->setText( trUtf8( "Interpolation" ) );
+
+ MiscGroup = new QGroupBox( SettingsFrame, "MiscGroup" );
+ MiscGroup->setGeometry( QRect(0, (int)(185 * hmult),
+ (int)(420 * wmult), (int)(285 * hmult)));
+ MiscGroup->setTitle( trUtf8( "Misc" ) );
+
+ NoJoyCheck = new QCheckBox( MiscGroup, "NoJoyCheck" );
+ NoJoyCheck->setGeometry( QRect((int)(11 * wmult), (int)(31 * hmult),
+ (int)(190 * wmult), (int)(31 * hmult)));
+ NoJoyCheck->setText( trUtf8( "No Joystick" ) );
+
+ LayeringCheck = new QCheckBox( MiscGroup, "LayeringCheck" );
+ LayeringCheck->setGeometry( QRect( (int)(225 * wmult), (int)(31 * hmult),
+ (int)(184 * wmult), (int)(31 * hmult)));
+ LayeringCheck->setText( trUtf8( "Layering" ) );
+
+ InterleavedCheck = new QCheckBox( MiscGroup, "InterleavedCheck" );
+ InterleavedCheck->setGeometry( QRect( (int)(11 * wmult), (int)(60 * hmult),
+ (int)(180 * wmult), (int)(31 * hmult) ) );
+ InterleavedCheck->setText( trUtf8( "Interleaved" ) );
+
+ LowRomCheck = new QCheckBox( MiscGroup, "LowRomCheck" );
+ LowRomCheck->setGeometry( QRect( (int)(225 * wmult), (int)(60 * hmult),
+ (int)(180 * wmult), (int)(31 * hmult)));
+ LowRomCheck->setText( trUtf8( "Low Rom" ) );
+
+ AltInterleavedCheck = new QCheckBox( MiscGroup, "AltInterleavedCheck" );
+ AltInterleavedCheck->setGeometry( QRect( (int)(11 * wmult), (int)(89 * hmult),
+ (int)(210 * wmult), (int)(31 * hmult) ) );
+ AltInterleavedCheck->setText( trUtf8( "Alt Interleaved" ) );
+
+ HiRomCheck = new QCheckBox( MiscGroup, "HiRomCheck" );
+ HiRomCheck->setGeometry( QRect( (int)(225 * wmult), (int)(89 * hmult),
+ (int)(178 * wmult), (int)(31 * hmult)));
+ HiRomCheck->setText( trUtf8( "Hi Rom" ) );
+
+ HeaderCheck = new QCheckBox( MiscGroup, "HeaderCheck" );
+ HeaderCheck->setGeometry( QRect( (int)(11 * wmult), (int)(118 * hmult),
+ (int)(210 * wmult), (int)(31 * hmult) ) );
+ HeaderCheck->setText( trUtf8( "Header" ) );
+
+ NtscCheck = new QCheckBox( MiscGroup, "NtscCheck" );
+ NtscCheck->setGeometry( QRect( (int)(225 * wmult), (int)(118 * hmult),
+ (int)(178 * wmult), (int)(31 * hmult)));
+ NtscCheck->setText( trUtf8( "NTSC" ) );
+
+ NoHeaderCheck = new QCheckBox( MiscGroup, "NoHeaderCheck" );
+ NoHeaderCheck->setGeometry( QRect( (int)(11 * wmult), (int)(147 * hmult),
+ (int)(210 * wmult), (int)(31 * hmult) ) );
+ NoHeaderCheck->setText( trUtf8( "No Header" ) );
+
+ PalCheck = new QCheckBox( MiscGroup, "PalCheck" );
+ PalCheck->setGeometry( QRect( (int)(225 * wmult), (int)(147 * hmult),
+ (int)(178 * wmult), (int)(31 * hmult)));
+ PalCheck->setText( trUtf8( "PAL" ) );
+
+ NoHdmaCheck = new QCheckBox( MiscGroup, "NoHdmaCheck" );
+ NoHdmaCheck->setGeometry( QRect( (int)(11 * wmult), (int)(176 * hmult),
+ (int)(210 * wmult), (int)(31 * hmult) ) );
+ NoHdmaCheck->setText( trUtf8( "No H-DMA" ) );
+
+ NoWindowsCheck = new QCheckBox( MiscGroup, "NoWindowsCheck" );
+ NoWindowsCheck->setGeometry( QRect( (int)(225 * wmult), (int)(176 * hmult),
+ (int)(178 * wmult), (int)(31 * hmult)));
+ NoWindowsCheck->setText( trUtf8( "No Windows" ) );
+
+ NoSpeedHacksCheck = new QCheckBox( MiscGroup, "NoSpeedHacksCheck" );
+ NoSpeedHacksCheck->setGeometry( QRect( (int)(11 * wmult), (int)(205 * hmult),
+ (int)(260 * wmult), (int)(31 * hmult) ) );
+ NoSpeedHacksCheck->setText( trUtf8( "No Speed Hacks" ) );
+
+ OptionsLabel = new QLabel( MiscGroup, "OptionsLabel" );
+ OptionsLabel->setGeometry( QRect( (int)(20 * wmult), (int)(240 * hmult),
+ (int)(166 * wmult), (int)(31 * hmult)) );
+ OptionsLabel->setText( trUtf8( "Extra Options" ) );
+
+ OptionsEdit = new QLineEdit( MiscGroup, "OptionsEdit" );
+ OptionsEdit->setGeometry( QRect( (int)(195 * wmult), (int)(240 * hmult),
+ (int)(201 * wmult), (int)(37 * hmult) ) );
+ OptionsEdit->setFocusPolicy( QLineEdit::TabFocus );
+ OptionsEdit->setMaxLength( 1023 );
+
+ SoundGroup = new QGroupBox( SettingsFrame, "SoundGroup" );
+ SoundGroup->setGeometry( QRect((int)(430 * wmult), (int)(10 * hmult),
+ (int)(360 * wmult), (int)(460 * hmult)));
+ SoundGroup->setTitle( trUtf8( "Sound" ) );
+
+ NoSoundCheck = new QCheckBox( SoundGroup, "NoSoundCheck" );
+ NoSoundCheck->setGeometry( QRect((int)(11 * wmult), (int)(31 * hmult),
+ (int)(170 * wmult), (int)(31 * hmult)));
+ NoSoundCheck->setText( trUtf8( "No Sound" ) );
+
+ StreoCheck = new QCheckBox( SoundGroup, "StreoCheck" );
+ StreoCheck->setGeometry( QRect( (int)(195 * wmult), (int)(31 * hmult),
+ (int)(154 * wmult), (int)(31 * hmult)));
+ StreoCheck->setText( trUtf8( "Stereo" ) );
+
+ EnvxCheck = new QCheckBox( SoundGroup, "EnvxCheck" );
+ EnvxCheck->setGeometry( QRect((int)(11 * wmult), (int)(63 * hmult),
+ (int)(170 * wmult), (int)(31 * hmult)));
+ EnvxCheck->setText( trUtf8( "Envx" ) );
+
+ NoEchoCheck = new QCheckBox( SoundGroup, "NoEchoCheck" );
+ NoEchoCheck->setGeometry( QRect( (int)(195 * wmult), (int)(63 * hmult),
+ (int)(154 * wmult), (int)(31 * hmult)));
+ NoEchoCheck->setText( trUtf8( "No Echo" ) );
+
+ ThreadSoundCheck = new QCheckBox( SoundGroup, "ThreadSoundCheck" );
+ ThreadSoundCheck->setGeometry( QRect((int)(11 * wmult), (int)(95 * hmult),
+ (int)(170 * wmult), (int)(31 * hmult)));
+ ThreadSoundCheck->setText( trUtf8( "Threaded" ) );
+
+ SyncSoundCheck = new QCheckBox( SoundGroup, "SyncSoundCheck" );
+ SyncSoundCheck->setGeometry( QRect( (int)(195 * wmult), (int)(95 * hmult),
+ (int)(154 * wmult), (int)(31 * hmult)));
+ SyncSoundCheck->setText( trUtf8( "Synced" ) );
+
+ InterpSoundCheck = new QCheckBox( SoundGroup, "InterpSoundCheck" );
+ InterpSoundCheck->setGeometry( QRect((int)(11 * wmult), (int)(127 * hmult),
+ (int)(300 * wmult), (int)(31 * hmult)));
+ InterpSoundCheck->setText( trUtf8( "Interpolated" ) );
+
+ NoSampleCachingCheck = new QCheckBox( SoundGroup, "NoSampleCachingCheck" );
+ NoSampleCachingCheck->setGeometry( QRect((int)(11 * wmult), (int)(159 * hmult),
+ (int)(300 * wmult), (int)(31 * hmult)));
+ NoSampleCachingCheck->setText( trUtf8( "No sample caching" ) );
+
+ AltSampleDecodeCheck = new QCheckBox( SoundGroup, "AltSampleDecodeCheck" );
+ AltSampleDecodeCheck->setGeometry( QRect((int)(11 * wmult), (int)(191 * hmult),
+ (int)(300 * wmult), (int)(31 * hmult)));
+ AltSampleDecodeCheck->setText( trUtf8( "Alt sample decoding" ) );
+
+ NoMasterVolumeCheck = new QCheckBox( SoundGroup, "NoMasterVolumeCheck" );
+ NoMasterVolumeCheck->setGeometry( QRect((int)(11 * wmult), (int)(223 * hmult),
+ (int)(300 * wmult), (int)(31 * hmult)));
+ NoMasterVolumeCheck->setText( trUtf8( "No master volume" ) );
+
+ BufferCheck = new QCheckBox( SoundGroup, "BufferCheck" );
+ BufferCheck->setGeometry( QRect((int)(11 * wmult), (int)(255 * hmult),
+ (int)(300 * wmult), (int)(31 * hmult)));
+ BufferCheck->setText( trUtf8( "Set buffer size" ) );
+
+ BufferSizeSlider = new QSlider( SoundGroup, "BufferSizeSlider" );
+ BufferSizeSlider->setGeometry( QRect( (int)(120 * wmult), (int)(290 * hmult),
+ (int)(120 * wmult), (int)(31 * hmult) ) );
+ BufferSizeSlider->setMinValue( 0 );
+ BufferSizeSlider->setMaxValue( 32 );
+ BufferSizeSlider->setOrientation( QSlider::Horizontal );
+
+ BufferSizeLabel = new QLabel( SoundGroup, "BufferSizeLabel" );
+ BufferSizeLabel->setGeometry( QRect( (int)(20 * wmult), (int)(290 * hmult),
+ (int)(91 * wmult), (int)(31 * hmult)) );
+ BufferSizeLabel->setText( trUtf8( "(bytes)" ) );
+
+ BufferSizeValLabel = new QLabel( SoundGroup, "BufferSizeValLabel" );
+ BufferSizeValLabel->setGeometry( QRect( (int)(250 * wmult), (int)(290 * hmult),
+ (int)(100 * wmult), (int)(31 * hmult)));
+ BufferSizeValLabel->setText( trUtf8( "128" ) );
+
+ SoundSkipSlider = new QSlider( SoundGroup, "SoundSkipSlider" );
+ SoundSkipSlider->setGeometry( QRect( (int)(180 * wmult), (int)(330 * hmult),
+ (int)(120 * wmult), (int)(31 * hmult) ) );
+ SoundSkipSlider->setMinValue( 0 );
+ SoundSkipSlider->setMaxValue( 3 );
+ SoundSkipSlider->setOrientation( QSlider::Horizontal );
+
+ SoundSkipLabel = new QLabel( SoundGroup, "SoundSkipLabel" );
+ SoundSkipLabel->setGeometry( QRect( (int)(20 * wmult), (int)(330 * hmult),
+ (int)(151 * wmult), (int)(31 * hmult)) );
+ SoundSkipLabel->setText( trUtf8( "sound skip" ) );
+
+ SoundSkipValLabel = new QLabel( SoundGroup, "SoundSkipValLabel" );
+ SoundSkipValLabel->setGeometry( QRect( (int)(310 * wmult), (int)(330 * hmult),
+ (int)(40 * wmult), (int)(31 * hmult)));
+ SoundSkipValLabel->setText( trUtf8( "0" ) );
+
+ SoundQualitySlider = new QSlider( SoundGroup, "SoundQualitySlider" );
+ SoundQualitySlider->setGeometry( QRect( (int)(180 * wmult), (int)(370 * hmult),
+ (int)(120 * wmult), (int)(31 * hmult) ) );
+ SoundQualitySlider->setMinValue( 0 );
+ SoundQualitySlider->setMaxValue( 7 );
+ SoundQualitySlider->setOrientation( QSlider::Horizontal );
+
+ SoundQualityLabel = new QLabel( SoundGroup, "SoundQualityLabel" );
+ SoundQualityLabel->setGeometry( QRect( (int)(20 * wmult), (int)(370 * hmult),
+ (int)(151 * wmult), (int)(31 * hmult)) );
+ SoundQualityLabel->setText( trUtf8( "Quality" ) );
+
+ SoundQualityValLabel = new QLabel( SoundGroup, "SoundQualityValLabel" );
+ SoundQualityValLabel->setGeometry( QRect( (int)(310 * wmult), (int)(370 * hmult),
+ (int)(40 * wmult), (int)(31 * hmult)));
+ SoundQualityValLabel->setText( trUtf8( "4" ) );
+
+ SaveButton = new QPushButton( SettingsTab, "SaveButton" );
+ SaveButton->setGeometry( QRect( (int)(628 * wmult), (int)(513 * hmult),
+ (int)(151 * wmult), (int)(40 * hmult)));
+ SaveButton->setText( trUtf8( "Save" ) );
+
+ /*if(bSystem)
+ {
+ ListButton = new QPushButton( SettingsTab, "ListButton" );
+ ListButton->setGeometry( QRect( (int)(28 * wmult), (int)(513 * hmult),
+ (int)(250 * wmult), (int)(40 * hmult)));
+ ListButton->setText( trUtf8( "Reload Game List" ) );
+ connect(ListButton, SIGNAL(pressed()), this,
+ SLOT(loadList()));
+ }*/
+
+ if(!bSystem)
+ {
+ ScreenTab = new QWidget( SnesTab, "ScreenTab" );
+
+ ScreenPic = new QLabel( ScreenTab, "ScreenPic" );
+ ScreenPic->setEnabled( TRUE );
+ ScreenPic->setGeometry( QRect( 0, 0, screenwidth, screenheight ) );
+ ScreenPic->setScaledContents( TRUE );
+ SnesTab->insertTab( ScreenTab, trUtf8( "ScreenShot" ) );
+ }
+ else
+ {
+ SystemTab = new QWidget( SnesTab, "SystemTab" );
+ SnesTab->insertTab( SystemTab, trUtf8( "System" ) );
+
+ NoVerifyCheck = new QCheckBox( SystemTab, "NoVerifyCheck" );
+ NoVerifyCheck->setGeometry( QRect( (int)(100 * wmult), (int)(215 * hmult),
+ (int)(250 * wmult), (int)(31 * hmult)));
+ NoVerifyCheck->setText( trUtf8( "Don't verify Rom's" ) );
+
+ ListButton = new QPushButton( SystemTab, "ListButton" );
+ ListButton->setGeometry( QRect( (int)(100 * wmult), (int)(250 * hmult),
+ (int)(250 * wmult), (int)(40 * hmult)));
+ ListButton->setText( trUtf8( "Reload Game List" ) );
+ connect(ListButton, SIGNAL(pressed()), this,
+ SLOT(loadList()));
+ }
+
+ if(!bSystem)
+ {
+ connect(DefaultCheck, SIGNAL(stateChanged(int)), this,
+ SLOT(defaultUpdate(int)));
+ }
+ connect(SoundSkipSlider, SIGNAL(valueChanged(int)), SoundSkipValLabel,
+ SLOT(setNum(int)));
+ connect(SoundQualitySlider, SIGNAL(valueChanged(int)), SoundQualityValLabel,
+ SLOT(setNum(int)));
+ connect(BufferSizeSlider, SIGNAL(valueChanged(int)), this,
+ SLOT(setBufferSize(int)));
+ connect(SaveButton, SIGNAL(pressed()), this,
+ SLOT(accept()));
+ connect(BufferCheck, SIGNAL(stateChanged(int)), this,
+ SLOT(bufferCheckUpdate(int)));
+}
+
+/*
+ * Destroys the object and frees any allocated resources
+ */
+SnesSettingsDlg::~SnesSettingsDlg()
+{
+ // no need to delete child widgets, Qt does it all for us
+}
+
+int SnesSettingsDlg::Show(SnesGameSettings *settings)
+{
+ game_settings = settings;
+ TransCheck->setChecked(game_settings->transparency);
+ SixteenCheck->setChecked(game_settings->sixteen);
+ HiResCheck->setChecked(game_settings->hi_res);
+ NoModeSwitchCheck->setChecked(game_settings->no_mode_switch);
+ FullScreenCheck->setChecked(game_settings->full_screen);
+ StretchCheck->setChecked(game_settings->stretch);
+ NoSoundCheck->setChecked(game_settings->no_sound);
+ StreoCheck->setChecked(game_settings->stereo);
+ EnvxCheck->setChecked(game_settings->envx);
+ ThreadSoundCheck->setChecked(game_settings->thread_sound);
+ SyncSoundCheck->setChecked(game_settings->sound_sync);
+ InterpSoundCheck->setChecked(game_settings->interpolated_sound);
+ NoSampleCachingCheck->setChecked(game_settings->no_sample_caching);
+ AltSampleDecodeCheck->setChecked(game_settings->alt_sample_decode);
+ NoEchoCheck->setChecked(game_settings->no_echo);
+ NoMasterVolumeCheck->setChecked(game_settings->no_master_volume);
+ NoJoyCheck->setChecked(game_settings->no_joy);
+ InterleavedCheck->setChecked(game_settings->interleaved);
+ AltInterleavedCheck->setChecked(game_settings->alt_interleaved);
+ HiRomCheck->setChecked(game_settings->hi_rom);
+ LowRomCheck->setChecked(game_settings->low_rom);
+ HeaderCheck->setChecked(game_settings->header);
+ NoHeaderCheck->setChecked(game_settings->no_header);
+ NtscCheck->setChecked(game_settings->ntsc);
+ PalCheck->setChecked(game_settings->pal);
+ LayeringCheck->setChecked(game_settings->layering);
+ NoHdmaCheck->setChecked(game_settings->no_hdma);
+ NoSpeedHacksCheck->setChecked(game_settings->no_speed_hacks);
+ NoWindowsCheck->setChecked(game_settings->no_windows);
+ BufferCheck->setChecked((game_settings->buffer_size == 0)?false:true);
+ OptionsEdit->setText(game_settings->extra_options);
+ SoundSkipValLabel->setNum(int(game_settings->sound_skip));
+ SoundSkipSlider->setValue(game_settings->sound_skip);
+ SoundQualityValLabel->setNum(int(game_settings->sound_quality));
+ SoundQualitySlider->setValue(game_settings->sound_quality);
+ BufferSizeValLabel->setNum(int(game_settings->buffer_size));
+ BufferSizeSlider->setValue(game_settings->buffer_size);
+ InterpolateBox->setCurrentItem(game_settings->interpolate);
+ if(game_settings->buffer_size == 0)
+ {
+ BufferCheck->setChecked(false);
+ BufferSizeValLabel->setEnabled(false);
+ BufferSizeSlider->setEnabled(false);
+ BufferSizeLabel->setEnabled(false);
+ }
+ else
+ {
+ BufferCheck->setChecked(true);
+ BufferSizeValLabel->setEnabled(true);
+ BufferSizeSlider->setEnabled(true);
+ BufferSizeLabel->setEnabled(true);
+ }
+ if(!bSystem)
+ {
+ DefaultCheck->setChecked(game_settings->default_options);
+ }
+ showFullScreen();
+ setActiveWindow();
+ if(exec())
+ {
+ SaveSettings();
+ return SAVE_SETTINGS;
+ }
+ else
+ return DONT_SAVE_SETTINGS;
+}
+
+void SnesSettingsDlg::loadList()
+{
+ SnesHandler::getHandler()->processGames(!NoVerifyCheck->isChecked());
+}
+
+void SnesSettingsDlg::SaveSettings()
+{
+ if(!bSystem)
+ game_settings->default_options = DefaultCheck->isChecked();
+ game_settings->transparency = TransCheck->isChecked();
+ game_settings->sixteen = SixteenCheck->isChecked();
+ game_settings->hi_res = HiResCheck->isChecked();
+ game_settings->no_mode_switch = NoModeSwitchCheck->isChecked();
+ game_settings->full_screen = FullScreenCheck->isChecked();
+ game_settings->stretch = StretchCheck->isChecked();
+ game_settings->no_sound = NoSoundCheck->isChecked();
+ game_settings->stereo = StreoCheck->isChecked();
+ game_settings->envx = EnvxCheck->isChecked();
+ game_settings->thread_sound = ThreadSoundCheck->isChecked();
+ game_settings->sound_sync = SyncSoundCheck->isChecked();
+ game_settings->interpolated_sound = InterpSoundCheck->isChecked();
+ game_settings->no_sample_caching = NoSampleCachingCheck->isChecked();
+ game_settings->alt_sample_decode = AltSampleDecodeCheck->isChecked();
+ game_settings->no_echo = NoEchoCheck->isChecked();
+ game_settings->no_master_volume = NoMasterVolumeCheck->isChecked();
+ game_settings->no_joy = NoJoyCheck->isChecked();
+ game_settings->interleaved = InterleavedCheck->isChecked();
+ game_settings->alt_interleaved = AltInterleavedCheck->isChecked();
+ game_settings->hi_rom = HiRomCheck->isChecked();
+ game_settings->low_rom = LowRomCheck->isChecked();
+ game_settings->header = HeaderCheck->isChecked();
+ game_settings->no_header = NoHeaderCheck->isChecked();
+ game_settings->ntsc = NtscCheck->isChecked();
+ game_settings->pal = PalCheck->isChecked();
+ game_settings->layering = LayeringCheck->isChecked();
+ game_settings->no_hdma = NoHdmaCheck->isChecked();
+ game_settings->no_speed_hacks = NoSpeedHacksCheck->isChecked();
+ game_settings->no_windows = NoWindowsCheck->isChecked();
+ game_settings->extra_options = OptionsEdit->text();
+ game_settings->sound_skip = SoundSkipSlider->value();
+ game_settings->sound_quality = SoundQualitySlider->value();
+ game_settings->interpolate = InterpolateBox->currentItem();
+ if(BufferCheck->isChecked())
+ game_settings->buffer_size = BufferSizeSlider->value();
+ else
+ game_settings->buffer_size = 0;
+}
+
+void SnesSettingsDlg::defaultUpdate(int state)
+{
+ SettingsFrame->setEnabled(!state);
+ game_settings->default_options = state;
+}
+
+void SnesSettingsDlg::bufferCheckUpdate(int state)
+{
+ if(!state)
+ {
+ BufferSizeValLabel->setNum(int(0));
+ BufferSizeSlider->setValue(0);
+ }
+ BufferSizeValLabel->setEnabled(state);
+ BufferSizeSlider->setEnabled(state);
+ BufferSizeLabel->setEnabled(state);
+}
+
+void SnesSettingsDlg::setBufferSize(int buffer)
+{
+ BufferSizeValLabel->setNum(buffer * 128);
+}
+
+void SnesSettingsDlg::SetScreenshot(QString picfile)
+{
+ if(ScreenPic)
+ {
+ Screenshot.load(picfile);
+ ScaleImageLabel(Screenshot,ScreenPic);
+ ScreenPic->setPixmap(Screenshot);
+ }
+}
+
+void SnesSettingsDlg::ScaleImageLabel(QPixmap &pixmap, QLabel *label)
+{
+ int FrameWidth = width();
+ int FrameHeight = (int)(height() - 33 * hmult);
+ int ImageWidth = pixmap.width();
+ int ImageHeight = pixmap.height();
+ int x = 0, y = 0;
+ //QPoint test = label->mapToGlobal(QPoint(0,0));
+ if (float(ImageHeight)/float(ImageWidth) < float(FrameHeight)/float(FrameWidth))
+ {
+ int temp = ImageWidth;
+ ImageWidth = FrameWidth;
+ ImageHeight = (ImageWidth * ImageHeight) / temp;
+ y = (FrameHeight - ImageHeight) / 2;
+ }
+ else
+ {
+ int temp = ImageHeight;
+ ImageHeight = FrameHeight;
+ ImageWidth = (ImageHeight * ImageWidth) / temp;
+ x = (FrameWidth - ImageWidth) / 2;
+ }
+ label->setGeometry( QRect( x, y, ImageWidth, ImageHeight ) );
+}
+
View
113 mythplugins/mythgame/mythgame/snessettingsdlg.h
@@ -0,0 +1,113 @@
+#ifndef SNESSETTINGSDLG_H
+#define SNESSETTINGSDLG_H
+
+#include <qvariant.h>
+#include <qdialog.h>
+#include <qpixmap.h>
+#include "snesrominfo.h"
+
+class QVBoxLayout;
+class QHBoxLayout;
+class QGridLayout;
+class QCheckBox;
+class QComboBox;
+class QFrame;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QPushButton;
+class QSlider;
+class QTabWidget;
+class QWidget;
+class MythContext;
+
+class SnesSettingsDlg : public QDialog
+{
+ Q_OBJECT
+
+public:
+ SnesSettingsDlg(QWidget* parent = 0,
+ const char* name = 0, bool modal = FALSE,
+ bool system = false,WFlags fl = 0 );
+ ~SnesSettingsDlg();
+
+ QTabWidget* SnesTab;
+ QWidget* SettingsTab;
+ QPushButton* ListButton;
+ QFrame* SettingsFrame;
+ QGroupBox* DisplayGroup;
+ QGroupBox* MiscGroup;
+ QGroupBox* SoundGroup;
+ QCheckBox* TransCheck;
+ QCheckBox* SixteenCheck;
+ QCheckBox* HiResCheck;
+ QCheckBox* NoModeSwitchCheck;
+ QCheckBox* FullScreenCheck;
+ QCheckBox* StretchCheck;
+ QCheckBox* NoSoundCheck;
+ QCheckBox* StreoCheck;
+ QCheckBox* EnvxCheck;
+ QCheckBox* ThreadSoundCheck;
+ QCheckBox* SyncSoundCheck;
+ QCheckBox* InterpSoundCheck;
+ QCheckBox* NoSampleCachingCheck;
+ QCheckBox* AltSampleDecodeCheck;
+ QCheckBox* NoEchoCheck;
+ QCheckBox* NoMasterVolumeCheck;
+ QCheckBox* NoJoyCheck;
+ QCheckBox* InterleavedCheck;
+ QCheckBox* AltInterleavedCheck;
+ QCheckBox* HiRomCheck;
+ QCheckBox* LowRomCheck;
+ QCheckBox* HeaderCheck;
+ QCheckBox* NoHeaderCheck;
+ QCheckBox* NtscCheck;
+ QCheckBox* PalCheck;
+ QCheckBox* LayeringCheck;
+ QCheckBox* NoHdmaCheck;
+ QCheckBox* NoSpeedHacksCheck;
+ QCheckBox* NoWindowsCheck;
+ QCheckBox* BufferCheck;
+ QCheckBox* NoVerifyCheck;
+ QLineEdit* OptionsEdit;
+ QLabel* OptionsLabel;
+ QLabel* InterpolateLabel;
+ QComboBox* InterpolateBox;
+ QLabel* SoundSkipLabel;
+ QLabel* SoundSkipValLabel;
+ QSlider* SoundSkipSlider;
+ QLabel* SoundQualityLabel;
+ QLabel* SoundQualityValLabel;
+ QSlider* SoundQualitySlider;
+ QLabel* BufferSizeLabel;
+ QLabel* BufferSizeValLabel;
+ QSlider* BufferSizeSlider;
+ QPushButton* SaveButton;
+ QCheckBox* DefaultCheck;
+ QWidget* ScreenTab;
+ QLabel* ScreenPic;
+ QWidget* SystemTab;
+
+ void SetScreenshot(QString picfile);
+ int Show(SnesGameSettings *settings);
+
+protected slots:
+
+ void defaultUpdate(int);
+ void loadList();
+ void setBufferSize(int);
+ void bufferCheckUpdate(int);
+
+protected:
+
+ void SaveSettings();
+ void ScaleImageLabel(QPixmap &pixmap, QLabel *label);
+ SnesGameSettings *game_settings;
+ bool bSystem;
+ QPixmap Screenshot;
+
+private:
+ float wmult, hmult;
+};
+
+#endif // SNESSETTINGSDLG_H
Please sign in to comment.
Something went wrong with that request. Please try again.