This program loads a Z80 machine code sprite engine into RAM starting at address 64776, just below the CLEAR boundary set at 64767. The routine is poked into a 256-byte buffer region at 65024–65280 (initialized to 253), and a jump vector is installed at 65021–65023 to redirect execution into the sprite handler. A checksum verification step sums all 217 data bytes and compares the result against 30092, halting with an error message if the DATA has been corrupted. The sprite can be enabled by calling RAND USR 64776 and disabled by POKEing address 64898 with the value 1.
Program Analysis
Program Structure
The program is organized into three logical phases:
- Memory initialization (lines 35–50): Sets the CLEAR boundary, fills a 256-byte workspace at 65024–65280 with the value 253, and installs a three-byte Z80 jump instruction (
JP nn, opcode 195) at address 65021 pointing to 65027 (low byte 27, high byte 253). - Machine code loading and verification (lines 60–150): Reads 217 bytes from DATA statements, POKEs them into addresses 64776–64992, accumulates a checksum, and halts with an error if the sum does not equal 30092.
- Data block (lines 1000–1210): Contains the raw Z80 opcodes for the sprite engine.
Memory Map
| Address Range | Purpose |
|---|---|
| 64776–64992 | Z80 sprite engine machine code (217 bytes) |
| 64898 | Sprite enable/disable flag (POKE 1 to disable) |
| 65021–65023 | JP instruction redirecting to sprite handler |
| 65024–65280 | Sprite workspace buffer, pre-filled with 253 (0xFD) |
Machine Code Entry and Control
The sprite routine is invoked via RAND USR 64776, which executes the machine code at address 64776 as a Z80 subroutine. The pre-fill value 253 (0xFD) for the workspace buffer is significant: in Z80 instruction encoding, 0xFD is the IY register prefix, suggesting the workspace may be structured to hold IY-indexed data or act as a self-modifying code region. The jump at 65021 with opcode 195 (0xC3) is a standard Z80 JP nn, routing control from a fixed hook point into the sprite handler.
Examining the DATA reveals several recognizable Z80 sequences: 243 (DI), 251 (EI), 201 (RET), and 237,86 (IM 1) / 237,94 (IM 2), indicating the routine manipulates interrupt mode — consistent with a software sprite that hooks the interrupt service routine to redraw itself every frame.
Interrupt-Driven Sprite Technique
The sequence 243,237,94,62,254,237,71 at the start of the code block decodes as DI / IM 2 / LD A,254 / LD I,A, which sets up interrupt mode 2 with the high byte of the interrupt vector table pointing to page 0xFE (65024 in decimal). Combined with the 253-filled buffer at 65024–65280, this creates an IM 2 vector table where every entry points to address 0xFDFD — within the pre-filled workspace — a classic technique for installing a stable IM 2 interrupt handler. The JP at 65021 then redirects that interrupt to the actual sprite routine.
Checksum Verification
Lines 60–150 implement a simple additive checksum over all 217 DATA bytes, comparing the result to the hardcoded value 30092. This is a practical integrity check to detect DATA entry errors, which were a common problem when typing in programs from printed listings. No polynomial or CRC is used — just a straight integer sum — but it is sufficient to catch most single-byte transcription errors.
Key BASIC Idioms
CLEAR 64767raises the RAMTOP, protecting the machine code area from BASIC’s memory manager and preventing the routine from being overwritten by the stack or string space.RESTORE 1000explicitly resets the DATA pointer to line 1000 before the READ loop, making the loader re-runnable without restarting the program.- The
FORloop at line 40 fills a 257-byte region (65024 to 65280 inclusive) — note this is 257 iterations, slightly more than one 256-byte page, which may be intentional to ensure the vector table page is fully populated.
Notable Anomalies
Line 40 iterates from 65024 to 65280 inclusive, which is 257 bytes rather than 256. Since the interrupt vector page at 0xFE spans 65024–65279, the extra byte at 65280 (0xFF00) is written but falls outside the vector table page and is harmless. The STOP at line 9998 acts as a program terminator after the loader completes, preventing fall-through into any subsequent code.
Content
Source Code
10 REM
20 REM Enable Sprite With RAND USR 64776
30 REM Disable Sprite 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
60 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
9998 STOP
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

