X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=dos1%2Fc.asm;h=c3c62c9d6a7deb4cfe11610ff89cfd3549f4556e;hb=HEAD;hp=d7a228f272c5d1f6a30da9cc08dd4859d53199a6;hpb=e410cee4738a4343308be88295af0abca8c9f1a2;p=vtuts diff --git a/dos1/c.asm b/dos1/c.asm index d7a228f..c3c62c9 100644 --- a/dos1/c.asm +++ b/dos1/c.asm @@ -1,5 +1,12 @@ -; Lowest yet: 277 - +; Sierpbounceski / Mindlapse +; -------------------------- +; Sierpinski fractal, bummed to 253b down from the 416b initial version +; Author: John Tsiombikas (Nuclear / Mindlapse) +; This code is public domain +; -------------------------- +; Build for DOS: nasm -o sierpb.com -f bin sierpb.asm +; Build as boot sector: nasm -o sierpb.img -f bin -DBOOTSECT sierpb.asm +; -------------------------- bits 16 %ifdef BOOTSECT org 7c00h @@ -12,6 +19,7 @@ SHADOW_OFFS equ 5 SIERP_PT equ code_end RANDVAL equ code_end + 4 +SIERP_VERTS equ code_end + 8 %macro WAIT_VBLANK 0 @@ -22,6 +30,18 @@ RANDVAL equ code_end + 4 jz .notblank ; loop while vblank bit is 0 (visible area) %endmacro +%macro RAND 0 + ; random number generator + mov ax, [randval] + mov bx, ax + shr bx, 7 + xor ax, bx + mov bx, ax + shl bx, 9 + xor ax, bx + mov [randval], ax +%endmacro + start: %ifdef BOOTSECT @@ -30,8 +50,7 @@ start: mov es, ax mov ss, ax jmp 00:.setcs -.setcs: - mov sp, 0 +.setcs: xor sp, sp %endif mov al, 13h int 10h @@ -41,14 +60,36 @@ start: add ax, 1000h mov es, ax - ; setup palette for the effect - ; - bg color (0) - ; - shadow color (1) - ; - fractal color (2) +mainloop: + ; --- animate start --- + mov cx, 3 + mov di, sierp_verts + mov si, sierp_vel +.loop: + mov bx, 4 +.xyloop: + mov ax, [di] ; grab vertex X + add ax, [si] ; add velocity X + jl .xout + cmp ax, [bx + bounds - 2] + jge .xout + jmp .skip_xflip +.xout: + sub ax, [si] ; revert to previous X + neg word [si] ; negate velocity X +.skip_xflip: + mov [di], ax ; update vertex X + + ; to do the same for Y increment edi and esi by 2 + add di, 2 + add si, 2 + sub bx, 2 + jnz .xyloop + dec cx + jnz .loop + ; --- animate end --- -mainloop: - call animate ; clear the framebuffer mov al, 128 @@ -56,25 +97,26 @@ mainloop: xor di, di rep stosb + mov si, setcol + 1 ; draw shadow - mov si, 5 - mov byte [setcol + 1], 199 ; shadow color + mov bp, 5 + mov byte [si], 199 ; shadow color call drawsierp ; draw fractal - xor si, si - mov byte [setcol + 1], 2 ; fractal color + xor bp, bp + mov byte [si], 48h ; fractal color call drawsierp ; copy framebuffer to video ram push ds push es - ; point ds:si (source) to es:0 - mov ax, es - mov ds, ax + ; point ds:si (source) to es:0 (framebuffer) + push es + pop ds xor si, si ; point es:di (dest) to a000:0 - mov ax, 0a000h - mov es, ax + push word 0a000h + pop es xor di, di mov cx, 32000 WAIT_VBLANK @@ -106,7 +148,7 @@ drawsierp: ; number of iterations in cx mov cx, NUM_POINTS dsloop: ; pick a vertex at random and move half-way there - call rand + RAND mov bx, 3 xor dx, dx div bx ; dx is now rand % 3 @@ -124,7 +166,7 @@ dsloop: ; pick a vertex at random and move half-way there add ax, [SIERP_PT + 2] shr ax, 1 mov [SIERP_PT + 2], ax ; store the reuslting Y back to [SIERP_PT + 2] - add ax, si ; add offset + add ax, bp ; add offset mov bx, ax shl ax, 8 shl bx, 6 @@ -144,56 +186,12 @@ sierp_vel: dw 1, 1 dw -1, 1 dw -1, -1 +bounds dw 200 - SHADOW_OFFS + dw 320 - SHADOW_OFFS -animate: - mov cx, 3 - mov di, sierp_verts - mov si, sierp_vel -.loop: - mov ax, [di] ; grab vertex X - add ax, [si] ; add velocity X - jl .xout - cmp ax, 320-SHADOW_OFFS - jge .xout - jmp .skip_xflip -.xout: - sub ax, [si] ; revert to previous X - neg word [si] ; negate velocity X -.skip_xflip: - mov [di], ax ; update vertex X - - ; to do the same for Y increment edi and esi by 2 - add di, 2 - add si, 2 - mov ax, [di] ; grab vertex Y - add ax, [si] ; add velocity Y - jl .yout - cmp ax, 200-SHADOW_OFFS - jge .yout - jmp .skip_yflip -.yout: - sub ax, [si] ; revert to previous Y - neg word [si] ; negate velocity Y -.skip_yflip: - mov [di], ax ; update vertex Y - - add di, 2 - add si, 2 - dec cx - jnz .loop - ret ; random number generator -rand: - mov ax, [randval] - mov bx, ax - shr bx, 7 - xor ax, bx - mov bx, ax - shl bx, 9 - xor ax, bx - mov [randval], ax - ret +;rand: ; mov eax, [RANDVAL] ; mul dword [randmul] ; add eax, 12345