Basketball

This file is part of and Timex Sinclair Public Domain Library Tape 1005. Download the collection to get this file.
Developer(s): Bill Ferrebee
Date: 198x
Type: Program
Platform(s): TS 1000

Strategy Basketball is a text-based coaching simulation where the player chooses offensive plays and defensive schemes against a computer opponent over two halves plus overtime if needed. Each possession the player selects from five shot types (long jump shot, short jump shot, layup, hook shot, set shot) or manages defense, and random-number comparisons weighted by a defense factor C determine whether each attempt scores, misses short, hits the rim, or results in a foul. The defense multiplier C is derived from a key-code formula (lines 5520–5521) that maps numeric keypresses to a fractional value, scaling shot success probabilities differently for each team’s offensive efficiency. The title screen animates the words “STRATEGY” and “BASKETBALL” scrolling diagonally across the screen, followed by a marquee-style scrolling credit line at the bottom of the display.


Program Analysis

Program Structure

The program is organized into several clearly separated functional regions:

  1. Lines 1–30: Initialization and jump to title sequence
  2. Lines 100–900: Main game loop — possession resolution
  3. Lines 5000–5130: Utility routines (wait for keypress, short delay/clear)
  4. Lines 5200–5330: Menu display subroutines
  5. Lines 5400–5470: Player input handler
  6. Lines 5499–5530: Defense selection subroutine
  7. Lines 5600–5660: Score display
  8. Lines 5700–5780: Successful shot handler
  9. Lines 5800–5840: Jump ball / tip-off routine
  10. Lines 5880–5970: Shooting percentage display
  11. Lines 6000–6020: Random team assignment for ball possession
  12. Lines 6100–6170: Foul and free-throw handler
  13. Lines 6200–6360: Miss outcomes (short, off rim, blocked)
  14. Lines 6400–6485: End-of-game / play-again logic
  15. Lines 6500–6730: Halftime and overtime transitions
  16. Lines 7000–7220: In-game menu handlers (defense change, stats views)
  17. Lines 9000–9260: Title animation and game setup
  18. Lines 9900–9910: SAVE and RUN

Defense Multiplier Calculation

The core balancing mechanism is the variable C, set at line 5520 or 5521 depending on which team (I=1 or I=2) is shooting. The player presses keys 6–9 to choose a defense type, and the key’s character code A is fed into the formula:

  • Home team offense: C = (A/2 - 9) / 7
  • Away team offense: C = (A/2 - 9) / 8

Character codes for ‘6’–’9′ are 34–37. Substituting gives C values of approximately 0.143 to 0.571 for the home team and 0.125 to 0.500 for the visiting team. Higher C values (looser defense) increase the probability thresholds for scoring, making shots more likely to go in.

Shot Resolution Logic

Each possession generates a random value R = RND and then dispatches to a shot-type handler via a computed GOTO at line 240. The expression uses Boolean arithmetic — on this platform, a true condition evaluates to 1 and false to 0, so only one term is non-zero. The five shot types and their base make percentages (at maximum C) are:

Shot TypeLineMake thresholdFoul trigger
Long Jump Shot300R < 0.28×CR > 0.9
Short Jump Shot400R < 0.38×CR > 0.9
Layup500R < 0.43×CR > 0.94 (block)
Hook Shot600same as Short Jumpsame as Short Jump
Set Shot700same as Layupsame as Layup

Hook and set shots simply GOTO into the short jump shot and layup handlers respectively (lines 610 and 710), reusing code efficiently. Long jump shots (B=1) score three points; all others score two points (lines 5710–5735).

Halftime, Overtime, and Game End

Shot counters S(1) and S(2) are checked after every shot at lines 232–233. When either team’s shot count reaches 45, halftime triggers (line 6700); at 90, the end-of-half/overtime check fires (line 6600). If scores are tied at full time, overtime is granted by resetting both shot counters to 85 (lines 6635–6637), giving each team five more possessions. The overtime banner is displayed at line 6645.

Title Screen Animation

