-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.c
More file actions
91 lines (71 loc) · 1.42 KB
/
monitor.c
File metadata and controls
91 lines (71 loc) · 1.42 KB
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
82
83
84
85
86
87
88
89
90
91
#include "monitor.h"
u16int *video_memory = (u16int *)0xB8000;
u8int cursor_x = 0;
u8int cursor_y = 0;
static void move_cursor()
{
u16int cursorLocation = cursor_y * cursor_x;
outb(0x3D4, 14);
outb(0x3D5,cursorLocation >> 8);
outb(0x3D4, 15);
outb(0x3D5, cursorLocation);
}
static void scroll()
{
u8int attributeByte = (0 << 4) | (15 & 0x0F);
u16int blank = 0x20;
if (cursor_y >= 5) {
int i;
for (i = 0*80; i < 24 * 80; i++) {
video_memory[i] = video_memory[i+80];
}
for (i = 24 * 80; i < 25 * 80; i++) {
video_memory[i] = blank;
}
cursor_y = 24;
}
}
void monitor_put(char c)
{
u8int backColor = 0;
u8int foreColor = 15;
u8int attributeByte = (backColor << 4) | (foreColor & 0x0F);
u16int attribute = attributeByte << 8;
u16int *location;
if (c == 0x08 && cursor_x) {
cursor_x--;
} else if (c == '\r') {
cursor_x = 0;
} else if (c == '\n') {
cursor_y++;
} else if (c >= ' ') {
location = video_memory + (cursor_y * 80 + cursor_x);
*location = c | attribute;
cursor_x++;
}
if (cursor_x >= 80) {
cursor_x = 0;
cursor_y++;
}
scroll();
move_cursor();
}
void monitor_clear()
{
u8int attributeByte = (0 << 4) | (15 & 0x0F);
u16int blank = 0x20 | (attributeByte << 8);
int i;
for (i = 0; i < 80 * 25; i++) {
video_memory[i] = blank;
}
cursor_x = 0;
cursor_y = 0;
move_cursor();
}
void monitor_write(char *c)
{
int i = 0;
while (c[i]) {
monitor_put(c[i++]);
}
}