Merge branch 'rr1-maint' into rr1-gambatte

This commit is contained in:
Ilari Liusvaara 2012-07-15 13:39:42 +03:00
commit c4ea2ca321
6 changed files with 68 additions and 29 deletions

View file

@ -14,7 +14,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
#include <set> #include <list>
/** /**
* For now, reserve 23 bytes, for: * For now, reserve 23 bytes, for:
@ -156,7 +156,7 @@ struct porttype_info
/** /**
* Get set of all available port types. * Get set of all available port types.
*/ */
static std::set<porttype_info*> get_all(); static std::list<porttype_info*> get_all();
/** /**
* Get some default port type. * Get some default port type.
*/ */
@ -173,7 +173,8 @@ struct porttype_info
* Parameter psize: The size of storage for this type. * Parameter psize: The size of storage for this type.
* Throws std::bad_alloc: Not enough memory. * Throws std::bad_alloc: Not enough memory.
*/ */
porttype_info(const std::string& pname, const std::string& hname, size_t psize) throw(std::bad_alloc); porttype_info(const std::string& pname, const std::string& hname, unsigned _pt_id, size_t psize)
throw(std::bad_alloc);
/** /**
* Unregister port type. * Unregister port type.
*/ */
@ -294,6 +295,10 @@ struct porttype_info
* Name of controller. * Name of controller.
*/ */
std::string ctrlname; std::string ctrlname;
/**
* Id of the port.
*/
unsigned pt_id;
private: private:
porttype_info(const porttype_info&); porttype_info(const porttype_info&);
porttype_info& operator=(const porttype_info&); porttype_info& operator=(const porttype_info&);

View file

@ -1,7 +1,7 @@
#ifndef _romtype__hpp__included__ #ifndef _romtype__hpp__included__
#define _romtype__hpp__included__ #define _romtype__hpp__included__
#include <set> #include <list>
#include <string> #include <string>
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
@ -19,6 +19,7 @@ public:
const std::string& get_iname(); const std::string& get_iname();
const std::string& get_hname(); const std::string& get_hname();
unsigned get_priority(); unsigned get_priority();
unsigned get_handle();
bool is_multi(); bool is_multi();
void fill_framerate_magic(uint64_t* magic); //4 elements filled. void fill_framerate_magic(uint64_t* magic); //4 elements filled.
double approx_framerate(); double approx_framerate();
@ -55,16 +56,17 @@ struct core_romimage
struct core_type struct core_type
{ {
public: public:
core_type(const std::string& iname, const std::string& hname, int (*_load)(core_romimage* images, core_type(const std::string& iname, const std::string& hname, unsigned id, int (*_load)(core_romimage* images,
uint64_t rtc_sec, uint64_t rtc_subsec)); uint64_t rtc_sec, uint64_t rtc_subsec));
static std::set<core_type*> get_core_types(); static std::list<core_type*> get_core_types();
void add_region(core_region& reg); void add_region(core_region& reg);
void add_romimage(core_romimage_info& info, unsigned index); void add_romimage(core_romimage_info& info, unsigned index);
core_region& get_preferred_region(); core_region& get_preferred_region();
std::set<core_region*> get_regions(); std::list<core_region*> get_regions();
core_sysregion& combine_region(core_region& reg); core_sysregion& combine_region(core_region& reg);
const std::string& get_iname(); const std::string& get_iname();
const std::string& get_hname(); const std::string& get_hname();
unsigned get_id();
unsigned get_image_count(); unsigned get_image_count();
core_romimage_info get_image_info(unsigned index); core_romimage_info get_image_info(unsigned index);
bool load(core_romimage* images, uint64_t rtc_sec, uint64_t rtc_subsec); bool load(core_romimage* images, uint64_t rtc_sec, uint64_t rtc_subsec);
@ -72,9 +74,10 @@ private:
int (*loadimg)(core_romimage* images, uint64_t rtc_sec, uint64_t rtc_subsec); int (*loadimg)(core_romimage* images, uint64_t rtc_sec, uint64_t rtc_subsec);
core_type(const core_type&); core_type(const core_type&);
core_type& operator=(const core_type&); core_type& operator=(const core_type&);
unsigned id;
std::string iname; std::string iname;
std::string hname; std::string hname;
std::set<core_region*> regions; std::list<core_region*> regions;
std::vector<core_romimage_info*> imageinfo; std::vector<core_romimage_info*> imageinfo;
}; };

View file

