home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / graphic / linefct.pas < prev    next >
Pascal/Delphi Source File  |  1995-07-28  |  2KB  |  63 lines

  1. Uses Crt;
  2.  
  3. Var x:Word;
  4.  
  5. Procedure PutPixel(x,y,col:word);assembler;
  6. {sets pixel (x/y) to color col (Mode 13h)}
  7. asm
  8.   mov ax,0a000h                 {load segment}
  9.   mov es,ax
  10.   mov ax,320                    {Offset = Y*320 + X}
  11.   mul y
  12.   add ax,x
  13.   mov di,ax                     {load offset}
  14.   mov al,byte ptr col           {load color}
  15.   mov es:[di],al                {and set pixel}
  16. End;
  17.  
  18. Procedure Line(x1,y1,x2,y2,col:Word);assembler;
  19. asm
  20.   {register used:
  21.     bx/cx: Fractional/integer portion of of y-coordinate
  22.     si   : fractional portion of increase}
  23.   mov si,x1                     {load x with initial value}
  24.   mov x,si
  25.   sub si,x2                     {and form x-difference (in si)}
  26.  
  27.   mov ax,y1                     {load y (saved in bx) with initial value}
  28.   mov bx,ax
  29.   sub ax,y2                     {and form y-difference (in ax)}
  30.  
  31.   mov cx,100                    {expand y-difference for computing accuracy}
  32.   imul cx
  33.   idiv si                       {and divide by x-diff (increase)}
  34.   mov si,ax                     {save increase in si}
  35.  
  36.   xor cx,cx                     {fractional portion of y-coordinate to 0}
  37.  
  38. @lp:
  39.   push x                        {x and integer portion of y to PutPixel}
  40.   push bx
  41.   push col
  42.   call PutPixel
  43.  
  44.   add cx,si                     {increment y-fractional portion}
  45.   cmp cx,100                    {fractional portion overflow}
  46.   jb @no_overflow               {no, then continue}
  47.   sub cx,100                    {otherwise decrement fractional portion}
  48.   inc bx                        {and increment integer portion}
  49.  
  50. @no_overflow:
  51.   inc x                         {increment x also}
  52.   mov ax,x
  53.   cmp ax,x2                     {end reached ?}
  54.   jb @lp                        {no, then next pass}
  55. end;
  56.  
  57. Begin
  58.   asm mov ax,0013h; int 10h end;{enable Mode 13h}
  59.   Line(10,10,100,50,1);         {draw line}
  60.   ReadLn;
  61.   Textmode(3);
  62. End.
  63.