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.

Code
Blame·8 commits across 114 linesoldernewer
First light: mode 13h and an XOR patternJul 22 1; tunnel256: a flight down a tunnel of light, for DOS.
2;
Angle and depth from the FPUJul 24 3; Target: DOS .COM, 386+ with an x87, VGA mode 13h (320x200, 256 colours).
First light: mode 13h and an XOR patternJul 22 4; Build: nasm -f bin tunnel.asm -o tunnel.com
Two ramps: amber and cyanAug 3 5; Run: DOSBox with cycles=max. Esc leaves.
Angle and depth from the FPUJul 24 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
14
15start:
First light: mode 13h and an XOR patternJul 22 17 mov ax, 0x0013 ; 320x200, 256 colours
18 int 0x10
19 push word 0xA000
20 pop es
21 cld
22
Two ramps: amber and cyanAug 3 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
Two ramps: amber and cyanAug 3 40 mov al, bl
Two ramps: amber and cyanAug 3 42 mov al, ah
44 inc cl
46
47; --- one frame ----------------------------------------------------------------
49 xor di, di
50pixel:
Row and column from one multiply by 0xCCCDJul 29 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
Angle and depth from the FPUJul 24 56 mov [y], ax
58 mov [x], ax
60 fild word [y]
61 fild word [x]
62 fpatan ; angle around the axis, -pi..pi
63 fmul dword [k_angle]
64 fistp word [u]
65
66 fild word [y]
67 fmul st0, st0
68 fild word [x]
69 fmul st0, st0
70 faddp st1, st0
71 fsqrt ; distance from the centre
72 fdivr dword [k_depth] ; depth = k / distance
73 fistp word [v]
74
Fog the vanishing pointAug 19 75 mov cx, [v] ; fog: the far end fades to black
76 shr cx, 3
77 cmp cx, 63
78 jbe .near
79 mov cl, 63
63 - fog is 63 xor fog: -4 bytesAug 30 80.near: xor cl, 63 ; 63 - fog
Angle and depth from the FPUJul 24 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
Two ramps: amber and cyanAug 3 87 xor al, bl ; bit 6 picks the ramp, bits 0-5 the level
Fog the vanishing pointAug 19 88 mov ch, al
89 and ch, 64
90 and al, 63
91 mul cl ; shade by fog
92 shr ax, 6
93 or al, ch
95 cmp di, 64000
96 jb pixel
97
98 inc bp ; next frame
99 in al, 0x60 ; Esc has scancode 1
100 dec al
101 jnz frame
103 mov ax, 0x0003 ; back to text mode
104 int 0x10
107k_angle: dd 40.743665 ; 128 / pi
108k_depth: dd 2048.0
109
110section .bss
111x: resw 1
112y: resw 1
113u: resw 1
114v: resw 1