kern
view src/term.c @ 46:b793b8fcba7d
apparently free_phys_page was never tested. the check for double-freeing a page
was inverted.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 28 Jul 2011 05:33:59 +0300 |
parents | 0489a34ab348 |
children | fa65b4f45366 |
line source
1 #include <ctype.h>
2 #include "term.h"
3 #include "vid.h"
5 static int bg, fg = LTGRAY;
6 static int cursor_x, cursor_y;
8 /* sets the active text color and returns previous value */
9 int set_text_color(int c)
10 {
11 int prev = fg;
13 if(c >= 0 && c < 16) {
14 fg = c;
15 }
16 return prev;
17 }
19 /* sets the active background color and returns the current value */
20 int set_back_color(int c)
21 {
22 int prev = bg;
24 if(c >= 0 && c < 16) {
25 bg = c;
26 }
27 return prev;
28 }
30 /* output a single character, handles formatting, cursor advancement
31 * and scrolling the screen when we reach the bottom.
32 */
33 int putchar(int c)
34 {
35 switch(c) {
36 case '\n':
37 cursor_y++;
39 case '\r':
40 cursor_x = 0;
41 break;
43 case '\b':
44 cursor_x--;
45 set_char(' ', cursor_x, cursor_y, fg, bg);
46 break;
48 case '\t':
49 cursor_x = ((cursor_x >> 3) + 1) << 3;
50 break;
52 default:
53 if(isprint(c)) {
54 set_char(c, cursor_x, cursor_y, fg, bg);
55 if(++cursor_x >= WIDTH) {
56 cursor_x = 0;
57 cursor_y++;
58 }
59 }
60 }
62 if(cursor_y >= HEIGHT) {
63 scroll_scr();
64 cursor_y--;
65 }
67 set_cursor(cursor_x, cursor_y);
68 return c;
69 }