gbasys
view src/input.c @ 9:85f219fcdc82
merged
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 22 Jun 2014 06:27:18 +0300 |
parents | 047c61960005 72c6429ae953 |
children |
line source
1 /*
2 gbasys - a gameboy advance hardware abstraction library
3 Copyright (C) 2004-2014 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "input.h"
20 #define REG_KEYSTATE (*(unsigned short*)0x4000130)
21 #define REG_KEYCTL (*(unsigned short*)0x4000132)
23 int get_key_state(int key) {
24 int res;
25 unsigned short prev_mask;
27 prev_mask = REG_KEYCTL;
28 disable_key_interrupts(key);
30 res = ~REG_KEYSTATE & key;
31 REG_KEYCTL = prev_mask;
32 return res;
33 }
35 void enable_key_interrupts(int keys) {
36 REG_KEYCTL |= (1 << 14) | keys;
37 }
39 void disable_key_interrupts(int keys) {
40 if(keys == KEY_ALL) keys |= (1 << 14);
41 REG_KEYCTL ^= keys;
42 }