improve --showvars output with help
[rofl0r-gnuboy.git] / events.c
blobc6ee9544d7377f854b13fd10e3fb1d2759d0db95
1 /*
2 * events.c
4 * Event queue.
5 */
8 #include "input.h"
11 char keystates[MAX_KEYS];
12 int nkeysdown;
14 #define MAX_EVENTS 32
16 static event_t eventqueue[MAX_EVENTS];
17 static int eventhead, eventpos;
20 int ev_postevent(event_t *ev)
22 int nextevent;
23 nextevent = (eventhead+1)%MAX_EVENTS;
24 if (nextevent == eventpos)
25 return 0;
26 eventqueue[eventhead] = *ev;
27 eventhead = nextevent;
28 return 1;
31 int ev_getevent(event_t *ev)
33 if (eventpos == eventhead)
35 ev->type = EV_NONE;
36 return 0;
38 *ev = eventqueue[eventpos];
39 eventpos = (eventpos+1)%MAX_EVENTS;
40 if (ev->type == EV_PRESS)
42 keystates[ev->code] = 1;
43 nkeysdown++;
45 if (ev->type == EV_RELEASE)
47 keystates[ev->code] = 0;
48 nkeysdown--;
49 if (nkeysdown < 0) nkeysdown = 0;
51 return 1;