summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-25 20:43:27 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-25 20:43:27 +0200
commit1252a288665a7d07dcf5f0e468dc67b9440132d0 (patch)
treefe5818b2cf703385312c8c6de76a7bef04eba496
parentce50b0f007b8d71078a03d2a83ad8e35b0931dab (diff)
working on fool-term
-rw-r--r--driver/keyboard.c6
-rw-r--r--packages/ncurses-5.9/foolterm.ti76
-rw-r--r--terminal/terminal.c312
-rw-r--r--terminal/terminal.h2
4 files changed, 222 insertions, 174 deletions
diff --git a/driver/keyboard.c b/driver/keyboard.c
index 951c0f0..e4a13dc 100644
--- a/driver/keyboard.c
+++ b/driver/keyboard.c
@@ -103,6 +103,7 @@ void keyboard_handle(uint8_t in)
uint8_t break_key_space=0xb9;
uint8_t break_key_backspace=0x8e;
uint8_t break_key_esc=0x81;
+ uint8_t break_key_tab=0x8f;
uint8_t make_key_shift_l=0x2a;
uint8_t break_key_shift_l=0xaa;
@@ -196,6 +197,11 @@ void keyboard_handle(uint8_t in)
ascii='\n';
match=true;
}
+ else if(break_key_tab==in)
+ {
+ ascii=0x09;
+ match=true;
+ }
else for(int i=0;i<26;i++)
{
diff --git a/packages/ncurses-5.9/foolterm.ti b/packages/ncurses-5.9/foolterm.ti
new file mode 100644
index 0000000..1c76eda
--- /dev/null
+++ b/packages/ncurses-5.9/foolterm.ti
@@ -0,0 +1,76 @@
+
+# FoolOS built-in terminal emulator
+# check "man 5 terminfo" to understand this file
+
+fool-term|FoolOS built-in terminal emulator,
+ am, bce, eo, mir, msgr,
+# xenl, xon,
+ cols#80, lines#24, colors#8, pairs#64, it#8,
+
+# this could hold an alterntive table paiting method
+# acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260i\316j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376,
+
+ clear=\Ec, cr=\015,
+
+# movement TODO
+#
+ home=\EH,
+
+ cub1=\Eb,
+ cud1=\Ed,
+ cuf1=\Ef,
+ cuu1=\Eu,
+
+# cup=\EY%p1%' '%+%c%p2%' '%+%c,
+
+# clear to end of screen / line
+ ed=\EJ,
+ el=\EK,
+
+# delchar
+ dch1=\Ex,
+
+# backspace
+ kbs=\010,
+
+# tab
+ ht=\011,
+
+# newline
+ nel=\012,
+
+# scrolling (down,reverse)
+ ind=\ED,
+ ri=\EM,
+
+# keys
+ kcub1=\E<, kcud1=\E^,
+ kcuf1=\E>, kcuu1=\Ev,
+
+
+# function keys
+# kf1=\E[[A,
+# kf10=\E[21~,
+# kf11=\E[23~,
+# kf12=\E[24~,
+# kf13=\E[25~,
+# kf14=\E[26~,
+# kf15=\E[28~,
+# kf16=\E[29~,
+# kf17=\E[31~,
+# kf18=\E[32~,
+# kf19=\E[33~,
+# kf2=\E[[B,
+# kf20=\E[34~,
+# kf3=\E[[C,
+# kf4=\E[[D,
+# kf5=\E[[E,
+# kf6=\E[17~,
+# kf7=\E[18~,
+# kf8=\E[19~,
+# kf9=\E[20~,
+
+#colors
+ setab=\E[4%p1%dm,
+ setaf=\E[3%p1%dm,
+
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->x<tty->width-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;x<tty->width;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;x<tty->width;x++)
+ {
+ set_char(tty, x, tty->y, ' ', tty->fg, tty->bg);
+ }
+ for(uint32_t y=tty->y+1;y<tty->height;y++)
+ {
+ for(uint32_t x=0;x<tty->width;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+1<tty->height)
+ tty->y++;
+ }
+
+ if(c=='f')
+ {
+ if(tty->x+1<tty->width)
+ 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+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;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;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;y<tty->height;y++)
- {
- for(uint32_t x=0;x<tty->width;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;
-}
-*/
diff --git a/terminal/terminal.h b/terminal/terminal.h
index 5e97cc1..06b8f5a 100644
--- a/terminal/terminal.h
+++ b/terminal/terminal.h
@@ -66,6 +66,8 @@ typedef struct terminal_tty_struct
term_out *screen;
term_in *input;
+ bool reverse_video;
+
}terminal_tty;
terminal_tty terminal_init(term_out *screen,term_in *input);