home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / UE311C.ZIP / FMR.C < prev    next >
C/C++ Source or Header  |  1991-10-11  |  13KB  |  623 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.     0, 0,
  164.     MARGIN,
  165.     SCRSIZ,
  166.     NPAUSE,
  167.         fmropen,
  168.         fmrclose,
  169.     fmrkopen,
  170.     fmrkclose,
  171.         ttgetc,
  172.         ttputc,
  173.         ttflush,
  174.         fmrmove,
  175.         fmreeol,
  176.         fmreeop,
  177.         fmreeop,
  178.         fmrbeep,
  179.     fmrrev,
  180.     fmrcres
  181. #if    COLOR
  182.     , fmrfcol,
  183.     fmrbcol
  184. #endif
  185. };
  186.  
  187. #if    COLOR
  188. PASCAL NEAR fmrfcol(color)        /* set the current output color */
  189.  
  190. int color;    /* color to set */
  191.  
  192. {
  193.     if (color == cfcolor)
  194.         return;
  195.     ttputc(ESC);
  196.     ttputc('[');
  197.     fmrparm((color & 7)+30);
  198.     ttputc('m');
  199.     cfcolor = color;
  200. }
  201.  
  202. PASCAL NEAR fmrbcol(color)        /* set the current background color */
  203.  
  204. int color;    /* color to set */
  205.  
  206. {
  207.     if (color == cbcolor)
  208.         return;
  209. #if    0
  210.     ttputc(ESC);
  211.     ttputc('[');
  212.     fmrparm(color+40);
  213.     ttputc('m');
  214. #endif
  215.         cbcolor = color;
  216. }
  217. #endif
  218.  
  219. PASCAL NEAR fmrmove(row, col)
  220. {
  221.         ttputc(ESC);
  222.         ttputc('[');
  223.         fmrparm(row+1);
  224.         ttputc(';');
  225.         fmrparm(col+1);
  226.         ttputc('H');
  227. }
  228.  
  229. PASCAL NEAR fmreeol()
  230. {
  231.         ttputc(ESC);
  232.         ttputc('[');
  233.         ttputc('K');
  234. }
  235.  
  236. PASCAL NEAR fmreeop()
  237. {
  238. #if    COLOR
  239.     fmrfcol(gfcolor);
  240.     fmrbcol(gbcolor);
  241. #endif
  242.         ttputc(ESC);
  243.         ttputc('[');
  244.     ttputc('2');
  245.         ttputc('J');
  246.  
  247.     gds_erase();    /* dump the background colors */
  248. }
  249.  
  250. PASCAL NEAR fmrrev(state)        /* change reverse video state */
  251.  
  252. int state;    /* TRUE = reverse, FALSE = normal */
  253.  
  254. {
  255.     ttputc(ESC);
  256.     ttputc('[');
  257.     ttputc(state ? '7': '0');
  258.     ttputc('m');
  259.     if (state)
  260.         fmrfcol(7);
  261. }
  262.  
  263. PASCAL NEAR fmrcres()    /* change screen resolution */
  264.  
  265. {
  266.     return(TRUE);
  267. }
  268.  
  269. PASCAL NEAR spal(char *dummy)        /* change pallette settings */
  270.  
  271. {
  272.     /* none for now */
  273. }
  274.  
  275. PASCAL NEAR fmrbeep()
  276. {
  277.         ttputc(BEL);
  278.         ttflush();
  279. }
  280.  
  281. PASCAL NEAR fmrparm(n)
  282. register int    n;
  283. {
  284.         register int q,r;
  285.  
  286.         q = n/10;
  287.         if (q != 0) {
  288.         r = q/10;
  289.         if (r != 0) {
  290.             ttputc((r%10)+'0');
  291.         }
  292.         ttputc((q%10) + '0');
  293.         }
  294.         ttputc((n%10) + '0');
  295. }
  296.  
  297. PASCAL NEAR fmropen()
  298.  
  299. {
  300.     strcpy(sres, "NORMAL");
  301.     revexist = TRUE;
  302.         ttopen();
  303.  
  304.     ttputc(ESC);        /* no attributes set */
  305.     ttputc('[');
  306.     fmrparm(40);
  307.     ttputc('m');
  308.  
  309.     gds_init();        /* initialize the GDS driver */
  310. }
  311.  
  312. PASCAL NEAR fmrclose()
  313.  
  314. {
  315. #if    COLOR
  316.     fmrfcol(7);
  317.     fmrbcol(0);
  318. #endif
  319.     gds_erase();        /* close the GDS driver, clear background */
  320.     ttclose();
  321. }
  322.  
  323. PASCAL NEAR fmrkopen()    /* open the keyboard */
  324.  
  325. {
  326.     /* save the original function key definitions */
  327.     savekeys(&functab);
  328.     setkeys(&newtab);
  329.  
  330.     /* save the cursor type */
  331.     rg.h.ah = 0x0a;        /* read cursor form */
  332.     int86(0x91, &rg, &rg);
  333.     octype = rg.h.al;    /* save old cursor type */
  334.     ocraster = rg.x.dx;    /* save old cursor rasters */
  335.  
  336.     /* and set it as a block */
  337.     rg.h.ah = 0x09;        /* set cursor form */
  338.     rg.h.al = 0xd1;        /* full-size, fast blink,
  339.                    high intensity, box */
  340.     int86(0x91, &rg, &rg);
  341.  
  342.     /* make sure the windows are re-framed */
  343.     upwind();
  344. }
  345.  
  346. PASCAL NEAR fmrkclose()    /* close the keyboard (a noop here) */
  347.  
  348. {
  349.     setkeys(&functab);
  350.     gds_erase();        /* close the GDS driver, clear bhackground */
  351.  
  352.     /* retore the original cursor */
  353.     rg.h.ah = 0x09;        /* set cursor form */
  354.     rg.h.al = octype;    /* restore original cursor type */
  355.     rg.x.dx = ocraster;    /* and raster limits */
  356.     int86(0x91, &rg, &rg);
  357. }
  358.  
  359. savekeys(ftable)    /* save function key definitions */
  360.  
  361. KEYDEF *ftable;        /* table to save definitions to */
  362.  
  363. {
  364.     char *sp;    /* ptr to new keystroke definition */
  365.     int index;    /* index into table to save */
  366.     int jindex;    /* an index into the keystroke buffer */
  367.     int len;    /* length of the keystroke buffer */
  368.     char *kptr;    /* ptr into kbuf */
  369.     char kbuf[16];    /* buffer to hold definition */
  370.  
  371.     /* set up the pointers to the temp keystroke buffer */
  372.     kptr = kbuf;
  373.     sg.ds = FP_SEG(kptr);
  374.     rg.x.di = FP_OFF(kptr);
  375.     kptr[0] = 15; /* set length of buffer */
  376.  
  377.     /* for each key to save */
  378.     for (index = 0; index < NUMFKEYS; index++) {
  379.  
  380.         /* set parameters to reading key assignment call */
  381.         rg.h.ah = 0x0f;                /* subfunction code */
  382.         rg.x.dx = ftable[index].kf_JIScode;    /* set key */
  383.  
  384.         /* call the BIOS for the info */
  385.         int86x(0x90, &rg, &rg, &sg);
  386.  
  387.         /* and record the length */
  388.         len = rg.x.cx;
  389.         ftable[index].kf_len = len;
  390.  
  391.         /* and the keystrokes */
  392.         sp = malloc(len);
  393.         if (sp == NULL)
  394.             return;
  395.         for (jindex = 0; jindex < len; jindex++)
  396.             sp[jindex] = kptr[jindex + 1];
  397.         ftable[index].kf_def = sp;
  398.     }
  399. }
  400.  
  401. setkeys(ftable)    /* set the function key definitions */
  402.  
  403. KEYDEF *ftable;        /* table to set definitions from */
  404.  
  405. {
  406.     char *sp;    /* ptr to new keystroke definition */
  407.     int index;    /* index into table to save */
  408.     int jindex;    /* an index into the keystroke buffer */
  409.     int len;    /* length of the keystroke buffer */
  410.     char *kptr;    /* ptr into kbuf */
  411.     char kbuf[16];    /* buffer to hold definition */
  412.  
  413.     kptr = kbuf;
  414.  
  415.     /* for each key to set */
  416.     for (index = 0; index < NUMFKEYS; index++) {
  417.  
  418.         /* set up the pointers to the temp keystroke buffer */
  419.         sg.ds = FP_SEG(kptr);
  420.         rg.x.di = FP_OFF(kptr);
  421.  
  422.         /* set parameters to reading key assignment call */
  423.         rg.h.ah = 0x0e;                /* subfunction code */
  424.         rg.h.al = 1;                /* add 0 to the key address */
  425.         rg.x.dx = ftable[index].kf_JIScode;    /* set key */
  426.         rg.x.cx = len = ftable[index].kf_len;
  427.  
  428.         /* copy the keystrokes in */
  429.         sp = ftable[index].kf_def;
  430.         for (jindex = 0; jindex < len; jindex++) {
  431.             kptr[jindex] = sp[jindex];
  432.         }
  433.  
  434.         /* call the BIOS for the info */
  435.         int86x(0x90, &rg, &rg, &sg);
  436.     }
  437. }
  438.  
  439. PASCAL NEAR scwrite(row, outstr, forg, bacg)    /* write a line out*/
  440.  
  441. int row;    /* row of screen to place outstr on */
  442. char *outstr;    /* string to write out (must be term.t_ncol long) */
  443. int forg;    /* forground color of string to write */
  444. int bacg;    /* background color */
  445.  
  446. {
  447.     /* move to the begining of the destination line */
  448.     fmrmove(row, 0);
  449.  
  450.     /* set the proper forground color */
  451.     fmrfcol(forg);
  452.  
  453.     /* write the text to the screen */
  454.     rg.h.ah = 0x1e;            /* Character string output */
  455.     rg.x.cx = term.t_ncol;        /* # of chars to display */
  456.     sg.ds = FP_SEG(outstr);        /* point to string to display */
  457.     rg.x.di = FP_OFF(outstr);
  458.     int86x(0x91, &rg, &rg, &sg);    /* call bios to write */
  459.  
  460.     /* set the background color for this line */
  461.     gds_bline(row, bacg);
  462.  
  463.     /* scwrite moves the cursor.... */
  464.     ttrow++;
  465.     ttcol = 0;
  466. }
  467.  
  468. #if    FLABEL
  469. int PASCAL NEAR fnclabel(f, n)        /* label a function key */
  470.  
  471. int f,n;    /* default flag, numeric argument [unused] */
  472.  
  473. {
  474.     /* on machines with no function keys...don't bother */
  475.     return(TRUE);
  476. }
  477. #endif
  478.  
  479. /****    FMR  GDS functions        ****/
  480.  
  481. /*    Some globals    */
  482.  
  483. unsigned char param[32];    /* parameter block for GDS_outdata */
  484.  
  485. /* draw operations code definitions */
  486.  
  487. #define    OP(class, elem, parlen)    class * 0x1000 + elem * 0x20 + parlen
  488. #define setpar(n, val)    param[n] = (val) & 255; param[n+1] = ((val) >> 8) & 255
  489.  
  490. gds_init()
  491.  
  492. {
  493.     /* set input parameters */
  494.     rg.h.ah = 0x80;        /* Graphics initialization function code */
  495.  
  496.     /* call GDS */
  497.     int86x(0x92, &rg, &rg, &sg);
  498.  
  499.     /* return success if AH == 0 */
  500.     if (rg.h.ah != 0)
  501.         return(FALSE);
  502.  
  503.     gds_paintmode(1);
  504.     return(TRUE);
  505. }
  506.  
  507. gds_erase()
  508.  
  509. {
  510.     /* set input parameters */
  511.     rg.h.ah = 0x84;        /* Graphics initialization function code */
  512.  
  513.     /* call GDS */
  514.     int86x(0x92, &rg, &rg, &sg);
  515.  
  516.     /* return success if AH == 0 */
  517.     return(rg.h.ah == 0);
  518. }
  519.  
  520. gds_outdata(data)    /* execute graphic data commands */
  521.  
  522. unsigned char *data;    /* graphic command buffer */
  523.  
  524. {
  525.     /* set input parameters */
  526.     rg.h.ah = 0x8f;        /* Output of graphic data function code */
  527.  
  528.     sg.ds = FP_SEG(data);    /* set address of command buffer */
  529.     rg.x.di = FP_OFF(data);
  530.  
  531.     /* call GDS */
  532.     int86x(0x92, &rg, &rg, &sg);
  533.  
  534.     /* return success if AH == 0 */
  535.     return(rg.h.ah == 0);
  536. }
  537.  
  538. gds_paintmode(mode)    /* set paint mode */
  539.  
  540. int mode;    /* forground mode for painting */
  541.  
  542. {
  543.     /* set command buffer length */
  544.     setpar(0, 4);
  545.  
  546.     /* set the graphic function code */
  547.     setpar(2, OP(5, 22, 2));
  548.  
  549.     /* set the mode */
  550.     setpar(4, mode);
  551.  
  552.     /* send it out */
  553.     return(gds_outdata(param));
  554. }
  555.  
  556. gds_boxcolor(color)    /* set box color */
  557.  
  558. int color;
  559.  
  560. {
  561.     /* set command buffer length */
  562.     setpar(0, 4);
  563.  
  564.     /* set the graphic function code */
  565.     setpar(2, OP(5, 23, 2));
  566.  
  567.     /* set the colorion */
  568.     setpar(4, color);
  569.  
  570.     /* send it out */
  571.     gds_outdata(param);
  572.  
  573.     /* set command buffer length */
  574.     setpar(0, 4);
  575.  
  576.     /* set the graphic function code */
  577.     setpar(2, OP(5, 28, 2));
  578.  
  579.     /* set the colorion */
  580.     setpar(4, color);
  581.  
  582.     /* send it out */
  583.     return(gds_outdata(param));
  584. }
  585.  
  586. /* draw a line's background color box */
  587.  
  588. gds_bline(line, color)
  589.  
  590. int line;    /* screen line to reset color on */
  591. int color;    /* color to draw background line in */
  592.  
  593. {
  594.     int typos;    /* top (upper left) coord of rectangle */
  595.  
  596.     typos = line * 30;
  597.  
  598.     /* set the proper color for the line */
  599.     gds_boxcolor(bcmap[color]);
  600.  
  601.     /* set command buffer length */
  602.     setpar(0, 10);
  603.  
  604.     /* set the graphic function code */
  605.     setpar(2, OP(4, 11, 8));
  606.  
  607.     /* set the upper left point */
  608.     setpar(4, 0);
  609.     setpar(6, typos);
  610.  
  611.     /* set the lower right point */
  612.     setpar(8, 1120);
  613.     setpar(10, typos + 30);
  614.  
  615.     /* send it out */
  616.     return(gds_outdata(param));
  617. }
  618. #else
  619. fmrhello()
  620. {
  621. }
  622. #endif
  623.