-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.c
executable file
·52 lines (44 loc) · 1 KB
/
input.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
#include "devices/input.h"
#include <debug.h>
#include "devices/intq.h"
#include "devices/serial.h"
/* Stores keys from the keyboard and serial port. */
static struct intq buffer;
/* Initializes the input buffer. */
void
input_init (void)
{
intq_init (&buffer);
}
/* Adds a key to the input buffer.
Interrupts must be off and the buffer must not be full. */
void
input_putc (uint8_t key)
{
ASSERT (intr_get_level () == INTR_OFF);
ASSERT (!intq_full (&buffer));
intq_putc (&buffer, key);
serial_notify ();
}
/* Retrieves a key from the input buffer.
If the buffer is empty, waits for a key to be pressed. */
uint8_t
input_getc (void)
{
enum intr_level old_level;
uint8_t key;
old_level = intr_disable ();
key = intq_getc (&buffer);
serial_notify ();
intr_set_level (old_level);
return key;
}
/* Returns true if the input buffer is full,
false otherwise.
Interrupts must be off. */
bool
input_full (void)
{
ASSERT (intr_get_level () == INTR_OFF);
return intq_full (&buffer);
}