Mercurial > lcfOS
annotate cos/kernel/video.c @ 92:0c4bdbf0aead
improvements?
author | windel |
---|---|
date | Sat, 15 Dec 2012 23:56:26 +0100 |
parents | d8627924d40d |
children |
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 |
24 | 21 void set_cursor(int newrow, int newcol) |
22 { | |
23 row = newrow; | |
24 col = newcol; | |
25 move_cursor(); | |
26 } | |
27 | |
28 void get_cursor(int *therow, int *thecol) | |
29 { | |
30 *therow = row; | |
31 *thecol = col; | |
32 } | |
33 | |
34 void set_color(int forecolor, int backcolor) | |
35 { | |
36 video_color = forecolor | (backcolor << 4); | |
37 } | |
38 | |
39 void clear_screen() | |
9 | 40 { |
41 unsigned char *vidmem = (unsigned char *) VIDMEM; | |
42 int loop; | |
43 | |
44 for (loop = 0; loop < SCREEN_SIZE; loop++) { | |
45 *vidmem++ = 0x20; | |
23 | 46 *vidmem++ = video_color; |
9 | 47 } |
48 } | |
49 | |
24 | 50 void init_screen() |
9 | 51 { |
52 clear_screen(); | |
24 | 53 set_cursor(0, 0); |
9 | 54 } |
55 | |
24 | 56 static void scroll_screen() |
9 | 57 { |
24 | 58 uint8_t* v; |
9 | 59 int i; |
60 | |
24 | 61 // Shift all lines one up: |
62 v = (uint8_t*)VIDMEM; | |
63 for (i = 0; i < SCREEN_SIZE; i++ ) | |
64 { | |
65 *v = *(v + NUM_COLS*2); | |
66 ++v; | |
67 *v = *(v + NUM_COLS*2); | |
9 | 68 ++v; |
69 } | |
70 | |
24 | 71 // Clear new line: |
72 v = (uint8_t*)VIDMEM + SCREEN_SIZE * 2 - NUM_COLS * 2; | |
73 for (i = 0; i < NUM_COLS; i++) | |
74 { | |
75 *v++ = ' '; | |
76 *v++ = video_color; | |
9 | 77 } |
78 } | |
79 | |
24 | 80 static void new_line() |
9 | 81 { |
82 ++row; | |
83 col = 0; | |
24 | 84 if (row == NUM_ROWS) |
85 { | |
9 | 86 scroll_screen(); |
87 row = NUM_ROWS - 1; | |
88 } | |
89 } | |
90 | |
24 | 91 static void clear_to_EOL() |
9 | 92 { |
93 int loop; | |
94 unsigned char *v = (unsigned char *) ((uint64_t)(VIDMEM + row * NUM_COLS * 2 + col * 2)); | |
95 | |
96 for (loop = col; loop < NUM_COLS; loop++) { | |
97 *v++ = ' '; | |
23 | 98 *v++ = video_color; |
9 | 99 } |
100 } | |
101 | |
24 | 102 static void print_char(int c) |
9 | 103 { |
104 unsigned char *v = (unsigned char *) ((uint64_t)(VIDMEM + row * NUM_COLS * 2 + col * 2)); | |
105 | |
106 switch(c) { | |
107 case '\n': | |
108 clear_to_EOL(); | |
109 new_line(); | |
110 break; | |
111 default: | |
112 *v++ = (unsigned char) c; | |
23 | 113 *v = video_color; |
9 | 114 |
115 if (col < NUM_COLS - 1) | |
116 ++col; | |
117 else | |
118 new_line(); | |
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 | 121 } |
122 | |
24 | 123 void print_string(const char *s) |
9 | 124 { |
24 | 125 while (*s != '\0') |
126 { | |
9 | 127 print_char(*s++); |
128 } | |
129 } | |
130 |