home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 198_01 / hp150.c < prev    next >
C/C++ Source or Header  |  1990-01-23  |  10KB  |  465 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    "edef.h"
  13.  
  14. #if     HP150
  15.  
  16. #define NROW    24                      /* Screen size.                 */
  17. #define NCOL    80                      /* Edit if you want to.         */
  18. #define    MARGIN    8            /* size of minimim margin and    */
  19. #define    SCRSIZ    64            /* scroll size for extended lines */
  20. #define    NPAUSE    15            /* # times thru update to pause */
  21. #define BEL     0x07                    /* BEL character.               */
  22. #define ESC     0x1B                    /* ESC character.               */
  23.  
  24. extern  int     openhp();               /* Forward references.          */
  25. extern  int     ttgetc();
  26. extern  int     ttputc();
  27. extern  int     ttflush();
  28. extern    int    hpflush();
  29. extern  int     closehp();
  30. extern    int    hp15kopen();
  31. extern    int    hp15kclose();
  32. extern  int     hp15move();
  33. extern  int     hp15eeol();
  34. extern  int     hp15eeop();
  35. extern  int     hp15beep();
  36. extern    int    gethpkey();
  37. extern    int    hp15rev();
  38. extern    int    hp15cres();
  39. #if    COLOR
  40. extern    int    hp15fcol();
  41. extern    int    hp15bcol();
  42. #endif
  43.  
  44. /* weird to ascii translation table */
  45.  
  46. char trans[][2] = {
  47.     0x24,    9,    /* tab */
  48.     0x25,    13,    /* ret */
  49.     0x27,    8,    /* backspace */
  50.     0x30,    48,    /* zero */
  51.     0x31,    49,    /* one */
  52.     0x32,    50,    /* two */
  53.     0x33,    51,    /* three */
  54.     0x34,    52,    /* four */
  55.     0x35,    53,    /* five */
  56.     0x36,    54,    /* six */
  57.     0x37,    55,    /* seven */
  58.     0x38,    56,    /* eight */
  59.     0x39,    57,    /* nine */
  60.     0x50,    13,    /* enter */
  61.     0x54,    27,    /* break -> ESC */
  62.     0x55,    27,    /* esc */
  63.     0x58,    24,    /* stop -> ^X */
  64.     0x70,    45,    /* N-minus */
  65.     0x71,    42,    /* N-asterisk */
  66.     0x72,    43,    /* N-plus */
  67.     0x73,    47,    /* N-slash */
  68.     0x74,    44,    /* N-comma */
  69.     0x75,    13,    /* N-enter */
  70.     0x76,    9,    /* N-tab */
  71.     0x77,    46    /* N-period */
  72. };
  73.  
  74. #define NTRANS    sizeof(trans) / 2
  75.  
  76. union REGS r;        /* register set for bios and dos (AGIOS) calls */
  77. int capslock = 0;    /* caps lock flag */
  78.  
  79. /*
  80.  * Standard terminal interface dispatch table. Most of the fields point into
  81.  * "termio" code.
  82.  */
  83. TERM    term    = {
  84.     NROW-1,
  85.         NROW-1,
  86.         NCOL,
  87.         NCOL,
  88.     MARGIN,
  89.     SCRSIZ,
  90.     NPAUSE,
  91.     openhp,
  92.         closehp,
  93.     hp15kopen,
  94.     hp15kclose,
  95.     gethpkey,
  96.         ttputc,
  97.         hpflush,
  98.         hp15move,
  99.         hp15eeol,
  100.         hp15eeop,
  101.         hp15beep,
  102.         hp15rev,
  103.         hp15cres
  104. #if    COLOR
  105.     , hp15fcol,
  106.     hp15bcol
  107. #endif
  108. };
  109.  
  110. hp15move(row, col)
  111. {
  112.         ttputc(ESC);
  113.         ttputc('&');
  114.         ttputc('a');
  115.         hp15parm(col);
  116.         ttputc('c');
  117.         hp15parm(row);
  118.         ttputc('R');
  119. }
  120.  
  121. hpflush()
  122.  
  123. {
  124.  
  125. }
  126.  
  127. hp15eeol()
  128. {
  129.         ttputc(ESC);
  130.         ttputc('K');
  131. }
  132.  
  133. hp15eeop()
  134. {
  135.         ttputc(ESC);
  136.         ttputc('J');
  137. }
  138.  
  139. hp15rev(status)        /* change the reverse video status */
  140.  
  141. int status;    /* TRUE = on, FALSE = off */
  142.  
  143. {
  144.     ttputc(ESC);
  145.     ttputc('&');
  146.     ttputc('d');
  147.     ttputc((status != FALSE) ? 'B': '@');
  148. }
  149.  
  150. hp15cres()    /* change screen resolution */
  151.  
  152. {
  153.     return(TRUE);
  154. }
  155.  
  156. spal()        /* change pallette register */
  157.  
  158. {
  159.     /*   not here */
  160. }
  161.  
  162. hp15beep()
  163. {
  164.         ttputc(BEL);
  165.         ttflush();
  166. }
  167.  
  168. hp15parm(n)
  169. register int    n;
  170. {
  171.         register int    q;
  172.  
  173.         q = n/10;
  174.         if (q != 0)
  175.                 hp15parm(q);
  176.         ttputc((n%10) + '0');
  177. }
  178.  
  179. #if    COLOR
  180. hp15fcol()    /* we really can't do colors here, so just ignore it */
  181. {
  182. }
  183.  
  184. hp15bcol()    /* we really can't do colors here, so just ignore it */
  185. {
  186. }
  187. #endif
  188.  
  189. gethpkey()    /* get a key from the HP keyboard while in keycode mode */
  190.  
  191. {
  192.     static int keepflag = 0;    /* kept ahead char flag */
  193.     static int keepchar = 0;    /* kept ehead flag */
  194.     int c;
  195.     int devid;            /* device ID */
  196.     int ctype;            /* type of character gotten */
  197.     int shiftb;            /* state of shift keys */
  198.     int i;
  199.     
  200.     /* if we are in an extended char sequence, finish it */
  201.     if (keepflag != 0) {
  202.         keepflag = 0;
  203.         return(keepchar);
  204.     }
  205.  
  206.     /* grab the next 4 char sequence */
  207. next:    shiftb = ttgetc();
  208.     devid = ttgetc();
  209.     c = ttgetc();
  210.     ttgetc();        /* skip null byte */
  211.     
  212.     /* make sure we are from the keyboard */
  213.     if (devid != 192)
  214.         goto next;
  215.  
  216.     /* if normal ascii, return it */
  217.     if ((shiftb & 0x80) == 0) {
  218.         if (capslock && c >= 'a' && c <= 'z')
  219.             c -= 32;
  220.         return(c);
  221.     }
  222.  
  223.     /* check specifically for the caps lock key */
  224.     if (c == 0x56) {
  225.         capslock = ~capslock;
  226.         goto next;
  227.     }
  228.  
  229.     /* check to see if it needs translation */
  230.     for (i=0; i < NTRANS; i++)
  231.         if (trans[i][0] == c)
  232.             return((int)trans[i][1]);
  233.  
  234.     /* other wise, shove it in the keep char and return the leadin code */
  235.     keepchar = c;
  236.     keepflag = 1;
  237.     return(0);
  238. }
  239.  
  240. openhp()        /* open the HP150 screen for input */
  241.  
  242. {
  243.     strcpy(sres, "NORMAL");
  244.     revexist = TRUE;
  245. }
  246.  
  247. closehp()        /* close the HP150 screen for input */
  248.  
  249. {
  250. }
  251.  
  252. hp15kopen()        /* open the HP150 keyboard for input */
  253.  
  254. {
  255.     /* define key charectoristics with AGIOS call (0, 40) */
  256.     defkey();
  257.  
  258.     /* Turn on RAW mode with MSDOS call 44h */
  259.     rawon();
  260.  
  261.     /* Turn off Control-C checking  MS-DOS 33h */
  262.     ckeyoff();
  263.  
  264.     /* Turn on keycode mode with AGIOS call (0,43) */
  265.     keycon();
  266.  
  267.     /* display the application softkey labels */
  268.     dsplbls();
  269. }
  270.  
  271. hp15kclose()        /* close the HP150 keyboard for input */
  272.  
  273. {
  274.     /* define key charectoristics with AGIOS call (0, 40) */
  275.     undefkey();
  276.     
  277.     /* Turn off RAW mode with MSDOS call 44h */
  278.     rawoff();
  279.  
  280.     /* Turn on Control-C checking  MS-DOS 33h */
  281.     ckeyon();
  282.  
  283.     /* Turn off keycode mode with AGIOS call (0,43) */
  284.     keycoff();
  285. }
  286.  
  287. rawon()        /* put the HP150 keyboard into RAW mode */
  288.  
  289. {
  290.     /* get the IO control info */
  291.  
  292.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  293.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  294.     intdos(&r, &r);        /* go fer it */
  295.  
  296.     r.h.dh = 0;        /* clear high byte for put */
  297.     r.h.dl |= 0x20;        /* set raw bit */
  298.  
  299.     /* and put it back */
  300.  
  301.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  302.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  303.     intdos(&r, &r);        /* go fer it */
  304. }
  305.  
  306. rawoff()    /* put the HP150 keyboard into COOKED mode */
  307.  
  308. {
  309.     /* get the IO control info */
  310.  
  311.     r.x.ax = 0x4400;    /* IO ctrl get device information */
  312.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  313.     intdos(&r, &r);        /* go fer it */
  314.  
  315.     r.h.dh = 0;        /* clear high byte for put */
  316.     r.h.dl &= 0xdf;        /* set raw bit */
  317.  
  318.     /* and put it back */
  319.  
  320.     r.x.ax = 0x4401;    /* IO ctrl put device information */
  321.     r.x.bx = 0x0001;    /* File handle; 1 for console */
  322.     intdos(&r, &r);        /* go fer it */
  323. }
  324.  
  325.  
  326. ckeyoff()    /* turn control-C trapping off */
  327.  
  328. {
  329.     r.h.ah = 0x33;    /* ctrl-break check */
  330.     r.h.al = 1;    /* set the state of the ctrl-break check */
  331.     r.h.dl = 0;    /* turn it off */
  332.     intdos(&r, &r);
  333. }
  334.  
  335. ckeyon()    /* turn control-C trapping on */
  336.  
  337. {
  338.     r.h.ah = 0x33;    /* ctrl-break check */
  339.     r.h.al = 1;    /* set the state of the ctrl-break check */
  340.     r.h.dl = 1;    /* turn it on */
  341.     intdos(&r, &r);
  342. }
  343.  
  344. #ifdef    unsigned
  345. #undef    unsigned
  346. #endif
  347.  
  348. agios(buf, len)    /* perform an AGIOS call */
  349.  
  350. char *buf;    /* sequence of bytes in command */
  351. int len;    /* length of command in bytes */
  352.  
  353. {
  354.     r.x.ax = 0x4403;    /* I/O ctrl write */
  355.     r.x.bx = 1;        /* console handle */
  356.     r.x.cx = len;        /* buffer length */
  357.     r.x.dx = (unsigned)buf;    /* buffer address */
  358.     return(intdos(&r, &r));    /* do it */
  359. }
  360.  
  361. keycon()    /* turn keycode mode on */
  362.  
  363. {
  364.     static char cmd[] = {43, 0, 1};
  365.  
  366.     return(agios(&cmd[0], 3));
  367. }
  368.  
  369. keycoff()    /* turn keycode mode off */
  370.  
  371. {
  372.     static char cmd[] = {43, 0, 0};
  373.  
  374.     return(agios(&cmd[0], 3));
  375. }
  376.  
  377. defkey()    /* change all special keys to intercept mode */
  378.  
  379. {
  380.     static char cmd[] = {40, 0, 2, 0, 0xfe, 0};
  381.  
  382.     return(agios(&cmd[0], 6));
  383. }
  384.  
  385. undefkey()    /* change all special keys to intercept mode */
  386.  
  387. {
  388.     static char cmd[] = {40, 0, 0, 0, 0xfe, 0};
  389.  
  390.     return(agios(&cmd[0], 6));
  391. }
  392.  
  393. dsplbls()    /* display the application softkey labels on the screen */
  394.  
  395. {
  396.     static char cmd[] = {11, 0};
  397.  
  398.     return(agios(&cmd[0], 2));
  399. }
  400.  
  401. #if    FLABEL
  402. fnclabel(f, n)        /* label a function key */
  403.  
  404. int f,n;    /* default flag, numeric argument */
  405.  
  406. {
  407.     register int status;    /* return status */
  408.     register int i;        /* loop index */
  409.     char lbl[17];    /* returned label contents */
  410.     /* AGIOS command buffer */
  411.     static char cmd[] = {8, 0, 1, 0, 7, 7, 7, 7, 10, 0, 10, 0};
  412.     /*                   code  key#  ptr to      top    bottom
  413.                                      label string  attribute */
  414.     union {        /* union to cast ptr into AGIOS arg string */
  415.         char *ptr;    /* pointer to arg string */
  416.         char cstr[4];
  417.     } ptru;
  418.  
  419.     /* must have a numeric argument */
  420.     if (f == FALSE) {
  421.         mlwrite("%Need function key number");
  422.         return(FALSE);
  423.     }
  424.  
  425.     /* and it must be a legal key number */
  426.     if (n < 1 || n > 8) {
  427.         mlwrite("%Function key number out of range");
  428.         return(FALSE);
  429.     }
  430.  
  431.     /* get the string to send */
  432.     status = mlreply("Label contents: ", &lbl[0], 17);
  433.     if (status != TRUE)
  434.         return(status);
  435.  
  436.     /* pad the label out */
  437.     for (i=0; i < 17; i++) {
  438.         if (lbl[i] == 0)
  439.             break;
  440.     }
  441.     for (; i < 16; i++)
  442.         lbl[i] = ' ';
  443.     lbl[16] = 0;
  444.  
  445.     /* set up the parameters */
  446.     cmd[2] = n;            /* function key number */
  447.     ptru.ptr = &lbl[0];        /* set up pointer to label string */
  448. force:    cmd[4] = ptru.cstr[0];
  449.     cmd[5] = ptru.cstr[1];
  450.     cmd[6] = ptru.cstr[2];
  451.     cmd[7] = ptru.cstr[3];
  452.  
  453.     /* and send it out */
  454.     agios(&cmd[0], 12);
  455.     return(TRUE);
  456. }
  457. #endif
  458. #else
  459.  
  460. h15hello()
  461.  
  462. {
  463. }
  464. #endif
  465.