-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathemu-con.c
65 lines (45 loc) · 1.14 KB
/
emu-con.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
53
54
55
56
57
58
59
60
61
62
63
64
65
//------------------------------------------------------------------------------
// EMU86 - Generic console
//------------------------------------------------------------------------------
#include "emu-con.h"
#include <stddef.h>
#include <stdlib.h>
// Keyboard queue
// Key enqueued by con_proc() through con_put_key()
// Key dequeued by con_get_key() & con_poll()
typedef struct _key_s
{
list_s node;
word_t k;
} key_s;
static list_s key_queue;
void con_put_key (word_t k)
{
key_s * key = malloc (sizeof (key_s));
if (key) {
list_insert_after (&key_queue, &key->node);
key->k = k;
}
}
int con_get_key (word_t * pk)
{
list_s * next = key_queue.next;
// WARNING : non-blocking call with SDL console
if (next == &key_queue) return 1; // no key
key_s * key = structof (key_s, node, next);
*pk = key->k;
list_remove (next);
free (next);
return 0; // got key
}
int con_poll_key (void)
{
list_s * next = key_queue.next;
if (next != &key_queue) return 1; // has key
return 0; // no key
}
void con_init_key ()
{
list_init (&key_queue);
}
//------------------------------------------------------------------------------