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