/*
 *      Driver file for Hazeltine 1510
 *      - Use with UMIST.def
 */

int haz_setup()
{
/* brain damaged
   - twidle is special, escape just enter edit
   - hardware does RIGHT with ^P so right and nextpage swapped
*/
	ictab[27]  = ectab[27]  = ENTERedit;
	ictab[126] = ectab[126] = SPECIAL;
	ictab[16]  = ectab[16]  = RIGHT; /* ^P */
	ictab[030] = NEXTPAGE;           /* ^X */
	ectab[030] = IGN;
}

int haz_restore()
{
}

int haz_special(typein, c)
register int typein;
register char c;
/* returns the itt arrow-key code corresponding
 * to hazeltine leadin - ch combination
 * If a dud combination, puts second character back in the buffer
 * and returns type TWO.
 * If a valid combination, returns the corresponding character
 * (via negative result).
 */
 { register char ch;

    if (c!='~') editerror("character %o given to haz_special", c);
    else
    if (typein)
     {  ch = ttyin();

	switch(ch)
	 {  case 014:   return (mode==INMODE ? UP : IGN);
	    case 013:   return (mode==INMODE ? DOWN : IGN);
	    case 022:   return(SEND);
	    default:    ttyback(ch); /* replace the character */
	 }
      }
    /* fall through on unrecognised characters, and always on input */

    return(TWO);
 }

/* move the cursor on the hazeltine - four characters */
haz_move(srow, scol)
register int srow, scol;
 {  /* tilde, DC1, column, row */
    ttyout('~'); ttyout(021);
    ttyout(scol + (scol<=30 ? 96 : 0));
    ttyout(srow + 96);
 }

char haz_intwo(c)
register char c;
 { return (c=='~' ? '^' : c); }

char haz_outtwo(c)
register char c;
 { return (c=='^' ? '~' : c); }


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

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

    /* rollup, pushdown, pushup, pulldown, pullup STRINGS */
    /* and hardscroll boolean */
   { "\n", "~\032", 0, 0, "~\023", true },
	/* scrseq */

    /* scrollup, scrolldown PROCEDURES */
   scr2_up, scr2_down,

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

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

    /* clearscreen, *clearhead, *cleartail STRINGS */
   { "~\034", 0, "~\017" },
	/* clrseq */

    /* clr_screen, clr_head, clr_tail PROCEDURES */
    clrs1, clrh0, clrt1,

    /* inspace, makespace, rubout, erase STRINGS */
    { 0, 0, 0, 0 },
	/* charseq */

    /* ins_char, del_char PROCEDURES */
    insc0, delc0,

    /* bright, normal STRINGS */
    { "~\037", "~\031" },
	/* vidseq */

    /* in_two, out_two PROCEDURES */
    haz_intwo, haz_outtwo,

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

    /* setup, special, pad, restore PROCEDURES */
    haz_setup, haz_special, no_int, haz_restore

 };
