home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / UE311C.ZIP / NEC.C < prev    next >
C/C++ Source or Header  |  1991-10-11  |  9KB  |  420 lines

  1. /*    NEC:    NEC PC-9801vm driver for
  2.         MicroEMACS 3.10
  3.         (C)Copyright 1990 by Daniel M. Lawrence
  4. */
  5.  
  6. #define    termdef    1            /* don't define term external */
  7.  
  8. #include        <stdio.h>
  9. #include    "estruct.h"
  10. #include    "eproto.h"
  11. #include        "edef.h"
  12. #include    "elang.h"
  13.  
  14. #if     NEC
  15. #include    <dos.h>
  16.  
  17. #if    PROTO
  18. int PASCAL NEAR fnclabel(int f, int n);
  19. int PASCAL NEAR readparam( int *v);
  20. void PASCAL NEAR dobbnmouse(void);
  21. void PASCAL NEAR docsi( int oh);
  22. void PASCAL NEAR ttputs(char *string);
  23. #else
  24. int PASCAL NEAR fnclabel();
  25. int PASCAL NEAR readparam();
  26. void PASCAL NEAR dobbnmouse();
  27. void PASCAL NEAR docsi();
  28. void PASCAL NEAR ttputs();
  29. #endif
  30.  
  31. #define NROW    24                      /* Screen size.                 */
  32. #define NCOL    80                      /* Edit if you want to.         */
  33. #define    NPAUSE    100            /* # times thru update to pause */
  34. #define    MARGIN    8            /* size of minimim margin and    */
  35. #define    SCRSIZ    64            /* scroll size for extended lines */
  36. #define BEL     0x07                    /* BEL character.               */
  37. #define ESC     0x1B                    /* ESC character.               */
  38.  
  39. /* Forward references.          */
  40. extern int PASCAL NEAR necmove();
  41. extern int PASCAL NEAR neceeol();
  42. extern int PASCAL NEAR neceeop();
  43. extern int PASCAL NEAR necbeep();
  44. extern int PASCAL NEAR necopen();
  45. extern int PASCAL NEAR necrev();
  46. extern int PASCAL NEAR necclose();
  47. extern int PASCAL NEAR neckopen();
  48. extern int PASCAL NEAR neckclose();
  49. extern int PASCAL NEAR neccres();
  50. extern int PASCAL NEAR necparm();
  51. extern int PASCAL NEAR necgetc();
  52. #if    INSDEL
  53. extern int PASCAL NEAR necins();
  54. extern int PASCAL NEAR necdel();
  55. #endif
  56.  
  57. #if    COLOR
  58. extern int PASCAL NEAR necfcol();
  59. extern int PASCAL NEAR necbcol();
  60.  
  61. static int cfcolor = -1;    /* current forground color */
  62. static int cbcolor = -1;    /* current background color */
  63. #endif
  64.  
  65. #if    FLABEL
  66.  
  67. #define    FSIZE    392        /* save of function key save buffer */
  68.  
  69. static unsigned char oldkeys[FSIZE];    /* original key save buffer */
  70. static unsigned char curkeys[FSIZE] = {    /* current key save buffer */
  71.  
  72.     /* function keys F1 - F10 */
  73.  
  74.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 59, 0, 0, 0, 0, 0, 0, 0, 0,
  75.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 60, 0, 0, 0, 0, 0, 0, 0, 0,
  76.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 61, 0, 0, 0, 0, 0, 0, 0, 0,
  77.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 62, 0, 0, 0, 0, 0, 0, 0, 0,
  78.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 63, 0, 0, 0, 0, 0, 0, 0, 0,
  79.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 64, 0, 0, 0, 0, 0, 0, 0, 0,
  80.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 65, 0, 0, 0, 0, 0, 0, 0, 0,
  81.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 66, 0, 0, 0, 0, 0, 0, 0, 0,
  82.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 67, 0, 0, 0, 0, 0, 0, 0, 0,
  83.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 68, 0, 0, 0, 0, 0, 0, 0, 0,
  84.  
  85.     /* function keys F11 - F20 */
  86.  
  87.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 84, 0, 0, 0, 0, 0, 0, 0, 0,
  88.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 85, 0, 0, 0, 0, 0, 0, 0, 0,
  89.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 86, 0, 0, 0, 0, 0, 0, 0, 0,
  90.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 87, 0, 0, 0, 0, 0, 0, 0, 0,
  91.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 88, 0, 0, 0, 0, 0, 0, 0, 0,
  92.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 89, 0, 0, 0, 0, 0, 0, 0, 0,
  93.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 90, 0, 0, 0, 0, 0, 0, 0, 0,
  94.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 91, 0, 0, 0, 0, 0, 0, 0, 0,
  95.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 92, 0, 0, 0, 0, 0, 0, 0, 0,
  96.     0xfe, ' ', ' ', ' ', ' ', ' ', 0x1d, 93, 0, 0, 0, 0, 0, 0, 0, 0,
  97.  
  98.     /* other unlabeled keys */
  99.  
  100.     0x1d, 73, 0, 0, 0, 0,    /* roll up */
  101.     0x1d, 81, 0, 0, 0, 0,    /* roll down */
  102.     0x1d, 82, 0, 0, 0, 0,    /* insert */
  103.     0x1d, 83, 0, 0, 0, 0,    /* delete */
  104.     0x1d, 72, 0, 0, 0, 0,    /* up */
  105.     0x1d, 75, 0, 0, 0, 0,    /* left */
  106.     0x1d, 77, 0, 0, 0, 0,    /* right */
  107.     0x1d, 80, 0, 0, 0, 0,    /* down */
  108.     0x1d, 78, 0, 0, 0, 0,    /* clear */
  109.     12, 0, 0, 0, 0, 0,    /* help */
  110.     0x1d, 71, 0, 0, 0, 0,    /* home */
  111.     0x1d, 0, 0, 0, 0, 0,    /* end */
  112. };
  113.  
  114. extern union REGS rg;        /* cpu register for use of DOS calls */
  115. #endif
  116.  
  117. /*
  118.  * Standard terminal interface dispatch table. Most of the fields point into
  119.  * "termio" code.
  120.  */
  121. NOSHARE TERM term    = {
  122.     NROW-1,
  123.         NROW-1,
  124.         NCOL,
  125.         NCOL,
  126.     0, 0,
  127.     MARGIN,
  128.     SCRSIZ,
  129.     NPAUSE,
  130.         necopen,
  131.         necclose,
  132.     neckopen,
  133.     neckclose,
  134.         necgetc,
  135.         ttputc,
  136.         ttflush,
  137.         necmove,
  138.         neceeol,
  139.         neceeop,
  140.         neceeop,
  141.         necbeep,
  142.     necrev,
  143.     neccres
  144. #if    COLOR
  145.     , necfcol,
  146.     necbcol
  147. #endif
  148. #if    INSDEL
  149.     , necins,
  150.     necdel
  151. #endif
  152. };
  153.  
  154. #if    COLOR
  155. PASCAL NEAR necfcol(color)        /* set the current output color */
  156.  
  157. int color;    /* color to set */
  158.  
  159. {
  160.     if (color == cfcolor)
  161.         return;
  162.     ttputc(ESC);
  163.     ttputc('[');
  164.     necparm((7 & color)+30);
  165.     ttputc('m');
  166.     cfcolor = color;
  167. }
  168.  
  169. PASCAL NEAR necbcol(color)        /* set the current background color */
  170.  
  171. int color;    /* color to set */
  172.  
  173. {
  174.     if (color == cbcolor)
  175.         return;
  176. #if    0
  177.     ttputc(ESC);
  178.     ttputc('[');
  179.     necparm((7 & color)+40);
  180.     ttputc('m');
  181. #endif
  182.         cbcolor = color;
  183. }
  184. #endif
  185.  
  186. #if    INSDEL
  187. PASCAL NEAR necins(lines)        /* insert some screen lines */
  188.  
  189. int lines;    /* number of lines to insert */
  190.  
  191. {
  192.     if (lines < 1)
  193.         return;
  194.     ttputc(ESC);
  195.     ttputc('[');
  196.     necparm(lines);
  197.     ttputc('L');
  198. }
  199.  
  200. PASCAL NEAR necdel(lines)        /* delete some screen lines */
  201.  
  202. int lines;    /* number of lines to delete */
  203.  
  204. {
  205.     if (lines < 1)
  206.         return;
  207.     ttputc(ESC);
  208.     ttputc('[');
  209.     necparm(lines);
  210.     ttputc('M');
  211. }
  212. #endif
  213.  
  214. PASCAL NEAR necmove(row, col)
  215. {
  216.         ttputc(ESC);
  217.         ttputc('[');
  218.         necparm(row+1);
  219.         ttputc(';');
  220.         necparm(col+1);
  221.         ttputc('H');
  222. }
  223.  
  224. PASCAL NEAR neceeol()
  225. {
  226.         ttputc(ESC);
  227.         ttputc('[');
  228.         ttputc('K');
  229. }
  230.  
  231. PASCAL NEAR neceeop()
  232. {
  233. #if    COLOR
  234.     necfcol(gfcolor);
  235.     necbcol(gbcolor);
  236. #endif
  237.         ttputc(ESC);
  238.         ttputc('[');
  239.         ttputc('J');
  240. }
  241.  
  242. PASCAL NEAR necrev(state)        /* change reverse video state */
  243.  
  244. int state;    /* TRUE = reverse, FALSE = normal */
  245.  
  246. {
  247. #if    COLOR
  248.     int ftmp, btmp;        /* temporaries for colors */
  249. #endif
  250.  
  251.     ttputc(ESC);
  252.     ttputc('[');
  253.     ttputc(state ? '7': '0');
  254.     ttputc('m');
  255. #if    COLOR & 0
  256.     if (state == FALSE) {
  257.         ftmp = cfcolor;
  258.         btmp = cbcolor;
  259.         cfcolor = -1;
  260.         cbcolor = -1;
  261.         necfcol(ftmp);
  262.         necbcol(btmp);
  263.     }
  264. #endif
  265. }
  266.  
  267. PASCAL NEAR neccres()    /* change screen resolution */
  268.  
  269. {
  270.     return(TRUE);
  271. }
  272.  
  273. PASCAL NEAR spal(char *dummy)        /* change pallette settings */
  274.  
  275. {
  276.     /* none for now */
  277. }
  278.  
  279. PASCAL NEAR necbeep()
  280. {
  281.         ttputc(BEL);
  282.         ttflush();
  283. }
  284.  
  285. PASCAL NEAR necparm(n)
  286. register int    n;
  287. {
  288.         register int q,r;
  289.  
  290.         q = n/10;
  291.         if (q != 0) {
  292.         r = q/10;
  293.         if (r != 0) {
  294.             ttputc((r%10)+'0');
  295.         }
  296.         ttputc((q%10) + '0');
  297.         }
  298.         ttputc((n%10) + '0');
  299. }
  300.  
  301. PASCAL NEAR necopen()
  302. {
  303.     strcpy(sres, "NORMAL");
  304.     revexist = TRUE;
  305.         ttopen();
  306.     ttputc(ESC);
  307.     ttputc(')');
  308.     ttputc('0');
  309. #if    FLABEL
  310.     getkeys(oldkeys);    /* save original function keys */
  311. #endif
  312. }
  313.  
  314. PASCAL NEAR necclose()
  315.  
  316. {
  317. #if    COLOR
  318.     necfcol(7);
  319.     necbcol(0);
  320. #endif
  321.     ttclose();
  322. }
  323.  
  324. PASCAL NEAR neckopen()    /* open the keyboard (a noop here) */
  325.  
  326. {
  327. #if    FLABEL
  328.     setkeys(curkeys);    /* and reset them to new values */
  329. #endif
  330. }
  331.  
  332. PASCAL NEAR neckclose()    /* close the keyboard (a noop here) */
  333.  
  334. {
  335. #if    FLABEL
  336.     setkeys(oldkeys);    /* restore the original function key block */
  337. #endif
  338. }
  339.  
  340. PASCAL NEAR necgetc()
  341.  
  342. {
  343.     return(ttgetc());
  344. }
  345.  
  346. #if    FLABEL
  347. int PASCAL NEAR fnclabel(f, n)        /* label a function key */
  348.  
  349. int f,n;    /* default flag, numeric argument [unused] */
  350.  
  351. {
  352.     char *ptr;    /* ptr into function key string */
  353.     char lbl[6];    /* returned label contents */
  354.     int status;
  355.     int index;
  356.  
  357.     /* must have a numeric argument */
  358.     if (f == FALSE) {
  359.         mlwrite(TEXT159);
  360. /*                      "%Need function key number" */
  361.         return(FALSE);
  362.     }
  363.  
  364.     /* and it must be a legal key number */
  365.     if (n < 1 || n > 10) {
  366.         mlwrite(TEXT50);
  367. /*                      "%Function key number out of range" */
  368.         return(FALSE);
  369.     }
  370.  
  371.     /* get the string to send */
  372.     status = mlreply(TEXT51, lbl, 6);
  373. /*                       "Label contents: " */
  374.     if (status != TRUE)
  375.         return(status);
  376.  
  377.     /* pad the label out */
  378.     for (index=0; index < 5; index++) {
  379.         if (lbl[index] == 0)
  380.             break;
  381.     }
  382.     for (; index < 5; index++)
  383.         lbl[index] = ' ';
  384.     lbl[5] = 0;
  385.  
  386.     /* label the key! */
  387.     ptr = &curkeys[(n - 1) * 16 + 1];
  388.     movmem(lbl, ptr, 5);
  389.     setkeys(curkeys);
  390.     return(TRUE);
  391. }
  392.  
  393. getkeys(keys)    /* read the function key labels and definitions */
  394.  
  395. unsigned char *keys;    /* function key block */
  396.  
  397. {
  398.     rg.h.cl = 0x0c;
  399.     rg.x.ax = 0;
  400.     rg.x.dx = (int)keys;
  401.     int86(0xdc, &rg, &rg);
  402. }
  403.  
  404. setkeys(keys)    /* reset the function key labels and definitions */
  405.  
  406. unsigned char *keys;    /* function key block */
  407.  
  408. {
  409.     rg.h.cl = 0x0d;
  410.     rg.x.ax = 0;
  411.     rg.x.dx = (int)keys;
  412.     int86(0xdc, &rg, &rg);
  413. }
  414. #endif
  415. #else
  416. nechello()
  417. {
  418. }
  419. #endif
  420.