This program implements a Donkey Kong-style arcade game in BASIC. The player character moves along platforms using keys 5, 8, 7 (left, right, jump) and I/T for diagonal jumps, while barrels scroll back and forth across four platform rows. The game uses a clever collision detection technique: it reads the character cell at the player’s current screen position via PEEK on the system variables at addresses 16398/16399 (the display file pointer), comparing the character found there against known hazard characters such as “O” for barrels. Block graphics characters render the Kong figure, barrels, ladders, and platforms, with a score variable G that decrements each loop iteration and is added to the cumulative score S on reaching Kong at line 9080.
Program Analysis
Program Structure
The program is organised into a main setup block, a game loop, subroutines for movement, and end-game handlers:
- Lines 10–70: Initialisation — variables for barrel column positions (
C,D), barrel directions (E,F), player position (Arow,Bcolumn), and score penalty counterG. - Lines 200–340: Static screen drawing — platforms, Kong figure, and decorative elements using block graphics and inverse characters.
- Lines 350–510: Main game loop — barrel rendering, player drawing, input handling, barrel direction reversal, and loop back to 350.
- Lines 600–650: Gravity/fall subroutine — the player falls downward until a non-space character is detected below them.
- Lines 6000–6009: Jump-up subroutine (key 7) — animates the player rising four rows.
- Lines 7000–7020: Diagonal jump right (key I) — animates a two-column rightward arc.
- Lines 8000–8020: Diagonal jump left (key T) — mirror of the I subroutine.
- Lines 9000–9070: Death/game-over sequence — flashes the player’s cell and prints “GAME OVER”.
- Lines 9080–9130: Win sequence — reached when player position equals Kong’s cell (row 6, column 7); adds
Gto cumulative scoreS, animates Kong, redraws, and restarts the level. - Lines 9140–9150:
SAVEandRUN— used only for distribution; not reached during normal play.
Screen Layout
| Row(s) | Content |
|---|---|
| 0 | Title: “DONKEY-KONG” in inverse video |
| 1–6 | Kong figure (block graphics + inverse chars) |
| 7 | Top platform |
| 10 | First barrel row (columns driven by C) |
| 11 | Second platform |
| 14 | Second barrel row (driven by D) |
| 15 | Third platform |
| 18 | Third barrel row (driven by C) |
| 19 | Fourth platform |
| 22 | Fourth barrel row (driven by D) |
| 23 | Ground/base platform |
| 20–22, col 0 | Decorative element (barrels stacked) |
Collision Detection via PEEK
The game’s collision detection relies entirely on reading the display file. The address of the current character at screen position (A,B) is computed using the ZX81/TS1000 system variables at addresses 16398 (D_FILE low byte) and 16399 (D_FILE high byte). The expression CHR$ PEEK (PEEK 16398+256*PEEK 16399) retrieves whatever character is currently displayed at the top-left of the screen; critically, the program first positions the cursor with PRINT AT A,B; (a semicolon suppresses the newline, moving the print position without outputting anything), so the subsequent PEEK reads the character at exactly that cell.
Specifically:
- Line 352: reads cell
(A,B)intoA$; if it equals"O"(a barrel character), jumps to the death routine at 9000. - Lines 376–378: reads cell
(A+1,B)intoB$; if it is a space, the player is over a gap and the fall subroutine at 600 is triggered. - Lines 620–631: inside the fall loop, reads cell
(A+2,B)intoG$; a non-space stops the fall, but a non-space at that position also triggers death (line 631), meaning landing on a barrel kills the player. - Lines 7002, 8002: check whether a diagonal jump landing cell contains
"O".
Variable Usage
| Variable | Purpose |
|---|---|
A | Player row |
B | Player column |
C | Starting column for odd barrel rows |
D | Starting column for even barrel rows |
E | Direction increment for C (+1 or −1) |
F | Direction increment for D (+1 or −1) |
G | Score penalty counter (decrements each loop; added to S on win) |
S | Cumulative score (persists across levels) |
A$, B$, G$, U$ | Temporary screen-read character buffers |
Key Input Handling
Input is polled inside the main loop at lines 470–500 using INKEY$:
- Key 7: Jump upward — calls subroutine 6000 only if the character at
(A,B)is a ladder ("H"). - Key 8: Move right — line 480 uses a Boolean expression:
B=B+(INKEY$="8" AND B<30), incrementingBby 1 only when within bounds. - Key 5: Move left — same Boolean idiom, decrementing
BwhenB>0. - Key I: Diagonal jump right — calls subroutine 7000.
- Key T: Diagonal jump left — calls subroutine 8000.
Note that INKEY$ is evaluated independently for each condition in lines 480–500, so pressing multiple keys simultaneously may yield unexpected behaviour due to re-polling.
Kong Animation
Lines 375 and 505 alternate between two states of Kong’s arms, creating a two-frame animation. Line 375 draws Kong with arms in one position as part of the barrel-update phase; line 505 redraws them in the alternate position after input handling. This gives a crude but effective looping animation tied to the game loop speed.
Score System
G is initialised to 0 at line 25 and decremented by 1 every main loop iteration at line 411. Upon reaching Kong (line 9081), S=S+G adds the (negative) value of G to the running score. Because G becomes more negative over time, the score rewards reaching Kong quickly. G is reset to 0 at line 25 on each level restart (via GOTO 10 at line 9130, which re-runs initialisation).
Notable Techniques and Anomalies
POKE 16418,0at line 15 clears the ZX81/TS1000 system variableMARGIN, which controls the TV picture margin — commonly used to allow printing to all 32 columns cleanly.- The fall routine at line 600 does not use
GOSUB/RETURN; it is entered viaGOTO 600from the main loop and exits withGOTO 350(implicitly, by falling through from line 632 back to 650 and looping until it can place the player). The loop at 600–650 incrementsAon each iteration, moving the player down one row per cycle. - Line 631 triggers
GOTO 9000(death) whenG$<>" ", meaning any non-space character below the falling player kills them immediately. This means landing on a platform character or barrel is fatal, though in practice only barrel encounters ("O") are the intended hazard. - The win condition check at line 412 (
IF A=6 AND B=7 THEN GOTO 9080) hard-codes Kong’s screen position. GOTO 1at line 9070 (game over) targets a non-existent line — this is a standard idiom that causes execution to restart from the first line of the program (line 10), effectively performing a full program restart including variable re-initialisation.- The diagonal jump subroutines (7000, 8000) draw and erase a series of intermediate positions without delay loops, making the arc animation very fast but effectively instant on slower machines.
Content
Source Code
10 REM "DONKEY"
15 POKE 16418,0
20 LET C=1
25 LET G=0
30 LET D=21
40 LET F=-1
50 LET E=1
60 LET A=22
70 LET B=4
200 PRINT AT 7,0;"HX XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
201 PRINT AT 0,0;"% % %D%O%N%K%E%Y%-%K%O%N%G% % % % % % % % % % % % % % % % % % "
210 PRINT AT 11,0;"XXX XXXXXXXXXXXXX X X XXX XXXXH"
220 PRINT AT 15,0;"HXX XXXXX XXXXXXX X XXXXXXXXXXX"
230 PRINT AT 19,0;"XXX XXXXXXXXX XXXXXXXXXXXX XXXH"
240 PRINT AT 23,0;"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXH"
250 FOR N=1 TO 4
260 PRINT AT 7+N,0;"H";AT 11+N,30;"H";AT 15+N,0;"H";AT 19+N,30;"H"
270 NEXT N
280 PRINT AT 6,7;"H H \~~ \;;"
290 PRINT AT 5,7;"H H \ .% \. "
300 PRINT AT 4,7;"HXXXXH \: \;;\ :"
310 PRINT AT 3,9;"% % "
320 PRINT AT 2,8;"\ :% \: ";AT 1,9;"O"
330 PRINT AT 20,0;"\..\:.";AT 21,0;"% % ";AT 22,0;"% % "
350 PRINT AT 10,C;" O O O ";AT 14,D;" O O O ";AT 18,C;" O O O ";AT 22,D;" O O O "
351 PRINT AT A,B;
352 LET A$=CHR$ PEEK (PEEK 16398+256*PEEK 16399)
353 PRINT AT A,B;"\ :"
354 IF A$="O" THEN GOTO 9000
360 LET C=C+E
370 LET D=D+F
375 PRINT AT 6,16;;"\;; \~~";AT 4,16;"\ .\;;\':";AT 1,11;"HELP"
376 PRINT AT A+1,B;
377 LET B$=CHR$ PEEK (PEEK 16398+256*PEEK 16399)
378 IF B$=" " THEN GOTO 600
380 IF C=21 THEN LET E=-1
390 IF C=2 THEN LET E=1
400 IF D=2 THEN LET F=1
410 IF D=21 THEN LET F=-1
411 LET G=G-1
412 IF A=6 AND B=7 THEN GOTO 9080
460 PRINT AT A,B;A$
470 IF INKEY$="7" AND A$="H" THEN GOSUB 6000
480 LET B=B+(INKEY$="8" AND B<30)-(INKEY$="5" AND B>0)
490 IF INKEY$="I" THEN GOSUB 7000
500 IF INKEY$="T" THEN GOSUB 8000
505 PRINT AT 6,16;"\~~ \;;";AT 4,16;"\:'\;;\. ";AT 1,11;" "
510 GOTO 350
600 PRINT AT A,B;" ";AT A+1,B;"\ :"
610 PRINT AT A+2,B;
620 LET G$=CHR$ PEEK (PEEK 16398+256*PEEK 16399)
630 IF G$<>" " THEN LET A=A+1
631 IF G$<>" " THEN GOTO 9000
632 LET A=A+1
650 GOTO 600
\n6000 FOR N=A TO A-3 STEP -1
\n6001 PRINT AT N,B;"\ :"
\n6002 FOR J=1 TO 3
\n6003 NEXT J
\n6004 PRINT AT N,B;"H"
\n6005 NEXT N
\n6006 PRINT AT N,B;"\ :";AT N,B;" "
\n6007 LET A=A-4
\n6009 RETURN
\n7000 PRINT AT A,B;" ";AT A-1,B;"\.'";AT A-1,B;" ";AT A-2,B;"\ :";AT A-2,B;" ";AT A-2,B+1;"\ :";AT A-2,B+1;" ";AT A-2,B+2;"\'.";AT A-2,B+2;"\ :";AT A-2,B+2;" ";AT A-1,B+2;"\'.";AT A-1,B+2;" "
\n7001 PRINT AT A,B+2;
\n7002 LET U$=CHR$ PEEK (PEEK 16398+256*PEEK 16399)
\n7003 IF U$="O" THEN GOTO 9000
\n7004 PRINT AT A,B+2;"\ :";AT A,B+2;" "
\n7010 LET B=B+2
\n7020 RETURN
\n8000 PRINT AT A,B;" ";AT A-1,B;"\'.";AT A-1,B;" ";AT A-2,B;"\ :";AT A-2,B;" ";AT A-2,B-1;"\ :";AT A-2,B-1;" ";AT A-2,B-2;"\'.";AT A-2,B-2;" ";AT A-1,B-2;"\ :";AT A-1,B-2;" "
\n8001 PRINT AT A,B-2;
\n8002 LET U$=CHR$ PEEK (PEEK 16398+256*PEEK 16399)
\n8003 IF U$="O" THEN GOTO 9000
\n8004 PRINT AT A,B-2;"\ :";AT A,B-2;" "
\n8010 LET B=B-2
\n8020 RETURN
\n9000 FOR N=1 TO 30
\n9010 PRINT AT A,B;"\ :";AT A,B;"\''";AT A,B;"\ :";AT A,B;"\.."
\n9020 NEXT N
\n9040 PRINT AT 10,10;"GAME OVER"
\n9050 PAUSE 200
\n9060 CLS
\n9070 GOTO 1
\n9080 PRINT AT 2,25;"\':\.:\' ";AT 3,26;"\' "
\n9081 LET S=S+G
\n9090 FOR N=1 TO 60
\n9091 NEXT N
\n9092 PRINT AT 2,25;"\':\ .\:'";AT 3,25;"\' "
\n9093 PRINT AT 1,0;"SCORE: ";S
\n9094 PRINT AT 3,9;" ";AT 2,8;" ";AT 1,9;" ";
\n9095 PRINT AT 4,16;"\:'% \:'";AT 3,16;" %"\ .O HELP"
\n9100 FOR U=1 TO 80
\n9120 NEXT U
\n9125 CLS
\n9130 GOTO 10
\n9140 SAVE "1017%6"
\n9150 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

