; tunnel256: a flight down a tunnel of light, for DOS. ; ; Target: DOS .COM, 386+ with an x87, VGA mode 13h (320x200, 256 colours). ; Build: nasm -f bin tunnel.asm -o tunnel.com ; ; Every pixel asks the FPU two questions: which way is it from the centre ; (fpatan) and how deep into the tunnel it sits (k / distance). The answers ; become texture coordinates, scrolled by the frame counter in BP. bits 16 cpu 386 org 0x100 start: fninit mov ax, 0x0013 ; 320x200, 256 colours int 0x10 push word 0xA000 pop es cld frame: xor di, di pixel: mov ax, di xor dx, dx mov cx, 320 div cx ; ax = row, dx = column sub ax, 100 ; centre the row sub dx, 160 ; centre the column mov [y], ax mov [x], dx fild word [y] fild word [x] fpatan ; angle around the axis, -pi..pi fmul dword [k_angle] fistp word [u] fild word [y] fmul st0, st0 fild word [x] fmul st0, st0 faddp st1, st0 fsqrt ; distance from the centre fdivr dword [k_depth] ; depth = k / distance fistp word [v] mov ax, [u] add ax, bp ; spin mov bx, [v] add bx, bp add bx, bp ; fly forward, twice as fast xor al, bl stosb cmp di, 64000 jb pixel inc bp ; next frame in al, 0x60 ; Esc has scancode 1 dec al jnz frame ret k_angle: dd 40.743665 ; 128 / pi k_depth: dd 2048.0 section .bss x: resw 1 y: resw 1 u: resw 1 v: resw 1