@ -25,7 +25,7 @@ namespace
struct porttype_invalid : public porttype_info struct porttype_invalid : public porttype_info
{ {
porttype_invalid() : porttype_info("invalid-port-type", "invalid-port-type", 0) porttype_invalid() : porttype_info("invalid-port-type", "invalid-port-type", 99999, 0)
{ {
write = NULL; write = NULL;
read = NULL; read = NULL;
@ -51,6 +51,11 @@ namespace
static porttype_invalid inv; static porttype_invalid inv;
return inv; return inv;
} }
bool compare_porttype(porttype_info* a, porttype_info* b)
{
return (a->pt_id < b->pt_id);
}
} }
porttype_info& porttype_info::lookup(const std::string& p) throw(std::runtime_error) porttype_info& porttype_info::lookup(const std::string& p) throw(std::runtime_error)
@ -72,11 +77,13 @@ porttype_info::~porttype_info() throw()
porttypes().erase(this); porttypes().erase(this);
} }
porttype_info::porttype_info(const std::string& pname, const std::string& _hname, size_t psize) throw(std::bad_alloc) porttype_info::porttype_info(const std::string& pname, const std::string& _hname, unsigned _pt_id, size_t psize)
throw(std::bad_alloc)
{ {
name = pname; name = pname;
hname = _hname; hname = _hname;
storage_size = psize; storage_size = psize;
pt_id = _pt_id;
porttypes().insert(this); porttypes().insert(this);
} }
@ -85,12 +92,13 @@ porttype_info& porttype_info::default_type()
return get_invalid_port_type(); return get_invalid_port_type();
} }
std::set<porttype_info*> porttype_info::get_all() std::list<porttype_info*> porttype_info::get_all()
{ {
std::set<porttype_info*> p; std::list<porttype_info*> p;
for(auto i : porttypes()) for(auto i : porttypes())
if(i->legal) if(i->legal)
p.insert(i); p.push_back(i);
p.sort(compare_porttype);
return p; return p;
} }

View file

