1 #include "controller.hpp"
3 #include <snes/snes.hpp>
4 #include <ui-libsnes/libsnes.hpp>
8 porttype_t porttypes
[2];
9 int analog_indices
[3] = {-1, -1, -1};
10 bool analog_is_mouse
[3];
12 void update_analog_indices() throw()
15 for(unsigned j
= 0; j
< sizeof(analog_indices
) / sizeof(analog_indices
[0]); j
++)
16 analog_indices
[j
] = -1;
17 for(unsigned j
= 0; j
< 8; j
++) {
18 devicetype_t d
= controller_type_by_logical(j
);
24 analog_is_mouse
[i
] = true;
25 analog_indices
[i
++] = j
;
29 analog_is_mouse
[i
] = false;
30 analog_indices
[i
++] = j
;
37 int controller_index_by_logical(unsigned lid
) throw()
39 bool p1multitap
= (porttypes
[0] == PT_MULTITAP
);
40 unsigned p1devs
= port_types
[porttypes
[0]].devices
;
41 unsigned p2devs
= port_types
[porttypes
[1]].devices
;
42 if(lid
>= p1devs
+ p2devs
)
48 return 4 + lid
- p1devs
;
58 int controller_index_by_analog(unsigned aid
) throw()
62 return analog_indices
[aid
];
65 bool controller_ismouse_by_analog(unsigned aid
) throw()
69 return analog_is_mouse
[aid
];
72 devicetype_t
controller_type_by_logical(unsigned lid
) throw()
74 int x
= controller_index_by_logical(lid
);
77 enum porttype_t rawtype
= porttypes
[x
>> 2];
78 if((x
& 3) < port_types
[rawtype
].devices
)
79 return port_types
[rawtype
].dtype
;
84 void controller_set_port_type(unsigned port
, porttype_t ptype
, bool set_core
) throw()
86 if(set_core
&& ptype
!= PT_INVALID
)
87 snes_set_controller_port_device(port
!= 0, port_types
[ptype
].bsnes_type
);
88 porttypes
[port
] = ptype
;
89 update_analog_indices();