Automatically build index triple and legacy-pcid maps
All cores build these the same way, so make the code common.
This commit is contained in:
parent
d10c863a56
commit
53b75adcf2
13 changed files with 32 additions and 82 deletions
|
@ -5,8 +5,9 @@
|
|||
|
||||
struct controller_set
|
||||
{
|
||||
struct port_index_map portindex;
|
||||
struct port_index_map portindex();
|
||||
std::vector<port_type*> ports;
|
||||
std::vector<std::pair<unsigned, unsigned>> logical_map;
|
||||
};
|
||||
|
||||
extern uint32_t magic_flags;
|
||||
|
|
|
@ -295,7 +295,7 @@ void do_load_beginning(bool reload) throw(std::bad_alloc, std::runtime_error)
|
|||
rrdata::add_internal();
|
||||
} else {
|
||||
auto ctrldata = our_rom->rtype->controllerconfig(our_movie.settings);
|
||||
port_type_set& portset = port_type_set::make(ctrldata.ports, ctrldata.portindex);
|
||||
port_type_set& portset = port_type_set::make(ctrldata.ports, ctrldata.portindex());
|
||||
controls.set_ports(portset);
|
||||
if(our_movie.input.get_types() != portset) {
|
||||
//The input type changes, so set the types.
|
||||
|
@ -387,7 +387,7 @@ void do_load_state(struct moviefile& _movie, int lmode)
|
|||
(lmode == LOAD_STATE_PRESERVE) ? &_movie.input : NULL, _movie.projectid);
|
||||
|
||||
auto ctrldata = our_rom->rtype->controllerconfig(_movie.settings);
|
||||
port_type_set& portset = port_type_set::make(ctrldata.ports, ctrldata.portindex);
|
||||
port_type_set& portset = port_type_set::make(ctrldata.ports, ctrldata.portindex());
|
||||
|
||||
//Negative return.
|
||||
rrdata::read_base(_movie.projectid, _movie.lazy_project_create);
|
||||
|
|
|
@ -447,7 +447,7 @@ moviefile::moviefile(const std::string& movie, core_type& romtype) throw(std::ba
|
|||
}
|
||||
settings = read_settings(r);
|
||||
auto ctrldata = gametype->get_type().controllerconfig(settings);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex());
|
||||
|
||||
input.clear(ports);
|
||||
read_linefile(r, "gamename", gamename, true);
|
||||
|
|
|
@ -207,7 +207,7 @@ namespace
|
|||
m.gamename = p.gamename;
|
||||
m.settings = p.settings;
|
||||
auto ctrldata = coretype.controllerconfig(m.settings);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex());
|
||||
m.input.clear(ports);
|
||||
try {
|
||||
m.gametype = &coretype.lookup_sysregion(p.gametype);
|
||||
|
|
|
@ -120,7 +120,6 @@ namespace
|
|||
{
|
||||
controller_set x;
|
||||
x.ports.push_back(&get_default_system_port_type());
|
||||
x.portindex.indices.push_back(sync_triple);
|
||||
return x;
|
||||
}
|
||||
std::pair<uint64_t, uint64_t> c_get_bus_map() { return std::make_pair(0ULL, 0ULL); }
|
||||
|
|
|
@ -262,24 +262,6 @@ namespace
|
|||
return r ? 0 : -1;
|
||||
}
|
||||
|
||||
port_index_triple t(unsigned p, unsigned c, unsigned i, bool nl)
|
||||
{
|
||||
port_index_triple x;
|
||||
x.valid = true;
|
||||
x.port = p;
|
||||
x.controller = c;
|
||||
x.control = i;
|
||||
return x;
|
||||
}
|
||||
|
||||
void push_port_indices(std::vector<port_index_triple>& tab, unsigned p, port_type& pt)
|
||||
{
|
||||
unsigned ctrls = pt.controller_info->controllers.size();
|
||||
for(unsigned i = 0; i < ctrls; i++)
|
||||
for(unsigned j = 0; j < pt.controller_info->controllers[i]->buttons.size(); j++)
|
||||
tab.push_back(t(p, i, j, true));
|
||||
}
|
||||
|
||||
controller_set bsnes_controllerconfig(std::map<std::string, std::string>& settings)
|
||||
{
|
||||
std::map<std::string, std::string> _settings = settings;
|
||||
|
@ -296,25 +278,19 @@ namespace
|
|||
r.ports.push_back(index_to_ptype[type2]);
|
||||
unsigned p1controllers = r.ports[1]->controller_info->controllers.size();
|
||||
unsigned p2controllers = r.ports[2]->controller_info->controllers.size();
|
||||
for(unsigned i = 0; i < (hreset ? 5 : 4); i++)
|
||||
r.portindex.indices.push_back(t(0, 0, i, false));
|
||||
push_port_indices(r.portindex.indices, 1, *r.ports[1]);
|
||||
push_port_indices(r.portindex.indices, 2, *r.ports[2]);
|
||||
r.portindex.logical_map.resize(p1controllers + p2controllers);
|
||||
r.logical_map.resize(p1controllers + p2controllers);
|
||||
if(p1controllers == 4) {
|
||||
r.portindex.logical_map[0] = std::make_pair(1, 0);
|
||||
r.logical_map[0] = std::make_pair(1, 0);
|
||||
for(size_t j = 0; j < p2controllers; j++)
|
||||
r.portindex.logical_map[j + 1] = std::make_pair(2U, j);
|
||||
r.logical_map[j + 1] = std::make_pair(2U, j);
|
||||
for(size_t j = 1; j < p1controllers; j++)
|
||||
r.portindex.logical_map[j + p2controllers] = std::make_pair(1U, j);
|
||||
r.logical_map[j + p2controllers] = std::make_pair(1U, j);
|
||||
} else {
|
||||
for(size_t j = 0; j < p1controllers; j++)
|
||||
r.portindex.logical_map[j] = std::make_pair(1, j);
|
||||
r.logical_map[j] = std::make_pair(1, j);
|
||||
for(size_t j = 0; j < p2controllers; j++)
|
||||
r.portindex.logical_map[j + p1controllers] = std::make_pair(2U, j);
|
||||
r.logical_map[j + p1controllers] = std::make_pair(2U, j);
|
||||
}
|
||||
for(unsigned i = 0; i < 8; i++)
|
||||
r.portindex.pcid_map.push_back(std::make_pair(i / 4 + 1, i % 4));
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -144,27 +144,12 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
|
||||
port_index_triple t(unsigned p, unsigned c, unsigned i, bool nl)
|
||||
{
|
||||
port_index_triple x;
|
||||
x.valid = true;
|
||||
x.port = p;
|
||||
x.controller = c;
|
||||
x.control = i;
|
||||
return x;
|
||||
}
|
||||
|
||||
controller_set gambatte_controllerconfig(std::map<std::string, std::string>& settings)
|
||||
{
|
||||
std::map<std::string, std::string> _settings = settings;
|
||||
controller_set r;
|
||||
r.ports.push_back(&psystem);
|
||||
for(unsigned i = 0; i < 4; i++)
|
||||
r.portindex.indices.push_back(t(0, 0, i, false));
|
||||
for(unsigned i = 0; i < 8; i++)
|
||||
r.portindex.indices.push_back(t(0, 1, i, true));
|
||||
r.portindex.logical_map.push_back(std::make_pair(0, 1));
|
||||
r.portindex.pcid_map.push_back(std::make_pair(0, 1));
|
||||
r.logical_map.push_back(std::make_pair(0, 1));
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@ ports = {
|
|||
{
|
||||
["name"] = "(system)", ["class"] = "(system)", ["buttons"] = {
|
||||
{shadow, "F", "framesync"},
|
||||
{shadow, "R", "reset"}
|
||||
{shadow, "R", "reset"},
|
||||
{shadow_null},
|
||||
{shadow_null},
|
||||
}
|
||||
},{
|
||||
["name"] = "gamepad", ["class"] = "gb", ["buttons"] = {
|
||||
|
|
|
@ -19,6 +19,7 @@ taxis="TAXIS";
|
|||
shadow="SHADOW";
|
||||
shadow_axis="SHADOW_AXIS";
|
||||
null="NULL";
|
||||
shadow_null="SHADOW_NULL";
|
||||
|
||||
if not arg[1] then
|
||||
error("Expected input file");
|
||||
|
@ -86,7 +87,12 @@ for i = 1,#ports do
|
|||
end
|
||||
if xbutton[1] == null then
|
||||
table.insert(bsyms, bsym);
|
||||
buttonsymbols[bsym] = "{port_controller_button::TYPE_NULL, U'\0', NULL, false, 0, 0,"
|
||||
buttonsymbols[bsym] = "{port_controller_button::TYPE_NULL, U'\\0', NULL, false, 0, 0,"
|
||||
.. "false, NULL}";
|
||||
end
|
||||
if xbutton[1] == shadow_null then
|
||||
table.insert(bsyms, bsym);
|
||||
buttonsymbols[bsym] = "{port_controller_button::TYPE_NULL, U'\\0', NULL, true, 0, 0,"
|
||||
.. "false, NULL}";
|
||||
end
|
||||
end
|
||||
|
@ -167,6 +173,9 @@ for i = 1,#ports do
|
|||
"(unsigned short)buffer["..(int_l+1).."] << 8));");
|
||||
int_l = int_l + 2;
|
||||
end
|
||||
if (bt == null) or (bt == shadow_null) then
|
||||
print("\t\t\t\t\treturn 0;");
|
||||
end
|
||||
end
|
||||
print("\t\t\t\t};");
|
||||
print("\t\t\t\tbreak;");
|
||||
|
|
|
@ -376,11 +376,7 @@ namespace sky
|
|||
controller_magic();
|
||||
controller_set r;
|
||||
r.ports.push_back(&psystem);
|
||||
r.portindex.indices.push_back(t(0, 0, 0, false));
|
||||
for(unsigned i = 0; i < 9; i++)
|
||||
r.portindex.indices.push_back(t(0, 1, i, true));
|
||||
r.portindex.logical_map.push_back(std::make_pair(0, 1));
|
||||
r.portindex.pcid_map.push_back(std::make_pair(0, 1));
|
||||
r.logical_map.push_back(std::make_pair(0, 1));
|
||||
return r;
|
||||
}
|
||||
std::pair<uint64_t, uint64_t> c_get_bus_map() { return std::make_pair(0, 0); }
|
||||
|
|
|
@ -58,16 +58,6 @@ namespace
|
|||
|
||||
#include "ports.inc"
|
||||
|
||||
port_index_triple t(unsigned p, unsigned c, unsigned i, bool nl)
|
||||
{
|
||||
port_index_triple x;
|
||||
x.valid = true;
|
||||
x.port = p;
|
||||
x.controller = c;
|
||||
x.control = i;
|
||||
return x;
|
||||
}
|
||||
|
||||
controller_set test_controllerconfig(std::map<std::string, std::string>& settings)
|
||||
{
|
||||
std::map<std::string, std::string> _settings = settings;
|
||||
|
@ -75,16 +65,8 @@ namespace
|
|||
r.ports.push_back(&psystem);
|
||||
r.ports.push_back(&ptype1);
|
||||
r.ports.push_back(&ptype2);
|
||||
for(unsigned i = 0; i < 5; i++)
|
||||
r.portindex.indices.push_back(t(0, 0, i, false));
|
||||
for(unsigned i = 0; i < 21; i++)
|
||||
r.portindex.indices.push_back(t(1, 0, i, true));
|
||||
for(unsigned i = 0; i < 21; i++)
|
||||
r.portindex.indices.push_back(t(2, 0, i, true));
|
||||
r.portindex.logical_map.push_back(std::make_pair(1, 0));
|
||||
r.portindex.logical_map.push_back(std::make_pair(2, 0));
|
||||
r.portindex.pcid_map.push_back(std::make_pair(1, 0));
|
||||
r.portindex.pcid_map.push_back(std::make_pair(2, 0));
|
||||
r.logical_map.push_back(std::make_pair(1, 0));
|
||||
r.logical_map.push_back(std::make_pair(2, 0));
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -443,7 +443,7 @@ bool lsnes_app::OnInit()
|
|||
loaded_rom dummy_rom;
|
||||
std::map<std::string, std::string> settings;
|
||||
auto ctrldata = dummy_rom.rtype->controllerconfig(settings);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex());
|
||||
|
||||
reinitialize_buttonmap();
|
||||
controls.set_ports(ports);
|
||||
|
@ -503,7 +503,7 @@ bool lsnes_app::OnInit()
|
|||
mov = new moviefile;
|
||||
mov->settings = c_settings;
|
||||
auto ctrldata = rom->rtype->controllerconfig(mov->settings);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex());
|
||||
mov->input.clear(ports);
|
||||
mov->coreversion = rom->rtype->get_core_identifier();
|
||||
mov->projectid = get_random_hexstring(40);
|
||||
|
|
|
@ -631,7 +631,7 @@ struct moviefile wxwin_project::make_movie()
|
|||
if(f.movie_rtc_subsecond < 0)
|
||||
throw std::runtime_error("RTC subsecond must be positive");
|
||||
auto ctrldata = our_rom->rtype->controllerconfig(f.settings);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex);
|
||||
port_type_set& ports = port_type_set::make(ctrldata.ports, ctrldata.portindex());
|
||||
f.input.clear(ports);
|
||||
return f;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue