-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.c
61 lines (58 loc) · 1.09 KB
/
console.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
#include "console.h"
#define S_COLS 80
#define S_ROWS 25
int row = 0, col = 0;
char* video = (char*) 0xb8000;
void kcls()
{
for (int i = 0; i < 2*S_ROWS*S_COLS; i++)
{
video[i] = 0;
}
col = 0;
row = 0;
}
void kputs( char* string )
{
int i;
for (i = 0; string[i] != '\0'; i++)
{
if ( ( string[i] == '\n' ) || ( col == S_COLS ) )
{
row++;
if ( row == S_ROWS )
{
kscroll();
row--;
}
col = 0;
}
if ( string[i] != '\n' )
{
video[(row * S_COLS + col)*2] = string[i];
video[(row * S_COLS + col)*2+1] = 0x07;
col++;
}
}
}
void kscroll()
{
for( int scroll_line = 0; scroll_line<S_ROWS; scroll_line++ )
{
if (scroll_line != S_ROWS-1)
{
for(int i=0; i < S_COLS; i++)
{
video[(scroll_line * S_COLS + i)*2] = video[((scroll_line +1 ) * S_COLS + i ) * 2];
video[(scroll_line * S_COLS + i)*2+1] = video[((scroll_line +1 ) * S_COLS + i ) * 2+1];
}
}
else
{
for(int i=0; i < 2 * S_COLS; i++)
{
video[scroll_line * S_COLS + i] = 0;
}
}
}
}