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.

Angle and depth from the FPU

Browse files
fpatan gives each pixel's angle around the centre and k / distance its depth. Their xor is the texture, and bp scrolls both: once around, twice forward.
isoldecommitted 1 parent 6309eef commit b68c137f0ae49cd17e90d72ffd3efad920d644d9
failing 1 step in 1 ms
1 file changed +40−4
modified tunnel.asm +40−4
@@ -1,15 +1,18 @@
11 ; tunnel256: a flight down a tunnel of light, for DOS.
22 ;
3−; Target: DOS .COM, 386+, VGA mode 13h (320x200, 256 colours).
3+; Target: DOS .COM, 386+ with an x87, VGA mode 13h (320x200, 256 colours).
44 ; Build: nasm -f bin tunnel.asm -o tunnel.com
55 ;
6−; No tunnel yet: row xor column, scrolled by the frame counter in BP.
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.
79
810 bits 16
911 cpu 386
1012 org 0x100
1113
1214 start:
15+ fninit
1316 mov ax, 0x0013 ; 320x200, 256 colours
1417 int 0x10
1518 push word 0xA000
@@ -23,8 +26,32 @@ pixel:
2326 xor dx, dx
2427 mov cx, 320
2528 div cx ; ax = row, dx = column
26− xor ax, dx
27− add ax, bp
29+ sub ax, 100 ; centre the row
30+ sub dx, 160 ; centre the column
31+ mov [y], ax
32+ mov [x], dx
33+
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
2855 stosb
2956 cmp di, 64000
3057 jb pixel
@@ -34,3 +61,12 @@ pixel:
3461 dec al
3562 jnz frame
3663 ret
64+
65+k_angle: dd 40.743665 ; 128 / pi
66+k_depth: dd 2048.0
67+
68+section .bss
69+x: resw 1
70+y: resw 1
71+u: resw 1
72+v: resw 1