home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / ks_cwarp.zip / KS_CWARP.CPP < prev    next >
C/C++ Source or Header  |  1995-10-10  |  3KB  |  175 lines

  1. //ks_cwarp.cpp : Circle xor warp
  2. //
  3. //Idea from FC's 2nd real, though I didn't spend much
  4. //time getting it to look the same. I'm pretty new to
  5. //asm so if you can optimise the inner loop, tell me.
  6. //
  7. //Compile with bcc.
  8. //
  9. //Comments/Suggestions welcome : ks2@st-andrews.ac.uk
  10. //
  11. //I am not currently a member of any group so if you
  12. //want me, mail me.
  13. //
  14. //Keith/Pixel Magic
  15.  
  16. #include <math.h>
  17. #include <alloc.h>
  18. #include <conio.h>
  19. #include <dos.h>
  20.  
  21. char far* bm1;        //Circle bitmaps
  22. char far* bm2;
  23. char far* vga;        //13h screen
  24. char far* mov1[256];    //Pointers used when moving bitmaps
  25. char far* mov2[256];
  26. char warp[256];        //Horizontal warping offsets
  27.  
  28. unsigned int vgaseg=0xA000;
  29.  
  30. void main()
  31. {
  32.  char far* tmp;
  33.  
  34.  bm1=(char far*)farmalloc(0xFFFF);
  35.  bm2=(char far*)farmalloc(0xFFFF);
  36.  
  37.  if(!bm1||!bm2) return;
  38.  
  39.  unsigned segbm1=FP_SEG(bm1);
  40.  unsigned segbm2=FP_SEG(bm2);
  41.  
  42.  long i;
  43.  long j;
  44.  
  45.  int s=10;            //size of rings
  46.  
  47.  vga=(char far*)MK_FP(0xA000,0);
  48.  
  49.  tmp=bm1;
  50.  
  51.  for(j=-99;j<101;j++)
  52.     for(i=-159;i<161;i++) {
  53.         long dist=i*i+j*j;
  54.         float sqr=sqrt(dist);
  55.         *(tmp++)=((int)(sqr/(float)s)%2) ? 1 : 2;
  56.         }
  57.  
  58.  tmp=bm2;
  59.  
  60.  for(j=-99;j<101;j++)
  61.     for(i=-159;i<161;i++) {
  62.         long dist=i*i+j*j;
  63.         float sqr=sqrt(dist);
  64.         *(tmp++)=((int)(sqr/(float)s)%2==0) ? 3 : 4;
  65.         }
  66.  
  67.  for(i=0;i<256;i++) {
  68.  
  69.     long x=80.0*cos(((M_PI*2.0)/256.0)*(float)i);
  70.     long y=50.0*sin(((M_PI*2.0)/256.0)*(float)i);
  71.  
  72.     x+=80;
  73.     y+=50;
  74.  
  75.     mov1[i]=&bm1[x+y*320];
  76.  
  77.     x=80.0*cos(((M_PI*4.0)/256.0)*(float)i);    //2*Speed
  78.     y=50.0*sin(((M_PI*4.0)/256.0)*(float)i);
  79.  
  80.     x+=80;
  81.     y+=50;
  82.  
  83.     mov2[i]=&bm2[x+y*320];
  84.     }
  85.  
  86.  for(i=0;i<256;i++) warp[i]=20.0*cos(((M_PI*8.0)/256.0)*(float)i);
  87.  
  88.  vga+=(80+320*50);    //get vga at center of screen (160x50)
  89.  
  90.  unsigned char c=0;
  91.  
  92.  unsigned char x,y;
  93.  
  94.  asm mov ah,0
  95.  asm mov al,13h
  96.  asm int 10h
  97.  
  98.  while(!kbhit()) {
  99.  
  100.     char far* tmpbm1=mov1[c];
  101.     char far* tmpbm2=mov2[c];
  102.     char far* tmpwarp1;
  103.     char far* tmpwarp2;
  104.  
  105.     c++;
  106.  
  107.     tmp=vga;
  108.  
  109.     unsigned char w;
  110.  
  111.     for(y=0;y<100;y++) {
  112.  
  113. //          asm push ax
  114.         asm mov al,c
  115.         asm add al,y
  116.         asm mov w,al
  117. //          asm pop ax
  118.         tmpwarp1=tmpbm1+warp[w];
  119.         tmpwarp2=tmpbm2+warp[255-w];
  120.  
  121.         asm push di
  122.         asm push si
  123.  
  124. //Check with td if ax,cx,bx are in use
  125.  
  126. //          asm push cx
  127. //          asm push ax
  128. //          asm push bx
  129.  
  130.         asm mov di,OFFSET tmpwarp1
  131.         asm mov si,OFFSET tmpwarp2
  132.  
  133.         asm mov cx,OFFSET tmp
  134.         asm mov bx,cx
  135.         asm add bx,160        //loop 160 times
  136.  
  137.         loop:
  138.  
  139.         asm mov es,segbm1
  140.         asm mov al,[es:di]
  141.         asm mov es,segbm2
  142.         asm mov ah,[es:si]
  143.         asm inc di
  144.         asm inc si
  145.  
  146.         asm xor al,ah
  147.  
  148.         asm mov es,vgaseg
  149.         asm xchg di,cx
  150.         asm stosb
  151.         asm xchg cx,di
  152.  
  153.         asm cmp cx,bx
  154.         asm jne loop
  155.  
  156. //          asm pop bx
  157. //          asm pop ax
  158. //          asm pop cx
  159.  
  160.         asm pop si
  161.         asm pop di
  162.  
  163.         tmp+=320;
  164.         tmpbm1+=320;
  165.         tmpbm2+=320; }
  166.  }
  167.  
  168.  getch();
  169.  
  170.  asm mov ah,0
  171.  asm mov al,3
  172.  asm int 10h
  173. }
  174.  
  175.