+ 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;
+
+ y = narg - 1;
+
+ ptr = index (arg, ';');
+ if (ptr)
+ x = atoi (ptr + 1) - 1;
+ else
+ x = 0;
+
+ vt102_cursor_absolute (v, x, y);
+ }
+ break;
+ case 'I':
+ while (narg--)
+ vt102_cursor_advance_tab (c->v);
+ break;
+ case 'J':
+ if (len == 2)
+ narg = 0; /*Different default */
+ switch (narg)
+ {
+ case 0:
+ crt_erase (&v->crt, v->pos, v->screen_end, 1, v->color);
+ break;
+ case 1:
+ crt_erase (&v->crt, v->screen_start, v->pos, 1, v->color);
+ break;
+ case 2:
+ crt_erase (&v->crt, v->screen_start, v->screen_end, 1,
+ v->color);
+ break;
+ }
+ break;
+ case 'K':
+ {
+ CRT_Pos ls = { 0, v->pos.y };
+ CRT_Pos le = { VT102_COLS - 1, v->pos.y };
+ if (len == 2)
+ narg = 0; /*Different default */
+
+ switch (narg)
+ {
+ case 0:
+ crt_erase (&v->crt, v->pos, le, 1, v->color);
+ break;
+ case 1:
+ crt_erase (&v->crt, ls, v->pos, 1, v->color);
+ break;
+ case 2:
+ crt_erase (&v->crt, ls, le, 1, v->color);
+ break;
+ }
+ }
+ break;
+
+ case 'L':
+ if ((v->pos.y >= v->top_margin.y)
+ && (v->pos.y <= v->bottom_margin.y))
+ {
+ while (narg--)
+ crt_scroll_down (&v->crt, v->pos, v->bottom_margin, 1,
+ v->color);
+ }
+ break;
+
+ case 'M':
+ if ((v->pos.y >= v->top_margin.y)
+ && (v->pos.y <= v->bottom_margin.y))
+ {
+ while (narg--)
+ {
+ vt102_history (c, v->pos, v->bottom_margin);
+ crt_scroll_up (&v->crt, v->pos, v->bottom_margin, 1,
+ v->color);
+ }
+ }
+ break;
+ case 'P':
+ while (narg--)
+ vt102_delete_from_line (v, v->pos);
+ break;
+ case 'R':
+ //FIXME: cursor position report - does anything use that?
+ break;
+ case 'S':
+ while (narg--)
+ {
+ vt102_history (c, v->top_margin, v->bottom_margin);
+ crt_scroll_up (&v->crt, v->top_margin, v->bottom_margin, 1,
+ v->color);
+ }
+ break;
+ case 'T':
+ while (narg--)
+ crt_scroll_down (&v->crt, v->top_margin, v->bottom_margin, 1,
+ v->color);
+ break;
+ case 'X':
+ {
+ CRT_Pos end = v->pos;
+ if (!narg)
+ narg++;
+
+ end.x += narg - 1;
+ if (end.x > v->bottom_margin.x)
+ end.x = v->bottom_margin.x;
+
+ crt_erase (&v->crt, v->pos, end, 1, v->color);
+ }
+ break;
+ case 'Z':
+ while (narg--)
+ vt102_cursor_retreat_tab (c->v);
+ break;
+ case '`':
+ vt102_cursor_absolute (v, narg - 1, v->pos.y);
+ break;
+ case 'b':
+ while (narg--)
+ vt102_regular_char (c, v, v->last_reg_char);
+ break;
+ case 'c':
+ //FIXME:
+ break;
+ case 'd':
+ vt102_cursor_absolute (v, v->pos.x, narg - 1);
+ break;
+ case 'g':
+ if (len == 2)
+ narg = 0; /*Different default */
+
+ switch (narg)
+ {
+ case 0:
+ v->tabs[v->pos.x] = 0;
+ break;
+ case 2: //FIXME: - LA120 says current line only WTF?
+ case 3:
+ memset (v->tabs, 0, sizeof (v->tabs));
+ break;
+ }
+ break;
+
+ case 'i': //4,5 Turn printer on and off WTF?
+ //FIXME
+ break;
+ case 'h':
+ case 'l':
+ vt102_parse_mode_string (v, &buf[1], len - 1);
+ break;
+
+
+ case 'm':
+ vt102_parse_attr_string (v, &buf[1], len - 1);
+ break;
+ case 'n': // 6 request cursor position
+ //FIXME
+ break;
+ case 'r':
+ v->top_margin = v->screen_start;
+ v->bottom_margin = v->screen_end;
+
+ if ((len > 2) && (ptr = index (arg, ';')))
+ {
+ ptr++;
+ v->top_margin.y = narg - 1;
+ v->bottom_margin.y = atoi (ptr) - 1;
+ }
+
+ if (v->top_margin.y < v->screen_start.y)
+ v->top_margin.y = v->screen_start.y;
+ if (v->top_margin.y > v->screen_end.y)
+ v->top_margin.y = v->screen_end.y;
+ if (v->bottom_margin.y < v->screen_start.y)
+ v->bottom_margin.y = v->screen_start.y;
+ if (v->bottom_margin.y > v->screen_end.y)
+ v->bottom_margin.y = v->screen_end.y;
+
+ 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:
+ log_f (c->l, "<%s:%d unhandled CSI: \\033%s>", __FILE__, __LINE__,
+ buf);
+
+ ;
+ }
+ break;
+ default:
+ log_f (c->l, "<%s:%d unhandled sequence: \\033%s>", __FILE__, __LINE__,
+ buf);
+ ;
+ }
+
+
+
+}
+
+void
+vt102_status_line (VT102 * v, char *str)
+{
+ int i = VT102_COLS;
+ CRT_CA *ca = &v->crt.screen[CRT_ADDR (VT102_STATUS_ROW, 0)];
+
+ while (i--)
+ {
+ ca->attr = CRT_ATTR_REVERSE;
+ ca->color = CRT_COLOR_NORMAL;
+ ca->chr = *str;
+ if (*str)
+ str++;
+ ca++;
+ }
+
+}
+
+
+void
+vt102_parser_reset (VT102_parser * p)
+{
+ p->in_cmd = 0;
+ p->cmd_more_bytes=0;
+ p->cmd_termination=0;
+ p->in_escape = 0;
+}
+
+
+void
+vt102_reset_state (VT102 * v)
+{
+ vt102_parser_reset (&v->parser);
+
+ v->attr = CRT_ATTR_NORMAL;
+ v->color = CRT_COLOR_NORMAL;
+
+ v->application_keypad_mode = 0;
+
+ v->top_margin = v->screen_start;
+ v->bottom_margin = v->screen_end;
+
+ memset (v->modes, 0, VT102_NMODES);
+ memset (v->private_modes, 0, VT102_NMODES);
+
+ 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;
+ v->modes[VT102_MODE_LOCAL_ECHO_OFF] = 1;
+
+ vt102_reset_tabs (v);
+}
+
+static void pre_parse_cmd(int ch,VT102_parser *p)
+{
+if (ch>TABLE_LENGTH) return;
+if (ch<0) return;
+
+p->cmd_more_bytes=0;
+p->in_cmd=0;
+
+p->cmd_termination=vt102_cmd_termination[ch];
+if (p->cmd_termination) {
+ p->in_cmd++;
+ return;
+}
+
+p->cmd_more_bytes=vt102_cmd_length[ch];
+
+if (p->cmd_more_bytes) {
+ p->in_cmd++;
+ return;
+}
+}
+
+void
+vt102_parse_char (Context * c, int ch)
+{
+ VT102 *v = c->v;
+ VT102_parser *p = &v->parser;
+
+#if 1
+ log_f (c->l, "char %3d %c ie=%d ic=%d cmb=%d ct=%d %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
+
+/* Turn anything non-ascii into '?' */
+#if 0
+ if ((ch != SYM_CHAR_RESET) && (ch != 0xb9) && (ch > 127))
+ {
+ ch = '?';
+ }
+#endif
+
+
+#if 0
+ if (p->dca_ptr == 2)
+ {
+ p->in_dca = 0;
+ }
+#endif
+ if (ch == SYM_CHAR_RESET)
+ {
+ vt102_reset_state (v);
+ }
+ else if (p->in_cmd)
+ {
+ p->cmd_buf[p->cmd_ptr++] = ch;
+ if (p->cmd_more_bytes) p->cmd_more_bytes--;
+
+
+ if (p->cmd_more_bytes==1) p->in_cmd=0;
+
+ switch (p->cmd_termination) {
+ case 0:
+ break;
+ default:
+ if (p->cmd_termination==ch) p->in_cmd=0;
+ break;
+ case CSI_ENDER:
+ if (csi_ender(ch)) p->in_cmd=0;
+ break;
+ }
+
+ if (!p->in_cmd) {
+ vt102_parse_esc(c);
+ p->cmd_more_bytes=0;
+ }
+ }
+ else if (p->in_escape)
+ {
+
+ p->cmd_ptr = 0;
+ p->cmd_buf[p->cmd_ptr++] = ch;
+ p->in_escape = 0;
+
+ pre_parse_cmd(ch,p);
+
+ if (!p->in_cmd)
+ vt102_parse_esc(c);
+ }
+ else if (ch == 0x9b) /*One byte CSI */
+ {
+ p->cmd_ptr = 0;
+ p->cmd_buf[p->cmd_ptr++] = '[';
+
+ pre_parse_cmd(ch,p);
+ }
+ else
+ {
+
+ switch (ch)
+ {
+ /*NUL*/ case 0:
+ /*SOH*/ case 1:
+ /*STX*/ case 2:
+ /*ETX*/ case 3:
+ /*EOT*/ case 4:
+ break;
+ /*ENQ*/ case 5:
+ if (c->t)
+ {
+ c->t->xmit (c->t, "vt102", 5);
+ }
+ break;
+ /*ACK*/ case 6:
+ /*BEL*/ case 7:
+ break;
+ /*BS*/ case 8:
+ vt102_cursor_retreat (c->v);
+ break;
+ /*HT*/ case 9:
+ vt102_cursor_advance_tab (c->v);
+ break;
+ /*LF*/ case 10:
+ /*VT*/ case 11:
+ /*FF*/ case 12:
+ vt102_cursor_advance_line (c);
+ if (!v->modes[VT102_MODE_NEWLINE_MODE])
+ break;