kern

view src/term.c @ 1:ebe5e0e44a9d

pretty much finished the code for article 1, might do minor adjustments though
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 02 Dec 2010 08:45:41 +0200
parents
children 86781ef20689
line source
1 #include "term.h"
2 #include "vid.h"
4 static int bg, fg = 15;
5 static int cursor_x, cursor_y;
7 void set_text_color(int c)
8 {
9 if(c >= 0 && c < 16) {
10 fg = c;
11 }
12 }
14 void set_back_color(int c)
15 {
16 if(c >= 0 && c < 16) {
17 bg = c;
18 }
19 }
21 int putchar(int c)
22 {
23 switch(c) {
24 case '\n':
25 cursor_y++;
27 case '\r':
28 cursor_x = 0;
29 break;
31 case '\b':
32 cursor_x--;
33 set_char(' ', cursor_x, cursor_y, fg, bg);
34 break;
36 case '\t':
37 cursor_x = ((cursor_x >> 3) + 1) << 3;
38 break;
40 default:
41 set_char(c, cursor_x, cursor_y, fg, bg);
42 if(++cursor_x >= WIDTH) {
43 cursor_x = 0;
44 cursor_y++;
45 }
46 }
48 if(cursor_y >= HEIGHT) {
49 scroll_scr();
50 cursor_y--;
51 }
52 return c;
53 }