The title sequence at lines 9000–9080 implements two diagonal scroll animations. “STRATEGY” is first printed scrolling downward in a column (lines 9000–9006), then diagonally (lines 9010–9014), before being shown in inverse video at its final position. The same technique is applied to “BASKETBALL” scrolling upward and then diagonally. A marquee at line 9062 scrolls a credit string by rotating Z$ one character at a time using string slicing: Z$=Z$(2 TO LEN Z$)+Z$(1). A border of inverse block characters (rendered as \##) frames the screen.

Input Handling and Key Codes

The player input subroutine at line 5400 reads CODE INKEY$ into A. Valid shot selection codes are 29–33 (corresponding to keys ‘1’–’5′). Special function keys use their character codes: 41 for ‘D’ (change defense), 53 for ‘S’ (view score), 56 for ‘P’ (view shooting percentage). The validation at line 5410 uses a compound condition to reject all other keypresses before branching.

Shooting Percentage Calculation

The subroutine at line 5900 computes each team’s field-goal percentage as INT((M(J)/S(J))*100), guarding against division by zero at line 5922. The result is displayed alongside the team name and a percent symbol rendered as a block graphic escape (\ '/\. ). The variable X(J) stores the computed percentage, while M(J) tracks made shots and S(J) tracks total attempts.

Notable Bugs and Anomalies

  • Line 5400 has a precedence issue: the condition A<29 OR A>33 AND A<>41 AND A<>53 AND A<>56 — because BASIC evaluates AND before OR, values of A from 29–33 will always pass due to the A<29 being false but the entire expression depending on grouping. This likely causes the routine to sometimes accept key ‘5’ (code 33) but reject codes 29–32 depending on implementation.
  • Line 9218 validates the visiting team name length but jumps back to 9206 (the home team INPUT) rather than the visiting team prompt — the visiting team name is re-entered against the home team label.
  • Line 7072 (CLS) is unreachable dead code; execution flow never reaches it.
  • The FOR/NEXT loops at lines 5001–5002 and 5640–5650 contain no body, functioning as no-ops or timing delays on some interpreters.
  • Line 6160 calls GOSUB 5750, which is the middle of the scoring subroutine (the made-shot counter increment), effectively skipping the “SHOT IS GOOD” print but correctly updating score and possession.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10211 – 10251.

Related Products

Related Articles

Related Content

Image Gallery

Source Code

   1 REM "BASKETBALL" 1984           BILL FERREBEE                   749 HILL STREET NO. 6           PARKERSBURG, WV 26104           TO SAVE GOTO 9900
   2 RAND 
  10 DIM T$(2,8)
  11 DIM M(2)
  12 DIM P(2)
  13 DIM S(2)
  14 DIM X(2)
  15 FOR J=1 TO 2
  16 LET P(J)=0
  17 LET M(J)=0
  18 LET S(J)=0
  19 LET X(J)=0
  20 NEXT J
  30 GOTO 9000
 100 IF I=2 THEN GOTO 150
 110 PRINT AT 1,1;"% %Y%O%U%R% %S%H%O%T%:%                  "
 120 GOSUB 5200
 130 GOSUB 5400
 140 GOTO 200
 150 LET B=INT (RND*4)+1
 200 LET R=RND
 210 CLS 
 220 PRINT TAB 16-(INT (LEN X$+5)/2);X$;" SHOT:"
 230 LET S(I)=S(I)+1
 231 FOR J=1 TO 2
 232 IF S(J)=45 THEN GOTO 6700
 233 IF S(J)=90 THEN GOTO 6600
 234 NEXT J
 240 GOTO (300 AND B=1)+(400 AND B=2)+(500 AND B=3)+(600 AND B=4)+(700 AND B=5)
 300 PRINT TAB 9;"LONG JUMP SHOT"
 310 IF R<.28*C THEN GOSUB 5700
 315 IF R<.28*C THEN GOTO 350
 320 IF R>.9 THEN GOTO 800
 330 IF R<.5*C THEN GOSUB 6200
 335 IF R<.5*C THEN GOTO 350
 340 IF R<.89*C THEN GOSUB 6300
 350 GOTO 900
 400 PRINT TAB 9;"SHORT JUMP SHOT"
 410 IF R<.38*C THEN GOSUB 5700
 415 IF R<.38*C THEN GOTO 350
 420 GOTO 320
 500 PRINT TAB 14;"LAYUP"
 510 IF R<.43*C THEN GOSUB 5700
 515 IF R<.43*C THEN GOTO 350
 520 IF R>.94 THEN GOSUB 6350
 525 IF R>.94 THEN GOTO 350
 530 GOTO 320
 600 PRINT TAB 12;"HOOK SHOT"
 610 GOTO 410
 700 PRINT TAB 12;"SET SHOT"
 710 GOTO 510
 800 GOSUB 6100
 900 GOTO 100
 5000 PRINT AT 21,3;"% %P%R%E%S%S% %A%N%Y% %K%E%Y% %T%O% %C%O%N%T%I%N%U%E% "
 5001 FOR J=1 TO 2
 5002 NEXT J
 5005 PRINT AT 21,3;" PRESS ANY KEY TO CONTINUE "
 5010 IF INKEY$="" THEN GOTO 5000
 5020 CLS 
 5030 RETURN 
 5100 FOR J=1 TO 25
 5110 NEXT J
 5120 CLS 
 5130 RETURN 
 5200 PRINT 
 5210 PRINT TAB 3;"% %1%  LONG (30 FT.) JUMP SHOT"
 5211 PRINT TAB 3;"% %2%  SHORT (15 FT.) JUMP SHOT"
 5212 PRINT TAB 3;"% %3%  LAYUP"
 5213 PRINT TAB 3;"% %4%  HOOK SHOT"
 5214 PRINT TAB 3;"% %5%  SET SHOT"
 5215 PRINT TAB 3;"% %D%  TO CHANGE DEFENSES"
 5216 PRINT TAB 3;"% %S%  TO VIEW SCORE"
 5217 PRINT TAB 3;"% %P%  TO VIEW SHOOTING  '/. "
 5220 PRINT 
 5230 RETURN 
 5295 PRINT AT 1,1;"% %N%E%W% %D%E%F%E%N%S%E%:"
 5300 PRINT 
 5310 PRINT TAB 3;"% %6%  PRESS"
 5311 PRINT TAB 3;"% %7%  MAN-TO-MAN"
 5312 PRINT TAB 3;"% %8%  ZONE"
 5313 PRINT TAB 3;"% %9%  NONE"
 5320 PRINT 
 5330 RETURN 
 5400 IF INKEY$="" THEN GOTO 5400
 5405 LET A=CODE INKEY$
 5410 IF A<29 OR A>33 AND A<>41 AND A<>53 AND A<>56 THEN GOTO 5400
 5420 IF A>28 AND A<34 THEN LET B=A-28
 5425 IF A>28 AND A<34 THEN RETURN 
 5430 IF A=41 THEN GOSUB 7000
 5440 IF A=53 THEN GOSUB 7100
 5450 IF A=56 THEN GOSUB 7200
 5460 GOTO 110
 5470 RETURN 
 5499 LET I=1
 5500 IF INKEY$="" THEN GOTO 5500
 5505 LET A=CODE INKEY$
 5510 IF A<34 OR A>37 THEN GOTO 5500
 5520 IF I=1 THEN LET C=(A/2-9)/7
 5521 IF I=2 THEN LET C=(A/2-9)/8
 5530 RETURN 
 5600 PRINT 
 5610 PRINT TAB 1;"% %S%C%O%R%E%:% "
 5612 PRINT 
 5615 PRINT TAB 8;T$(1);TAB 24;P(1)
 5620 PRINT TAB 8;T$(2);TAB 24;P(2)
 5630 PAUSE 90
 5640 FOR J=1 TO 2
 5650 NEXT J
 5660 RETURN 
 5700 PRINT TAB 10;"SHOT IS GOOD"
 5710 IF B=1 THEN LET P(I)=P(I)+3
 5715 IF B=1 THEN PRINT TAB 10;"THREE POINTS"
 5720 IF B=1 THEN GOTO 5740
 5730 LET P(I)=P(I)+2
 5735 PRINT TAB 11;"TWO POINTS"
 5740 LET M(I)=M(I)+1
 5750 IF I=1 THEN GOTO 5765
 5755 LET I=1
 5760 GOTO 5770
 5765 LET I=2
 5770 GOSUB 5600
 5771 GOSUB 6010
 5775 GOSUB 5100
 5780 RETURN 
 5800 PRINT AT 9,9;"% %C%E%N%T%E%R% %J%U%M%P% "
 5810 GOSUB 6000
 5815 PRINT 
 5820 PRINT TAB 16-(INT (LEN X$+13)/2);X$;" GETS THE TIP"
 5830 PAUSE 90
 5835 CLS 
 5840 RETURN 
 5880 GOSUB 5600
 5890 RETURN 
 5900 PRINT 
 5910 PRINT TAB 1;"% %S%H%O%O%T%I%N%G% %P%E%R%C%E%N%T%A%G%E%:% "
 5915 PRINT 
 5920 FOR J=1 TO 2
 5922 IF M(J)=0 OR S(J)=0 THEN LET X(J)=0
 5924 IF M(J)=0 OR S(J)=0 THEN GOTO 5932
 5930 LET X(J)=INT ((M(J)/S(J))*100)
 5932 IF M(J)=0 OR S(J)=0 THEN LET M(J)=0
 5940 PRINT TAB 8;T$(J);TAB 24;X(J);TAB 27;" '/. "
 5950 NEXT J
 5955 IF S(1)=90 OR S(2)=90 THEN GOTO 5970
 5960 GOSUB 5100
 5970 RETURN 
 6000 LET I=INT (RND*2)+1
 6010 IF I=1 THEN LET X$=H$
 6015 IF I=2 THEN LET X$=V$
 6020 RETURN 
 6100 PRINT TAB 16-(INT (LEN X$+17)/2);X$;" FOULED--TWO SHOTS"
 6105 LET S(I)=S(I)-1
 6110 IF RND<.5 THEN GOTO 6130
 6115 IF RND<.75 THEN GOTO 6150
 6120 PRINT TAB 7;"BOTH SHOTS MISSED"
 6125 GOTO 6160
 6130 PRINT TAB 8;"BOTH SHOTS MADE"
 6135 LET P(I)=P(I)+2
 6140 GOTO 6160
 6150 PRINT TAB 6;"1 MADE AND 1 MISSED"
 6155 LET P(I)=P(I)+1
 6160 GOSUB 5750
 6170 RETURN 
 6200 PRINT TAB 10;"SHOT IS SHORT"
 6210 GOSUB 6000
 6220 IF I=1 THEN PRINT TAB 16-(INT (LEN X$+18)/2);X$;" RETRIEVES THE BALL"
 6225 IF I=2 THEN PRINT TAB 16-(INT (LEN X$+14)/2);X$;" TAKES CONTROL"
 6230 GOSUB 5100
 6240 RETURN 
 6300 PRINT TAB 6;"SHOT IS OFF THE RIM"
 6310 GOSUB 6000
 6320 PRINT TAB 16-(INT (LEN X$+17)/2);X$;" GETS THE REBOUND"
 6330 GOSUB 5100
 6340 RETURN 
 6350 PRINT TAB 9;"SHOT IS BLOCKED"
 6360 GOTO 6210
 6400 GOSUB 5900
 6405 PRINT AT 21,7;"% %P%L%A%Y% %A%G%A%I%N%?% %(%Y%/%N%)% "
 6410 IF INKEY$="" THEN GOTO 6410
 6420 IF INKEY$="N" THEN GOTO 6480
 6430 IF INKEY$="Y" THEN GOTO 6450
 6440 GOTO 6410
 6450 CLEAR 
 6451 CLS 
 6452 DIM T$(2,8)
 6453 DIM M(2)
 6454 DIM P(2)
 6455 DIM S(2)
 6456 DIM X(2)
 6460 FOR J=1 TO 2
 6461 LET P(J)=0
 6462 LET M(J)=0
 6463 LET S(J)=0
 6464 LET X(J)=0
 6465 NEXT J
 6470 GOTO 9180
 6480 PRINT AT 21,0;"% % % % %T%H%A%N%K% % %Y%O%U% % %F%O%R% % %P%L%A%Y%I%N%G% % % % "
 6485 STOP 
 6500 PRINT AT 1,9;"% %S%E%C%O%N%D% %H%A%L%F% "
 6510 GOSUB 5800
 6520 RETURN 
 6600 CLS 
 6601 GOSUB 5600
 6605 IF P(1)=P(2) THEN GOTO 6630
 6610 PRINT AT 6,13;"% %F%I%N%A%L% "
 6620 GOSUB 6400
 6630 PRINT AT 6,11;"% %O%V%E%R%T%I%M%E% "
 6635 FOR J=1 TO 2
 6636 LET S(J)=85
 6637 NEXT J
 6640 GOSUB 5100
 6645 PRINT AT 1,11;"% %O%V%E%R%T%I%M%E% "
 6650 GOSUB 5800
 6660 GOTO 100
 6700 CLS 
 6701 GOSUB 5600
 6705 PRINT AT 6,11;"% %H%A%L%F%T%I%M%E% "
 6710 GOSUB 5000
 6715 GOSUB 6500
 6720 LET S(1)=46
 6721 LET S(2)=46
 6730 GOTO 100
 7000 CLS 
 7010 GOSUB 5295
 7020 GOSUB 5500
 7030 RETURN 
 7072 CLS 
 7100 CLS 
 7110 GOSUB 5900
 7120 RETURN 
 7200 CLS 
 7210 GOSUB 5600
 7220 RETURN 
 9000 FOR J=0 TO 9
 9002 PRINT AT J,12;"        "
 9004 PRINT AT J+1,12;"STRATEGY"
 9006 NEXT J
 9010 FOR J=1 TO 9
 9012 PRINT AT 10-J,12-J;"STRATEGY"
 9014 NEXT J
 9020 PRINT AT 10,11;"% %S%T%R%A%T%E%G%Y% "
 9030 FOR J=21 TO 12 STEP -1
 9032 PRINT AT J,11;"          "
 9034 PRINT AT J-1,11;"BASKETBALL"
 9036 NEXT J
 9040 FOR J=1 TO 9
 9042 PRINT AT 11+J,11+J;"BASKETBALL"
 9044 NEXT J
 9050 PRINT AT 11,10;"% %B%A%S%K%E%T%B%A%L%L% "
 9060 LET Z$="                               % % %M%O%U%N%T%A%I%N%E%E%R% % %S%O%F%T%W%A%R%E% % % %1%9%8%4% % "
 9061 FOR J=1 TO 32
 9062 PRINT AT 21,0;Z$( TO 32)
 9063 LET Z$=Z$(2 TO LEN Z$)+Z$(1)
 9064 NEXT J
 9070 PRINT AT 0,0;"################################################################"
 9071 FOR J=1 TO 20
 9072 PRINT AT J,0;"##"
 9073 PRINT AT J,31;"##"
 9074 NEXT J
 9080 PAUSE 180
 9090 CLS 
 9100 PRINT 
 9102 PRINT TAB 4;"IN % %S%T%R%A%T%E%G%Y% %B%A%S%K%E%T%B%A%L%L% ,"
 9104 PRINT "YOU WILL TEST YOUR COACHING"
 9106 PRINT "SKILLS AGAINST THE COMPUTER."
 9110 PRINT 
 9120 PRINT TAB 4;"HERE ARE THE OFFENSIVE PLAYS"
 9122 PRINT "AVAILABLE:"
 9130 GOSUB 5200
 9140 GOSUB 5000
 9150 PRINT 
 9152 PRINT TAB 4;"BOTH TEAMS WILL USE THE"
 9154 PRINT "DEFENSE YOU CHOOSE."
 9160 PRINT 
 9170 PRINT TAB 4;"YOUR OPTIONS ARE:"
 9180 GOSUB 5300
 9182 PRINT AT 21,4;"% %C%H%O%O%S%E% %Y%O%U%R% %D%E%F%E%N%S%E% "
 9184 GOSUB 5499
 9190 GOSUB 5000
 9200 PRINT 
 9202 PRINT "NAME OF HOME TEAM:"
 9204 PRINT AT 4,5;"(MAXIMUM OF 8 LETTERS)"
 9206 INPUT H$
 9208 IF LEN H$>8 THEN GOTO 9206
 9210 PRINT AT 1,23;H$
 9212 LET T$(1)=H$
 9214 PRINT "NAME OF VISITING TEAM:"
 9216 INPUT V$
 9218 IF LEN V$>8 THEN GOTO 9206
 9220 PRINT AT 2,23;V$
 9222 LET T$(2)=V$
 9230 GOSUB 5100
 9240 PRINT AT 1,10;"% %F%I%R%S%T% %H%A%L%F% "
 9250 GOSUB 5800
 9260 GOTO 100
 9900 SAVE "1024%0"
 9910 RUN 

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

Scroll to Top