Supermaze

Products: Supermaze
Date: 1982
Type: Cassette
Platform(s): TS 1000
Tags: Game

Supermaze is a text-based 3-D maze navigation game that stores up to ten pre-built mazes in a two-dimensional array M(10,105), with each maze’s start position, exit position, and minimum move count packed into indices 101–103. The program uses machine code routines embedded in REM statements (lines 1–9) and called via USR to render the first-person perspective view of corridor walls at up to four positions deep. Navigation uses F (forward), R (right turn), and L (left turn) commands, with direction encoded as a numeric value (1=North, 2=East, 3=South, 4=West) and the step increment A adjusted accordingly. Optional gameplay features selectable from a menu include dropping stone markers, a compass overlay, a trap door that teleports the player, and collectible gold bars placed at random positions using RND.


Program Analysis

Program Structure

The program is organized into distinct functional blocks:

  • Lines 1–9: Machine code stored in REM statements; line 9 contains a dispatch table of CALL instructions.
  • Lines 10–18: Array dimension declarations in REM (executed via USR, not BASIC DIM).
  • Lines 20–107: Title screen, menu dispatch, and instructions.
  • Lines 110–179: Main menu with six options, dispatched via GOTO C*20+140.
  • Lines 180–499: Subroutines for maze selection (350), option setup (700), and game variable initialization (420).
  • Lines 500–670: Main game loop — view rendering, input handling, movement, win/lose detection.
  • Lines 700–732: Option selection menu (stones, compass, trap door, gold bars).
  • Lines 800–830: Trap door handler.
  • Lines 840–845: Gold bar reminder.
  • Lines 900–925: Results screen.
  • Line 9000: SAVE routine.

Machine Code Usage

Lines 1–9 contain Z80 machine code packed into REM statements. Line 9 acts as a master dispatcher, issuing a sequence of CD (CALL) opcodes targeting routines defined in lines 1–6. The routines use 2A 0C 40 (LD HL,(400C)) to load the display file address, then use ADD HL,BC, LD (HL),n, and INC HL sequences to write wall graphics directly to screen memory. Line 51 initializes everything with LET A=USR 17658, which calls the line-9 dispatcher at address 17658 (the byte offset into the REM of line 9).

The view renderer at line 514 calls USR (F*24+16515) and related expressions, selecting different machine code entry points based on depth F (0–4) and which walls are present. The multipliers (24, 28, 37, 35, 10) correspond to the byte lengths of each rendering sub-routine for a given perspective depth.

Maze Data Format

Each maze is stored in a row of the M(10,105) array. Indices 1–100 represent a 10×10 grid of cells, where each cell value encodes which walls are present as a bitmask. Index 101 holds the starting cell number, index 102 the exit cell, and index 103 the minimum number of moves required. The smaller mazes (5×5, 6×8, etc.) use only a subset of the 100 cells.

Direction and Movement Model

Direction D uses the encoding 1=North, 2=East, 3=South, 4=West. The step increment A is recalculated at lines 631–634 after every action:

DDirectionA
1North-10
2East+1
3South+10
4West-1

The forward look-ahead loop (lines 510–549) advances a depth counter F from 0 to 4, computing the cell at P+A*F and calling appropriate USR routines to draw successive corridor layers. A wall collision at depth F=4 or hitting the entrance/exit boundary terminates the loop.

Wall Encoding and String Parsing

At lines 513 and 560, P$=STR$ M(N,P+A*F) converts the cell value to a string. Individual characters of P$ are then indexed by the current direction value L (left side) or R (right side) at lines 520 and 532 to check for "1", indicating a wall. This is an economical way to decode a packed wall bitmask using BASIC’s string indexing rather than bitwise arithmetic.

Menu Dispatch Technique

At line 155–157, the main menu uses the idiom IF C<7 THEN GOTO C*20+140. The six options map to target lines 160, 180, 200, 220, 240, and 260. Options 1 (instructions) and 5 (review options) land at lines 163 and 241 respectively, while option 4 (save) falls through to line 221, each within the computed range.

Options System

