Star Trip

Products: ZX Star-Trip
Date: 1981
Type: Cassette
Platform(s): TS 1000
Tags: Game

STARTRIP is a Star Trek–inspired strategy game in which the player commands the Enterprise across a toroidal 8×8 galaxy of sectors, each represented as an 8×8 parsec grid. The player manages energy, photon torpedoes, and shields while hunting Klingon ships, docking with starbases for resupply, and avoiding novas and supernovas. Game state for each sector is packed into a single integer per cell of the A(8,8) array, encoding Klingon count, starbase presence, and star count as hundreds, tens, and units digits respectively. Screen-position reading via PEEK of the display file address (lines 9000–9010) is used to detect what character occupies a given AT position before printing, allowing collision detection without a separate map array. Difficulty is controlled by the RA variable (1–6 star-rating), which scales the Klingon population, energy budget, and final score thresholds.


Program Analysis

Program Structure

The program is organised into functional blocks separated by REM statements, with command dispatch handled by a computed GOTO C*1000 at line 660. The main game loop runs from roughly line 400 to 660, with the following major sections:

  1. Lines 5–19: Initialisation and title display (via GOSUB 9300), string table load (GOSUB 9200)
  2. Lines 30–214: Galaxy generation — populating the 8×8 sector array
  3. Lines 220–354: Current sector setup — placing the Enterprise, Klingons, starbase, and stars
  4. Lines 400–660: Status display, docking check, and command input loop
  5. Lines 1000–1150: Helm (warp movement)
  6. Lines 2000–2140: Short-range scan (labelled “Long Range Scan” in the REM but displaying adjacent sectors)
  7. Lines 3000–3170: Phaser control
  8. Lines 4000–4160: Photon torpedo control
  9. Lines 5000–5060: Shield control
  10. Lines 6000–6140: Instructions
  11. Lines 7000–7010: Resignation
  12. Lines 8000–8590: Subroutines (distance calculation, Klingon kill, course vector, shield destruction)
  13. Lines 9000–9420: Utility subroutines and initialisation
  14. Lines 9890–9999: End-of-game scoring and rating

Galaxy and Sector Data Packing

Each element of the two-dimensional array A(8,8) stores three values packed into a single integer: 100*X + 10*Y + Z, where X is the number of Klingons (1 to RA), Y is 1 if a starbase is present (0 otherwise), and Z is the number of stars (1–5). Unpacking is performed with integer division and modulo arithmetic at lines 270–300. This is a classic space-saving technique that avoids the need for a three-dimensional array.

Screen-Peek Collision Detection

The subroutine at lines 9000–9010 reads the character code at the current cursor position directly from the display file:

9000 LET CH=PEEK (PEEK 16398+256*PEEK 16399)

System variables at addresses 16398–16399 hold the address of the current print position in the display file. By issuing PRINT AT r,c; (with no output) and then calling this subroutine, the program determines what is already drawn at that cell. Character codes used as sentinels include 128 (space/empty), 3 (starbase graphic), 151 (star graphic), and 176 (Klingon graphic). This avoids maintaining a separate in-memory sector map.

Computed GOTO Dispatch

Command selection uses GOTO C*1000 at line 660, where C is an integer 1–7 entered by the player. This dispatches directly to line 1000 (helm), 2000 (scan), 3000 (phasers), 4000 (torpedoes), 5000 (shields), 6000 (instructions), or 7000 (resignation). Input is validated at line 658 to ensure C is an integer in range.

Toroidal Galaxy Wrapping

The galaxy wraps at its edges. Sector coordinates P and Q are kept in range 1–8 using the idiom at lines 240–250:

LET P=P-8*(P>8)+8*(P<1)

The same pattern is applied to the scan subroutine at lines 2012–2014 for variables G and H. Boolean expressions evaluate to 1 (true) or 0 (false), making this a branchless modular wrap.

Movement and Sector Transition

Warp movement (lines 1070–1136) steps the ship one parsec at a time in a direction determined by the 8-point compass encoded as course 0–7. The course-to-vector translation at lines 8530–8590 sets M (row delta) and N (column delta) using conditional assignments. If the ship moves off the edge of the current sector, U is set to 1 and GOTO 230 regenerates the new sector; otherwise it lands within the current sector.

Difficulty Scaling

