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

  1. /* gdemo.c - Graphics demo program */
  2.  
  3. /************************************************************************/
  4. /*    Copyright (C) 1986-1988 Phar Lap Software, Inc.            */
  5. /*    Unpublished - rights reserved under the Copyright Laws of the    */
  6. /*    United States.  Use, duplication, or disclosure by the         */
  7. /*    Government is subject to restrictions as set forth in         */
  8. /*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  9. /*    Computer Software clause at 252.227-7013.            */
  10. /*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  11. /************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <time.h>
  16.  
  17. /*
  18.  * Include the Microsoft graphics library definition file.  Before we do
  19.  * this, we will undefine the keywords cdecl and far so that we will
  20.  * be able to compile the function prototypes.  High C-386 v1.6 doesn't
  21.  * like the cdecl keyword and we don't really need it anyway.
  22.  * We undefine the far keyword because protected mode programs run
  23.  * in flat model and will want to pass in near pointers to buffers
  24.  * when they call graphics routines.
  25.  */
  26. #define cdecl
  27. #define far
  28. #include "graph.h"
  29. #undef far
  30. #undef cdecl
  31.  
  32. /*
  33.  
  34. main - Main routine
  35.  
  36. */
  37.  
  38. main()
  39.  
  40. {
  41.  
  42.     struct videoconfig vc;    /* Video configuration */
  43.     int btime;        /* Execution time for buffered mode */
  44.     int ubtime;        /* Execution time for unbuffered mode */
  45.  
  46.     /* Get the current video mode */
  47.  
  48.     _getvideoconfig(&vc);
  49.  
  50.     /* Switch to CGA high res black/white graphics mode */
  51.  
  52.     _setvideomode(_HRESBW);
  53.  
  54.     /* Run the demo first in buffered mode if protected mode */
  55.  
  56.     _gbuffmode(1);
  57.     btime = randline();
  58.     
  59.     /* Run the demo again in unbuffered mode */
  60.  
  61.     _gbuffmode(0);
  62.     ubtime = randline();
  63.  
  64.     /* Restore the original video mode */
  65.  
  66.     _setvideomode(vc.mode);
  67.  
  68.     /* Print out the buffered and unbuffered execution times */
  69.  
  70.     printf("\n\n");
  71.     printf("Buffered mode execution time = %i milliseconds.\n",
  72.            btime);
  73.     printf("Unbuffered mode execution time = %i milliseconds.\n",
  74.            ubtime);
  75.  
  76.     /* Exit back to DOS */
  77.  
  78.     return 0;    
  79.  
  80. }
  81.  
  82.  
  83. /*
  84.  
  85. randline - Random line demo
  86.  
  87. */
  88.  
  89. int randline()
  90.  
  91. {
  92.  
  93.     int i;        /* Loop counter */
  94.     clock_t stime;    /* Start type */
  95.     clock_t etime;    /* End time */
  96.  
  97.     /* Reseed the random number generator to a constant 100 so that
  98.        we always generate the same random lines. */
  99.  
  100.     srand(100);
  101.  
  102.     /* Start the clock */
  103.  
  104.     stime = clock();
  105.  
  106.     /* The demo code clears the screen and randomly draws 1000 lines */
  107.  
  108.     _clearscreen(_GCLEARSCREEN);
  109.     for(i = 0; i < 1000; ++i)
  110.     {
  111.         _fmoveto(randx(), randy());
  112.         _lineto(randx(), randy());
  113.     }
  114.  
  115.     /* Stop the clock */
  116.  
  117.     etime = clock();
  118.  
  119.     /* Return withe the elapse execution time in milliseconds */
  120.  
  121.     return (int)((1000L * (etime - stime)) / CLK_TCK);
  122.  
  123. }
  124.  
  125.  
  126. /*
  127.  
  128. randx - Generate a random X coordinate value
  129.  
  130. */
  131.  
  132. int randx()
  133.  
  134. {
  135.     
  136.     return rand() % 640;
  137.  
  138. }
  139.  
  140.  
  141. /*
  142.  
  143. randy - Generate a random Y coordinate value
  144.  
  145. */
  146.  
  147. int randy()
  148.  
  149. {
  150.     
  151.     return rand() % 200;
  152.  
  153. }
  154.