/************************************************************************
 *                                                                      *
 *                      copyright Richard Bornat 1981                   *
 *                                                                      *
 ************************************************************************/

/************************************************************************
 *                                                                      *
 *      settings for tec 630. This must be the worst terminal in        *
 *      the world (I never want to touch a worse one). It needs         *
 *      handshaking (version 7 TANDEM mode) and padding out of          *
 *      most of the hardware operations - clearscreen needs an          *
 *      almost unbelievable amount of dead time.  It should be          *
 *      melted down and the scrap thrown down a volcano, or better      *
 *      dropped into the sun. Whoever designed it is an even bigger     *
 *      twit than the poor unfortunate who bought it. It took hours     *
 *      of my time to fight this thing and I'm not sure it's dead yet.  *
 *                                                                      *
 ************************************************************************/

#define TER_ROWS 25
#define TER_COLS 80

tec_move(srow, scol)
register int srow, scol;
 { ttyout(033); ttyout(075);
   ttyout(srow+040); ttyout(scol+040);
 }

int tec_special(typein, c)
int typein;
register char c;
/* used to return the character type corresponding to
 * 'esc, character' combination on tec630.
 * On input returns class IGN (which will treat character as
 * control character)
 */
  { if (!typein) return(IGN);
    else
     {  register char ctype = IGN;

        switch(ttyin())
         {
            /* the enter key (in shift lock) */
            case 02:            ctype = ENTERedit; break;
            /* the 'clear screen' key */
            case 05:            ctype = LINEERASE; break;
            /* the delete/insert line key */
            case 07: case 014:
                                ctype = WRIGHT; break;
            /* the erase-eol key */
            case 013:           ctype = TAILERASE; break;
            /* the clear/set tab key */
            case 022: case 023:
                                ctype = WLEFT; break;
            /* the next/prev page key */
            case 027:           ctype = LSTART; break;
            case 030:           ctype = LEND; break;
            /* the page 1 key */
            case 031:           ctype = SEND; break;
            /* the down key */
            case 0107:          if (mode==INMODE) ctype=DOWN; break;
            /* the print key */
            case 0120:          ctype = HEADRUBOUT; break;
            /* the scroll up/down key */
            case 0141:          if (mode==INMODE) ctype=BOTSCREEN; break;
            case 0142:          if (mode==INMODE) ctype=TOPSCREEN; break;
            /* typing one of these gives a control mark */
            case '^': case '~':
                                ctype = CONTROL; break;
         }

        return(ctype);
     }
 }

#define PADCOUNT 4

tec_pad()
 {  register int i;
    for (i=1; i<=PADCOUNT; i++) ttyout('\000');
 }

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

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

    /* rollup, pushdown, pushup, pulldown, pullup STRINGS */
    /* and hardscroll boolean */
    { "\0\0\n", "\0\0\033\014", 0, 0, "\0\0\033\007", true },
        /* 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,

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

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

    /* clearscreen, *clearhead, *cleartail STRINGS */
    { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\033\006", 0, "\0\0\033\013" },
        /* 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\033\021", 0, "\0\033\020" },
        /* 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 */
    { 0, 0 },
        /* vidseq */

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

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

    /* setup, special, pad PROCEDURES */
    no_int, tec_special, tec_pad

 };

/* table of characters for input (INMODE) mode */
char  ictab[] =
 {      /* 000 - 007, null - ^G */
        IGN, IGN, IGN, IGN, IGN, ENTERedit, IGN, WERASE,
        /* 010 - 017, ^H - ^O */
        LEFT, TAB, NL, UP, RIGHT, CR, IGN, IGN,
        /* 020 - 027, ^P - ^W */
        /* ^Q and ^S are unuseable because they are used for
         * handshaking
         */
        IGN, IGN, ERASE, IGN, IGN, IGN, IGN, WRUBOUT,
        /* 030 - 037, ^X - ^_ */
        IGN, IGN, IGN, SPECIAL, IGN, IGN, CHMODE, IGN,
        SPACE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, RUBOUT
 };

/* table of characters for edit (EDMODE) mode. Much the same
 * as ictab, except for the absence of UP, DOWN, TOPSCREEN,
 * BOTSCREEN and LINEERASE. CR or LF are also COMMAND in this mode
 */
char  ectab[] =
 {      /* 000 - 007, null - ^G */
        IGN, IGN, IGN, IGN, IGN, ENTERedit, IGN, WERASE,
        /* 010 - 017, ^H - ^O */
        LEFT, TAB, COMMAND, IGN, RIGHT, COMMAND, IGN, IGN,
        /* 020 - 027, ^P - ^W */
        IGN, IGN, ERASE, IGN, IGN, IGN, IGN, WRUBOUT,
        /* 030 - 037, ^X - ^_ */
        IGN, IGN, IGN, SPECIAL, IGN, IGN, CHMODE, IGN,
        SPACE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, ONE,
        ONE, ONE, ONE, ONE, ONE, ONE, ONE, RUBOUT
 };

#define T_STARTC 021
#define T_STOPC 023
