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

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


int cf34_setup() {
extern char qread();

#ifdef HANDSHAKE
extern struct tchars tchars;

tchars.t_startc = 021;
tchars.t_stopc = 023;
#endif /* HANDSHAKE */

sendseq("\033^4"); /* enable message line */
sendseq("\033^;   "); /* clear message line */
sendseq("\033^;K<8ddeedd::  rruunnnniinngg");
sendseq("\033#"); /* keyboard buffered lock */
/*sendseq("\0336"); /* auto linewrap off */
/*sendseq("\033^@ "); /* define spaces for insert/delete char */
sendseq("\0338"); /* roll mode short */
sendseq("\033O"); /* highlights off */
sendseq("\033L\033G\033Y\033I"); /* set highlights to reverse video */
sendseq("\033*W3"); /* cursor flashing block */
/* program ded keys */
sendseq("\033^\\)D c$[ D."); /* arrow left */
sendseq("\033^\\)E b$[ C."); /* arrow right */
sendseq("\033^\\)F a$[ @."); /* arrow down */
sendseq("\033^\\)G `$[ A."); /* arrow up */
sendseq("\033^\\*@#@$[ 0."); /* keypad 0 */
sendseq("\033^\\*A#A$[ 1."); /* keypad 1 */
sendseq("\033^\\*B#B$[ 2."); /* keypad 2 */
sendseq("\033^\\*C#C$[ 3."); /* keypad 3 */
sendseq("\033^\\*D#D$[ 4."); /* keypad 4 */
sendseq("\033^\\*E#E$[ 5."); /* keypad 5 */
sendseq("\033^\\*F#F$[ 6."); /* keypad 6 */
sendseq("\033^\\*G#G$[ 7."); /* keypad 7 */
sendseq("\033^\\*H#H$[ 8."); /* keypad 8 */
sendseq("\033^\\*I#I$[ 9."); /* keypad 9 */
sendseq("\033^\\*J#J$[ .."); /* keypad . */
sendseq("\033^\\*L#L$[ ,."); /* keypad , */
sendseq("\033^\\*M#M$[ -."); /* keypad - */
sendseq("\033^\\)K#N$[$[."); /* keypad enter */
sendseq("\033^\\'G 5$[ a."); /* blank key */
sendseq("\033^\\(M P$[ b."); /* clear field */
sendseq("\033^\\)N [$[ c."); /* clear screen */
sendseq("\033^\\'B Y$[ d."); /* copy */
sendseq("\033^\\(A X$[ e."); /* send page */
sendseq("\033^\\(C T$[ f."); /* send line */
sendseq("\033^\\)C ~"); /* disable home key */
sendseq("\033^\\(K ~"); /* disable insrt char key */
sendseq("\033^\\(J ~"); /* disable del char key */
sendseq("\033^\\(I ~"); /* disable insrt line key */
sendseq("\033^\\(H ~"); /* disable del line key */
sendseq("\033`"); qread(); qread(); /* read cursor char */
sendseq("\033$"); /* keyboard unlock */
}

int cf34_restore() {
extern char qread();

sendseq("\033#"); /* keyboard buffered lock */
/*sendseq("\0335"); /* enable auto linewrap */
sendseq("\033M"); /* reset highlights */
sendseq("\033*W1"); /* cursor flashing underline */
sendseq("\033^\\*@(0 0"); /* keypad 0 */
sendseq("\033^\\*A(0 1"); /* keypad 1 */
sendseq("\033^\\*B(0 2"); /* keypad 2 */
sendseq("\033^\\*C(0 3"); /* keypad 3 */
sendseq("\033^\\*D(0 4"); /* keypad 4 */
sendseq("\033^\\*E(0 5"); /* keypad 5 */
sendseq("\033^\\*F(0 6"); /* keypad 6 */
sendseq("\033^\\*G(0 7"); /* keypad 7 */
sendseq("\033^\\*H(0 8"); /* keypad 8 */
sendseq("\033^\\*I(0 9"); /* keypad 9 */
sendseq("\033^\\*J(0 ."); /* keypad . */
sendseq("\033^\\*L(0 ,"); /* keypad , */
sendseq("\033^\\*M(0 -"); /* keypad - */
sendseq("\033^\\)K(0$M"); /* keypad enter */
sendseq("\0337"); /* roll mode long */
sendseq("\033^;   "); /* blank message line */
sendseq("\033^5"); /* enable status line */
sendseq("\033`"); qread(); qread(); /* read cursor character */
sendseq("\033$"); /* keyboard unlock */
}

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

if (c != '\033') {
 editerror("character %o given to cf34_special",c);
 return(IGN);
 }
if (typein) {
 ch = ttyin();
 switch(ch) {
  case 'C': return(RIGHT);
  case 'D': return(LEFT);
  case 033: return(ENTERedit);
  case '0': return(OVER);
  case '1': return(CONTROL);
  case '2': return(READPIPE);
  case '4': return(LSTART);
  case '5': return(LEND);
  case '7': return(WLEFT);
  case '8': return(WRIGHT);
  case ',': return(CHMODE);
  case '-': return(SEND);
  case 'a': return(TAILERASE);
  case 'b': return(WERASE);
  case 'c': return(ERASE);
  case 'd': return(WRUBOUT);
  case 'e': return(HEADRUBOUT);
  }
 if (mode!=INMODE) {complain(); return(IGN);}
 switch(ch) {
  case '@': return(DOWN);
  case 'A': return(UP);
  case '3': return(BOTSCREEN);
  case '6': return(TOPSCREEN);
  case '9': return(LASTPAGE);
  case '.': return(NEXTPAGE);
  case 'f': return(LINEERASE);
  default:  complain(); return(IGN);
  }
 }
else return(IGN);
}



struct TERMINAL cf34_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", "\033^.", 0, 0, "\033^)", true }, */
    { "\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) */
    /* scr2_up, scr2_down, */
    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, "\033^-", 0, "\033^(" }, */
    { 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 */
    cf34_move, 4,

    /* setup, special, pad, restore PROCEDURES */
   cf34_setup, cf34_special, no_int, cf34_restore

 };
