14 RANDVAL equ code_end + 4
22 jnz .inblank ; loop while vblank bit is 1 (in vblank)
26 jz .notblank ; loop while vblank bit is 0 (visible area)
43 ; "allocate" the next segment for the framebuffer
48 ; setup palette for the effect
56 mov al, 10 ; 0: 40, 40, 80
61 mov al, 4 ; 1: 16, 16, 32
66 mov al, 18h ; 2: 96, 192, 96
76 ; clear the framebuffer
84 mov byte [setcol + 1], 1 ; shadow color
88 mov byte [setcol + 1], 2 ; fractal color
91 ; copy framebuffer to video ram
94 ; point ds:si (source) to es:0
98 ; point es:di (dest) to a000:0
111 in al, 60h ; read pending scancode from the keyboard port (if any)
112 dec al ; ESC is 1, so decrement ...
113 jnz mainloop ; ... and loop as long as the result was not 0
115 ; switch back to text mode (mode 3)
122 ; draw sierpinski triangle
124 ; start from one of the vertices
125 mov ax, [sierp_verts]
126 mov bx, [sierp_verts + 2]
128 mov [SIERP_PT + 2], bx
129 ; number of iterations in cx
131 dsloop: ; pick a vertex at random and move half-way there
135 div bx ; dx is now rand % 3
136 ; put the vertex address in bx
140 ; add to SIERP_PT and divide by 2 to move half-way there
144 mov [SIERP_PT], ax ; store the resulting X back to [SIERP_PT]
145 mov di, ax ; save X coordinate in di
147 add ax, [SIERP_PT + 2]
149 mov [SIERP_PT + 2], ax ; store the reuslting Y back to [SIERP_PT + 2]
150 add ax, si ; add offset
154 add bx, ax ; bx = Y * 320
156 mov byte [es:bx + di], al
176 mov ax, [di] ; grab vertex X
177 add ax, [si] ; add velocity X
179 cmp ax, 320-SHADOW_OFFS
183 sub ax, [si] ; revert to previous X
184 neg word [si] ; negate velocity X
186 mov [di], ax ; update vertex X
188 ; to do the same for Y increment edi and esi by 2
191 mov ax, [di] ; grab vertex Y
192 add ax, [si] ; add velocity Y
194 cmp ax, 200-SHADOW_OFFS
198 sub ax, [si] ; revert to previous Y
199 neg word [si] ; negate velocity Y
201 mov [di], ax ; update vertex Y
209 ; random number generator
221 ; mul dword [randmul]
223 ; and eax, 0x7fffffff
228 ;randmul dd 1103515245
233 times 510-($-$$) db 0