home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / memacs / ue311c.arc / FMR.C < prev    next >
C/C++ Source or Header  |  1990-08-16  |  13KB  |  621 lines

  1. /*    FMR.C:    Fujitsu FMR series Driver
  2.  *        for MicroEMACS 3.10
  3.  *        (C)Copyright 1990 by Daniel M. Lawrence
  4.  *
  5.  *    Note that this driver relies on GDS.SYS being loaded!
  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     FMR
  17.  
  18. /*    FMR special key definitions    */
  19.  
  20. typedef struct KEYDEF {
  21.     unsigned int kf_JIScode;    /* JIS code of key */
  22.     int kf_len;            /* length of key sequence */
  23.     char *kf_def;            /* keystroke sequence */
  24. } KEYDEF;
  25.  
  26. KEYDEF functab[] = {
  27.  
  28.     /* F1 - F10 */
  29.     0x8001, 0, NULL,
  30.     0x8002, 0, NULL,
  31.     0x8003, 0, NULL,
  32.     0x8004, 0, NULL,
  33.     0x8005, 0, NULL,
  34.     0x8006, 0, NULL,
  35.     0x8007, 0, NULL,
  36.     0x8008, 0, NULL,
  37.     0x8009, 0, NULL,
  38.     0x800a, 0, NULL,
  39.  
  40.     /* S-F1 - S-F10 */
  41.     0x800b, 0, NULL,
  42.     0x801d, 0, NULL,
  43.     0x8021, 0, NULL,
  44.     0x8022, 0, NULL,
  45.     0x8023, 0, NULL,
  46.     0x8024, 0, NULL,
  47.     0x8025, 0, NULL,
  48.     0x8026, 0, NULL,
  49.     0x8027, 0, NULL,
  50.     0x8028, 0, NULL,
  51.  
  52.     /* other special keys */
  53.  
  54.     /* cursor arrows */
  55.     0x1e, 0, NULL,
  56.     0x1f, 0, NULL,
  57.     0x1d, 0, NULL,
  58.     0x1c, 0, NULL
  59.  
  60. };
  61.  
  62. #define    NUMFKEYS    sizeof(functab)/sizeof(KEYDEF)
  63.  
  64. /*    EMACS internal key sequences mapped from FMR keys    */
  65.  
  66. KEYDEF newtab[NUMFKEYS] = {
  67.  
  68.     /* F1 - F10 */
  69.     0x8001, 3, "\000\0101",
  70.     0x8002, 3, "\000\0102",
  71.     0x8003, 3, "\000\0103",
  72.     0x8004, 3, "\000\0104",
  73.     0x8005, 3, "\000\0105",
  74.     0x8006, 3, "\000\0106",
  75.     0x8007, 3, "\000\0107",
  76.     0x8008, 3, "\000\0108",
  77.     0x8009, 3, "\000\0109",
  78.     0x800a, 3, "\000\0100",
  79.  
  80.     /* S-F1 - S-F10 */
  81.     0x800b, 3, "\000\0501",
  82.     0x801d, 3, "\000\0502",
  83.     0x8021, 3, "\000\0503",
  84.     0x8022, 3, "\000\0504",
  85.     0x8023, 3, "\000\0505",
  86.     0x8024, 3, "\000\0506",
  87.     0x8025, 3, "\000\0507",
  88.     0x8026, 3, "\000\0508",
  89.     0x8027, 3, "\000\0509",
  90.     0x8028, 3, "\000\0500",
  91.  
  92.     /* other special keys */
  93.  
  94.     /* cursor arrows */
  95.     0x1e, 3, "\000\010P",
  96.     0x1f, 3, "\000\010N",
  97.     0x1d, 3, "\000\010B",
  98.     0x1c, 3, "\000\010F"
  99. };
  100.  
  101. union REGS rg;        /* cpu register for use of DOS calls */
  102. struct SREGS sg;    /* cpu segment registers         */
  103.  
  104. #if    PROTO
  105. int PASCAL NEAR fnclabel(int f, int n);
  106. int PASCAL NEAR readparam( int *v);
  107. void PASCAL NEAR dobbnmouse(void);
  108. void PASCAL NEAR docsi( int oh);
  109. void PASCAL NEAR ttputs(char *string);
  110. #else
  111. int PASCAL NEAR fnclabel();
  112. int PASCAL NEAR readparam();
  113. void PASCAL NEAR dobbnmouse();
  114. void PASCAL NEAR docsi();
  115. void PASCAL NEAR ttputs();
  116. #endif
  117.  
  118. #define NROW    24                      /* Screen size.                 */
  119. #define NCOL    80                      /* Edit if you want to.         */
  120. #define    NPAUSE    100            /* # times thru update to pause */
  121. #define    MARGIN    8            /* size of minimim margin and    */
  122. #define    SCRSIZ    64            /* scroll size for extended lines */
  123. #define BEL     0x07                    /* BEL character.               */
  124. #define ESC     0x1B                    /* ESC character.               */
  125.  
  126. /* Forward references.          */
  127. extern int PASCAL NEAR fmrmove();
  128. extern int PASCAL NEAR fmreeol();
  129. extern int PASCAL NEAR fmreeop();
  130. extern int PASCAL NEAR fmrbeep();
  131. extern int PASCAL NEAR fmropen();
  132. extern int PASCAL NEAR fmrrev();
  133. extern int PASCAL NEAR fmrclose();
  134. extern int PASCAL NEAR fmrkopen();
  135. extern int PASCAL NEAR fmrkclose();
  136. extern int PASCAL NEAR fmrcres();
  137. extern int PASCAL NEAR fmrparm();
  138.  
  139. unsigned int octype;        /* original cursor type */
  140. unsigned int ocraster;        /* original cursor raster line limits */
  141.  
  142. #if    COLOR
  143. extern int PASCAL NEAR fmrfcol();
  144. extern int PASCAL NEAR fmrbcol();
  145.  
  146. static int cfcolor = -1;    /* current forground color */
  147. static int cbcolor = -1;    /* current background color */
  148.  
  149. int bcmap[16] =            /* background color map */
  150.     {0, 4, 8, 12, 2, 6, 10, 14,
  151.      1, 5, 9, 13, 3, 7, 11, 15};
  152. #endif
  153.  
  154. /*
  155.  * Standard terminal interface dispatch table. Most of the fields point into
  156.  * "termio" code.
  157.  */
  158. NOSHARE TERM term    = {
  159.     NROW-1,
  160.         NROW-1,
  161.         NCOL,
  162.         NCOL,
  163.     MARGIN,
  164.     SCRSIZ,
  165.     NPAUSE,
  166.         fmropen,
  167.         fmrclose,
  168.     fmrkopen,
  169.     fmrkclose,
  170.         ttgetc,
  171.         ttputc,
  172.         ttflush,
  173.         fmrmove,
  174.         fmreeol,
  175.         fmreeop,
  176.         fmrbeep,
  177.     fmrrev,
  178.     fmrcres
  179. #if    COLOR
  180.     , fmrfcol,
  181.     fmrbcol
  182. #endif
  183. };
  184.  
  185. #if    COLOR
  186. PASCAL NEAR fmrfcol(color)        /* set the current output color */
  187.  
  188. int color;    /* color to set */
  189.  
  190. {
  191.     if (color == cfcolor)
  192.         return;
  193.     ttputc(ESC);
  194.     ttputc('[');
  195.     fmrparm((color & 7)+30);
  196.     ttputc('m');
  197.     cfcolor = color;
  198. }
  199.  
  200. PASCAL NEAR fmrbcol(color)        /* set the current background color */
  201.  
  202. int color;    /* color to set */
  203.  
  204. {
  205.     if (color == cbcolor)
  206.         return;
  207. #if    0
  208.     ttputc(ESC);
  209.     ttputc('[');
  210.     fmrparm(color+40);
  211.     ttputc('m');
  212. #endif
  213.         cbcolor = color;
  214. }
  215. #endif
  216.  
  217. PASCAL NEAR fmrmove(row, col)
  218. {
  219.         ttputc(ESC);
  220.         ttputc('[');
  221.         fmrparm(row+1);
  222.         ttputc(';');
  223.         fmrparm(col+1);
  224.         ttputc('H');
  225. }
  226.  
  227. PASCAL NEAR fmreeol()
  228. {
  229.         ttputc(ESC);
  230.         ttputc('[');
  231.         ttputc('K');
  232. }
  233.  
  234. PASCAL NEAR fmreeop()
  235. {
  236. #if    COLOR
  237.     fmrfcol(gfcolor);
  238.     fmrbcol(gbcolor);
  239. #endif
  240.         ttputc(ESC);
  241.         ttputc('[');
  242.     ttputc('2');
  243.         ttputc('J');
  244.  
  245.     gds_erase();    /* dump the background colors */
  246. }
  247.  
  248. PASCAL NEAR fmrrev(state)        /* change reverse video state */
  249.  
  250. int state;    /* TRUE = reverse, FALSE = normal */
  251.  
  252. {
  253.     ttputc(ESC);
  254.     ttputc('[');
  255.     ttputc(state ? '7': '0');
  256.     ttputc('m');
  257.     if (state)
  258.         fmrfcol(7);
  259. }
  260.  
  261. PASCAL NEAR fmrcres()    /* change screen resolution */
  262.  
  263. {
  264.     return(TRUE);
  265. }
  266.  
  267. PASCAL NEAR spal(char *dummy)        /* change pallette settings */
  268.  
  269. {
  270.     /* none for now */
  271. }
  272.  
  273. PASCAL NEAR fmrbeep()
  274. {
  275.         ttputc(BEL);
  276.         ttflush();
  277. }
  278.  
  279. PASCAL NEAR fmrparm(n)
  280. register int    n;
  281. {
  282.         register int q,r;
  283.  
  284.         q = n/10;
  285.         if (q != 0) {
  286.         r = q/10;
  287.         if (r != 0) {
  288.             ttputc((r%10)+'0');
  289.         }
  290.         ttputc((q%10) + '0');
  291.         }
  292.         ttputc((n%10) + '0');
  293. }
  294.  
  295. PASCAL NEAR fmropen()
  296.  
  297. {
  298.     strcpy(sres, "NORMAL");
  299.     revexist = TRUE;
  300.         ttopen();
  301.  
  302.     ttputc(ESC);        /* no attributes set */
  303.     ttputc('[');
  304.     fmrparm(40);
  305.     ttputc('m');
  306.  
  307.     gds_init();        /* initialize the GDS driver */
  308. }
  309.  
  310. PASCAL NEAR fmrclose()
  311.  
  312. {
  313. #if    COLOR
  314.     fmrfcol(7);
  315.     fmrbcol(0);
  316. #endif
  317.     gds_erase();        /* close the GDS driver, clear bhackground */
  318.     ttclose();
  319. }
  320.  
  321. PASCAL NEAR fmrkopen()    /* open the keyboard (a noop here) */
  322.  
  323. {
  324.     /* save the original function key definitions */
  325.     savekeys(&functab);
  326.     setkeys(&newtab);
  327.  
  328.     /* save the cursor type */
  329.     rg.h.ah = 0x0a;        /* read cursor form */
  330.     int86(0x91, &rg, &rg);
  331.     octype = rg.h.al;    /* save old cursor type */
  332.     ocraster = rg.x.dx;    /* save old cursor rasters */
  333.  
  334.     /* and set it as a block */
  335.     rg.h.ah = 0x09;        /* set cursor form */
  336.     rg.h.al = 0xd1;        /* full-size, fast blink,
  337.                    high intensity, box */
  338.     int86(0x91, &rg, &rg);
  339.  
  340.     /* make sure the windows are re-framed */
  341.     upwind();
  342. }
  343.  
  344. PASCAL NEAR fmrkclose()    /* close the keyboard (a noop here) */
  345.  
  346. {
  347.     setkeys(&functab);
  348.     gds_erase();        /* close the GDS driver, clear bhackground */
  349.  
  350.     /* retore the original cursor */
  351.     rg.h.ah = 0x09;        /* set cursor form */
  352.     rg.h.al = octype;    /* restore original cursor type */
  353.     rg.x.dx = ocraster;    /* and raster limits */
  354.     int86(0x91, &rg, &rg);
  355. }
  356.  
  357. savekeys(ftable)    /* save function key definitions */
  358.  
  359. KEYDEF *ftable;        /* table to save definitions to */
  360.  
  361. {
  362.     char *sp;    /* ptr to new keystroke definition */
  363.     int index;    /* index into table to save */
  364.     int jindex;    /* an index into the keystroke buffer */
  365.     int len;    /* length of the keystroke buffer */
  366.     char *kptr;    /* ptr into kbuf */
  367.     char kbuf[16];    /* buffer to hold definition */
  368.  
  369.     /* set up the pointers to the temp keystroke buffer */
  370.     kptr = kbuf;
  371.     sg.ds = FP_SEG(kptr);
  372.     rg.x.di = FP_OFF(kptr);
  373.     kptr[0] = 15; /* set length of buffer */
  374.  
  375.     /* for each key to save */
  376.     for (index = 0; index < NUMFKEYS; index++) {
  377.  
  378.         /* set parameters to reading key assignment call */
  379.         rg.h.ah = 0x0f;                /* subfunction code */
  380.         rg.x.dx = ftable[index].kf_JIScode;    /* set key */
  381.  
  382.         /* call the BIOS for the info */
  383.         int86x(0x90, &rg, &rg, &sg);
  384.  
  385.         /* and record the length */
  386.         len = rg.x.cx;
  387.         ftable[index].kf_len = len;
  388.  
  389.         /* and the keystrokes */
  390.         sp = malloc(len);
  391.         if (sp == NULL)
  392.             return;
  393.         for (jindex = 0; jindex < len; jindex++)
  394.             sp[jindex] = kptr[jindex + 1];
  395.         ftable[index].kf_def = sp;
  396.     }
  397. }
  398.  
  399. setkeys(ftable)    /* set the function key definitions */
  400.  
  401. KEYDEF *ftable;        /* table to set definitions from */
  402.  
  403. {
  404.     char *sp;    /* ptr to new keystroke definition */
  405.     int index;    /* index into table to save */
  406.     int jindex;    /* an index into the keystroke buffer */
  407.     int len;    /* length of the keystroke buffer */
  408.     char *kptr;    /* ptr into kbuf */
  409.     char kbuf[16];    /* buffer to hold definition */
  410.  
  411.     kptr = kbuf;
  412.  
  413.     /* for each key to set */
  414.     for (index = 0; index < NUMFKEYS; index++) {
  415.  
  416.         /* set up the pointers to the temp keystroke buffer */
  417.         sg.ds = FP_SEG(kptr);
  418.         rg.x.di = FP_OFF(kptr);
  419.  
  420.         /* set parameters to reading key assignment call */
  421.         rg.h.ah = 0x0e;                /* subfunction code */
  422.         rg.h.al = 1;                /* add 0 to the key address */
  423.         rg.x.dx = ftable[index].kf_JIScode;    /* set key */
  424.         rg.x.cx = len = ftable[index].kf_len;
  425.  
  426.         /* copy the keystrokes in */
  427.         sp = ftable[index].kf_def;
  428.         for (jindex = 0; jindex < len; jindex++) {
  429.             kptr[jindex] = sp[jindex];
  430.         }
  431.  
  432.         /* call the BIOS for the info */
  433.         int86x(0x90, &rg, &rg, &sg);
  434.     }
  435. }
  436.  
  437. PASCAL NEAR scwrite(row, outstr, forg, bacg)    /* write a line out*/
  438.  
  439. int row;    /* row of screen to place outstr on */
  440. char *outstr;    /* string to write out (must be term.t_ncol long) */
  441. int forg;    /* forground color of string to write */
  442. int bacg;    /* background color */
  443.  
  444. {
  445.     /* move to the begining of the destination line */
  446.     fmrmove(row, 0);
  447.  
  448.     /* set the proper forground color */
  449.     fmrfcol(forg);
  450.  
  451.     /* write the text to the screen */
  452.     rg.h.ah = 0x1e;            /* Character string output */
  453.     rg.x.cx = term.t_ncol;        /* # of chars to display */
  454.     sg.ds = FP_SEG(outstr);        /* point to string to display */
  455.     rg.x.di = FP_OFF(outstr);
  456.     int86x(0x91, &rg, &rg, &sg);    /* call bios to write */
  457.  
  458.     /* set the background color for this line */
  459.     gds_bline(row, bacg);
  460.  
  461.     /* scwrite moves the cursor.... */
  462.     ttrow++;
  463.     ttcol = 0;
  464. }
  465.  
  466. #if    FLABEL
  467. int PASCAL NEAR fnclabel(f, n)        /* label a function key */
  468.  
  469. int f,n;    /* default flag, numeric argument [unused] */
  470.  
  471. {
  472.     /* on machines with no function keys...don't bother */
  473.     return(TRUE);
  474. }
  475. #endif
  476.  
  477. /****    FMR  GDS functions        ****/
  478.  
  479. /*    Some globals    */
  480.  
  481. unsigned char param[32];    /* parameter block for GDS_outdata */
  482.  
  483. /* draw operations code definitions */
  484.  
  485. #define    OP(class, elem, parlen)    class * 0x1000 + elem * 0x20 + parlen
  486. #define setpar(n, val)    param[n] = (val) & 255; param[n+1] = ((val) >> 8) & 255
  487.  
  488. gds_init()
  489.  
  490. {
  491.     /* set input parameters */
  492.     rg.h.ah = 0x80;        /* Graphics initialization function code */
  493.  
  494.     /* call GDS */
  495.     int86x(0x92, &rg, &rg, &sg);
  496.  
  497.     /* return success if AH == 0 */
  498.     if (rg.h.ah != 0)
  499.         return(FALSE);
  500.  
  501.     gds_paintmode(1);
  502.     return(TRUE);
  503. }
  504.  
  505. gds_erase()
  506.  
  507. {
  508.     /* set input parameters */
  509.     rg.h.ah = 0x84;        /* Graphics initialization function code */
  510.  
  511.     /* call GDS */
  512.     int86x(0x92, &rg, &rg, &sg);
  513.  
  514.     /* return success if AH == 0 */
  515.     return(rg.h.ah == 0);
  516. }
  517.  
  518. gds_outdata(data)    /* execute graphic data commands */
  519.  
  520. unsigned char *data;    /* graphic command buffer */
  521.  
  522. {
  523.     /* set input parameters */
  524.     rg.h.ah = 0x8f;        /* Output of graphic data function code */
  525.  
  526.     sg.ds = FP_SEG(data);    /* set address of command buffer */
  527.     rg.x.di = FP_OFF(data);
  528.  
  529.     /* call GDS */
  530.     int86x(0x92, &rg, &rg, &sg);
  531.  
  532.     /* return success if AH == 0 */
  533.     return(rg.h.ah == 0);
  534. }
  535.  
  536. gds_paintmode(mode)    /* set paint mode */
  537.  
  538. int mode;    /* forground mode for painting */
  539.  
  540. {
  541.     /* set command buffer length */
  542.     setpar(0, 4);
  543.  
  544.     /* set the graphic function code */
  545.     setpar(2, OP(5, 22, 2));
  546.  
  547.     /* set the mode */
  548.     setpar(4, mode);
  549.  
  550.     /* send it out */
  551.     return(gds_outdata(param));
  552. }
  553.  
  554. gds_boxcolor(color)    /* set box color */
  555.  
  556. int color;
  557.  
  558. {
  559.     /* set command buffer length */
  560.     setpar(0, 4);
  561.  
  562.     /* set the graphic function code */
  563.     setpar(2, OP(5, 23, 2));
  564.  
  565.     /* set the colorion */
  566.     setpar(4, color);
  567.  
  568.     /* send it out */
  569.     gds_outdata(param);
  570.  
  571.     /* set command buffer length */
  572.     setpar(0, 4);
  573.  
  574.     /* set the graphic function code */
  575.     setpar(2, OP(5, 28, 2));
  576.  
  577.     /* set the colorion */
  578.     setpar(4, color);
  579.  
  580.     /* send it out */
  581.     return(gds_outdata(param));
  582. }
  583.  
  584. /* draw a line's background color box */
  585.  
  586. gds_bline(line, color)
  587.  
  588. int line;    /* screen line to reset color on */
  589. int color;    /* color to draw background line in */
  590.  
  591. {
  592.     int typos;    /* top (upper left) coord of rectangle */
  593.  
  594.     typos = line * 30;
  595.  
  596.     /* set the proper color for the line */
  597.     gds_boxcolor(bcmap[color]);
  598.  
  599.     /* set command buffer length */
  600.     setpar(0, 10);
  601.  
  602.     /* set the graphic function code */
  603.     setpar(2, OP(4, 11, 8));
  604.  
  605.     /* set the upper left point */
  606.     setpar(4, 0);
  607.     setpar(6, typos);
  608.  
  609.     /* set the lower right point */
  610.     setpar(8, 1120);
  611.     setpar(10, typos + 30);
  612.  
  613.     /* send it out */
  614.     return(gds_outdata(param));
  615. }
  616. #else
  617. fmrhello()
  618. {
  619. }
  620. #endif
  621.