Challenger 1

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

Challenger 1 is a two-program package containing a maze game and a Tic Tac Toe game, both driven largely by machine code routines stored in the REM statement at line 1 of each program. The maze program allows the user to select a speed from 0 (fast) to 9 (slow), writing a timing value via POKE 16898, and uses PEEK/POKE of system variable addresses to manage game state across RUN restarts. The Tic Tac Toe program calls USR 16514 to invoke machine code that handles game logic, returning a value used to determine win or tie conditions displayed with conditional AND string expressions. Both programs use SAVE to store themselves to tape and manipulate POKE 16389 to switch between 32-column and other display modes. The REM blocks at line 1 in each program serve as machine code storage areas, a common technique for embedding Z80 routines directly in BASIC listings.


Program Analysis

Package Overview

The listing contains two independent BASIC programs. The first is a maze game with user-selectable speed; the second is a Tic Tac Toe game that pits the user against the computer. Each program uses the line-1 REM statement as a machine code storage area, accessed via USR calls pointing into that region of memory.

Program 1 — Maze: Structure

LinesPurpose
1REM block containing Z80 machine code for maze logic
10Sets SLOW mode
80Title screen and speed prompt
90–100Input loop waiting for a digit character ‘0’–’9′
110POKEs timing value derived from the chosen digit
120–150CLS, game state setup via PEEK/POKE, conditional RUN
200–270FAST mode, SAVE routine, reset POKEs, restart via RUN

Program 1 — Notable Techniques

  • Speed selection via POKE: Line 110 calculates CODE C$*2-52 from the digit entered and POKEs it to address 16898, directly writing a timing constant used by the machine code.
  • INKEY$ polling loop: Lines 90–100 use a tight IF C$<"0" OR C$>"9" THEN GOTO 90 loop, rejecting non-digit input.
  • Conditional game-state management: Line 130 uses an expression combining USR 16514<>34 (a Boolean yielding 0 or 1) with PEEK 16971 to compute a new value for the game-level counter, which is then bounded below by 1 at line 140 using A*(A>0)+1.
  • Conditional RUN: Line 150 uses RUN 120+(30 AND INKEY$<"A") to either restart the game loop (jumping to line 150) or fall through to the SAVE/reset block, depending on whether a key is currently held.
  • Display mode switching: POKE 16389 is used at lines 210 and 240 to switch between display widths before and after the SAVE operation.

Program 2 — Tic Tac Toe: Structure

LinesPurpose
1REM block containing Z80 machine code for game logic and board rendering
10–30Display mode setup and SLOW
40–50Title and first-move prompt, INPUT A$
60–65CLS and game header
70Call machine code via USR 16514; result stored in A
80Conditional PRINT using AND to select win or tie message
90Tight RUN loop waiting for keypress before restarting
100–140FAST, POKE display register, SAVE, RUN

Program 2 — Notable Techniques

  • USR return value as game result: Line 70 captures USR 16514 into A. The machine code routine at the start of the REM block performs the entire game, returning a non-zero value for a win and zero (or a specific value) for a tie.
  • AND-conditional string display: Line 80 uses the idiom "** I WIN **" AND A and "** TIE GAME **" AND NOT A. In this dialect, AND with a numeric condition returns the string if the condition is true, or an empty string otherwise, allowing a single PRINT statement to handle both outcomes.
  • Conditional RUN loop: Line 90 uses RUN 90 AND INKEY$<"A" to loop on itself until a key is pressed, whereupon INKEY$<"A" becomes false, the AND yields 0, and RUN 0 restarts the program from the beginning.
  • INPUT for first-move choice: INPUT A$ at line 50 captures whether the user wants to go first; the actual interpretation is handled inside the machine code, which presumably inspects the system variable area where A$ is stored.

Shared Architectural Pattern

Both programs follow the same architectural pattern: a BASIC front-end handles user interaction and display setup, while all substantive game logic resides in Z80 machine code embedded in the line-1 REM statement. The entry point USR 16514 is consistent across both programs; 16514 is the address of the second byte of the REM statement’s data area (the first byte being the length word), placing the machine code immediately at the start of the REM content. POKE 16389 manipulates the system display register in both programs before and after SAVE operations.

