annotate cos/kernel/video.c @ 271:cf7d5fb7d9c8

Reorganization
author Windel Bouwman
date Tue, 20 Aug 2013 18:56:02 +0200
parents d8627924d40d
children
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 static int row, col;
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 18
diff changeset
10 uint8_t video_color = 0x1F;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
11
18
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
12 void move_cursor()
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
13 {
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
14 uint16_t cursorLocation = row * 80 + col;
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
15 outb(0x3D4, 14);
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
16 outb(0x3D5, cursorLocation >> 8);
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
17 outb(0x3D4, 15);
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
18 outb(0x3D5, cursorLocation & 0xFF);
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
19 }
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
20
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
21 void set_cursor(int newrow, int newcol)
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
22 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
23 row = newrow;
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
24 col = newcol;
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
25 move_cursor();
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
26 }
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
27
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
28 void get_cursor(int *therow, int *thecol)
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
29 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
30 *therow = row;
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
31 *thecol = col;
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
32 }
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
33
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
34 void set_color(int forecolor, int backcolor)
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
35 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
36 video_color = forecolor | (backcolor << 4);
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
37 }
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
38
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
39 void clear_screen()
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
40 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
41 unsigned char *vidmem = (unsigned char *) VIDMEM;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
42 int loop;
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 for (loop = 0; loop < SCREEN_SIZE; loop++) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
45 *vidmem++ = 0x20;
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 18
diff changeset
46 *vidmem++ = video_color;
9
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
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
50 void init_screen()
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
51 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
52 clear_screen();
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
53 set_cursor(0, 0);
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
54 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
55
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
56 static void scroll_screen()
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
57 {
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
58 uint8_t* v;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
59 int i;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
60
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
61 // Shift all lines one up:
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
62 v = (uint8_t*)VIDMEM;
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
63 for (i = 0; i < SCREEN_SIZE; i++ )
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
64 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
65 *v = *(v + NUM_COLS*2);
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
66 ++v;
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
67 *v = *(v + NUM_COLS*2);
9
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 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
70
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
71 // Clear new line:
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
72 v = (uint8_t*)VIDMEM + SCREEN_SIZE * 2 - NUM_COLS * 2;
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
73 for (i = 0; i < NUM_COLS; i++)
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
74 {
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
75 *v++ = ' ';
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
76 *v++ = video_color;
9
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 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
79
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
80 static void new_line()
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
81 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
82 ++row;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
83 col = 0;
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
84 if (row == NUM_ROWS)
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
85 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
86 scroll_screen();
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
87 row = NUM_ROWS - 1;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
88 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
89 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
90
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
91 static void clear_to_EOL()
9
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 int loop;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
94 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
95
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
96 for (loop = col; loop < NUM_COLS; loop++) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
97 *v++ = ' ';
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 18
diff changeset
98 *v++ = video_color;
9
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
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
102 static void print_char(int c)
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
103 {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
104 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
105
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
106 switch(c) {
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
107 case '\n':
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
108 clear_to_EOL();
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
109 new_line();
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
110 break;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
111 default:
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
112 *v++ = (unsigned char) c;
23
5dd47d6eebac Added ubersimple malloc algorithm
windel
parents: 18
diff changeset
113 *v = video_color;
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
114
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
115 if (col < NUM_COLS - 1)
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
116 ++col;
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
117 else
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
118 new_line();
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
119 }
18
6129643f5c34 Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents: 9
diff changeset
120 move_cursor();
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
121 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
122
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
123 void print_string(const char *s)
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
124 {
24
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
125 while (*s != '\0')
d8627924d40d Split up in more files and reboot command
windel
parents: 23
diff changeset
126 {
9
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
127 print_char(*s++);
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
128 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
129 }
92ace1ca50a8 64 bits kernel without interrupts but with printf in C
windel
parents:
diff changeset
130