/* Copyright (C) Magna Carta Software, Inc. 1990. All Rights Reserved C COMMUNICATIONS TOOLKIT VT.C -- VTxxx terminal emulation routines. t->mode is bit-encoded as: Bit 0: 1 = keypad application mode; Bit 1: 1 = keypad application mode; Bit 2: 2 = keypad application mode; Bit 3: CR = CRLF; Bit 4: 1 = keyclick on; t->ansimode is bit-encoded as: Bit 0: ansi mode in effect; Bit 1: 2 = CR => CRLF; Bit 2: printer controller mode; */ #define CCT_DEVELOPMENT #include #if !defined(ANSI_H_INCLUDED) #include #endif #if !defined(VT_H_INCLUDED) #include #endif /* VT_DISPATCH_CTRL_ -- Deal with control characters sent from the host. This function is used by all ANSI X3.64 and VTxxx series terminals and emulators. */ short vt_dispatch_ctrl_(TERMINAL *t, short ch) { short ret = 0; #if XDEBUG (*t->putc)(ch, t->att); #endif switch(ch) { case NUL: /* ignore NULs */ break; case ENQ: /* ENQ, send answerback string */ /* term_c_puts(t, t->answerback); */ break; case BEL: /* BEL, sounds speaker */ set_sound_on(1175, 250); break; case BS: /* BS, moves cursor left */ if (t->ccol > t->lmargin) (*t->cur_pos_)(t, --t->ccol, t->crow); break; case HT: /* HT, move to next tab stop or EOL */ ret = term_find_next_tab_stop(t); if (ret != EOF) (*t->cur_pos_)(t, t->ccol = ret, t->crow); break; case LF: if (t->crow < t->bmargin) (*t->cur_pos_)(t, t->ccol, ++t->crow); else (*t->scroll)(t, t->lmargin, t->tmargin, t->rmargin, t->bmargin, t->d_att, 1); break; case VT: /* VT, move to next row */ case FF: /* FF, move to next row */ (*t->cur_pos)(t, CUD); break; case CR: /* CR, move to left margin */ (*t->cur_pos_)(t, 0, t->crow); if (isaddlf_(t)) { if (t->crow < t->bmargin) (*t->cur_pos_)(t, 0, ++t->crow); else (*t->scroll)(t, t->lmargin, t->tmargin, t->rmargin, t->bmargin, t->d_att, 1); } /* CHECK IF IN PRINTER CONTROLLER MODE */ if (t->ansimode & PRN_CTRL) { term_print_line_(t); } break; case SO: /* SO, select G1 char. set */ /* select G1 character set */ break; case SI: /* SO, select G1 char. set */ /* select G0 character set */ break; case CAN: /* CAN, cancel esc. sequence */ case SUB: /* SUB, cancel esc. sequence */ ret = EOF; /* reset parsing */ break; case DEL: /* DEL, ignore on input */ break; default: break; } return (ret); } /* VT_MEDIA_COPY_ -- VTxxx supported media copy commands. ANSI X3.64 commands CSIxxPn i */ void vt_media_copy_(TERMINAL *t) { WORD i=0; while (i < t->parmcount || i == 0) { switch (t->num[i]) { case 0: /* copy entire screen to primary aux. device */ break; case 1: /* print cursor line */ break; case 4: /* printer controller mode off */ t->mode &= ~PRN_AUTO; break; case 5: /* printer controller mode on */ t->mode |= PRN_AUTO; break; default: #if XDEBUG printf("HOST: Unrecognized DEC printer controller sequence"); #endif break; } i++; } } /* VT_RESET_MODE_ -- Called on receipt of "CSI Ps;...;Psh" (SM) sequence. This routine sets DEC private modes. */ void vt_reset_mode_(TERMINAL *t, short cmd) { WORD i=0; while (i < t->parmcount || i== 0) { switch (cmd) { /* set vs. reset interpretation */ case MODE_DECANM: /* ANSI/VT52 mode */ t->mode &= ~DECANM; init_term(t->port, t, (void (*)()) vt52_init, t->vid_init); break; case MODE_DECARM: /* auto-repeat on or off */ t->mode &= ~DECARM; break; case MODE_DECAWM: /* wrap on or off */ t->mode &= ~DECAWM; break; case MODE_DECCKM: /* cursor key mode */ if (t->mode & DECKPAM) { t->mode &= ~DECCKM; } break; case MODE_DECCOLM: /* 132/80 column mode */ t->mode &= ~DECCOLM; break; case MODE_DECINLM: /* 480 vs. 240 scan lines/sec. */ t->mode &= ~DECINLM; break; case MODE_DECOM: /* origin at margin vs. normal origin */ t->mode &= ~DECOM; t->clmargin = t->ctmargin = 0; t->cbmargin = t->d_rows - 1; t->crmargin = t->d_cols - 1; break; case MODE_DECSCLM: /* smooth/jump scrolling */ t->mode &= ~DECSCLM; break; case MODE_DECSCNM: /* white/black or black/white screen */ t->mode &= ~DECSCNM; t->att = ((t->att & 0XF) << 4) | (t->att >> 4); t->att &= 0X7F; /* remove blink */ break; default: ansi_reset_mode_(t); break; } i++; } if (isansi_(t) && !iscur_(t)) { term_assign_key(t, UP_ARROW, 0, "\x1B[A"); term_assign_key(t, DOWN_ARROW, 0, "\x1B[B"); term_assign_key(t, RIGHT_ARROW, 0, "\x1B[C"); term_assign_key(t, LEFT_ARROW, 0, "\x1B[D"); } } /* VT_SET_MODE_ -- Called on receipt of "CSI Ps;...;Psh" (SM) sequence. This routine sets DEC private modes. */ void vt_set_mode_(TERMINAL *t, short cmd) { WORD i=0; while (i < t->parmcount || i == 0) { switch (cmd) { /* set vs. reset interpretation */ case MODE_DECANM: /* ANSI/VT52 mode */ t->mode |= DECANM; init_term(t->port, t, (void (*)()) vt100_init, t->vid_init); break; case MODE_DECARM: /* auto-repeat on or off */ t->mode |= DECARM; break; case MODE_DECAWM: /* wrap on or off */ t->mode |= DECAWM; break; case MODE_DECCKM: /* cursor key mode */ t->mode |= DECCKM; break; case MODE_DECCOLM: /* 132/80 column mode */ t->mode |= DECCOLM; break; case MODE_DECINLM: /* 480 vs. 240 scan lines/sec. */ t->mode |= DECINLM; break; case MODE_DECOM: /* origin at margin vs. normal origin */ t->mode |= DECOM; t->ctmargin = t->tmargin; t->cbmargin = t->bmargin; break; case MODE_DECSCLM: /* smooth/jump scrolling */ t->mode |= DECSCLM; break; case MODE_DECSCNM: /* white/black or black/white screen */ t->mode |= DECSCNM; t->att = ((t->att & 0XF) << 4) | (t->att >> 4); if (t->att & 0X80) t->att &= 0X7F; /* remove blink */ break; default: ansi_set_mode_(t); break; } i++; } if (isansi_(t) && iscur_(t)) { term_assign_key(t, UP_ARROW, 0, "\x1BOA"); term_assign_key(t, DOWN_ARROW, 0, "\x1BOB"); term_assign_key(t, RIGHT_ARROW, 0, "\x1BOC"); term_assign_key(t, LEFT_ARROW, 0, "\x1BOD"); } }