A flight down a tunnel of light for DOS, in under 256 bytes. Every pixel asks the x87 for an angle and a depth.
1; tunnel256: a flight down a tunnel of light, for DOS.
2;
3; Target: DOS .COM, 386+ with an x87, VGA mode 13h (320x200, 256 colours).
4; Build: nasm -f bin tunnel.asm -o tunnel.com
5;
6; Every pixel asks the FPU two questions: which way is it from the centre
7; (fpatan) and how deep into the tunnel it sits (k / distance). The answers
8; become texture coordinates, scrolled by the frame counter in BP.
10 bits 16
11 cpu 386
12 org 0x100
14start:
15 fninit
16 mov ax, 0x0013 ; 320x200, 256 colours
17 int 0x10
18 push word 0xA000
19 pop es
20 cld
22frame:
23 xor di, di
24pixel:
25 mov ax, di
26 xor dx, dx
27 mov cx, 320
28 div cx ; ax = row, dx = column
29 sub ax, 100 ; centre the row
30 sub dx, 160 ; centre the column
36 fpatan ; angle around the axis, -pi..pi
41 fmul st0, st0
43 fmul st0, st0
44 faddp st1, st0
45 fsqrt ; distance from the centre
50 add ax, bp ; spin
52 add bx, bp
53 add bx, bp ; fly forward, twice as fast
54 xor al, bl
55 stosb
56 cmp di, 64000
59 inc bp ; next frame
60 in al, 0x60 ; Esc has scancode 1
61 dec al
63 ret
65k_angle: dd 40.743665 ; 128 / pi
66k_depth: dd 2048.0
68section .bss
69x: resw 1
70y: resw 1
71u: resw 1
72v: resw 1