10 DEF FNR(R) = INT(((T/1000+RND(1))-INT(T/1000+RND(0)))*R) Defines a function to return an integer from 0 to R-1 The BASIC random number generator is poor quality and repeats after something like 1700 numbers. Adding T/1000 adds more randomness. The BASIC function RND(1) returns a new random number n where 0 <= n < 1 RND(0) returns the previous random number So (T/1000+RND(1))-INT(T/1000+RND(0)) computes the fractional part of (T/1000+RND(1)) 20 GS = 645: PRINTCHR$(12);: GOSUB8000: GOTO 1000 GS is a pointer to memory of the 100 bytes representing the current state of the galaxy. The units digit is the number of starbases, the tens digit is the number of Klingons. "Scanned" areas have 100 added to the byte value. Subroutine 8000 prints the opening messages and initialises data 50 D = SQR((E3-K(1,I))*(E3-K(1,I))+(E4-K(2,I))*(E4-K(2,I))): RETURN This subroutine computes the Euclidean distance between Klingon number I in this sector and the Enterprise (SQR is square root function) 1000 FOR I = 0 TO 9: FOR J = 0 TO 9: S(I,J) = 0: NEXT J,I We come here when we enter a new sector. Clear the sector array (10 x 10 integer array S) This is the "short range scan" data 1010 S(E3,E4) = 4: N = PEEK(GS+E1+E2*10) (E1,E2) are the coordinates of the current sector in the galaxy, (E3,E4) are the coordinates of the enterprise in the sector N is the byte representing the current sector in the galaxy. So this will put the enterprise in the short range scan array and read the sector data from the galaxy scan 1011 IF N>99 THEN N = N-100 Clear the "scanned" flag for the byte, so we can read the two digits 1012 NS = FNR(3)+30/SQR((E1-5)*(E1-5)+(E2-5)*(E2-5)+3) NS computes the number of stars in this sector. There will be more stars in sectors close to the centre of the galaxy (coordinates 5,5) 1014 FOR I = 1 TO NS: S(FNR(10),FNR(10)) = 1: NEXT Add NS stars to the short range scan. This might overwrite an existing star or the Enterprise, but we put the Enterprise back later. 1020 NK = INT(N/10): NB = N-NK*10 The number of Klingons (NK) is the 10's digit, the number starbases (NB) is the units digit. 1025 FOR I = 0 TO 4: K(0,I) = 0: NEXT Clear the Klingon hitpoints array. K(0,I) is the hitpoints for Klingon I, K(1,I) is the X coordinate K(2,I) is the Y coordinate. 1030 BS$ = "RED": IF NK = 0 THEN BS$ = "GREEN": GOTO 1100 Set the battle status (BS$) If GREEN then skip the loop setting up Klingons 1040 FOR I = 1 TO NK: K(0,I-1) = 100-100*(RND(1)>.8) Set the hit points for Klingon I to either 100 or 200 20% of Klingons are double health. A "true" condition returns -1, "false" returns 0 So if the random value from 0 to 1 is greater than .8 then 100 is added to the hitpoints 1050 X = FNR(10): Y = FNR(10): IF S(X,Y)>0 THEN 1050 Choose coordinates for Klingon I, ensure the space is empty. 1060 S(X,Y) = 2: K(1,I-1) = X: K(2,I-1) = Y: NEXT I Place the Klingon (2) in the sector and record its coordinates. NEXT I loops to the next Klingon 1100 IF NB = 0 THEN 1140 1110 FOR I = 1 TO NB Loop over the number of starbases 1120 X = FNR(10): Y = FNR(10): IF S(X,Y)<>0 THEN 1120 1130 S(X,Y) = 3: NEXT Place the starbases on empty spaces 1140 IF D = 0 THEN GOSUB 9400 D is set if we are currently "docked" with a starbase. If not then subroutine at 9400 checks for a starbase in the four locations around the Enterprise 1195 S(E3,E4) = 4: GOSUB 61000 Place the Enterprise in the sector, set up the print hook. 1197 PRINT CHR$(12): PRINT Clear the screen 1200 PRINT" TIME ENERGY SHIELDS KLINGONS TORPEDOES" 1210 PRINT: PRINT" POWER PLANT WARP DRIVE IMPULSE DRIVE" 1220 PRINT: PRINT" BATTLE STATUS: ": PRINT Print status lines 1230 FOR I = 0 TO 9: PRINT: PRINT" ";: FOR J = 0 TO 9 1240 PRINT MID$(S$,S(J,I)+1,1);" ";: NEXTJ: PRINT" "; Print one line of short range scan: String S$ converts the number in S(x,y) to the displayed character 1250 IF I<3 THEN PRINT D$(I); D$(I) is the direction key reminder (812/7E3/654) 1260 IF I = 5 THEN D = -1: GOSUB 1299 1265 IF I = 7 THEN D = 0: GOSUB 1299 1267 IF I = 9 THEN D = 1: GOSUB 1299 Subroutine 1299 prints a line of the long range scan with Y offset D 1269 IF I<9 THEN PRINT 1270 NEXTI: POKE 55026,32 55026 is 0xD6F2 which is part of screen memory on a 2KB video RAM machine. This puts a space at the end of the long range scan to overwrite the curser which would otherwise stay there. 1280 GOSUB 60050: GOTO 2000 Set up the print hook (output vector at 0x021A) 1299 FOR J1 = -1 TO 1: X = E1+J1: Y = E2+D 1300 P = PEEK(GS+X+Y*10): POKE(GS+X+Y*10),P-(P<99)*100 1305 IF P>99 THEN P = P-100 1310 IF X<0ORX>9ORY<0ORY>9 THEN PRINT" 9";: GO TO 1360 1320 PRINT RIGHT$(" "+STR$(P),3); 1360 NEXTJ1: RETURN This subroutine prints a line of long range scan by peeking the galaxy scan (address GS), it sets the 100's digit in the galaxy scan for each scanned sector by subtracting (P<99)*100 If the current value P is less than 99 then condition (P<99) is true, which evaluates to -1, so subtracting 100 times this will add 100 the result if it was less than 99. 2000 GOSUB 60050 This is the start of the inner game loop. First we set up the print hook. 2002 PRINT"a";INT(T);" c";INT(E);" e";INT(S);" "; 2010 PRINT"i";T1;" ";"g";INT(K);" ";"k";INT(P(0));"% "; 2015 PRINT"m";INT(P(1));"% o";INT(P(2));"% "; 2020 PRINT"q";BS$;" ";L$; Print status information at various locations on the screen: T = time left E = current energy S = current shields T1 = number of torpedoes left K = total number of Klingons left P(0) = power plant health P(1) = warp drive health P(2) = impulse drive health 2030 PS = 53647 2035 PS = PS+192 PS is the location in screen memory of the start of the short range scan: we use this to poke at the short range scan to update the screen or look at what is on the screen. Screen memory starts at 0xD000 = 53248 and there are 64 bytes per row (only 48 or so will fit on the screen due to TV overscan). When the program was changed to work with a 48 x 32 character screen, the short range scan display was moved ddown 3 lines (192 bytes). 2040 E3 = INT(E3): E4 = INT(E4) Ensure that the Enterprise sector coordinates are integer 2050 IF D = 0 THEN GOSUB 9400 If we are not currently docked at a starbase, check for a starbase next to the enterprise 2099 PRINT"s "; Clear the status line 2100 NK = 0: FOR I = 0 TO 4: IF K(0,I) <= 0 THEN NEXT: GOTO 2300 If all the Klingons are destroyed (hit points <= 0) then we move to the instruction after NEXT and GOTO 2300 Otherwise, we process lines from 2101 to the next NEXT once for each live Klingon 2101 E3 = INT(E3): E4 = INT(E4) If we get here then we have a live Klingon number I 2102 NK = NK+1: IF FNR(30)>9 THEN 2290 Check if the Klingon will shoot this time, if not then skip to 2290 2105 POKEPS+E3*2+E4*128,187 Put character 187 over the Enterprise in short range scan to indicate a hit 2110 GOSUB 50 Compute distance D from the Enterprise to Klingon I 2120 HT = (200-(K(0,I)>100)*200)/D Compute hit strength based on distance: double damage if this is a strong Klingon with currently over 100 hit points 2130 IF HT > S THEN HT = HT-S : S = 0 Shields absorb some of the hit 2140 IF S >= HT THEN S = S-HT: GOTO 2290 Shields absorb all of the hit, so skip damage calculate 2145 H1 = FNR(4): HT = HT/5 Decide hit location (H1) and damage amount (HT/5) 2150 IF H1 = 0 THEN PRINT"sPOWER PLANT HIT!";: P(0) = P(0)-HT 2160 IF H1 = 1 THEN PRINT"sWARP DRIVE HIT!";: P(1) = P(1)-HT 2170 IF H1 = 2 THEN PRINT"sIMPULSE DRIVE HIT!";: P(2) = P(2)-HT 2180 IF H1 = 3 THEN PRINT"sTORPEDO TUBES HIT!";: IF FNR(8)0 THEN BS$ = "RED" Update battle status 2302 PP = PEEK(GS+E1+E2*10): PP = PP-INT(PP/10)*10 PP is number of starbases in the current sector. We need this so that we can update the 10s digit in the scan: 2304 POKE GS+E1+E2*10,(PP+NK*10+100) Update galaxy scan with the new number of Klingons NK and mark as scanned (by adding 100) 2309 IF E<100 OR NK = 0 THEN 2400 If there is not enough energy, or no Klingons, then skip the phasor firing 2320 POKE KEY,253: IF (PEEK(KEY) AND 2)>0 THEN 2400 If "P" key is not currently pressed, then skip 2330 E = E-100: FOR I = 0 TO 4: IF K(0,I)< = 0 THEN 2390 Reduce energy by 100, step I through currently living Klingons 2340 GOSUB 50: PK = PS+K(1,I)*2+K(2,I)*128: POKE PK,187 Compute distance to Klingon, in D, update screen at Klingon position with character 187 to show that it was hit 2350 IF K(0,I)<100/D/NK THEN K = K-1 Damage to Klingon is 100/D/NK, check if destroyed and update number of Klingons 2351 K(0,I) = K(0,I)-100/D/NK Update Klingon hit points 2360 IF K(0,I)>0 THEN POKE PK,75: FOR II = 1 TO 200: NEXT If still alive, then put Klingon back on screen and pause 2370 IF K(0,I)<=0 THEN POKE PK,213: S(K(1,I),K(2,I)) = 0 If Klingon is dead, then clear space on screen (char 213 is dot) and update short range scan 2390 NEXT Next Klingon 2400 IF E<100 OR S>=500 THEN 2500 Check if enough energy to raise shields and shields are less than max 2410 POKE KEY,247: IF (PEEK(KEY) AND 128)>0 THEN 2500 Check if "S" key is held down 2420 IF S>400 THEN E = E-500+S: S = 500: GOTO 2500 Set shields to max if over 500: remove the amount of energy needed to raise shields to 500 2430 S = S+100: E = E-100 Otherwise, add 100 to shields and remove 100 energy 2500 POKE KEY,239: IF (PEEK(KEY) AND 32)>0 THEN 2600 Check if repair ("R") key is pressed 2510 FOR I = 0 TO 2: IF P(I)>90 THEN 2590 Skip each repair if health is over 90% 2520 R = FNR(9)+1: IF E69 THEN POKE PT,213 PT is current location of torpedo on screen. If this is not the enterprise, the clear this location (char 213) 2620 TX = TX+D(0,TF): TY = TY+D(1,TF) Update torpedo coordinates in current directopn (TF). Array D(0,dir) and D(1,dir) give the update to the X and Y coordinate respectively for each of the 8 direction numbers. 2630 IF TX<0 OR TX>9 OR TY<0 OR TY>9 THEN TF = 0: GOTO 2700 Check if torpedo has moved out of sector 2640 PT = PS+TX*2+TY*128: IF PEEK(PT) = 213 THEN 2690 Check if the new torpedo location is currently empty (char 213 is "dot") 2645 POKE PT,213: TF = 0 If we get here, then we hit something. Clear the screen location and clear "torpedo firing" indicator. We can check the short range scan array S(x,y) to see what we hit 2650 IF S(TX,TY)<>2 THEN 2660 Check if we hit a Klingon 2652 FOR I = 0 TO 4: IF K(1,I) = TX AND K(2,I) = TY THEN K(0,I) = 0 2654 NEXT: S(TX,TY) = 0: K = K-1: NK = NK-1: GOTO 2700 Find which Klingon we hit, set its health to 0. Clear this space in the scan data and reduce number of Klingons (both globally and in this sector) 2660 IF S(TX,TY) = 1 THEN 7000 Check if we hit a star and goto 7000 for fireworks 2670 IF S(TX,TY) = 3 THEN S(TX,TY) = 0: GOTO 2700 If we hit a starbase, then it is cleared from the scan and the screen, but will re-appear if we move out of the sector and back again (the starbase's shields hide it) 2675 GOSUB 61000: STOP I don't think we can get here 2690 POKE PT,TF+15 We get here when the torpedo is still moving, so put the torpedo arrow character (TF+15) on the screen at current location. Character 16 in the character set is the "up arraw", character 17 is "up right" and so on. 2700 POKE KEY,239: K1 = PEEK(KEY) 2710 IF K1 = 127 THEN L$ = "W" 2720 IF K1 = 239 THEN L$ = "T" 2730 IF K1 = 253 THEN L$ = "I" Check for one of the keys W, T or I and set current direction function (the meaning of a direction key) 2735 POKE KEY,191: IF PEEK(KEY) = 127 THEN P1 = 8: GOTO 2750 Check if Key 8 is pressed, set P1 and skip checking 1-7 2740 POKE KEY,127: K1 = PEEK(KEY): IF K1 = 255 THEN 3000 This is checking for a direction key (1-7 are in row 127) If none were pressed, skip to 3000 2745 FOR I = 2 TO 8: IF ABS(K1+2^(I-1)-255)<.1 THEN P1 = 9-I 2746 NEXT Set P1 to the direction key pressed. 2^(I-1) uses floating point arithmetic so the test is <.1 rather than =0 2750 IF L$<>"I" OR P(2)<50 OR E<5000/P(2) THEN 2800 For impulse drive we need health >= 50 and enough energy Less health means more energy is used for impulse. 2755 S(E3,E4) = 0: D = 0: POKE PS+E3*2+E4*128,213 2760 E5 = E1*10+E3: E6 = E2*10+E4: E5 = E5+D(0,P1): E6 = E6+D(1,P1) Clear enterprise location in short range scan, and on screen, compute new enterprise location in "global coordinates" (E5,E6) which range from (0,0) to (99,99) 2765 E = E-5000/P(2) Reduce energy 2770 F1 = INT(E5/10): F2 = INT(E6/10): F3 = E5-F1*10: F4 = E6-F2*10 (F1,F2) is new galaxy location for Enterprise (sector coordinates) (F3,F4) is new location in the new sector for the Enterprise 2775 MM = PEEK(PS+F3*2+F4*128): IF MM<>42 AND MM<>75 THEN 2777 Check new screen location (if we are moving to a new sector, this is still checking the current sector!) 2776 PRINT"sMANOUVRE ABORTED!!";: F3 = E3: F4 = E4: F1 = E1: F2 = E2 We are going to hit something (star or Klingon), so reset new location to old location. 2777 E3 = F3: E4 = F4: POKE PS+E3*2+E4*128,69 Set current location to new location and put E on screen 2780 IF E1 = F1 AND E2 = F2 THEN 2000 Check for moving to a new sector 2790 E1 = F1: E2 = F2: GOTO 1000 We goto line 1000 when we enter a new sector (through warp drive or impulse drive or start of program or leaving galaxy scan) 2800 IF L$<>"W" THEN 2850 Check for warp drive function 2805 IF P(1) < 50 OR E<10000/P(1) THEN 2850 Check if warp drive has enough health and we have enough energy (less health means more energy needed) 2810 S(E3,E4) = 0: E5 = E1*10+E3: E6 = E2*10+E4 Clear Enterprise from short range scan area compute global coordinates. 2815 E = E-10000/P(1) Update energy 2820 E5 = E5+D(0,P1)*10+(100-P(1))^2/100*(RND(1)-.5) 2830 E6 = E6+D(1,P1)*10+(100-P(1))^2/100*(RND(1)-.5) Update global coordinates according to current direction indicator (Array D converts a direction number P1 to an update of X or Y coordinate). If the health of the warp drive is less than 100%, then add a small error to the location which is random and depends on the square of the damage (^ is "raise to the power" in BASIC). 2840 F1 = INT(E5/10): F2 = INT(E6/10) Convert global coordinates to new sector X,Y coordinates. 2842 IF F1<0 OR F1>9 OR F2<0 OR F2>9 THEN 2776 Check if new sector is outside the galaxy, if so then abort the move. 2844 E3 = INT(E5-F1*10): E4 = INT(E6-F2*10): GOTO 2780 Compute new coordinates within the sector and skip torpedo firing. 2850 IF L$<>"T" THEN 3000 If we did not warp, check if T is pressed, if not then skip 2900 IF T1 = 0 OR TF>0 THEN 3000 If there are no torpedoes, or one is alrady firing then skip. 2910 T1 = T1-1: TF = P1: TX = E3: TY = E4 Fire a torpedo: reduce number of torpedoes, set TF to direction, set torpedo XY coordinates to Enterprise location 3000 IF BS$ = "RED" THEN 3100 Only allow galaxy scan when condition is green 3010 POKE KEY,247: IF (PEEK(KEY)AND16)>0 THEN 3100 Check for G pressed, if not then skip to 3100 (end of main loop) 3015 K = 0: GOSUB 61000 3020 PRINTCHR$(12): PRINT: PRINT: PRINT: PRINT: PRINT: PRINT 3025 PRINT" 0 1 2 3 4 5 6 7 8 9" 3030 FOR Y = 0 TO 9: PRINTY;: FOR X = 0 TO 9: N = PEEK(GS+X+Y*10) 3040 IF N>99 THEN PRINTRIGHT$(" "+STR$(N-100),3); 3050 IF N<100 THEN PRINT" **"; 3055 K = K+INT(N/10)-INT(N/100)*10 3060 NEXTX: PRINT: NEXTY 3065 PRINT: PRINT"YOU ARE AT SECTOR";E1;E2 Clear screen and display galaxy scan. RIGHT$(" "+STR$(N-100),3) will pad the number N-100 with spaces on the left so that it is 3 characters. If the hundreds digit is not set then this sector has not been scanned with the long range scan. 3070 IF (PEEK(KEY) AND 16) = 0 THEN 3070 Stay in this loop until "G" key is released 3080 GOSUB 60050: T = T-10: GOTO 1000 Reduce time by 10 and go to start of main loop for entering a new sector: this will clear the screen and restore display with status, short range scan and long range scan 3100 T = T-1: IF E<3000 THEN E = E+P(0)/10 End of main loop is here: reduce the time and recharge some energy, based on the health of the power plant. 3101 IF P(0)<1 THEN PRINT"sSHIP EXPLODES!!!";: GOTO 11000 But if the power plant has <1% health, then lose the game! 3110 IF T>0 AND K>0 THEN 2000 If you have time left and there are Klingons left anywhere, then go back around the inner game loop. Otherwise, we are either out of time or have destroyed all Klingons: 3115 GOSUB 61000: PRINT 3120 IF K>0 THEN 10000 Go to 10000 if there are Klingons left (we must be out of time). 3130 PRINT: PRINT"YOU HAVE DESTROYED ALL THE KLINGONS" 3140 PRINT"AND SAVED THE GALAXY!": END Win the game! This code executes when a torpedo at TX,TY hits a star: 7000 FL = 745: S(TX,TY) = 0: S(E3,E4) = 4 FL is address 0x2E9 and is a small unused memory area which we are using as a stack. Clear the star and put the enterprise back on the short range scan array. 7005 FOR A = -1 TO 1: FOR B = -1 TO 1: X1 = TX+A: Y1 = TY+B 7010 IF X1<0 OR X1>9 OR Y1<0 OR Y1>9 THEN 7100 Scan the 9 locations around where the star was hit (the location at A=0,B=0 which is the original star location has already been cleared) 7020 IF S(X1,Y1) = 4 THEN DR = 1 Check if you hit the Enterprise and set DR = 1 7025 IF S(X1,Y1) = 1 THEN FL = FL+2: POKE FL,X1: POKE FL+1,Y1 Check if another star was caught in the blast: add it to the stack and increment the stack pointer FL 7030 IF S(X1,Y1)<>2 THEN 7100 Check if a Klingon was cause in the blast, if not the skip to 7100 7035 FOR II = 0 TO 4: IF K(0,II) <= 0 THEN 7050 Find the Klingon that was hit (Klingon number II) 7040 IF K(1,II) = X1 AND K(2,II) = Y1 THEN K(0,II) = 0 Set the Klingon's health to zero 7050 NEXT: NK = NK-1: K = K-1 Reduce the global and local number of Klingons 7100 NEXTB,A Scan the next location around the star that was hit Now we display the explosion: 7102 FOR A = -3 TO 3: FOR B = -3 TO 3: POKE PS+TX*2+A+(TY*2+B)*64,161: NEXTB,A Fill the area on the screen with char 161 (filled block) 7105 FOR I = 1 TO 1000: NEXT: IF DR = 1 THEN 7500 Wait for a while. If the Enterprise was hit (DR flag set) then goto 7500 and lose the game. 7107 FOR A = -3 TO 3: FOR B = -3 TO 3: POKE PS+TX*2+A+(TY*2+B)*64,32: NEXTB,A Clear the explosion with spaces 7110 FOR A = -1 TO 1: FOR B = -1 TO 1: X1 = TX+A: Y1 = TY+B 7120 IF X1<0 OR X1>9 OR Y1<0 OR Y1>9 THEN 7200 7130 S(X1,Y1) = 0: POKE PS+X1*2+Y1*128,213 Clear the locations in the short range scan array and put dots on the screen where the explosion hit. 7200 NEXTB,A: Now we check the stack of stars to be processed. 7210 IF FL>745 THEN TX = PEEK(FL): TY = PEEK(FL+1): FL = FL-2: GOTO 7005 If FL>754 (the stack base), then pop a pair of coordinates off the stack, set the torpedo coordinates and branch back to 7005 to kick off another explosion 7220 GOTO 2000 Otherwise, the dust has settled, go back to the main loop 7500 GOSUB 61000: PRINT: PRINT"TRIGGER HAPPY FOOL!!": END We got caught in a star explosion. The next subroutine prints messages and initialises data: 8000 PRINT: PRINT" REAL-TIME STARTREK!": KEY = 57088 8001 DIMD(1,8),S(9,9),K(2,4),P(2),D$(2) 8002 PRINT: PRINT: PRINT"DIFFICULTY(1-4)?";: POKE 530,1: POKE KEY,127 8003 II = RND(1): J = PEEK(KEY): IF J = 255 THEN 8003 J records which key (1 to 4) was pressed 8005 PRINT"...": PRINT: FOR I = 0 TO 99: POKE GS+I,0: NEXT Clear the galaxy scan memory area starting at GS 8020 S$ = CHR$(213)+"*KBE" 8040 K = 45-((J>127)+(J>191)+(J>222))*20+FNR(7): FOR I = 1 TO K Determine initial number of Klingons based on difficulty in J 8045 X = FNR(10): T = T+1: Y = FNR(10): IF PEEK(GS+X+Y*10) >= 50 THEN 8045 Pick a sector for this Klingon (no more than 5 per sector) 8050 POKE GS+X+Y*10,(PEEK(GS+X+Y*10)+10): NEXT Increment the number of Klingons in this sector 8060 B = 3+FNR(2)-(J>127)-(J>191)-(J>222) Determine initial number of starbases depending on difficulty 8065 FOR I = 1 TO B: X = FNR(10): Y = FNR(10) 8070 POKE GS+X+Y*10,(PEEK(GS+X+Y*10)+1): NEXT Add starbases to the galaxy scan 8080 E1 = FNR(10): E2 = FNR(10): E3 = FNR(10): E4 = FNR(10) Pick initial Enterprise location 8100 T = 3600: GOSUB 9000: GOSUB 60000: GOSUB 61000 Set the initial time, set Enterprise energy etc, set up the print hook 8107 PRINT"THERE ARE";K;"KLINGONS" 8110 D$(0) = "8 1 2": D$(1) = "7 E 3": D$(2) = "6 5 4" 8120 PRINT"YOU HAVE";T;"STARDATES": PRINT"AND";B;"STARBASES" 8128 PRINT"YOU ARE IN SECTOR";E1;E2: PRINT" GOOD LUCK!": PRINT 8132 PRINT"PRESS SPACE": POKE KEY,253 8150 IF PEEK(KEY) = 255 THEN 8150 8152 D(0,2) = 1: D(0,6) = -1: D(0,7) = -1: D(0,8) = -1: D(1,5) = 1: D(1,6) = 1 8170 D(0,3) = 1: D(0,4) = 1: D(1,8) = -1: D(1,1) = -1: D(1,2) = -1: D(1,4) = 1 9000 T1 = 8: E = 3000: S = 0: P(0) = 100: P(1) = 100: P(2) = 100: RETURN Set number of torpedoes, restore energy, set shields to zero and repair everything to 100% health. We also come here when we dock with a starbase. 9400 IF BS$ = "RED" THEN RETURN We come here to check for docking with a starbase: can only do this on battle status green, so return immediately if status is red. 9410 IF S(E3-1-(E3<1),E4) = 3 OR S(E3,E4-1-(E4<1)) = 3 THEN GOTO 9500 9430 IF S(E3+1+(E3>=9),E4) = 3 OR S(E3,E4+1+(E4>=9)) = 3 THEN GOTO 9500 Check the four locations around the Enterprise. (By adding eg "E3<1" we don't add an offset to the X or Y coordinate if the result is outside the array boundaries, so we will just check the enterprise location instead) 9460 RETURN 9500 PRINT"sDOCK WITH BASE(Y/N)?"; We get to 9500 if a starbase was found and battle status is green 9505 FOR II = 1 TO 500: NEXT 9510 POKE KEY,239: HT = 1: IF (PEEK(KEY)AND8) = 0 THEN HT = 89 9520 IF HT = 89 THEN T = T-10: D = 1: GOSUB 9000 9530 RETURN Check if Y or N is pressed. If "Y" then reduce time left by 10, set "Currently docked" flag D and GOSUB 9000 to restore energy etc. 10000 PRINT: PRINT"OUT OF TIME!" 10010 PRINT"THE KLINGONS WIN!": END Lose the game 11000 GOSUB 61000: PRINT: PRINT"SHIP EXPLODES": GOTO 10010 Lose the game 60000 DATA 8,133,80,152,72,138,72,165,80,201,97,48,18,201,122,16 60010 DATA 14,170,189,5,2,133,81,189,6,2,133,82,24,144,22,165,82 60020 DATA 41,7,9,208,133,82,165,80,160,0,132,14,145,81,230,81 60030 DATA 208,2,230,82,104,170,104,168,165,80,40,96,255 60032 DATA 207,0,213,0,220,0,228,0,237,0,79,1,92,1,104,1,157,1,212,1 60040 FOR I = 552 TO 633: READA: POKE I,A: NEXT This data is the machine code for the print hook which is poked into a free memory area. 60050 POKE 538,40: POKE 539,2: RETURN Set the print hook to the small machine code area we set up above (at location 552 = 0x0240) 61000 POKE 538,212: POKE 539,251: RETURN Restore the default print hook (0xFBD4, see P.44 in the manual)