aboutsummaryrefslogtreecommitdiffstats
path: root/src/vt102.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vt102.c')
-rw-r--r--src/vt102.c125
1 files changed, 121 insertions, 4 deletions
diff --git a/src/vt102.c b/src/vt102.c
index 84b544a..9f32ce0 100644
--- a/src/vt102.c
+++ b/src/vt102.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.10 2008/02/06 17:53:28 james
+ * *** empty log message ***
+ *
* Revision 1.9 2008/02/06 15:53:22 james
* *** empty log message ***
*
@@ -186,9 +189,16 @@ in_margins (VT102 * v, CRT_Pos p)
void
vt102_log_line (VT102 * v, int line)
{
+ static FILE *log;
CRT_Pos e = { VT102_COLS - 1, line };
CRT_Pos p = { 0, line };
+ if (!log)
+ log=fopen("log","a+");
+
+ if (!log) return;
+
+
for (; e.x > 0; --e.x)
{
if (v->crt.screen[CRT_ADDR_POS (&e)].chr != ' ')
@@ -202,9 +212,9 @@ vt102_log_line (VT102 * v, int line)
c = ' ';
if (c > 126)
c = ' ';
- fputc (c, stderr);
+ fputc (c, log);
}
- fputc ('\n', stderr);
+ fputc ('\n', log);
}
void
@@ -355,6 +365,7 @@ vt102_cursor_home (VT102 * v)
v->pos = v->top_margin;
vt102_cursor_normalize (v);
v->pending_wrap = 0;
+
}
vt102_cursor_absolute (VT102 * v, int x, int y)
@@ -534,6 +545,7 @@ vt102_change_attr (VT102 * v, char *na)
case 1:
v->attr |= CRT_ATTR_BOLD;
break;
+ case 21:
case 22:
v->attr &= ~CRT_ATTR_BOLD;
break;
@@ -556,7 +568,10 @@ vt102_change_attr (VT102 * v, char *na)
v->attr &= ~CRT_ATTR_REVERSE;
break;
default:
+ ;
+#if 0
fprintf (stderr, "unhandled SGR %d\n", a);
+#endif
}
}
@@ -601,12 +616,51 @@ vt102_parse_attr_string (VT102 * v, char *buf, int len)
vt102_change_attr (v, &num[o]);
}
+void vt102_save_state(VT102 *v)
+{
+v->saved.pos=v->pos;
+v->saved.attr=v->attr;
+v->saved.origin_mode=v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE];
+}
+
+void vt102_restore_state(VT102 *v)
+{
+v->pos=v->saved.pos;
+v->attr=v->saved.attr;
+v->private_modes[VT102_PRIVATE_MODE_ORIGIN_MODE]=v->saved.origin_mode;
+vt102_cursor_normalize(v);
+v->pending_wrap = 0;
+}
+
void
vt102_parse_esc (VT102 * v, int c)
{
-
switch (c)
{
+case 'E':
+ if(v->pos.y==v->bottom_margin.y) {
+ vt102_log_line (v, v->pos.y);
+ crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1);
+ } else {
+ vt102_cursor_relative(v,0,1);
+ }
+ break;
+case 'H':
+ v->tabs[v->pos.x]++;
+ break;
+case 'M':
+ if(v->pos.y==v->top_margin.y) {
+ crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1);
+ } else {
+ vt102_cursor_relative(v,0,-1);
+ }
+ break;
+case '7':
+ vt102_save_state(v);
+ break;
+case '8':
+ vt102_restore_state(v);
+ break;
#if 0
case '=':
case '>':
@@ -618,8 +672,11 @@ vt102_parse_esc (VT102 * v, int c)
break;
#endif
default:
+#if 0
fprintf (stderr, "unhandled ESC \\033 \\%03o (ESC %c)\n", c,
(c < 32) ? '?' : c);
+#endif
+ ;
}
}
void
@@ -663,7 +720,19 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
case 'D':
vt102_cursor_relative (v, -narg, 0);
break;
+ case 'E':
+ vt102_cursor_relative (v, 0, narg);
+ vt102_cursor_carriage_return (v);
+ break;
+ case 'F':
+ vt102_cursor_relative (v, 0, -narg);
+ vt102_cursor_carriage_return (v);
+ break;
+ case 'G':
+ vt102_cursor_absolute (v, narg-1, v->pos.y);
+ break;
case 'H':
+ case 'f':
{
int x, y;
@@ -778,13 +847,27 @@ vt102_parse_csi (VT102 * v, char *buf, int len)
vt102_cursor_home (v);
break;
+ case 's':
+ v->saved.pos=v->pos;
+ break;
+ case 'u':
+ v->pos=v->saved.pos;
+ vt102_cursor_normalize(v);
+ v->pending_wrap = 0;
+ break;
default:
+#if 0
fprintf (stderr, "unhandled CSI \\033%s\n", buf, buf[0]);
+#endif
+ ;
}
break;
default:
+#if 0
fprintf (stderr, "unhandled CSI \\033%s\n", buf, buf[0]);
+#endif
+ ;
}
@@ -815,7 +898,7 @@ vt102_parse_char (VT102 * v, int c)
VT102_parser *p = &v->parser;
#if 0
- fprintf (stderr, "%c pc %d %d %d %d %d\n", (c < 32) ? 32 : c, c,
+ fprintf (stderr, "char %c pc %d %d %d %d %d\n", (c < 32) ? 32 : c, c,
p->in_csi, p->in_escape, v->pos.x, v->pos.y);
#endif
if (p->in_csi)
@@ -852,7 +935,10 @@ vt102_parse_char (VT102 * v, int c)
/*STX*/ case 2:
/*ETX*/ case 3:
/*EOT*/ case 4:
+ break;
/*ENQ*/ case 5:
+ /*FIXME: Should send ack*/
+ break;
/*ACK*/ case 6:
/*BEL*/ case 7:
break;
@@ -907,6 +993,7 @@ vt102_parse_char (VT102 * v, int c)
}
v->crt.pos = v->pos;
+ v->crt.hide_cursor=v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] ? 0:1;
if (v->current_line.y != v->pos.y)
{
@@ -951,9 +1038,39 @@ vt102_reset (VT102 * v)
v->private_modes[VT102_PRIVATE_MODE_AUTO_WRAP] = 1;
v->private_modes[VT102_PRIVATE_MODE_AUTO_REPEAT] = 1;
+ v->private_modes[VT102_PRIVATE_MODE_SHOW_CURSOR] = 1;
vt102_cursor_home (v);
vt102_reset_tabs (v);
v->current_line = v->pos;
+ vt102_save_state(v);
+
+#if 0
+{
+char buf[3];
+int i;
+ for (i=0;i<200;++i) {
+ sprintf(buf,"%3d",i);
+ vt102_parse_char (v,buf[0]);
+ vt102_parse_char (v,buf[1]);
+ vt102_parse_char (v,buf[2]);
+ vt102_parse_char (v,13);
+ vt102_parse_char (v,27);
+ vt102_parse_char (v,'M');
+ }
+ vt102_parse_char(v,'f');
+ vt102_parse_char (v,13);
+ for (i=0;i<23;++i) {
+ vt102_parse_char (v,27);
+ vt102_parse_char (v,'M');
+ }
+ vt102_parse_char(v,'b');
+ vt102_parse_char (v,13);
+}
+#endif
+
+
+ vt102_status_line (v, "VT102 foo bar baz I'm the urban spaceman baby");
+
}