14 RANDVAL equ code_end + 4
22 jz .notblank ; loop while vblank bit is 0 (visible area)
39 ; "allocate" the next segment for the framebuffer
44 ; setup palette for the effect
53 ; clear the framebuffer
61 mov byte [setcol + 1], 199 ; shadow color
65 mov byte [setcol + 1], 2 ; fractal color
68 ; copy framebuffer to video ram
71 ; point ds:si (source) to es:0
75 ; point es:di (dest) to a000:0
88 in al, 60h ; read pending scancode from the keyboard port (if any)
89 dec al ; ESC is 1, so decrement ...
90 jnz mainloop ; ... and loop as long as the result was not 0
92 ; switch back to text mode (mode 3)
99 ; draw sierpinski triangle
101 ; start from one of the vertices
102 mov ax, [sierp_verts]
103 mov bx, [sierp_verts + 2]
105 mov [SIERP_PT + 2], bx
106 ; number of iterations in cx
108 dsloop: ; pick a vertex at random and move half-way there
112 div bx ; dx is now rand % 3
113 ; put the vertex address in bx
117 ; add to SIERP_PT and divide by 2 to move half-way there
121 mov [SIERP_PT], ax ; store the resulting X back to [SIERP_PT]
122 mov di, ax ; save X coordinate in di
124 add ax, [SIERP_PT + 2]
126 mov [SIERP_PT + 2], ax ; store the reuslting Y back to [SIERP_PT + 2]
127 add ax, si ; add offset
131 add bx, ax ; bx = Y * 320
133 mov byte [es:bx + di], al
153 mov ax, [di] ; grab vertex X
154 add ax, [si] ; add velocity X
156 cmp ax, 320-SHADOW_OFFS
160 sub ax, [si] ; revert to previous X
161 neg word [si] ; negate velocity X
163 mov [di], ax ; update vertex X
165 ; to do the same for Y increment edi and esi by 2
168 mov ax, [di] ; grab vertex Y
169 add ax, [si] ; add velocity Y
171 cmp ax, 200-SHADOW_OFFS
175 sub ax, [si] ; revert to previous Y
176 neg word [si] ; negate velocity Y
178 mov [di], ax ; update vertex Y
186 ; random number generator
198 ; mul dword [randmul]
200 ; and eax, 0x7fffffff
205 ;randmul dd 1103515245
210 times 510-($-$$) db 0