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; Run: DOSBox with cycles=max. Esc leaves.
6;
7; Every pixel asks the FPU two questions: which way is it from the centre
8; (fpatan) and how deep into the tunnel it sits (k / distance). The answers
9; become texture coordinates, scrolled by the frame counter in BP.
11 bits 16
12 cpu 386
13 org 0x100
15start:
16 fninit
17 mov ax, 0x0013 ; 320x200, 256 colours
18 int 0x10
19 push word 0xA000
20 pop es
21 cld
23; --- palette: an amber ramp, then a cyan one, twice over ---------------------
24 xor cx, cx
25palette:
26 mov dx, 0x3C8
27 mov al, cl
28 out dx, al ; colour index
29 inc dx ; 0x3C9 takes red, green, blue
30 and al, 63 ; level
31 mov ah, al
32 shr ah, 2 ; level / 4
33 mov bl, ah
34 add bl, ah
35 add bl, ah ; 3 * level / 4
36 test cl, 64
38 xchg al, ah ; cyan is amber with red and blue swapped
39.amber: out dx, al ; red
40 mov al, bl
41 out dx, al ; green
42 mov al, ah
43 out dx, al ; blue
44 inc cl
47; --- one frame ----------------------------------------------------------------
48frame:
49 xor di, di
50pixel:
51 mov ax, 0xCCCD ; di * 0.8: DH = row, DL = column * 0.8
52 mul di
53 sub dh, 100 ; centre the row
54 sub dl, 128 ; centre the column
55 movsx ax, dh
57 movsx ax, dl
62 fpatan ; angle around the axis, -pi..pi
67 fmul st0, st0
69 fmul st0, st0
70 faddp st1, st0
71 fsqrt ; distance from the centre
76 add ax, bp ; spin
78 add bx, bp
79 add bx, bp ; fly forward, twice as fast
80 xor al, bl ; bit 6 picks the ramp, bits 0-5 the level
81 stosb
82 cmp di, 64000
85 inc bp ; next frame
86 in al, 0x60 ; Esc has scancode 1
87 dec al
89 ret
91k_angle: dd 40.743665 ; 128 / pi
92k_depth: dd 2048.0
94section .bss
95x: resw 1
96y: resw 1
97u: resw 1
98v: resw 1