kern

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/term.c	Thu Dec 02 08:45:41 2010 +0200
     1.3 @@ -0,0 +1,53 @@
     1.4 +#include "term.h"
     1.5 +#include "vid.h"
     1.6 +
     1.7 +static int bg, fg = 15;
     1.8 +static int cursor_x, cursor_y;
     1.9 +
    1.10 +void set_text_color(int c)
    1.11 +{
    1.12 +	if(c >= 0 && c < 16) {
    1.13 +		fg = c;
    1.14 +	}
    1.15 +}
    1.16 +
    1.17 +void set_back_color(int c)
    1.18 +{
    1.19 +	if(c >= 0 && c < 16) {
    1.20 +		bg = c;
    1.21 +	}
    1.22 +}
    1.23 +
    1.24 +int putchar(int c)
    1.25 +{
    1.26 +	switch(c) {
    1.27 +	case '\n':
    1.28 +		cursor_y++;
    1.29 +
    1.30 +	case '\r':
    1.31 +		cursor_x = 0;
    1.32 +		break;
    1.33 +
    1.34 +	case '\b':
    1.35 +		cursor_x--;
    1.36 +		set_char(' ', cursor_x, cursor_y, fg, bg);
    1.37 +		break;
    1.38 +
    1.39 +	case '\t':
    1.40 +		cursor_x = ((cursor_x >> 3) + 1) << 3;
    1.41 +		break;
    1.42 +
    1.43 +	default:
    1.44 +		set_char(c, cursor_x, cursor_y, fg, bg);
    1.45 +		if(++cursor_x >= WIDTH) {
    1.46 +			cursor_x = 0;
    1.47 +			cursor_y++;
    1.48 +		}
    1.49 +	}
    1.50 +
    1.51 +	if(cursor_y >= HEIGHT) {
    1.52 +		scroll_scr();
    1.53 +		cursor_y--;
    1.54 +	}
    1.55 +	return c;
    1.56 +}