home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / memacs / ue311c.arc / NEC.C < prev    next >
C/C++ Source or Header  |  1990-08-16  |  9KB  |  427 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.     MARGIN,
  127.     SCRSIZ,
  128.     NPAUSE,
  129.         necopen,
  130.         necclose,
  131.     neckopen,
  132.     neckclose,
  133.         necgetc,
  134.         ttputc,
  135.         ttflush,
  136.         necmove,
  137.         neceeol,
  138.         neceeop,
  139.         necbeep,
  140.     necrev,
  141.     neccres
  142. #if    COLOR
  143.     , necfcol,
  144.     necbcol
  145. #endif
  146. #if    INSDEL
  147.     , necins,
  148.     necdel
  149. #endif
  150. };
  151.  
  152. #if    COLOR
  153. PASCAL NEAR necfcol(color)        /* set the current output color */
  154.  
  155. int color;    /* color to set */
  156.  
  157. {
  158.     if (color == cfcolor)
  159.         return;
  160.     ttputc(ESC);
  161.     ttputc('[');
  162.     necparm((color)+30);
  163.     ttputc('m');
  164.     cfcolor = color;
  165. }
  166.  
  167. PASCAL NEAR necbcol(color)        /* set the current background color */
  168.  
  169. int color;    /* color to set */
  170.  
  171. {
  172.     if (color == cbcolor)
  173.         return;
  174. #if    0
  175.     ttputc(ESC);
  176.     ttputc('[');
  177.     necparm(color+40);
  178.     ttputc('m');
  179. #endif
  180.         cbcolor = color;
  181. }
  182. #endif
  183.  
  184. #if    INSDEL
  185. PASCAL NEAR necins(lines)        /* insert some screen lines */
  186.  
  187. int lines;    /* number of lines to insert */
  188.  
  189. {
  190.     if (lines < 1)
  191.         return;
  192.     ttputc(ESC);
  193.     ttputc('[');
  194.     necparm(lines);
  195.     ttputc('L');
  196. }
  197.  
  198. PASCAL NEAR necdel(lines)        /* delete some screen lines */
  199.  
  200. int lines;    /* number of lines to delete */
  201.  
  202. {
  203.     if (lines < 1)
  204.         return;
  205.     ttputc(ESC);
  206.     ttputc('[');
  207.     necparm(lines);
  208.     ttputc('M');
  209. }
  210. #endif
  211.  
  212. PASCAL NEAR necmove(row, col)
  213. {
  214.         ttputc(ESC);
  215.         ttputc('[');
  216.         necparm(row+1);
  217.         ttputc(';');
  218.         necparm(col+1);
  219.         ttputc('H');
  220. }
  221.  
  222. PASCAL NEAR neceeol()
  223. {
  224.         ttputc(ESC);
  225.         ttputc('[');
  226.         ttputc('K');
  227. }
  228.  
  229. PASCAL NEAR neceeop()
  230. {
  231. #if    COLOR
  232.     necfcol(gfcolor);
  233.     necbcol(gbcolor);
  234. #endif
  235.         ttputc(ESC);
  236.         ttputc('[');
  237.         ttputc('J');
  238. }
  239.  
  240. PASCAL NEAR necrev(state)        /* change reverse video state */
  241.  
  242. int state;    /* TRUE = reverse, FALSE = normal */
  243.  
  244. {
  245. #if    COLOR
  246.     int ftmp, btmp;        /* temporaries for colors */
  247. #endif
  248.  
  249. #if    1
  250.     if (state) {
  251.         ttputc(ESC);
  252.         ttputc('[');
  253.         ttputc('7');
  254.         ttputc('m');
  255.     } else {
  256.         ttputc(ESC);
  257.         ttputc('[');
  258.         necparm(cfcolor+30);
  259.         ttputc('m');
  260.     }
  261. #endif
  262. #if    COLOR && 0
  263.     if (state == FALSE) {
  264.         ftmp = cfcolor;
  265.         btmp = cbcolor;
  266.         cfcolor = -1;
  267.         cbcolor = -1;
  268.         necfcol(ftmp);
  269.         necbcol(btmp);
  270.     }
  271. #endif
  272. }
  273.  
  274. PASCAL NEAR neccres()    /* change screen resolution */
  275.  
  276. {
  277.     return(TRUE);
  278. }
  279.  
  280. PASCAL NEAR spal(char *dummy)        /* change pallette settings */
  281.  
  282. {
  283.     /* none for now */
  284. }
  285.  
  286. PASCAL NEAR necbeep()
  287. {
  288.         ttputc(BEL);
  289.         ttflush();
  290. }
  291.  
  292. PASCAL NEAR necparm(n)
  293. register int    n;
  294. {
  295.         register int q,r;
  296.  
  297.         q = n/10;
  298.         if (q != 0) {
  299.         r = q/10;
  300.         if (r != 0) {
  301.             ttputc((r%10)+'0');
  302.         }
  303.         ttputc((q%10) + '0');
  304.         }
  305.         ttputc((n%10) + '0');
  306. }
  307.  
  308. PASCAL NEAR necopen()
  309. {
  310.     strcpy(sres, "NORMAL");
  311.     revexist = TRUE;
  312.         ttopen();
  313.     ttputc(ESC);
  314.     ttputc(')');
  315.     ttputc('0');
  316. #if    FLABEL
  317.     getkeys(oldkeys);    /* save original function keys */
  318. #endif
  319. }
  320.  
  321. PASCAL NEAR necclose()
  322.  
  323. {
  324. #if    COLOR
  325.     necfcol(7);
  326.     necbcol(0);
  327. #endif
  328.     ttclose();
  329. }
  330.  
  331. PASCAL NEAR neckopen()    /* open the keyboard (a noop here) */
  332.  
  333. {
  334. #if    FLABEL
  335.     setkeys(curkeys);    /* and reset them to new values */
  336. #endif
  337. }
  338.  
  339. PASCAL NEAR neckclose()    /* close the keyboard (a noop here) */
  340.  
  341. {
  342. #if    FLABEL
  343.     setkeys(oldkeys);    /* restore the original function key block */
  344. #endif
  345. }
  346.  
  347. PASCAL NEAR necgetc()
  348.  
  349. {
  350.     return(ttgetc());
  351. }
  352.  
  353. #if    FLABEL
  354. int PASCAL NEAR fnclabel(f, n)        /* label a function key */
  355.  
  356. int f,n;    /* default flag, numeric argument [unused] */
  357.  
  358. {
  359.     char *ptr;    /* ptr into function key string */
  360.     char lbl[6];    /* returned label contents */
  361.     int status;
  362.     int index;
  363.  
  364.     /* must have a numeric argument */
  365.     if (f == FALSE) {
  366.         mlwrite(TEXT159);
  367. /*                      "%Need function key number" */
  368.         return(FALSE);
  369.     }
  370.  
  371.     /* and it must be a legal key number */
  372.     if (n < 1 || n > 10) {
  373.         mlwrite(TEXT50);
  374. /*                      "%Function key number out of range" */
  375.         return(FALSE);
  376.     }
  377.  
  378.     /* get the string to send */
  379.     status = mlreply(TEXT51, lbl, 6);
  380. /*                       "Label contents: " */
  381.     if (status != TRUE)
  382.         return(status);
  383.  
  384.     /* pad the label out */
  385.     for (index=0; index < 5; index++) {
  386.         if (lbl[index] == 0)
  387.             break;
  388.     }
  389.     for (; index < 5; index++)
  390.         lbl[index] = ' ';
  391.     lbl[5] = 0;
  392.  
  393.     /* label the key! */
  394.     ptr = &curkeys[(n - 1) * 16 + 1];
  395.     movmem(lbl, ptr, 5);
  396.     setkeys(curkeys);
  397.     return(TRUE);
  398. }
  399.  
  400. getkeys(keys)    /* read the function key labels and definitions */
  401.  
  402. unsigned char *keys;    /* function key block */
  403.  
  404. {
  405.     rg.h.cl = 0x0c;
  406.     rg.x.ax = 0;
  407.     rg.x.dx = (int)keys;
  408.     int86(0xdc, &rg, &rg);
  409. }
  410.  
  411. setkeys(keys)    /* reset the function key labels and definitions */
  412.  
  413. unsigned char *keys;    /* function key block */
  414.  
  415. {
  416.     rg.h.cl = 0x0d;
  417.     rg.x.ax = 0;
  418.     rg.x.dx = (int)keys;
  419.     int86(0xdc, &rg, &rg);
  420. }
  421. #endif
  422. #else
  423. nechello()
  424. {
  425. }
  426. #endif
  427.