bits 16
%ifdef BOOTSECT
org 7c00h
%else
org 100h
%endif
NUM_POINTS equ 8192
SHADOW_OFFS equ 5
SIERP_PT equ code_end
RANDVAL equ code_end + 4
SIERP_VERTS equ code_end + 8
%macro WAIT_VBLANK 0
mov dx, 3dah
.notblank:
in al, dx
and al, 8
jz .notblank
%endmacro
%macro RAND 0
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
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
jmp 00:.setcs
.setcs: xor sp, sp
%endif
mov al, 13h
int 10h
mov ax, es
add ax, 1000h
mov es, ax
mainloop:
mov cx, 3
mov di, sierp_verts
mov si, sierp_vel
.loop:
mov bx, 4
.xyloop:
mov ax, [di]
add ax, [si]
jl .xout
cmp ax, [bx + bounds - 2]
jge .xout
jmp .skip_xflip
.xout:
sub ax, [si]
neg word [si]
.skip_xflip:
mov [di], ax
add di, 2
add si, 2
sub bx, 2
jnz .xyloop
dec cx
jnz .loop
mov al, 128
mov cx, 64000
xor di, di
rep stosb
mov si, setcol + 1
mov bp, 5
mov byte [si], 199
call drawsierp
xor bp, bp
mov byte [si], 48h
call drawsierp
push ds
push es
push es
pop ds
xor si, si
push word 0a000h
pop es
xor di, di
mov cx, 32000
WAIT_VBLANK
rep movsw
pop es
pop ds
%ifdef BOOTSECT
jmp mainloop
%else
in al, 60h
dec al
jnz mainloop
mov ax, 3
int 10h
ret
%endif
drawsierp:
mov ax, [sierp_verts]
mov bx, [sierp_verts + 2]
mov [SIERP_PT], ax
mov [SIERP_PT + 2], bx
mov cx, NUM_POINTS
dsloop:
RAND
mov bx, 3
xor dx, dx
div bx
mov bx, sierp_verts
shl dx, 2
add bx, dx
mov ax, [bx]
add ax, [SIERP_PT]
shr ax, 1
mov [SIERP_PT], ax
mov di, ax
mov ax, [bx + 2]
add ax, [SIERP_PT + 2]
shr ax, 1
mov [SIERP_PT + 2], ax
add ax, bp
mov bx, ax
shl ax, 8
shl bx, 6
add bx, ax
setcol: mov al, 1
mov byte [es:bx + di], al
dec cx
jnz dsloop
ret
sierp_verts:
dw 160, 40
dw 240, 160
dw 80, 160
sierp_vel:
dw 1, 1
dw -1, 1
dw -1, -1
bounds dw 200 - SHADOW_OFFS
dw 320
randval dw 0ace1h
code_end:
%ifdef BOOTSECT
times 510-($-$$) db 0
db 0x55,0xaa
%endif