Potential Anomalies

  • Line 150 in the maze program uses 30 AND INKEY$<"A" rather than the more common 120 AND ... seen in similar constructions; this causes a jump to line 150 (an existing line) rather than line 120, effectively re-entering the game state check rather than the CLS. Whether this is intentional depends on the machine code behavior.
  • The POKE value at line 110 (CODE C$*2-52) for digit ‘0’ gives 48*2-52=44, and for ‘9’ gives 57*2-52=62, producing a range of 44–62 for the timing constant at address 16898.

Content

Appears On

Related Products

In Amazer, enter the maze from the top and work your way down to the bottom without being captured by...

Related Articles

Related Content

Image Gallery

Source Code

   1 REM UORNDM#RND NEW*LEN ▌M#RNDM#RNDE£RNDLN TAB PI CLEARQ# U#RND[E]▛WM#RND# NEW▘#U#RND# RETURN▖K▝▞  RETURN2S▝▞▘ CLEAR##CHR$ ▖INKEY$ ACS S[S]S CLS▖[J] CLEAR[Y]#4▘##[(]M#RND[U]4?Y1[>]INKEY$ ACS S[S]S CLS# GOSUB #LEN 2### NEW▘LEN ▝M#RND##ACS Z GOSUB #LEN £ACS S[S]S CLS#▙▟LEN ▀M#RNDU#RNDACS Z#ACS Z█X CLEAR##ACS S[S]S CLS#[)]#U#RND[B]CR77QX▞27▖# CLEAR##[)][S]C3U#RND▟[S]C/ACS 5U#RND[)][S]C?#▟[S]C~~U#RND[S]C▖Q-/▝Q ▌(ABS 7QX77QX▞27▖[J] CLEAR[Y]#U#RND#C* CLEAR[-]#[S]C+#[S]C)# CLEAR▚#[S]C~~U#RND[S]C▖Q /▝Q:▌(USR 7QXU#RND[B]4▘# CLEAR##U#RNDWM#RND RETURN" AND [0]RNDU#RND7LN TAB PIE£RND)5 ; CLEAR## GOSUB #6#RNDU#RND▛M#RND# NEW▝X5#RND)5 #7#7# INPUT  RETURN7#E£RND;# NEW3W#;#[B]4 CLS6#RND#▛ NEW3W#;#[B]4 CLS6#RND▞ ( RETURN#Y#<= RETURN3SQR )5 5#RNDP4#Q(Y RUN <= RETURNE#RND FASTACS #4▘FY LOAD <= RETURN333S▘73S▝ GOSUB #3S▘; FOR E£RND GOSUB #K" FOR #[B]4▞6#RND STOPQ  LPRINT QO:6 FOR E(RND GOSUB PI GOSUB #**5#RNDP4[7]Q:77#F##7#7#7##F#E#RND GOSUB ##RND GOSUB ##RND6#RND##INKEY$ ACS C,,#[B]4▌>Q*/<CHR$ OCJ FOR U#RND GOSUB #M#RND# GOSUB #M#RND## CLEAR###ACS J INPUT (#,,YXF[Y]74▌7[Y]FC/#[B]C▒CHR$ O4(>Q█TAN [J]>Q*# GOSUB #M#RND/▘ FOR 6#RND# GOSUB INKEY$ ▞37QX[S]4▀7Q ( PRINT TAN 
  10 SLOW
  80 PRINT ,TAB 10;"M A Z E",,,,,"ENTER SPEED:  0=FAST TO 9=SLOW"
  90 LET C$=INKEY$ 
 100 IF C$<"0" OR C$>"9" THEN GOTO 90
 110 POKE 16898,CODE C$*2-52
 120 CLS
 130 LET A=(USR 16514<>34)*3+PEEK 16971-3
 140 POKE 16971,A*(A>0)+1
 150 RUN 120+(30 AND INKEY$ <"A")
 200 FAST
 210 POKE 16389,64
 220 CLS
 230 SAVE "MAZ[E]"
 240 POKE 16389,128
 250 CLS
 260 POKE 16971,14
 270 RUN 
 
   1 REM E£RND)# ;Y1LN #PILN ▟PILN #PILN ▟PILN #PI CLEARQ## CLEARQ##E(RND777YY[Y]ASN /PI CLEAR#O NEW▛WACS SIN # GOSUB INKEY$  CLEAR## RETURN#STI# CLEAR##G CLEAR## CLEAR##ARND#LN [,]PIC",LN VAL PILN  STEP PI[J][Y]C- CLEAR## CLEAR##G[X]K<> CLEARO# CLEAR[Y]#S▒I#/SGN LN T#TAN I# CLEAR## CLEAR## CLEAR##ARND#LN [,]PIC£,LN VAL PILN  STEP PI[J][Y]ASN  SAVE INKEY$  CLEAR## CLEAR##G[X]K>= CLEARO# CLEAR[Y]#S▖I#/SQR  CLEAR## RETURN#4"Y▌ CLEAR[Y]#4#Y▛/# RETURN#K# GOSUB #(RND<<<▞▘ CLEAR##ARND, RETURNY4N#XC< RETURN▌C? RETURN▛C" CLEAR## RETURN▞C▖ RETURN▒4▝▞,,# CLEAR[A]# RETURN▀C,,# CLEAR[I]# RETURN▒#4# CLEAR#O NEW▞LEN ▝/#Y~~ CLEAR[-]#ACS ##C▘[Y]Y▌4▘# CLEAR[Y]##4#Y,,[Y]4#CHR$ ▝/#4QI▘Y▝#ACS #C▝▐▐▐ CLEAR[Y]#C+ CLEAR[Y]#C([J][+] RETURN▝##K NEWLEN ▝ RETURN,,S STEP /(#LN VAL PI FOR E£RND,,[J][Y]C, FOR / STEP  CLEAR#OY▛[4]WACS #C▘WLN VAL PIE£RND,,#[B]4 DIM LN T##CHR$ #: ▞▀£CHR$ ▀S▞( RAND CHR$ #/ NEXT 5#RNDOY#[Y]S###Y RUN <= RETURN▘ ▌£?K>( IF Y LOAD <= RETURN?▘~~▖$?K▖( IF / STOP CLEAR##GARND##LN VAL PIE£RND,,#[B]4SQR Y▖#7#)4 ;Q▞7# CLEARO#Y# CLEAR[Y]#ABS [T]RND▘  TAN )0 ;Q▌777Q▌;#W77Q▌7#W77Q▌7#WTAN ;FFQ▗7▞▝Q▄7Q▄7Q▙7( PRINT Q▄7Q▄TAN ,[Y]S▝[J]TAN CHR$ ▌K▝LEN ~~[Y]COS , RETURN▞S▝CHR$ ▌▛ GOSUB #LEN ~~[Y]COS ,ACS #""? GOSUB #LEN ▌[Y]COS LEN ▌[Y]TAN  FAST5# #)# # RETURN▛C▖ RETURN▖4▘;777( LET ## LPRINT TAN VAL #5# )# # RETURN▛C▖ RETURN▖4▘;777( LET ##AT D GOSUB PILN ;#C(##D GOSUB #LN ;#C▞ FOR ,,ACS WACS 1##E£RND,,TAN #[B]#C,, RETURNOCOS  RETURNRCOS  RETURNUTAN  RETURN#COS  RETURN#COS  RETURN#COS  RETURNSGN COS  RETURNUSR COS  RETURNNOT TAN Q▄7Q▖)4 ;Q▙7Q▌TAN 
  10 POKE 16389,128
  20 CLS
  30 SLOW
  40 PRINT ,TAB 8;"TIC TAC TOE",,,,,"  DO YOU WANT TO GO FIRST?"
  50 INPUT A$
  60 CLS
  65 PRINT TAB 8;"TIC TAC TOE"
  70 LET A=USR 16514
  80 PRINT AT 13,7;" ** I WIN **" AND A;"** TIE GAME **" AND NOT A
  90 RUN 90 AND INKEY$ <"A"
 100 FAST
 110 POKE 16389,72
 120 CLS
 130 SAVE "TI[C]"
 140 RUN 

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

People

No people associated with this content.

Scroll to Top