home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / MISC / LINEAR.ZIP / TEST.C < prev   
C/C++ Source or Header  |  1995-10-27  |  2KB  |  108 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <dos.h>
  5. #include <string.h>
  6. #include <time.h>
  7.  
  8. #include "paging.h"
  9.  
  10. char * VPtr;
  11.  
  12. #define Plot(x,y,c)
  13.  
  14. void Line(int xd,int yd,int xf,int yf,int Color)
  15.   {
  16.   int i;
  17.   int Dx,Dy,Xi,Yi,Cumul,x,y;
  18.  
  19.   x=xd;
  20.   y=yd;
  21.  
  22.  
  23.   Xi=(xd<xf?+1:-1);
  24.   Yi=(yd<yf?+1:-1);
  25.   Dx=abs(xd-xf);
  26.   Dy=abs(yd-yf);
  27.  
  28.   y*=640;
  29.   Yi*=640;
  30.  
  31.   VPtr[x+y]=Color;
  32.   if (Dx>Dy)
  33.     {
  34.     Cumul=Dx >> 1;
  35.     for(i=1;i<=Dx;i++)
  36.       {
  37.       x+=Xi;
  38.       Cumul+=Dy;
  39.       if (Cumul>=Dx)
  40.         {
  41.         Cumul-=Dx;
  42.         y+=Yi;
  43.         }
  44.       VPtr[x+y]=Color;
  45.       }
  46.     }
  47.   else
  48.     {
  49.     Cumul=Dy >> 1;
  50.     for(i=1;i<=Dy;i++)
  51.       {
  52.       y+=Yi;
  53.       Cumul+=Dx;
  54.       if (Cumul>=Dy)
  55.         {
  56.         Cumul-=Dy;
  57.         x+=Xi;
  58.         }
  59.       VPtr[x+y]=Color;
  60.       }
  61.     }
  62.   }
  63.  
  64.  
  65. void main(void)
  66.   {
  67.   union REGS Regs;
  68.   int i,k=0;
  69.  
  70.   // Set to VESA 640x480 256 colors
  71.  
  72.   Regs.w.ax=0x4f02;
  73.   Regs.w.bx=0x101;
  74.   int386(0x10,&Regs,&Regs);
  75.  
  76.   // allocate 1Mb Video buffer
  77.   VPtr=(char *)GetLinearVideo(1);
  78.   if (VPtr!=NULL)
  79.     {
  80.     for(;!kbhit();)
  81.       memset(VPtr,rand(),640*480);
  82.     getch();
  83.  
  84.     // set lines
  85.  
  86.     while(!kbhit())
  87.       for(i=0;i<480;i++)
  88.         memset(VPtr+i*640,k++,640);
  89.  
  90.     getch();
  91.     memset(VPtr,0,640*480);  // cls ...
  92.     while(!kbhit())
  93.       Line(rand() % 640,rand() % 480,rand() % 640,rand() % 480,k++);
  94.  
  95.     // Speedy isn't it ?
  96.  
  97.     CloseLinearVideo();
  98.  
  99.     Regs.w.ax=0x03;
  100.     int386(0x10,&Regs,&Regs);
  101.  
  102.     return;
  103.     }
  104.  
  105.   Regs.w.ax=0x03;
  106.   int386(0x10,&Regs,&Regs);
  107.   }
  108.