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·3 commits across 72 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
5;
Angle and depth from the FPUJul 24 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
13
14start:
First light: mode 13h and an XOR patternJul 22 16 mov ax, 0x0013 ; 320x200, 256 colours
17 int 0x10
18 push word 0xA000
19 pop es
20 cld
21
22frame:
23 xor di, di
24pixel:
Row and column from one multiply by 0xCCCDJul 29 25 mov ax, 0xCCCD ; di * 0.8: DH = row, DL = column * 0.8
26 mul di
27 sub dh, 100 ; centre the row
28 sub dl, 128 ; centre the column
29 movsx ax, dh
Angle and depth from the FPUJul 24 30 mov [y], ax
32 mov [x], ax
34 fild word [y]
35 fild word [x]
36 fpatan ; angle around the axis, -pi..pi
37 fmul dword [k_angle]
38 fistp word [u]
39
40 fild word [y]
41 fmul st0, st0
42 fild word [x]
43 fmul st0, st0
44 faddp st1, st0
45 fsqrt ; distance from the centre
46 fdivr dword [k_depth] ; depth = k / distance
47 fistp word [v]
48
49 mov ax, [u]
50 add ax, bp ; spin
51 mov bx, [v]
52 add bx, bp
53 add bx, bp ; fly forward, twice as fast
54 xor al, bl
56 cmp di, 64000
57 jb pixel
58
59 inc bp ; next frame
60 in al, 0x60 ; Esc has scancode 1
61 dec al
62 jnz frame
63 ret
65k_angle: dd 40.743665 ; 128 / pi
66k_depth: dd 2048.0
67
68section .bss
69x: resw 1
70y: resw 1
71u: resw 1
72v: resw 1