Mercurial > lcfOS
annotate cos/kernel/video.c @ 23:5dd47d6eebac
Added ubersimple malloc algorithm
author | windel |
---|---|
date | Thu, 01 Dec 2011 21:42:59 +0100 |
parents | 6129643f5c34 |
children | d8627924d40d |
rev | line source |
---|---|
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 static int row, col; | |
23 | 10 uint8_t video_color = 0x1F; |
9 | 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 |
9 | 21 void |
22 clear_screen() | |
23 { | |
24 unsigned char *vidmem = (unsigned char *) VIDMEM; | |
25 int loop; | |
26 | |
27 for (loop = 0; loop < SCREEN_SIZE; loop++) { | |
28 *vidmem++ = 0x20; | |
23 | 29 *vidmem++ = video_color; |
9 | 30 } |
31 } | |
32 | |
33 void | |
34 init_screen() | |
35 { | |
36 row = col = 0; | |
37 clear_screen(); | |
18
6129643f5c34
Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents:
9
diff
changeset
|
38 move_cursor(); |
9 | 39 } |
40 | |
41 | |
42 static void | |
43 scroll_screen() | |
44 { | |
45 unsigned short* v; | |
46 int i; | |
47 int n = SCREEN_SIZE; | |
48 | |
49 for (v = (unsigned short*) VIDMEM, i = 0; i < n; i++ ) { | |
50 *v = *(v + NUM_COLS); | |
51 ++v; | |
52 } | |
53 | |
54 for (v = (unsigned short*) VIDMEM + n, i = 0; i < NUM_COLS; i++) { | |
23 | 55 *v++ = (video_color << 8) & 0x20; |
9 | 56 } |
57 } | |
58 | |
59 static void | |
60 new_line() | |
61 { | |
62 ++row; | |
63 col = 0; | |
64 if (row == NUM_ROWS) { | |
65 scroll_screen(); | |
66 row = NUM_ROWS - 1; | |
67 } | |
68 } | |
69 | |
70 static void | |
71 clear_to_EOL() | |
72 { | |
73 int loop; | |
74 unsigned char *v = (unsigned char *) ((uint64_t)(VIDMEM + row * NUM_COLS * 2 + col * 2)); | |
75 | |
76 for (loop = col; loop < NUM_COLS; loop++) { | |
77 *v++ = ' '; | |
23 | 78 *v++ = video_color; |
9 | 79 } |
80 } | |
81 | |
82 static void | |
83 print_char(int c) | |
84 { | |
85 unsigned char *v = (unsigned char *) ((uint64_t)(VIDMEM + row * NUM_COLS * 2 + col * 2)); | |
86 | |
87 switch(c) { | |
88 case '\n': | |
89 clear_to_EOL(); | |
90 new_line(); | |
91 break; | |
92 default: | |
93 *v++ = (unsigned char) c; | |
23 | 94 *v = video_color; |
9 | 95 |
96 if (col < NUM_COLS - 1) | |
97 ++col; | |
98 else | |
99 new_line(); | |
100 } | |
18
6129643f5c34
Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents:
9
diff
changeset
|
101 move_cursor(); |
9 | 102 } |
103 | |
104 void | |
105 print_string(const char *s) | |
106 { | |
107 while (*s != '\0') { | |
108 print_char(*s++); | |
109 } | |
110 } | |
111 |