From 1252a288665a7d07dcf5f0e468dc67b9440132d0 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Mon, 25 May 2015 20:43:27 +0200 Subject: working on fool-term --- terminal/terminal.c | 312 +++++++++++++++++++++++----------------------------- 1 file changed, 138 insertions(+), 174 deletions(-) (limited to 'terminal/terminal.c') diff --git a/terminal/terminal.c b/terminal/terminal.c index add207a..05e89d9 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -8,8 +8,6 @@ #include "kernel/kmalloc.h" #include "driver/screen.h" - - typedef enum { ecma48_reset, @@ -50,42 +48,11 @@ typedef enum { ecma48_bg_default =49, }terminal_settings; - - -// deprecated -#define VT52_WIDTH 75 -#define VT52_HEIGHT 24 - -#define VT52_ESC_1 0x1b //ESC - -#define VT52_UP 'A' -#define VT52_DOWN 'B' -#define VT52_RIGHT 'C' -#define VT52_LEFT 'D' -#define VT52_GRAPH_ON 'F' -#define VT52_GRAPH_OFF 'G' -#define VT52_HOME 'H' -#define VT52_REV_FEED 'I' -#define VT52_ERASE_SCR 'J' -#define VT52_ERASE_LINE 'K' -#define VT52_KEYPAD_ON '=' -#define VT52_KEYPAD_OFF '>' - -#define VT52_EXIT '<' - -#define VT52_ENTER_AUTOPRINT '^' -#define VT52_EXIT_AUTOPRINT '_' - -#define VT52_PRINT_LINE 'W' -#define VT52_ENTER_PRINT 'W' -#define VT52_EXIT_PRINT 'X' -#define VT52_PRINT ']' -#define VT52_JUMP 'Y' // followed by LINE COL (subtr -32 from val) -#define VT52_IDENTIFY 'Z' -#define VT52_IDENTIFY_TO_HOST "/Z" // #define NPAR_START 1000 +#define TERM_WIDTH 80 +#define TERM_HEIGHT 24 static uint32_t index(terminal_tty *tty, uint32_t x, uint32_t y) { @@ -102,8 +69,33 @@ static void set_char(terminal_tty *tty, uint32_t x, uint32_t y, uint8_t c, uint8 static void process_graphic_npar(terminal_tty *tty, terminal_settings s) { + uint8_t buf; + switch(s) { + case ecma48_reset: + tty->fg=SCR_WHITE; + tty->bg=SCR_BLACK; + break; + + case ecma48_reverse_video: + + if(tty->reverse_video)break; + buf=tty->fg; + tty->fg=tty->bg; + tty->bg=buf; + break; + + case ecma48_reverse_video_off: + + if(!tty->reverse_video)break; + buf=tty->fg; + tty->fg=tty->bg; + tty->bg=buf; + break; + + //fg + case ecma48_fg_black: tty->fg=SCR_BLACK; break; @@ -135,8 +127,7 @@ static void process_graphic_npar(terminal_tty *tty, terminal_settings s) case ecma48_fg_white: tty->fg=SCR_WHITE; break; - - + // bg case ecma48_bg_black: tty->bg=SCR_BLACK; @@ -170,14 +161,8 @@ static void process_graphic_npar(terminal_tty *tty, terminal_settings s) tty->bg=SCR_WHITE; break; - - - - - - case ecma48_bg_default: - tty->fg=SCR_BLACK; + tty->bg=SCR_BLACK; break; } @@ -208,9 +193,6 @@ static void process_graphic_npars(terminal_tty *tty) tty->npar=0; - - - } static void reset(terminal_tty *tty) @@ -250,8 +232,10 @@ terminal_tty terminal_init(term_out *screen,term_in *input) tty.x=0; tty.y=0; - tty.width=VT52_WIDTH; - tty.height=VT52_HEIGHT; + tty.width=TERM_WIDTH; + tty.height=TERM_HEIGHT; + + tty.reverse_video=false; reset(&tty); @@ -296,12 +280,26 @@ bool terminal_put(terminal_tty *tty, uint8_t c) { // CONTROL CHARACTERS - if(c==0x07){return;} // BEL + if(c==0x07){return;} // BEL (ignore) if(c==0x7F){return;} // nothing - if(c==0x09){return;} // TAB TODO! - if(c==0x0E){return;} // G1 set - if(c==0x0F){return;} // G0 set + if(c==0x09) // TAB + { + if(tty->x==tty->width-1)return; + set_char(tty,tty->x,tty->y,' ',tty->fg,tty->bg); + tty->x++; + + while(tty->xwidth-1&&tty->x%8!=0) + { + set_char(tty,tty->x,tty->y,' ',tty->fg,tty->bg); + tty->x++; + } + tty->x--; + c=' '; + } + + if(c==0x0E){return;} // G1 set (ignore) + if(c==0x0F){return;} // G0 set (ignore) if(c==0x18||c==0x1A){tty->escaping=0;return;} // cancel escaping if(c==0x1B){tty->escaping=1;return;} // ESC @@ -336,10 +334,77 @@ bool terminal_put(terminal_tty *tty, uint8_t c) // ESC- but not CSI-sequences if(tty->escaping==1) { - if(c=='c'){reset(tty);} // RESET + // FOOL-TERM: delchar + if(c=='x') + { + set_char(tty, tty->x, tty->y, ' ', tty->fg, tty->bg); + } + // FOOL-TERM: clear to end of line + if(c=='K') + { + for(uint32_t x=tty->x;xwidth;x++) + { + set_char(tty, x, tty->y, ' ', tty->fg, tty->bg); + } + } + // FOOL-TERM: clear to end of screen + if(c=='J') + { + for(uint32_t x=tty->x;xwidth;x++) + { + set_char(tty, x, tty->y, ' ', tty->fg, tty->bg); + } + for(uint32_t y=tty->y+1;yheight;y++) + { + for(uint32_t x=0;xwidth;x++) + { + set_char(tty,x, y, ' ', tty->fg, tty->bg); + } + } + } + + // FOOL-TERM: home + if(c=='H') + { + tty->x=0; + tty->y=0; + } + // FOOL-TERM: movement + if(c=='u') + { + if(tty->y>0) + tty->y--; + } + + if(c=='d') + { + if(tty->y+1height) + tty->y++; + } + + if(c=='f') + { + if(tty->x+1width) + tty->x++; + } + + if(c=='b') + { + if(tty->x>0) + tty->x--; + } + + + /// + + + if(c=='c'){reset(tty); + } // RESET + if(c=='D'){tty->y++;} // LINEFEED if(c=='E'){tty->y++;tty->x=0;} //NEWLINE - if(c=='H'){} // SET TABSTOP: TODO + + //if(c=='H'){} // SET TABSTOP: TODO if(c=='M'){ // REVERSE LINEFEED if(tty->y==0) @@ -352,7 +417,7 @@ bool terminal_put(terminal_tty *tty, uint8_t c) if(y!=0) c=tty->data[index(tty,x,y-1)]; tty->data[index(tty,x,y)] = c; - tty->screen->put_char(c&0xff,(c>>8)&0xff,c>>16,x,y); //TODO: get from buffer + tty->screen->put_char(c&0xff,(c>>8)&0xff,c>>16,x,y); } } } @@ -371,7 +436,7 @@ bool terminal_put(terminal_tty *tty, uint8_t c) return;} - if(c=='7'){}// SAVE STATE + if(c=='7'){}// SAVE STATE (coord,attributes,G0/G1?) if(c=='8'){}// RESTORE STATE if(c=='['){tty->escaping=2;tty->npar=0;return;} // CONTROL SEQ INTRODUCER @@ -388,7 +453,11 @@ bool terminal_put(terminal_tty *tty, uint8_t c) else if(tty->escaping==2) { //ECMA-48: TODO - //ECMA-48 GRAPHIC RENDITION: TODO + + + + + //ECMA-48 GRAPHIC RENDITION: OK if(c!='m') { tty->command[NPAR_START+(tty->npar++)]=c; @@ -400,9 +469,18 @@ bool terminal_put(terminal_tty *tty, uint8_t c) //ECMA-48 MODE SWITCHES: TODO //ECMA-48 STATUS REPORT: TODO - //DEC PRIVATE MODE: TODO //LINUX CONSOLE PRIVATE CSI: TODO + // + // ESC [ 1 ; n ] Set color n as the underline color + // ESC [ 2 ; n ] Set color n as the dim color + // ESC [ 8 ] Make the current color pair the default attributes. + // ESC [ 9 ; n ] Set screen blank timeout to n minutes. + // ESC [ 10 ; n ] Set bell frequency in Hz. + // ESC [ 11 ; n ] Set bell duration in msec. + // ESC [ 12 ; n ] Bring specified console to the front. + // ESC [ 13 ] Unblank the screen. + // ESC [ 14 ; n ] Set the VESA powerdown interval in minutes. } else //PROBABLY (AND HOPEFULLY) JUST A NORMAL CHAR @@ -435,7 +513,7 @@ bool terminal_put(terminal_tty *tty, uint8_t c) uint32_t c=tty->data[index(tty,x,y+1)]; if(y==tty->height-1)c=' '|tty->fg<<8|tty->bg<<16; tty->data[index(tty,x,y)] = c; - tty->screen->put_char(c&0xff,(c>>8)&0xff,c>>16,x,y); //TODO: get from buffer + tty->screen->put_char(c&0xff,(c>>8)&0xff,c>>16,x,y); } } } @@ -445,117 +523,3 @@ bool terminal_put(terminal_tty *tty, uint8_t c) return true; } -//deprecated -/* -bool vt52_put(terminal_tty *tty, uint8_t c) -{ - if(c==VT52_ESC_1){tty->escaping=1;return;} - if(c=='['){if(tty->escaping==1)escaping=2;return;} - - if(escaping==3){tty->x=c-32; escaping++;return;} //TODO: check for overflow? - if(escaping==4){tty->y=c-32; escaping=0;return;} - - // does this really need to be escaped with ESC [ not JUST ESC?? TODO; check? - if(escaping==2) // two last characters are escape seq: ^[ - { - if(c==VT52_JUMP)escaping++; - - else - { - switch('c') - { - case VT52_UP: - if(tty->y>0)tty->y--; - break; - - case VT52_DOWN: - if(tty->y+1height)tty->y++; - break; - - case VT52_LEFT: - if(tty->x+1width)tty->x++; - break; - - case VT52_RIGHT: - if(tty->x>0)tty->x--; - break; - - case VT52_HOME: - tty->x=tty->y=0; - break; - - case VT52_REV_FEED: - - break; - - case VT52_ERASE_SCR: - for(uint32_t y=tty->y+1;yheight;y++) - { - for(uint32_t x=0;xwidth;x++) - { - uint32_t c=tty->data[index(tty,x,y+1)]; - tty->data[index(tty,x,y)] = c; - tty->screen->put_char(c,0xf,x,y); - } - } - case VT52_ERASE_LINE: - - for(uint32_t x=tty->x;xwidth;x++) - { - uint32_t c=tty->data[index(tty,x,tty->y)]; - tty->data[index(tty,x,tty->y)] = c; - tty->screen->put_char(c,0xf,x,tty->y); - } - - break; - - } - - escaping=0; - } - - return; - - } - - if(c!='\n') - { - tty->data[index(tty,tty->x,tty->y)]=c; - tty->screen->put_char(c,0xf,tty->x,tty->y); - } - else - { - tty->y++; - tty->x=-1; - - } - - tty->x++; - - if(tty->x>=tty->width) - { - tty->x=0; - tty->y++; - - } - - //autoscroll - if(tty->y>=tty->height) - { - tty->y--; - for(uint32_t y=0;yheight;y++) - { - for(uint32_t x=0;xwidth;x++) - { - uint32_t c=tty->data[index(tty,x,y+1)]; - if(y==tty->height-1)c=' '; - tty->data[index(tty,x,y)] = c; - tty->screen->put_char(c,0xf,x,y); - } - } - } - - tty->screen->update_cursor(tty->x,tty->y); - return true; -} -*/ -- cgit v1.2.3