The player-chosen star-rating RA (1–6) controls several aspects of difficulty:

  • Maximum Klingons per sector (INT(RND*RA)+1)
  • Size of Klingon, position arrays (DIM G(RA), DIM H(RA), DIM K(RA))
  • Initial total energy budget: TE=(RA+1)*8000
  • Score thresholds at end-of-game, scaled by (RA+7)/16

Scoring System

The final score at line 9906 is computed as:

S = PE + INT(TE/100/RA) + (KL-K)*10

where PE is a penalty (negative values for destroying a starbase, crew casualties, or energy exhaustion), TE is remaining total energy divided by difficulty, KL is the initial Klingon count, and K is the survivors. Five rating tiers are checked sequentially at lines 9930–9980, each threshold a multiple of RA*200.

Notable Techniques and Anomalies

  • The REM at line 1995 says “LONG RANGE SCAN” but the print at line 2000 says “SHORT RANGE SCAN” — the labels are transposed.
  • FAST (line 14) is called before galaxy generation to speed up the setup loop, and SLOW (line 228) re-enables normal display before sector rendering.
  • The string array A$(13,33) stores all game messages with fixed-length padding. Random selection from subsets uses RND*N+offset with fractional indices, relying on array indexing truncation.
  • Line 9999 attempts to print all 13 rows of A$ in a loop up to 20, which will access undefined rows 14–20 — this is a latent bug that would cause an error if the game-over scoring branch reaches the excellent path.
  • Phaser damage to the player (lines 3131–3136) fires back based on remaining Klingon strength divided by distance, and there is a chance of triggering a Scottie damage message and further energy drain.
  • The subroutine at line 8200 searches the Klingon position arrays to find which entry matches G,H (the torpedo hit position), then calls 8230 to mark it destroyed — an unusual fall-through into a shared code path also used by phasers.

Key Variables

VariableRole
A(8,8)Galaxy sector data (packed Klingons/starbase/stars)
G(RA), H(RA)Row/column positions of Klingons in current sector
K(RA)Shield strength of each Klingon (negative = alive, 0 = dead)
EEnterprise energy
TETotal fleet energy pool (for docking replenishment)
OPhoton torpedoes remaining
SShield energy level
TCurrent stardate
KTotal Klingons remaining in galaxy
KLInitial total Klingon count
P, QCurrent sector coordinates
A, BEnterprise position within sector (row, col)
RADifficulty rating (1–6)
PEPenalty score
CHCharacter code read from display file

Content

Appears On

Related Products

Nail the aliens in outer space. Warp, photons, starbases, smart K-ons.

Related Articles

Related Content

Image Gallery

