FadeOut

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Demo

“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,8LD DE, 0x08FE: D=8 (bit-shift counter, one pass per pixel row group), E=254 (AND mask, initially 0xFE).
  • 123,7,7,7,95LD 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,0LD 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,250LD 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,247DEC C / JR NZ: outer pixel-row group loop.
  • 21,32,233DEC 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.

Content

Appears On

One of a series of library tapes. Programs on these tapes were renamed to a number series. This tape contained

Related Products

Related Articles

Related Content

Image Gallery

FadeOut

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 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top