home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / ue312os2.zip / src / hp150.c < prev    next >
C/C++ Source or Header  |  1994-08-26  |  14KB  |  583 lines

  1. /*
  2.  * The routines in this file provide support for HP150 screens
  3.  * and routines to access the Keyboard through KEYCODE mode.
  4.  * It compiles into nothing if not an HP150 screen device.
  5.  * added by Daniel Lawrence
  6.  */
  7.  
  8. #define    termdef    1            /* don't define "term" external */
  9.  
  10. #include        <stdio.h>
  11. #include        "estruct.h"
  12. #include    "eproto.h"
  13. #include    "edef.h"
  14. #include    "elang.h"
  15.  
  16. #if     HP150
  17.  
  18. #define NROW    24                      /* Screen size.                 */
  19. #define NCOL    80                      /* Edit if you want to.         */
  20. #define    MARGIN    8            /* size of minimim margin and    */
  21. #define    SCRSIZ    64            /* scroll size for extended lines */
  22. #define    NPAUSE    15            /* # times thru update to pause */
  23. #define BEL     0x07                    /* BEL character.               */
  24. #define ESC     0x1B                    /* ESC character.               */
  25.  
  26. extern int PASCAL NEAR  openhp();    /* Forward references.          */
  27. extern int PASCAL NEAR    hpflush();
  28. extern int PASCAL NEAR  closehp();
  29. extern int PASCAL NEAR    hp15kopen();
  30. extern int PASCAL NEAR    hp15kclose();
  31. extern int PASCAL NEAR  hp15move();
  32. extern int PASCAL NEAR  hp15eeol();
  33. extern int PASCAL NEAR  hp15eeop();
  34. extern int PASCAL NEAR  hp15beep();
  35. extern int PASCAL NEAR    gethpkey();
  36. extern int PASCAL NEAR    hp15rev();
  37. extern int PASCAL NEAR    hp15cres();
  38. #if    COLOR
  39. extern int PASCAL NEAR    hp15fcol();
  40. extern int PASCAL NEAR    hp15bcol();
  41. #endif
  42.  
  43. PASCAL NEAR hp15parm();
  44. PASCAL NEAR rawon();
  45. PASCAL NEAR rawoff();
  46. PASCAL NEAR ckeyoff();
  47. PASCAL NEAR ckeyon();
  48. PASCAL NEAR agios();
  49. PASCAL NEAR keycon();
  50. PASCAL NEAR keycoff();
  51. PASCAL NEAR defkey();
  52. PASCAL NEAR undefkey();
  53. PASCAL NEAR dsplbls();
  54.  
  55. /*    Some needed locals    */
  56.  
  57. union REGS r;        /* register set for bios and dos (AGIOS) calls */
  58. int capslock = 0;    /* caps lock flag */
  59. int break_flag;        /* state of MSDOS control break processing */
  60.  
  61. /*
  62.  * Standard terminal interface dispatch table. Most of the fields point into
  63.  * "termio" code.
  64.  */
  65. TERM    term    = {
  66.     NROW-1,
  67.         NROW-1,
  68.         NCOL,
  69.         NCOL,
  70.     MARGIN,
  71.     SCRSIZ,
  72.     0, 0,
  73.     NPAUSE,
  74.     openhp,
  75.         closehp,
  76.     hp15kopen,
  77.     hp15kclose,
  78.     gethpkey,
  79.         ttputc,
  80.         hpflush,
  81.         hp15move,
  82.         hp15eeol,
  83.         hp15eeop,
  84.         hp15eeop,
  85.         hp15beep,
  86.         hp15rev,
  87.         hp15cres
  88. #if    COLOR
  89.     , hp15fcol,
  90.     hp15bcol
  91. #endif
  92. };
  93.  
  94. PASCAL NEAR hp15move(row, col)
  95. {
  96.         ttputc(ESC);
  97.         ttputc('&');
  98.         ttputc('a');
  99.         hp15parm(col);
  100.         ttputc('c');
  101.         hp15parm(row);
  102.         ttputc('R');
  103. }
  104.  
  105. PASCAL NEAR hpflush()
  106.  
  107. {
  108.  
  109. }
  110.  
  111. PASCAL NEAR hp15eeol()
  112. {
  113.         ttputc(ESC);
  114.         ttputc('K');
  115. }
  116.  
  117. PASCAL NEAR hp15eeop()
  118. {
  119.         ttputc(ESC);
  120.         ttputc('J');
  121. }
  122.  
  123. PASCAL NEAR hp15rev(status)    /* change the reverse video status */
  124.  
  125. int status;    /* TRUE = on, FALSE = off */
  126.  
  127. {
  128.     ttputc(ESC);
  129.     ttputc('&');
  130.     ttputc('d');
  131.     ttputc((status != FALSE) ? 'B': '@');
  132. }
  133.  
  134. PASCAL NEAR hp15cres()    /* change screen resolution */
  135.  
  136. {
  137.     return(TRUE);
  138. }
  139.  
  140. PASCAL NEAR spal()        /* change pallette register */
  141.  
  142. {
  143.     /*   not here */
  144. }
  145.  
  146. PASCAL NEAR hp15beep()
  147. {
  148.         ttputc(BEL);
  149.         ttflush();
  150. }
  151.  
  152. PASCAL NEAR hp15parm(n)
  153.  
  154. register int    n;
  155.  
  156. {
  157.         register int    q;
  158.  
  159.         q = n/10;
  160.         if (q != 0)
  161.                 hp15parm(q);
  162.         ttputc((n%10) + '0');
  163. }
  164.  
  165. #if    COLOR
  166. PASCAL NEAR hp15fcol()    /* we really can't do colors here, so just ignore it */
  167. {
  168. }
  169.  
  170. PASCAL NEAR hp15bcol()    /* we really can't do colors here, so just ignore it */
  171. {
  172. }
  173. #endif
  174.  
  175. PASCAL NEAR gethpkey()    /* get a key from the HP keyboard while in keycode mode */
  176.  
  177. {
  178.     unsigned c;        /* character to translate */
  179.     int devid;        /* device ID */
  180.     int ctype;        /* type of character gotten */
  181.     unsigned shiftb;    /* state of shift keys */
  182.     int i;            /* index in first translation loop */
  183.  
  184.     /* return any keystrokes waiting in the
  185.        type ahead buffer */
  186.     if (in_check())
  187.         return(in_get());
  188.  
  189.     /* grab the next 4 char sequence */
  190. next:    shiftb = ttgetc();
  191.     devid = ttgetc();
  192.     c = ttgetc();
  193.     ttgetc();        /* skip null byte */
  194.  
  195.     /* make sure we are from the keyboard */
  196.     if (devid != 192)
  197.         goto next;
  198.  
  199.     /* if normal ascii, return it */
  200.     if ((shiftb & 0x80) == 0) {
  201.         if (capslock && c >= 'a' && c <= 'z')
  202.             c -= 32;
  203.         return(c);
  204.     }
  205.  
  206.     /* check specifically for the caps lock key */
  207.     if (c == 0x56) {
  208.         capslock = ~capslock;
  209.         goto next;
  210.     }
  211.  
  212.     /* interpet it as an extended HP sequence */
  213.     c = extcode(shiftb, c);
  214.  
  215.     /* if it becomes standard ascii... just return it */
  216.     if ((c >> 8) == 0)
  217.         return(c & 255);
  218.  
  219.     /* or return it as en extended emacs internal sequence */
  220.     in_put(c >> 8);        /* prefix byte */
  221.     in_put(c & 255);    /* event code byte */
  222.     return(0);        /* extended escape sequence */
  223. }
  224.  
  225. /*    extcode:    resolve MSDOS extended character codes
  226.             encoding the proper sequences into emacs
  227.             printable character specifications
  228. */
  229.  
  230. int extcode(shiftb, c)
  231.  
  232. unsigned shiftb;    /* shift flag */
  233. unsigned c;        /* byte following a zero extended char byte */
  234.  
  235. {
  236.     int sstate;    /* state of the various shift keys */
  237.  
  238.     /* remember if we are shifted */
  239.     if ((shiftb & 0x04) != 0)
  240.         sstate = SHFT;
  241.     else
  242.         sstate = 0;
  243.  
  244.     /* remember if we are alted (extended char keys) */
  245.     if ((shiftb & 0x30) != 0)
  246.         sstate |= ALTD;
  247.  
  248.     /* remember if we are controled */
  249.     if ((shiftb & 0x08) != 0)
  250.         sstate |= CTRL;
  251.  
  252.     /* function keys 1 through 9 */
  253.     if (c >= 0 && c < 9)
  254.         return(sstate | SPEC | c + 1 + '0');
  255.  
  256.     /* function key 10 */
  257.     if (c == 9)
  258.         return(sstate | SPEC | '0');
  259.  
  260.     /* function key 11 */
  261.     if (c == 10)
  262.         return(sstate | SPEC | 'E');
  263.  
  264.     /* function key 12 */
  265.     if (c == 11)
  266.         return(sstate | SPEC | 'T');
  267.  
  268.     /* some others as well */
  269.     switch (c) {
  270.  
  271.         case 36:    return(sstate | 9);    /* tab */
  272.         case 37:    return(sstate | 13);    /* ret */
  273.         case 39:    return(sstate | 8);    /* backspace */
  274.         case 48:    return(sstate | 48);    /* zero */
  275.         case 49:    return(sstate | 49);    /* one */
  276.         case 50:    return(sstate | 50);    /* two */
  277.         case 51:    return(sstate | 51);    /* three */
  278.         case 52:    return(sstate | 52);    /* four */
  279.         case 53:    return(sstate | 53);    /* five */
  280.         case 54:    return(sstate | 54);    /* six */
  281.         case 55:    return(sstate | 55);    /* seven */
  282.         case 56:    return(sstate | 56);    /* eight */
  283.         case 57:    return(sstate | 57);    /* nine */
  284.         case 80:    return(sstate | 13);    /* enter */
  285.         case 84:    return(sstate | 27);    /* break -> ESC */
  286.         case 85:    return(sstate | 27);    /* esc */
  287.         case 88:    return(sstate | 24);    /* stop -> ^X */
  288.         case 112:    return(sstate | 45);    /* N-minus */
  289.         case 113:    return(sstate | 42);    /* N-asterisk */
  290.         case 114:    return(sstate | 43);    /* N-plus */
  291.         case 115:    return(sstate | 47);    /* N-slash */
  292.         case 116:    return(sstate | 44);    /* N-comma */
  293.         case 117:    return(sstate | 13);    /* N-enter */
  294.         case 118:    return(sstate | 9);    /* N-tab */
  295.         case 119:    return(sstate | 46);    /* N-period */
  296.  
  297.         case 44:
  298.         case 45:
  299.         case 110:    return(sstate | SPEC | '<');    /* HOME */
  300.  
  301.         case 32:
  302.         case 41:
  303.         case 101:    return(sstate | SPEC | 'P');    /* cursor up */
  304.  
  305.         case 47:    return(sstate | SPEC | 'Z');    /* page up */
  306.  
  307.         case 35:
  308.         case 42:
  309.         case 97:    return(sstate | SPEC | 'B');    /* cursor left */
  310.  
  311.         case 34:
  312.         case 43:
  313.         case 99:    return(sstate | SPEC | 'F');    /* cursor right */
  314.  
  315.         case 82:    return(sstate | SPEC | '>');    /* end */
  316.  
  317.         case 33:
  318.         case 40:
  319.         case 98:    return(sstate | SPEC | 'N');    /* cursor down */
  320.  
  321.         case 46:
  322.         case 108:    return(sstate | SPEC | 'V');    /* page down */
  323.  
  324.         case 64:
  325.         case 70:
  326.         case 107:    return(sstate | SPEC | 'C');    /* insert */
  327.  
  328.         case 65:
  329.         case 71:
  330.         case 109:    return(sstate | SPEC | 'D');    /* delete */
  331.  
  332.         /* the HP has some extra keys we need to map */
  333.  
  334.         case 83:
  335.         case 89:    return(sstate | SPEC | 'Q');    /* reformat paragraph */
  336.         case 81:    return(sstate | CTLX | 'C');    /* shell up to system */
  337.         case 67:    return(sstate | SPEC | CTRL | 'L'); /* center display */
  338.         case 68:    return(sstate | CTRL | 'O');    /* open line */
  339.         case 69:    return(sstate | CTRL | 'K');    /* Kill to end of line */
  340.     }
  341.  
  342.     return(sstate | c);
  343. }
  344.  
  345. PASCAL NEAR openhp()        /* open the HP150 screen for input */
  346.  
  347. {
  348.     strcpy(sres, "NORMAL");
  349.     strcpy(os, "MSDOS");
  350.     revexist = TRUE;
  351. }
  352.  
  353. PASCAL NEAR closehp()        /* close the HP150 screen for input */
  354.  
  355. {
  356. }
  357.  
  358. PASCAL NEAR hp15kopen()        /* open the HP150 keyboard for input */
  359.  
  360. {
  361.     /* define key charectoristics with AGIOS call (0, 40) */
  362.     defkey();
  363.  
  364.     /* Turn on RAW mode with MSDOS call 44h */
  365.     rawon();
  366.  
  367.     /* Turn off Control-C checking  MS-DOS 33h */
  368.     ckeyoff();
  369.  
  370.     /* Turn on keycode mode with AGIOS call (0,43) */
  371.     keycon();
  372.  
  373.     /* display the application softkey labels */
  374.     dsplbls();
  375. }
  376.  
  377. PASCAL NEAR hp15kclose()    /* close the HP150 keyboard for input */
  378.  
  379. {
  380.     /* define key charectoristics with AGIOS call (0, 40) */
  381.     undefkey();
  382.     
  383.     /* Turn off RAW mode with MSDOS call 44h */
  384.     rawoff();
  385.  
  386.     /* Turn on Control-C checking  MS-DOS 33h */
  387.     ckeyon();
  388.  
  389.     /* Turn off keycode mode with AGIOS call (0,43) */
  390.     keycoff();
  391. }
  392.  
  393. PASCAL NEAR rawon()    /* put the HP150 keyboard into RAW mode */
  394.  
  395. {
  396.     /* get the IO control info */
  397.  
  398.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  399.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  400.     intdos(&r, &r);        /* go fer it */
  401.  
  402.     r.h.dh = 0;        /* clear high byte for put */
  403.     r.h.dl |= 0x20;        /* set raw bit */
  404.  
  405.     /* and put it back */
  406.  
  407.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  408.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  409.     intdos(&r, &r);        /* go fer it */
  410. }
  411.  
  412. PASCAL NEAR rawoff()    /* put the HP150 keyboard into COOKED mode */
  413.  
  414. {
  415.     /* get the IO control info */
  416.  
  417.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  418.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  419.     intdos(&r, &r);        /* go fer it */
  420.  
  421.     r.h.dh = 0;        /* clear high byte for put */
  422.     r.h.dl &= 0xdf;        /* set raw bit */
  423.  
  424.     /* and put it back */
  425.  
  426.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  427.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  428.     intdos(&r, &r);        /* go fer it */
  429. }
  430.  
  431. PASCAL NEAR ckeyoff()    /* turn control-C trapping off */
  432.  
  433. {
  434.     /* find the current state of the control break inturrupt */
  435.     r.h.ah = 0x33;    /* ctrl-break check */
  436.     r.h.al = 0;    /* request the state of the ctrl-break check */
  437.     intdos(&r, &r);
  438.     break_flag = r.h.dl;
  439.  
  440.     /* set the break processing off if it is on */
  441.     if (break_flag == 1) {
  442.         r.h.ah = 0x33;    /* ctrl-break check */
  443.         r.h.al = 1;    /* set the state of the ctrl-break check */
  444.         r.h.dl = 0;    /* turn it off */
  445.         intdos(&r, &r);
  446.     }
  447. }
  448.  
  449. PASCAL NEAR ckeyon()    /* turn control-C trapping on */
  450.  
  451. {
  452.     if (break_flag == 1) {
  453.         r.h.ah = 0x33;    /* ctrl-break check */
  454.         r.h.al = 1;    /* set the state of the ctrl-break check */
  455.         r.h.dl = 1;    /* turn it on */
  456.         intdos(&r, &r);
  457.     }
  458. }
  459.  
  460. #ifdef    unsigned
  461. #undef    unsigned
  462. #endif
  463.  
  464. PASCAL NEAR agios(buf, len)    /* perform an AGIOS call */
  465.  
  466. char *buf;    /* sequence of bytes in command */
  467. int len;    /* length of command in bytes */
  468.  
  469. {
  470.     r.x.ax = 0x4403;    /* I/O ctrl write */
  471.     r.x.bx = 1;        /* console handle */
  472.     r.x.cx = len;        /* buffer length */
  473.     r.x.dx = (unsigned)buf;    /* buffer address */
  474.     return(intdos(&r, &r));    /* do it */
  475. }
  476.  
  477. PASCAL NEAR keycon()    /* turn keycode mode on */
  478.  
  479. {
  480.     static char cmd[] = {43, 0, 1};
  481.  
  482.     return(agios(&cmd[0], 3));
  483. }
  484.  
  485. PASCAL NEAR keycoff()    /* turn keycode mode off */
  486.  
  487. {
  488.     static char cmd[] = {43, 0, 0};
  489.  
  490.     return(agios(&cmd[0], 3));
  491. }
  492.  
  493. PASCAL NEAR defkey()    /* change all special keys to intercept mode */
  494.  
  495. {
  496.     static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
  497.  
  498.     return(agios(&cmd[0], 6));
  499. }
  500.  
  501. PASCAL NEAR undefkey()    /* change all special keys to intercept mode */
  502.  
  503. {
  504.     static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
  505.  
  506.     return(agios(&cmd[0], 6));
  507. }
  508.  
  509. PASCAL NEAR dsplbls()    /* display the application softkey labels on the screen */
  510.  
  511. {
  512.     static char cmd[] = {11, 0};
  513.  
  514.     return(agios(&cmd[0], 2));
  515. }
  516.  
  517. #if    FLABEL
  518. PASCAL NEAR fnclabel(f, n)        /* label a function key */
  519.  
  520. int f,n;    /* default flag, numeric argument */
  521.  
  522. {
  523.     register int status;    /* return status */
  524.     register int i;        /* loop index */
  525.     char lbl[17];    /* returned label contents */
  526.     /* AGIOS command buffer */
  527.     static char cmd[] = {8, 0, 1, 0, 7, 7, 7, 7, 10, 0, 10, 0};
  528.     /*                   code  key#  ptr to      top    bottom
  529.                                      label string  attribute */
  530.     union {        /* union to cast ptr into AGIOS arg string */
  531.         char *ptr;    /* pointer to arg string */
  532.         char cstr[4];
  533.     } ptru;
  534.  
  535.     /* must have a numeric argument */
  536.     if (f == FALSE) {
  537.         mlwrite(TEXT159);
  538. /*                      "%Need function key number" */
  539.         return(FALSE);
  540.     }
  541.  
  542.     /* and it must be a legal key number */
  543.     if (n < 1 || n > 8) {
  544.         mlwrite(TEXT160);
  545. /*                      "%Function key number out of range" */
  546.         return(FALSE);
  547.     }
  548.  
  549.     /* get the string to send */
  550.     status = mlreply(TEXT161, &lbl[0], 17);
  551. /*                       "Label contents: " */
  552.     if (status != TRUE)
  553.         return(status);
  554.  
  555.     /* pad the label out */
  556.     for (i=0; i < 17; i++) {
  557.         if (lbl[i] == 0)
  558.             break;
  559.     }
  560.     for (; i < 16; i++)
  561.         lbl[i] = ' ';
  562.     lbl[16] = 0;
  563.  
  564.     /* set up the parameters */
  565.     cmd[2] = n;            /* function key number */
  566.     ptru.ptr = &lbl[0];        /* set up pointer to label string */
  567. force:    cmd[4] = ptru.cstr[0];
  568.     cmd[5] = ptru.cstr[1];
  569.     cmd[6] = ptru.cstr[2];
  570.     cmd[7] = ptru.cstr[3];
  571.  
  572.     /* and send it out */
  573.     agios(&cmd[0], 12);
  574.     return(TRUE);
  575. }
  576. #endif
  577. #else
  578. PASCAL NEAR h15hello()
  579.  
  580. {
  581. }
  582. #endif
  583.