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

  1. /* gserver.c - Graphics server code */
  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. /*
  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.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. #include "graph.h"
  23. #include "gserver.h"
  24.  
  25. /*
  26.  
  27. main - Main routine for the real mode graphics server
  28.  
  29. */
  30.  
  31. main()
  32.  
  33. {
  34.  
  35.     extern void gserver();
  36.  
  37.     /* Print out a message on the screen telling that we were loaded
  38.        okay */
  39.  
  40.     flushall();
  41.     printf("C run-time library -- Copyright (C) 1987 Microsoft, Inc.\n");
  42.     printf("Real mode graphics server has initialized.\n");
  43.     flushall();
  44.  
  45.     /* Return to protected mode */
  46.  
  47.     protret();
  48. }
  49.  
  50.  
  51. /*
  52.  
  53. gserver - Graphics server
  54.  
  55. */
  56.  
  57. void gserver(bp)
  58.  
  59. char *bp;        /* Pointer to the communications buffer
  60.                passed in by the protected mode code */
  61.  
  62. {
  63.  
  64.     char *ebp;        /* End of buffer pointer */
  65.     unsigned int len;    /* Length of the current command */
  66.     struct xycoord xy;    /* X-Y co-ordinates */
  67.     struct rccoord rc;    /* Row-column co-ordinates */
  68.     struct videoconfig vc;    /* Video configuration */
  69.  
  70.     /* The first short in the communications buffer gives the number
  71.        of bytes used for graphics commands in the buffer.  From this
  72.        count, calculate "ebp" which point to the first byte after the
  73.        last command in the buffer. */
  74.  
  75.     ebp = bp + SHORT0;
  76.     bp += sizeof(short);
  77.  
  78.     /* Loop through the buffer and execute each graphics command. */
  79.  
  80.     while(bp < ebp)
  81.     {
  82.  
  83.         /* Decode the current graphics command */
  84.  
  85.         switch(*bp++)
  86.         {
  87.  
  88.             /* Command executors */
  89.  
  90.             case op_arc:
  91.                 *SHORT16P = _arc(SHORT0, SHORT2, SHORT4,
  92.                             SHORT6, SHORT8, SHORT10, SHORT12,
  93.                             SHORT14);
  94.                 len = sizeof(short) * 9;
  95.                 break;
  96.  
  97.             case op_clearscreen:
  98.                 _clearscreen(SHORT0);
  99.                 len = sizeof(short);
  100.                 break;
  101.  
  102.             case op_displaycursor:
  103.                 *SHORT2P = _displaycursor(SHORT0);
  104.                 len = sizeof(short) * 2;
  105.                 break;
  106.  
  107.             case op_ellipse:
  108.                 *SHORT10P = _ellipse(SHORT0, SHORT2, SHORT4,
  109.                             SHORT6, SHORT8);
  110.                 len = sizeof(short) * 6;
  111.                 break;
  112.  
  113.             case op_floodfill:
  114.                 *SHORT6P = _floodfill(SHORT0, SHORT2, SHORT4);
  115.                 len = sizeof(short) * 4;
  116.                 break;
  117.  
  118.             case op_getbkcolor:
  119.                 *LONG0P = _getbkcolor();
  120.                 len = sizeof(long);
  121.                 break;
  122.  
  123.             case op_getcolor:
  124.                 *SHORT0P = _getcolor();
  125.                 len = sizeof(short);
  126.                 break;
  127.  
  128.             case op_getcurrentposition:
  129.                 xy = _getcurrentposition();
  130.                 *SHORT0P = xy.xcoord;
  131.                 *SHORT2P = xy.ycoord;
  132.                 len = sizeof(short) * 2;
  133.                 break;
  134.  
  135.             case op_getfillmask:
  136.                 *SHORT8P = _getfillmask(bp) != NULL;
  137.                 len = sizeof(short) + 8;
  138.                 break;
  139.  
  140.             case op_getlinestyle:
  141.                 *SHORT0P = _getlinestyle();
  142.                 len = sizeof(short);
  143.                 break;
  144.  
  145.             case op_getlogcoord:
  146.                 xy = _getlogcoord(SHORT0, SHORT2);
  147.                 *SHORT4P = xy.xcoord;
  148.                 *SHORT6P = xy.ycoord;
  149.                 len = sizeof(short) * 4;
  150.                 break;
  151.  
  152.             case op_getphyscoord:
  153.                 xy = _getphyscoord(SHORT0, SHORT2);
  154.                 *SHORT4P = xy.xcoord;
  155.                 *SHORT6P = xy.ycoord;
  156.                 len = sizeof(short) * 4;
  157.                 break;
  158.  
  159.             case op_getpixel:
  160.                 *SHORT4P = _getpixel(SHORT0, SHORT2);
  161.                 len = sizeof(short) * 3;
  162.                 break;
  163.  
  164.             case op_gettextcolor:
  165.                 *SHORT0P = _gettextcolor();
  166.                 len = sizeof(short);
  167.                 break;
  168.  
  169.             case op_gettextposition:
  170.                 rc = _gettextposition();
  171.                 *SHORT0P = rc.row;
  172.                 *SHORT2P = rc.col;
  173.                 len = sizeof(short) * 2;
  174.                 break;
  175.  
  176.             case op_getvideoconfig:
  177.                 _getvideoconfig(&vc);
  178.                 *SHORT0P = vc.numxpixels;
  179.                 *SHORT2P = vc.numypixels;
  180.                 *SHORT4P = vc.numtextcols;
  181.                 *SHORT6P = vc.numtextrows;
  182.                 *SHORT8P = vc.numcolors;
  183.                 *SHORT10P = vc.bitsperpixel;
  184.                 *SHORT12P = vc.numvideopages;
  185.                 *SHORT14P = vc.mode;
  186.                 *SHORT16P = vc.adapter;
  187.                 *SHORT18P = vc.monitor;
  188.                 *SHORT20P = vc.memory;
  189.                 len = sizeof(short) * 11;
  190.                 break;
  191.  
  192.             case op_imagesize:
  193.                 *LONG8P = _imagesize(SHORT0, SHORT2, SHORT4,
  194.                           SHORT6);
  195.                 len = sizeof(short) * 4 + sizeof(long);
  196.                 break;
  197.  
  198.             case op_lineto:
  199.                 *SHORT4P = _lineto(SHORT0, SHORT2);
  200.                 len = sizeof(short) * 3;
  201.                 break;
  202.  
  203.             case op_moveto:
  204.                 xy = _moveto(SHORT0, SHORT2);
  205.                 *SHORT4P = xy.xcoord;
  206.                 *SHORT6P = xy.ycoord;
  207.                 len = sizeof(short) * 4;
  208.                 break;
  209.  
  210.             case op_outtext:
  211.                 _outtext(bp);
  212.                 len = strlen(bp) + 1;
  213.                 break;
  214.  
  215.             case op_pie:
  216.                 *SHORT18P = _pie(SHORT0, SHORT2, SHORT4,
  217.                             SHORT6, SHORT8, SHORT10, SHORT12,
  218.                             SHORT14, SHORT16);
  219.                 len = sizeof(short) * 10;
  220.                 break;
  221.  
  222.             case op_rectangle:
  223.                 *SHORT10P = _rectangle(SHORT0, SHORT2, SHORT4,
  224.                             SHORT6, SHORT8);
  225.                 len = sizeof(short) * 6;
  226.                 break;
  227.  
  228.             case op_remapallpalette:
  229.                 *(short *)(bp + 64) = _remapallpalette(LONG0P);
  230.                 len = sizeof(long) * 16 + sizeof(short);
  231.                 break;
  232.  
  233.             case op_remappalette:
  234.                 *LONG6P = _remappalette(SHORT0, LONG2);
  235.                 len = sizeof(short) + sizeof(long) * 2;
  236.                 break;
  237.  
  238.             case op_selectpalette:
  239.                 *SHORT2P = _selectpalette(SHORT0);
  240.                 len = sizeof(short) * 2;
  241.                 break;
  242.  
  243.             case op_setactivepage:
  244.                 *SHORT2P = _setactivepage(SHORT0);
  245.                 len = sizeof(short) * 2;
  246.                 break;
  247.  
  248.             case op_setbkcolor:
  249.                 *LONG4P = _setbkcolor(LONG0);
  250.                 len = sizeof(long) * 2;
  251.                 break;
  252.  
  253.             case op_setcliprgn:
  254.                 _setcliprgn(SHORT0, SHORT2, SHORT4, SHORT6);
  255.                 len = sizeof(short) * 4;
  256.                 break;
  257.  
  258.             case op_setcolor:
  259.                 *SHORT2P = _setcolor(SHORT0);
  260.                 len = sizeof(short) * 2;
  261.                 break;
  262.  
  263.             case op_setfillmask:
  264.                 _setfillmask(bp);
  265.                 len = 8;
  266.                 break;
  267.  
  268.             case op_setnullmask:
  269.                 _setfillmask(NULL);
  270.                 len = 0;
  271.                 break;
  272.  
  273.             case op_setlinestyle:
  274.                 _setlinestyle(SHORT0);
  275.                 len = sizeof(short);
  276.                 break;
  277.  
  278.             case op_setlogorg:
  279.                 xy = _setlogorg(SHORT0, SHORT2);
  280.                 *SHORT4P = xy.xcoord;
  281.                 *SHORT6P = xy.ycoord;
  282.                 len = sizeof(short) * 4;
  283.                 break;
  284.  
  285.             case op_setpixel:
  286.                 *SHORT4P = _setpixel(SHORT0, SHORT2);
  287.                 len = sizeof(short) * 3;
  288.                 break;
  289.  
  290.             case op_settextcolor:
  291.                 *SHORT2P = _settextcolor(SHORT0);
  292.                 len = sizeof(short) * 2;
  293.                 break;
  294.  
  295.             case op_settextposition:
  296.                 rc = _settextposition(SHORT0, SHORT2);
  297.                 *SHORT4P = rc.row;
  298.                 *SHORT6P = rc.col;
  299.                 len = sizeof(short) * 4;
  300.                 break;
  301.  
  302.             case op_settextwindow:
  303.                 _settextwindow(SHORT0, SHORT2, SHORT4, SHORT6);
  304.                 len = sizeof(short) * 4;
  305.                 break;
  306.  
  307.             case op_setvideomode:
  308.                 *SHORT2P = _setvideomode(SHORT0);
  309.                 len = sizeof(short) * 2;
  310.                 break;
  311.  
  312.             case op_setviewport:
  313.                 _setviewport(SHORT0, SHORT2, SHORT4, SHORT6);
  314.                 len = sizeof(short) * 4;
  315.                 break;
  316.  
  317.             case op_setvisualpage:
  318.                 *SHORT2P = _setvisualpage(SHORT0);
  319.                 len = sizeof(short) * 2;
  320.                 break;
  321.  
  322.             case op_wrapon:
  323.                 *SHORT2P = _wrapon(SHORT0);
  324.                 len = sizeof(short) * 2;
  325.                 break;
  326.  
  327.             case op_kbhit:
  328.                 *SHORT0P = kbhit();
  329.                 len = sizeof(short);
  330.                 break;
  331.  
  332.             case op_bios_keybrd:
  333.                 *SHORT2P = _bios_keybrd(SHORT0);
  334.                 len = sizeof(short) * 2;
  335.                 break;
  336.  
  337.             default:
  338.                 printf("Bad graphics command\n");
  339.                 return;
  340.  
  341.         }
  342.  
  343.         /* Increment the buffer pointer to the next command. */
  344.  
  345.         bp += len;
  346.  
  347.     }
  348.  
  349.     /* Return back to the protected mode caller. */
  350.  
  351.     return;
  352.  
  353. }
  354.