The string array O$(7) acts as a set of flags. Each element is set to "Y" if the corresponding option is active, or cleared to "" or " " when disabled. The four player-selectable options are:

  1. O$(1) — Drop stones (5 allowed, tracked in S(5) and counter II)
  2. O$(2) — Compass overlay (printed at lines 551–555)
  3. O$(3) — Trap door (enabled automatically for mazes 6–10 at line 479)
  4. O$(4) — Gold bars (up to 5 placed randomly in G(5))

Notable Techniques

  • The trap door routine (line 800) randomizes both the player’s new position and direction, then sets TR=0 and clears O$(3) so it triggers only once per game.
  • Gold bar collection (lines 620–623) zeroes out G(X) entries as the player visits their cells; the exit is blocked at line 592 until all bars are collected.
  • The SLOW call at line 20 and line 571 ensures display stability during rendering, a common technique when USR routines write directly to screen memory.
  • The compass at lines 551–555 prints a static N/W+E/S cross and then highlights the current direction in inverse video using PRINT AT with inverse characters.
  • Line 370 validates maze selection with IF N>10 OR N<1 THEN GOTO 360; note the target is line 360 which does not exist, so it falls through to line 365 — a deliberate non-existent line target used to re-prompt.
  • The delay loops (e.g., lines 641–642, 664–665, 802–804) use empty FOR/NEXT bodies as timing mechanisms.

Bugs and Anomalies

  • Line 546 has a logical precedence issue: IF O$(4)="Y" AND G(1)=PP OR G(2)=PP OR G(3)=PP OR G(4)=PP OR G(5)=PP — the AND binds only G(1)=PP, so gold bar rendering for bars 2–5 fires regardless of whether option 4 is enabled.
  • At line 218, after manual maze data entry, the program jumps to line 100 which does not exist; execution will fall through to line 105, effectively returning to the title screen prompt.
  • Line 490 corrects an infinite-loop risk in trap door placement (IF M(N,TR)=0 THEN LET TR=0), but lines 816–822 use a similar loop that could run indefinitely if the maze has very few non-zero cells.
  • The INPUT C$ at line 255 in the options review text never actually checks the input value other than for "1" at line 256, making the stone-drop enable logic redundant with the menu at line 700.

Content

Appears On

Related Products

Navigate your way through a 3D maze with trap doors, gold bars, marker stones and a compass. Ten separate mazes,...

Related Articles

Related Content

Image Gallery

Supermaze

