-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtty.c
59 lines (49 loc) · 866 Bytes
/
tty.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
#include <tty.h>
#include <cpu.h>
struct line
{
unsigned short text[80];
};
static struct line buffer[40];
static int buf_line;
static int buf_pos;
void tty_write_str(const char *str)
{
char c;
do
{
c = *str++;
tty_putchar(c);
} while(c);
}
void tty_putchar(unsigned char c)
{
if(c == '\t')
{
buffer[buf_line].text[buf_pos+0] = ' ';
buffer[buf_line].text[buf_pos+1] = ' ';
buffer[buf_line].text[buf_pos+2] = ' ';
buffer[buf_line].text[buf_pos+3] = ' ';
buf_pos += 4;
}
if(c == '\n' || buf_pos >= 80)
{
buf_pos = 0;
buf_line++;
buffer[buf_line].text[0] = 0;
if(buf_line >= 40)
buf_line = 0;
}
if(c != '\n' && c != '\t')
buffer[buf_line].text[buf_pos++] = c;
}
unsigned short *tty_get_line(int n)
{
int line;
line = buf_line + n;
if(line > 40)
line -= 40;
if(line < 0)
line += 40;
return buffer[line].text;
}