--- title: "FadeOut" id: 56294 type: "computer_media" slug: "fadeout" url: "http://localhost/computer_media/fadeout/" markdown_url: "http://localhost/computer_media/fadeout.md" published_at: "2024-08-04T10:49:46+00:00" modified_at: "2026-03-30T21:42:42+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/08/SCR-20240804-lgrb.png" excerpt: "A self-relocating machine code routine POKEs itself into RAM, fills the screen with text, then fades the entire display to black in a smooth animated effect." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" genre: - name: "Demo" slug: "demo" taxonomy: "genre" url: "http://localhost/type/demo/" media_contents: - id: 56277 title: "Timex Sinclair Public Domain Library Tape 2001" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-2001/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/FadeOut%20%28198x%29%28Waters%2C%20M%29%28TS2068%29%28UK%29%28Program%29.zip" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/08/SCR-20240804-lgrb.png" media_type_tags: "Demo" --- # FadeOut “Fade Out” is a display effect program that fills the screen with text and then uses a machine code routine to gradually fade the display to blank. The BASIC section POKEs 50 bytes of machine code data into RAM starting at address 30000, fills the screen with repeated digit strings, then calls the routine via RANDOMIZE USR 30000. The machine code manipulates the display file directly by ANDing each byte with the attribute or pixel data, producing a progressive fade effect across all 22 lines. After the effect completes, LIST is called at line 60, likely to demonstrate the cleared or faded screen state. *** ## Program Analysis ### Program Structure The program is organized into four logical phases: 1. **Setup (lines 1–7):** REM statements documenting the program’s title, author, source, and relocation instructions. 2. **Machine code loader (lines 10–20):** A `RESTORE`/`FOR...NEXT` loop READs 50 bytes from the DATA statement and POKEs them into memory starting at address 30000. 3. **Screen fill (line 30):** A loop prints a 32-character digit string for each of the 22 screen lines, fully populating the display file. 4. **Execution and aftermath (lines 40–60):**`RANDOMIZE USR 30000` calls the machine code routine; `LIST` at line 60 runs after the effect completes. ### Relocation The author’s REMs (lines 4–6) explicitly note that the routine is relocatable by changing the loop bounds in line 10. Both the `FOR N=30000 TO 30049` in line 10 and the `USR 30000` in line 40 would need to be updated together. The machine code itself contains no absolute self-references, making true relocation straightforward. ### Machine Code Routine The 50-byte routine loaded at address 30000 operates directly on the display file at address 16384 (0x4000). A disassembly of the DATA bytes reveals the core algorithm: - `17,254,8` — `LD DE, 0x08FE`: D=8 (bit-shift counter, one pass per pixel row group), E=254 (AND mask, initially 0xFE). - `123,7,7,7,95` — `LD A,E / RLCA / RLCA / RLCA / LD E,A`: rotates the mask left three times each outer iteration, cycling through patterns to progressively blank pixel columns. - `33,0,64,1,24,0` — `LD HL,16384 / LD BC,24`: sets up HL pointing to the display file start, BC as a line counter (24 character rows × pixel rows). - `126,163,119,35,16,250` — `LD A,(HL) / AND E / LD (HL),A / INC HL / DJNZ`: inner loop ANDs each display byte with the mask and writes it back, advancing through all pixel rows. - `13,32,247` — `DEC C / JR NZ`: outer pixel-row group loop. - `21,32,233` — `DEC D / JR NZ`: repeats for each of the 8 bit positions. - After fading pixels, the routine reads the system variable area (address 23693 / 0x5C8D) and uses `LDIR` to clear or overwrite the attribute file, then restores a border colour byte and returns via `RET` (201). ### Screen Fill Technique Line 30 uses `FOR N=0 TO 21: PRINT "12345678901234567890123456789012": NEXT N` to write a 32-character string across each of the 22 display lines. This ensures the entire pixel display area contains non-zero data for the fade effect to act upon visibly. ### DATA Statement All 50 machine code bytes are held in a single `DATA` statement at line 50. The `RESTORE` at the start of line 10 ensures the data pointer is reset before reading, making the loader re-entrant if the program is run more than once. ### Notable Techniques - The AND-mask rotation approach fades the display one bit-column at a time rather than erasing whole bytes, producing a smooth progressive darkening effect. - Using `RANDOMIZE USR` rather than a direct `USR` call suppresses the return value, keeping the BASIC layer clean. - `LIST` at line 60 serves as a visual confirmation that the effect has completed and provides a natural program endpoint. - The trailing `0,0,0` bytes at the end of the DATA statement are padding, not executable code—they follow the `RET` (201) byte. ### Potential Anomalies The inner `DJNZ` loop uses `BC=24` with B as the repeat counter (24 iterations per mask pass), covering the 192 pixel rows of the display file divided by 8. However, each pass advances HL by only 24 bytes rather than the full 192-byte width of a character row group, which suggests the loop structure relies on the interleaved ZX Spectrum display file layout to traverse all pixel data correctly across the three screen thirds. ## Source Code ``` 1 REM "FADE OUT" 2 REM By M. Waters 3 REM ZX Computing Monthly 4 REM Relocateable to any 5 REM address by changing the 6 REM FOR...NEXT in line 10 7 REM 10 RESTORE : FOR N=30000 TO 30049 20 READ A: POKE N,A: NEXT N 30 FOR N=0 TO 21: PRINT "12345678901234567890123456789012": NEXT N 40 RANDOMIZE USR 30000 50 DATA 17,254,8,123,7,7,7,95,33,0,64,1,24,0,126,163,119,35,16,250,13,32,247,21,32,233,58,141,92,119,84,93,19,1,192,2,237,176,58,72,92,119,14,63,237,176,201,0,0,0 60 LIST ```