Source Code

   5 REM (C)1981 BUG-BYTE
  10 REM **STARTRIP**
  11 LET T=0
  12 GOSUB 9300
  14 FAST 
  16 GOSUB 9200
  18 LET PE=0
  19 LET TE=(RA+1)*8000
  20 LET K=0
  30 LET T=INT (RND*200)+201
  40 LET E=3000
  50 LET O=15
  60 LET S=0
  90 LET L=T
 100 DIM A(8,8)
 125 REM **SET UP SECTORS**
 130 FOR I=1 TO 8
 140 FOR J=1 TO 8
 150 LET Y=0
 160 LET X=INT (RND*RA)+1
 170 IF RND>.88 THEN LET Y=1
 180 LET Z=INT (RND*5)+1
 190 LET A(I,J)=100*X+10*Y+Z
 200 LET K=K+X
 210 NEXT J
 212 NEXT I
 214 LET KL=K
 220 LET P=INT (RND*8)+1
 225 LET Q=INT (RND*8)+1
 228 SLOW 
 230 REM **SET UP CURRENT SECTOR
 232 LET V=0
 240 LET P=P-8*(P>8)+8*(P<1)
 250 LET Q=Q-8*(Q>8)+8*(Q<1)
 255 LET A=INT (RND*8)
 258 LET B=INT (RND*8)
 260 LET Z=A(P,Q)
 270 LET X=INT (Z/100)
 280 LET Z=Z-X*100
 290 LET Y=INT (Z/10)
 300 LET Z=Z-Y*10
 302 DIM G(RA)
 304 DIM H(RA)
 306 DIM K(RA)
 308 PRINT AT 0,0;
 310 FOR I=1 TO 8
 312 PRINT "% % % % % % % % "
 314 NEXT I
 316 PRINT AT A,B;"%$"
 320 FOR I=1 TO X
 321 LET K(I)=-200
 322 LET G(I)=INT (RND*8)
 324 LET H(I)=INT (RND*8)
 326 PRINT AT G(I),H(I);
 327 GOSUB 9000
 328 IF CH<>128 THEN GOTO 322
 330 PRINT "%K"
 332 NEXT I
 334 IF Y=0 THEN GOTO 344
 336 PRINT AT INT (RND*8),INT (RND*8);
 338 GOSUB 9000
 340 IF CH<>128 THEN GOTO 336
 342 PRINT "''"
 344 FOR I=1 TO Z
 346 PRINT AT INT (RND*8),INT (RND*8);
 348 GOSUB 9000
 350 IF CH<>128 THEN GOTO 346
 352 PRINT "%*"
 354 NEXT I
 400 LET C$="GREEN"
 402 IF E<=0 THEN GOTO 9800
 410 IF X<>0 THEN LET C$="RED"
 420 PRINT AT A,B-1+(B=0);
 430 GOSUB 9000
 440 IF CH=3 THEN LET C$="DOCKED"
 442 PRINT AT A,B+1-(B=7);
 444 GOSUB 9000
 446 IF CH=3 THEN LET C$="DOCKED"
 448 IF V=1 OR C$<>"DOCKED" THEN GOTO 550
 450 LET TE=TE+E-3000
 452 LET E=3000
 453 IF TE>=0 THEN GOTO 458
 454 PRINT "STARFLEET""S ENERGY BANKS       EXHAUSTED."
 456 GOTO 9900
 458 LET O=15
 460 LET V=1
 550 PRINT AT 1,10;"STARDATE   ";T
 560 PRINT AT 2,10;"CONDITION  ";C$;"   "
 570 PRINT AT 3,10;"ENERGY     ";E;"   "
 580 PRINT AT 4,10;"TORPEDOES  ";O;" "
 590 PRINT AT 5,10;"SHIELDS    ";S;"   "
 600 PRINT AT 6,10;"KLINGONS   ";K;"   "
 610 GOSUB 9100
 630 IF L=T OR C$="DOCKED" OR C$="GREEN" THEN GOTO 640
 635 IF RND>.3 THEN GOTO 4152
 640 IF K=0 THEN PRINT "WELL DONE,CAPTAIN-THE FEDERATION HAS BEEN SAVED"
 645 IF K=0 THEN GOTO 9900
 648 LET L=T-1
 650 PRINT "WHAT ARE YOUR ORDERS, CAPTAIN?             (1-7)"
 655 INPUT C
 658 IF C<0 OR C>7 OR C<>INT C THEN GOTO 655
 659 IF RND>.75 THEN PRINT "SPOCK:   ";A$(RND*3+10.5)
 660 GOTO C*1000
 995 REM **HELM CONTROL**
 1000 GOSUB 8500
 1010 PRINT "SULU: WARP FACTOR,CAPTAIN?(1-63)"
 1020 INPUT W
 1022 IF W>E THEN PRINT "SCOTTIE:YE OVERLOADIN"" THE      ENERGY BANKS,CAP""N."
 1030 IF W>E OR W<1 OR W>63 OR W<>INT W THEN GOTO 1010
 1040 PRINT AT A,B;"% "
 1050 LET E=E-W
 1060 LET T=T+W
 1070 FOR I=1 TO W
 1080 LET U=1
 1090 LET A=A+M
 1100 LET B=B+N
 1110 IF A<0 OR A>7 OR B<0 OR B>7 THEN GOTO 1120
 1112 LET U=0
 1113 PRINT AT A,B;
 1114 GOSUB 9000
 1115 IF CH=128 THEN GOTO 1120
 1116 LET A=A-M
 1117 LET B=B-N
 1120 NEXT I
 1130 IF U=0 THEN GOTO 1140
 1132 LET Q=Q+INT (A/8)
 1134 LET P=P+INT (B/8)
 1136 GOTO 230
 1140 PRINT AT A,B;"%$"
 1150 GOTO 400
 1995 REM **LONG RANGE SCAN**
 2000 PRINT "SHORT RANGE SCAN"
 2002 PRINT "%K''%*  %K''%*  %K''%*"
 2005 FOR J=Q-1 TO Q+1
 2010 FOR I=P-1 TO P+1
 2012 LET G=I-8*(I>8)+8*(I<1)
 2014 LET H=J-8*(J>8)+8*(J<1)
 2020 LET U=A(G,H)
 2030 IF INT (U/100)=0 THEN PRINT "0";
 2040 IF INT (U/10)=0 THEN PRINT "0";
 2050 PRINT U;"  ";
 2090 NEXT I
 2100 PRINT 
 2110 NEXT J
 2120 FOR D=1 TO 35
 2130 NEXT D
 2140 GOTO 610
 2995 REM **PHASER CONTROL**
 3000 PRINT "CHEKOV: PHASER ENERGY?"
 3020 INPUT F
 3030 IF E<F OR F<>INT F THEN GOTO 3000
 3032 LET E=E-F
 3035 IF X=0 THEN GOTO 3150
 3040 LET F=F/X
 3050 FOR I=1 TO RA
 3060 IF K(I)=0 THEN GOTO 3140
 3070 GOSUB 8000
 3080 LET G=K(I)
 3090 LET G=G+2*INT (F/D)
 3100 IF G>=0 THEN GOSUB 8230
 3110 IF G>=0 THEN GOTO 3140
 3120 LET K(I)=G
 3130 IF C$="DOCKED" THEN GOTO 3140
 3131 LET G=-INT (G/D)
 3132 LET S=S-G
 3133 PRINT G;" HIT ON SHIELDS."
 3134 IF G<100 THEN GOTO 3140
 3135 PRINT "SCOTTIE: ";A$(RND*3+3.5);"CAP""N."
 3136 LET E=E-INT (RND*G)*2
 3140 NEXT I
 3145 IF S<0 THEN GOTO 8100
 3150 LET L=T
 3160 LET A(P,Q)=A(P,Q)-(INT (A(P,Q)/100)-X)*100
 3170 GOTO 400
 3995 REM **TORPEDO CONTROL**
 4000 IF O<1 THEN PRINT "SULU: NO TORPEDOES LEFT, SIR"
 4002 IF O<1 THEN GOTO 650
 4010 GOSUB 8500
 4020 LET O=O-1
 4030 LET G=A
 4040 LET H=B
 4050 FOR I=1 TO 7
 4060 LET G=G+M
 4070 LET H=H+N
 4082 PRINT AT G,H;
 4084 GOSUB 9000
 4090 IF CH<>128 THEN GOTO 4110
 4100 NEXT I
 4110 IF CH<>3 THEN GOTO 4116
 4111 PRINT AT G,H;"% "
 4112 GOSUB 9100
 4113 PRINT "SPOCK: WE HAVE DESTROYED A STAR BASE, CAPTAIN"
 4114 LET PE=-200
 4115 GOTO 9900
 4116 IF CH<>151 THEN GOTO 4130
 4118 PRINT AT G,H;"% "
 4120 GOSUB 9100
 4121 LET R=INT (RND*10)
 4122 PRINT "STAR HAS GONE ";
 4123 IF R<9 THEN GOTO 4127
 4124 PRINT "SUPERNOVA"
 4125 LET PE=-100
 4126 GOTO 9900
 4127 PRINT "NOVA"
 4128 LET S=S-100
 4129 GOTO 4152
 4130 IF CH<>176 THEN GOTO 4150
 4140 GOSUB 8200
 4142 GOTO 4152
 4150 GOSUB 9100
 4152 LET F=0
 4155 IF RND>.75 THEN PRINT "KLINGON MESSAGE:";A$(RND*4+6.5)
 4160 GOTO 3032
 4995 REM **SHIELD CONTROL**
 5000 LET E=E+S
 5020 PRINT "CHEKOV: SHIELD ENERGY, SIR?"
 5030 INPUT S
 5040 LET E=E-S
 5050 IF E<1 THEN PRINT "SCOTTIE:THE ENERGY BANKS CANNO"" TAKE IT, CAP""N."
 5052 IF E<1 THEN GOTO 5000
 5060 GOTO 400
 5995 REM **INSTRUCTIONS**
 6000 CLS 
 6010 PRINT "   YOU ARE CAPTAIN KIRK OF THE  STARSHIP ENTERPRISE(%$). YOUR    MISSION IS TO DESTROY ALL THE   KLINGON SHIPS(%K)IN THE GALAXY."
 6012 PRINT 
 6015 PRINT "   THERE ARE 64 SECTORS OF THE  GALAXY,WHICH ARE EACH 8 PARSECS SQUARE."   
 6017 PRINT 
 6020 PRINT "   YOU ARE GIVEN 15 PHOTON      TORPEDOES,AND 3000 ENERGY UNITS."
 6021 PRINT 
 6022 PRINT "   YOU MAY DOCK BESIDE A STAR   BASE(''),WHICH REPLENISHES YOUR  ENERGY AND TORPEDOES AND        PROTECTS YOU FROM ATTACK."
 6023 PRINT 
 6024 PRINT "PRESS ANY KEY TO CONTINUE"
 6025 IF INKEY$="" THEN GOTO 6025
 6030 CLS 
 6040 PRINT "   THE COMMANDS ARE:"
 6050 PRINT "1)HELM-TO MOVE TO ANY POINT IN  THE GALAXY,GIVING THE COURSE ANDWARP(EACH UNIT MOVES 1 PARSEC)."
 6055 PRINT 
 6060 PRINT "2)LONG RANGE SCAN-GIVES THE NO. OF %K''%* IN THE ADJACENT SECTORS."
 6065 PRINT 
 6070 PRINT "3)PHASERS-THIS WEAPON ACTS IN   ALL DIRECTIONS BUT ITS EFFECT   DECREASES WITH DISTANCE."
 6075 PRINT 
 6080 PRINT "4)PHOTON TORPEDOES-DIRECTIONAL  WEAPON BUT A SINGLE BOLT WILL   DESTROY A KLINGON AT ANY DIST."
 6085 PRINT 
 6090 PRINT "5)SHIELDS-INPUT AMOUNT OF       ENERGY DIVERTED TO THE SHIELDS."
 6095 PRINT 
 6100 PRINT "6)INSTRUCTIONS"
 6110 PRINT "7)RESIGNATION"
 6120 PRINT "PRESS ANY KEY TO CONTINUE"
 6125 IF INKEY$="" THEN GOTO 6125
 6130 CLS 
 6132 IF T=0 THEN RETURN 
 6134 LET L=T
 6140 GOTO 230
 6995 REM **RESIGNATION**
 7000 PRINT "STARFLEET: RESIGNATION ACCEPTED"
 7010 GOTO 9900
 7990 REM **SUBROUTINES**
 7995 REM **CAL. KLINGON DIST.**
 8000 LET Z=A-G(I)
 8010 LET Y=B-H(I)
 8020 LET D=INT SQR (Z*Z+Y*Y)
 8030 RETURN 
 8095 REM ***********************
 8100 PRINT "THE ENTERPRISE IS DEAD IN SPACE."
 8110 IF S>-100 THEN GOTO 8120
 8112 LET PE=-300
 8114 PRINT " THERE ARE NO SURVIVERS."
 8116 GOTO 9900
 8120 IF S>-50 THEN GOTO 8130
 8122 LET PE=-200
 8124 PRINT "HALF THE CREW WERE KILLED."
 8126 GOTO 9900
 8130 LET PE=S*2
 8132 PRINT -S;" OF THE CREW WERE KILLED."
 8134 GOTO 9900
 8195 REM ***********************
 8200 FOR I=1 TO RA
 8210 IF G(I)=G AND H(I)=H THEN GOTO 8230
 8220 NEXT I
 8230 LET K(I)=0
 8235 PRINT AT G(I),H(I);"% "
 8240 GOSUB 9100
 8250 PRINT A$(RND*3+.5)
 8260 LET X=X-1
 8265 LET K=K-1
 8270 RETURN 
 8495 REM **READ COURSE AND CAL**
 8496 REM **  MOVEMENT VECTOR  **
 8500 PRINT "CHEKOV:COURSE, CAPTAIN?(O-7)"
 8510 INPUT C
 8520 IF C<0 OR C>7 OR C<>INT C THEN GOTO 8500
 8530 LET M=0
 8540 LET N=0
 8550 IF C<2 OR C>6 THEN LET M=-1
 8560 IF C>2 AND C<6 THEN LET M=1
 8570 IF C<4 AND C>0 THEN LET N=1
 8580 IF C>4 THEN LET N=-1
 8590 RETURN 
 8595 REM ***********************
 9000 LET CH=PEEK (PEEK 16398+256*PEEK 16399)
 9010 RETURN 
 9100 PRINT AT 8,0;
 9110 FOR J=1 TO 14
 9120 PRINT "                                "
 9130 NEXT J
 9140 PRINT AT 8,0;
 9150 RETURN 
 9200 DIM A$(13,33)
 9202 LET A$(1)="SULU: BULLS EYE, CAPTAIN"
 9204 LET A$(2)="SPOCK: KLINGON DESTROYED"
 9206 LET A$(3)="CHEKOV: WE GOT HIM, SIR"
 9208 LET A$(11)="HUMAN LOGIC FASCINATES ME"
 9210 LET A$(12)="I CAN NEVER UNDERSTAND EMOTIONS"
 9220 LET A$(13)="HUMAN BEHAVIOUR IS VERYIRRATIONAL"
 9222 LET A$(4)="DILITHIUM CRYSTALS     DAMAGED,"
 9224 LET A$(5)="ANTIMATTER STABLISER   BROKEN ,"
 9226 LET A$(6)="WEE DAMAGE TO ENERGY   BANKS ,"
 9228 LET A$(7)="YOU DON""T STAND A CHANCE, KIRK"
 9230 LET A$(8)="GIVE YOURSELF UP, KIRK"
 9232 LET A$(9)="SURRENDER NOW,  KIRK, OR DIE"
 9234 LET A$(10)="YOUR PUNY RACE  CAN""T KILL A FLY"
 9250 RETURN 
 9300 PRINT TAB 9;"************"
 9310 PRINT TAB 9;"**STARTRIP**"
 9320 PRINT TAB 9;"************"
 9330 PRINT 
 9340 PRINT "DO YOU WANT INSTRUCTIONS?"
 9350 LET B$=INKEY$
 9360 IF B$="" THEN GOTO 9350
 9370 IF B$="Y" THEN GOSUB 6000
 9372 PRINT 
 9380 PRINT "WHAT STAR-RATING ARE YOU,       CAPTAIN?   ( 6 IS THE HIGHEST )"
 9390 INPUT RA
 9400 IF RA>6 OR RA<1 OR RA<>INT RA THEN GOTO 9380
 9410 CLS 
 9420 RETURN 
 9890 LET E=0
 9892 PRINT "YOU HAVE NO ENERGY LEFT"
 9894 LET PE=-100
 9900 FOR D=1 TO 25
 9902 NEXT D
 9903 CLS 
 9904 PRINT TAB 10;"GAME OVER"
 9906 LET S=PE+INT (TE/100/RA)+(KL-K)*10
 9908 PRINT 
 9910 PRINT "YOUR SCORE IS ";S
 9920 PRINT 
 9922 PRINT "YOU HAVE KILLED ";KL-K;" KLINGONS"
 9924 PRINT 
 9928 LET RA=(RA+7)/16
 9930 IF S>RA*200 THEN GOTO 9940
 9932 PRINT "NOT VERY GOOD-YOU""LL HAVE TO DO BETTER THAN THAT."
 9934 STOP 
 9940 IF S>RA*400 THEN GOTO 9950
 9942 PRINT "NOT BAD, BUT YOU CAN STILL DO   MUCH BETTER."
 9944 STOP 
 9950 IF S>RA*600 THEN GOTO 9960
 9952 PRINT "A WORTHY ATTEMPT, CAPTAIN."
 9954 STOP 
 9960 IF S>RA*800 THEN GOTO 9970
 9962 PRINT "VERY GOOD, YOU DESERVE PROMOTION"
 9964 STOP 
 9970 IF S>RA*1000 THEN GOTO 9980
 9972 PRINT "A CREDITABLE EXAMPLE FOR THE    REST OF THE FLEET, WELL DONE."
 9974 STOP 
 9980 PRINT "EXCELLENT, YOU DESERVE TO BE    STARFLEET COMMANDER."
 9997 FOR A=1 TO 20
 9998 PRINT A$(A)
 9999 NEXT A

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

People

No people associated with this content.

Scroll to Top