]> git.dujemihanovic.xyz Git - nameless-os.git/blob - kernel/arch/x86/tty/tty.c
d3ef87b1d862290002347932aaa03c8b02f2e4b0
[nameless-os.git] / kernel / arch / x86 / tty / tty.c
1 #define VGA_WIDTH 80
2 #define VGA_HEIGHT 25
3
4 volatile char *video_memory = (char *) 0xB8000; /* VGA VRAM starts at 0xB8000 */
5
6 static int cursor_x = 0;
7 static int cursor_y = 0;
8
9 void screen_clear(void)
10 {
11 int x, y;
12 for ( y = 0; y < VGA_HEIGHT; y++ ) {
13 for ( x = 0; x < VGA_WIDTH; x++ ) {
14 video_memory[(y * VGA_WIDTH + x) * 2 + 1] = 0x07;
15 video_memory[(y * VGA_WIDTH + x) * 2] = ' ';
16 }
17 }
18
19 cursor_x = 0;
20 cursor_y = 0;
21 }
22
23 void scroll_up(void)
24 {
25 int x, y;
26 for ( y = 1; y < VGA_HEIGHT; y++ ) {
27 for ( x = 0; x < VGA_WIDTH; x++ ) {
28 video_memory[((y - 1) * VGA_WIDTH + x) * 2] = video_memory[(y * VGA_WIDTH + x) * 2];
29 }
30 }
31 for ( x = 0; x < VGA_WIDTH; x++ ) {
32 video_memory[((VGA_HEIGHT - 1) * VGA_WIDTH + x) * 2] = ' ';
33 }
34 cursor_y = VGA_HEIGHT - 1;
35 }
36
37 void kprint(const char *string)
38 {
39 char next_char;
40 next_char = *string;
41
42 while ( next_char != 0 ) {
43 if ( next_char == '\n') { cursor_x = 0; cursor_y++; }
44 else { video_memory[(cursor_y * VGA_WIDTH + cursor_x++) * 2] = next_char; }
45 if ( cursor_x >= VGA_WIDTH ) { cursor_x = 0; cursor_y++; }
46 if ( cursor_y >= VGA_HEIGHT ) { scroll_up(); }
47 next_char = *++string;
48 }
49 }