diff options
Diffstat (limited to 'terminal')
| -rw-r--r-- | terminal/vt52.c | 120 | ||||
| -rw-r--r-- | terminal/vt52.h | 12 |
2 files changed, 113 insertions, 19 deletions
diff --git a/terminal/vt52.c b/terminal/vt52.c index 4a9cb0a..9ff1150 100644 --- a/terminal/vt52.c +++ b/terminal/vt52.c @@ -1,16 +1,43 @@ // // http://en.wikipedia.org/wiki/VT52 +// http://vt100.net/docs/vt520-rm/ // - #include "vt52.h" #include "kernel/kmalloc.h" - -//TODO: check? #define VT52_WIDTH 80 #define VT52_HEIGHT 25 -#define VT52_ESC 0x33 + + +#define VT52_ESC_1 0x1b //ESC +#define VT52_ESC_2 0x5b //[ + +#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" static uint32_t index(vt52_tty *tty, uint32_t x, uint32_t y) { @@ -22,14 +49,13 @@ static void clear(vt52_tty *tty) for(int x=0;x<tty->width;x++) for(int y=0;y<tty->height;y++) { - tty->data[index(tty,x,y)]='.'; - tty->screen->put_char('.',0xf,x,y); + tty->data[index(tty,x,y)]=' '; + tty->screen->put_char(' ',0xf,x,y); } } -vt52_tty vt52_init(term_screen *screen) +vt52_tty vt52_init(term_out *screen) { - vt52_tty tty; tty.data=kballoc(1); @@ -52,9 +78,79 @@ static void set_char(vt52_tty *tty, uint32_t x, uint32_t y, uint32_t c) tty->data[index(tty,x,y)]=c; } +static uint8_t escaping=0; + // send one ASCII character to the terminal void vt52_put(vt52_tty *tty, uint8_t c) { + if(c==VT52_ESC_1){escaping=1;return;} + if(c==VT52_ESC_2){if(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;} + + 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+1<tty->height)tty->y++; + break; + + case VT52_LEFT: + if(tty->x+1<tty->width)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;y<tty->height;y++) + { + for(uint32_t x=0;x<tty->width-1;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;x<tty->width-1;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; @@ -87,10 +183,8 @@ void vt52_put(vt52_tty *tty, uint8_t c) tty->screen->put_char(c,0xf,x,y); } } - for(uint32_t x=0;x<tty->width;x++) - { - } - - } + + tty->screen->update_cursor(tty->x,tty->y); } + diff --git a/terminal/vt52.h b/terminal/vt52.h index 557c247..cdc62bd 100644 --- a/terminal/vt52.h +++ b/terminal/vt52.h @@ -7,13 +7,13 @@ // REQUIREMENTS // * kballoc // block wise in-kernel allocation - -typedef struct term_screen_struct +typedef struct term_out_struct { - + void (*put_char)(uint8_t c,uint8_t color, uint32_t x, uint32_t y); + void (*update_cursor)(uint32_t col,uint32_t row); -}term_screen; +}term_out; typedef struct vt52_tty_struct { @@ -23,11 +23,11 @@ typedef struct vt52_tty_struct uint32_t x; uint32_t y; uint32_t *data; // screen data - term_screen *screen; + term_out *screen; }vt52_tty; -vt52_tty vt52_init(term_screen *screen); +vt52_tty vt52_init(term_out *screen); void vt52_put(vt52_tty *tty, uint8_t c); #endif |
