1 ; Sierpbounceski / Mindlapse
2 ; --------------------------
3 ; Sierpinski fractal, bummed to 253b down from the 416b initial version
4 ; Author: John Tsiombikas (Nuclear / Mindlapse) <nuclear@member.fsf.org>
5 ; This code is public domain
6 ; --------------------------
7 ; Build for DOS: nasm -o sierpb.com -f bin sierpb.asm
8 ; Build as boot sector: nasm -o sierpb.img -f bin -DBOOTSECT sierpb.asm
9 ; --------------------------
21 RANDVAL equ code_end + 4
22 SIERP_VERTS equ code_end + 8
30 jz .notblank ; loop while vblank bit is 0 (visible area)
34 ; random number generator
58 ; "allocate" the next segment for the framebuffer
64 ; --- animate start ---
71 mov ax, [di] ; grab vertex X
72 add ax, [si] ; add velocity X
74 cmp ax, [bx + bounds - 2]
78 sub ax, [si] ; revert to previous X
79 neg word [si] ; negate velocity X
81 mov [di], ax ; update vertex X
83 ; to do the same for Y increment edi and esi by 2
94 ; clear the framebuffer
103 mov byte [si], 199 ; shadow color
107 mov byte [si], 48h ; fractal color
110 ; copy framebuffer to video ram
113 ; point ds:si (source) to es:0 (framebuffer)
117 ; point es:di (dest) to a000:0
130 in al, 60h ; read pending scancode from the keyboard port (if any)
131 dec al ; ESC is 1, so decrement ...
132 jnz mainloop ; ... and loop as long as the result was not 0
134 ; switch back to text mode (mode 3)
141 ; draw sierpinski triangle
143 ; start from one of the vertices
144 mov ax, [sierp_verts]
145 mov bx, [sierp_verts + 2]
147 mov [SIERP_PT + 2], bx
148 ; number of iterations in cx
150 dsloop: ; pick a vertex at random and move half-way there
154 div bx ; dx is now rand % 3
155 ; put the vertex address in bx
159 ; add to SIERP_PT and divide by 2 to move half-way there
163 mov [SIERP_PT], ax ; store the resulting X back to [SIERP_PT]
164 mov di, ax ; save X coordinate in di
166 add ax, [SIERP_PT + 2]
168 mov [SIERP_PT + 2], ax ; store the reuslting Y back to [SIERP_PT + 2]
169 add ax, bp ; add offset
173 add bx, ax ; bx = Y * 320
175 mov byte [es:bx + di], al
189 bounds dw 200 - SHADOW_OFFS
193 ; random number generator
196 ; mul dword [randmul]
198 ; and eax, 0x7fffffff
203 ;randmul dd 1103515245
208 times 510-($-$$) db 0