Handle conflicting sysregions

This commit is contained in:
Ilari Liusvaara 2013-01-11 22:31:13 +02:00
parent f6102a69ae
commit bb48143284
8 changed files with 30 additions and 17 deletions

View file

@ -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.

View 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();

View file

@ -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;

View file

@ -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) {

View file

@ -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) {

View file

@ -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()

View file

@ -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) {

View file

@ -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();