Mogh
12-19-2007, 10:54 PM
*** metab.asm
; 2D-Metaballs in 256 bytes
; Coded: Mogh at DXTH4X.COM
.model tiny, stdcall
.386
.code
option casemap :none
org 100h
BLOB_SIZE equ (offset blob1_end - offset blobs)
start:
push 0A000h
pop es
mov al, 13h
int 10h
xor cx, cx
make_palette:
mov dx, 3c8h
mov al, cl
out dx, al
inc dx
shr ax, 2
out dx, al
out dx, al
out dx, al
loop make_palette ; slow, but small
main_loop:
xor di, di
rend_screen:
mov bx, offset blobs
fldz
cwd
mov ax, di
mov cx, 320
div cx
@@:
mov tmp, dx
fild tmp
fsub real4 ptr [bx]
fmul st, st
mov tmp, ax
fild tmp
fsub real4 ptr [bx+4]
fmul st, st
fadd
fidivr word ptr [bx+8]
fadd
add bl, (BLOB_SIZE and 0FFh)
test bl, bl
jnz @B
fcom m_0_09
fnstsw ax
sahf
jc @F
mov al, 255
jmp put_pixel
@@:
fcom m_0_01
fnstsw ax
sahf
jc @F
fimul m_2700
fist tmp
mov al, byte ptr [tmp]
jmp put_pixel
@@:
mov al, 27
put_pixel:
fstp st
mov [di+500h], al
inc di
cmp di, (320*200)
jnz rend_screen
mov bx, offset blobs
@@:
fld counter
fld st
fidiv word ptr [bx+10]
fsin
fimul blob1_s
fadd real4 ptr [bx]
fstp real4 ptr [bx]
fidiv word ptr [bx+12]
fcos
fimul blobs_ca
fadd real4 ptr [bx+4]
fstp real4 ptr [bx+4]
add bl, (BLOB_SIZE and 0FFh)
test bl, bl
jnz @B
fld counter
fadd counter_a
fstp counter
mov si, 500h
xor di, di
mov cx, (320*200)/2
rep movsw
in al, 60h
dec al
jnz main_loop
mov ax, 03h
int 10h
ret
; data ---
m_0_09 real4 0.09
m_0_01 real4 0.01
m_2700 word 2700
counter real4 0.0
counter_a real4 0.5
blobs_ca word 3
blobs:
blob1_x real4 15.0
blob1_y real4 105.0
blob1_rad word 64
blob1_s word 8
blob1_c word 9
blob1_end:
blob2_x real4 15.0
blob2_y real4 105.0
blob2_rad word 33
blob2_s word 9
blob2_c word 8
blobs_end:
tmp word 0
end start
*** make.bat
ml /AT /Cp /c /nologo metab.asm
link /nologo /tiny metab.obj,metab.com,,,,
Like beginners see: Assembly is hard, i learn it from school.
I didn't add comments much but i hope you understand a little bit..
; 2D-Metaballs in 256 bytes
; Coded: Mogh at DXTH4X.COM
.model tiny, stdcall
.386
.code
option casemap :none
org 100h
BLOB_SIZE equ (offset blob1_end - offset blobs)
start:
push 0A000h
pop es
mov al, 13h
int 10h
xor cx, cx
make_palette:
mov dx, 3c8h
mov al, cl
out dx, al
inc dx
shr ax, 2
out dx, al
out dx, al
out dx, al
loop make_palette ; slow, but small
main_loop:
xor di, di
rend_screen:
mov bx, offset blobs
fldz
cwd
mov ax, di
mov cx, 320
div cx
@@:
mov tmp, dx
fild tmp
fsub real4 ptr [bx]
fmul st, st
mov tmp, ax
fild tmp
fsub real4 ptr [bx+4]
fmul st, st
fadd
fidivr word ptr [bx+8]
fadd
add bl, (BLOB_SIZE and 0FFh)
test bl, bl
jnz @B
fcom m_0_09
fnstsw ax
sahf
jc @F
mov al, 255
jmp put_pixel
@@:
fcom m_0_01
fnstsw ax
sahf
jc @F
fimul m_2700
fist tmp
mov al, byte ptr [tmp]
jmp put_pixel
@@:
mov al, 27
put_pixel:
fstp st
mov [di+500h], al
inc di
cmp di, (320*200)
jnz rend_screen
mov bx, offset blobs
@@:
fld counter
fld st
fidiv word ptr [bx+10]
fsin
fimul blob1_s
fadd real4 ptr [bx]
fstp real4 ptr [bx]
fidiv word ptr [bx+12]
fcos
fimul blobs_ca
fadd real4 ptr [bx+4]
fstp real4 ptr [bx+4]
add bl, (BLOB_SIZE and 0FFh)
test bl, bl
jnz @B
fld counter
fadd counter_a
fstp counter
mov si, 500h
xor di, di
mov cx, (320*200)/2
rep movsw
in al, 60h
dec al
jnz main_loop
mov ax, 03h
int 10h
ret
; data ---
m_0_09 real4 0.09
m_0_01 real4 0.01
m_2700 word 2700
counter real4 0.0
counter_a real4 0.5
blobs_ca word 3
blobs:
blob1_x real4 15.0
blob1_y real4 105.0
blob1_rad word 64
blob1_s word 8
blob1_c word 9
blob1_end:
blob2_x real4 15.0
blob2_y real4 105.0
blob2_rad word 33
blob2_s word 9
blob2_c word 8
blobs_end:
tmp word 0
end start
*** make.bat
ml /AT /Cp /c /nologo metab.asm
link /nologo /tiny metab.obj,metab.com,,,,
Like beginners see: Assembly is hard, i learn it from school.
I didn't add comments much but i hope you understand a little bit..