@ -129,9 +129,9 @@ namespace
core_romimage_info image_rom_dmg("gbrom", "Cartridge ROM", 1, header_fn); core_romimage_info image_rom_dmg("gbrom", "Cartridge ROM", 1, header_fn);
core_romimage_info image_rom_gbc("gbcrom", "Cartridge ROM", 1, header_fn); core_romimage_info image_rom_gbc("gbcrom", "Cartridge ROM", 1, header_fn);
core_romimage_info image_rom_gbca("gbcarom", "Cartridge ROM", 1, header_fn); core_romimage_info image_rom_gbca("gbcarom", "Cartridge ROM", 1, header_fn);
core_type type_dmg("dmg", "Game Boy", load_rom_dmg); core_type type_dmg("dmg", "Game Boy", 1, load_rom_dmg);
core_type type_gbc("gbc", "Game Boy Color", load_rom_gbc); core_type type_gbc("gbc", "Game Boy Color", 0, load_rom_gbc);
core_type type_gbc_gba("gbc_gba", "Game Boy Color (GBA)", load_rom_gbc_gba); core_type type_gbc_gba("gbc_gba", "Game Boy Color (GBA)", 2, load_rom_gbc_gba);
core_type_region_bind bind_A(type_dmg, region_world); core_type_region_bind bind_A(type_dmg, region_world);
core_type_region_bind bind_B(type_gbc, region_world); core_type_region_bind bind_B(type_gbc, region_world);
core_type_region_bind bind_C(type_gbc_gba, region_world); core_type_region_bind bind_C(type_gbc_gba, region_world);
@ -148,7 +148,7 @@ namespace
struct porttype_gamepad : public porttype_info struct porttype_gamepad : public porttype_info
{ {
porttype_gamepad() : porttype_info("gamepad", "Gamepad", generic_port_size<1, 0, 8>()) porttype_gamepad() : porttype_info("gamepad", "Gamepad", 1, generic_port_size<1, 0, 8>())
{ {
write = generic_port_write<1, 0, 8>; write = generic_port_write<1, 0, 8>;
read = generic_port_read<1, 0, 8>; read = generic_port_read<1, 0, 8>;
@ -180,7 +180,7 @@ namespace
struct porttype_none : public porttype_info struct porttype_none : public porttype_info
{ {
porttype_none() : porttype_info("none", "None", generic_port_size<0, 0, 0>()) porttype_none() : porttype_info("none", "None", 0, generic_port_size<0, 0, 0>())
{ {
write = generic_port_write<0, 0, 0>; write = generic_port_write<0, 0, 0>;
read = generic_port_read<0, 0, 0>; read = generic_port_read<0, 0, 0>;

View file

@ -94,7 +94,7 @@ namespace
std::set<std::string> find_present_roms(const std::vector<std::string>& cmdline) std::set<std::string> find_present_roms(const std::vector<std::string>& cmdline)
{ {
std::set<std::string> p; std::set<std::string> p;
std::set<core_type*> types = core_type::get_core_types(); std::list<core_type*> types = core_type::get_core_types();
for(auto i : types) { for(auto i : types) {
for(unsigned j = 0; j < i->get_image_count(); j++) { for(unsigned j = 0; j < i->get_image_count(); j++) {
std::string iname = i->get_image_info(j).iname; std::string iname = i->get_image_info(j).iname;
@ -437,7 +437,7 @@ int recognize_commandline_rom(core_type& major, const std::string& romname) thro
core_type& recognize_platform(const std::set<std::string>& present) throw(std::bad_alloc, std::runtime_error) core_type& recognize_platform(const std::set<std::string>& present) throw(std::bad_alloc, std::runtime_error)
{ {
std::set<core_type*> possible = core_type::get_core_types(); std::list<core_type*> possible = core_type::get_core_types();
unsigned total = 0; unsigned total = 0;
for(auto i : present) { for(auto i : present) {
regex_results r; regex_results r;

View file

@ -69,6 +69,16 @@ namespace
i++; i++;
} }
} }
bool compare_coretype(core_type* a, core_type* b)
{
return (a->get_id() < b->get_id());
}
bool compare_regions(core_region* a, core_region* b)
{
return (a->get_handle() < b->get_handle());
}
} }
core_region::core_region(const std::string& _iname, const std::string& _hname, unsigned _priority, unsigned _handle, core_region::core_region(const std::string& _iname, const std::string& _hname, unsigned _priority, unsigned _handle,
@ -114,6 +124,11 @@ unsigned core_region::get_priority()
return priority; return priority;
} }
unsigned core_region:: get_handle()
{
return handle;
}
void core_region::fill_framerate_magic(uint64_t* _magic) void core_region::fill_framerate_magic(uint64_t* _magic)
{ {
for(size_t i = 0; i < 4; i++) for(size_t i = 0; i < 4; i++)
@ -159,9 +174,14 @@ void core_sysregion::fill_framerate_magic(uint64_t* magic)
region.fill_framerate_magic(magic); region.fill_framerate_magic(magic);
} }
unsigned core_type::get_id()
{
return id;
}
void core_type::add_region(core_region& reg) void core_type::add_region(core_region& reg)
{ {
regions.insert(&reg); regions.push_back(&reg);
} }
void core_type::add_romimage(core_romimage_info& info, unsigned index) void core_type::add_romimage(core_romimage_info& info, unsigned index)
@ -199,17 +219,20 @@ core_romimage_info core_type::get_image_info(unsigned index)
return *imageinfo[index]; return *imageinfo[index];
} }
std::set<core_type*> core_type::get_core_types() std::list<core_type*> core_type::get_core_types()
{ {
std::set<core_type*> ret; std::list<core_type*> ret;
for(auto i : types()) for(auto i : types())
ret.insert(i.second); ret.push_back(i.second);
ret.sort(compare_coretype);
return ret; return ret;
} }
std::set<core_region*> core_type::get_regions() std::list<core_region*> core_type::get_regions()
{ {
return regions; std::list<core_region*> ret = regions;
ret.sort(compare_regions);
return ret;
} }
core_region& core_type::get_preferred_region() core_region& core_type::get_preferred_region()
@ -239,9 +262,9 @@ core_sysregion& core_type::combine_region(core_region& reg)
throw std::runtime_error("Invalid region for system type"); throw std::runtime_error("Invalid region for system type");
} }
core_type::core_type(const std::string& _iname, const std::string& _hname, int (*_load)(core_romimage* images, core_type::core_type(const std::string& _iname, const std::string& _hname, unsigned _id,
uint64_t rtc_sec, uint64_t rtc_subsec)) int (*_load)(core_romimage* images, uint64_t rtc_sec, uint64_t rtc_subsec))
: iname(_iname), hname(_hname), loadimg(_load) : iname(_iname), hname(_hname), loadimg(_load), id(_id)
{ {
types()[iname] = this; types()[iname] = this;
process_registrations(); process_registrations();