Permalink
Browse files

Add zip support. Thanks to Nach.

git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@50 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24
  • Loading branch information...
1 parent e88878f commit f3b412cefe50002e145224d8fc1a62a4e17929cd sinamas committed Aug 30, 2007
View
@@ -8,3 +8,9 @@ echo "cd gambatte_sdl && scons -c"
echo "cd libgambatte && scons -c"
(cd libgambatte && scons -c)
+
+echo "rm -f *gambatte*/config.log"
+rm -f *gambatte*/config.log
+
+echo "rm -rf *gambatte*/.scon*"
+rm -rf *gambatte*/.scon*
@@ -142,7 +142,7 @@ GambatteQt::~GambatteQt() {
void GambatteQt::open() {
pause();
- QString fileName = QFileDialog::getOpenFileName(this, "Open", recentFileActs[0]->data().toString(), "Game Boy ROM images (*.gb *.gbc *.sgb);;All files (*)");
+ QString fileName = QFileDialog::getOpenFileName(this, "Open", recentFileActs[0]->data().toString(), "Game Boy ROM images (*.dmg *.gb *.gbc *.sgb *.zip);;All files (*)");
if (!fileName.isEmpty())
loadFile(fileName);
@@ -162,7 +162,7 @@ void GambatteQt::about() {
this,
tr("About Gambatte"),
tr("<h3>Gambatte Qt svn</h3>\
- <p><b>Author:</b> Sindre Aamås (<a href=\"mailto:aamas@stud.ntnu.no\">aamas@stud.ntnu.no</a>).<br>\
+ <p><b>Author:</b> Sindre Aam�s (<a href=\"mailto:aamas@stud.ntnu.no\">aamas@stud.ntnu.no</a>).<br>\
<b>Homepage:</b> <a href=\"http://sourceforge.net/projects/gambatte\">http://sourceforge.net/projects/gambatte</a>.</p>\
<p>Gambatte is an accuracy-focused, open-source, cross-platform Game Boy / Game Boy Color emulator written in C++. It is based on hundreds of corner case hardware tests, as well as previous documentation and reverse engineering efforts.</p>")
);
View
@@ -35,7 +35,7 @@ CONFIG += warn_on \
QT += opengl
TARGET = ../bin/gambatte_qt
INCLUDEPATH += ../../libgambatte/include
-LIBS += -L../../libgambatte -lgambatte
+LIBS += -L../../libgambatte -lgambatte -lz
unix {
DEFINES += PLATFORM_UNIX
View
@@ -1,7 +1,8 @@
env = Environment(CPPPATH = ['src', '../libgambatte/include'],
LIBS = ['gambatte'],
LIBPATH = '../libgambatte',
- CPPFLAGS = ARGUMENTS.get('CPPFLAGS', '-Wall -O2 -fno-exceptions -fno-rtti -fomit-frame-pointer'))
+ CFLAGS = ARGUMENTS.get('CFLAGS', '-Wall -O2 -fomit-frame-pointer'),
+ CXXFLAGS = ARGUMENTS.get('CXXFLAGS', ARGUMENTS.get('CFLAGS', '-Wall -O2 -fomit-frame-pointer') + ' -fno-exceptions -fno-rtti'))
env.ParseConfig('sdl-config --cflags --libs')
@@ -11,4 +12,11 @@ sourceFiles = Split('''
src/syncfunc.cpp
''')
+conf = env.Configure()
+
+if conf.CheckLib('z'):
+ env.Append(LIBS = ['z'])
+
+conf.Finish()
+
env.Program('gambatte_sdl', sourceFiles)
View
@@ -1,9 +1,10 @@
env = Environment(CPPPATH = ['src', 'include'],
- CPPFLAGS = ARGUMENTS.get('CPPFLAGS', '-Wall -O2 -fno-exceptions -fno-rtti -fomit-frame-pointer'))
+ CFLAGS = ARGUMENTS.get('CFLAGS', '-Wall -O2 -fomit-frame-pointer'),
+ CXXFLAGS = ARGUMENTS.get('CXXFLAGS', ARGUMENTS.get('CFLAGS', '-Wall -O2 -fomit-frame-pointer') + ' -fno-exceptions -fno-rtti'))
sourceFiles = Split('''
- src/gambatte.cpp
src/cpu.cpp
+ src/gambatte.cpp
src/interrupter.cpp
src/memory.cpp
src/rtc.cpp
@@ -40,4 +41,15 @@ sourceFiles = Split('''
src/video/filters/maxsthq2x.cpp
''')
+conf = env.Configure()
+
+if conf.CheckHeader('zlib.h') and conf.CheckLib('z'):
+ sourceFiles.append('src/file/unzip/unzip.c')
+ sourceFiles.append('src/file/unzip/ioapi.c')
+ sourceFiles.append('src/file/file_zip.cpp')
+else:
+ sourceFiles.append('src/file/file.cpp')
+
+conf.Finish()
+
env.Library('gambatte', sourceFiles)
@@ -0,0 +1,83 @@
+/***************************************************************************
+Copyright (C) 2007 by Nach
+http://nsrt.edgeemu.com
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License version 2 for more details.
+
+You should have received a copy of the GNU General Public License
+version 2 along with this program; if not, write to the
+Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+***************************************************************************/
+
+#include "file.h"
+
+using namespace std;
+
+static const unsigned int MAX_FILE_NAME = 512;
+
+File::File(const char *filename) : stream(filename, ios::in | ios::binary), is_zip(false), fsize(0), count(0)
+{
+ if (stream)
+ {
+ stream.seekg(0, ios::end);
+ fsize = stream.tellg();
+ stream.seekg(0, ios::beg);
+ }
+}
+
+File::~File()
+{
+ close();
+}
+
+void File::rewind()
+{
+ if (is_open())
+ {
+ stream.seekg(0, ios::beg);
+ }
+}
+
+bool File::is_open()
+{
+ return(stream.is_open());
+}
+
+void File::close()
+{
+ if (is_open())
+ {
+ stream.close();
+ }
+}
+
+void File::read(char *buffer, size_t amount)
+{
+ if (is_open())
+ {
+ stream.read(buffer, amount);
+ count = stream.gcount();
+ }
+ else
+ {
+ count = 0;
+ }
+}
+
+size_t File::size()
+{
+ return(fsize);
+}
+
+size_t File::gcount()
+{
+ return(count);
+}
@@ -0,0 +1,41 @@
+/***************************************************************************
+Copyright (C) 2007 by Nach
+http://nsrt.edgeemu.com
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License version 2 for more details.
+
+You should have received a copy of the GNU General Public License
+version 2 along with this program; if not, write to the
+Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+***************************************************************************/
+
+#include <fstream>
+
+class File {
+ private:
+ std::ifstream stream;
+ bool is_zip; //Change this to an enum later
+ size_t fsize, count;
+ void *zipfile;
+ bool zip_sub_open;
+
+ void zip(const char *filename);
+
+ public:
+ File(const char *filename);
+ ~File();
+ void rewind();
+ bool is_open();
+ void close();
+ size_t size();
+ void read(char *buffer, size_t amount);
+ size_t gcount();
+};
@@ -0,0 +1,175 @@
+/***************************************************************************
+Copyright (C) 2007 by Nach
+http://nsrt.edgeemu.com
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License version 2 for more details.
+
+You should have received a copy of the GNU General Public License
+version 2 along with this program; if not, write to the
+Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+***************************************************************************/
+
+#include "file.h"
+
+namespace zlib {
+#include "unzip/unzip.h"
+}
+
+using namespace std;
+using namespace zlib;
+
+static const unsigned int MAX_FILE_NAME = 512;
+
+File::File(const char *filename) : stream(filename, ios::in | ios::binary), is_zip(false), fsize(0), count(0)
+{
+ if (stream)
+ {
+ char temp[4];
+ stream.read(temp, sizeof(temp));
+
+ //check for standard zip 'magic number'
+ if ((temp[0] == 'P') && (temp[1] == 'K') && (temp[2] == 3) && (temp[3] == 4))
+ {
+ stream.close();
+ is_zip = true;
+ zip(filename);
+ }
+ else
+ {
+ stream.seekg(0, ios::end);
+ fsize = stream.tellg();
+ stream.seekg(0, ios::beg);
+ }
+ }
+}
+
+void File::zip(const char *filename)
+{
+ zipfile = unzOpen(filename);
+ if (zipfile)
+ {
+ zip_sub_open = false;
+
+ unz_file_info cFileInfo;
+ char ourFile[MAX_FILE_NAME] = { '\n' };
+
+ for (int cFile = unzGoToFirstFile((unzFile)zipfile); cFile == UNZ_OK; cFile = unzGoToNextFile((unzFile)zipfile))
+ {
+ //Temporary char array for file name
+ char cFileName[MAX_FILE_NAME];
+
+ //Gets info on current file, and places it in cFileInfo
+ unzGetCurrentFileInfo((unzFile)zipfile, &cFileInfo, cFileName, MAX_FILE_NAME, 0, 0, 0, 0);
+
+ //Check for largest file which should be the ROM
+ if ((size_t)cFileInfo.uncompressed_size > fsize)
+ {
+ strcpy(ourFile, cFileName);
+ fsize = (size_t)cFileInfo.uncompressed_size;
+ }
+ }
+
+ if (ourFile[0] != '\n')
+ {
+ //Sets current file to the file we liked before
+ unzLocateFile((unzFile)zipfile, ourFile, 1);
+
+ if (unzOpenCurrentFile((unzFile)zipfile) == UNZ_OK)
+ {
+ zip_sub_open = true;
+ }
+ }
+
+ if (!zip_sub_open)
+ {
+ unzClose((unzFile)zipfile);
+ zipfile = 0;
+ }
+ }
+}
+
+File::~File()
+{
+ close();
+}
+
+void File::rewind()
+{
+ if (is_open())
+ {
+ if (!is_zip)
+ {
+ stream.seekg(0, ios::beg);
+ }
+ else
+ {
+ unzCloseCurrentFile((unzFile)zipfile);
+ unzOpenCurrentFile((unzFile)zipfile);
+ }
+ }
+}
+
+bool File::is_open()
+{
+ if (!is_zip)
+ {
+ return(stream.is_open());
+ }
+ return(zipfile && zip_sub_open);
+}
+
+void File::close()
+{
+ if (is_open())
+ {
+ if (!is_zip)
+ {
+ stream.close();
+ }
+ else
+ {
+ unzOpenCurrentFile((unzFile)zipfile);
+ unzClose((unzFile)zipfile);
+ zipfile = 0;
+ zip_sub_open = false;
+ }
+ }
+}
+
+void File::read(char *buffer, size_t amount)
+{
+ if (is_open())
+ {
+ if (!is_zip)
+ {
+ stream.read(buffer, amount);
+ count = stream.gcount();
+ }
+ else
+ {
+ count = (size_t)unzReadCurrentFile((unzFile)zipfile, buffer, amount);
+ }
+ }
+ else
+ {
+ count = 0;
+ }
+}
+
+size_t File::size()
+{
+ return(fsize);
+}
+
+size_t File::gcount()
+{
+ return(count);
+}
Oops, something went wrong.

0 comments on commit f3b412c

Please sign in to comment.