kern

view src/term.c @ 2:86781ef20689

added hardware scrolling, memset16 and temporary keyboard input for testing
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 04 Dec 2010 08:04:43 +0200
parents ebe5e0e44a9d
children 0489a34ab348
line source
1 #include "term.h"
2 #include "vid.h"
4 static int bg, fg = LTGRAY;
5 static int cursor_x, cursor_y;
7 /* sets the active text color and returns previous value */
8 int set_text_color(int c)
9 {
10 int prev = fg;
12 if(c >= 0 && c < 16) {
13 fg = c;
14 }
15 return prev;
16 }
18 /* sets the active background color and returns the current value */
19 int set_back_color(int c)
20 {
21 int prev = bg;
23 if(c >= 0 && c < 16) {
24 bg = c;
25 }
26 return prev;
27 }
29 /* output a single character, handles formatting, cursor advancement
30 * and scrolling the screen when we reach the bottom.
31 * TODO make visible cursor actually move.
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 }