Pack movie data in memory
[lsnes.git] / src / core / controller_multitap.cpp
blobc1e466b4234405f5b53966a1ae9bc7553a52db9e
1 #include "lsnes.hpp"
2 #include <snes/snes.hpp>
3 #include <ui-libsnes/libsnes.hpp>
5 #include "core/controllerframe.hpp"
7 namespace
9 const char* buttons = "BYsSudlrAXLR";
11 struct porttype_multitap : public porttype_info
13 porttype_multitap() : porttype_info(PT_MULTITAP, "multitap", 6) {}
14 void write(unsigned char* buffer, unsigned idx, unsigned ctrl, short x) const throw()
16 if(ctrl >= 12 || idx > 4)
17 return;
18 unsigned i = idx * 12 + ctrl;
19 if(x)
20 buffer[i / 8] |= (1 << (i % 8));
21 else
22 buffer[i / 8] &= ~(1 << (i % 8));
25 short read(const unsigned char* buffer, unsigned idx, unsigned ctrl) const throw()
27 if(ctrl >= 12 || idx > 4)
28 return 0;
29 unsigned i = idx * 12 + ctrl;
30 return ((buffer[i / 8] & (1 << (i % 8))) != 0);
33 void display(const unsigned char* buffer, unsigned idx, char* buf) const throw()
35 if(idx > 3) {
36 buf[0] = '\0';
37 return;
39 unsigned j = idx * 12;
40 for(unsigned i = 0; i < 12; i++)
41 buf[i] = (buffer[(i + j) / 8] & (1 << ((i + j) % 8))) ? buttons[i % 12] : ' ';
42 buf[12] = '\0';
45 size_t serialize(const unsigned char* buffer, char* textbuf) const throw()
47 unsigned j = 0;
48 for(unsigned i = 0; i < 48; i++) {
49 if(i % 12 == 0)
50 textbuf[j++] = '|';
51 textbuf[j++] = (buffer[i / 8] & (1 << (i % 8))) ? buttons[i % 12] : '.';
53 return j;
56 size_t deserialize(unsigned char* buffer, const char* textbuf) const throw()
58 buffer[0] = 0;
59 buffer[1] = 0;
60 buffer[2] = 0;
61 buffer[3] = 0;
62 buffer[4] = 0;
63 buffer[5] = 0;
64 const char* orig_texbuf = textbuf;
65 size_t index = 0;
66 for(unsigned i = 0; i < 48; i++) {
67 if(read_button_value(textbuf, index))
68 buffer[i / 8] |= (1 << (i % 8));
69 if(i % 12 == 0 && i > 0)
70 skip_rest_of_field(textbuf, index, true);
72 skip_rest_of_field(textbuf, index, false);
73 return index;
76 devicetype_t devicetype(unsigned idx) const throw()
78 return (idx < 4) ? DT_GAMEPAD : DT_NONE;
81 unsigned controllers() const throw()
83 return 4;
86 unsigned internal_type() const throw()
88 return SNES_DEVICE_MULTITAP;
91 bool legal(unsigned port) const throw()
93 return true;
95 } multitap;