9
|
1 #include "kernel.h"
|
|
2
|
|
3 #define VIDMEM 0xB8000
|
|
4
|
|
5 #define NUM_COLS 80
|
|
6 #define NUM_ROWS 25
|
|
7 #define SCREEN_SIZE (NUM_COLS * NUM_ROWS)
|
|
8
|
|
9 #define SCREEN_ATTR 0x0F
|
|
10
|
|
11 static int row, col;
|
|
12
|
|
13 void
|
|
14 clear_screen()
|
|
15 {
|
|
16 unsigned char *vidmem = (unsigned char *) VIDMEM;
|
|
17 int loop;
|
|
18
|
|
19 for (loop = 0; loop < SCREEN_SIZE; loop++) {
|
|
20 *vidmem++ = 0x20;
|
|
21 *vidmem++ = SCREEN_ATTR;
|
|
22 }
|
|
23 }
|
|
24
|
|
25 void
|
|
26 init_screen()
|
|
27 {
|
|
28 row = col = 0;
|
|
29 clear_screen();
|
|
30 }
|
|
31
|
|
32
|
|
33 static void
|
|
34 scroll_screen()
|
|
35 {
|
|
36 unsigned short* v;
|
|
37 int i;
|
|
38 int n = SCREEN_SIZE;
|
|
39
|
|
40 for (v = (unsigned short*) VIDMEM, i = 0; i < n; i++ ) {
|
|
41 *v = *(v + NUM_COLS);
|
|
42 ++v;
|
|
43 }
|
|
44
|
|
45 for (v = (unsigned short*) VIDMEM + n, i = 0; i < NUM_COLS; i++) {
|
|
46 *v++ = SCREEN_ATTR & (0x20 << 8);
|
|
47 }
|
|
48 }
|
|
49
|
|
50 static void
|
|
51 new_line()
|
|
52 {
|
|
53 ++row;
|
|
54 col = 0;
|
|
55 if (row == NUM_ROWS) {
|
|
56 scroll_screen();
|
|
57 row = NUM_ROWS - 1;
|
|
58 }
|
|
59 }
|
|
60
|
|
61 static void
|
|
62 clear_to_EOL()
|
|
63 {
|
|
64 int loop;
|
|
65 unsigned char *v = (unsigned char *) ((uint64_t)(VIDMEM + row * NUM_COLS * 2 + col * 2));
|
|
66
|
|
67 for (loop = col; loop < NUM_COLS; loop++) {
|
|
68 *v++ = ' ';
|
|
69 *v++ = SCREEN_ATTR;
|
|
70 }
|
|
71 }
|
|
72
|
|
73 static void
|
|
74 print_char(int c)
|
|
75 {
|
|
76 unsigned char *v = (unsigned char *) ((uint64_t)(VIDMEM + row * NUM_COLS * 2 + col * 2));
|
|
77
|
|
78 switch(c) {
|
|
79 case '\n':
|
|
80 clear_to_EOL();
|
|
81 new_line();
|
|
82 break;
|
|
83 default:
|
|
84 *v++ = (unsigned char) c;
|
|
85 *v = SCREEN_ATTR;
|
|
86
|
|
87 if (col < NUM_COLS - 1)
|
|
88 ++col;
|
|
89 else
|
|
90 new_line();
|
|
91 }
|
|
92 }
|
|
93
|
|
94 void
|
|
95 print_string(const char *s)
|
|
96 {
|
|
97 while (*s != '\0') {
|
|
98 print_char(*s++);
|
|
99 }
|
|
100 }
|
|
101
|