World shattering Z80 machine code effect routine. Each time the code is called the screen shakes once, so a single call gives a ‘hit by a missile’ effect, and multiple calls give an earthquake.
This program demonstrates a screen-shaking “earthquake” effect implemented in Z80 machine code, poked into memory at address 40000 from DATA statements. The machine code routine works by rapidly scrolling or displacing the screen buffer, and is described as relocatable and requiring approximately 80 bytes. The BASIC loader at line 380 uses RESTORE and a FOR/NEXT loop to read 77 bytes of decimal data and POKE them into place before the effect is called via RANDOMIZE USR 40000. An introductory “STOP THE TAPE” siren display uses alternating INK and PAPER colors with FLASH across all 22 lines, and the program includes a menu offering options to repeat the demo, save the machine code block, or quit. The machine code contains values of 118 (the HALT opcode, equivalent to PAUSE 1 in effect) which the comments note can be replaced with zeroes for a faster shake.
Program Analysis
Program Structure
The program is organized into several distinct phases controlled by line flow and GO TO/GO SUB branching:
- Lines 20–80: Attract screen — flashing “STOP THE TAPE” banner cycling INK/PAPER colors, then waits for a keypress via
RANDOMIZE USR 26727andINKEY$polling. - Lines 90–150: Title and mountain scene — text credits, PLOT/DRAW mountain graphics, then calls the machine code loader at line 380.
- Lines 160–200: Earthquake demo — calls
USR 40000in loops with random PAUSEs, activates a volcano graphic with FLASH characters. - Lines 210–290: Explanatory text pages describing the routine’s nature and usage.
- Lines 300–360: Menu — repeat, quit, or SAVE the machine code.
- Lines 380–410: Subroutine to POKE machine code; DATA lines holding 77 bytes in decimal.
- Line 420: SAVE with autorun, then VERIFY.
Machine Code Routine
The earthquake effect resides at address 40000 and is 77 bytes long (loop variable i runs 0 TO 76). It is called via RANDOMIZE USR 40000 or LET a=USR 40000 — both idioms discard the return value cleanly. The routine is described as relocatable, meaning no absolute internal address references prevent it from being placed elsewhere in RAM (such as a REM statement or the printer buffer).
The DATA stream contains the value 118 several times. In Z80 machine code, opcode 118 is HALT, which the comments note behaves like a brief pause. The program explicitly tells users to replace these with zeroes (NOP, opcode 0) for a faster shake effect. This is a practical, documented tuning parameter embedded directly in the data.
The routine saves and restores three memory locations (evident from the three 245/push and 241/pop patterns at the start and end of the DATA), and performs block memory moves using the Z80’s LDIR (opcode sequence 237,176) and LDDR (opcode sequence 237,184) instructions to shift the screen contents, producing the scrolling shake effect.
Attract Screen Technique
Lines 30–50 create a two-color alternating FLASH banner across all 22 screen rows. Variables a and b hold INK and PAPER values (2 and 7), and a swap via temporary variable c alternates them on each iteration of the FOR loop, producing a striped flashing effect without any array or additional data structure.
Machine Code Loader
The subroutine at line 380 uses a standard RESTORE/READ/POKE pattern:
RESTORE 400resets the DATA pointer to line 400.- A
FOR i=0 TO 76loop reads each byte into variablecodeand POKEs it to40000+i. - The DATA is split across lines 400 and 410 for line-length manageability.
Key BASIC Idioms
| Idiom | Location | Purpose |
|---|---|---|
RANDOMIZE USR 40000 | Lines 170, 280 | Call machine code, discarding return value safely |
LET a=USR 40000 | Lines 170, 190 | Alternate form of machine code call within FOR loop |
PAUSE 0 + INKEY$ | Lines 210–220, 260–270, 320–330 | Efficient keypress wait idiom |
IF INKEY$<>"" THEN GO TO 310 | Line 310 | Flush any held key before PAUSE 0 menu wait |
RUN 90 | Line 330 | Restart from line 90, reinitializing variables |
Graphics
The mountain scene is drawn entirely with PLOT and DRAW statements using relative coordinates, building up a silhouette across lines 120–140. The volcano eruption in line 180 uses block graphic characters (rendered as ▘, ▗, etc.) positioned with AT coordinates and wrapped in FLASH 1 to animate the eruption visually. Note that AT PI,17 in line 180 uses the constant PI (≈3.14159), which truncates to row 3 — a slightly unconventional but valid use of a floating-point expression where an integer is expected.
Menu and SAVE Flow
The menu at lines 300–360 guards against key-bounce by requiring INKEY$ to be empty (line 310) before entering PAUSE 0. The SAVE option (line 350) prints the required SAVE "QUAKE" CODE 40000,80 command to the screen for the user to type manually rather than executing it directly, giving the user control over when the tape recorder is running. Line 420 saves the BASIC program itself and attempts to verify it.
Notable Anomaly
Line 10 contains a long REM statement with what appears to be garbled or encoded text including BASIC keywords. This is characteristic of REM statements used as machine code storage or as autorun metadata artifacts and does not affect program execution.
Content
Source Code
10 REM USE LIST 2d RETURN :H\ NEW o AND g GO SUB i{= CLEAR GO SUB a{= CLEAR LIST \ RETURN :H\ NEW o AND g GO SUB i{= CLEAR GO SUB a{= CLEAR LIST <>oo
20 BORDER 5: PAPER 5: LET a=2: LET b=7: CLS
30 FOR i=0 TO 21
40 PRINT AT i,8; INK a; PAPER b; FLASH 1;" STOP THE TAPE "
50 LET c=a: LET a=b: LET b=c: NEXT i
60 PRINT #1;AT 1,0; INK 9;" PRESS ANY KEY TO TURN PAGE",
70 RANDOMIZE USR 26727
80 IF INKEY$="" THEN GO TO 70
90 BORDER 7: PAPER 7: INK 9: BRIGHT 0: CLS : BORDER 5
100 PRINT AT 18,0; INK 2;" Wizard Prang "; INK 1;"presents-"," "; PAPER 6;" EARTHQUAKE "; PAPER 7," another world shattering Z80 machine code effect routine."
110 REM DRAW MOUNTAINS
120 PLOT 8,40: DRAW 24,0: DRAW 37,48: DRAW 24,-40: PLOT 86,60: DRAW 50,64
130 DRAW 5,-6: DRAW 5,4: DRAW 4,-7: DRAW 5,8: DRAW 48,-88: PLOT 182,75: DRAW 24,24: DRAW 31,-40
140 DRAW 7,0: PLOT 116,98: DRAW 13,1: DRAW 7,-5: DRAW 11,5: DRAW 10,-4: DRAW 4,5: DRAW 9,-5
150 GO SUB 380: REM CODE POKER
160 REM SHAKE IT UP
170 FOR i=1 TO 3: LET a=USR 40000: PAUSE (RND*10)+1: NEXT i
180 PRINT AT 1,17; FLASH 1;"\.'\.'";AT 2,16;"\'.\.'\.'\'.";AT PI,17;"\'.\.'"; FLASH 0;AT 4,17;"!!!",," !!!": REM Turns on volcano!
190 FOR i=1 TO 20: LET a=USR 40000: PAUSE (RND*10)+1: NEXT i
200 PRINT AT 0,0; INK 2; FLASH 1;" R to REPEAT- Other to CONTINUE ": PRINT ,,,,,,,,,,
210 PAUSE 0
220 IF INKEY$="r" OR INKEY$="R" THEN PRINT AT 0,0,,: GO TO 160
230 CLS : PRINT " This routine is relocatable and requires about 80 bytes of memory, so you could stick it in a REM like we do with our 'STOP TAPE' siren, or in the printer buffer or wherever."
240 PRINT " At the moment, the code is at address 40000, and also in DATA statements in BASIC, at line 3000, in decimal form. Each time the code is called the screen shakes once, so a single call gives a 'hit by a missile' effect, and multiple calls give an earthquake."
250 PRINT " You will be able to SAVE the code on its own via the menu on the next page, or just edit the BASIC to suit yourself."," There are lots of REMs."'" Press Q to turn page, or any other to see a single shake."
260 PAUSE 0
270 IF INKEY$="q" OR INKEY$="Q" THEN GO TO 300
280 RANDOMIZE USR 40000: GO TO 260: REM SINGLE SHAKE
290 REM MENU
300 CLS : PRINT '''''TAB 5;"Press R to Read Again"''TAB 5;"Press Q to Quit"''TAB 5;"Press S to SAVE CODE "
310 IF INKEY$<>"" THEN GO TO 310
320 PAUSE 0
330 IF INKEY$="r" OR INKEY$="R" THEN RUN 90
340 IF INKEY$="q" OR INKEY$="Q" THEN BORDER 7: CLS : PRINT AT 10,8;"START THE TAPE": LOAD ""
350 IF INKEY$="s" OR INKEY$="S" THEN CLS : PRINT AT 10,4;"SAVE ""QUAKE""CODE 40000,80"
360 GO TO 300
370 REM QUAKE code in decimal data form, with loader. Locates code at 40000, change to suit.
380 RESTORE 400: FOR i=0 TO 76: READ code: POKE 40000+i,code: NEXT i: RETURN
390 REM The '118's are machine code equivalents of 'PAUSE 1'. Replace with zeroes for faster shake.
400 DATA 58,0,64,245,58,255,90,245,58,255,87,245,33,0,64,84,93,1,254,26,35,237,176,251,118,118,118,118,58,255,87,50,254,87,33,255,90,84,93,1,253,26,43,43
410 DATA 237,184,251,118,118,118,118,118,118,33,0,64,84,93,1,254,26,35,237,176,241,50,255,87,241,50,255,90,241,50,0,64,201
420 SAVE "QUAKE" LINE 10: PRINT FLASH 1;"Verify...": VERIFY ""
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
