Sprite 2

This file is part of CATS Library Tape 9, and Timex Sinclair Public Domain Library Tape 2004. Download the collection to get this file.
Developer(s): Wes Brzozowski
Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Demo

This program is a sprite demonstration for the TS2068, written by Wes Brzozowski of the SINCUS user group. It installs a machine code routine into RAM starting at address 64776, hooking the interrupt vector so that a sprite is updated automatically on each frame via a custom IM2 interrupt handler. The BASIC loader verifies the machine code with a checksum before execution, halting with an error message if the data is corrupt. The main loop cycles through two DATA lines of humorous copyright strings — including deliberate misspellings and fictional companies — displaying each with a SOUND-based audio effect while the sprite routine runs in the background. The interrupt is enabled with RANDOMIZE USR 64776 and can be disabled by POKEing address 64898 with 1.


Program Analysis

Program Structure

The program is divided into three logical sections. Lines 1–22 form the main display loop, cycling through humorous copyright strings from DATA at lines 25–26 while triggering sound effects and the sprite routine. Lines 35–150 constitute the machine code installer, which clears memory, fills an IM2 interrupt table, sets the interrupt vector, loads Z80 opcodes via READ/POKE, and validates the result with a checksum. Lines 1000–1210 contain the raw machine code data. The entry point at line 2000 jumps back to line 1, and line 9999 saves the program with an auto-run directive.

Interrupt Mechanism

The loader sets up an IM2 (Interrupt Mode 2) handler. Line 40 fills addresses 65024–65280 with the value 253, creating a jump table where every entry points to address 0xFDFD (65021). Line 50 then POKEs a Z80 JP instruction at 65021–65023 pointing to 0xFD1B (64795), which is within the installed machine code block. The machine code at 64776 (enabled by RANDOMIZE USR 64776) reprograms the interrupt vector register I and switches to IM2, redirecting every maskable interrupt through the sprite routine. This is a well-established TS2068/Spectrum technique for hooking the display interrupt without patching ROM.

Machine Code Routine

The machine code occupies addresses 64776–64992 (217 bytes). Based on the REMs at lines 29–30, it is enabled with RANDOMIZE USR 64776 and disabled by POKE 64898,1 — address 64898 acts as a flag byte that the interrupt handler checks on each invocation. The data at lines 1120–1130 includes a recognizable 8-byte sprite bitmap pattern (60,66,165,129,165,153,66,60 — a smiley face). The routine also uses a helper at approximately address 64965 that computes screen addresses from sprite coordinates stored at address 64894 (0xFD7E).

Checksum Validation

Lines 90–150 accumulate the sum of all 217 data bytes into checksum and compare it against the expected value 30092. If the sum exceeds this threshold the program halts with “Checksum Error!!!!!!”. Because the comparison uses > rather than <>, a corrupted data set that sums to exactly 30092 would not be caught, and a sum lower than expected (e.g., due to missing bytes) would also pass silently — a minor validation weakness.

Display Loop and DATA

