home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / GDEMO / GSERVER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-22  |  14.4 KB  |  611 lines

  1. /* gserver.c - Graphics server code */
  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. /*
  14.  * This is real mode code which must be compiled in large model.  We
  15.  * have to be compiled in large model so that all pointers are FAR
  16.  * pointers.  We need to use FAR pointers throughout because when the
  17.  * protected mode program calls us to execute graphics commands, the
  18.  * buffer it passes commands in is a FAR buffer.
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #include "graph.h"        /* from MSC 7.0 include directory */
  25. #include "gserver.h"
  26.  
  27.  
  28. /*
  29.  
  30. main - Main routine for the real mode graphics server
  31.  
  32. */
  33.  
  34. main()
  35.  
  36. {
  37.     /* Print out a message on the screen telling that we were loaded
  38.        okay */
  39.  
  40.     flushall();
  41.     printf("Real mode graphics server has initialized.\n");
  42.     flushall();
  43.  
  44.     /* Return to protected mode */
  45.  
  46.     protret();
  47. }
  48.  
  49.  
  50. /*
  51.  
  52. gserver - Graphics server
  53.     This is the routine that gets called from protected mode
  54.     whenever there are graphics commands to be executed.  We execute
  55.     all the commands in the buffer and then return.
  56.  
  57.     Use __cdecl to force stack-based calling conventions, because this
  58.     routine is called from an ASM routine that passes the argument
  59.     on the stack.
  60. */
  61.  
  62. void __cdecl gserver(bp)
  63.  
  64. char *bp;        /* Pointer to the graphics commands buffer
  65.                passed in by the protected mode code */
  66.  
  67. {
  68.  
  69.     char *ebp;        /* End of buffer pointer */
  70.     unsigned int len;    /* Length of the current command */
  71.     struct _wxycoord wxy;    /* wxy co-ordinates */
  72.     struct xycoord xy;    /* X-Y co-ordinates */
  73.     struct rccoord rc;    /* Row-column co-ordinates */
  74.     struct videoconfig vc;    /* Video configuration */
  75.  
  76.     /* The first short in the graphics commands buffer gives the number
  77.        of bytes used for graphics commands in the buffer.  From this
  78.        count, calculate "ebp" which point to the first byte after the
  79.        last command in the buffer. */
  80.  
  81.     ebp = bp + SHORT0;
  82.     bp += sizeof(short);
  83.  
  84.     /* Loop through the buffer and execute each graphics command. */
  85.  
  86.     while(bp < ebp)
  87.     {
  88.  
  89.         /* Decode the current graphics command */
  90.  
  91.         switch(*bp++)
  92.         {
  93.  
  94.             /* Command executors */
  95.  
  96.             case op_arc:
  97.                 *SHORT16P = _arc(SHORT0, SHORT2, SHORT4,
  98.                             SHORT6, SHORT8, SHORT10, SHORT12,
  99.                             SHORT14);
  100.                 len = sizeof(short) * 9;
  101.                 break;
  102.  
  103.             case op_arc_w:
  104.                 *SHORT16P = _arc_w(DOUBL0, DOUBL8, DOUBL16,
  105.                             DOUBL24, DOUBL32, DOUBL40,
  106.                             DOUBL48, DOUBL56);
  107.                 len = sizeof(double) * 8 + sizeof(short);
  108.                 break;
  109.  
  110.             case op_arc_wxy:
  111.                 *SHORT64P = _arc_wxy((struct _wxycoord *)DOUBL0P
  112.                         , (struct _wxycoord *)DOUBL16P,
  113.                                (struct _wxycoord *)DOUBL32P,
  114.                         (struct _wxycoord *)DOUBL48P);
  115.                 len = sizeof(struct _wxycoord) * 4 
  116.                     + sizeof(short);
  117.                 break;
  118.  
  119.             case op_clearscreen:
  120.                 _clearscreen(SHORT0);
  121.                 len = sizeof(short);
  122.                 break;
  123.  
  124.             case op_displaycursor:
  125.                 *SHORT2P = _displaycursor(SHORT0);
  126.                 len = sizeof(short) * 2;
  127.                 break;
  128.  
  129.             case op_ellipse:
  130.                 *SHORT10P = _ellipse(SHORT0, SHORT2, SHORT4,
  131.                             SHORT6, SHORT8);
  132.                 len = sizeof(short) * 6;
  133.                 break;
  134.  
  135.             case op_ellipse_w:
  136.                 *SHORT34P = _ellipse_w(SHORT0, DOUBL2, DOUBL10,
  137.                             DOUBL18, DOUBL26);
  138.                 len = sizeof(double) * 4 + sizeof(short) * 2;
  139.                 break;
  140.  
  141.             case op_ellipse_wxy:
  142.                 *SHORT34P = _ellipse_wxy(SHORT0,
  143.                         (struct _wxycoord *)DOUBL2P, 
  144.                         (struct _wxycoord *)DOUBL18P);
  145.                 len = sizeof(struct _wxycoord) * 2
  146.                      + sizeof(short) * 2;
  147.                 break;
  148.  
  149.             case op_floodfill:
  150.                 *SHORT6P = _floodfill(SHORT0, SHORT2, SHORT4);
  151.                 len = sizeof(short) * 4;
  152.                 break;
  153.  
  154.             case op_floodfill_w:
  155.                 *SHORT18P = _floodfill_w(DOUBL0, DOUBL8,
  156.                         SHORT16);
  157.                 len = sizeof(double) * 2 + sizeof(short);
  158.                 break;
  159.  
  160.             case op_getactivepage:
  161.                 *SHORT0P = _getactivepage();
  162.                 len = sizeof(short);
  163.                 break;
  164.  
  165.             case op_getarcinfo:
  166.                 *SHORT12P = _getarcinfo(
  167.                        (struct xycoord *)SHORT0P,
  168.                        (struct xycoord *)SHORT4P,
  169.                            (struct xycoord *) SHORT8P);
  170.                 len = sizeof(struct xycoord) * 3 + sizeof(short);
  171.                 break;
  172.  
  173.             case op_getbkcolor:
  174.                 *LONG0P = _getbkcolor();
  175.                 len = sizeof(long);
  176.                 break;
  177.  
  178.             case op_getcolor:
  179.                 *SHORT0P = _getcolor();
  180.                 len = sizeof(short);
  181.                 break;
  182.  
  183.             case op_getcurrentposition:
  184.                 xy = _getcurrentposition();
  185.                 *SHORT0P = xy.xcoord;
  186.                 *SHORT2P = xy.ycoord;
  187.                 len = sizeof(short) * 2;
  188.                 break;
  189.  
  190.             case op_getcurrentposition_w:
  191.                 wxy = _getcurrentposition_w();
  192.                 *DOUBL0P = wxy.wx;
  193.                 *DOUBL8P = wxy.wy;
  194.                 len = sizeof(struct _wxycoord);
  195.                 break;
  196.  
  197.             case op_getfillmask:
  198.                 *SHORT8P = _getfillmask(bp) != NULL;
  199.                 len = sizeof(short) + 8;
  200.                 break;
  201.  
  202.             case op_getfontinfo:
  203.                 *SHORT8P = _getfontinfo((struct _fontinfo *)bp);
  204.                 len = sizeof(short) + 8;
  205.                 break;
  206.  
  207.             case op_getgtextextent:
  208.                 len = strlen(bp);
  209.                 *(short *)(bp + len + 1) = _getgtextextent(bp);
  210.                 len += 3;
  211.                 break;
  212.  
  213.             case op_getgtextvector:
  214.                 xy = _getgtextvector();
  215.                 *SHORT0P = xy.xcoord;
  216.                 *SHORT2P = xy.ycoord;
  217.                 len = sizeof(short) * 2;
  218.                 break;
  219.  
  220.             case op_getlinestyle:
  221.                 *SHORT0P = _getlinestyle();
  222.                 len = sizeof(short);
  223.                 break;
  224.  
  225.             case op_getphyscoord:
  226.                 xy = _getphyscoord(SHORT0, SHORT2);
  227.                 *SHORT4P = xy.xcoord;
  228.                 *SHORT6P = xy.ycoord;
  229.                 len = sizeof(short) * 4;
  230.                 break;
  231.  
  232.             case op_getpixel:
  233.                 *SHORT4P = _getpixel(SHORT0, SHORT2);
  234.                 len = sizeof(short) * 3;
  235.                 break;
  236.  
  237.             case op_getpixel_w:
  238.                 *SHORT16P = _getpixel_w(DOUBL0, DOUBL8);
  239.                 len = sizeof(double) * 2 + sizeof(short);
  240.                 break;
  241.  
  242.             case op_gettextcolor:
  243.                 *SHORT0P = _gettextcolor();
  244.                 len = sizeof(short);
  245.                 break;
  246.  
  247.             case op_gettextcursor:
  248.                 *SHORT0P = _gettextcursor();
  249.                 len = sizeof(short);
  250.                 break;
  251.  
  252.             case op_gettextposition:
  253.                 rc = _gettextposition();
  254.                 *SHORT0P = rc.row;
  255.                 *SHORT2P = rc.col;
  256.                 len = sizeof(short) * 2;
  257.                 break;
  258.  
  259.             case op_gettextwindow:
  260.                 _gettextwindow(SHORT0P, SHORT2P, 
  261.                         SHORT4P, SHORT6P);
  262.                 len = sizeof(short) * 4;
  263.                 break;
  264.  
  265.             case op_getvideoconfig:
  266.                 _getvideoconfig(&vc);
  267.                 *SHORT0P = vc.numxpixels;
  268.                 *SHORT2P = vc.numypixels;
  269.                 *SHORT4P = vc.numtextcols;
  270.                 *SHORT6P = vc.numtextrows;
  271.                 *SHORT8P = vc.numcolors;
  272.                 *SHORT10P = vc.bitsperpixel;
  273.                 *SHORT12P = vc.numvideopages;
  274.                 *SHORT14P = vc.mode;
  275.                 *SHORT16P = vc.adapter;
  276.                 *SHORT18P = vc.monitor;
  277.                 *SHORT20P = vc.memory;
  278.                 len = sizeof(short) * 11;
  279.                 break;
  280.  
  281.             case op_getviewcoord:
  282.                 xy = _getviewcoord(SHORT0, SHORT2);
  283.                 *SHORT4P = xy.xcoord;
  284.                 *SHORT6P = xy.ycoord;
  285.                 len = sizeof(short) * 4;
  286.                 break;
  287.  
  288.             case op_getviewcoord_w:
  289.                 xy = _getviewcoord_w(DOUBL0, DOUBL8);
  290.                 *SHORT16P = xy.xcoord;
  291.                 *SHORT18P = xy.ycoord;
  292.                 len = sizeof(short) * 2 + sizeof(double) * 2;
  293.                 break;
  294.  
  295.             case op_getviewcoord_wxy:
  296.                 xy = _getviewcoord_wxy((struct _wxycoord *)DOUBL0P);
  297.                 *SHORT16P = xy.xcoord;
  298.                 *SHORT18P = xy.ycoord;
  299.                 len = sizeof(short) * 2 + sizeof(double) * 2;
  300.                 break;
  301.  
  302.             case op_getvisualpage:
  303.                 *SHORT0P = _getvisualpage();
  304.                 len = sizeof(short);
  305.                 break;
  306.  
  307.             case op_getwindowcoord:
  308.                 wxy = _getwindowcoord(SHORT0, SHORT2);
  309.                 *DOUBL4P = wxy.wx;
  310.                 *DOUBL12P = wxy.wy;
  311.                 len = sizeof(short) * 2 + sizeof(double) * 2;
  312.                 break;
  313.  
  314.             case op_getwritemode:
  315.                 *SHORT0P = _getwritemode();
  316.                 len = sizeof(short);
  317.                 break;
  318.  
  319.             case op_grstatus:
  320.                 *SHORT0P = _grstatus();
  321.                 len = sizeof(short);
  322.                 break;
  323.  
  324.             case op_imagesize:
  325.                 *LONG8P = _imagesize(SHORT0, SHORT2, SHORT4,
  326.                           SHORT6);
  327.                 len = sizeof(short) * 4 + sizeof(long);
  328.                 break;
  329.  
  330.             case op_imagesize_w:
  331.                 *LONG32P = _imagesize_w(DOUBL0, DOUBL8, DOUBL16,
  332.                           DOUBL24);
  333.                 len = sizeof(double) * 4 + sizeof(long);
  334.                 break;
  335.  
  336.             case op_imagesize_wxy:
  337.                 *LONG32P = _imagesize_wxy(
  338.                         (struct _wxycoord *) DOUBL0P,
  339.                         (struct _wxycoord *) DOUBL16P);
  340.                 len = sizeof(struct _wxycoord) * 2
  341.                      + sizeof(long);
  342.                 break;
  343.  
  344. /*
  345.             case op_inchar:
  346.                 *SHORT0P = _inchar();
  347.                 len = sizeof(short);
  348.                 break;
  349. */
  350.  
  351.             case op_lineto:
  352.                 *SHORT4P = _lineto(SHORT0, SHORT2);
  353.                 len = sizeof(short) * 3;
  354.                 break;
  355.  
  356.             case op_lineto_w:
  357.                 *SHORT16P = _lineto_w(DOUBL0, DOUBL8);
  358.                 len = sizeof(double) * 2 + sizeof(short);
  359.                 break;
  360.  
  361.             case op_moveto:
  362.                 xy = _moveto(SHORT0, SHORT2);
  363.                 *SHORT4P = xy.xcoord;
  364.                 *SHORT6P = xy.ycoord;
  365.                 len = sizeof(short) * 4;
  366.                 break;
  367.  
  368.             case op_moveto_w:
  369.                 wxy = _moveto_w(DOUBL0, DOUBL8);
  370.                 *DOUBL16P = wxy.wx;
  371.                 *DOUBL24P = wxy.wy;
  372.                 len = sizeof(double) * 4;
  373.                 break;
  374.  
  375.             case op_outgtext:
  376.                 _outgtext(bp);
  377.                 len = strlen(bp) + 1;
  378.                 break;
  379.  
  380.             case op_outmem:
  381.                 _outmem((const char *)bp, (short)bp + strlen(bp));
  382.                 len = strlen(bp) + 1 + sizeof(short);
  383.                 break;
  384.  
  385.             case op_outtext:
  386.                 _outtext(bp);
  387.                 len = strlen(bp) + 1;
  388.                 break;
  389.  
  390.             case op_pie:
  391.                 *SHORT18P = _pie(SHORT0, SHORT2, SHORT4,
  392.                             SHORT6, SHORT8, SHORT10, SHORT12,
  393.                             SHORT14, SHORT16);
  394.                 len = sizeof(short) * 10;
  395.                 break;
  396.  
  397.             case op_pie_w:
  398.                 *SHORT66P = _pie_w(SHORT0, DOUBL2, DOUBL10,
  399.                             DOUBL18, DOUBL26, DOUBL34, DOUBL42,
  400.                             DOUBL50, DOUBL58);
  401.                 len = sizeof(short) * 2 + sizeof(double) * 8;
  402.                 break;
  403.  
  404.             case op_pie_wxy:
  405.                 *SHORT66P = _pie_wxy(SHORT0,
  406.                        (struct _wxycoord *) DOUBL2P, 
  407.                        (struct _wxycoord *) DOUBL18P,
  408.                            (struct _wxycoord *) DOUBL34P, 
  409.                        (struct _wxycoord *) DOUBL50P);
  410.                 len = sizeof(short) * 2 + 
  411.                     sizeof(struct _wxycoord) * 4;
  412.                 break;
  413.  
  414.             case op_rectangle:
  415.                 *SHORT10P = _rectangle(SHORT0, SHORT2, SHORT4,
  416.                             SHORT6, SHORT8);
  417.                 len = sizeof(short) * 6;
  418.                 break;
  419.  
  420.             case op_rectangle_w:
  421.                 *SHORT34P = _rectangle_w(SHORT0, DOUBL2, 
  422.                         DOUBL10, DOUBL18, DOUBL26);
  423.                 len = sizeof(short) + sizeof(double) * 4;
  424.                 break;
  425.  
  426.             case op_rectangle_wxy:
  427.                 *SHORT34P = _rectangle_wxy(SHORT0, 
  428.                         (struct _wxycoord *) DOUBL2P, 
  429.                         (struct _wxycoord *) DOUBL18P);
  430.                 len = sizeof(short) + 
  431.                     sizeof(struct _wxycoord) * 2;
  432.                 break;
  433.  
  434.             case op_registerfonts:
  435.                 len = strlen(bp);
  436.                 *(short *)(bp + len + 1) = _registerfonts(bp);
  437.                 len += 3;
  438.                 break;
  439.  
  440.             case op_remapallpalette:
  441.                 *SHORT4P = _remapallpalette(LONG6P);
  442.                 len = *LONG0P + sizeof(long) + sizeof(short);
  443.                 break;
  444.  
  445.             case op_remappalette:
  446.                 *LONG6P = _remappalette(SHORT0, LONG2);
  447.                 len = sizeof(short) + sizeof(long) * 2;
  448.                 break;
  449.  
  450.             case op_scrolltextwindow:
  451.                 _scrolltextwindow(SHORT0);
  452.                 len = sizeof(short);
  453.                 break;
  454.  
  455.             case op_selectpalette:
  456.                 *SHORT2P = _selectpalette(SHORT0);
  457.                 len = sizeof(short) * 2;
  458.                 break;
  459.  
  460.             case op_setactivepage:
  461.                 *SHORT2P = _setactivepage(SHORT0);
  462.                 len = sizeof(short) * 2;
  463.                 break;
  464.  
  465.             case op_setbkcolor:
  466.                 *LONG4P = _setbkcolor(LONG0);
  467.                 len = sizeof(long) * 2;
  468.                 break;
  469.  
  470.             case op_setcliprgn:
  471.                 _setcliprgn(SHORT0, SHORT2, SHORT4, SHORT6);
  472.                 len = sizeof(short) * 4;
  473.                 break;
  474.  
  475.             case op_setcolor:
  476.                 *SHORT2P = _setcolor(SHORT0);
  477.                 len = sizeof(short) * 2;
  478.                 break;
  479.  
  480.             case op_setfillmask:
  481.                 _setfillmask(bp);
  482.                 len = 8;
  483.                 break;
  484.  
  485.             case op_setfont:
  486.                 len = strlen(bp);
  487.                 *(short *)(bp + len + 1) = _setfont(bp);
  488.                 len += 3;
  489.                 break;
  490.  
  491.             case op_setgtextvector:
  492.                 xy = _setgtextvector(SHORT0, SHORT2);
  493.                 *SHORT4P = xy.xcoord;
  494.                 *SHORT6P = xy.ycoord;
  495.                 len = sizeof(short) * 4;
  496.                 break;
  497.  
  498.             case op_setnullmask:
  499.                 _setfillmask(NULL);
  500.                 len = 0;
  501.                 break;
  502.  
  503.             case op_setlinestyle:
  504.                 _setlinestyle(SHORT0);
  505.                 len = sizeof(short);
  506.                 break;
  507.  
  508.             case op_setlogorg:
  509.                 xy = _setlogorg(SHORT0, SHORT2);
  510.                 *SHORT4P = xy.xcoord;
  511.                 *SHORT6P = xy.ycoord;
  512.                 len = sizeof(short) * 4;
  513.                 break;
  514.  
  515.             case op_setpixel:
  516.                 *SHORT4P = _setpixel(SHORT0, SHORT2);
  517.                 len = sizeof(short) * 3;
  518.                 break;
  519.  
  520.             case op_setpixel_w:
  521.                 *SHORT16P = _setpixel_w(DOUBL0, DOUBL8);
  522.                 len = sizeof(short) + sizeof(double) * 2;
  523.                 break;
  524.  
  525.             case op_settextcolor:
  526.                 *SHORT2P = _settextcolor(SHORT0);
  527.                 len = sizeof(short) * 2;
  528.                 break;
  529.  
  530.             case op_settextcursor:
  531.                 *SHORT2P = _settextcursor(SHORT0);
  532.                 len = sizeof(short) * 2;
  533.                 break;
  534.  
  535.             case op_settextposition:
  536.                 rc = _settextposition(SHORT0, SHORT2);
  537.                 *SHORT4P = rc.row;
  538.                 *SHORT6P = rc.col;
  539.                 len = sizeof(short) * 4;
  540.                 break;
  541.  
  542.             case op_settextrows:
  543.                 *SHORT2P = _settextrows(SHORT0);
  544.                 len = sizeof(short) * 2;
  545.                 break;
  546.  
  547.             case op_settextwindow:
  548.                 _settextwindow(SHORT0, SHORT2, SHORT4, SHORT6);
  549.                 len = sizeof(short) * 4;
  550.                 break;
  551.  
  552.             case op_setvideomode:
  553.                 *SHORT2P = _setvideomode(SHORT0);
  554.                 len = sizeof(short) * 2;
  555.                 break;
  556.  
  557.             case op_setvideomoderows:
  558.                 *SHORT4P = _setvideomoderows(SHORT0, SHORT2);
  559.                 len = sizeof(short) * 2;
  560.                 break;
  561.  
  562.             case op_setviewport:
  563.                 _setviewport(SHORT0, SHORT2, SHORT4, SHORT6);
  564.                 len = sizeof(short) * 4;
  565.                 break;
  566.  
  567.             case op_setvisualpage:
  568.                 *SHORT2P = _setvisualpage(SHORT0);
  569.                 len = sizeof(short) * 2;
  570.                 break;
  571.  
  572.             case op_setwindow:
  573.                 *SHORT34P = _setwindow(SHORT0, DOUBL2, 
  574.                         DOUBL10, DOUBL18, DOUBL26);
  575.                 len = sizeof(short) + sizeof(double) * 4;
  576.                 break;
  577.  
  578.             case op_setwritemode:
  579.                 *SHORT2P = _setwritemode(SHORT0);
  580.                 len = sizeof(short) * 2;
  581.                 break;
  582.  
  583.             case op_unregisterfonts:
  584.                 _unregisterfonts();
  585.                 len = 0;
  586.                 break;
  587.  
  588.             case op_wrapon:
  589.                 *SHORT2P = _wrapon(SHORT0);
  590.                 len = sizeof(short) * 2;
  591.                 break;
  592.  
  593.             default:
  594.                 printf("Bad graphics command: %d\n",
  595.                     *(bp-1));
  596.                 return;
  597.  
  598.         }
  599.  
  600.         /* Increment the buffer pointer to the next command. */
  601.  
  602.         bp += len;
  603.  
  604.     }
  605.  
  606.     /* Return back to the protected mode caller. */
  607.  
  608.     return;
  609.  
  610. }
  611.