// // http://en.wikipedia.org/wiki/VT52 // #include "vt52.h" #include "kernel/kmalloc.h" //TODO: check? #define VT52_WIDTH 80 #define VT52_HEIGHT 25 #define VT52_ESC 0x33 static uint32_t index(vt52_tty *tty, uint32_t x, uint32_t y) { return tty->width*y+x; } static void clear(vt52_tty *tty) { for(int x=0;xwidth;x++) for(int y=0;yheight;y++) { tty->data[index(tty,x,y)]='.'; tty->screen->put_char('.',0xf,x,y); } } vt52_tty vt52_init(term_screen *screen) { vt52_tty tty; tty.data=kballoc(1); tty.screen=screen; tty.x=0; tty.y=0; tty.width=VT52_WIDTH; tty.height=VT52_HEIGHT; clear(&tty); return tty; } static void set_char(vt52_tty *tty, uint32_t x, uint32_t y, uint32_t c) { tty->data[index(tty,x,y)]=c; } // send one ASCII character to the terminal void vt52_put(vt52_tty *tty, uint8_t c) { 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=0; } 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-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); } } for(uint32_t x=0;xwidth;x++) { } } }