home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pctech / pctj1188.arc / STRIPCH.C < prev    next >
C/C++ Source or Header  |  1988-09-06  |  4KB  |  123 lines

  1. #include        <stdio.h>       /* printf() */ 
  2. #include        <math.h>        /* sin() */ 
  3. #include        <dos.h>         /* int86() */ 
  4.  
  5. #define XEND    640 
  6. #define YEND    480 
  7. #define VPAGESIZE       ((XEND/8)*YEND) 
  8.  
  9. void SplitScreen( int ); 
  10. void ScreenOrigin( int, int ); 
  11. void SetPixel( int, int, int, int ); 
  12. void SetVideoMode( int ); 
  13.  
  14. union REGS      regs;           /* defined in DOS.H; used by int86() */ 
  15.  
  16.  
  17. main() 
  18.         int                     i; 
  19.         int                     x,y; 
  20.         long                    lVBufOffset; 
  21.         unsigned char far *     lpVBufByte; 
  22.         unsigned int far *      lpCRT_LEN = (int far *)0x0040004C; 
  23.  
  24.  
  25.         /* select 640 by 480 16-color mode */ 
  26.         SetVideoMode( 0x12 ); 
  27.         printf( "This is 640 by 480 16-color graphics mode." ); 
  28.  
  29.         /* initialize video page 1 */ 
  30.         printf( "\nDrawing grid lines in video page 1 ..." );  
  31.         *lpCRT_LEN = VPAGESIZE;                 /* update ROM BIOS variable */ 
  32.         for( lVBufOffset=VPAGESIZE; lVBufOffset < 0x10000L; lVBufOffset++ ) 
  33.         { 
  34.           lpVBufByte = (unsigned char far *)(0xA0000000L + lVBufOffset); 
  35.           *lpVBufByte = 0;                      /* zero all pixels */ 
  36.         } 
  37.  
  38.         for( x=0; x<XEND; x+=40 )               /* draw vertical lines */ 
  39.           for( y=0; y<150; y++ ) 
  40.             SetPixel( x, y, 1, 2 );     /* video page 1, pixel color 2 */ 
  41.  
  42.         /* split the screen */ 
  43.         SplitScreen( 0 ); 
  44.         ScreenOrigin( 0, YEND ); 
  45.  
  46.         printf( "\nSplitting .. " ); 
  47.  
  48.         for( y=1; y<=150; y++ ) 
  49.           SplitScreen( y ); 
  50.  
  51.  
  52.         /* draw a sine wave and pan from right to left while doing so */ 
  53.         printf( "\nHorizontal Panning ..." ); 
  54.  
  55.         for( i=0; i<3; i++ )            /* do this for 3 screen widths */ 
  56.         { 
  57.           for( x=1; x<=XEND; x++ ) 
  58.           { 
  59.             if( i )             /* erase previously-drawn pixel */ 
  60.             { 
  61.               y = 75 + (int)(75.0 * sin( 0.03*(double)(x+(i-1)*XEND) ) ); 
  62.               if( (x-1) % 40 )                  /* use correct color for .. */ 
  63.                 SetPixel( x-1, y, 1, 0 );               /* .. vertical bars */ 
  64.               else 
  65.                 SetPixel( x-1, y, 1, 2 ); 
  66.             } 
  67.  
  68.             /* increment the screen origin (pan) */ 
  69.             ScreenOrigin( x, YEND ); 
  70.  
  71.             /* set new pixel */ 
  72.             y = 75 + (int)(75.0 * sin( 0.03*(double)(x+i*XEND) ) ); 
  73.             SetPixel( x-1, y, 1, 7 ); 
  74.           } 
  75.         } 
  76.  
  77.         /* pan vertically, just to show how it looks */ 
  78.         printf( "\nVertical Panning ..." ); 
  79.         for( i=0; i<150; i++ ) 
  80.           ScreenOrigin( 0, YEND+i ); 
  81.  
  82.         for( ; i>=0; --i ) 
  83.           ScreenOrigin( 0, YEND+i ); 
  84.  
  85.         /* undo the split screen */ 
  86.         printf( "\nUnsplitting .." ); 
  87.         for( y=150; y>=0; --y ) 
  88.           SplitScreen( y ); 
  89.  
  90.         ScreenOrigin( 0, 0 ); 
  91.         SplitScreen( 0x3FF ); 
  92.  
  93.         printf( "\nDone." ); 
  94.  
  95.  
  96. void SetVideoMode( mode ) 
  97. int     mode; 
  98.         /* establish the specified ROM BIOS video mode */ 
  99.         regs.h.ah = 0; 
  100.         regs.h.al = mode; 
  101.         int86( 0x10, ®s, ®s ); 
  102.  
  103.  
  104. void SetPixel( x, y, vpage, value ) 
  105. int     x, y;                   /* pixel x-y coordinates */ 
  106. int     vpage;                  /* ROM BIOS video page */ 
  107. int     value;                  /* pixel value */ 
  108.         /* setup for ROM BIOS function */ 
  109.         regs.h.ah = 0x0C; 
  110.         regs.h.al = value; 
  111.         regs.h.bh = vpage; 
  112.         regs.x.cx = x; 
  113.         regs.x.dx = y; 
  114.  
  115.         /* use ROM BIOS function to set pixel */ 
  116.         int86( 0x10, ®s, ®s ); 
  117.