home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / GDEMO / GGLUE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-23  |  38.3 KB  |  1,903 lines

  1. /* gglue.c - Graphics glue routines */
  2.  
  3. /************************************************************************/
  4. /*    Copyright (C) 1986-1993 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. #include <pharlap.h>
  17. #include "gserver.h"
  18.  
  19. /*
  20.  * Include the Microsoft graphics library definition file.  Before we do
  21.  * this, we will undefine the keywords '__far' and '__huge' so that we will
  22.  * be able to compile the function prototypes with all 32-bit compilers.
  23.  *
  24.  * Also, for MetaWare High C/C++, define '__cdecl' so all the prototypes
  25.  * in graph.h work.
  26.  */
  27. #undef __far
  28. #undef __huge
  29. #define __far
  30. #define __huge
  31. #ifdef __HIGHC__
  32. #define __cdecl
  33. #endif
  34. #ifndef _MSC_VER
  35. #define _MSC_VER 700    /* so __far and __huge don't get defined again */
  36. #endif
  37. #include "graph.h"
  38.  
  39. /*
  40.  * Global data used by the glue code
  41.  */
  42. int _gopenf = 0;    /* Graphics server is open (initialized) flag */
  43. int _gregf = 0;        /* "_gclose" has been registered with "exit" flag */
  44.  
  45. char def_dname[] = "gserver.drv";    /* Default name of the graphics
  46.                        server */
  47. REALPTR _server_func;    /* Real mode FAR address of the graphics server */
  48.             /* function entry point */
  49.  
  50.  
  51. GBPTR _gbuffp;        /* Pointer to the protected mode graphics */
  52.             /* commands buffer */
  53. USHORT _rbuffseg;    /* Real mode segment addr of real mode */
  54.             /* graphics commands buffer */
  55. REALPTR _rbuffp;    /* Real mode FAR ptr to the real mode */
  56.             /* graphics commands buffer */
  57.  
  58. int _gbuff_flag;    /* Buffered mode flag - TRUE = buffered, FALSE =
  59.                unbuffered */
  60.  
  61. REALPTR protpsp;    /* protected mode PSP */
  62.  
  63.  
  64. /*
  65.  * Prototypes for functions in this file
  66.  */
  67. static int _gopen(char *fnp);
  68. #ifdef __WATCOMC__
  69. void _gclose(void);
  70. #else
  71. void __cdecl _gclose(void);
  72. #endif
  73. static GBPTR _galloc(unsigned nbytes);
  74. static void _gflush();
  75.  
  76. /*
  77.  * Prototypes for functions in prot.asm
  78.  * Force C stack-based calling conventions for these.
  79.  */
  80. #ifdef __cplusplus
  81. extern "C" {
  82. #endif
  83. void __STKCALL realexit();
  84. int __STKCALL realload(char *filenamep, REALPTR *server_funcp);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88.  
  89. /*
  90.  
  91. _gopen - Open (initialize) the real mode graphics server
  92.  
  93.     fnp    pointer to name of .EXE file containing real mode graphics
  94.         server program
  95.  
  96. Returns:
  97.     0    if success
  98.     <>0    if error
  99. */
  100. static int _gopen(char *fnp)
  101. {
  102.     int rc;            /* Return code */
  103.     USHORT largest;        /* largest number of page available */
  104.  
  105.     /* Make a quick return if the server is already open */
  106.     if(_gopenf)
  107.         return 0;
  108.  
  109.     /* Allocate real mode graphics commands buffer */
  110.     /* If error terminate program */
  111.     rc = _dx_real_alloc(GBUFF_SIZE / 16, &_rbuffseg, &largest);
  112.     if (rc != 0)
  113.     {
  114.         printf("Can't allocate real mode commands buffer: \
  115. DOS error = %d\n", rc);
  116.         exit(rc);
  117.     }
  118.     RP_SET(_rbuffp, 0, _rbuffseg);
  119.  
  120.     /* Allocate protected mode graphics commands buffer */
  121.     /* If error terminate program */
  122.     _gbuffp = malloc(GBUFF_SIZE);
  123.     if (_gbuffp == NULL)
  124.     {
  125.         printf("Can't allocate protected mode commands buffer\n");
  126.         exit(1);
  127.     }
  128.  
  129.         /* Load and initialize the real mode graphics server */
  130.         /* If there was a load error terminate the program */
  131.         rc = realload(fnp, &_server_func);
  132.         if(rc)
  133.         {
  134.                 printf("Error loading real mode graphics server: %s: ", fnp);
  135.                 switch(rc)
  136.                 {
  137.                 case 2:
  138.                         printf("file not found\n");
  139.                         break;
  140.                 case 5:
  141.                         printf("access denied\n");
  142.                         break;
  143.                 case 8:
  144.                         printf("insufficient memory\n");
  145.                         break;
  146.                 case 10:
  147.                         printf("invalid environment segment\n");
  148.                         break;
  149.                 case 11:
  150.                         printf("invalid file format\n");
  151.                         break;
  152.                 default:
  153.                         printf("error code=%d\n", rc);
  154.                         break;
  155.                 }
  156.                 exit(rc);
  157.         }
  158.  
  159.     /* Mark the protected mode graphics commands buffer empty. */
  160.     *(GBSPTR)_gbuffp = sizeof(short);
  161.  
  162.     /* Start the graphics server in buffered mode. */
  163.     _gbuff_flag = 0;
  164.  
  165.     /* Turn on the open flag */
  166.     _gopenf = 1;
  167.  
  168.     /* Register _gclose to be called at exit time */
  169.     if(!_gregf)
  170.     {
  171.         _gregf = 1;
  172.         atexit(_gclose);
  173.     }
  174.  
  175.     /* Return success */
  176.  
  177.     return 0;
  178. }
  179.  
  180.  
  181. /*
  182.  
  183. _gclose - Close the graphics driver
  184.  
  185.     1).  Any existing commands in the graphics commands buffer
  186.          are executed.
  187.  
  188.     2).  The server is told to exit and it
  189.          does any necessary clean-up operations.
  190.  
  191. */
  192.  
  193. #ifdef __WATCOMC__
  194. void _gclose(void)
  195. #else
  196. void __cdecl _gclose(void)
  197. #endif
  198. {
  199.  
  200.     /* Switch on the current state of the open flag.  This switch
  201.        is required in case we are re-entered due to an abnormal error
  202.        exit from "_gflush" or "realexit". */
  203.  
  204.     switch(_gopenf)
  205.     {
  206.  
  207.     /* First flush any commands in the graphics commands buffer */
  208.     case 1:
  209.         ++_gopenf;
  210.         _gflush();
  211.  
  212.     /* Then tell the real mode code to exit */
  213.     case 2:
  214.         ++_gopenf;
  215.         realexit(protpsp);
  216.         
  217.     /* Then turn off the open flag */
  218.     default:
  219.         _gopenf = 0;
  220.         break;
  221.         
  222.     }
  223.  
  224.     /* free the buffers */
  225.     _dx_real_free(_rbuffseg);
  226.     free(_gbuffp);
  227.  
  228.     /* Return */
  229.     return;
  230.  
  231. }
  232.  
  233.  
  234. /*
  235.  
  236. _gbuffmode - Set video buffering mode
  237.  
  238. This routine is called to change the buffering mode for the graphics commands
  239. buffer.  The routine takes a single argument which is the new mode. A
  240. value of zero means unbuffered and a value of one means buffered.  The
  241. routine returns as a function result the old mode.
  242.  
  243. */
  244.  
  245. int _gbuffmode(int newmode)
  246.  
  247. {
  248.  
  249.     int oldmode;        /* Old buffering mode */
  250.  
  251.     if(!_gopenf)
  252.         _gopen(def_dname);
  253.     oldmode = _gbuff_flag;
  254.     _gbuff_flag = newmode;
  255.     if(!newmode)
  256.         _gflush();
  257.  
  258.     return oldmode;
  259.  
  260. }
  261.  
  262.  
  263. /* 
  264.  
  265. _galloc - Allocate space in the graphics commands buffer
  266.  
  267. This routine is used by the glue routines to allocate space
  268. in the graphics commands buffer.  The caller passes in the number
  269. of bytes that it needs in the graphics commands buffer to hold
  270. a command.  If this number of bytes are available, then the
  271. routine returns immediately with a pointer
  272. into the buffer where the command can be placed.  If the
  273. space is not available, then the real mode server is called to
  274. empty out the buffer in order to make room for the new command.
  275. When the server is all done, this routine returns with a 
  276. pointer to the empty graphics commands buffer.
  277.  
  278. */
  279.  
  280. static GBPTR _galloc(unsigned nbytes)
  281. {
  282.  
  283.     register GBPTR bp;        /* Buffer pointer */
  284.     GBPTR rp;            /* Returned pointer */
  285.  
  286.     /* If the server is not open, then open to the default server */
  287.  
  288.     if(!_gopenf)
  289.         _gopen(def_dname);
  290.  
  291.     /* If the graphics commands buffer does not have enough room for
  292.        the number of bytes requested by the caller, then flush the buffer
  293.        by executing all of the commands in it in order to make room. */
  294.  
  295.     bp = _gbuffp;
  296.     if(SHORT0 + nbytes > GBUFF_SIZE)
  297.         _gflush();
  298.  
  299.     /* Calculate the return pointer for the caller */
  300.  
  301.     rp = bp + SHORT0;
  302.  
  303.     /* Increment the used byte count that is located in the first 2
  304.        bytes of the buffer */
  305.  
  306.     *SHORT0P += nbytes;
  307.  
  308.     /* Return */
  309.  
  310.     return rp;
  311. }
  312.  
  313. /*
  314.  
  315. _gflush - Flush the graphics commands buffer
  316.  
  317. This routine is called to flush the graphics commands buffer.  If
  318. the buffer is not empty, then this routine calls the real mode
  319. server to execute all of the commands in the buffer.  The buffer
  320. is then marked as empty.
  321.  
  322. */
  323.  
  324. static void _gflush()
  325.  
  326. {
  327.  
  328.     register GBPTR bp;        /* Buffer pointer */
  329.     RMC_BLK rm_regs = {0};        /* Real mode register values for call*/
  330.  
  331.     /* If the server is not open, then return */
  332.     if(!_gopenf)
  333.         return;
  334.  
  335.     /* If the prot mode commands buffer is not empty, then (1) copy the 
  336.        buffer to the real mode commands buffer, (2) call the real mode
  337.        server to execute the graphics commands in the buffer, and (3)
  338.        copy the real mode buffer back again to get anything returned
  339.        by the call. */
  340.     bp = _gbuffp;
  341.     if(SHORT0 > sizeof(short))
  342.     {
  343.         WriteRealMem(_rbuffp, _gbuffp, GBUFF_SIZE);
  344.         _dx_call_real(_server_func, &rm_regs, 2, _rbuffp);
  345.         ReadRealMem(_gbuffp, _rbuffp, GBUFF_SIZE);
  346.     }
  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.     *SHORT0P = sizeof(short);
  351.  
  352. }
  353.  
  354. /*
  355. _arc - _arc glue routine 
  356. */
  357. short  __cdecl _arc(short x1, short y1, short x2, short y2,
  358.                short x3, short y3, short x4, short y4)
  359. {
  360.     register GBPTR bp;        /* Buffer pointer */
  361.  
  362.     bp = _galloc(sizeof(short) * 9 + 1);
  363.     *bp++ = op_arc;
  364.     *SHORT0P = x1;
  365.     *SHORT2P = y1;
  366.     *SHORT4P = x2;
  367.     *SHORT6P = y2;
  368.     *SHORT8P = x3;
  369.     *SHORT10P = y3;
  370.     *SHORT12P = x4;
  371.     *SHORT14P = y4;
  372.     if(!_gbuff_flag)
  373.     {
  374.         _gflush();
  375.         return SHORT16;
  376.     }
  377.     return 1;
  378. }
  379.  
  380. /*
  381. _arc_w - _arc_w glue routine 
  382. */
  383. short  __cdecl _arc_w(double x1, double y1, double x2, double y2,
  384.                double x3, double y3, double x4, double y4)
  385. {
  386.  
  387.     register GBPTR bp;        /* Buffer pointer */
  388.  
  389.     bp = _galloc(sizeof(double) * 8 + sizeof(short) + 1);
  390.     *bp++ = op_arc_w;
  391.     *DOUBL0P = x1;
  392.     *DOUBL8P = y1;
  393.     *DOUBL16P = x2;
  394.     *DOUBL24P = y2;
  395.     *DOUBL32P = x3;
  396.     *DOUBL40P = y3;
  397.     *DOUBL48P = x4;
  398.     *DOUBL56P = y4;
  399.     if(!_gbuff_flag)
  400.     {
  401.         _gflush();
  402.         return SHORT64;
  403.     }
  404.     return 1;
  405. }
  406.  
  407. /*
  408. _arc_wxy - _arc_wxy glue routine 
  409. */
  410. short  __cdecl _arc_wxy(const struct _wxycoord *pwxy1, const struct _wxycoord *pwxy2,
  411.         const struct _wxycoord *pwxy3, const struct _wxycoord *pwxy4)
  412. {
  413.  
  414.     register GBPTR bp;        /* Buffer pointer */
  415.  
  416.     bp = _galloc(sizeof(struct _wxycoord) * 4 + sizeof(short) + 1);
  417.     *bp++ = op_arc_wxy;
  418.     *DOUBL0P = pwxy1->wx;
  419.     *DOUBL8P = pwxy1->wy;
  420.     *DOUBL16P = pwxy2->wx;
  421.     *DOUBL24P = pwxy2->wy;
  422.     *DOUBL32P = pwxy3->wx;
  423.     *DOUBL40P = pwxy3->wy;
  424.     *DOUBL48P = pwxy4->wx;
  425.     *DOUBL56P = pwxy4->wy;
  426.     if(!_gbuff_flag)
  427.     {
  428.         _gflush();
  429.         return SHORT64;
  430.     }
  431.     return 1;
  432. }
  433.  
  434. /*
  435. _clearscreen - _clearscreen glue routine
  436. */
  437. void  __cdecl _clearscreen(short area)
  438. {
  439.     register GBPTR bp;
  440.  
  441.     bp = _galloc(sizeof(short) + 1);
  442.     *bp++ = op_clearscreen;
  443.     *SHORT0P = area;
  444.     if(!_gbuff_flag)
  445.         _gflush();
  446.     return;
  447. }
  448.  
  449. /*
  450. _displaycursor - _displaycursor glue routine 
  451. */
  452. short  __cdecl _displaycursor(short n)
  453. {
  454.     register GBPTR bp;        /* Buffer pointer */
  455.  
  456.     bp = _galloc(sizeof(short) * 2 + 1);
  457.     *bp++ = op_displaycursor;
  458.     *SHORT0P = n;
  459.     _gflush();
  460.     return SHORT2;
  461. }
  462.  
  463.  
  464. /*
  465. _ellipse - _ellipse glue routine 
  466. */
  467. short  __cdecl _ellipse(short c, short x1, short y1, short x2, short y2)
  468. {
  469.  
  470.     register GBPTR bp;        /* Buffer pointer */
  471.  
  472.     bp = _galloc(sizeof(short) * 6 + 1);
  473.     *bp++ = op_ellipse;
  474.     *SHORT0P = c;
  475.     *SHORT2P = x1;
  476.     *SHORT4P = y1;
  477.     *SHORT6P = x2;
  478.     *SHORT8P = y2;
  479.     if(!_gbuff_flag)
  480.     {
  481.         _gflush();
  482.         return SHORT10;
  483.     }
  484.     return 1;
  485. }
  486.  
  487. /*
  488. _ellipse_w - _ellipse_w glue routine 
  489. */
  490. short  __cdecl _ellipse_w(short c, double x1, double y1, double x2, double y2)
  491. {
  492.     register GBPTR bp;        /* Buffer pointer */
  493.  
  494.     bp = _galloc(sizeof(double) * 4 + sizeof(short) * 2 + 1);
  495.     *bp++ = op_ellipse_w;
  496.     *SHORT0P = c;
  497.     *DOUBL2P = x1;
  498.     *DOUBL10P = y1;
  499.     *DOUBL18P = x2;
  500.     *DOUBL26P = y2;
  501.     if(!_gbuff_flag)
  502.     {
  503.         _gflush();
  504.         return SHORT34;
  505.     }
  506.     return 1;
  507. }
  508.  
  509. /*
  510. _ellipse_wxy - _ellipse_wxy glue routine 
  511. */
  512. short  __cdecl _ellipse_wxy(short c, const struct _wxycoord *pwxy1, 
  513.                 const struct _wxycoord *pwxy2)
  514. {
  515.     register GBPTR bp;        /* Buffer pointer */
  516.  
  517.     bp = _galloc(sizeof(struct _wxycoord) * 2 + sizeof(short) * 2 + 1);
  518.     *bp++ = op_ellipse_wxy;
  519.     *SHORT0P = c;
  520.     *DOUBL2P = pwxy1->wx;
  521.     *DOUBL10P = pwxy1->wy;
  522.     *DOUBL18P = pwxy2->wx;
  523.     *DOUBL26P = pwxy2->wy;
  524.     if(!_gbuff_flag)
  525.     {
  526.         _gflush();
  527.         return SHORT34;
  528.     }
  529.     return 1;
  530. }
  531.  
  532. /*
  533. _floodfill - _floodfill glue routine 
  534. */
  535. short  __cdecl _floodfill(short x, short y, short b)
  536. {
  537.     register GBPTR bp;        /* Buffer pointer */
  538.  
  539.     bp = _galloc(sizeof(short) * 4 + 1);
  540.     *bp++ = op_floodfill;
  541.     *SHORT0P = x;
  542.     *SHORT2P = y;
  543.     *SHORT4P = b;
  544.     if(!_gbuff_flag)
  545.     {
  546.         _gflush();
  547.         return SHORT6;
  548.     }
  549.     return 1;
  550. }
  551.  
  552. /*
  553. _floodfill_w - _floodfill_w glue routine 
  554. */
  555. short  __cdecl _floodfill_w(double x, double y, short b)
  556. {
  557.     register GBPTR bp;        /* Buffer pointer */
  558.  
  559.     bp = _galloc(sizeof(double) * 2 + sizeof(short) + 1);
  560.     *bp++ = op_floodfill;
  561.     *DOUBL0P = x;
  562.     *DOUBL8P = y;
  563.     *SHORT16P = b;
  564.     if(!_gbuff_flag)
  565.     {
  566.         _gflush();
  567.         return SHORT18;
  568.     }
  569.     return 1;
  570. }
  571.  
  572.  
  573. /*
  574. _fmoveto - Fast _moveto glue routine (buffered)
  575. */
  576. void _fmoveto(short x, short y)
  577. {
  578.     register GBPTR bp;        /* Buffer pointer */
  579.  
  580.     bp = _galloc(sizeof(short) * 4 + 1);
  581.     *bp++ = op_moveto;
  582.     *SHORT0P = x;
  583.     *SHORT2P = y;
  584.     if(!_gbuff_flag)
  585.         _gflush();
  586.     return;
  587. }
  588.  
  589. /*
  590. _getactivepage - _getactivepage glue routine 
  591. */
  592. short  __cdecl _getactivepage(void)
  593. {
  594.  
  595.     register GBPTR bp;        /* Buffer pointer */
  596.  
  597.     bp = _galloc(sizeof(short) + 1);
  598.     *bp++ = op_getactivepage;
  599.     _gflush();
  600.     return SHORT0;
  601. }
  602.  
  603. /*
  604. _getarcinfo - _getarcinfo glue routine 
  605. */
  606. short  __cdecl _getarcinfo(struct _xycoord *start, struct _xycoord *end,
  607.         struct _xycoord *fill)
  608. {
  609.     register GBPTR bp;        /* Buffer pointer */
  610.  
  611.     bp = _galloc(sizeof(struct _xycoord) * 3 + sizeof(short) + 1);
  612.     *bp++ = op_getarcinfo;
  613.     *SHORT0P = start->xcoord;
  614.     *SHORT2P = start->ycoord;
  615.     *SHORT4P = end->xcoord;
  616.     *SHORT6P = end->ycoord;
  617.     *SHORT8P = fill->xcoord;
  618.     *SHORT10P = fill->ycoord;
  619.     if(!_gbuff_flag)
  620.     {
  621.         _gflush();
  622.         return SHORT12;
  623.     }
  624.     return 1;
  625. }
  626.  
  627.  
  628. /*
  629. _getbkcolor - _getbkcolor glue routine 
  630. */
  631. long  __cdecl _getbkcolor(void)
  632. {
  633.     register GBPTR bp;        /* Buffer pointer */
  634.  
  635.     bp = _galloc(sizeof(long) + 1);
  636.     *bp++ = op_getbkcolor;
  637.     _gflush();
  638.     return LONG0;
  639. }
  640.  
  641. /*
  642. _getcolor - _getcolor glue routine 
  643. */
  644. short  __cdecl _getcolor(void)
  645. {
  646.     register GBPTR bp;        /* Buffer pointer */
  647.  
  648.     bp = _galloc(sizeof(short) * 1 + 1);
  649.     *bp++ = op_getcolor;
  650.     _gflush();
  651.     return SHORT0;
  652. }
  653.  
  654. /*
  655. _getcurrentposition - _getcurrentposition glue routine 
  656. */
  657. struct _xycoord  __cdecl _getcurrentposition(void)
  658. {
  659.     register GBPTR bp;        /* Buffer pointer */
  660.     struct _xycoord xy;        /* X-Y return value */
  661.  
  662.     bp = _galloc(sizeof(short) * 2 + 1);
  663.     *bp++ = op_getcurrentposition;
  664.     _gflush();
  665.     xy.xcoord = SHORT0;
  666.     xy.ycoord = SHORT2;
  667.     return xy;
  668. }
  669.  
  670. /*
  671. _getcurrentposition_w - _getcurrentposition_w glue routine 
  672. */
  673. struct _wxycoord  __cdecl _getcurrentposition_w(void)
  674. {
  675.     register GBPTR bp;        /* Buffer pointer */
  676.     struct _wxycoord xy;        /* X-Y return value */
  677.  
  678.     bp = _galloc(sizeof(short) * 2 + 1);
  679.     *bp++ = op_getcurrentposition_w;
  680.     _gflush();
  681.     xy.wx = DOUBL0;
  682.     xy.wy = DOUBL8;
  683.     return xy;
  684. }
  685.  
  686. /*
  687. _getfillmask - _getfillmask glue routine 
  688. */
  689. unsigned char * __cdecl _getfillmask(register unsigned char *mp)
  690. {
  691.     register GBPTR bp;        /* Buffer pointer */
  692.     int i;                /* Loop counter */
  693.  
  694.     bp = _galloc(sizeof(short) + 8 + 1);
  695.     *bp++ = op_getfillmask;
  696.     _gflush();
  697.     if(!SHORT8)
  698.         return NULL;
  699.     for(i = 0; i < 8; ++i)
  700.         *mp++ = *bp++;
  701.     return mp - 8;
  702. }
  703.  
  704.  
  705. /*
  706. _getfontinfo - _getfontinfo glue routine 
  707. */
  708. short   __cdecl _getfontinfo(struct _fontinfo *fontbuffer)
  709. {
  710.     register GBPTR bp;        /* Buffer pointer */
  711.  
  712.     bp = _galloc(sizeof(struct _fontinfo) + sizeof(short) + 1);
  713.     *bp++ = op_getfontinfo;
  714.     _gflush();
  715.     fontbuffer->type = ((struct _fontinfo *) bp)->type;
  716.     fontbuffer->ascent = ((struct _fontinfo *) (bp + 2))->ascent;
  717.     fontbuffer->pixwidth = ((struct _fontinfo *) (bp + 4))->pixwidth;
  718.     fontbuffer->pixheight = ((struct _fontinfo *) (bp + 6))->pixheight;
  719.     fontbuffer->avgwidth = ((struct _fontinfo *) (bp + 8))->avgwidth;
  720.     strcpy(fontbuffer->filename , ((struct _fontinfo *)(bp + 10))->filename);
  721.     strcpy(fontbuffer->facename , ((struct _fontinfo *)bp)->facename);
  722.     return SHORT124;
  723. }
  724.  
  725. /*
  726. _getgtextextent - _getgtextextent glue routine 
  727. */
  728. short   __cdecl _getgtextextent(const char *text)
  729. {
  730.     register GBPTR bp;    /* Buffer pointer */
  731.     int n;            /* String length */
  732.     int cc;            /* Cycle count */
  733.     int i;            /* Buffer copy count */
  734.     int ret;        /* return value */
  735.  
  736.     ret = 0;
  737.     n = strlen(text);
  738.     while(n)
  739.     {
  740.         cc = n;
  741.         if(cc > GBUFF_SIZE - 4)
  742.             cc = GBUFF_SIZE - 4;
  743.         bp = _galloc(cc + 4);
  744.         *bp++ = op_getgtextextent;
  745.         for(i = 0; i < cc; ++i)
  746.             *(bp+i) = *(text+i);
  747.         *(bp + cc) = 0;
  748.         n -= cc;
  749.         _gflush();
  750.         ret += *(short *)(bp + cc + 1);
  751.     }
  752.     return ret;
  753. }
  754.  
  755. /*
  756. _getgtextvector - _getgtextvector glue routine 
  757. */
  758. struct _xycoord   __cdecl _getgtextvector(void)
  759. {
  760.     register GBPTR bp;        /* Buffer pointer */
  761.     struct _xycoord xy;        /* X-Y return value */
  762.  
  763.     bp = _galloc(sizeof(short) * 2 + 1);
  764.     *bp++ = op_getgtextvector;
  765.     _gflush();
  766.     xy.xcoord = SHORT0;
  767.     xy.ycoord = SHORT2;
  768.     return xy;
  769. }
  770.  
  771. /*
  772. _getlinestyle - _getlinestyle glue routine 
  773. */
  774. unsigned short   __cdecl _getlinestyle(void)
  775. {
  776.  
  777.     register GBPTR bp;        /* Buffer pointer */
  778.  
  779.     bp = _galloc(sizeof(short) * 1 + 1);
  780.     *bp++ = op_getlinestyle;
  781.     _gflush();
  782.     return (unsigned short)SHORT0;
  783.  
  784. }
  785.  
  786. /*
  787. _getphyscoord - _getphyscoord glue routine 
  788. */
  789. struct _xycoord   __cdecl _getphyscoord(short x, short y)
  790. {
  791.     register GBPTR bp;        /* Buffer pointer */
  792.     struct _xycoord xy;        /* X-Y return value */
  793.  
  794.     bp = _galloc(sizeof(short) * 4 + 1);
  795.     *bp++ = op_getphyscoord;
  796.     *SHORT0P = x;
  797.     *SHORT2P = y;
  798.     _gflush();
  799.     xy.xcoord = SHORT4;
  800.     xy.ycoord = SHORT6;
  801.     return xy;
  802. }
  803.  
  804. /*
  805. _getpixel - _getpixel glue routine
  806. */
  807. short   __cdecl _getpixel(short x, short y)
  808. {
  809.     register GBPTR bp;
  810.  
  811.     bp = _galloc(sizeof(short) * 3 + 1);
  812.     *bp++ = op_getpixel;
  813.     *SHORT0P = x;
  814.     *SHORT2P = y;
  815.     _gflush();
  816.     return SHORT4;
  817. }
  818.  
  819. /*
  820. _getpixel_w - _getpixel_w glue routine
  821. */
  822. short   __cdecl _getpixel_w(double wx, double wy)
  823. {
  824.     register GBPTR bp;
  825.  
  826.     bp = _galloc(sizeof(double) * 2 + sizeof(short) + 1);
  827.     *bp++ = op_getpixel_w;
  828.     *DOUBL0P = wx;
  829.     *DOUBL8P = wy;
  830.     _gflush();
  831.     return SHORT16;
  832. }
  833.  
  834. /*
  835. _gettextcolor - _gettextcolor glue routine 
  836. */
  837. short   __cdecl _gettextcolor(void)
  838. {
  839.     register GBPTR bp;        /* Buffer pointer */
  840.  
  841.     bp = _galloc(sizeof(short) * 1 + 1);
  842.     *bp++ = op_gettextcolor;
  843.     _gflush();
  844.     return SHORT0;
  845. }
  846.  
  847. /*
  848. _gettextcursor - _gettextcursor glue routine 
  849. */
  850. short   __cdecl _gettextcursor(void)
  851. {
  852.     register GBPTR bp;        /* Buffer pointer */
  853.  
  854.     bp = _galloc(sizeof(short) * 1 + 1);
  855.     *bp++ = op_gettextcursor;
  856.     _gflush();
  857.     return SHORT0;
  858. }
  859.  
  860. /*
  861. _gettextposition - _gettextposition glue routine 
  862. */
  863. struct _rccoord   __cdecl _gettextposition(void)
  864. {
  865.     register GBPTR bp;        /* Buffer pointer */
  866.     struct _rccoord rc;        /* Row/column structure */
  867.  
  868.     bp = _galloc(sizeof(short) * 2 + 1);
  869.     *bp++ = op_gettextposition;
  870.     _gflush();
  871.     rc.row = SHORT0;
  872.     rc.col = SHORT2;
  873.     return rc;
  874. }
  875.  
  876. /*
  877. _getvideoconfig - _getvideoconfig glue routine 
  878. */
  879. struct _videoconfig * __cdecl _getvideoconfig(struct _videoconfig *p)
  880. {
  881.     register GBPTR bp;        /* Buffer pointer */
  882.  
  883.     bp = _galloc(sizeof(short) * 11 + 1);
  884.     *bp++ = op_getvideoconfig;
  885.     _gflush();
  886.     p->numxpixels = SHORT0;
  887.     p->numypixels = SHORT2;
  888.     p->numtextcols = SHORT4;
  889.     p->numtextrows = SHORT6;
  890.     p->numcolors = SHORT8;
  891.     p->bitsperpixel = SHORT10;
  892.     p->numvideopages = SHORT12;
  893.     p->mode = SHORT14;
  894.     p->adapter = SHORT16;
  895.     p->monitor = SHORT18;
  896.     p->memory = SHORT20;
  897.     return p;
  898. }
  899.  
  900. /*
  901. _gettextwindow - _gettextwindow glue routine
  902. */
  903. void   __cdecl _gettextwindow(short *r1, short *c1, short *r2, short *c2)
  904. {
  905.     register GBPTR bp;
  906.  
  907.     bp = _galloc(sizeof(short) * 4 + 1);
  908.     *bp++ = op_gettextwindow;
  909.     if(!_gbuff_flag)
  910.         _gflush();
  911.     *r1 = SHORT0;
  912.     *c1 = SHORT2;
  913.     *r2 = SHORT4;
  914.     *c2 = SHORT6;
  915.     
  916.  
  917.     return;
  918. }
  919.  
  920. /*
  921. _getviewcoord - _getviewcoord glue routine 
  922. */
  923.  
  924. struct _xycoord   __cdecl _getviewcoord(short x, short y)
  925. {
  926.     register GBPTR bp;        /* Buffer pointer */
  927.     struct _xycoord xy;        /* X-Y return value */
  928.  
  929.     bp = _galloc(sizeof(short) * 4 + 1);
  930.     *bp++ = op_getviewcoord;
  931.     *SHORT0P = x;
  932.     *SHORT2P = y;
  933.     _gflush();
  934.     xy.xcoord = SHORT4;
  935.     xy.ycoord = SHORT6;
  936.     return xy;
  937. }
  938.  
  939. /*
  940. _getviewcoord_w - _getviewcoord_w glue routine 
  941. */
  942. struct _xycoord   __cdecl _getviewcoord_w(double wx, double wy)
  943. {
  944.     register GBPTR bp;        /* Buffer pointer */
  945.     struct _xycoord xy;        /* X-Y return value */
  946.  
  947.     bp = _galloc(sizeof(short) * 2 + sizeof(double) * 2 + 1);
  948.     *bp++ = op_getviewcoord_w;
  949.     *DOUBL0P = wx;
  950.     *DOUBL8P = wy;
  951.     _gflush();
  952.     xy.xcoord = SHORT16;
  953.     xy.ycoord = SHORT18;
  954.     return xy;
  955. }
  956.  
  957. /*
  958. _getviewcoord_wxy - _getviewcoord_wxy glue routine 
  959. */
  960. struct _xycoord   __cdecl _getviewcoord_wxy(const struct _wxycoord *pwxy1)
  961. {
  962.     register GBPTR bp;        /* Buffer pointer */
  963.     struct _xycoord xy;        /* X-Y return value */
  964.  
  965.     bp = _galloc(sizeof(short) * 2 + sizeof(double) * 2 + 1);
  966.     *bp++ = op_getviewcoord_wxy;
  967.     *DOUBL0P = pwxy1->wx;
  968.     *DOUBL8P = pwxy1->wy;
  969.     _gflush();
  970.     xy.xcoord = SHORT16;
  971.     xy.ycoord = SHORT18;
  972.     return xy;
  973. }
  974.  
  975. /*
  976. _getvisualpage - _getvisualpage glue routine 
  977. */
  978. short   __cdecl _getvisualpage(void)
  979. {
  980.     register GBPTR bp;        /* Buffer pointer */
  981.  
  982.     bp = _galloc(sizeof(short) * 1 + 1);
  983.     *bp++ = op_getvisualpage;
  984.     _gflush();
  985.     return SHORT0;
  986. }
  987.  
  988. /*
  989. _getwindowcoord - _getwindowcoord glue routine 
  990. */
  991.  
  992. struct _wxycoord  __cdecl _getwindowcoord(short x, short y)
  993. {
  994.     register GBPTR bp;        /* Buffer pointer */
  995.     struct _wxycoord wxy;        /* X-Y return value */
  996.  
  997.     bp = _galloc(sizeof(short) * 4 + 1);
  998.     *bp++ = op_getwindowcoord;
  999.     *SHORT0P = x;
  1000.     *SHORT2P = y;
  1001.     _gflush();
  1002.     wxy.wx = DOUBL4;
  1003.     wxy.wy = DOUBL12;
  1004.     return wxy;
  1005. }
  1006.  
  1007. /*
  1008. _getwritemode - _getwritemode glue routine 
  1009. */
  1010. short   __cdecl _getwritemode(void)
  1011. {
  1012.     register GBPTR bp;        /* Buffer pointer */
  1013.  
  1014.     bp = _galloc(sizeof(short) * 1 + 1);
  1015.     *bp++ = op_getwritemode;
  1016.     _gflush();
  1017.     return SHORT0;
  1018. }
  1019.  
  1020. /*
  1021. _grstatus - _grstatus glue routine 
  1022. */
  1023. short   __cdecl _grstatus(void)
  1024. {
  1025.     register GBPTR bp;        /* Buffer pointer */
  1026.  
  1027.     bp = _galloc(sizeof(short) + 1);
  1028.     *bp++ = op_grstatus;
  1029.     _gflush();
  1030.     return SHORT0;
  1031. }
  1032.  
  1033. /*
  1034. _imagesize - _imagesize glue routine 
  1035. */
  1036. long   __cdecl _imagesize(short x1, short y1, short x2, short y2)
  1037. {
  1038.     register GBPTR bp;        /* Buffer pointer */
  1039.  
  1040.     bp = _galloc(sizeof(short) * 4 + sizeof(long) + 1);
  1041.     *bp++ = op_imagesize;
  1042.     *SHORT0P = x1;
  1043.     *SHORT2P = y1;
  1044.     *SHORT4P = x2;
  1045.     *SHORT6P = y2;
  1046.     _gflush();
  1047.     return LONG8;
  1048. }
  1049.  
  1050. /*
  1051. _imagesize_w - _imagesize_w glue routine 
  1052. */
  1053. long   __cdecl _imagesize_w(double x1, double y1, double x2, double y2)
  1054. {
  1055.     register GBPTR bp;        /* Buffer pointer */
  1056.  
  1057.     bp = _galloc(sizeof(double) * 4 + sizeof(long) + 1);
  1058.     *bp++ = op_imagesize_w;
  1059.     *DOUBL0P = x1;
  1060.     *DOUBL8P = y1;
  1061.     *DOUBL16P = x2;
  1062.     *DOUBL24P = y2;
  1063.     _gflush();
  1064.     return LONG32;
  1065. }
  1066.  
  1067. /*
  1068. _imagesize_wxy - _imagesize_wxy glue routine 
  1069. */
  1070. long   __cdecl _imagesize_wxy(const struct _wxycoord *pwxy1 ,
  1071.                 const struct _wxycoord *pwxy2)
  1072. {
  1073.     register GBPTR bp;        /* Buffer pointer */
  1074.  
  1075.     bp = _galloc(sizeof(double) * 4 + sizeof(long) + 1);
  1076.     *bp++ = op_imagesize_wxy;
  1077.     *DOUBL0P = pwxy1->wx;
  1078.     *DOUBL8P = pwxy1->wy;
  1079.     *DOUBL16P = pwxy2->wx;
  1080.     *DOUBL24P = pwxy2->wy;
  1081.     _gflush();
  1082.     return LONG32;
  1083. }
  1084.  
  1085. /*
  1086. _inchar - _inchar glue routine
  1087. */
  1088.  
  1089. short   __cdecl _inchar(void)
  1090. {
  1091.     register GBPTR bp;        /* Buffer pointer */
  1092.  
  1093.     bp = _galloc(sizeof(short) + 1);
  1094.     *bp++ = op_inchar;
  1095.     _gflush();
  1096.     return SHORT0;
  1097. }
  1098.  
  1099.  
  1100. /*
  1101. _lineto - _lineto glue routine
  1102. */
  1103. short   __cdecl _lineto(short x, short y)
  1104. {
  1105.     register GBPTR bp;
  1106.  
  1107.     bp = _galloc(sizeof(short) * 3 + 1);
  1108.     *bp++ = op_lineto;
  1109.     *SHORT0P = x;
  1110.     *SHORT2P = y;
  1111.     if(!_gbuff_flag)
  1112.     {
  1113.         _gflush();
  1114.         return SHORT4;
  1115.     }
  1116.     return 1;
  1117. }
  1118.  
  1119. /*
  1120. _lineto_w - _lineto_w glue routine
  1121. */
  1122. short   __cdecl _lineto_w(double x, double y)
  1123. {
  1124.     register GBPTR bp;
  1125.  
  1126.     bp = _galloc(sizeof(double) * 2 + sizeof(short) + 1);
  1127.     *bp++ = op_lineto_w;
  1128.     *DOUBL0P = x;
  1129.     *DOUBL8P = y;
  1130.     if(!_gbuff_flag)
  1131.     {
  1132.         _gflush();
  1133.         return SHORT16;
  1134.     }
  1135.     return 1;
  1136. }
  1137.  
  1138. /*
  1139. _moveto - _moveto glue routine
  1140. */
  1141. struct _xycoord   __cdecl _moveto(short x, short y)
  1142. {
  1143.     register GBPTR bp;        /* Buffer pointer */
  1144.     struct _xycoord ppnt;        /* Previous point */
  1145.  
  1146.     bp = _galloc(sizeof(short) * 3 + 1);
  1147.     *bp++ = op_moveto;
  1148.     *SHORT0P = x;
  1149.     *SHORT2P = y;
  1150.     _gflush();
  1151.     ppnt.xcoord= SHORT4;
  1152.     ppnt.ycoord = SHORT6;
  1153.     return ppnt;
  1154. }
  1155.  
  1156. /*
  1157. _moveto_w - _moveto_w glue routine
  1158. */
  1159. struct _wxycoord   __cdecl _moveto_w(double wx, double wy)
  1160. {
  1161.     register GBPTR bp;        /* Buffer pointer */
  1162.     struct _wxycoord ppnt;        /* Previous point */
  1163.  
  1164.     bp = _galloc(sizeof(double) * 3 + 1);
  1165.     *bp++ = op_moveto_w;
  1166.     *DOUBL0P = wx;
  1167.     *DOUBL8P = wy;
  1168.     _gflush();
  1169.     ppnt.wx= DOUBL16;
  1170.     ppnt.wy= DOUBL24;
  1171.     return ppnt;
  1172. }
  1173.  
  1174. /*
  1175. _outgtext - _outgtext glue routine 
  1176. */
  1177. void   __cdecl _outgtext(const char *p)
  1178. {
  1179.     register GBPTR bp;    /* Buffer pointer */
  1180.     int n;            /* String length */
  1181.     int cc;            /* Cycle count */
  1182.     int i;            /* Buffer copy count */
  1183.  
  1184.     n = strlen(p);
  1185.     while(1)
  1186.     {
  1187.         cc = n;
  1188.         if(cc > GBUFF_SIZE - 2)
  1189.             cc = GBUFF_SIZE - 2;
  1190.         bp = _galloc(cc + 2);
  1191.         *bp++ = op_outgtext;
  1192.         for(i = 0; i < cc; ++i)
  1193.             *(bp+i) = *(p+i);
  1194.         *(bp + cc) = 0;
  1195.         n -= cc;
  1196.         if(n == 0)
  1197.             break;
  1198.         _gflush();
  1199.     }
  1200. }
  1201.  
  1202. /*
  1203. _outmem - _outmem glue routine 
  1204. */
  1205. void   __cdecl _outmem(const char *p, short len)
  1206. {
  1207.     register GBPTR bp;    /* Buffer pointer */
  1208.     int cc;            /* Cycle count */
  1209.     int i;            /* Buffer copy count */
  1210.  
  1211.     while(1)
  1212.     {
  1213.         cc = len;
  1214.         if(cc > GBUFF_SIZE - 2)
  1215.             cc = GBUFF_SIZE - 2;
  1216.         bp = _galloc(cc + 2);
  1217.         *bp++ = op_outmem;
  1218.         for(i = 0; i < cc; ++i)
  1219.             *(bp+i) = *(p+i);
  1220.         *(bp + cc) = 0;
  1221.         len -= cc;
  1222.         if(len == 0)
  1223.             break;
  1224.         _gflush();
  1225.     }
  1226. }
  1227.  
  1228. /*
  1229. _outtext - _outtext glue routine 
  1230. */
  1231. void   __cdecl _outtext(const char *p)
  1232. {
  1233.     register GBPTR bp;    /* Buffer pointer */
  1234.     int n;            /* String length */
  1235.     int cc;            /* Cycle count */
  1236.     int i;            /* Buffer copy count */
  1237.  
  1238.     n = strlen(p);
  1239.     while(1)
  1240.     {
  1241.         cc = n;
  1242.         if(cc > GBUFF_SIZE - 2)
  1243.             cc = GBUFF_SIZE - 2;
  1244.         bp = _galloc(cc + 2);
  1245.         *bp++ = op_outtext;
  1246.         for(i = 0; i < cc; ++i)
  1247.             *(bp+i) = *(p+i);
  1248.         *(bp + cc) = 0;
  1249.         n -= cc;
  1250.         if(n == 0)
  1251.             break;
  1252.     }
  1253.     _gflush();
  1254.     return;
  1255. }
  1256.  
  1257. /*
  1258. _pie - _pie glue routine 
  1259. */
  1260. short   __cdecl _pie(short c, short x1, short y1, short x2, short y2,
  1261.                short x3, short y3, short x4, short y4)
  1262. {
  1263.     register GBPTR bp;        /* Buffer pointer */
  1264.  
  1265.     bp = _galloc(sizeof(short) * 10 + 1);
  1266.     *bp++ = op_pie;
  1267.     *SHORT0P = c;
  1268.     *SHORT2P = x1;
  1269.     *SHORT4P = y1;
  1270.     *SHORT6P = x2;
  1271.     *SHORT8P = y2;
  1272.     *SHORT10P = x3;
  1273.     *SHORT12P = y3;
  1274.     *SHORT14P = x4;
  1275.     *SHORT16P = y4;
  1276.     if(!_gbuff_flag)
  1277.     {
  1278.         _gflush();
  1279.         return SHORT18;
  1280.     }
  1281.     return 1;
  1282. }
  1283.  
  1284. /*
  1285. _pie_w - _pie_w glue routine 
  1286. */
  1287. short   __cdecl _pie_w(short c, double x1, double y1, double x2, double y2,
  1288.                double x3, double y3, double x4, double y4)
  1289. {
  1290.     register GBPTR bp;        /* Buffer pointer */
  1291.  
  1292.     bp = _galloc(sizeof(short) * 2 + sizeof(double) * 8 + 1);
  1293.     *bp++ = op_pie_w;
  1294.     *SHORT0P = c;
  1295.     *DOUBL2P = x1;
  1296.     *DOUBL10P = y1;
  1297.     *DOUBL18P = x2;
  1298.     *DOUBL26P = y2;
  1299.     *DOUBL34P = x3;
  1300.     *DOUBL42P = y3;
  1301.     *DOUBL50P = x4;
  1302.     *DOUBL58P = y4;
  1303.     if(!_gbuff_flag)
  1304.     {
  1305.         _gflush();
  1306.         return SHORT66;
  1307.     }
  1308.     return 1;
  1309. }
  1310.  
  1311. /*
  1312. _pie_wxy - _pie_wxy glue routine 
  1313. */
  1314. short   __cdecl _pie_wxy(short c, const struct _wxycoord *pwxy1, 
  1315.     const struct _wxycoord *pwxy2, const struct _wxycoord *pwxy3, 
  1316.     const struct _wxycoord *pwxy4)
  1317. {
  1318.     register GBPTR bp;        /* Buffer pointer */
  1319.  
  1320.     bp = _galloc(sizeof(short) * 2 + sizeof(double) * 8 + 1);
  1321.     *bp++ = op_pie_wxy;
  1322.     *SHORT0P = c;
  1323.     *DOUBL2P = pwxy1->wx;
  1324.     *DOUBL10P = pwxy1->wy;
  1325.     *DOUBL18P = pwxy2->wx;
  1326.     *DOUBL26P = pwxy2->wy;
  1327.     *DOUBL34P = pwxy3->wx;
  1328.     *DOUBL42P = pwxy3->wy;
  1329.     *DOUBL50P = pwxy4->wx;
  1330.     *DOUBL58P = pwxy4->wy;
  1331.     if(!_gbuff_flag)
  1332.     {
  1333.         _gflush();
  1334.         return SHORT66;
  1335.     }
  1336.     return 1;
  1337. }
  1338.  
  1339. /*
  1340. _rectangle - _rectangle glue routine 
  1341. */
  1342. short   __cdecl _rectangle(short c, short x1, short y1, short x2, short y2)
  1343. {
  1344.     register GBPTR bp;        /* Buffer pointer */
  1345.  
  1346.     bp = _galloc(sizeof(short) * 6 + 1);
  1347.     *bp++ = op_rectangle;
  1348.     *SHORT0P = c;
  1349.     *SHORT2P = x1;
  1350.     *SHORT4P = y1;
  1351.     *SHORT6P = x2;
  1352.     *SHORT8P = y2;
  1353.     if(!_gbuff_flag)
  1354.     {
  1355.         _gflush();
  1356.         return SHORT10;
  1357.     }
  1358.     return SHORT10;
  1359. }
  1360.  
  1361. /*
  1362. _rectangle_w - _rectangle_w glue routine 
  1363. */
  1364. short   __cdecl _rectangle_w(short c, double x1, double y1, double x2, double y2)
  1365. {
  1366.     register GBPTR bp;        /* Buffer pointer */
  1367.  
  1368.     bp = _galloc(sizeof(short) * 2 + sizeof(double) * 4 + 1);
  1369.     *bp++ = op_rectangle_w;
  1370.     *SHORT0P = c;
  1371.     *DOUBL2P = x1;
  1372.     *DOUBL10P = y1;
  1373.     *DOUBL18P = x2;
  1374.     *DOUBL26P = y2;
  1375.     if(!_gbuff_flag)
  1376.     {
  1377.         _gflush();
  1378.         return SHORT34;
  1379.     }
  1380.     return SHORT34;
  1381. }
  1382.  
  1383. /*
  1384. _rectangle_wxy - _rectangle_wxy glue routine 
  1385. */
  1386. short   __cdecl _rectangle_wxy(short c, const struct _wxycoord *pwxy1, 
  1387.                 const struct _wxycoord *pwxy2)
  1388. {
  1389.     register GBPTR bp;        /* Buffer pointer */
  1390.  
  1391.     bp = _galloc(sizeof(short) * 2 + sizeof(double) * 4 + 1);
  1392.     *bp++ = op_rectangle_wxy;
  1393.     *SHORT0P = c;
  1394.     *DOUBL2P = pwxy1->wx;
  1395.     *DOUBL10P = pwxy1->wy;
  1396.     *DOUBL18P = pwxy2->wx;
  1397.     *DOUBL26P = pwxy2->wy;
  1398.     _gflush();
  1399.     return SHORT34;
  1400. }
  1401.  
  1402. /*
  1403. _registerfonts - _registerfonts glue routine 
  1404. */
  1405. short   __cdecl _registerfonts(const char *pathname)
  1406. {
  1407.     register GBPTR bp;    /* Buffer pointer */
  1408.     int n;            /* String length */
  1409.     int cc;            /* Cycle count */
  1410.     int i;            /* Buffer copy count */
  1411.     int ret;        /* return value */
  1412.  
  1413.     ret = 0;
  1414.     n = strlen(pathname);
  1415.     while(n)
  1416.     {
  1417.         cc = n;
  1418.         if(cc > GBUFF_SIZE - 4)
  1419.             cc = GBUFF_SIZE - 4;
  1420.         bp = _galloc(cc + 4);
  1421.         *bp++ = op_registerfonts;
  1422.         for(i = 0; i < cc; ++i)
  1423.             *(bp+i) = *(pathname+i);
  1424.         *(bp + cc) = 0;
  1425.         n -= cc;
  1426.         _gflush();
  1427.         ret += *(short *)(bp + cc + 1);
  1428.     }
  1429.     return ret;
  1430. }
  1431.  
  1432. /*
  1433. _remapallpalette - _rempallpalette glue routine 
  1434. */
  1435. short  __cdecl _remapallpalette(const long *p)
  1436. {
  1437.     register GBPTR bp;        /* Buffer pointer */
  1438.     struct _videoconfig vc;
  1439.     int size;
  1440.  
  1441. //
  1442. // Figure out how big the array is
  1443. //
  1444.     _getvideoconfig(&vc);
  1445.     if (vc.numcolors == 256)
  1446.         size = 256 * sizeof(long);
  1447.     else if (vc.numcolors == 64)
  1448.         size = 64 * sizeof(long);
  1449.     else
  1450.         size = 16 * sizeof(long);
  1451.  
  1452.     bp = _galloc(size + sizeof(long) + sizeof(short) + 1);
  1453.     *bp++ = op_remapallpalette;
  1454.     *LONG0P = size;
  1455.     memcpy(LONG6P, p, size);
  1456.     if(!_gbuff_flag)
  1457.     {
  1458.         _gflush();
  1459.         return *SHORT4P;
  1460.     }
  1461.     return 0;
  1462. }
  1463.  
  1464. /*
  1465. _remappalette - _remappalette glue routine 
  1466. */
  1467. long   __cdecl _remappalette(short p, long c)
  1468. {
  1469.     register GBPTR bp;        /* Buffer pointer */
  1470.  
  1471.     bp = _galloc(sizeof(short) + sizeof(long) + 1);
  1472.     *bp++ = op_remappalette;
  1473.     *SHORT0P = p;
  1474.     *LONG2P = c;
  1475.     _gflush();
  1476.     return LONG6;
  1477. }
  1478.  
  1479. /*
  1480. _scrolltextwindow - Fast _scrolltextwindow glue routine (buffered)
  1481. */
  1482. void   __cdecl _scrolltextwindow(short lines)
  1483. {
  1484.     register GBPTR bp;        /* Buffer pointer */
  1485.  
  1486.     bp = _galloc(sizeof(short) + 1);
  1487.     *bp++ = op_scrolltextwindow;
  1488.     *SHORT0P = lines;
  1489.     if(!_gbuff_flag)
  1490.         _gflush();
  1491.     return;
  1492. }
  1493.  
  1494. /*
  1495. _selectpalette - _selectpalette glue routine 
  1496. */
  1497. short   __cdecl _selectpalette(short n)
  1498. {
  1499.     register GBPTR bp;        /* Buffer pointer */
  1500.  
  1501.     bp = _galloc(sizeof(short) * 2 + 1);
  1502.     *bp++ = op_selectpalette;
  1503.     *SHORT0P = n;
  1504.     _gflush();
  1505.     return SHORT2;
  1506. }
  1507.  
  1508. /*
  1509. _setactivepage - _setactivepage glue routine 
  1510. */
  1511. short   __cdecl _setactivepage(short n)
  1512. {
  1513.  
  1514.     register GBPTR bp;        /* Buffer pointer */
  1515.  
  1516.     bp = _galloc(sizeof(short) * 2 + 1);
  1517.     *bp++ = op_setactivepage;
  1518.     *SHORT0P = n;
  1519.     _gflush();
  1520.     return SHORT2;
  1521. }
  1522.  
  1523. /*
  1524. _setbkcolor - _setbkcolor glue routine 
  1525. */
  1526. long   __cdecl _setbkcolor(long c)
  1527. {
  1528.     register GBPTR bp;        /* Buffer pointer */
  1529.  
  1530.     bp = _galloc(sizeof(long) * 2 + 1);
  1531.     *bp++ = op_setbkcolor;
  1532.     *LONG0P = c;
  1533.     _gflush();
  1534.     return LONG4;
  1535. }
  1536.  
  1537. /*
  1538. _setcliprgn - _setcliprgn glue routine 
  1539. */
  1540. void   __cdecl _setcliprgn(short x1, short y1, short x2, short y2)
  1541. {
  1542.  
  1543.     register GBPTR bp;        /* Buffer pointer */
  1544.  
  1545.     bp = _galloc(sizeof(short) * 4 + 1);
  1546.     *bp++ = op_setcliprgn;
  1547.     *SHORT0P = x1;
  1548.     *SHORT2P = y1;
  1549.     *SHORT4P = x2;
  1550.     *SHORT6P = y2;
  1551.     if(!_gbuff_flag)
  1552.         _gflush();
  1553.     return;
  1554. }
  1555.  
  1556. /*
  1557. _setcolor - _setcolor glue routine 
  1558. */
  1559. short   __cdecl _setcolor(short c)
  1560. {
  1561.     register GBPTR bp;        /* Buffer pointer */
  1562.  
  1563.     bp = _galloc(sizeof(short) * 2 + 1);
  1564.     *bp++ = op_setcolor;
  1565.     *SHORT0P = c;
  1566.     _gflush();
  1567.     return SHORT2;
  1568. }
  1569.  
  1570. /*
  1571. _setfillmask - _setfillmask glue routine 
  1572. */
  1573. void   __cdecl _setfillmask(const unsigned char *p)
  1574. {
  1575.     register GBPTR bp;        /* Buffer pointer */
  1576.     int i;
  1577.  
  1578.     if(p == NULL)
  1579.     {
  1580.         bp = _galloc(1);
  1581.         *bp++ = op_setnullmask;
  1582.     }
  1583.     else
  1584.     {
  1585.         bp = _galloc(8 + 1);
  1586.         *bp++ = op_setfillmask;
  1587.         for(i = 0; i < 8; ++i)
  1588.             *(bp+i) = *(p+i);
  1589.     }
  1590.     if(!_gbuff_flag)
  1591.         _gflush();
  1592.     return;
  1593. }
  1594.  
  1595. /*
  1596. _setfont - _setfont glue routine 
  1597. */
  1598. short   __cdecl _setfont(const char *option)
  1599. {
  1600.     register GBPTR bp;    /* Buffer pointer */
  1601.     int n;            /* String length */
  1602.     int cc;            /* Cycle count */
  1603.     int i;            /* Buffer copy count */
  1604.     int ret;        /* return value */
  1605.  
  1606.     ret = 0;
  1607.     n = strlen(option);
  1608.     while(n)
  1609.     {
  1610.         cc = n;
  1611.         if(cc > GBUFF_SIZE - 4)
  1612.             cc = GBUFF_SIZE - 4;
  1613.         bp = _galloc(cc + 4);
  1614.         *bp++ = op_setfont;
  1615.         for(i = 0; i < cc; ++i)
  1616.             *(bp+i) = *(option+i);
  1617.         *(bp + cc) = 0;
  1618.         n -= cc;
  1619.         _gflush();
  1620.         ret += *(short *)(bp + cc + 1);
  1621.     }
  1622.     return ret;
  1623. }
  1624.  
  1625. /*
  1626. _setgtextvector - _setgtextvector glue routine 
  1627. */
  1628. struct _xycoord   __cdecl _setgtextvector(short x, short y)
  1629. {
  1630.     register GBPTR bp;        /* Buffer pointer */
  1631.     struct _xycoord xy;        /* X-Y return value */
  1632.  
  1633.     bp = _galloc(sizeof(short) * 4 + 1);
  1634.     *bp++ = op_setgtextvector;
  1635.     *SHORT0P = x;
  1636.     *SHORT2P = y;
  1637.     _gflush();
  1638.     xy.xcoord = SHORT4;
  1639.     xy.ycoord = SHORT6;
  1640.     return xy;
  1641. }
  1642.  
  1643. /*
  1644. _setlinestyle - _setlinestyle glue routine 
  1645. */
  1646. void   __cdecl _setlinestyle(unsigned short m)
  1647. {
  1648.     register GBPTR bp;        /* Buffer pointer */
  1649.  
  1650.     bp = _galloc(sizeof(short) + 1);
  1651.     *bp++ = op_setlinestyle;
  1652.     *SHORT0P = m;
  1653.     if(!_gbuff_flag)
  1654.         _gflush();
  1655.     return;
  1656. }
  1657.  
  1658. /*
  1659. _setlogorg - _setlogorg glue routine 
  1660. */
  1661. struct _xycoord   __cdecl _setlogorg(short x, short y)
  1662. {
  1663.     register GBPTR bp;        /* Buffer pointer */
  1664.     struct _xycoord xy;        /* X-Y return value */
  1665.  
  1666.     bp = _galloc(sizeof(short) * 4 + 1);
  1667.     *bp++ = op_setlogorg;
  1668.     *SHORT0P = x;
  1669.     *SHORT2P = y;
  1670.     _gflush();
  1671.     xy.xcoord = SHORT4;
  1672.     xy.ycoord = SHORT6;
  1673.     return xy;
  1674. }
  1675.  
  1676. /*
  1677. _setpixel - _setpixel glue routine 
  1678. */
  1679. short   __cdecl _setpixel(short x, short y)
  1680. {
  1681.     register GBPTR bp;        /* Buffer pointer */
  1682.  
  1683.     bp = _galloc(sizeof(short) * 3 + 1);
  1684.     *bp++ = op_setpixel;
  1685.     *SHORT0P = x;
  1686.     *SHORT2P = y;
  1687.     _gflush();
  1688.     return SHORT4;
  1689. }
  1690.  
  1691. /*
  1692. _setpixel_w - _setpixel_w glue routine 
  1693. */
  1694. short   __cdecl _setpixel_w(double x, double y)
  1695. {
  1696.     register GBPTR bp;        /* Buffer pointer */
  1697.  
  1698.     bp = _galloc(sizeof(short) + sizeof(double) + 1);
  1699.     *bp++ = op_setpixel_w;
  1700.     *DOUBL0P = x;
  1701.     *DOUBL8P = y;
  1702.     _gflush();
  1703.     return SHORT16;
  1704. }
  1705.  
  1706. /*
  1707. _settextcolor - _settextcolor glue routine 
  1708. */
  1709. short   __cdecl _settextcolor(short c)
  1710. {
  1711.     register GBPTR bp;        /* Buffer pointer */
  1712.  
  1713.     bp = _galloc(sizeof(short) * 2 + 1);
  1714.     *bp++ = op_settextcolor;
  1715.     *SHORT0P = c;
  1716.     return SHORT2;
  1717. }
  1718.  
  1719. /*
  1720. _settextcursor - _settextcursor glue routine 
  1721. */
  1722. short   __cdecl _settextcursor(short c)
  1723. {
  1724.     register GBPTR bp;        /* Buffer pointer */
  1725.  
  1726.     bp = _galloc(sizeof(short) * 2 + 1);
  1727.     *bp++ = op_settextcursor;
  1728.     *SHORT0P = c;
  1729.     _gflush();
  1730.     return SHORT2;
  1731. }
  1732.  
  1733. /*
  1734. _settextposition - _settextposition glue routine 
  1735. */
  1736. struct _rccoord   __cdecl _settextposition(short r, short c)
  1737. {
  1738.     register GBPTR bp;        /* Buffer pointer */
  1739.     struct _rccoord rc;        /* X-Y return value */
  1740.  
  1741.     bp = _galloc(sizeof(short) * 4 + 1);
  1742.     *bp++ = op_settextposition;
  1743.     *SHORT0P = r;
  1744.     *SHORT2P = c;
  1745.     _gflush();
  1746.     rc.row = SHORT4;
  1747.     rc.col = SHORT6;
  1748.     return rc;
  1749. }
  1750.  
  1751. /*
  1752. _settextrows - _settextrows glue routine 
  1753. */
  1754. short   __cdecl _settextrows(short c)
  1755. {
  1756.     register GBPTR bp;        /* Buffer pointer */
  1757.  
  1758.     bp = _galloc(sizeof(short) * 2 + 1);
  1759.     *bp++ = op_settextrows;
  1760.     *SHORT0P = c;
  1761.     _gflush();
  1762.     return SHORT2;
  1763. }
  1764.  
  1765. /*
  1766. _settextwindow - _settextwindow glue routine 
  1767. */
  1768. void   __cdecl _settextwindow(short r1, short c1, short r2, short c2)
  1769. {
  1770.     register GBPTR bp;        /* Buffer pointer */
  1771.  
  1772.     bp = _galloc(sizeof(short) * 4 + 1);
  1773.     *bp++ = op_settextwindow;
  1774.     *SHORT0P = r1;
  1775.     *SHORT2P = c1;
  1776.     *SHORT4P = r2;
  1777.     *SHORT6P = c2;
  1778.     if(!_gbuff_flag)
  1779.         _gflush();
  1780.     return;
  1781.  
  1782. }
  1783.  
  1784. /*
  1785. _setvideomode - _setvideomode glue routine
  1786. */
  1787. short   __cdecl _setvideomode(short mode)
  1788. {
  1789.     register GBPTR bp;        /* Buffer pointer */
  1790.  
  1791.     bp = _galloc(sizeof(short) * 2 + 1);
  1792.     *bp++ = op_setvideomode;
  1793.     *SHORT0P = mode;
  1794.     _gflush();
  1795.     return SHORT2;
  1796. }
  1797.  
  1798. /*
  1799. _setvideomoderows - _setvideomoderows glue routine 
  1800. */
  1801. short   __cdecl _setvideomoderows(short mode, short rows)
  1802. {
  1803.     register GBPTR bp;        /* Buffer pointer */
  1804.  
  1805.     bp = _galloc(sizeof(short) * 2 + 1);
  1806.     *bp++ = op_setvideomoderows;
  1807.     *SHORT0P = mode;
  1808.     *SHORT2P = rows;
  1809.     _gflush();
  1810.     return SHORT4;
  1811. }
  1812.  
  1813. /*
  1814. _setviewport - _setviewport glue routine 
  1815. */
  1816. void   __cdecl _setviewport(short x1, short y1, short x2, short y2)
  1817. {
  1818.     register GBPTR bp;        /* Buffer pointer */
  1819.  
  1820.     bp = _galloc(sizeof(short) * 4 + 1);
  1821.     *bp++ = op_setviewport;
  1822.     *SHORT0P = x1;
  1823.     *SHORT2P = y1;
  1824.     *SHORT4P = x2;
  1825.     *SHORT6P = y2;
  1826.     if(!_gbuff_flag)
  1827.         _gflush();
  1828.     return;
  1829. }
  1830.  
  1831. /*
  1832. _setvisualpage - _setvisualpage glue routine 
  1833. */
  1834. short   __cdecl _setvisualpage(short n)
  1835. {
  1836.     register GBPTR bp;        /* Buffer pointer */
  1837.  
  1838.     bp = _galloc(sizeof(short) * 2 + 1);
  1839.     *bp++ = op_setvisualpage;
  1840.     *SHORT0P = n;
  1841.     _gflush();
  1842.     return SHORT2;
  1843. }
  1844.  
  1845. /*
  1846. _setwindow - _setwindow glue routine 
  1847. */
  1848. short   __cdecl _setwindow(short c, double x1, double y1, double x2, double y2)
  1849. {
  1850.     register GBPTR bp;        /* Buffer pointer */
  1851.  
  1852.     bp = _galloc(sizeof(short) * 2 + sizeof(double) * 4 + 1);
  1853.     *bp++ = op_setwindow;
  1854.     *SHORT0P = c;
  1855.     *DOUBL2P = x1;
  1856.     *DOUBL10P = y1;
  1857.     *DOUBL18P = x2;
  1858.     *DOUBL26P = y2;
  1859.     _gflush();
  1860.     return SHORT34;
  1861. }
  1862.  
  1863. /*
  1864. _setwritemode - _setwritemode glue routine 
  1865. */
  1866. short   __cdecl _setwritemode(short n)
  1867. {
  1868.     register GBPTR bp;        /* Buffer pointer */
  1869.  
  1870.     bp = _galloc(sizeof(short) * 2 + 1);
  1871.     *bp++ = op_setwritemode;
  1872.     *SHORT0P = n;
  1873.     _gflush();
  1874.     return SHORT2;
  1875. }
  1876.  
  1877. /*
  1878. _unregisterfonts - _unregisterfonts glue routine 
  1879. */
  1880. void  __cdecl _unregisterfonts(void)
  1881. {
  1882.     register GBPTR bp;        /* Buffer pointer */
  1883.  
  1884.     bp = _galloc(1);
  1885.     *bp++ = op_unregisterfonts;
  1886.     _gflush();
  1887.     return;
  1888. }
  1889.  
  1890. /*
  1891. _wrapon - _wrapon glue routine 
  1892. */
  1893. short  __cdecl _wrapon(short n)
  1894. {
  1895.     register GBPTR bp;        /* Buffer pointer */
  1896.  
  1897.     bp = _galloc(sizeof(short) * 2 + 1);
  1898.     *bp++ = op_wrapon;
  1899.     *SHORT0P = n;
  1900.     _gflush();
  1901.     return SHORT2;
  1902. }
  1903.