The screen above is the result of several parts of the program, update of the score, current batter, current pitcher, runners on base, and the result of a batter play from the roll of the dice and lookup of the play result, and processing of the play result.
So here is some of the code that produces this output .
First here is a subset of the data for each player’s info (9000’s) and the batter result vs. left and right handed pitchers (9100’s)
9001 DATA “JACKIE ROBINSON”,”R4A2B+53B+21B+2OF+0 ”
9002 DATA “CHARLIE GEHRINGER”,”L2A2B14 ”
9004 DATA “HONUS WAGNER”,”R5ASS173B+72B+41B+4OF+4″
9007 DATA “PIE TRAYNOR”,”R2A3B13 ”
9101 DATA “*3E$4/K/S4VV2CS/1PD+PG+AGFNFPP”,”*3$4GD22G4EGKVA+1GPSPCPN/FSFG/”
9102 DATA “3P4PP2$P*2PGGVG/GFESD+SNAFKC1F”,”3PP$4VVP*KFFG+PGG/ESD2SNAF/C1/”
9104 DATA “KK4$3PE*K311F2C/PD/PGVGA+NSFFG”,”*4$3///SN$EG2CSN1ND+PP+AGFKVFP”
9107 DATA “*N$32NGEE4DG1CGGVFFV++PAFGPSSG”,”*/$32SSEE4FF1CPPN/D/AA/+FGGSSK”
For often used subroutines I like to set a variable to the line number so they are easily called with GO SUB. For example GTNAME subroutine which reads the players name and info is at line 135. One nice feature of Sinclair BASIC is that GOSUB’S and RESTORES can be called with variables or a calculation, not all BASIC’s allow this.
(setting variables for subroutine calls)
9991 LET BALK=310: LET UDBASE=110: LET GTNAME=135: LET UDSCORE=140: LET UDOUT=165
so a call with GO SUB GETNAME will call the code below. Which will pull the name and info for the player indexed by PNUM. So to access HONUS WAGNER, PNUM would be set to 4, before calling GTNAME
135 REM GTNAME – PASS IN PNUM
137 RESTORE 9000+PNUM: READ N$,H$(1)
In this next block of code, in line 9082 the batter results the current batter accessed from the line up array L, is read into B$(1) for result vs left handed pitcher, and B$(2) for result vs. right handed pitcher.
8060 REM NOW BATTING
8061 PAPER 0: INK 6
8062 LET PNUM=L(HV,B(HV)): GO SUB GTNAME: RESTORE 9100+L(HV,B(HV)): READ B$(1),B$(2)
8065 PRINT AT 10,9;Z$(1 TO 23): PRINT AT 10,9;N$;
They result of the play is now pull brom B$(PH, ROLL-9), where PH is 1 or 2 based on which hand the pitchers uses, and stored as a single character in R$. Rolling the dice results in integer from 10 to 39, so to pull the proper character from the string 9 is subtracted.
2010 GO SUB DICE : REM RETURNS ROLL
2020 LET R$=B$(PH,ROLL-9)
In the case from the picture above the result in R$ = 1 and the following code was triggered
8130 IF R$=”1″ OR R$=”C” OR R$=”E” THEN GO SUB 8500
Calling the subroutine in 8500. The array R(x) where x is 1, 2, 3 is used to track if the base in empty R(x)=0 or if a player is on the base R(x)=player index. For a R$=1 – single – all runners advance one base, and current batter is on first.
So in line 8501 – if a runner is on third then he scores and one is added to score by a call to ADD1, and R(3) is cleared by assigning to 0. Next line 8502 checks for a runner on second R(2) if there is one, it is moved to third base R(3)=R(2) and R(2) cleared, then in line 8503 same is done for first base. Then in 8504 the current batter is place on first R(1) and the message of the play result is assigned to M$ and you can see it displayed in the picture above.
8500 REM SINGLE 1
8501 IF R(3)>0 THEN GO SUB ADD1: LET R(3)=0
8502 IF R(2)>0 THEN LET R(3)=R(2): LET R(2)=0
8503 IF R(1)>0 THEN LET R(2)=R(1)
8504 LET R(1)=L(HV,B(HV)): LET M$=”Single, all runners advance one base”
Each play result has a subroutine to handle to scoring and movement on the bases, or to handle the different type of outs (say a ground out, fly out, strike out) etc.
So hopefully this gives a sense of some of the inner-workings of this game, some feeling of my BASIC coding style, and some of the features of Sinclair BASIC.