Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/source/keypad.cpp
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
#include "ameteor/keypad.hpp"
18
#include "globals.hpp"
19
#include "ameteor.hpp"
20
21
namespace AMeteor
22
{
23
Keypad::Keypad () :
24
m_keyinput(IO.GetRef16(Io::KEYINPUT)),
25
m_keycnt(IO.GetRef16(Io::KEYCNT))
26
{
27
}
28
29
void Keypad::KeyPressed(int code)
30
{
31
if (m_keys.count(code))
32
m_keyinput &= ~m_keys[code];
33
}
34
35
void Keypad::KeyReleased(int code)
36
{
37
if (m_keys.count(code))
38
m_keyinput |= m_keys[code];
39
}
40
41
void Keypad::JoyButtonPressed (uint16_t joyid, uint16_t button)
42
{
43
uint32_t id = ((int)joyid) << 16 | button;
44
if (m_joys.count(id))
45
m_keyinput &= ~m_joys[id];
46
}
47
48
void Keypad::JoyButtonReleased (uint16_t joyid, uint16_t button)
49
{
50
uint32_t id = ((int)joyid) << 16 | button;
51
if (m_joys.count(id))
52
m_keyinput |= m_joys[id];
53
}
54
55
void Keypad::JoyMoved (uint16_t joyid, uint16_t axis, float pos)
56
{
57
uint32_t id = (((int)joyid) << 16) | ((pos < 0) << 15) | (axis & 0x7FFF);
58
// if pos is 0, we disable the positive and negative targets
59
if (pos == 0)
60
{
61
if (m_axis.count(id))
62
m_keyinput |= m_axis[id];
63
if (m_axis.count(id | (1 << 15)))
64
m_keyinput |= m_axis[id | (1 << 15)];
65
}
66
else
67
{
68
// we enable the corresponding button
69
if (m_axis.count(id))
70
m_keyinput &= ~((uint16_t)m_axis[id]);
71
// we disable the opposite button (we may have skipped 0)
72
if (m_axis.count(id ^ 0x8000))
73
m_keyinput |= m_axis[id ^ 0x8000];
74
}
75
}
76
77
void Keypad::VBlank ()
78
{
79
// if keypad IRQ are enabled
80
if (m_keycnt & (0x1 << 14))
81
// if irq condition is and
82
if (m_keycnt & (0x1 << 15))
83
{
84
// if condition is satisfied
85
if ((~m_keyinput & m_keycnt & 0x3FF) == (m_keycnt & 0x3FF))
86
CPU.SendInterrupt(0x1000);
87
}
88
// if irq condition is or
89
else
90
{
91
// if condition is satisfied
92
if (~m_keyinput & m_keycnt & 0x3FF)
93
CPU.SendInterrupt(0x1000);
94
}
95
}
96
}
97
98