aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/mainloop.c7
-rw-r--r--src/Makefile.am7
-rw-r--r--src/ansi.c80
-rw-r--r--src/crt.c14
-rw-r--r--src/crt.h5
-rw-r--r--src/prototypes.h13
-rw-r--r--src/ptty.c5
-rw-r--r--src/serial.c5
-rw-r--r--src/terminal.c15
-rw-r--r--src/utf8.c4
-rw-r--r--src/vt102.c312
-rw-r--r--src/vt102.h14
-rw-r--r--src/vt102_charset.c140
13 files changed, 471 insertions, 150 deletions
diff --git a/apps/mainloop.c b/apps/mainloop.c
index 73b2236..9e378d1 100644
--- a/apps/mainloop.c
+++ b/apps/mainloop.c
@@ -11,6 +11,9 @@ static char rcsid[] =
/*
* $Log$
+ * Revision 1.12 2008/02/26 23:23:16 james
+ * *** empty log message ***
+ *
* Revision 1.11 2008/02/24 00:43:55 james
* *** empty log message ***
*
@@ -88,6 +91,8 @@ static char rcsid[] =
#include "clients.h"
+Context *context;
+
typedef struct
{
int nclients;
@@ -389,6 +394,8 @@ mainloop (TTY * tty, Socket * server_socket, Socket * client_socket,
Context c = { 0 };
Clients *clients;
+ context=&c;
+
c.tp = tty_parser_new ();
c.u = utf8_new ();
diff --git a/src/Makefile.am b/src/Makefile.am
index 7e0a3b9..3793b26 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,9 @@
# $Id$
#
# $Log$
+# Revision 1.18 2008/02/26 23:23:17 james
+# *** empty log message ***
+#
# Revision 1.17 2008/02/24 00:42:53 james
# *** empty log message ***
#
@@ -68,13 +71,13 @@ INCLUDES=
# NB order here matters.
PROJECTHDRS= crt.h utf8.h tty.h ansi.h vt102.h keys.h history.h ring.h slide.h \
log.h ipc.h symsocket.h keydis.h cmd.h lockfile.h context.h \
- prototypes.h
+ vt102_charset.h prototypes.h
HDRS=project.h
SRCS=ansi.c crt.c html.c libsympathy.c render.c version.c vt102.c tty.c \
keydis.c history.c ring.c ptty.c terminal.c util.c log.c ipc.c \
- slide.c symsocket.c serial.c cmd.c lockfile.c utf8.c
+ slide.c symsocket.c serial.c cmd.c lockfile.c utf8.c vt102_charset.c
CPROTO=cproto
diff --git a/src/ansi.c b/src/ansi.c
index 7a0d630..3e4ace1 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.31 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.30 2008/02/24 00:42:53 james
* *** empty log message ***
*
@@ -320,10 +323,41 @@ ansi_set_attr (ANSI * a, int attr)
}
static void
-ansi_emit_noutf8 (TTY * t, uint32_t ch)
+ascii_emit (TTY * t, uint32_t ch)
{
- uint8_t c = (ch > 0x7f) ? '?' : ch;
+int i;
+
+/*Some quick obvious subsititons for quotation marks*/
+switch(ch) {
+case 0x2018:
+ ch='`';
+ break;
+case 0x2019:
+ ch='\'';
+ break;
+case 0x201c:
+case 0x201d:
+ ch='"';
+ break;
+}
+
+/*Short cut the easy stuff*/
+if (ch<0x7f) {
+ uint8_t c = ch ;
t->xmit (t, &c, 1);
+ return;
+}
+
+for (i=0;i<VT102_CHARSET_SIZE;++i) {
+if (vt102_charset_gl[i]==ch) {
+ uint8_t c[3] ={016,i,017};
+ t->xmit (t, &c, 3);
+ return;
+}
+}
+
+ t->xmit (t, "?", 1);
+
}
static void
@@ -331,9 +365,10 @@ ansi_render (ANSI * a, CRT_CA ca)
{
int dif;
- if (ca.chr < 0x20)
- ca.chr = ' ';
- if ((ca.chr > 0x7e) && (ca.chr < 0xa0))
+ if ((ca.chr < VT102_CHARSET_SIZE) && (vt102_charset_c0[ca.chr]))
+ ca.chr=vt102_charset_c0[ca.chr];
+
+ if ((ca.chr >= 0x80) && (ca.chr < 0xa0))
ca.chr = ' ';
ansi_set_attr (a, ca.attr);
@@ -342,7 +377,7 @@ ansi_render (ANSI * a, CRT_CA ca)
if (a->utf8)
utf8_emit (a->terminal, ca.chr);
else
- ansi_emit_noutf8 (a->terminal, ca.chr);
+ ascii_emit(a->terminal,ca.chr);
a->pos.x++;
@@ -460,7 +495,7 @@ ansi_draw_line (ANSI * a, CRT_CA * cap, int y)
CRT_Pos p = { 0, y };
CRT_CA *acap = &a->crt.screen[CRT_ADDR_POS (&p)];
- for (p.x = 0; p.x < CRT_COLS; ++p.x)
+ for (p.x = 0; p.x < a->crt.width; ++p.x)
{
if (p.x >= a->size.x)
continue;
@@ -480,11 +515,10 @@ ansi_draw_line (ANSI * a, CRT_CA * cap, int y)
}
static void
-ansi_resize_check (ANSI * a)
+ansi_resize_check (ANSI * a,int new_width)
{
- if (!crt_pos_cmp (a->terminal->size, a->size))
- return;
+ if ((new_width && (new_width != a->crt.width)) || crt_pos_cmp (a->terminal->size, a->size)) {
terminal_getsize (a->terminal);
@@ -495,15 +529,28 @@ ansi_resize_check (ANSI * a)
crt_reset (&a->crt);
+ if (new_width)
+ a->crt.width=new_width;
+
// FIXME: -- echos back crap?
// a->terminal->xmit (a->terminal, "\033[c", 3);
+// maybe - issue 132 column command if we're 132?
+
ansi_cls (a);
a->terminal->xmit (a->terminal, "\033=", 2);
a->terminal->xmit (a->terminal, "\033[?6l", 5);
a->terminal->xmit (a->terminal, "\033[r", 3);
+ if (a->utf8) {
+ a->terminal->xmit (a->terminal,"\033%G",3);
+ } else {
+ a->terminal->xmit (a->terminal,"\033(B",3);
+ a->terminal->xmit (a->terminal,"\033)0",3);
+ a->terminal->xmit (a->terminal,"\017",1);
+ }
}
+}
#define HISTORY_GUESS_SCROLL 24 /*guess all 24 lines usually scroll */
/*if they haven't then ansi_draw will patch it up*/
@@ -517,9 +564,9 @@ ansi_history (ANSI * a, History * h)
if (a->history_ptr == h->wptr)
return;
- ansi_resize_check (a);
+ ansi_resize_check (a,0);
- if ((a->size.x < CRT_COLS) || (a->size.y < CRT_ROWS))
+ if ((a->size.x < a->crt.width) || (a->size.y < CRT_ROWS))
return;
ansi_force_attr_normal (a);
@@ -568,7 +615,7 @@ ansi_history (ANSI * a, History * h)
{
memcpy (&a->crt.screen[CRT_ADDR_POS (&e)],
&a->crt.screen[CRT_ADDR_POS (&s)],
- sizeof (CRT_CA) * CRT_COLS);
+ sizeof (CRT_CA)*a->crt.width);
}
/* erase new line */
@@ -594,8 +641,7 @@ ansi_draw (ANSI * a, CRT * c)
int o;
int hidden_cursor = 0;
- ansi_resize_check (a);
-
+ ansi_resize_check (a,c->width);
for (p.y = 0; p.y < CRT_ROWS; ++p.y)
@@ -608,7 +654,7 @@ ansi_draw (ANSI * a, CRT * c)
}
- if ((CRT_COLS > a->size.x) || (CRT_ROWS > a->size.y))
+ if ((c->width > a->size.x) || (CRT_ROWS > a->size.y))
{
char msg[1024]; // = "Window is too small";
int i;
@@ -617,7 +663,7 @@ ansi_draw (ANSI * a, CRT * c)
i =
sprintf (msg, "Window too small (%dx%d need %dx%d)", a->size.x,
- a->size.y, CRT_COLS, CRT_ROWS);
+ a->size.y, c->width, CRT_ROWS);
ansi_showhide_cursor (a, 1);
ansi_set_attr (a, CRT_ATTR_REVERSE);
diff --git a/src/crt.c b/src/crt.c
index 87b814d..693e003 100644
--- a/src/crt.c
+++ b/src/crt.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.12 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.11 2008/02/23 11:48:37 james
* *** empty log message ***
*
@@ -74,7 +77,9 @@ crt_cls (CRT * c)
int i;
crt_erase (c, s, e, 1, CRT_COLOR_NORMAL);
+#if 0
c->sh.dir = 0;
+#endif
}
void
@@ -87,9 +92,11 @@ crt_scroll_up (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color)
s.x = 0;
e.x = CRT_COLS - 1;
+#if 0
c->sh.s = s;
c->sh.e = e;
c->sh.dir = -1;
+#endif
l = e.x - s.x;
l++;
@@ -120,9 +127,11 @@ crt_scroll_down (CRT * c, CRT_Pos s, CRT_Pos e, int ea, int color)
s.x = 0;
e.x = CRT_COLS - 1;
+#if 0
c->sh.s = s;
c->sh.e = e;
c->sh.dir = 1;
+#endif
l = e.x - s.x;
l++;
@@ -152,7 +161,10 @@ crt_reset (CRT * c)
c->pos.x = 0;
c->pos.y = 0;
c->hide_cursor = 1;
+ c->width=CRT_COLS;
+#if 0
c->sh.dir = 0;
+#endif
}
void
@@ -169,5 +181,7 @@ crt_insert (CRT * c, CRT_CA ca)
c->screen[CRT_ADDR (c->pos.y, c->pos.x)] = ca;
+#if 0
c->sh.dir = 0;
+#endif
}
diff --git a/src/crt.h b/src/crt.h
index 7eee5ac..5883c04 100644
--- a/src/crt.h
+++ b/src/crt.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.12 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.11 2008/02/26 19:08:27 james
* *** empty log message ***
*
@@ -115,8 +118,8 @@ typedef struct CRT_struct
{
CRT_CA screen[CRT_CELS];
CRT_Pos pos;
- CRT_ScrollHint sh;
int hide_cursor;
+ int width;
} CRT;
diff --git a/src/prototypes.h b/src/prototypes.h
index c2c0a8e..735617b 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -16,7 +16,6 @@ extern ANSI *ansi_new_html(FILE *f);
/* vt102.c */
extern int vt102_cmd_length[128];
extern int vt102_cmd_termination[128];
-extern void redispatch_with_more(VT102_parser *p, int n);
extern void vt102_log_line(Context *c, int line);
extern void vt102_history(Context *c, CRT_Pos t, CRT_Pos b);
extern void vt102_clip_cursor(VT102 *v, CRT_Pos tl, CRT_Pos br);
@@ -41,10 +40,11 @@ extern void vt102_change_attr(VT102 *v, char *na);
extern void vt102_parse_attr_string(VT102 *v, char *buf, int len);
extern void vt102_save_state(VT102 *v);
extern void vt102_restore_state(VT102 *v);
-extern void vt102_regular_char(Context *c, VT102 *v, int ch);
+extern void vt102_regular_char(Context *c, VT102 *v, uint32_t ch);
+extern int vt102_send_id(Context *c, char *buf);
extern void vt102_scs(Context *c, int g, int s);
-extern void vt102_parse_esc(Context *c);
extern void vt102_parse_csi(Context *c, char *buf, int len);
+extern void vt102_parse_esc(Context *c);
extern void vt102_status_line(VT102 *v, char *str);
extern void vt102_parser_reset(VT102_parser *p);
extern void vt102_reset_state(VT102 *v);
@@ -165,3 +165,10 @@ extern void utf8_flush(Context *c);
extern void utf8_parse(Context *c, uint32_t ch);
extern UTF8 *utf8_new(void);
extern void utf8_emit(TTY *t, int ch);
+/* vt102_charset.c */
+extern uint32_t vt102_charset_c0[128];
+extern uint32_t vt102_charset_us[128];
+extern uint32_t vt102_charset_uk[128];
+extern uint32_t vt102_charset_vt52[128];
+extern uint32_t vt102_charset_gl[128];
+extern uint32_t *charset_from_csid[];
diff --git a/src/ptty.c b/src/ptty.c
index bddc56e..98f1282 100644
--- a/src/ptty.c
+++ b/src/ptty.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.11 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.10 2008/02/24 00:42:53 james
* *** empty log message ***
*
@@ -147,7 +150,7 @@ ptty_open (char *path, char *argv[])
client_termios (&ctermios);
winsize.ws_row = VT102_ROWS;
- winsize.ws_col = VT102_COLS;
+ winsize.ws_col = VT102_COLS_80;
child = forkpty (&fd, name, &ctermios, &winsize);
diff --git a/src/serial.c b/src/serial.c
index ab06e60..fe08594 100644
--- a/src/serial.c
+++ b/src/serial.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.11 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.10 2008/02/24 00:47:14 james
* *** empty log message ***
*
@@ -204,7 +207,7 @@ serial_open (char *path, int lock_mode)
t->fd = fd;
t->rfd = t->fd;
t->wfd = t->fd;
- t->size.x = VT102_COLS;
+ t->size.x = VT102_COLS_80;
t->size.y = VT102_ROWS;
t->blocked = serial_lock_check (t->lock);
t->hanging_up = 0;
diff --git a/src/terminal.c b/src/terminal.c
index 9a3290e..d0cde99 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.10 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.9 2008/02/15 03:32:07 james
* *** empty log message ***
*
@@ -97,11 +100,15 @@ terminal_close (TTY * _t)
set_nonblocking (t->wfd);
- t->xmit (_t, "\033[r", 3);
- t->xmit (_t, "\033[0m", 4);
- i = sprintf (buf, "\033[%d;%dH", CRT_ROWS + 1, 1);
+ t->xmit (_t,"\033%@",3); //Leave UTF-8
+ t->xmit (_t,"\033(B",3); //US-ASCII in G0
+ t->xmit (_t,"\033)B",3); //US-ASCII in G1
+ t->xmit (_t,"\017",1); //Select G0
+ t->xmit (_t, "\033[r", 3); //No margins
+ t->xmit (_t, "\033[0m", 4); //Default attributes
+ i = sprintf (buf, "\033[%d;%dH", CRT_ROWS + 1, 1); //Cursor to bottom
t->xmit (_t, buf, i);
- t->xmit (_t, "\033[J", 3);
+ t->xmit (_t, "\033[J", 3); //erase rest of screen
set_blocking (t->rfd);
set_blocking (t->wfd);
diff --git a/src/utf8.c b/src/utf8.c
index ff8a2ec..e324a53 100644
--- a/src/utf8.c
+++ b/src/utf8.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.6 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.5 2008/02/24 00:42:53 james
* *** empty log message ***
*
@@ -180,3 +183,4 @@ utf8_emit (TTY * t, int ch)
t->xmit (t, buf, 4);
}
}
+
diff --git a/src/vt102.c b/src/vt102.c
index b4fe381..721886b 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.41 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.40 2008/02/26 19:00:59 james
* *** empty log message ***
*
@@ -295,7 +298,7 @@ ESC+B
#define TABLE_LENGTH 128
-static char terminal_id[]="vt102";
+static char terminal_id[] = "vt102";
/* number of aditional chars after \033 ... to complete the escape if it's fixed length*/
int vt102_cmd_length[TABLE_LENGTH] = {
@@ -341,14 +344,15 @@ csi_ender (int c)
return 0;
}
-
-
-/*Stay or enter command acquision and exit after n more chars*/
-void
-redispatch_with_more (VT102_parser * p, int n)
+static inline int ctrl_chr(int ch,int term)
{
+if ((term>0) && (ch==term)) return 0;
+if (ch==033) return 0;
+if ((ch>0) && (ch<040)) return 1;
+return 0;
}
+
static inline int
in_margins (VT102 * v, CRT_Pos p)
{
@@ -368,9 +372,9 @@ in_margins (VT102 * v, CRT_Pos p)
void
vt102_log_line (Context * c, int line)
{
- CRT_Pos e = { VT102_COLS - 1, line };
+ CRT_Pos e = { c->v->current_width - 1, line };
CRT_Pos p = { 0, line };
- char logbuf[VT102_COLS + 1];
+ char logbuf[VT102_MAX_COLS + 1];
if (!c->l)
return;
@@ -551,8 +555,9 @@ vt102_cursor_advance (Context * c)
void
vt102_cursor_retreat (VT102 * v)
{
- if (v->pos.x != v->top_margin.x)
+ if (v->pos.x != v->top_margin.x) {
v->pos.x--;
+ }
v->pending_wrap = 0;
}
@@ -564,7 +569,7 @@ vt102_reset_tabs (VT102 * v)
memset (v->tabs, 0, sizeof (v->tabs));
- for (i = 0; i < VT102_COLS; i += 8)
+ for (i = 0; i < VT102_MAX_COLS; i += 8)
{
v->tabs[i]++;
}
@@ -610,7 +615,7 @@ vt102_cursor_absolute (VT102 * v, int x, int y)
if (v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE])
{
v->pos.x = x + v->top_margin.x;
- v->pos.y = y + v->top_margin.x;
+ v->pos.y = y + v->top_margin.y;
}
else
{
@@ -708,15 +713,20 @@ vt102_change_mode (VT102 * v, int private, char *ns, int set)
case VT102_PRIVATE_MODE_ORIGIN_MODE:
vt102_cursor_home (v);
break;
- case VT102_PRIVATE_MODE_132COLS:
- /* We don't implement 132 col mode - yet*/
- v->top_margin = v->screen_start;
- v->bottom_margin = v->screen_end;
- vt102_cursor_home(v);
- crt_cls (&v->crt);
-
+ case VT102_PRIVATE_MODE_132COLS:
+ /* We don't implement 132 col mode - yet */
+
+ v->current_width=v->private_modes[VT102_PRIVATE_MODE_132COLS] ? VT102_COLS_132:VT102_COLS_80;
- break;
+ v->crt.width=v->current_width;
+ v->screen_end.x=v->current_width-1;
+ v->top_margin = v->screen_start;
+ v->bottom_margin = v->screen_end;
+ vt102_cursor_home (v);
+ crt_cls (&v->crt);
+
+
+ break;
}
}
@@ -956,7 +966,7 @@ vt102_restore_state (VT102 * v)
}
void
-vt102_regular_char (Context * c, VT102 * v, int ch)
+vt102_regular_char (Context * c, VT102 * v, uint32_t ch)
{
vt102_do_pending_wrap (c);
@@ -964,7 +974,12 @@ vt102_regular_char (Context * c, VT102 * v, int ch)
if (v->modes[VT102_MODE_INSERT])
vt102_insert_into_line (v, v->pos);
- v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = ch;
+ if (ch < VT102_CHARSET_SIZE ){
+ int cs=charset_from_csid[v->g[v->cs]][ch];
+ v->crt.screen[CRT_ADDR_POS (&v->pos)].chr = cs ?cs:ch;
+ } else {
+ v->crt.screen[CRT_ADDR_POS (&v->pos)].chr=ch;
+ }
v->crt.screen[CRT_ADDR_POS (&v->pos)].attr = v->attr;
v->crt.screen[CRT_ADDR_POS (&v->pos)].color = v->color;
vt102_cursor_advance (c);
@@ -972,20 +987,46 @@ vt102_regular_char (Context * c, VT102 * v, int ch)
v->last_reg_char = ch;
}
-vt102_send_id(Context *c,char *buf)
+vt102_send_id (Context * c, char *buf)
{
-
- if (c->t)
- {
- int l=strlen(buf);
- c->t->xmit (c->t, buf,l);
- }
+
+ if (c->t)
+ {
+ int l = strlen (buf);
+ c->t->xmit (c->t, buf, l);
+ }
}
void
vt102_scs (Context * c, int g, int s)
{
-/*Ignoring charsets*/
+VT102 *v=c->v;
+int cs=VT102_CSID_US;
+
+
+switch (s) {
+case 'A':
+ cs=VT102_CSID_UK;
+ break;
+case '1':
+case '2':
+case 'B':
+ cs=VT102_CSID_US;
+ break;
+case '0':
+ cs=VT102_CSID_GL;
+ break;
+}
+
+switch(g) {
+case '(':
+ v->g[0]=cs;
+ break;
+case ')':
+ v->g[1]=cs;
+ break;
+}
+
}
void
@@ -1088,7 +1129,7 @@ vt102_parse_csi (Context * c, char *buf, int len)
case 'K':
{
CRT_Pos ls = { 0, v->pos.y };
- CRT_Pos le = { VT102_COLS - 1, v->pos.y };
+ CRT_Pos le = { v->current_width -1, v->pos.y };
if (len == 2)
narg = 0; /*Different default */
@@ -1174,7 +1215,7 @@ vt102_parse_csi (Context * c, char *buf, int len)
vt102_regular_char (c, v, v->last_reg_char);
break;
case 'c':
- vt102_send_id(c,terminal_id);
+ vt102_send_id (c, terminal_id);
break;
case 'd':
vt102_cursor_absolute (v, v->pos.x, narg - 1);
@@ -1195,7 +1236,7 @@ vt102_parse_csi (Context * c, char *buf, int len)
}
break;
- case 'i': //Printer commands
+ case 'i': //Printer commands
//FIXME
break;
case 'h':
@@ -1207,13 +1248,13 @@ vt102_parse_csi (Context * c, char *buf, int len)
case 'm':
vt102_parse_attr_string (v, &buf[1], len - 1);
break;
- case 'n': //Device status report
- //5 requestion status
- // 6 request cursor position FIXME
- //?15n printer status
+ case 'n': //Device status report
+ //5 requestion status
+ // 6 request cursor position FIXME
+ //?15n printer status
+ break;
+ case 'q': //Load LED on off
break;
- case 'q': //Load LED on off
- break;
case 'r':
v->top_margin = v->screen_start;
v->bottom_margin = v->screen_end;
@@ -1244,8 +1285,8 @@ vt102_parse_csi (Context * c, char *buf, int len)
vt102_cursor_normalize (v);
v->pending_wrap = 0;
break;
- case 'y': //Invoke confidence test
- break;
+ case 'y': //Invoke confidence test
+ break;
default:
log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__,
@@ -1271,11 +1312,14 @@ vt102_parse_esc (Context * c)
VT102_parser *p = &v->parser;
#if 1
-p->cmd_buf[p->cmd_ptr]=0;
-log_f (c->l, "<cmd in x=%d y=%d <ESC>%s >",v->pos.x,v->pos.y,p->cmd_buf);
+ p->cmd_buf[p->cmd_ptr] = 0;
+ log_f (c->l, "<cmd in x=%3d y=%2d aw=%d <ESC>%s >", v->pos.x, v->pos.y,v->pending_wrap,
+ p->cmd_buf);
#endif
-#if 0 //VT52
+if (v->private_modes[VT102_PRIVATE_MODE_VT52]) {
+int ate=1;
+
switch (p->cmd_buf[0])
{
case 'A':
@@ -1291,14 +1335,16 @@ log_f (c->l, "<cmd in x=%d y=%d <ESC>%s >",v->pos.x,v->pos.y,p->cmd_buf);
vt102_cursor_relative (v, -1, 0);
break;
case 'F':
- //Set graphics mode
- break;
- case 'G':
- //Quit graphics mode
- break;
+ v->cs=1;
+ v->g[1]=VT102_CSID_VT52;
+ break;
+ case 'G':
+ v->cs=0;
+ v->g[0]=VT102_CSID_US;
+ break;
case 'H':
- vt102_cursor_absolute (v, 0, 0);
- break;
+ vt102_cursor_absolute (v, 0, 0);
+ break;
case 'I':
vt102_cursor_retreat_line (c);
break;
@@ -1307,69 +1353,72 @@ log_f (c->l, "<cmd in x=%d y=%d <ESC>%s >",v->pos.x,v->pos.y,p->cmd_buf);
break;
case 'K':
{
- CRT_Pos le = { VT102_COLS - 1, v->pos.y };
+ CRT_Pos le = { v->current_width - 1, v->pos.y };
crt_erase (&v->crt, v->pos, le, 1, v->color);
}
break;
case 'Y':
vt102_cursor_absolute (v, p->cmd_buf[2] - 040, p->cmd_buf[1] - 040);
break;
-case 'V': //Print current line
- break;
-case 'W': //Printer on
- break;
-case 'X': //printer off
- break;
-case ']'://print screen
- break;
-case 'Z'://ID
- vt102_send_id(c,"\033/Z");
- break;
- }
-case '^': //Autoprint on
- break;
-case '_'://Autoprint off
- break;
- case '=':
- v->application_keypad_mode = 1;
+ case 'V': //Print current line
break;
- case '>':
- v->application_keypad_mode = 0;
+ case 'W': //Printer on
+ break;
+ case 'X': //printer off
+ break;
+ case ']': //print screen
+ break;
+ case 'Z': //ID
+ vt102_send_id (c, "\033/Z");
break;
+case '^': //Autoprint on
+ break;
+case '_': //Autoprint off
+ break;
+case '=':
+ v->application_keypad_mode = 1;
+ break;
+case '>':
+ v->application_keypad_mode = 0;
+ break;
+default:
+ ate=0;
+}
+if(ate) return;
+}
-#endif
/*If you edit this switch don't forget to edit the length and termination tables*/
switch (p->cmd_buf[0])
{
- case 'D':
- vt102_cursor_advance_line(c);
- break;
-
+ case 'D':
+ vt102_cursor_advance_line (c);
+ break;
+
case 'E':
- vt102_cursor_advance_line(c);
- v->pos.x=v->top_margin.x;
- vt102_cursor_normalize (v);
- v->pending_wrap = 0;
+ vt102_cursor_advance_line (c);
+ v->pos.x = v->top_margin.x;
+ vt102_cursor_normalize (v);
+ v->pending_wrap = 0;
break;
case 'H':
v->tabs[v->pos.x]++;
break;
- case 'M':
+ case 'M':
vt102_cursor_retreat_line (c);
break;
- case 'N': //select G2 for one char
- break;
- case 'O': //select G3 for one char
- break;
- case 'Z':
- vt102_send_id(c,terminal_id);
- break;
- case 'c':
- vt102_reset(v);
+ case 'N': //select G2 for one char
+ break;
+ case 'O': //select G3 for one char
+ break;
+ case 'Z':
+ vt102_send_id (c, terminal_id);
+ break;
+ case 'c':
+ vt102_reset (v);
- break;
+ break;
case '=':
v->application_keypad_mode = 1;
break;
@@ -1380,11 +1429,11 @@ case '_'://Autoprint off
case '#':
switch (p->cmd_buf[1])
{
- case '3': //top of double height line
- case '4': //bottom of double height line
- case '5': //single width line
- case '6': //double width line
- break;
+ case '3': //top of double height line
+ case '4': //bottom of double height line
+ case '5': //single width line
+ case '6': //double width line
+ break;
case '8':
/*DECALN*/
{
@@ -1394,7 +1443,7 @@ case '_'://Autoprint off
for (i = 0; i < CRT_ADDR_POS (&v->screen_end); ++i)
v->crt.screen[i].chr = 'E';
}
- break;
+ break;
default:
log_f (c->l,
@@ -1433,25 +1482,32 @@ case '_'://Autoprint off
;
}
-p->cmd_buf[p->cmd_ptr]=0;
-log_f (c->l, "<cmd out x=%d y=%d>",v->pos.x,v->pos.y);
+ p->cmd_buf[p->cmd_ptr] = 0;
+ log_f (c->l, "<cmd out x=%3d y=%2d aw=%d>", v->pos.x, v->pos.y,v->pending_wrap);
}
void
vt102_status_line (VT102 * v, char *str)
{
- int i = VT102_COLS;
+ int i = v->current_width -1;
CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
- while (i--)
+ for (i=0;i<v->current_width;++i)
{
ca->attr = CRT_ATTR_REVERSE;
ca->color = CRT_COLOR_NORMAL;
- ca->chr = *str;
+ ca->chr = *str ? *str:' ';
if (*str)
str++;
ca++;
}
+
+ for (;i<VT102_MAX_COLS;++i) {
+ ca->attr = CRT_ATTR_NORMAL;
+ ca->color = CRT_COLOR_NORMAL;
+ ca->chr=' ';
+ ca++;
+ }
}
@@ -1476,6 +1532,10 @@ vt102_reset_state (VT102 * v)
v->application_keypad_mode = 0;
+ v->current_width=VT102_COLS_80;
+ v->crt.width=v->current_width;
+ v->screen_end.x = v->current_width -1;
+
v->top_margin = v->screen_start;
v->bottom_margin = v->screen_end;
@@ -1488,6 +1548,9 @@ vt102_reset_state (VT102 * v)
v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
vt102_reset_tabs (v);
+
+ v->g[0]=v->g[1]=VT102_CSID_US;
+ v->cs=0;
}
static void
@@ -1548,16 +1611,19 @@ vt102_parse_char (Context * c, int ch)
{
vt102_reset_state (v);
}
- else if (p->in_cmd)
+ else if (p->in_cmd && !ctrl_chr(ch,p->cmd_termination))
{
p->cmd_buf[p->cmd_ptr++] = ch;
- if (p->cmd_more_bytes) {
- p->cmd_more_bytes--;
+ if (p->cmd_ptr==VT102_CMD_LEN)
+ p->in_cmd=0;
+ if (p->cmd_more_bytes)
+ {
+ p->cmd_more_bytes--;
- if (!p->cmd_more_bytes == 1)
- p->in_cmd = 0;
- }
+ if (!p->cmd_more_bytes == 1)
+ p->in_cmd = 0;
+ }
switch (p->cmd_termination)
{
@@ -1580,9 +1646,8 @@ vt102_parse_char (Context * c, int ch)
p->cmd_termination = 0;
}
}
- else if (p->in_escape)
+ else if (p->in_escape && !ctrl_chr(ch,0))
{
-
p->cmd_ptr = 0;
p->cmd_buf[p->cmd_ptr++] = ch;
p->in_escape = 0;
@@ -1601,6 +1666,13 @@ vt102_parse_char (Context * c, int ch)
}
else
{
+#if 1
+if (ch!=27)
+ log_f (c->l,
+ "<chr in x=%3d y=%2d aw=%d \\%03o %3d %c",
+ v->pos.x, v->pos.y, v->pending_wrap,ch,ch,safe_ch(ch));
+
+#endif
switch (ch)
{
@@ -1611,7 +1683,7 @@ vt102_parse_char (Context * c, int ch)
/*EOT*/ case 4:
break;
/*ENQ*/ case 5:
- vt102_send_id(c,terminal_id);
+ vt102_send_id (c, terminal_id);
break;
/*ACK*/ case 6:
/*BEL*/ case 7:
@@ -1633,11 +1705,11 @@ vt102_parse_char (Context * c, int ch)
break;
/*SO*/ case 14:
/*select G1 */
- /*Ignoring charsets */
+ v->cs=1;
break;
/*SI*/ case 15:
/*select G0 */
- /*Ignoring charsets */
+ v->cs=0;
break;
/*DLE*/ case 16:
/*DC1 */ case 17:
@@ -1661,13 +1733,13 @@ vt102_parse_char (Context * c, int ch)
/*DEL*/ case 127:
break;
/*regular character */ default:
-#if 1
- log_f (c->l, "char %3d %c ie=%d ic=%d cmb=%d ct=%3d %2d %2d %d", ch,
- safe_ch (ch), p->in_escape, p->in_cmd, p->cmd_more_bytes,
- p->cmd_termination, v->pos.x, v->pos.y, v->pending_wrap);
-#endif
vt102_regular_char (c, v, ch);
}
+
+#if 1
+ if (ch!=27)
+ log_f (c->l, "<chr out x=%3d y=%2d aw=%d>", v->pos.x, v->pos.y,v->pending_wrap);
+#endif
}
v->crt.pos = v->pos;
@@ -1864,7 +1936,9 @@ vt102_reset (VT102 * v)
v->screen_start.x = 0;
v->screen_start.y = 0;
- v->screen_end.x = VT102_COLS - 1;
+ v->current_width=VT102_COLS_80;
+ v->crt.width=v->current_width;
+ v->screen_end.x = v->current_width -1;
v->screen_end.y = VT102_ROWS - 1;
vt102_cursor_home (v);
diff --git a/src/vt102.h b/src/vt102.h
index 0ce734f..7be7d05 100644
--- a/src/vt102.h
+++ b/src/vt102.h
@@ -12,6 +12,9 @@
/*
* $Log$
+ * Revision 1.19 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
* Revision 1.18 2008/02/26 19:08:27 james
* *** empty log message ***
*
@@ -74,7 +77,9 @@
#define VT102_CMD_LEN 128
#define VT102_ROWS 24
-#define VT102_COLS 132
+#define VT102_COLS_132 132
+#define VT102_COLS_80 80
+#define VT102_MAX_COLS VT102_COLS_132
#define VT102_STATUS_ROW 24
#define VT102_NMODES 32
@@ -117,13 +122,18 @@ typedef struct
uint8_t modes[VT102_NMODES];
uint8_t private_modes[VT102_NMODES];
- uint8_t tabs[VT102_COLS];
+ uint8_t tabs[VT102_COLS_132];
int application_keypad_mode;
int last_reg_char;
int xn_glitch;
+ int current_width;
+
+ int g[2];
+ int cs;
+
} VT102;
#define VT102_PRIVATE_MODE_CURSOR_MODE 1
diff --git a/src/vt102_charset.c b/src/vt102_charset.c
new file mode 100644
index 0000000..bd0597a
--- /dev/null
+++ b/src/vt102_charset.c
@@ -0,0 +1,140 @@
+/*
+ * vt102_charset.c:
+ *
+ * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
+ * All rights reserved.
+ *
+ */
+
+static char rcsid[] = "$Id$";
+
+/*
+ * $Log$
+ * Revision 1.1 2008/02/26 23:23:17 james
+ * *** empty log message ***
+ *
+ */
+
+#include "project.h"
+
+uint32_t vt102_charset_c0[VT102_CHARSET_SIZE]={
+[0x00]=0x2400,
+[0x01]=0x2401,
+[0x02]=0x2402,
+[0x03]=0x2403,
+[0x04]=0x2404,
+[0x05]=0x2405,
+[0x06]=0x2406,
+[0x07]=0x2407,
+[0x08]=0x2408,
+[0x09]=0x2409,
+[0x0a]=0x240a,
+[0x0b]=0x240b,
+[0x0c]=0x240c,
+[0x0d]=0x240d,
+[0x0e]=0x240e,
+[0x0f]=0x240f,
+[0x10]=0x2410,
+[0x11]=0x2411,
+[0x12]=0x2412,
+[0x13]=0x2413,
+[0x14]=0x2414,
+[0x15]=0x2415,
+[0x16]=0x2416,
+[0x17]=0x2417,
+[0x18]=0x2418,
+[0x19]=0x2419,
+[0x1a]=0x241a,
+[0x1b]=0x241b,
+[0x1c]=0x241c,
+[0x1d]=0x241d,
+[0x1e]=0x241e,
+[0x1f]=0x241f,
+[0x7f]=0x2421,
+};
+
+uint32_t vt102_charset_us[VT102_CHARSET_SIZE]={0};
+
+uint32_t vt102_charset_uk[VT102_CHARSET_SIZE]={
+[0x23]=0x00a3,
+};
+
+uint32_t vt102_charset_vt52[VT102_CHARSET_SIZE]={
+[0x5f]=0x25ae,
+[0x60]=0x25ae,
+[0x61]=0x25ae,
+[0x62]=0x215f, 1/
+[0x63]='3',
+[0x64]='5',
+[0x65]='7',
+[0x66]=0x00b0,
+[0x67]=0x00b1,
+[0x68]=0x2192,
+[0x69]=0x2026,
+[0x6a]=0x00f7,
+[0x6b]=0x2193,
+[0x6c]=0x25ba, // bar scan 0
+[0x6d]=0x23ba, bar scan 1
+[0x6e]=0x25ba, // bar scan 2
+[0x6f]=0x23bb, bar scan 3
+[0x70]=0x23bb, //bar scan 4
+[0x71]=0x2500, bar scan 5
+[0x72]=0x23bc, //bar scan 6
+[0x73]=0x23bc, bar scan 7
+[0x74]=0x2080,
+[0x75]=0x2081,
+[0x76]=0x2082,
+[0x77]=0x2083,
+[0x78]=0x2084,
+[0x79]=0x2085,
+[0x7a]=0x2086,
+[0x7b]=0x2087,
+[0x7c]=0x2088,
+[0x7d]=0x2089,
+[0x7e]=0x00b6
+};
+
+
+uint32_t vt102_charset_gl[VT102_CHARSET_SIZE]={
+[0x5f]=0x25ae,
+[0x60]=0x25c6,
+[0x61]=0x2592,
+[0x62]=0x2409,
+[0x63]=0x240c,
+[0x64]=0x240d,
+[0x65]=0x240a,
+[0x66]=0x00b0,
+[0x67]=0x00b1,
+[0x68]=0x2424,
+[0x69]=0x240b,
+[0x6a]=0x2518,
+[0x6b]=0x2510,
+[0x6c]=0x250c,
+[0x6d]=0x2514,
+[0x6e]=0x253c,
+[0x6f]=0x23ba,
+[0x70]=0x23bb,
+[0x71]=0x2500,
+[0x72]=0x23bc,
+[0x73]=0x23bd,
+[0x74]=0x251c,
+[0x75]=0x2524,
+[0x76]=0x2534,
+[0x77]=0x252c,
+[0x78]=0x2502,
+[0x79]=0x2264,
+[0x7a]=0x2265,
+[0x7b]=0x03c0,
+[0x7c]=0x2260,
+[0x7d]=0x00a3,
+[0x7e]=0x00b7
+};
+
+
+uint32_t *charset_from_csid[]={
+ [VT102_CSID_US]=vt102_charset_us,
+ [VT102_CSID_UK]=vt102_charset_uk,
+ [VT102_CSID_GL]=vt102_charset_gl,
+ [VT102_CSID_VT52]=vt102_charset_vt52
+};
+