Optimal Coding 6 – 2D algorithms

Line and Circle drawing
Line-Drawing Algorithms
Bresenham’s line algorithm
Implementations in Delphi

Here is my old “Pascal” line drawing function for 256 color SVGA in DOS:
procedure LineSVGA256(x1,y1,x2,y2:word;c:byte);assembler;
var xtav,ytav,xdir,ydir:word;
asm mov dx,0ffffh; mov ax,0a000h; mov es,ax; mov ax,x1; mov bx,x2
sub ax,bx; jnc @negxdir; neg ax; neg dx
@negxdir: mov xtav,ax; mov xdir,dx; mov dx,0ffffh; mov ax,y1; mov bx,y2
sub ax,bx; jnc @negydir; neg ax; neg dx
@negydir: mov ytav,ax; mov ydir,dx; cmp ax,xtav; jc @vizsintes
@fuggoleges: or byte ptr cs:[@incdecf],00001000b; cmp xdir,1; jnz @i0; and byte ptr cs:[@incdecf],11110111b
@i0: or byte ptr cs:[@addsubf],00101000b; cmp ydir,1; jnz @i2; and byte ptr cs:[@addsubf],11010111b
@i2: mov cx,ytav; mov bx,cx; shr bx,1; inc cx; push bx
mov ax,y1; mov bx,VideoUResX; mul bx; add ax,x1; jnc @ide1; inc dx
@ide1: mov di,ax; mov ax,4f05h; xor bx,bx; int 10h; pop bx; mov al,c
@_0: mov es:[di],al
@addsubf: sub di,VideoUResX
jnc @05; add dx,ydir; push bx; mov ax,4f05h; xor bx,bx; int 10h; mov al,c; pop bx;
@05: add bx,xtav; cmp bx,ytav; jc @_1; sub bx,ytav;
@incdecf: dec di
jno @_1; add dx,xdir; push bx; mov ax,4f05h; xor bx,bx; int 10h; mov al,c; pop bx;
@_1: loop @_0; jmp @vege
@vizsintes: or byte ptr cs:[@addsubv],00101000b; cmp ydir,1; jnz @i1; and byte ptr cs:[@addsubv],11010111b
@i1: or byte ptr cs:[@incdecv],00001000b; cmp xdir,1; jnz @i3; and byte ptr cs:[@incdecv],11110111b
@i3:mov cx,xtav; mov bx,cx; shr bx,1; inc cx; push bx
mov ax,y1; mov bx,VideoUResX; mul bx; add ax,x1; jnc @ide2; inc dx
@ide2: mov di,ax; mov ax,4f05h; xor bx,bx; int 10h; pop bx; mov al,c
@_2: mov es:[di],al
@incdecv: dec di
jno @15; add dx,xdir; push bx; mov ax,4f05h; xor bx,bx; int 10h; mov al,c; pop bx;
@15: add bx,ytav; cmp bx,xtav; jc @_3; sub bx,xtav;
@addsubv: sub di,VideoUResX
jnc @_3; add dx,ydir; push bx; mov ax,4f05h; xor bx,bx; int 10h; mov al,c; pop bx;{}
@_3: loop @_2
@vege:
end;

Midpoint circle algorithm/Bresenham’s circle algorithm
Circle-Drawing Algorithms

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.