Core Native GBA
0.0.17
create your own game-engine with just lua for nitendo game boy advance console.
Loading...
Searching...
No Matches
keys.c
Go to the documentation of this file.
1
#include "
zeebo.h
"
2
3
static
uint16_t
keys_current
= 0;
4
static
uint16_t
keys_old
= 0;
5
6
static
const
char
*
const
key_bindings
[] = {
7
"a"
,
8
"b"
,
9
"menu"
,
10
"menu"
,
11
"right"
,
12
"left"
,
13
"up"
,
14
"down"
,
15
"c"
,
16
"d"
17
};
18
19
static
void
key_update
(lua_State* L,
int
callback,
const
char
*
const
key, uint8_t value)
20
{
21
lua_rawgeti(L, LUA_REGISTRYINDEX, callback);
22
lua_pushstring(L, key);
23
lua_pushinteger(L, value);
24
lua_pcall(L, 2, 0, 0);
25
}
26
27
/**
28
* @li 1 released
29
* @li 0 pressing
30
*/
31
void
keys_callback_update
(lua_State* L,
int
callback)
32
{
33
uint16_t mask = 1;
34
uint8_t i = 0;
35
keys_current
= *(uint16_t*)(0x4000130);
36
37
while
(i <
sizeof
(
key_bindings
)) {
38
if
((
keys_current
&~
keys_old
) & mask) {
39
key_update
(L, callback,
key_bindings
[i], 0);
40
}
41
else
if
((~
keys_current
&
keys_old
) & mask) {
42
key_update
(L, callback,
key_bindings
[i], 1);
43
}
44
mask = mask << 1;
45
i = i + 1;
46
}
47
48
keys_old
=
keys_current
;
49
}
keys_old
static uint16_t keys_old
Definition
keys.c:4
keys_current
static uint16_t keys_current
Definition
keys.c:3
key_bindings
static const char *const key_bindings[]
Definition
keys.c:6
keys_callback_update
void keys_callback_update(lua_State *L, int callback)
Definition
keys.c:31
key_update
static void key_update(lua_State *L, int callback, const char *const key, uint8_t value)
Definition
keys.c:19
zeebo.h
src
keys.c
Generated by
1.12.0