/*
 *      Driver file for DEC VT100 (VT52 mode)
 *      - Use with UMIST.def
 */

/*#define HANDSHAKE /* enable XON/XOFF protocol for this terminal only */

vt1_setup()
{
#ifdef HANDSHAKE
	extern struct tchars tchars;
	tchars.t_startc = 021;
	tchars.t_stopc = 023;
#endif
	sendseq("\033[1/m");            /* set short screen */
	sendseq("\033[?2l\033=");       /* vt52; set keypad applic mode */
}

vt1_restore()
{
	sendseq("\033>\033<");          /* set keypad numeric mode; vt100 */
	sendseq("\033[0/m");            /* set long screen */
}

vt1_move(srow, scol)
register int srow, scol;
/* ESC, ^Y, row+040, col+040 */
{
	ttyout('\033');
	ttyout('Y');
	ttyout(srow+040);
	ttyout(scol+040);
}

int vt1_special(typein,c)
int typein;
register char c;
/* returns the character type corresponding
 * to VT100 keypad escape sequences
 */
{
	register char ch;

	if (c != '\033') editerror("character %o given to vt1_special", c);
	else
	{
		if (typein)
		{
			ch = ttyin();
			switch(ch)
			{
			case '\033' : return(ENTERedit);
			case 'A' : return(UP);
			case 'B' : return(DOWN);
			case 'C' : return(RIGHT);
			case 'D' : return(LEFT);
			case 'P' : return(LSTART);
			case 'Q' : return(mode==INMODE ? TOPSCREEN : IGN);
			case 'R' : return(LEND);
			case 'S' : return(CHMODE);
			case '?' :
				ch = ttyin();
				switch(ch)
				{
				case 'w' : return(HEADRUBOUT);
				case 'y' : return(TAILERASE);
				case 't' : return(WRUBOUT);
				case 'u' : return(ERASE);
				case 'v' : return(WERASE);
				case 'q' : return(WLEFT);
				case 's' : return(WRIGHT);
				case 'p' : return(SEND);
				case 'M' : return(ENTERedit);
				}
				if (mode == INMODE)
					switch(ch)
					{
					case 'x' : return(LINEERASE);
					case 'r' : return(BOTSCREEN);
					case 'm' : return(LASTPAGE);
					case 'l' : return(NEXTPAGE);
					}
			}
		complain();
		}
	return(IGN);
	}
}

struct TERMINAL vt1_ter =
 {  /* nrows, ncols - size of the screen */
    TER_ROWS, TER_COLS,

    /* up, left, c_MODIFY, c_CONTROL, c_BLOB - single characters */
    { 0, '\010', 0, 0200|'^', 0200|' ' },
	/* onechar */

    /* rollup, pushdown, pushup, pulldown, pullup STRINGS */
    /* and hardscroll boolean */
    /* you MUST have rollup */
    { "\n", 0, 0, 0, 0, false },
	/* scrseq */

    /* scrollup, scrolldown PROCEDURES */
    /* scr1_ is pushup, pulldown */
    /* scr2_ is pushdown, pullup */
    /* scr3_ is both */
    /* scr0_ is neither (and in that case hardscroll is false) */
    scr0_up, scr0_down,

    /* splitdown, splitup, joindown, joinup STRINGS */
    { 0, 0, 0, 0 },
	/* splitseq */

    /* split_row, join_row PROCEDURES */
    split0, join0,

    /* clearscreen, *clearhead, *cleartail STRINGS */
    /* I assume ^L for clear screen, but it isn't important */
    { "\033H\033J", 0, "\033K" },
	/* clrseq */

    /* clr_screen, clr_head, clr_tail PROCEDURES */
    /* I assume hardware support for clear screen at least */
    clrs1, clrh0, clrt1,

    /* inspace, makespace, rubout, erase STRINGS */
    /* inspace puts a space and moves the cursor right,
     * makespace doesn't move it. Likewise rubout moves the
     * cursor left, erase doesn't move it
     */
    { 0, 0, 0, 0 },
	/* charseq */

    /* ins_char, del_char PROCEDURES */
    /* insc1 uses inspace, insc2 makespace */
    /* delc1 uses rubout, delc2 erase */
    /* insc0, delc0 use neither */
    insc0, delc0,

    /* bright, normal STRINGS */
    { "\033<\033[1;7m\033[?2l", "\033<\033[m\033[?2l" },
	/* vidseq */

    /* in_two, out_two PROCEDURES */
    no_char, no_char,

    /* move PROCEDURE and nmove integer */
    vt1_move, 4,

    /* setup, special, pad, restore PROCEDURES */
    vt1_setup, vt1_special, no_int, vt1_restore

 };
