2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
|
|
|
// SSSS tt ee ee ll ll aa
|
|
|
|
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
|
|
|
|
// SS SS tt ee ll ll aa aa
|
|
|
|
// SSSS ttt eeeee llll llll aaaaa
|
|
|
|
//
|
2009-01-01 18:13:40 +00:00
|
|
|
// Copyright (c) 1995-2009 by Bradford W. Mott and the Stella team
|
2001-12-27 19:54:36 +00:00
|
|
|
//
|
|
|
|
// See the file "license" for information on usage and redistribution of
|
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//
|
2009-05-13 13:55:40 +00:00
|
|
|
// $Id$
|
2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
|
Some configure work:
- removed TEXTURES_ARE_DIRTY logic, and just recreate the GL textures
when a screenmode changes
- enable checking for machine type and if nasm is available
- logic to enable scaler mode only when in OpenGL mode (still not complete
and defaults to off)
First pass at adding scaler code to OpenGL. Still much work TODO,
but the C version is working correctly (asm is causing crashes,
haven't figured out why). GL quad coordinates aren't properly
set yet, so the image always appears in the upper left corner, and
is not scaled to the window size. CPU usage is also quite high,
but I'm on a 1GHz laptop with i950 GL, so that may explain it.
Fixed long-standing bug in software rendering, where switching to a
lower-res screen while a message is being displayed would cause a
segfault.
Large refactoring of mainSDL. Specifically, OSystem now owns all
the subsystems except for Settings, taking responsibility for creating
and destroying them.
Properties fixes for 'Tomarc the Barbarian' and 'Gyruss'.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1136 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2006-10-22 18:58:46 +00:00
|
|
|
#include <sstream>
|
2009-06-08 16:50:14 +00:00
|
|
|
#include <map>
|
Some configure work:
- removed TEXTURES_ARE_DIRTY logic, and just recreate the GL textures
when a screenmode changes
- enable checking for machine type and if nasm is available
- logic to enable scaler mode only when in OpenGL mode (still not complete
and defaults to off)
First pass at adding scaler code to OpenGL. Still much work TODO,
but the C version is working correctly (asm is causing crashes,
haven't figured out why). GL quad coordinates aren't properly
set yet, so the image always appears in the upper left corner, and
is not scaled to the window size. CPU usage is also quite high,
but I'm on a 1GHz laptop with i950 GL, so that may explain it.
Fixed long-standing bug in software rendering, where switching to a
lower-res screen while a message is being displayed would cause a
segfault.
Large refactoring of mainSDL. Specifically, OSystem now owns all
the subsystems except for Settings, taking responsibility for creating
and destroying them.
Properties fixes for 'Tomarc the Barbarian' and 'Gyruss'.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1136 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2006-10-22 18:58:46 +00:00
|
|
|
|
2007-09-03 18:37:24 +00:00
|
|
|
#include "bspf.hxx"
|
|
|
|
|
2006-03-05 01:18:42 +00:00
|
|
|
#include "DefProps.hxx"
|
2007-09-03 18:37:24 +00:00
|
|
|
#include "OSystem.hxx"
|
2001-12-27 19:54:36 +00:00
|
|
|
#include "Props.hxx"
|
2007-09-03 18:37:24 +00:00
|
|
|
#include "Settings.hxx"
|
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
#include "PropsSet.hxx"
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2006-03-19 00:46:04 +00:00
|
|
|
PropertiesSet::PropertiesSet(OSystem* osystem)
|
|
|
|
: myOSystem(osystem),
|
2006-03-03 19:58:35 +00:00
|
|
|
mySize(0)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2007-07-19 16:21:39 +00:00
|
|
|
const string& props = myOSystem->propertiesFile();
|
2009-06-08 16:50:14 +00:00
|
|
|
load(props);
|
|
|
|
}
|
Some configure work:
- removed TEXTURES_ARE_DIRTY logic, and just recreate the GL textures
when a screenmode changes
- enable checking for machine type and if nasm is available
- logic to enable scaler mode only when in OpenGL mode (still not complete
and defaults to off)
First pass at adding scaler code to OpenGL. Still much work TODO,
but the C version is working correctly (asm is causing crashes,
haven't figured out why). GL quad coordinates aren't properly
set yet, so the image always appears in the upper left corner, and
is not scaled to the window size. CPU usage is also quite high,
but I'm on a 1GHz laptop with i950 GL, so that may explain it.
Fixed long-standing bug in software rendering, where switching to a
lower-res screen while a message is being displayed would cause a
segfault.
Large refactoring of mainSDL. Specifically, OSystem now owns all
the subsystems except for Settings, taking responsibility for creating
and destroying them.
Properties fixes for 'Tomarc the Barbarian' and 'Gyruss'.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1136 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2006-10-22 18:58:46 +00:00
|
|
|
|
2009-06-08 16:50:14 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
PropertiesSet::~PropertiesSet()
|
|
|
|
{
|
|
|
|
myExternalProps.clear();
|
|
|
|
myTempProps.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void PropertiesSet::load(const string& filename)
|
|
|
|
{
|
Some configure work:
- removed TEXTURES_ARE_DIRTY logic, and just recreate the GL textures
when a screenmode changes
- enable checking for machine type and if nasm is available
- logic to enable scaler mode only when in OpenGL mode (still not complete
and defaults to off)
First pass at adding scaler code to OpenGL. Still much work TODO,
but the C version is working correctly (asm is causing crashes,
haven't figured out why). GL quad coordinates aren't properly
set yet, so the image always appears in the upper left corner, and
is not scaled to the window size. CPU usage is also quite high,
but I'm on a 1GHz laptop with i950 GL, so that may explain it.
Fixed long-standing bug in software rendering, where switching to a
lower-res screen while a message is being displayed would cause a
segfault.
Large refactoring of mainSDL. Specifically, OSystem now owns all
the subsystems except for Settings, taking responsibility for creating
and destroying them.
Properties fixes for 'Tomarc the Barbarian' and 'Gyruss'.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1136 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2006-10-22 18:58:46 +00:00
|
|
|
if(myOSystem->settings().getBool("showinfo"))
|
2009-06-08 16:50:14 +00:00
|
|
|
cout << "User game properties: \'" << filename << "\'\n";
|
|
|
|
|
|
|
|
ifstream in(filename.c_str(), ios::in);
|
|
|
|
|
|
|
|
// Loop reading properties
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
// Make sure the stream is still good or we're done
|
|
|
|
if(!in)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Get the property list associated with this profile
|
|
|
|
Properties prop;
|
|
|
|
prop.load(in);
|
|
|
|
|
|
|
|
// If the stream is still good then insert the properties
|
|
|
|
if(in)
|
|
|
|
insert(prop);
|
|
|
|
}
|
|
|
|
if(in)
|
|
|
|
in.close();
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-06-08 16:50:14 +00:00
|
|
|
bool PropertiesSet::save(const string& filename) const
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
ofstream out(filename.c_str(), ios::out);
|
|
|
|
if(!out)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Only save those entries in the external list
|
|
|
|
for(PropsList::const_iterator i = myExternalProps.begin();
|
|
|
|
i != myExternalProps.end(); ++i)
|
|
|
|
i->second.save(out);
|
|
|
|
|
|
|
|
return true;
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-06-17 17:04:55 +00:00
|
|
|
bool PropertiesSet::getMD5(const string& md5, Properties& properties,
|
2006-12-01 18:30:21 +00:00
|
|
|
bool useDefaults) const
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2006-03-05 01:18:42 +00:00
|
|
|
properties.setDefaults();
|
2002-01-08 17:11:32 +00:00
|
|
|
bool found = false;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2009-06-08 16:50:14 +00:00
|
|
|
// There are three lists to search when looking for a properties entry,
|
|
|
|
// which must be done in the following order
|
|
|
|
// If 'useDefaults' is specified, only use the built-in list
|
|
|
|
//
|
|
|
|
// 'save': entries previously inserted that are saved on program exit
|
|
|
|
// 'temp': entries previously inserted that are discarded
|
|
|
|
// 'builtin': the defaults compiled into the program
|
|
|
|
|
|
|
|
// First check properties from external file
|
|
|
|
if(!useDefaults)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
// Check external list
|
|
|
|
PropsList::const_iterator iter = myExternalProps.find(md5);
|
|
|
|
if(iter != myExternalProps.end())
|
|
|
|
{
|
|
|
|
properties = iter->second;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
else // Search temp list
|
2006-03-05 01:18:42 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
iter = myTempProps.find(md5);
|
|
|
|
if(iter != myTempProps.end())
|
2006-03-05 01:18:42 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
properties = iter->second;
|
|
|
|
found = true;
|
2006-03-05 01:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-16 02:14:25 +00:00
|
|
|
}
|
2005-09-11 22:55:51 +00:00
|
|
|
|
2007-04-09 18:12:40 +00:00
|
|
|
// Otherwise, search the internal database using binary search
|
2006-03-05 01:18:42 +00:00
|
|
|
if(!found)
|
|
|
|
{
|
2007-07-31 15:46:21 +00:00
|
|
|
int low = 0, high = DEF_PROPS_SIZE - 1;
|
2007-04-09 18:12:40 +00:00
|
|
|
while(low <= high)
|
2006-03-05 01:18:42 +00:00
|
|
|
{
|
2007-04-09 18:12:40 +00:00
|
|
|
int i = (low + high) / 2;
|
2006-03-05 01:18:42 +00:00
|
|
|
int cmp = strncmp(md5.c_str(), DefProps[i][Cartridge_MD5], 32);
|
2007-04-09 18:12:40 +00:00
|
|
|
|
|
|
|
if(cmp == 0) // found it
|
2006-03-05 01:18:42 +00:00
|
|
|
{
|
|
|
|
for(int p = 0; p < LastPropType; ++p)
|
2006-03-19 00:46:04 +00:00
|
|
|
if(DefProps[i][p][0] != 0)
|
2006-03-05 01:18:42 +00:00
|
|
|
properties.set((PropertyType)p, DefProps[i][p]);
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(cmp < 0)
|
2007-04-09 18:12:40 +00:00
|
|
|
high = i - 1; // look at lower range
|
2006-03-05 01:18:42 +00:00
|
|
|
else
|
2007-04-09 18:12:40 +00:00
|
|
|
low = i + 1; // look at upper range
|
2006-03-05 01:18:42 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-17 17:04:55 +00:00
|
|
|
|
|
|
|
return found;
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2005-09-16 18:15:44 +00:00
|
|
|
void PropertiesSet::insert(const Properties& properties, bool save)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
// Note that the following code is optimized for insertion when an item
|
|
|
|
// doesn't already exist, and when the external properties file is
|
|
|
|
// relatively small (which is the case with current versions of Stella,
|
|
|
|
// as the properties are built-in)
|
|
|
|
// If an item does exist, it will be removed and insertion done again
|
|
|
|
// This shouldn't be a speed issue, as insertions will only fail with
|
|
|
|
// duplicates when you're changing the current ROM properties, which
|
|
|
|
// most people tend not to do
|
|
|
|
|
2007-09-06 02:15:00 +00:00
|
|
|
// Since the PropSet is keyed by md5, we can't insert without a valid one
|
2009-06-08 16:50:14 +00:00
|
|
|
const string& md5 = properties.get(Cartridge_MD5);
|
|
|
|
if(md5 == "")
|
2007-09-06 02:15:00 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-08 16:50:14 +00:00
|
|
|
// The status of 'save' determines which list to save to
|
|
|
|
PropsList& list = save ? myExternalProps : myTempProps;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2009-06-08 16:50:14 +00:00
|
|
|
pair<PropsList::iterator,bool> ret;
|
|
|
|
ret = list.insert(make_pair(md5, properties));
|
|
|
|
if(ret.second == false)
|
2002-01-08 17:11:32 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
// Remove old item and insert again
|
|
|
|
list.erase(ret.first);
|
|
|
|
list.insert(make_pair(md5, properties));
|
2002-01-08 17:11:32 +00:00
|
|
|
}
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2009-06-08 16:50:14 +00:00
|
|
|
void PropertiesSet::removeMD5(const string& md5)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
// We only remove from the external list
|
|
|
|
myExternalProps.erase(md5);
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 00:53:48 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2006-12-01 18:30:21 +00:00
|
|
|
void PropertiesSet::print() const
|
2004-07-05 00:53:48 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
// We only look at the external properties and the built-in ones;
|
|
|
|
// the temp properties are ignored
|
|
|
|
// Also, any properties entries in the external file override the built-in
|
|
|
|
// ones
|
|
|
|
// The easiest way to merge the lists is to create another temporary one
|
|
|
|
// This isn't fast, but I suspect this method isn't used too often (or at all)
|
|
|
|
|
|
|
|
PropsList list;
|
|
|
|
|
|
|
|
// First insert all external props
|
|
|
|
list = myExternalProps;
|
|
|
|
|
|
|
|
// Now insert all the built-in ones
|
|
|
|
// Note that if we try to insert a duplicate, the insertion will fail
|
|
|
|
// This is fine, since a duplicate in the built-in list means it should
|
|
|
|
// be overrided anyway (and insertion shouldn't be done)
|
|
|
|
Properties properties;
|
|
|
|
for(int i = 0; i < DEF_PROPS_SIZE; ++i)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2009-06-08 16:50:14 +00:00
|
|
|
properties.setDefaults();
|
|
|
|
for(int p = 0; p < LastPropType; ++p)
|
|
|
|
if(DefProps[i][p][0] != 0)
|
|
|
|
properties.set((PropertyType)p, DefProps[i][p]);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2009-06-08 16:50:14 +00:00
|
|
|
list.insert(make_pair(DefProps[i][Cartridge_MD5], properties));
|
2004-07-05 00:53:48 +00:00
|
|
|
}
|
|
|
|
|
2009-06-08 16:50:14 +00:00
|
|
|
// Now, print the resulting list
|
|
|
|
for(PropsList::const_iterator i = list.begin(); i != list.end(); ++i)
|
|
|
|
i->second.print();
|
2002-01-08 17:11:32 +00:00
|
|
|
}
|