kern

annotate src/term.c @ 49:50730d42d2d3

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