/*
 *      Driver file for Cifer 2605
 *      - Use with UMIST.def
 */
/*#define HANDSHAKE /* enable <cntl-s> <cntl-q> handshake */

cf05_move(srow, scol)
register int srow, scol;
 {  /* ESC, P, col, row */
    ttyout('\033');
    ttyout('P');
    ttyout(scol);
    ttyout(srow);
 }


int cf05_setup() {
#ifdef HANDSHAKE
extern struct tchars tchars;

tchars.t_startc = 021;
tchars.t_stopc = 023;
#endif HANDSHAKE
sendseq("\033O");                   /* highlights off */
sendseq("\033L\033G\033Y\033I");    /* set highlights inverse video only */
}

int cf05_restore() {
   sendseq("\033M");                /* clear highlights */
}

int cf05_special(typein,c) int typein; register char c;
{
   register char ch;

   if (c != '\033')
      editerror("character %o given to cf05_special",c);
   else {
      if (typein) {
	 ch = ttyin();
	 switch(ch) {
	 case 'C': return(RIGHT);
	 case 'D': return(LEFT);
	 case 'H': return(LSTART);
	 case '_': return(LEND);
	 case 'l': return(WRUBOUT);
	 case '"': return(HEADRUBOUT);
	 case 'm': return(WERASE);
	 case '#': return(TAILERASE);
	 case 'x': return(ERASE);
	 case '$': return(RUBOUT);
	 case 'y': return(CONTROL);
	 case '%': return(READPIPE);
	 case 'f': return(SEND);
	 case '&': return(OVER);
	 case 033:
	 case 'g': return(ENTERedit);
	 case '(': return(CHMODE);
	 case 'e': return(WLEFT);
	 case ')': return(LSTART);
	 case 'o': return(WRIGHT);
	 case '+': return(LEND);
	 }
	 if (mode==INMODE) switch(ch) {
	 case '@': return(DOWN);
	 case 'A': return(UP);
	 case '[':
	 case 'B': return(NEXTPAGE);
	 case ']':
	 case 'J': return(LASTPAGE);
	 case 'K':
	 case '!': return(LINEERASE);
	 case 'i': return(BOTSCREEN);
	 case 'n': return(TOPSCREEN);
	 }
	 complain();
      }
      return(IGN);
   }
}


struct TERMINAL cf05_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 */
    { "\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 */
    { "\033N", "\033O" },
	/* vidseq */

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

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

    /* setup, special, pad, restore PROCEDURES */
   cf05_setup, cf05_special, no_int, cf05_restore

 };
