Handle conflicting sysregions
This commit is contained in:
parent
f6102a69ae
commit
bb48143284
8 changed files with 30 additions and 17 deletions
|
@ -26,10 +26,11 @@ struct moviefile
|
||||||
* This constructor loads a movie/savestate file and fills structure accordingly.
|
* This constructor loads a movie/savestate file and fills structure accordingly.
|
||||||
*
|
*
|
||||||
* parameter filename: The file to load.
|
* parameter filename: The file to load.
|
||||||
|
* parameter romtype: Type of ROM.
|
||||||
* throws std::bad_alloc: Not enough memory.
|
* throws std::bad_alloc: Not enough memory.
|
||||||
* throws std::runtime_error: Can't load the movie file
|
* throws std::runtime_error: Can't load the movie file
|
||||||
*/
|
*/
|
||||||
moviefile(const std::string& filename) throw(std::bad_alloc, std::runtime_error);
|
moviefile(const std::string& filename, core_type& romtype) throw(std::bad_alloc, std::runtime_error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads this movie structure and saves it into file.
|
* Reads this movie structure and saves it into file.
|
||||||
|
|
|
@ -203,6 +203,7 @@ public:
|
||||||
const std::string& get_hname();
|
const std::string& get_hname();
|
||||||
const std::list<std::string>& get_extensions();
|
const std::list<std::string>& get_extensions();
|
||||||
bool is_known_extension(const std::string& ext);
|
bool is_known_extension(const std::string& ext);
|
||||||
|
core_sysregion& lookup_sysregion(const std::string& sysreg);
|
||||||
std::string get_biosname();
|
std::string get_biosname();
|
||||||
unsigned get_id();
|
unsigned get_id();
|
||||||
unsigned get_image_count();
|
unsigned get_image_count();
|
||||||
|
@ -267,7 +268,7 @@ struct core_sysregion
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
core_sysregion(const std::string& name, core_type& type, core_region& region);
|
core_sysregion(const std::string& name, core_type& type, core_region& region);
|
||||||
static core_sysregion& lookup(const std::string& name);
|
~core_sysregion() throw();
|
||||||
const std::string& get_name();
|
const std::string& get_name();
|
||||||
core_region& get_region();
|
core_region& get_region();
|
||||||
core_type& get_type();
|
core_type& get_type();
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace
|
||||||
|
|
||||||
void refresh_cart_mappings() throw(std::bad_alloc)
|
void refresh_cart_mappings() throw(std::bad_alloc)
|
||||||
{
|
{
|
||||||
if(!get_current_rom_info().first)
|
if(!our_rom || !our_rom->rtype)
|
||||||
return;
|
return;
|
||||||
std::list<memory_region*> cur_regions = lsnes_memory.get_regions();
|
std::list<memory_region*> cur_regions = lsnes_memory.get_regions();
|
||||||
std::list<memory_region*> regions;
|
std::list<memory_region*> regions;
|
||||||
|
|
|
@ -442,7 +442,7 @@ bool do_load_state(const std::string& filename, int lmode)
|
||||||
lua_callback_pre_load(filename2);
|
lua_callback_pre_load(filename2);
|
||||||
struct moviefile mfile;
|
struct moviefile mfile;
|
||||||
try {
|
try {
|
||||||
mfile = moviefile(filename2);
|
mfile = moviefile(filename2, *our_rom->rtype);
|
||||||
} catch(std::bad_alloc& e) {
|
} catch(std::bad_alloc& e) {
|
||||||
OOM_panic();
|
OOM_panic();
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
|
|
|
@ -373,7 +373,7 @@ moviefile::moviefile() throw(std::bad_alloc)
|
||||||
poll_flag = 0;
|
poll_flag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
moviefile::moviefile(const std::string& movie) throw(std::bad_alloc, std::runtime_error)
|
moviefile::moviefile(const std::string& movie, core_type& romtype) throw(std::bad_alloc, std::runtime_error)
|
||||||
{
|
{
|
||||||
poll_flag = false;
|
poll_flag = false;
|
||||||
start_paused = false;
|
start_paused = false;
|
||||||
|
@ -390,7 +390,7 @@ moviefile::moviefile(const std::string& movie) throw(std::bad_alloc, std::runtim
|
||||||
throw std::runtime_error("Can't decode movie data");
|
throw std::runtime_error("Can't decode movie data");
|
||||||
read_linefile(r, "gametype", tmp);
|
read_linefile(r, "gametype", tmp);
|
||||||
try {
|
try {
|
||||||
gametype = &core_sysregion::lookup(tmp);
|
gametype = &romtype.lookup_sysregion(tmp);
|
||||||
} catch(std::bad_alloc& e) {
|
} catch(std::bad_alloc& e) {
|
||||||
throw;
|
throw;
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
|
|
|
@ -21,9 +21,9 @@ namespace
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, core_sysregion*>& sysregions()
|
std::multimap<std::string, core_sysregion*>& sysregions()
|
||||||
{
|
{
|
||||||
static std::map<std::string, core_sysregion*> x;
|
static std::multimap<std::string, core_sysregion*> x;
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,15 +281,24 @@ std::set<std::string> core_type::srams()
|
||||||
core_sysregion::core_sysregion(const std::string& _name, core_type& _type, core_region& _region)
|
core_sysregion::core_sysregion(const std::string& _name, core_type& _type, core_region& _region)
|
||||||
: name(_name), type(_type), region(_region)
|
: name(_name), type(_type), region(_region)
|
||||||
{
|
{
|
||||||
sysregions()[_name] = this;
|
sysregions().insert(std::make_pair(_name, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
core_sysregion& core_sysregion::lookup(const std::string& _name)
|
core_sysregion::~core_sysregion() throw()
|
||||||
{
|
{
|
||||||
if(sysregions().count(_name))
|
for(auto i = sysregions().begin(); i != sysregions().end(); i++)
|
||||||
return *(sysregions()[_name]);
|
if(i->second == this) {
|
||||||
else
|
sysregions().erase(i);
|
||||||
throw std::runtime_error("Bad system-region type");
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core_sysregion& core_type::lookup_sysregion(const std::string& sysreg)
|
||||||
|
{
|
||||||
|
for(auto i : sysregions())
|
||||||
|
if(i.first == sysreg && &i.second->get_type() == this)
|
||||||
|
return *i.second;
|
||||||
|
throw std::runtime_error("Bad system-region type");
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& core_sysregion::get_name()
|
const std::string& core_sysregion::get_name()
|
||||||
|
@ -483,4 +492,4 @@ emucore_callbacks::~emucore_callbacks() throw()
|
||||||
|
|
||||||
struct emucore_callbacks* ecore_callbacks;
|
struct emucore_callbacks* ecore_callbacks;
|
||||||
|
|
||||||
bool new_core_flag = false;
|
bool new_core_flag = false;
|
||||||
|
|
|
@ -495,7 +495,9 @@ bool lsnes_app::OnInit()
|
||||||
moviefile* mov = NULL;
|
moviefile* mov = NULL;
|
||||||
if(c_file != "")
|
if(c_file != "")
|
||||||
try {
|
try {
|
||||||
mov = new moviefile(c_file);
|
if(!rom)
|
||||||
|
throw std::runtime_error("No ROM loaded");
|
||||||
|
mov = new moviefile(c_file, *rom->rtype);
|
||||||
if(c_rom != "")
|
if(c_rom != "")
|
||||||
rom->load(mov->settings, mov->movie_rtc_second, mov->movie_rtc_subsecond);
|
rom->load(mov->settings, mov->movie_rtc_second, mov->movie_rtc_subsecond);
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
|
|
|
@ -294,7 +294,7 @@ int main(int argc, char** argv)
|
||||||
if(i->length() > 0 && (*i)[0] != '-') {
|
if(i->length() > 0 && (*i)[0] != '-') {
|
||||||
try {
|
try {
|
||||||
tried = true;
|
tried = true;
|
||||||
movie = moviefile(*i);
|
movie = moviefile(*i, *r.rtype);
|
||||||
loaded = true;
|
loaded = true;
|
||||||
} catch(std::bad_alloc& e) {
|
} catch(std::bad_alloc& e) {
|
||||||
OOM_panic();
|
OOM_panic();
|
||||||
|
|
Loading…
Add table
Reference in a new issue