kern

annotate src/term.c @ 52:fa65b4f45366

picking this up again, let's fix it
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 07 Aug 2011 06:42:00 +0300
parents 06172322fb76
children
rev   line source
nuclear@4 1 #include <ctype.h>
nuclear@1 2 #include "term.h"
nuclear@1 3 #include "vid.h"
nuclear@52 4 #include "intr.h"
nuclear@1 5
nuclear@2 6 static int bg, fg = LTGRAY;
nuclear@1 7 static int cursor_x, cursor_y;
nuclear@1 8
nuclear@2 9 /* sets the active text color and returns previous value */
nuclear@2 10 int set_text_color(int c)
nuclear@1 11 {
nuclear@2 12 int prev = fg;
nuclear@2 13
nuclear@1 14 if(c >= 0 && c < 16) {
nuclear@1 15 fg = c;
nuclear@1 16 }
nuclear@2 17 return prev;
nuclear@1 18 }
nuclear@1 19
nuclear@2 20 /* sets the active background color and returns the current value */
nuclear@2 21 int set_back_color(int c)
nuclear@1 22 {
nuclear@2 23 int prev = bg;
nuclear@2 24
nuclear@1 25 if(c >= 0 && c < 16) {
nuclear@1 26 bg = c;
nuclear@1 27 }
nuclear@2 28 return prev;
nuclear@1 29 }
nuclear@1 30
nuclear@2 31 /* output a single character, handles formatting, cursor advancement
nuclear@2 32 * and scrolling the screen when we reach the bottom.
nuclear@2 33 */
nuclear@1 34 int putchar(int c)
nuclear@1 35 {
nuclear@52 36 int istate = get_intr_state();
nuclear@52 37 disable_intr();
nuclear@52 38
nuclear@1 39 switch(c) {
nuclear@1 40 case '\n':
nuclear@1 41 cursor_y++;
nuclear@1 42
nuclear@1 43 case '\r':
nuclear@1 44 cursor_x = 0;
nuclear@1 45 break;
nuclear@1 46
nuclear@1 47 case '\b':
nuclear@1 48 cursor_x--;
nuclear@1 49 set_char(' ', cursor_x, cursor_y, fg, bg);
nuclear@1 50 break;
nuclear@1 51
nuclear@1 52 case '\t':
nuclear@1 53 cursor_x = ((cursor_x >> 3) + 1) << 3;
nuclear@1 54 break;
nuclear@1 55
nuclear@1 56 default:
nuclear@2 57 if(isprint(c)) {
nuclear@2 58 set_char(c, cursor_x, cursor_y, fg, bg);
nuclear@2 59 if(++cursor_x >= WIDTH) {
nuclear@2 60 cursor_x = 0;
nuclear@2 61 cursor_y++;
nuclear@2 62 }
nuclear@1 63 }
nuclear@1 64 }
nuclear@1 65
nuclear@1 66 if(cursor_y >= HEIGHT) {
nuclear@1 67 scroll_scr();
nuclear@1 68 cursor_y--;
nuclear@1 69 }
nuclear@2 70
nuclear@2 71 set_cursor(cursor_x, cursor_y);
nuclear@52 72
nuclear@52 73 set_intr_state(istate);
nuclear@1 74 return c;
nuclear@1 75 }