kern

diff 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 diff
     1.1 --- a/src/term.c	Thu Dec 02 08:45:41 2010 +0200
     1.2 +++ b/src/term.c	Sat Dec 04 08:04:43 2010 +0200
     1.3 @@ -1,23 +1,35 @@
     1.4  #include "term.h"
     1.5  #include "vid.h"
     1.6  
     1.7 -static int bg, fg = 15;
     1.8 +static int bg, fg = LTGRAY;
     1.9  static int cursor_x, cursor_y;
    1.10  
    1.11 -void set_text_color(int c)
    1.12 +/* sets the active text color and returns previous value */
    1.13 +int set_text_color(int c)
    1.14  {
    1.15 +	int prev = fg;
    1.16 +
    1.17  	if(c >= 0 && c < 16) {
    1.18  		fg = c;
    1.19  	}
    1.20 +	return prev;
    1.21  }
    1.22  
    1.23 -void set_back_color(int c)
    1.24 +/* sets the active background color and returns the current value */
    1.25 +int set_back_color(int c)
    1.26  {
    1.27 +	int prev = bg;
    1.28 +
    1.29  	if(c >= 0 && c < 16) {
    1.30  		bg = c;
    1.31  	}
    1.32 +	return prev;
    1.33  }
    1.34  
    1.35 +/* output a single character, handles formatting, cursor advancement
    1.36 + * and scrolling the screen when we reach the bottom.
    1.37 + * TODO make visible cursor actually move.
    1.38 + */
    1.39  int putchar(int c)
    1.40  {
    1.41  	switch(c) {
    1.42 @@ -38,10 +50,12 @@
    1.43  		break;
    1.44  
    1.45  	default:
    1.46 -		set_char(c, cursor_x, cursor_y, fg, bg);
    1.47 -		if(++cursor_x >= WIDTH) {
    1.48 -			cursor_x = 0;
    1.49 -			cursor_y++;
    1.50 +		if(isprint(c)) {
    1.51 +			set_char(c, cursor_x, cursor_y, fg, bg);
    1.52 +			if(++cursor_x >= WIDTH) {
    1.53 +				cursor_x = 0;
    1.54 +				cursor_y++;
    1.55 +			}
    1.56  		}
    1.57  	}
    1.58  
    1.59 @@ -49,5 +63,7 @@
    1.60  		scroll_scr();
    1.61  		cursor_y--;
    1.62  	}
    1.63 +
    1.64 +	set_cursor(cursor_x, cursor_y);
    1.65  	return c;
    1.66  }