Oldies 2000: metaballs
Boy was I glad to remember that Dosbox can be used to run old Turbo Pascal programs! It makes me so nostalgic to see this running, and a bit sad to have lost the older things I had written in Pascal.
I was an assembly freak at the time and I remember being very proud of the routine below, which was used to render circles (not used in metaK as far as I know, but metaballs did rely heavily on that mode 13h library I wrote). I wrote the routine and the library from scratch using a text file describing the specifications of that VGA mode.
I remember that I first based the circle routine on mathematical rules and then identified sections that could be optimized to run faster. Today I can’t understand much in that code. If blogs existed at the time I’m sure I would have written a few posts about the techniques used to write and optimize that assembly library.
The library could load images, render all sorts of shapes, text, all these routine written in assembly for performance. I even remember that at some stage I had made a program that would display molecules in 3D with a homemade 3D engine based on that same mode 13h library. I think this program has been lost unfortunately.
For your personal enjoyment, you can download the executable and source code of that gem. You’ll need DosBox to run it though, as well as the knowledge of how to use DOS!.
Procedure Circle(x,y,r: integer);assembler; { Cercle... }
Var
y1,y2,x1,x2,i,r2: integer;
Asm
mov cx,x { Ma version du tracÇ de cercle, me semble plutìt rapide, }
sub cx,r { mais je n'ai pas cherchÇ Ö l'amÇliorer. }
@boucle:
mov ax,cx
sub ax,x
mul ax
mov bx,ax
mov ax,r
mul ax
sub ax,bx { ax= r˝ - (i-x)˝ }
mov r2,ax
mov ax,0
mov bx,ax
@racine:
mov ax,bx
inc ax
mov bx,ax
mul ax
cmp ax,r2
jl @racine
mov ax,bx
mov bx,y
sub bx,ax
add ax,y { ax= y+sqrt(r˝- (i-x)˝ } { bx= y-sqrt(r˝- (i-x)˝ }
push ax
les di,_buffer
mov ax,320
mul bx
add ax,cx
add di,ax
mov al,_couleur
mov es:[di],al
pop ax
mov bx,ax
les di,_buffer
mov ax,320
mul bx
add ax,cx
add di,ax
mov al,_couleur
mov es:[di],al
mov ax,x
add ax,r
add cx,1
cmp cx,ax
jne @boucle
mov cx,y
sub cx,r
@boucle2:
mov ax,cx
sub ax,y
mul ax
mov bx,ax
mov ax,r
mul ax
sub ax,bx { ax= r˝ - (i-y)˝ }
mov r2,ax
mov ax,0
mov bx,ax
@racine2:
mov ax,bx
inc ax
mov bx,ax
mul ax
cmp ax,r2
jl @racine2
mov ax,bx
mov bx,x
sub bx,ax
add ax,x { ax= x+sqrt(r˝- (i-y)˝ } { bx= y-sqrt(r˝- (i-y)˝ }
cmp _style,0
je @s0
inc ax
cmp _style,1
je @s1
@s0:
push ax
les di,_buffer
mov ax,320
mul cx
add ax,bx
add di,ax
mov al,_couleur
mov es:[di],al
pop ax
mov bx,ax
les di,_buffer
mov ax,320
mul cx
add ax,bx
add di,ax
mov al,_couleur
mov es:[di],al
jmp @fin
@s1:
push ax
les di,_buffer
mov ax,320
mul cx
add ax,bx
add di,ax
mov al,_couleur
mov es:[di],al
pop ax
inc bx
cmp bx,ax
jne @s1
jmp @fin
@fin:
mov ax,y
add ax,r
add cx,1
cmp cx,ax
jne @boucle2
End;


