Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/keypad.hpp
2 views
1
// Meteor - A Nintendo Gameboy Advance emulator
2
// Copyright (C) 2009-2011 Philippe Daouadi
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
#ifndef __KEYPAD_H__
18
#define __KEYPAD_H__
19
20
#include <stdint.h>
21
#include <map>
22
23
namespace AMeteor
24
{
25
class Keypad
26
{
27
public :
28
enum Button
29
{
30
BTN_A = 0x001,
31
BTN_B = 0x002,
32
BTN_SELECT = 0x004,
33
BTN_START = 0x008,
34
BTN_RIGHT = 0x010,
35
BTN_LEFT = 0x020,
36
BTN_UP = 0x040,
37
BTN_DOWN = 0x080,
38
BTN_R = 0x100,
39
BTN_L = 0x200
40
};
41
42
Keypad ();
43
44
void Reset ()
45
{
46
}
47
48
void BindKey(int code, Button btn)
49
{
50
m_keys[code] = (uint16_t)btn;
51
}
52
void UnbindKey(int code)
53
{
54
m_keys.erase(code);
55
}
56
void BindJoy(uint16_t joyid, uint16_t button, Button btn)
57
{
58
m_joys[((int)joyid) << 16 | button] = (uint16_t)btn;
59
}
60
void UnbindJoy(uint16_t joyid, uint16_t button)
61
{
62
m_joys.erase(((int)joyid) << 16 | button);
63
}
64
void BindAxis(uint16_t joyid, uint16_t axis, Button btn)
65
{
66
m_axis[((int)joyid) << 16 | axis] = (uint16_t)btn;
67
}
68
void UnbindAxis(uint16_t joyid, uint16_t axis)
69
{
70
m_axis.erase(((int)joyid) << 16 | axis);
71
}
72
73
void ResetBindings()
74
{
75
m_keys.clear();
76
m_joys.clear();
77
m_axis.clear();
78
}
79
80
inline void SetPadState(uint16_t keys);
81
82
void KeyPressed(int code);
83
void KeyReleased(int code);
84
void JoyButtonPressed (uint16_t joyid, uint16_t button);
85
void JoyButtonReleased (uint16_t joyid, uint16_t button);
86
void JoyMoved (uint16_t joyid, uint16_t axis, float pos);
87
88
void VBlank ();
89
90
private :
91
uint16_t& m_keyinput;
92
uint16_t& m_keycnt;
93
94
std::map<int, uint16_t> m_keys;
95
std::map<int, uint16_t> m_joys;
96
std::map<int, uint16_t> m_axis;
97
};
98
99
void Keypad::SetPadState(uint16_t keys)
100
{
101
m_keyinput = keys;
102
}
103
}
104
105
#endif
106
107