home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / demo / demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.7 KB  |  82 lines

  1. /******************************************************************************
  2. *                                                                             *
  3. * Name:  demo.c                                                               *
  4. *                                                                             *
  5. * Description:  This program shows how assembly language video graphics       *
  6. *                can be built into a high-level program.                      *
  7. *                                                                             *
  8. *                                                                             *
  9. * Notes:        Use  MAKE DEMO  to build this program.  You need the          *
  10. *                following tools:                                             *
  11. *                                                                             *
  12. *                    - Microsoft C                                            *
  13. *                    - Microsoft Macro Assembler                              *
  14. *                    - LINK                                                   *
  15. *                                                                             *
  16. *                                                                             *
  17. *               Use an IBM CGA, EGA, or VGA, or compatible hardware.          *
  18. *                                                                             *
  19. ******************************************************************************/
  20.  
  21. #define    TRUE        1
  22. #define    FALSE        0
  23.  
  24. #define    CGA        2
  25. #define    EGA        3
  26. #define    MCGA        4
  27. #define    VGA        5
  28.  
  29. #define    Xmax        319
  30. #define    Ymax        199
  31.  
  32. #define FivePI          (double)(5*3.1415926535)
  33.  
  34. main()
  35. {
  36.     static struct            /* for video ID */
  37.     {
  38.       char    Subsystem;
  39.       char    Display;
  40.     }        VIDstruct[2];
  41.  
  42.     int    VIDok = FALSE;
  43.  
  44.     int    x,y,Fgd;
  45.     int    i;
  46.     double    sin();
  47.  
  48.  
  49. /* verify presence of CGA-compatible hardware */
  50.  
  51.     VideoID( VIDstruct );
  52.  
  53.     for( i=0; (i<=1) && !VIDok; i++ )
  54.       VIDok = ( VIDstruct[i].Subsystem == CGA ) ||
  55.               ( VIDstruct[i].Subsystem == EGA ) ||
  56.               ( VIDstruct[i].Subsystem == MCGA ) ||
  57.               ( VIDstruct[i].Subsystem == VGA );
  58.       
  59.     if( !VIDok )
  60.     {
  61.       printf( "\nCan't find compatible video hardware\n");
  62.       exit( 1 );
  63.     }
  64.  
  65. /* draw something in 320x200 4-color mode */
  66.  
  67.     SetVmode( 4 );            /* BIOS mode 4 is 320x200 4-color */
  68.  
  69.     Line04( 0, Ymax/2, Xmax, Ymax/2, 3 );
  70.  
  71.     for( x=0; x<=Xmax; x++ )
  72.     {
  73.       y = sin( FivePI * (double)x/(double)Xmax ) * (double)(Ymax/2);
  74.       y += Ymax/2;
  75.  
  76.       Fgd = ( x%10 ? 2 : 3 );    /* select foreground pixel value */
  77.  
  78.       Line04( x, y, x, Ymax/2, Fgd );    /* draw a line or two */
  79.       Line04( x, Ymax-y, x, Ymax/2, 5-Fgd );
  80.     }
  81. }
  82.