acompiled

The catalog contains seeded project examples. Your workspace stores your own projects and conversations.

sizecoders/tunnel256

Public
Star7

A flight down a tunnel of light for DOS, in under 256 bytes. Every pixel asks the x87 for an angle and a depth.

History
105 lines·3.3 KB·NASM Raw Blame
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 mov al, cl
31 and al, 63 ; level
32 mov ah, al
33 shr ah, 2 ; level / 4
34 mov bl, ah
35 add bl, ah
36 add bl, ah ; 3 * level / 4
37 test cl, 64
38 jnz .cyan
39 out dx, al ; amber: red = level
40 mov al, bl
41 out dx, al ; green = 3/4 level
42 mov al, ah
43 out dx, al ; blue = 1/4 level
44 jmp .next
45.cyan: xchg al, ah
46 out dx, al ; cyan: red = 1/4 level
47 mov al, bl
48 out dx, al ; green = 3/4 level
49 mov al, ah
50 out dx, al ; blue = level
51.next: inc cl
54; --- one frame ----------------------------------------------------------------
55frame:
56 xor di, di
57pixel:
58 mov ax, 0xCCCD ; di * 0.8: DH = row, DL = column * 0.8
59 mul di
60 sub dh, 100 ; centre the row
61 sub dl, 128 ; centre the column
62 movsx ax, dh
63 mov [y], ax
64 movsx ax, dl
65 mov [x], ax
67 fild word [y]
68 fild word [x]
69 fpatan ; angle around the axis, -pi..pi
70 fmul dword [k_angle]
71 fistp word [u]
73 fild word [y]
74 fmul st0, st0
75 fild word [x]
76 fmul st0, st0
77 faddp st1, st0
78 fsqrt ; distance from the centre
79 fdivr dword [k_depth] ; depth = k / distance
80 fistp word [v]
82 mov ax, [u]
83 add ax, bp ; spin
84 mov bx, [v]
85 add bx, bp
86 add bx, bp ; fly forward, twice as fast
87 xor al, bl ; bit 6 picks the ramp, bits 0-5 the level
88 stosb
89 cmp di, 64000
92 inc bp ; next frame
93 in al, 0x60 ; Esc has scancode 1
94 dec al
95 jnz frame
96 ret
98k_angle: dd 40.743665 ; 128 / pi
99k_depth: dd 2048.0
101section .bss
102x: resw 1
103y: resw 1
104u: resw 1
105v: resw 1