gbasys
diff src/input.c @ 8:047c61960005
- added bg2 matrix support
- changed some stupid const pointers to register addresses to hardcoded compile-time defines
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 22 Jun 2014 06:26:11 +0300 |
parents | 06726f0b8cd3 |
children | 85f219fcdc82 |
line diff
1.1 --- a/src/input.c Tue Sep 04 05:05:50 2012 +0300 1.2 +++ b/src/input.c Sun Jun 22 06:26:11 2014 +0300 1.3 @@ -20,18 +20,26 @@ 1.4 1.5 #include "input.h" 1.6 1.7 -volatile unsigned short *reg_key_state = (unsigned short*)0x4000130; 1.8 -volatile unsigned short *reg_key_cntl = (unsigned short*)0x4000132; 1.9 +#define REG_KEYSTATE (*(unsigned short*)0x4000130) 1.10 +#define REG_KEYCTL (*(unsigned short*)0x4000132) 1.11 1.12 int get_key_state(int key) { 1.13 - return ~(*reg_key_state) & key; 1.14 + int res; 1.15 + unsigned short prev_mask; 1.16 + 1.17 + prev_mask = REG_KEYCTL; 1.18 + disable_key_interrupts(key); 1.19 + 1.20 + res = ~REG_KEYSTATE & key; 1.21 + REG_KEYCTL = prev_mask; 1.22 + return res; 1.23 } 1.24 1.25 void enable_key_interrupts(int keys) { 1.26 - *reg_key_cntl |= (1 << 14) | keys; 1.27 + REG_KEYCTL |= (1 << 14) | keys; 1.28 } 1.29 1.30 void disable_key_interrupts(int keys) { 1.31 if(keys == KEY_ALL) keys |= (1 << 14); 1.32 - *reg_key_cntl ^= keys; 1.33 + REG_KEYCTL ^= keys; 1.34 }