Source Code

   1 REM B2AC4012803E14936511140193651D03D20F1C92AC4016C03EF9368511F019368511203D20F1C92AC401D203EA936511A01936511703D20F1C92AC4011613E6936511601936511B03D20F1C92AC4013813E393685113019368511E03D20F1C9B
   2 REM B2AC4011B0936832336419329368223364C90000002AC4017C09363233631ED193622336323363C90002AC401BB093683233683233681148193682233683233681C92AC401FB0936832336831C5093682233683C90000002AC4013C193631620936223363C90000000001C1C1CB
   3 REM B1D2AC401609368323364193293683C90000000002AC4016A09367233632336841ED193672336323363C92AC401AF09368323368323364148193683233683C90002AC401F3093682233683233641C4093682233683C90002AC40137193672336841620936723363C90000001E1CB
   4 REM B2AC401609362233641B429366C90000000000000000002AC401280936723364121093622336411029366120093669367C92AC4016D09364121093622336493622336416A1936612009366C92AC401D2093672336412109362233641E60936612009367C90002AC4011619367233641840936612009367C9000000000000222324B
   5 REM B2AC4011B093661B52936223364C90000000000000000002AC4013B09366120093661F293622336412109362233649362C92AC4017B09368112009366936616B193622336412109362233681C92AC401DB09366120093661E7093622336412109362C90000002AC4011B193661840936412109362C90000000000000002223B
   6 REM B2AC40170936833E132336833D20FA2AC4019B2936823E132336833D20FAC92AC4016D093EE363233D20FA36842AC4015C293EF363233D20FAC9002AC401B1093EA3683233D20FA2AC401FB1936823E92336833D20FAC9002AC401F5093E63683233D20FA1C0093E536822336833D20FAC9000002AC401391936323363233684161093632336323363C90000000222324251C1D1E1F2021222324B
   7 REM "TAN          E£RND' ': ',,Q.TAN E£RND' PI ',,Q.TAN E£RND'  TO ' ,,Q.TAN E£RND' %Y' ,,Q.TAN %I2345"
   8 REM "TAN          E£RND' ': ',,Q,,TAN E£RND' PI ',,Q,,TAN E£RND'  TO ' ,,Q,,TAN E£RND' %Y' ,,Q,,TAN 12345"
   9 REM BCD8340CD3142CD341CD9B40CDB641CD1A43CDB340CD7B42CD3B41CDCB40CDEE41CD6443CDE340CDC542CD7341CD4444C90B
  10 REM DIM M(10,105)
  14 REM DIM O$(7)
  16 REM DIM S(5)
  18 REM DIM G(5)
  20 SLOW 
  51 LET A=USR 17658
  96 PRINT AT 1,11;"@@@@@@@@@@@@@@@@@@@@@@";AT 2,11;"@@%S%U%P%E%R%M%A%Z%E@@";AT 3,11;"@@@@@@@@@@@@@@@@@@@@@@"
 105 PRINT AT 21,7;"HIT ENTER TO START"
 106 INPUT C$
 107 CLS 
 110 PRINT AT 1,9;"@@@@@@@@@@@@@@@@@@@@@@";AT 2,9;"@@%S%U%P%E%R%M%A%Z%E@@";AT 3,9;"@@@@@@@@@@@@@@@@@@@@@@"
 120 PRINT AT 6,2;"CHOOSE THE ACTION YOU WANT";AT 8,5;"1. INSTRUCTIONS";AT 10,5;"2. PLAY"
 130 PRINT AT 12,5;"3. CREATE MAZE";AT 14,5;"4. SAVE PROGRAM";AT 16,5;"5. REVIEW OPTIONS";AT 18,5;"6. REVIEW MAZE"
 150 IF INKEY$="" THEN GOTO 150
 152 LET A$=INKEY$
 153 CLS 
 154 LET C=VAL A$
 155 IF C<7 THEN GOTO C*20+140
 157 GOTO 180
 163 PRINT AT 1,9;"INSTRUCTIONS";AT 3,0;"TO PLAY SUPERMAZE YOU MUST FIND";AT 4,0;"YOUR WAY THRU A 3-D MAZE USING"
 164 PRINT AT 5,0;"THREE COMMANDS, F-FORWARD MOVE,";AT 6,0;"R-RIGHT TURN, L-LEFT TURN. A";AT 7,0;"TURN DOES NOT COUNT AS A MOVE."
 166 PRINT AT 8,0;"EACH NEW POSITION SHOWS YOU A";AT 9,0;"PICTURE OF WHAT IS AHEAD OF YOU.";AT 10,0;"YOU CAN SEE UP TO FOUR MOVES"
 167 PRINT AT 11,0;"IN FRONT OF YOU UNLESS A WALL OR";AT 12,0;"AN EXIT IS CLOSER. YOU LOSE THE"
 168 PRINT AT 13,0;"GAME IF YOU WALK INTO A WALL OR";AT 14,0;"GO OUT THE ENTRANCE. YOU WIN"
 169 PRINT AT 15,0;"WHEN YOU LEAVE THRU THE EXIT."
 175 PRINT AT 21,6;"HIT ENTER TO START"
 177 INPUT C$
 178 CLS 
 179 GOTO 110
 180 GOSUB 350
 181 GOSUB 700
 184 GOSUB 420
 185 GOTO 500
 200 GOSUB 350
 202 CLS 
 205 PRINT AT 11,3;"INPUT MAZE LOCATION ";
 210 FOR I=1 TO 105
 212 PRINT AT 11,23;I
 214 INPUT M(N,I)
 216 NEXT I
 218 GOTO 100
 221 PRINT AT 5,0;"START THE RECORDER AND HIT ENTER";AT 6,5;" TO SAVE THIS PROGRAM"
 222 IF INKEY$="" THEN GOTO 222
 223 CLS 
 224 GOTO 9000
 241 PRINT AT 0,4;"*** PROGRAM OPTIONS ***"
 242 PRINT AT 2,1;"%1. DROP STONES - YOU ARE GIVEN";AT 3,1;"5 STONES TO DROP ON THE FLOOR";AT 4,1;"FOR LATER REFERENCE. A STONE "
 244 PRINT AT 5,1;"(.) IS DROPPED USING THE D KEY";AT 7,1;"%2. COMPASS - COMPASS OPTION";AT 8,1;"SHOWS YOU THE DIRECTION YOU";AT 9,1;"ARE FACING."
 245 PRINT AT 11,1;"%3. TRAP DOOR - A TRAP DOOR IS";AT 12,1;"PLACED RANDOMLY IN THE MAZE.";AT 13,1;"FALLING THRU IT TRANSPORTS YOU"
 246 PRINT AT 14,1;"TO ANOTHER PART OF THE MAZE.";AT 15,1;"THE TRAP DOOR OCCURS ONLY ONCE."
 247 PRINT AT 17,1;"%4. SEEK GOLD BARS - UP TO 5";AT 18,1;"GOLD BARS "",,"" ARE PLACED AT";AT 19,1;"RANDOM FOR YOU TO FIND BEFORE";
 248 PRINT AT 20,1;"YOU LEAVE.";AT 21,6;"(HIT ENTER TO CONTINUE)"
 255 INPUT C$
 256 IF C$="1" THEN LET C=1
 257 CLS 
 258 GOTO 110
 260 GOSUB 350
 262 CLS 
 265 FOR I=1 TO 105 STEP 5
 267 PRINT TAB 1;M(N,I);TAB 7;M(N,I+1);TAB 13;M(N,I+2);TAB 19;M(N,I+3);TAB 25;M(N,(I+4));
 270 PRINT " ";
 275 NEXT I 
 276 PRINT AT 21,3;"HIT ENTER TO START OVER" 
 277 INPUT C$
 278 CLS 
 279 GOTO 110
 350 CLS 
 351 PRINT AT 1,3;"*** MAZE INFORMATION ***";AT 3,5;"NO.";TAB 11;"SIZE";TAB 20;"MOVES";
 352 PRINT AT 5,6;"1.";TAB 12;"5X5";TAB 21;"11";TAB 6;"2.";TAB 12;"6X8";TAB 21;"18";TAB 6;"3.";TAB 12;"7X5";TAB 21;"15";
 353 PRINT TAB 6;"4.";TAB 12;"8X8";TAB 21;"26";TAB 6;"5.";TAB 11;"10X8";TAB 21;"23";
 354 PRINT TAB 6;"6.";TAB 11;"10X10";TAB 21;"22";TAB 6;"7.";TAB 11;"10X10";TAB 21;"35"
 355 PRINT TAB 6;"8.";TAB 11;"10X10";TAB 21;"43"
 356 PRINT TAB 6;"9.";TAB 11;"10X10";TAB 21;"48",TAB 5;"10.";TAB 11;"10X10";TAB 21;"55"
 365 PRINT AT 16,3;"WHICH MAZE DO YOU WANT?";
 366 INPUT N
 370 IF N>10 OR N<1 THEN GOTO 360
 380 IF C<>2 THEN RETURN 
 400 IF M(N,101)<>0 THEN GOTO 417
 410 PRINT AT 18,6;"CHOOSE ANOTHER MAZE"
 415 GOTO 366
 417 RETURN 
 420 LET S=M(N,101)
 425 LET E=M(N,102)
 430 LET P=S
 450 LET F=0
 455 LET D=2
 460 LET W=0
 465 LET A=1
 468 LET FM=0
 470 LET II=1
 472 RAND 
 475 FOR X=1 TO 5
 476 LET S(X)=0
 477 LET G(X)=0
 478 NEXT X
 479 IF N>5 THEN LET O$(3)="Y"
 480 IF O$(4)<>"Y" THEN GOTO 499
 481 LET JJ=INT (RND*6)
 482 FOR X=1 TO JJ
 483 LET G(X)=INT (RND*100)+1
 484 IF M(N,G(X))=0 THEN GOTO 483
 485 NEXT X
 486 LET TR=0
 487 IF O$(3)<>"Y" THEN GOTO 499
 488 IF TR<>0 THEN GOTO 499
 489 LET TR=INT (RND*100)+1
 490 IF M(N,TR)=0 THEN LET TR=0
 491 GOTO 488
 499 RETURN 
 500 CLS 
 510 IF F>4 OR W=1 THEN GOTO 550
 511 IF D=4 AND P+A*F=S-1 AND F<>0 THEN GOTO 550
 512 IF D=2 AND P+A*F=E+1 AND F<>0 THEN GOTO 550
 513 LET P$=STR$ M(N,P+A*F)
 514 LET ZZ=USR (F*24+16515)
 515 LET PP=P+A*F
 516 LET L=D
 518 IF D=1 THEN LET L=5
 520 IF P$(L)="1" THEN GOTO 526
 522 LET ZZ=USR (F*28+16795)
 524 GOTO 528
 526 LET ZZ=USR (F*37+16945)
 528 LET R=D+2
 530 IF D=4 THEN LET R=2
 532 IF P$(R)="1" THEN GOTO 538
 534 LET ZZ=USR (F*28+16643)
 536 GOTO 540
 538 LET ZZ=USR (F*37+17141)
 540 LET L=D+1
 542 IF P$(L)<>"1" AND F<>4 THEN GOTO 546
 543 LET ZZ=USR (F*35+17336)
 544 LET W=1
 546 IF O$(4)="Y" AND G(1)=PP OR G(2)=PP OR G(3)=PP OR G(4)=PP OR G(5)=PP THEN LET ZZ=USR (F*10+17595)
 547 IF S(1)=PP OR S(2)=PP OR S(3)=PP OR S(4)=PP OR S(5)=PP THEN LET ZZ=USR (F*10+17532)
 548 LET F=F+1
 549 GOTO 510
 550 IF O$(2)=" " THEN GOTO 560
 551 PRINT AT 1,2;"N";AT 2,1;"W+E";AT 3,2;"S"
 552 IF D=1 THEN PRINT AT 1,2;"%N"
 553 IF D=2 THEN PRINT AT 2,3;"%E"
 554 IF D=3 THEN PRINT AT 3,2;"%S"
 555 IF D=4 THEN PRINT AT 2,1;"%W"
 556 IF O$(3)<>"Y" OR P<>TR THEN GOTO 560
 557 GOSUB 800
 558 GOTO 631
 560 LET P$=STR$ M(N,P)
 570 PRINT AT 21,7;"WHICH WAY? (F,R,L)"
 571 SLOW 
 572 IF INKEY$="" THEN GOTO 572
 573 LET A$=INKEY$
 575 IF A$<>"F" AND A$<>"R" AND A$<>"L" AND A$<>"D" THEN GOTO 572
 578 IF A$<>"R" THEN GOTO 584
 580 LET D=D+1
 582 IF D=5 THEN LET D=1
 583 GOTO 631
 584 IF A$<>"L" THEN GOTO 590
 585 LET D=D-1
 586 IF D=0 THEN LET D=4
 588 GOTO 631
 590 IF P<>E OR D<>2 OR A$<>"F" THEN GOTO 599
 591 IF O$(4)<>"Y" THEN GOTO 593
 592 IF G(1)<>0 OR G(2)<>0 OR G(3)<>0 OR G(4)<>0 OR G(5)<>0 THEN GOTO 840
 593 LET FM=FM+1
 595 PRINT AT 1,9;"% %Y%O%U% %E%S%C%A%P%E%D% ";AT 3,4;"% %H%I%T% %E%N%T%E%R% %T%O% %S%T%A%R%T% %O%V%E%R% "
 596 INPUT A$
 597 CLS 
 598 GOTO 900
 599 IF A$<>"F" OR P<>S OR D<>4 THEN GOTO 608
 600 PRINT AT 1,11;"% %Y%O%U% %L%O%S%E% ";AT 3,2;"% %Y%O%U% %W%A%L%K%E%D% %O%U%T% %T%H%E% %E%N%T%R%A%N%C%E% ";AT 4,4;"% %H%I%T% %E%N%T%E%R% %T%O% %S%T%A%R%T% %O%V%E%R% "
 604 INPUT A$
 605 CLS 
 606 GOTO 20
 608 LET L=D+1
 610 IF A$<>"F" OR P$(L)<>"1" THEN GOTO 619
 612 PRINT AT 1,11;"% %Y%O%U% %L%O%S%E% ";AT 3,4;"% %Y%O%U% %W%A%L%K%E%D% %I%N%T%O% %A% %W%A%L%L% "
 616 INPUT A$
 617 CLS 
 618 GOTO 20
 619 IF A$<>"F" THEN GOTO 638
 620 IF O$(4)<>"Y" THEN GOTO 625
 621 FOR X=1 TO JJ
 622 IF G(X)=P THEN LET G(X)=0
 623 NEXT X
 625 LET FM=FM+1
 630 IF A$="F" THEN LET P=P+A
 631 IF D=1 THEN LET A=-10
 632 IF D=2 THEN LET A=1
 633 IF D=3 THEN LET A=10
 634 IF D=4 THEN LET A=-1
 635 LET F=0
 636 LET W=0
 638 IF A$<>"D" OR O$(1)<>"Y" THEN GOTO 660
 639 LET S(II)=P
 640 PRINT AT 21,7;"   STONE DROPPED  "
 641 FOR X=1 TO 15
 642 NEXT X
 645 LET II=II+1
 647 IF II>5 THEN LET O$(1)=" "
 648 GOTO 570
 660 IF A$<>"D" THEN GOTO 670
 662 PRINT AT 21,7;"   OUT OF STONES   "
 664 FOR X=1 TO 15
 665 NEXT X
 668 GOTO 570
 670 GOTO 500
 700 CLS 
 701 PRINT AT 1,4;"*** MENU OF OPTIONS ***";AT 3,8;"1) DROP STONES";AT 5,8;"2) COMPASS";AT 7,8;"3. TRAP DOOR"
 703 PRINT AT 9,8;"4) SEEK GOLD BARS";AT 21,6;"CHOOSE OPTIONS (Y/N)"
 712 FOR I=1 TO 4
 714 PRINT AT I*2+1,6;"%>"
 716 IF INKEY$="" THEN GOTO 716
 718 IF INKEY$<>"Y" THEN GOTO 726
 720 LET O$(I)="Y"
 722 PRINT AT I*2+1,6;"Y"
 724 GOTO 730
 726 PRINT AT I*2+1,6;"N"
 728 LET O$(I)=""
 730 NEXT I
 732 RETURN 
 800 PRINT AT 21,7;"OH NO - A TRAP DOOR"
 802 FOR X=1 TO 10
 804 NEXT X
 812 LET D=INT (RND*4)+1
 814 LET TR=0
 816 IF TR<>0 THEN GOTO 824
 818 LET TR=INT (RND*100)+1
 820 IF M(N,TR)=0 THEN LET TR=0
 822 GOTO 816
 824 LET P=TR
 826 LET TR=0
 828 LET O$(3)=""
 830 RETURN 
 840 PRINT AT 1,7;"% %G%O% %B%A%C%K% %F%O%R% %T%H%E% % ";AT 2,7;"% %R%E%S%T% %O%F% %T%H%E% %G%O%L%D% ";
 841 FOR X=1 TO 20
 842 NEXT X
 845 GOTO 570
 900 PRINT AT 2,8;"*** RESULTS ***";AT 5,5;"YOU CHOSE MAZE ";AT 5,20;N;
 905 PRINT AT 5,22;". THE";AT 7,5;"MINIMUM NUMBER OF MOVES";AT 9,5;"NEEDED IS ";AT 9,15;M(N,103);
 910 PRINT AT 9,17;". YOU TOOK";AT 11,5;FM;AT 11,9;"MOVES. ";
 915 IF O$(4)="Y" THEN PRINT AT 11,16;"YOU FOUND ";AT 11,26;JJ;AT 13,5;"GOLD BARS."
 920 INPUT A$
 922 CLS 
 925 GOTO 20
 9000 SAVE "MAZ%E"
 9010 GOTO 20

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

People

No people associated with this content.

Scroll to Top