home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / SPRITE.ZIP / BITMAP.C
Encoding:
C/C++ Source or Header  |  1990-07-10  |  2.1 KB  |  92 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. #include <graphics.h>
  6.  
  7. #define Bit(x) (1 << x)
  8.  
  9. void Sprite( int x, int y, unsigned char *bitmap, int byteswide, int rows )
  10. {
  11.     char far *ptr;
  12.     register int i, j;
  13.     unsigned char XOR;
  14.     unsigned char SAVE;
  15.     int  Shift;
  16.     unsigned char ANDVAL = 0;
  17.     int  YStart;
  18.     int  SaveShift;
  19.  
  20.     Shift  = x % 8;
  21.     for (i=0; i<Shift; ++i)
  22.         ANDVAL += Bit(i);
  23.     SaveShift = 8 - Shift;
  24.  
  25.     YStart = y * 80 + x / 8;
  26.  
  27.     for (j=0; j<rows; ++j) {
  28.         ptr = MK_FP( 0xA000U, YStart );
  29.         YStart += 80;
  30.         SAVE = 0;
  31.         for (i=0; i<byteswide; ++i) {
  32.             XOR = (*bitmap >> Shift) + SAVE;
  33.             SAVE = ( (*bitmap & ANDVAL) << SaveShift );
  34.             *ptr++ ^= XOR;
  35.             bitmap++;
  36.         }
  37.         *ptr   ^= SAVE;
  38.     }
  39. }
  40.  
  41.  
  42. unsigned char LetterA[145] = {
  43.     0x00,  0x00,  0x80,  0x00,  0x00,
  44.     0x00,  0x01,  0xc0,  0x00,  0x00,
  45.     0x00,  0x01,  0xc0,  0x00,  0x00,
  46.     0x00,  0x01,  0xe0,  0x00,  0x00,
  47.     0x00,  0x03,  0xe0,  0x00,  0x00,
  48.     0x00,  0x03,  0xf0,  0x00,  0x00,
  49.     0x00,  0x06,  0xf0,  0x00,  0x00,
  50.     0x00,  0x06,  0xf8,  0x00,  0x00,
  51.     0x00,  0x0c,  0xf8,  0x00,  0x00,
  52.     0x00,  0x0c,  0x7c,  0x00,  0x00,
  53.     0x00,  0x18,  0x7c,  0x00,  0x00,
  54.     0x00,  0x18,  0x3e,  0x00,  0x00,
  55.     0x00,  0x30,  0x3e,  0x00,  0x00,
  56.     0x00,  0x30,  0x1f,  0x00,  0x00,
  57.     0x00,  0x60,  0x1f,  0x00,  0x00,
  58.     0x00,  0x60,  0x0f,  0x00,  0x00,
  59.     0x00,  0xc0,  0x0f,  0x80,  0x00,
  60.     0x00,  0xc0,  0x0f,  0x80,  0x00,
  61.     0x01,  0xff,  0xff,  0xc0,  0x00,
  62.     0x01,  0xff,  0xff,  0xc0,  0x00,
  63.     0x03,  0x80,  0x03,  0xe0,  0x00,
  64.     0x03,  0x00,  0x03,  0xe0,  0x00,
  65.     0x07,  0x00,  0x01,  0xf0,  0x00,
  66.     0x06,  0x00,  0x01,  0xf0,  0x00,
  67.     0x0e,  0x00,  0x00,  0xf8,  0x00,
  68.     0x0c,  0x00,  0x00,  0xf8,  0x00,
  69.     0x1c,  0x00,  0x00,  0xfc,  0x00,
  70.     0x3e,  0x00,  0x00,  0xfe,  0x00,
  71.     0xff,  0xc0,  0x07,  0xff,  0x80
  72. };
  73.  
  74. void main()
  75. {
  76.     int graphdriver=VGA, graphmode=VGAHI;
  77.     register int i;
  78.     int x=8, y=8;
  79.  
  80.     initgraph(&graphdriver,&graphmode,"");
  81.     for (i=0; i<200; i++) {
  82.         Sprite( x, y, LetterA, 5, 29 );
  83.         x += 41;
  84.         if ( x > 610 ) {
  85.             x = 8;
  86.             y += 33;
  87.         }
  88.     }
  89.     getch();
  90.     closegraph();
  91. }
  92.