1 /******************************************************************************/
2 /* Mednafen NEC PC-FX Emulation Module */
3 /******************************************************************************/
4 /* gamepad.cpp:
5 ** Copyright (C) 2006-2016 Mednafen Team
6 **
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software Foundation, Inc.,
19 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 #include "../pcfx.h"
23 #include "../input.h"
24 #include "gamepad.h"
25
26 namespace MDFN_IEN_PCFX
27 {
28
29 class PCFX_Input_Gamepad : public PCFX_Input_Device
30 {
31 public:
PCFX_Input_Gamepad()32 PCFX_Input_Gamepad()
33 {
34 buttons = 0;
35 }
36
~PCFX_Input_Gamepad()37 virtual ~PCFX_Input_Gamepad() override
38 {
39
40 }
41
ReadTransferTime(void)42 virtual uint32 ReadTransferTime(void) override
43 {
44 return(1536);
45 }
46
WriteTransferTime(void)47 virtual uint32 WriteTransferTime(void) override
48 {
49 return(1536);
50 }
51
Read(void)52 virtual uint32 Read(void) override
53 {
54 return(buttons | (FX_SIG_PAD << 28));
55 }
56
Write(uint32 data)57 virtual void Write(uint32 data) override
58 {
59
60 }
61
62
Power(void)63 virtual void Power(void) override
64 {
65 buttons = 0;
66 }
67
TransformInput(uint8 * data,const bool DisableSR)68 virtual void TransformInput(uint8* data, const bool DisableSR) override
69 {
70 if(DisableSR)
71 {
72 uint16 tmp = MDFN_de16lsb(data);
73
74 if((tmp & 0xC0) == 0xC0)
75 tmp &= ~0xC0;
76
77 MDFN_en16lsb(data, tmp);
78 }
79 }
80
Frame(const void * data)81 virtual void Frame(const void *data) override
82 {
83 buttons = MDFN_de16lsb((uint8 *)data);
84 }
85
StateAction(StateMem * sm,const unsigned load,const bool data_only,const char * section_name)86 virtual void StateAction(StateMem *sm, const unsigned load, const bool data_only, const char *section_name) override
87 {
88 SFORMAT StateRegs[] =
89 {
90 SFVAR(buttons),
91 SFEND
92 };
93
94 if(!MDFNSS_StateAction(sm, load, data_only, StateRegs, section_name, true) && load)
95 Power();
96 }
97
98 private:
99
100 uint16 buttons;
101 };
102
103 static const IDIIS_SwitchPos ModeSwitchPositions[] =
104 {
105 { "a", "A" },
106 { "b", "B" },
107 };
108
109 const IDIISG PCFX_GamepadIDII =
110 {
111 IDIIS_Button("i", "I", 11),
112 IDIIS_Button("ii", "II", 10),
113 IDIIS_Button("iii", "III", 9),
114 IDIIS_Button("iv", "IV", 6),
115 IDIIS_Button("v", "V", 7),
116 IDIIS_Button("vi", "VI", 8),
117 IDIIS_Button("select", "SELECT", 4),
118 IDIIS_Button("run", "RUN", 5),
119 IDIIS_Button("up", "UP ↑", 0, "down"),
120 IDIIS_Button("right", "RIGHT →", 3, "left"),
121 IDIIS_Button("down", "DOWN ↓", 1, "up"),
122 IDIIS_Button("left", "LEFT ←", 2, "right"),
123
124 IDIIS_Switch("mode1", "MODE 1", 12, ModeSwitchPositions),
125 IDIIS_Padding<1>(),
126 IDIIS_Switch("mode2", "MODE 2", 13, ModeSwitchPositions),
127 };
128
PCFXINPUT_MakeGamepad(void)129 PCFX_Input_Device *PCFXINPUT_MakeGamepad(void)
130 {
131 return(new PCFX_Input_Gamepad());
132 }
133
134 }
135