The outer loop at line 1 iterates n from 1 to 8, reading pairs of strings from the DATA at line 25 and printing them on the lower screen (PRINT #1). After each pair is displayed with a 150-frame pause, RANDOMIZE USR 64776 at line 5 re-enters the sprite routine, and an inner loop at line 6 produces a sweep of SOUND commands across noise/tone channels. Line 16 POKEs 64898 with 1 to disable the sprite interrupt before the next iteration. After the eight pairs are exhausted, RESTORE and GO TO 1 restart the cycle, but the second DATA line (line 26) — containing real competitor names like Apple, Atari, Commodore, IBM, and Texas Instruments — is never reached by the loop since RESTORE 25 always resets to the first DATA statement and only 8 pairs are read.

Notable Techniques and Idioms

  • RESTORE 25 targets the DATA line directly, avoiding sequential scanning from line 1.
  • PRINT #1;a$''b$ prints two strings separated by a newline to stream 1 (the lower screen area).
  • The \* escape in the DATA strings inserts the © symbol (char 127 on TS2068), used to prefix the fake copyright notices.
  • CLEAR 64767 sets RAMTOP just below the machine code area, protecting it from BASIC’s memory manager.
  • The SOUND statements at lines 6 and 9 target AY registers directly: register 6 (noise period), 7 (mixer), 8–10 (channel amplitudes), 12–13 (envelope period).

Anomalies and Observations

  • Line 26’s DATA block (real competitor names) is unreachable with the current loop logic — RESTORE always resets to line 25 and only 8 pairs (16 strings) are consumed, all from line 25.
  • The checksum uses > instead of <>, so a below-expected sum passes undetected.
  • Line 9 uses PAUSE 22+a, producing an increasing pause each inner iteration — this creates the sweeping audio effect by varying timing between SOUND updates.
  • The humorous DATA at line 25 contains intentional typos (“Ldt”, “timeX Computer Carp”, “Uncle Clive’s Works”, “Sir Clive’s Car lot”, “TimEx-computer crap”) as jokes for the user group audience.

Content

Appears On

Capital Area Timex Sinclair User Group’s Library Tape.
One of a series of library tapes compiled from multiple user groups.

Related Products

Related Articles

Related Content

Image Gallery

Sprite 2

Source Code

    1 RESTORE 25: FOR n=1 TO 8: CLS 
    2 READ a$,b$
    3 PRINT #1;a$''b$
    4 PAUSE 150
    5 RANDOMIZE USR 64776
    6 FOR a=1 TO 15: SOUND 6,15;7,7;8,16;9,16;10,16;12,16;13,16
    9 PAUSE 22+a: SOUND 6,0;7,0;8,0;9,0;10,16;12,2;13,4
   10 NEXT a
   16 POKE 64898,1
   17 NEXT n
   20 RESTORE 25
   22 GO TO 1
   25 DATA "\*  1982 Sinclair Research Ltd","\*  1983 Timex Computer Corp","\*  1982 Sinclair Research Ldt","\*  1984 timeX Computer Carp","\*  1982 Uncle Clive's Works","\*  1984 Timex, Portugal, Ltd","\*  1984 Sir Clive's Car lot","\*  1985 TimEx-computer crap"
   26 DATA "\*  1982 Sinclair Research Inc","\*  1982 Sincus News","\*  1980  APPLE WORKS","\*  1984 Atari Skunk Works","\*  1981 Commodore Computers Inc","\*  1983 IBM PCjr","\*  1981 Texas Instruments Inc","\*  1983 Adam Computers"
   28 REM Sprite demo by Wes Brzozowski, SINCUS
   29 REM Enable with RAND USR 64776
   30 REM Disable with POKE 64898,1
   35 CLEAR 64767
   40 FOR j=65024 TO 65280: POKE j,253: NEXT j
   50 POKE 65021,195: POKE 65022,27: POKE 65023,253
   90 LET checksum=0
  100 RESTORE 1000
  110 FOR j=64776 TO 64992
  120 READ dat: LET checksum=checksum+dat
  130 POKE j,dat
  140 NEXT j
  150 IF checksum>30092 THEN CLS : PRINT "Checksum Error!!!!!!": STOP 
 1000 DATA 243,237,94,62,254,237,71,175,50,130
 1010 DATA 253,205,211,253,205,64,253,251,201,245
 1020 DATA 197,213,229,205,139,253,58,130,253,167
 1030 DATA 32,16,205,78,253,205,211,253,205,64
 1040 DATA 253,225,209,193,241,195,56,0,237,86
 1050 DATA 225,209,193,241,251,201,1,131,253,237
 1060 DATA 91,126,253,205,165,253,205,180,253,201
 1070 DATA 237,91,126,253,237,75,128,253,62,31
 1080 DATA 187,32,2,14,255,175,187,32,2,14
 1090 DATA 1,186,32,2,6,1,62,23,186,32
 1100 DATA 2,6,255,237,67,128,253,123,129,95
 1110 DATA 122,128,87,237,83,126,253,201,10,10
 1120 DATA 1,255,0,60,66,165,129,165,153,66
 1130 DATA 60,237,91,126,253,205,165,253,229,1
 1140 DATA 131,253,205,200,253,32,8,225,1,0
 1150 DATA 253,205,180,253,201,225,201,122,230,7
 1160 DATA 15,15,15,179,111,122,230,24,246,64
 1170 DATA 103,201,22,8,10,119,36,3,21,32
 1180 DATA 249,201,22,8,126,36,2,3,21,32
 1190 DATA 249,201,22,8,10,3,190,192,36,21
 1200 DATA 32,248,201,237,91,126,253,205,165,253
 1210 DATA 1,0,253,205,190,253,201
 2000 GO TO 1
 9998 STOP 
 9999 SAVE CHR$ 18+CHR$ 1+"SPRITE"+CHR$ 18+CHR$ 0 LINE 30

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

Scroll to Top