forked from luke8086/boot2c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbios.c
81 lines (64 loc) · 1.07 KB
/
bios.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* bios.c - BIOS services
*
* author: luke8086
* license: GPL-2
*/
#include "intr.h"
#include "bios.h"
void
toggle_cursor(int visible)
{
struct regs regs = {
.ah = 0x01,
.ch = (visible ? 0x06 : 0x20 ),
.cl = (visible ? 0x07 : 0x00 ),
};
intr(0x10, ®s);
}
void
move_cursor(int x, int y)
{
struct regs regs = {
.ah = 0x02,
.bh = 0x00,
.dh = y,
.dl = x,
};
intr(0x10, ®s);
}
void
put_char(char ascii)
{
struct regs regs = {
.ah = 0x0e,
.al = ascii,
.bh = 0x00,
};
intr(0x10, ®s);
}
int
check_keystroke(void)
{
struct regs regs = { .ah = 0x01 };
intr(0x16, ®s);
return !(regs.eflags & 0x0040);
}
struct keystroke
get_keystroke(void)
{
struct regs regs = { .ah = 0x00 };
intr(0x16, ®s);
struct keystroke ret = {
.scancode = regs.ah,
.ascii = regs.al,
};
return ret;
}
uint32_t
get_time(void)
{
struct regs regs = { .ah = 0x00 };
intr(0x1a, ®s);
return ((regs.cx << 16) | regs.dx);
}