home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 7.ddi / EXAMPLES / GRAPHICS / GGLUE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-25  |  21.9 KB  |  1,397 lines

  1. /* gglue.c - Graphics glue routines */
  2.  
  3. /************************************************************************/
  4. /*    Copyright (C) 1986-1988 Phar Lap Software, Inc.            */
  5. /*    Unpublished - rights reserved under the Copyright Laws of the    */
  6. /*    United States.  Use, duplication, or disclosure by the         */
  7. /*    Government is subject to restrictions as set forth in         */
  8. /*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  9. /*    Computer Software clause at 252.227-7013.            */
  10. /*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  11. /************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #include "gserver.h"
  18.  
  19. /*
  20.  * Include the Microsoft graphics library definition file.  Before we do
  21.  * this, we will undefine the keywords cdecl and far so that we will
  22.  * correctly compile the function prototypes.  High C-386 1.6 doesn't like the
  23.  * cdecl keyword and it is not really necessary (since we know this is C code).
  24.  * We will undefine far because protected mode programs are going to
  25.  * pass in near pointers to the graphics library routines.
  26.  */
  27. #define cdecl
  28. #define far
  29. #include "graph.h"
  30.  
  31. /*
  32.  * The communications buffer pointer and size variables 
  33.  * appear in prot.asm
  34.  */
  35. extern GBPTR _gbuffp;    /* Pointer to the graphics communications buffer */
  36. extern int _gbuffsize;    /* Size in bytes of the communications buffer */
  37.  
  38. int _gbuff_flag;    /* Buffered mode flag - TRUE = buffered, FALSE =
  39.                unbuffered */
  40.  
  41. unsigned long _server_ptr; /* Real mode address of the graphics server */
  42.  
  43. unsigned long _rbuffp;    /* Real mode address of the communucations buffer */
  44.  
  45. int _gopenf = {0};    /* Graphics server is open flag */
  46.  
  47. char def_dname[] = "gserver.drv";    /* Default name of the graphics
  48.                        server */
  49.  
  50. onexit_t _gexitfp = {0};        /* On exit function pointer for
  51.                        use by _gclose */
  52.  
  53. int _gregf = {0};            /* "_gclose" has been registered
  54.                        with "exit" flag */
  55.  
  56. /*
  57.  * Forward function declarations
  58.  */
  59. onexit_t _gclose();
  60. void _gflush();
  61. int _gbuffmode();
  62.  
  63. /*
  64.  * Functions which appear in prot.asm
  65.  */
  66. extern void realcall();
  67. extern void realexit();
  68. extern int realload();
  69. extern unsigned long prottoreal();
  70.  
  71. /*
  72.  
  73. _gopen - Open the graphics server
  74.  
  75. This routine is called to open the real mode graphics server.  It is
  76. passed in the address of the name of the file that contains the real
  77. mode server code.  Since this routine does no searching of the PATH
  78. environment variable, the file name must contain a directory path or the
  79. file must be located in the current directory.  
  80.  
  81. The open process consists of the following steps:
  82.  
  83.     1).  The real mode server is loaded into memory
  84.  
  85.     2).  Its initialization routine is called
  86.     
  87.     3).  The communications buffer is marked as empty
  88.  
  89.     4).  The communications buffer is set to buffered mode
  90.  
  91. If the open is successful, then this routine returns 0.  If the
  92. open is unsuccessful, then this routine prints out an error message
  93. and termintes the program.
  94.  
  95. */
  96.  
  97. int _gopen(fnp)
  98.  
  99. char *fnp;        /* Pointer to the name of the .EXE file that contains
  100.                the graphics server. */
  101.  
  102. {
  103.  
  104.     int rc;            /* Return code */
  105.  
  106.     /* Make a quick return if the server is already open */
  107.  
  108.     rc = 0;
  109.     if(_gopenf)
  110.         goto ret1;
  111.  
  112.     /* Load and initialize the real mode graphics server */
  113.  
  114.     rc = realload(fnp, &_server_ptr);
  115.  
  116.     /* If there was a load error terminate the program */
  117.  
  118.     if(rc)
  119.     {
  120.         printf("Error loading real mode graphics server: %s: ", fnp);
  121.         switch(rc)
  122.         {
  123.         case 2:
  124.             printf("file not found\n");
  125.             break;
  126.         case 5:
  127.             printf("access denied\n");
  128.             break;
  129.         case 8:
  130.             printf("insufficient memory\n");
  131.             break;
  132.         case 10:
  133.             printf("invalid environment segment\n");
  134.             break;
  135.         case 11:
  136.             printf("invalid file format\n");
  137.             break;
  138.         default:
  139.             printf("error code=%d\n", rc);
  140.             break;
  141.         }
  142.         exit(rc);
  143.     }
  144.  
  145.     /* Mark the communications buffer as empty. */
  146.  
  147.     *(GBSPTR)_gbuffp = sizeof(short);
  148.  
  149.     /* Convert the protected mode address of the communications
  150.        buffer to a real mode address for use when the real
  151.        mode server is called. */
  152.  
  153.     _rbuffp = prottoreal(_gbuffp, 0x14);
  154.     
  155.     /* Start the graphics server in buffered mode. */
  156.  
  157.     _gbuff_flag = 1;
  158.  
  159.     /* Turn on the open flag */
  160.  
  161.     _gopenf = 1;
  162.  
  163.     /* Register _gclose to be called at exit time */
  164.  
  165.     if(!_gregf)
  166.     {
  167.         _gregf = 1;
  168.         _gexitfp = onexit(_gclose);
  169.     }
  170.  
  171.     /* Return to the calller */
  172.  
  173. ret1:    return rc;
  174.  
  175. }
  176.  
  177.  
  178. /*
  179.  
  180. _gclose - Close the graphics driver
  181.  
  182. This routine is called to close the real mode graphics server.  
  183. The following steps are performed in the close process:
  184.  
  185.     1).  Any existing commands in the communications buffer
  186.          are executed.
  187.  
  188.     2).  The server is told to exit and it
  189.          does any necessary clean-up operations.
  190.  
  191.     3).  The real mode memory allocated to the server is freed.
  192.  
  193. */
  194.  
  195. onexit_t _gclose()
  196.  
  197. {
  198.  
  199.     /* Switch on the current state of the open flag.  This switch
  200.        is required in case we are re-entered due to an abnormal error
  201.        exit from "_gflush" or "realexit". */
  202.  
  203.     switch(_gopenf)
  204.     {
  205.  
  206.     /* First flush any commands in the communications buffer */
  207.  
  208.     case 1:
  209.         ++_gopenf;
  210.         _gflush();
  211.  
  212.     /* Then tell the real mode code to exit */
  213.  
  214.     case 2:
  215.         ++_gopenf;
  216.         realexit();
  217.         
  218.     /* Then turn off the open flag */
  219.  
  220.     default:
  221.         _gopenf = 0;
  222.         break;
  223.         
  224.     }
  225.  
  226.     /* Return */
  227.  
  228.     return _gexitfp;
  229.  
  230. }
  231.  
  232.  
  233. /*
  234.  
  235. _gbuffmode - Set video buffering mode
  236.  
  237. This routine is called to change the buffering mode for communications
  238. buffer.  The routine takes a single argument which is the new mode. A
  239. value of zero means unbuffered and a value of one means buffered.  The
  240. routine returns as a function result the old mode.
  241.  
  242. */
  243.  
  244. int _gbuffmode(newmode)
  245.  
  246. int newmode;        /* New buffering mode */
  247.  
  248. {
  249.  
  250.     int oldmode;        /* Old buffering mode */
  251.  
  252.     if(!_gopenf)
  253.         _gopen(def_dname);
  254.     oldmode = _gbuff_flag;
  255.     _gbuff_flag = newmode;
  256.     if(!newmode)
  257.         _gflush();
  258.  
  259.     return oldmode;
  260.  
  261. }
  262.  
  263.  
  264. /* 
  265.  
  266. _galloc - Allocate space in the communications buffer
  267.  
  268. This routine is used by the glue routines to allocate space
  269. in the communications buffer.  The caller passes in the number
  270. of bytes that it needs in the communications buffer to hold
  271. a command.  If this number of bytes are available, then the
  272. routine returns immediately with a pointer
  273. into the buffer where the command can be placed.  If the
  274. space is not available, then the real mode server is called to
  275. empty out the buffer in order to make room for the new command.
  276. When the server is all done, this routine returns with a 
  277. pointer to the empty communications buffer.
  278.  
  279. */
  280.  
  281. GBPTR _galloc(n)
  282.  
  283. unsigned n;        /* Number of bytes needed */
  284.  
  285. {
  286.  
  287.     register GBPTR bp;        /* Buffer pointer */
  288.     GBPTR rp;            /* Returned pointer */
  289.  
  290.     /* If the server is not open, then open to the default server */
  291.  
  292.     if(!_gopenf)
  293.         _gopen(def_dname);
  294.  
  295.     /* If the communications buffer does not have enough room for
  296.        the number of bytes requested by the caller, then flush the buffer
  297.        by executing all of the commands in it in order to make room. */
  298.  
  299.     bp = _gbuffp;
  300.     if(SHORT0 + n > _gbuffsize)
  301.         _gflush();
  302.  
  303.     /* Calculate the return pointer for the caller */
  304.  
  305.     rp = bp + SHORT0;
  306.  
  307.     /* Increment the used byte count that is located in the first 2
  308.        bytes of the buffer */
  309.  
  310.     *SHORT0P += n;
  311.  
  312.     /* Return */
  313.  
  314.     return rp;
  315. }
  316.  
  317. /*
  318.  
  319. _gflush - Flush the communications buffer
  320.  
  321. This routine is called to flush the communications buffer.  If
  322. the buffer is not empty, then this routine calls the real mode
  323. server to execute all of the commands in the buffer.  The buffer
  324. is then marked as empty.
  325.  
  326. */
  327.  
  328. void _gflush()
  329.  
  330. {
  331.  
  332.     register GBPTR bp;        /* Buffer pointer */
  333.  
  334.  
  335.     /* If the server is not open, then return */
  336.  
  337.     if(!_gopenf)
  338.         return;
  339.  
  340.     /* If the communications buffer is not empty, then call
  341.        then real mode server to execute the graphics commands
  342.        in the buffer. */
  343.  
  344.     bp = _gbuffp;
  345.     if(SHORT0 > sizeof(short))
  346.         realcall(_server_ptr, _rbuffp);
  347.  
  348.     /* Empty out the buffer by setting the use count at the front
  349.        of the buffer to the size of the use count. */
  350.  
  351.     *SHORT0P = sizeof(short);
  352.  
  353. }        
  354.  
  355.  
  356. /*
  357.  
  358. _arc - _arc glue routine 
  359.  
  360. */
  361.  
  362. short  _arc(short x1, short y1, short x2, short y2,
  363.                short x3, short y3, short x4, short y4)
  364.  
  365. {
  366.  
  367.     register GBPTR bp;        /* Buffer pointer */
  368.  
  369.     bp = _galloc(sizeof(short) * 9 + 1);
  370.     *bp++ = op_arc;
  371.     *SHORT0P = x1;
  372.     *SHORT2P = y1;
  373.     *SHORT4P = x2;
  374.     *SHORT6P = y2;
  375.     *SHORT8P = x3;
  376.     *SHORT10P = y3;
  377.     *SHORT12P = x4;
  378.     *SHORT14P = y4;
  379.     if(!_gbuff_flag)
  380.     {
  381.         _gflush();
  382.         return SHORT16;
  383.     }
  384.     return 1;
  385.  
  386. }
  387.  
  388.  
  389. /*
  390.  
  391. _clearscreen - _clearscreen glue routine
  392.  
  393. */
  394.  
  395. void  _clearscreen(short area)
  396.  
  397. {
  398.  
  399.     register GBPTR bp;
  400.  
  401.     bp = _galloc(sizeof(short) + 1);
  402.     *bp++ = op_clearscreen;
  403.     *SHORT0P = area;
  404.     if(!_gbuff_flag)
  405.         _gflush();
  406.     return;
  407.  
  408. }
  409.  
  410.  
  411. /*
  412.  
  413. _displaycursor - _displaycursor glue routine 
  414.  
  415. */
  416.  
  417. short  _displaycursor(short n)
  418.  
  419. {
  420.  
  421.     register GBPTR bp;        /* Buffer pointer */
  422.  
  423.     bp = _galloc(sizeof(short) * 2 + 1);
  424.     *bp++ = op_displaycursor;
  425.     *SHORT0P = n;
  426.     _gflush();
  427.     return SHORT2;
  428.  
  429. }
  430.  
  431.  
  432. /*
  433.  
  434. _ellipse - _ellipse glue routine 
  435.  
  436. */
  437.  
  438. short  _ellipse(short c, short x1, short y1, short x2, short y2)
  439.  
  440. {
  441.  
  442.     register GBPTR bp;        /* Buffer pointer */
  443.  
  444.     bp = _galloc(sizeof(short) * 6 + 1);
  445.     *bp++ = op_ellipse;
  446.     *SHORT0P = c;
  447.     *SHORT2P = x1;
  448.     *SHORT4P = y1;
  449.     *SHORT6P = x2;
  450.     *SHORT8P = y2;
  451.     if(!_gbuff_flag)
  452.     {
  453.         _gflush();
  454.         return SHORT10;
  455.     }
  456.     return 1;
  457.  
  458. }
  459.  
  460.  
  461. /*
  462.  
  463. _floodfill - _floodfill glue routine 
  464.  
  465. */
  466.  
  467. short  _floodfill(short x, short y, short b)
  468.  
  469. {
  470.  
  471.     register GBPTR bp;        /* Buffer pointer */
  472.  
  473.     bp = _galloc(sizeof(short) * 4 + 1);
  474.     *bp++ = op_floodfill;
  475.     *SHORT0P = x;
  476.     *SHORT2P = y;
  477.     *SHORT4P = b;
  478.     if(!_gbuff_flag)
  479.     {
  480.         _gflush();
  481.         return SHORT6;
  482.     }
  483.     return 1;
  484.  
  485. }
  486.  
  487.  
  488. /*
  489.  
  490. _fmoveto - Fast _moveto glue routine (buffered)
  491.  
  492. */
  493.  
  494. void  _fmoveto(short x, short y)
  495.  
  496. {
  497.  
  498.     register GBPTR bp;        /* Buffer pointer */
  499.  
  500.     bp = _galloc(sizeof(short) * 4 + 1);
  501.     *bp++ = op_moveto;
  502.     *SHORT0P = x;
  503.     *SHORT2P = y;
  504.     if(!_gbuff_flag)
  505.         _gflush();
  506.     return;
  507.  
  508. }
  509.  
  510.  
  511. /*
  512.  
  513. _getbkcolor - _getbkcolor glue routine 
  514.  
  515. */
  516.  
  517. long  _getbkcolor(void)
  518.  
  519. {
  520.  
  521.     register GBPTR bp;        /* Buffer pointer */
  522.  
  523.     bp = _galloc(sizeof(long) + 1);
  524.     *bp++ = op_getbkcolor;
  525.     _gflush();
  526.     return LONG0;
  527.  
  528. }
  529.  
  530.  
  531. /*
  532.  
  533. _getcolor - _getcolor glue routine 
  534.  
  535. */
  536.  
  537. short  _getcolor(void)
  538.  
  539. {
  540.  
  541.     register GBPTR bp;        /* Buffer pointer */
  542.  
  543.     bp = _galloc(sizeof(short) * 1 + 1);
  544.     *bp++ = op_getcolor;
  545.     _gflush();
  546.     return SHORT0;
  547.  
  548. }
  549.  
  550.  
  551. /*
  552.  
  553. _getcurrentposition - _getcurrentposition glue routine 
  554.  
  555. */
  556.  
  557. struct xycoord  _getcurrentposition(void)
  558.  
  559. {
  560.  
  561.     register GBPTR bp;        /* Buffer pointer */
  562.     struct xycoord xy;        /* X-Y return value */
  563.  
  564.     bp = _galloc(sizeof(short) * 2 + 1);
  565.     *bp++ = op_getcurrentposition;
  566.     _gflush();
  567.     xy.xcoord = SHORT0;
  568.     xy.ycoord = SHORT2;
  569.     return xy;
  570.  
  571. }
  572.  
  573.  
  574. /*
  575.  
  576. _getfillmask - _getfillmask glue routine 
  577.  
  578. */
  579.  
  580. unsigned char *_getfillmask(register unsigned char *mp)
  581.  
  582. {
  583.  
  584.     register GBPTR bp;        /* Buffer pointer */
  585.     int i;                /* Loop counter */
  586.  
  587.     bp = _galloc(sizeof(short) + 8 + 1);
  588.     *bp++ = op_getfillmask;
  589.     _gflush();
  590.     if(!SHORT8)
  591.         return NULL;
  592.     for(i = 0; i < 8; ++i)
  593.         *mp++ = *bp++;
  594.     return mp - 8;
  595.  
  596. }
  597.  
  598.  
  599. /*
  600.  
  601. _getlinestyle - _getlinestyle glue routine 
  602.  
  603. */
  604.  
  605. unsigned short  _getlinestyle(void)
  606.  
  607. {
  608.  
  609.     register GBPTR bp;        /* Buffer pointer */
  610.  
  611.     bp = _galloc(sizeof(short) * 1 + 1);
  612.     *bp++ = op_getlinestyle;
  613.     _gflush();
  614.     return (unsigned short)SHORT0;
  615.  
  616. }
  617.  
  618.  
  619. /*
  620.  
  621. _getlogcoord - _getlogcoord glue routine 
  622.  
  623. */
  624.  
  625. struct xycoord  _getlogcoord(short x, short y)
  626.  
  627. {
  628.  
  629.     register GBPTR bp;        /* Buffer pointer */
  630.     struct xycoord xy;        /* X-Y return value */
  631.  
  632.     bp = _galloc(sizeof(short) * 4 + 1);
  633.     *bp++ = op_getlogcoord;
  634.     *SHORT0P = x;
  635.     *SHORT2P = y;
  636.     _gflush();
  637.     xy.xcoord = SHORT4;
  638.     xy.ycoord = SHORT6;
  639.     return xy;
  640.  
  641. }
  642.  
  643.  
  644. /*
  645.  
  646. _getphyscoord - _getphyscoord glue routine 
  647.  
  648. */
  649.  
  650. struct xycoord  _getphyscoord(short x, short y)
  651.  
  652. {
  653.  
  654.     register GBPTR bp;        /* Buffer pointer */
  655.     struct xycoord xy;        /* X-Y return value */
  656.  
  657.     bp = _galloc(sizeof(short) * 4 + 1);
  658.     *bp++ = op_getphyscoord;
  659.     *SHORT0P = x;
  660.     *SHORT2P = y;
  661.     _gflush();
  662.     xy.xcoord = SHORT4;
  663.     xy.ycoord = SHORT6;
  664.     return xy;
  665.  
  666. }
  667.  
  668.  
  669. /*
  670.  
  671. _getpixel - _getpixel glue routine
  672.  
  673. */
  674.  
  675. short  _getpixel(short x, short y)
  676.  
  677. {
  678.  
  679.     register GBPTR bp;
  680.  
  681.     bp = _galloc(sizeof(short) * 3 + 1);
  682.     *bp++ = op_getpixel;
  683.     *SHORT0P = x;
  684.     *SHORT2P = y;
  685.     _gflush();
  686.     return SHORT4;
  687.  
  688. }
  689.  
  690.  
  691. /*
  692.  
  693. _gettextcolor - _gettextcolor glue routine 
  694.  
  695. */
  696.  
  697. short  _gettextcolor(void)
  698.  
  699. {
  700.  
  701.     register GBPTR bp;        /* Buffer pointer */
  702.  
  703.     bp = _galloc(sizeof(short) * 1 + 1);
  704.     *bp++ = op_gettextcolor;
  705.     _gflush();
  706.     return SHORT0;
  707.  
  708. }
  709.  
  710.  
  711. /*
  712.  
  713. _gettextposition - _gettextposition glue routine 
  714.  
  715. */
  716.  
  717. struct rccoord  _gettextposition(void)
  718.  
  719. {
  720.  
  721.     register GBPTR bp;        /* Buffer pointer */
  722.     struct rccoord rc;        /* Row/column structure */
  723.  
  724.     bp = _galloc(sizeof(short) * 2 + 1);
  725.     *bp++ = op_gettextposition;
  726.     _gflush();
  727.     rc.row = SHORT0;
  728.     rc.col = SHORT2;
  729.     return rc;
  730.  
  731. }
  732.  
  733.  
  734. /*
  735.  
  736. _getvideoconfig - _getvideoconfig glue routine 
  737.  
  738. */
  739.  
  740. struct videoconfig *_getvideoconfig(struct videoconfig *p)
  741.  
  742. {
  743.  
  744.     register GBPTR bp;        /* Buffer pointer */
  745.  
  746.     bp = _galloc(sizeof(short) * 7 + 1);
  747.     *bp++ = op_getvideoconfig;
  748.     _gflush();
  749.     p->numxpixels = SHORT0;
  750.     p->numypixels = SHORT2;
  751.     p->numtextcols = SHORT4;
  752.     p->numtextrows = SHORT6;
  753.     p->numcolors = SHORT8;
  754.     p->bitsperpixel = SHORT10;
  755.     p->numvideopages = SHORT12;
  756.     p->mode = SHORT14;
  757.     p->adapter = SHORT16;
  758.     p->monitor = SHORT18;
  759.     p->memory = SHORT20;
  760.     return p;
  761.  
  762. }
  763.  
  764.  
  765. /*
  766.  
  767. _imagesize - _imagesize glue routine 
  768.  
  769. */
  770.  
  771. long  _imagesize(short x1, short y1, short x2, short y2)
  772.  
  773. {
  774.  
  775.     register GBPTR bp;        /* Buffer pointer */
  776.  
  777.     bp = _galloc(sizeof(short) * 4 + sizeof(long) + 1);
  778.     *bp++ = op_imagesize;
  779.     *SHORT0P = x1;
  780.     *SHORT2P = y1;
  781.     *SHORT4P = x2;
  782.     *SHORT6P = y2;
  783.     _gflush();
  784.     return LONG8;
  785.  
  786. }
  787.  
  788.  
  789. /*
  790.  
  791. _lineto - _lineto glue routine
  792.  
  793. */
  794.  
  795. short  _lineto(short x, short y)
  796.  
  797. {
  798.  
  799.     register GBPTR bp;
  800.  
  801.     bp = _galloc(sizeof(short) * 3 + 1);
  802.     *bp++ = op_lineto;
  803.     *SHORT0P = x;
  804.     *SHORT2P = y;
  805.     if(!_gbuff_flag)
  806.     {
  807.         _gflush();
  808.         return SHORT4;
  809.     }
  810.     return 1;
  811.  
  812. }
  813.  
  814.  
  815. /*
  816.  
  817. _moveto - _moveto glue routine
  818.  
  819. */
  820.  
  821. struct xycoord  _moveto(short x, short y)
  822.  
  823. {
  824.  
  825.     register GBPTR bp;        /* Buffer pointer */
  826.     struct xycoord ppnt;        /* Previous point */
  827.  
  828.     bp = _galloc(sizeof(short) * 3 + 1);
  829.     *bp++ = op_moveto;
  830.     *SHORT0P = x;
  831.     *SHORT2P = y;
  832.     _gflush();
  833.     ppnt.xcoord= SHORT4;
  834.     ppnt.ycoord = SHORT6;
  835.     return ppnt;
  836.  
  837. }
  838.  
  839.  
  840. /*
  841.  
  842. _outtext - _outtext glue routine 
  843.  
  844. */
  845.  
  846. void  _outtext(char *p)
  847.  
  848. {
  849.  
  850.     register GBPTR bp;    /* Buffer pointer */
  851.     int n;            /* String length */
  852.     int cc;            /* Cycle count */
  853.     int i;            /* Buffer copy count */
  854.  
  855.     n = strlen(p);
  856.     while(1)
  857.     {
  858.         cc = n;
  859.         if(cc > _gbuffsize - 2)
  860.             cc = _gbuffsize - 2;
  861.         bp = _galloc(cc + 2);
  862.         *bp++ = op_outtext;
  863.         for(i = 0; i < cc; ++i)
  864.             *(bp+i) = *(p+i);
  865.         *(bp + cc) = 0;
  866.         n -= cc;
  867.         if(n == 0)
  868.             break;
  869.         _gflush();
  870.     }
  871.  
  872. }
  873.  
  874.  
  875. /*
  876.  
  877. _pie - _pie glue routine 
  878.  
  879. */
  880.  
  881. short  _pie(short c, short x1, short y1, short x2, short y2,
  882.                short x3, short y3, short x4, short y4)
  883.  
  884. {
  885.  
  886.     register GBPTR bp;        /* Buffer pointer */
  887.  
  888.     bp = _galloc(sizeof(short) * 10 + 1);
  889.     *bp++ = op_pie;
  890.     *SHORT0P = c;
  891.     *SHORT2P = x1;
  892.     *SHORT4P = y1;
  893.     *SHORT6P = x2;
  894.     *SHORT8P = y2;
  895.     *SHORT10P = x3;
  896.     *SHORT12P = y3;
  897.     *SHORT14P = x4;
  898.     *SHORT16P = y4;
  899.     if(!_gbuff_flag)
  900.     {
  901.         _gflush();
  902.         return SHORT18;
  903.     }
  904.     return 1;
  905.  
  906. }
  907.  
  908.  
  909. /*
  910.  
  911. _rectangle - _rectangle glue routine 
  912.  
  913. */
  914.  
  915. short  _rectangle(short c, short x1, short y1, short x2, short y2)
  916.  
  917. {
  918.  
  919.     register GBPTR bp;        /* Buffer pointer */
  920.  
  921.     bp = _galloc(sizeof(short) * 6 + 1);
  922.     *bp++ = op_rectangle;
  923.     *SHORT0P = c;
  924.     *SHORT2P = x1;
  925.     *SHORT4P = y1;
  926.     *SHORT6P = x2;
  927.     *SHORT8P = y2;
  928.     if(!_gbuff_flag)
  929.     {
  930.         _gflush();
  931.         return SHORT10;
  932.     }
  933.     return 1;
  934.  
  935. }
  936.  
  937.  
  938. /*
  939.  
  940. _remapallpalette - _rempallpalette glue routine 
  941.  
  942. */
  943.  
  944. short  _remapallpalette(long *p)
  945.  
  946. {
  947.  
  948.     register GBPTR bp;        /* Buffer pointer */
  949.     int i;
  950.  
  951.     bp = _galloc(sizeof(long) * 16 + sizeof(short) + 1);
  952.     *bp++ = op_remapallpalette;
  953.     for(i = 0; i < (sizeof(long) * 16); ++i)
  954.         *(bp+i) = *(p+i);
  955.     bp += sizeof(long) * 16;
  956.     if(!_gbuff_flag)
  957.     {
  958.         _gflush();
  959.         return *(GBSPTR)bp;
  960.     }
  961.     return 0;
  962.  
  963. }
  964.  
  965.  
  966. /*
  967.  
  968. _remappalette - _remappalette glue routine 
  969.  
  970. */
  971.  
  972. long  _remappalette(short p, long c)
  973.  
  974. {
  975.  
  976.     register GBPTR bp;        /* Buffer pointer */
  977.  
  978.     bp = _galloc(sizeof(short) + sizeof(long) + 1);
  979.     *bp++ = op_remappalette;
  980.     *SHORT0P = p;
  981.     *LONG2P = c;
  982.     _gflush();
  983.     return LONG6;
  984.  
  985. }
  986.  
  987.  
  988. /*
  989.  
  990. _selectpalette - _selectpalette glue routine 
  991.  
  992. */
  993.  
  994. short  _selectpalette(short n)
  995.  
  996. {
  997.  
  998.     register GBPTR bp;        /* Buffer pointer */
  999.  
  1000.     bp = _galloc(sizeof(short) * 2 + 1);
  1001.     *bp++ = op_selectpalette;
  1002.     *SHORT0P = n;
  1003.     _gflush();
  1004.     return SHORT2;
  1005.  
  1006. }
  1007.  
  1008.  
  1009. /*
  1010.  
  1011. _setactivepage - _setactivepage glue routine 
  1012.  
  1013. */
  1014.  
  1015. short  _setactivepage(short n)
  1016.  
  1017. {
  1018.  
  1019.     register GBPTR bp;        /* Buffer pointer */
  1020.  
  1021.     bp = _galloc(sizeof(short) * 2 + 1);
  1022.     *bp++ = op_setactivepage;
  1023.     *SHORT0P = n;
  1024.     _gflush();
  1025.     return SHORT2;
  1026.  
  1027. }
  1028.  
  1029.  
  1030. /*
  1031.  
  1032. _setbkcolor - _setbkcolor glue routine 
  1033.  
  1034. */
  1035.  
  1036. long  _setbkcolor(long c)
  1037.  
  1038. {
  1039.  
  1040.     register GBPTR bp;        /* Buffer pointer */
  1041.  
  1042.     bp = _galloc(sizeof(long) * 2 + 1);
  1043.     *bp++ = op_setbkcolor;
  1044.     *LONG0P = c;
  1045.     _gflush();
  1046.     return LONG4;
  1047.  
  1048. }
  1049.  
  1050.  
  1051. /*
  1052.  
  1053. _setcliprgn - _setcliprgn glue routine 
  1054.  
  1055. */
  1056.  
  1057. void  _setcliprgn(short x1, short y1, short x2, short y2)
  1058.  
  1059. {
  1060.  
  1061.     register GBPTR bp;        /* Buffer pointer */
  1062.  
  1063.     bp = _galloc(sizeof(short) * 4 + 1);
  1064.     *bp++ = op_setcliprgn;
  1065.     *SHORT0P = x1;
  1066.     *SHORT2P = y1;
  1067.     *SHORT4P = x2;
  1068.     *SHORT6P = y2;
  1069.     if(!_gbuff_flag)
  1070.         _gflush();
  1071.     return;
  1072.  
  1073. }
  1074.  
  1075.  
  1076. /*
  1077.  
  1078. _setcolor - _setcolor glue routine 
  1079.  
  1080. */
  1081.  
  1082. short  _setcolor(short c)
  1083.  
  1084. {
  1085.  
  1086.     register GBPTR bp;        /* Buffer pointer */
  1087.  
  1088.     bp = _galloc(sizeof(short) * 2 + 1);
  1089.     *bp++ = op_setcolor;
  1090.     *SHORT0P = c;
  1091.     _gflush();
  1092.     return SHORT2;
  1093.  
  1094. }
  1095.  
  1096.  
  1097. /*
  1098.  
  1099. _setfillmask - _setfillmask glue routine 
  1100.  
  1101. */
  1102.  
  1103. void  _setfillmask(unsigned char *p)
  1104.  
  1105. {
  1106.  
  1107.     register GBPTR bp;        /* Buffer pointer */
  1108.     int i;
  1109.  
  1110.     if(p == NULL)
  1111.     {
  1112.         bp = _galloc(1);
  1113.         *bp++ = op_setnullmask;
  1114.     }
  1115.     else
  1116.     {
  1117.         bp = _galloc(8 + 1);
  1118.         *bp++ = op_setfillmask;
  1119.         for(i = 0; i < 8; ++i)
  1120.             *(bp+i) = *(p+i);
  1121.     }
  1122.     if(!_gbuff_flag)
  1123.         _gflush();
  1124.     return;
  1125.  
  1126. }
  1127.  
  1128.  
  1129. /*
  1130.  
  1131. _setlinestyle - _setlinestyle glue routine 
  1132.  
  1133. */
  1134.  
  1135. void  _setlinestyle(unsigned short m)
  1136.  
  1137. {
  1138.  
  1139.     register GBPTR bp;        /* Buffer pointer */
  1140.  
  1141.     bp = _galloc(sizeof(short) + 1);
  1142.     *bp++ = op_setlinestyle;
  1143.     *SHORT0P = m;
  1144.     if(!_gbuff_flag)
  1145.         _gflush();
  1146.     return;
  1147.  
  1148. }
  1149.  
  1150.  
  1151. /*
  1152.  
  1153. _setlogorg - _setlogorg glue routine 
  1154.  
  1155. */
  1156.  
  1157. struct xycoord  _setlogorg(short x, short y)
  1158.  
  1159. {
  1160.  
  1161.     register GBPTR bp;        /* Buffer pointer */
  1162.     struct xycoord xy;        /* X-Y return value */
  1163.  
  1164.     bp = _galloc(sizeof(short) * 4 + 1);
  1165.     *bp++ = op_setlogorg;
  1166.     *SHORT0P = x;
  1167.     *SHORT2P = y;
  1168.     _gflush();
  1169.     xy.xcoord = SHORT4;
  1170.     xy.ycoord = SHORT6;
  1171.     return xy;
  1172.  
  1173. }
  1174.  
  1175.  
  1176. /*
  1177.  
  1178. _setpixel - _setpixel glue routine 
  1179.  
  1180. */
  1181.  
  1182. short  _setpixel(short x, short y)
  1183.  
  1184. {
  1185.  
  1186.     register GBPTR bp;        /* Buffer pointer */
  1187.  
  1188.     bp = _galloc(sizeof(short) * 3 + 1);
  1189.     *bp++ = op_setpixel;
  1190.     *SHORT0P = x;
  1191.     *SHORT2P = y;
  1192.     _gflush();
  1193.     return SHORT4;
  1194.  
  1195. }
  1196.  
  1197.  
  1198. /*
  1199.  
  1200. _settextcolor - _settextcolor glue routine 
  1201.  
  1202. */
  1203.  
  1204. short  _settextcolor(short c)
  1205.  
  1206. {
  1207.  
  1208.     register GBPTR bp;        /* Buffer pointer */
  1209.  
  1210.     bp = _galloc(sizeof(short) * 2 + 1);
  1211.     *bp++ = op_settextcolor;
  1212.     *SHORT0P = c;
  1213.     _gflush();
  1214.     return SHORT2;
  1215.  
  1216. }
  1217.  
  1218.  
  1219. /*
  1220.  
  1221. _settextposition - _settextposition glue routine 
  1222.  
  1223. */
  1224.  
  1225. struct rccoord  _settextposition(short r, short c)
  1226.  
  1227. {
  1228.  
  1229.     register GBPTR bp;        /* Buffer pointer */
  1230.     struct rccoord rc;        /* X-Y return value */
  1231.  
  1232.     bp = _galloc(sizeof(short) * 4 + 1);
  1233.     *bp++ = op_settextposition;
  1234.     *SHORT0P = r;
  1235.     *SHORT2P = c;
  1236.     _gflush();
  1237.     rc.row = SHORT4;
  1238.     rc.col = SHORT6;
  1239.     return rc;
  1240.  
  1241. }
  1242.  
  1243.  
  1244. /*
  1245.  
  1246. _settextwindow - _settextwindow glue routine 
  1247.  
  1248. */
  1249.  
  1250. void  _settextwindow(short r1, short c1, short r2, short c2)
  1251.  
  1252. {
  1253.  
  1254.     register GBPTR bp;        /* Buffer pointer */
  1255.  
  1256.     bp = _galloc(sizeof(short) * 4 + 1);
  1257.     *bp++ = op_settextwindow;
  1258.     *SHORT0P = r1;
  1259.     *SHORT2P = c1;
  1260.     *SHORT4P = r2;
  1261.     *SHORT6P = c2;
  1262.     if(!_gbuff_flag)
  1263.         _gflush();
  1264.     return;
  1265.     
  1266.  
  1267. }
  1268.  
  1269.  
  1270. /*
  1271.  
  1272. _setvideomode - _setvideomode glue routine
  1273.  
  1274. */
  1275.  
  1276. short  _setvideomode(short mode)
  1277.  
  1278. {
  1279.  
  1280.     register GBPTR bp;        /* Buffer pointer */
  1281.  
  1282.     bp = _galloc(sizeof(short) * 2 + 1);
  1283.     *bp++ = op_setvideomode;
  1284.     *SHORT0P = mode;
  1285.     _gflush();
  1286.     return SHORT2;
  1287.  
  1288. }
  1289.  
  1290.  
  1291. /*
  1292.  
  1293. _setviewport - _setviewport glue routine 
  1294.  
  1295. */
  1296.  
  1297. void  _setviewport(short x1, short y1, short x2, short y2)
  1298.  
  1299. {
  1300.  
  1301.     register GBPTR bp;        /* Buffer pointer */
  1302.  
  1303.     bp = _galloc(sizeof(short) * 4 + 1);
  1304.     *bp++ = op_setviewport;
  1305.     *SHORT0P = x1;
  1306.     *SHORT2P = y1;
  1307.     *SHORT4P = x2;
  1308.     *SHORT6P = y2;
  1309.     if(!_gbuff_flag)
  1310.         _gflush();
  1311.     return;
  1312.  
  1313. }
  1314.  
  1315.  
  1316. /*
  1317.  
  1318. _setvisualpage - _setvisualpage glue routine 
  1319.  
  1320. */
  1321.  
  1322. short  _setvisualpage(short n)
  1323.  
  1324. {
  1325.  
  1326.     register GBPTR bp;        /* Buffer pointer */
  1327.  
  1328.     bp = _galloc(sizeof(short) * 2 + 1);
  1329.     *bp++ = op_setvisualpage;
  1330.     *SHORT0P = n;
  1331.     _gflush();
  1332.     return SHORT2;
  1333.  
  1334. }
  1335.  
  1336.  
  1337. /*
  1338.  
  1339. _wrapon - _wrapon glue routine 
  1340.  
  1341. */
  1342.  
  1343. short _wrapon(short n)
  1344.  
  1345. {
  1346.  
  1347.     register GBPTR bp;        /* Buffer pointer */
  1348.  
  1349.     bp = _galloc(sizeof(short) * 2 + 1);
  1350.     *bp++ = op_wrapon;
  1351.     *SHORT0P = n;
  1352.     _gflush();
  1353.     return SHORT2;
  1354.  
  1355. }
  1356.  
  1357.  
  1358. /*
  1359.  
  1360. kbhit - kbhit glue routine 
  1361.  
  1362. */
  1363.  
  1364. int kbhit(void)
  1365.  
  1366. {
  1367.  
  1368.     register GBPTR bp;        /* Buffer pointer */
  1369.  
  1370.     bp = _galloc(sizeof(short) + 1);
  1371.     *bp++ = op_kbhit;
  1372.     _gflush();
  1373.     return SHORT0;
  1374.  
  1375. }
  1376.  
  1377.  
  1378. /*
  1379.  
  1380. _bios_keybrd - _bios_keybrd glue routine 
  1381.  
  1382. */
  1383.  
  1384. unsigned _bios_keybrd(unsigned n)
  1385.  
  1386. {
  1387.  
  1388.     register GBPTR bp;        /* Buffer pointer */
  1389.  
  1390.     bp = _galloc(sizeof(short) * 2 + 1);
  1391.     *bp++ = op_bios_keybrd;
  1392.     *SHORT0P = n;
  1393.     _gflush();
  1394.     return SHORT2;
  1395.  
  1396. }
  1397.