kern

annotate 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
rev   line source
nuclear@1 1 #include "term.h"
nuclear@1 2 #include "vid.h"
nuclear@1 3
nuclear@1 4 static int bg, fg = 15;
nuclear@1 5 static int cursor_x, cursor_y;
nuclear@1 6
nuclear@1 7 void set_text_color(int c)
nuclear@1 8 {
nuclear@1 9 if(c >= 0 && c < 16) {
nuclear@1 10 fg = c;
nuclear@1 11 }
nuclear@1 12 }
nuclear@1 13
nuclear@1 14 void set_back_color(int c)
nuclear@1 15 {
nuclear@1 16 if(c >= 0 && c < 16) {
nuclear@1 17 bg = c;
nuclear@1 18 }
nuclear@1 19 }
nuclear@1 20
nuclear@1 21 int putchar(int c)
nuclear@1 22 {
nuclear@1 23 switch(c) {
nuclear@1 24 case '\n':
nuclear@1 25 cursor_y++;
nuclear@1 26
nuclear@1 27 case '\r':
nuclear@1 28 cursor_x = 0;
nuclear@1 29 break;
nuclear@1 30
nuclear@1 31 case '\b':
nuclear@1 32 cursor_x--;
nuclear@1 33 set_char(' ', cursor_x, cursor_y, fg, bg);
nuclear@1 34 break;
nuclear@1 35
nuclear@1 36 case '\t':
nuclear@1 37 cursor_x = ((cursor_x >> 3) + 1) << 3;
nuclear@1 38 break;
nuclear@1 39
nuclear@1 40 default:
nuclear@1 41 set_char(c, cursor_x, cursor_y, fg, bg);
nuclear@1 42 if(++cursor_x >= WIDTH) {
nuclear@1 43 cursor_x = 0;
nuclear@1 44 cursor_y++;
nuclear@1 45 }
nuclear@1 46 }
nuclear@1 47
nuclear@1 48 if(cursor_y >= HEIGHT) {
nuclear@1 49 scroll_scr();
nuclear@1 50 cursor_y--;
nuclear@1 51 }
nuclear@1 52 return c;
nuclear@1 53 }