home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Underground
/
UNDERGROUND.ISO
/
graphic
/
linefct.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-07-28
|
2KB
|
63 lines
Uses Crt;
Var x:Word;
Procedure PutPixel(x,y,col:word);assembler;
{sets pixel (x/y) to color col (Mode 13h)}
asm
mov ax,0a000h {load segment}
mov es,ax
mov ax,320 {Offset = Y*320 + X}
mul y
add ax,x
mov di,ax {load offset}
mov al,byte ptr col {load color}
mov es:[di],al {and set pixel}
End;
Procedure Line(x1,y1,x2,y2,col:Word);assembler;
asm
{register used:
bx/cx: Fractional/integer portion of of y-coordinate
si : fractional portion of increase}
mov si,x1 {load x with initial value}
mov x,si
sub si,x2 {and form x-difference (in si)}
mov ax,y1 {load y (saved in bx) with initial value}
mov bx,ax
sub ax,y2 {and form y-difference (in ax)}
mov cx,100 {expand y-difference for computing accuracy}
imul cx
idiv si {and divide by x-diff (increase)}
mov si,ax {save increase in si}
xor cx,cx {fractional portion of y-coordinate to 0}
@lp:
push x {x and integer portion of y to PutPixel}
push bx
push col
call PutPixel
add cx,si {increment y-fractional portion}
cmp cx,100 {fractional portion overflow}
jb @no_overflow {no, then continue}
sub cx,100 {otherwise decrement fractional portion}
inc bx {and increment integer portion}
@no_overflow:
inc x {increment x also}
mov ax,x
cmp ax,x2 {end reached ?}
jb @lp {no, then next pass}
end;
Begin
asm mov ax,0013h; int 10h end;{enable Mode 13h}
Line(10,10,100,50,1); {draw line}
ReadLn;
Textmode(3);
End.