Added support for gzip'ed ROMs.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1330 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2007-07-24 12:43:14 +00:00
parent 9f2a046e11
commit 2ff9f25576
1 changed files with 11 additions and 10 deletions

View File

@ -13,12 +13,13 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: OSystem.cxx,v 1.98 2007-07-19 16:21:39 stephena Exp $ // $Id: OSystem.cxx,v 1.99 2007-07-24 12:43:14 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <zlib.h>
#include "MediaFactory.hxx" #include "MediaFactory.hxx"
@ -46,6 +47,8 @@
#include "OSystem.hxx" #include "OSystem.hxx"
#include "Widget.hxx" #include "Widget.hxx"
#define MAX_ROM_SIZE 512 * 1024
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OSystem::OSystem() OSystem::OSystem()
: myEventHandler(NULL), : myEventHandler(NULL),
@ -453,7 +456,7 @@ void OSystem::createLauncher()
bool OSystem::openROM(const string& rom, string& md5, uInt8** image, int* size) bool OSystem::openROM(const string& rom, string& md5, uInt8** image, int* size)
{ {
// Try to open the file as a zipped archive // Try to open the file as a zipped archive
// If that fails, we assume it's just a normal data file // If that fails, we assume it's just a gzipped or normal data file
unzFile tz; unzFile tz;
if((tz = unzOpen(rom.c_str())) != NULL) if((tz = unzOpen(rom.c_str())) != NULL)
{ {
@ -509,16 +512,14 @@ bool OSystem::openROM(const string& rom, string& md5, uInt8** image, int* size)
} }
else else
{ {
ifstream in(rom.c_str(), ios_base::binary); // Assume the file is either gzip'ed or not compressed at all
if(!in) gzFile f = gzopen(rom.c_str(), "rb");
if(!f)
return false; return false;
in.seekg(0, ios::end); *image = new uInt8[MAX_ROM_SIZE];
*size = (int)in.tellg(); *size = gzread(f, *image, MAX_ROM_SIZE);
in.seekg(0, ios::beg); gzclose(f);
*image = new uInt8[*size];
in.read((char*)(*image), *size);
in.close();
} }
// If we get to this point, we know we have a valid file to open // If we get to this point, we know we have a valid file to open