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.

Two ramps: amber and cyan

Browse files
The palette loop writes all 256 DAC entries. Bit 6 of the index picks the ramp and bits 0-5 the level, so 128-255 repeat 0-127 and the texture byte needs no masking.
isoldekerfagentcommitted 1 parent 89ddf83 commit 62ad2d1faf7ce8a6ed1fc0ff0ec00d49a7a5730d
failing 1 step in 1 ms
2 files changed +46−2
modified README.md +12−1
@@ -1,9 +1,20 @@
11 # tunnel256
22
3−A flight down a tunnel of light for DOS, in under 256 bytes. So far the flight is a scrolling XOR pattern.
3+A flight down a tunnel of light for DOS. Two ramps of colour, one FPU, no lookup tables, under 256 bytes.
44
55 ```
66 nasm -f bin tunnel.asm -o tunnel.com
77 ```
88
99 Esc leaves.
10+
11+## How it moves
12+
13+- `0xCCCD × di` turns a screen offset into the row in `dh` and 0.8 × the column in `dl`, with no division. The 0.8 nearly cancels mode 13h's tall pixels, so the tunnel is round on a 4:3 screen.
14+- The angle around the axis becomes `u` and `2048 / distance` becomes `v`. `u xor v` is the texture.
15+- `bp` counts frames. It is added once to `u` (spin) and twice to `v` (forward).
16+- Bit 6 of the texture picks the amber or cyan ramp.
17+
18+## Credits
19+
20+Isolde Varga, with kerf taking bytes out.
modified tunnel.asm +34−1
@@ -2,6 +2,7 @@
22 ;
33 ; Target: DOS .COM, 386+ with an x87, VGA mode 13h (320x200, 256 colours).
44 ; Build: nasm -f bin tunnel.asm -o tunnel.com
5+; Run: DOSBox with cycles=max. Esc leaves.
56 ;
67 ; Every pixel asks the FPU two questions: which way is it from the centre
78 ; (fpatan) and how deep into the tunnel it sits (k / distance). The answers
@@ -19,6 +20,38 @@ start:
1920 pop es
2021 cld
2122
23+; --- palette: an amber ramp, then a cyan one, twice over ---------------------
24+ xor cx, cx
25+palette:
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
52+ jnz palette
53+
54+; --- one frame ----------------------------------------------------------------
2255 frame:
2356 xor di, di
2457 pixel:
@@ -51,7 +84,7 @@ pixel:
5184 mov bx, [v]
5285 add bx, bp
5386 add bx, bp ; fly forward, twice as fast
54− xor al, bl
87+ xor al, bl ; bit 6 picks the ramp, bits 0-5 the level
5588 stosb
5689 cmp di, 64000
5790 jb pixel