forked from rofl0r/gnuboy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.c
60 lines (43 loc) · 768 Bytes
/
events.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* events.c
*
* Event queue.
*/
#include "input.h"
char keystates[MAX_KEYS];
int nkeysdown;
#define MAX_EVENTS 32
static event_t eventqueue[MAX_EVENTS];
static int eventhead, eventpos;
int ev_postevent(event_t *ev)
{
int nextevent;
nextevent = (eventhead+1)%MAX_EVENTS;
if (nextevent == eventpos)
return 0;
eventqueue[eventhead] = *ev;
eventhead = nextevent;
return 1;
}
int ev_getevent(event_t *ev)
{
if (eventpos == eventhead)
{
ev->type = EV_NONE;
return 0;
}
*ev = eventqueue[eventpos];
eventpos = (eventpos+1)%MAX_EVENTS;
if (ev->type == EV_PRESS)
{
keystates[ev->code] = 1;
nkeysdown++;
}
if (ev->type == EV_RELEASE)
{
keystates[ev->code] = 0;
nkeysdown--;
if (nkeysdown < 0) nkeysdown = 0;
}
return 1;
}