2 #include <snes/snes.hpp>
3 #include <ui-libsnes/libsnes.hpp>
5 #include "core/controllerframe.hpp"
9 struct porttype_superscope
: public porttype_info
11 porttype_superscope() : porttype_info(PT_SUPERSCOPE
, "superscope", 5) {}
12 void write(unsigned char* buffer
, unsigned idx
, unsigned ctrl
, short x
) const throw()
14 if(ctrl
>= 6 || idx
> 0)
19 serialize_short(buffer
+ 2 * ctrl
+ 1, x
);
26 buffer
[0] |= (1 << (ctrl
- 2));
28 buffer
[0] &= ~(1 << (ctrl
- 2));
33 short read(const unsigned char* buffer
, unsigned idx
, unsigned ctrl
) const throw()
35 if(ctrl
>= 6 || idx
> 0)
40 return unserialize_short(buffer
+ 2 * ctrl
+ 1);
45 return ((buffer
[0] & (1 << (ctrl
- 2))) != 0);
49 void display(const unsigned char* buffer
, unsigned idx
, char* buf
) const throw()
55 sprintf(buf
, "%i %i %c%c%c%c", unserialize_short(buffer
+ 1), unserialize_short(buffer
+ 3),
56 ((buffer
[0] & 1) ? 'T' : '-'), ((buffer
[0] & 2) ? 'C' : '-'),
57 ((buffer
[0] & 4) ? 'U' : '-'), ((buffer
[0] & 8) ? 'P' : '-'));
60 size_t serialize(const unsigned char* buffer
, char* textbuf
) const throw()
63 sprintf(tmp
, "|%c%c%c%c %i %i", ((buffer
[0] & 1) ? 'T' : '.'), ((buffer
[0] & 2) ? 'C' : '.'),
64 ((buffer
[0] & 4) ? 'U' : '.'), ((buffer
[0] & 8) ? 'P' : '.'),
65 unserialize_short(buffer
+ 1), unserialize_short(buffer
+ 3));
66 size_t len
= strlen(tmp
);
67 memcpy(textbuf
, tmp
, len
);
71 size_t deserialize(unsigned char* buffer
, const char* textbuf
) const throw()
75 if(read_button_value(textbuf
, idx
))
77 if(read_button_value(textbuf
, idx
))
79 if(read_button_value(textbuf
, idx
))
81 if(read_button_value(textbuf
, idx
))
83 serialize_short(buffer
+ 1, read_axis_value(textbuf
, idx
));
84 serialize_short(buffer
+ 3, read_axis_value(textbuf
, idx
));
85 skip_rest_of_field(textbuf
, idx
, false);
89 devicetype_t
devicetype(unsigned idx
) const throw()
91 return (idx
== 0) ? DT_SUPERSCOPE
: DT_NONE
;
94 unsigned controllers() const throw()
99 unsigned internal_type() const throw()
101 return SNES_DEVICE_SUPER_SCOPE
;
104 bool legal(unsigned port
) const throw()