annotate cos/kernel/video.c @ 16:ddefe6d97cd7

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