Cricket

Type: Program
Platform(s): TS 2068
Tags: Game

This program implements a two-team cricket game in which each team bats through ten wickets, with the player pressing keys 5, 7, or 8 to deliver balls and attempt shots on the off-side or on-side. Difficulty is selectable at three levels, which controls the ball animation speed via the variable `p` passed to PAUSE. A substantial UDG (User Defined Graphics) setup routine at line 9000 loads seventeen custom characters (UDGs `\a` through `\q`) by READing DATA values and POKEing them into memory starting at USR “a”, used to draw fielders, a batsman, and the ball on a cricket pitch layout. Ball trajectory after a shot is simulated by choosing a random direction (one of four diagonals) and a random number of steps, with catches possible at four fixed coordinate positions on the field. Run scoring is mapped from the number of steps taken by the ball, with values of 1 through 6 including a six for the longest trajectories.


Program Analysis

Program Structure

The program is organized into several logical segments, though without explicit subroutine labeling beyond the REM comments near line 9105. Execution begins at line 1 with a REM, immediately calls the UDG loader at line 9000, then shows an instruction screen before entering the main game loop.

  1. Lines 1–27: Title screen, instructions, difficulty selection, team name input
  2. Lines 30–75: Innings setup, field drawing via GO SUB 8505, variable initialization
  3. Lines 96–1250: Ball delivery animation loop (FOR n=1 TO 20)
  4. Lines 1300–1308: Bowled-out handler
  5. Lines 2000–2250: Catch handler (dropped or caught)
  6. Lines 3000–3035: Caught-behind handler
  7. Lines 4500–5000: Delivery trigger — waits for key “7”
  8. Lines 5001–6099: Shot and ball-travel animation, run scoring, scoreboard update
  9. Lines 7000–8500: Wicket check, innings end, match result
  10. Lines 8505–8620: Field-drawing and wicket-fall animation subroutines
  11. Lines 9000–9130: UDG loader using READ/DATA and POKE
  12. Lines 9200–9280: Duck (zero score) wicket-fall animation variant
  13. Line 9500: Spare memory diagnostic (unreachable in normal play)
  14. Lines 9998–9999: SAVE and VERIFY

UDG Loader and Custom Characters

The subroutine at line 9000 defines seventeen UDGs (\a through \q, characters 144–160). It uses RESTORE 9000 to reset the DATA pointer, then POKEs 8 bytes per character into the UDG area located at USR "a". The loop runs from USR "a" to USR "q"+7, covering all 17×8 = 136 bytes. The REM lines at 9105–9120 serve as a developer legend mapping letter names to their escape sequences.

The UDGs represent: stump graphics (\a\d), the ball (\e), fielder bodies and legs (\f\n), and the bowler animation frames (\j\q).

Ball Delivery Animation

The delivery is animated in the FOR loop at lines 100–1200. The ball UDG \e starts at screen row 19 (near the bowler) and moves upward one row per iteration, pausing for p frames (set by difficulty: 5, 3, or 1). At step 10 of 20, a lateral deviation is applied: q=INT(RND*5-3) shifts the column by –3 to +1, simulating swing or spin. The variable b (set to 15 in GO SUB 8505) marks the stumps column; if the ball ends at y=b or y=b+1 without being hit, the batsman is bowled (lines 1210–1300).

Batting and Shot Detection

Key detection at line 140 allows the player to press “0” (no shot) to skip to step 13, ending the delivery early. Shot opportunities are checked at delivery step n=12:

  • Key “5” (off-side) is valid when y<=15 — ball is on the off side (lines 150, 170)
  • Key “8” (on-side) is valid when y>=16 — ball is on the on side (lines 155, 160)
  • Playing the wrong side shot routes to the caught-behind handler at line 3000

There is a subtle issue: line 5001 is referenced by lines 150 and 155, but line 5001 does not exist in the listing — execution falls through to line 5002. This is a deliberate use of the non-existent line technique.

Ball Travel and Run Scoring

After a shot, lines 5006–6060 animate the ball traveling across the field. Variable s is a random step count (0–14), and h (1–4) selects one of four diagonal directions: up-left, up-right, down-left, down-right. Four fixed coordinate pairs (lines 6000–6015) are designated as catching positions; hitting any of them triggers the catch subroutine at line 2000. Boundary detection at line 6047–6048 terminates travel when the ball leaves the screen. Runs are awarded by mapping s ranges to 1, 2, 3, 4, or 6 runs (lines 6061–6078), with no 5-run score possible.

Wicket and Scoreboard Management

Wickets are accumulated in variable w and incremented in the GO SUB 8555 subroutine (line 8575), except when k=2 (dropped catch), in which case the subroutine returns early at line 8569. A duck detection check at line 8578 compares ss (previous score snapshot) to rr (current total); if equal, a special duck animation plays at lines 9200–9280. Ten wickets triggers end-of-innings at line 7000.

The innings loop at lines 22–27 pre-collects both team names into h$, a 2×12 DIM string array. The variable tt toggles between 1 and 2 to select the batting team. The second innings target comparison uses t(1) vs t(2) at lines 8640–8672, but note that lines 8650 and 8665 both print h$(2) as the winner regardless of which team actually won — line 8655 should reference h$(1) for the case where team 1’s score is greater.

Key Variables Summary

VariablePurpose
pPAUSE duration per ball frame (difficulty: 5/3/1)
bStumps column position (15)
mBowler column, decrements each wicket (starts 17)
wWickets fallen this innings
rRuns scored on current delivery
t(o)Team total for team o
rr / ssScore snapshots for duck detection
sRandom ball travel steps (determines runs)
hShot direction selector (1–4)
kCatch outcome flag (1=caught, 2=dropped)
oCurrent batting team index (1 or 2)

Bugs and Anomalies

  • Lines 8650/8655: When team 1 scores more than team 2, the PRINT statement incorrectly names h$(2) as the winner instead of h$(1).
  • Line 4505: INPUT INKEY$ is an unusual idiom — it pauses for input but does not use the result; the actual key is re-read at lines 4510–4520. This effectively acts as a wait-for-any-key pause.
  • Line 8555 contains PRINT ;2,9;"\h" — the semicolon before the AT coordinates is a syntax oddity; the AT should use the keyword form PRINT AT 2,9;.... Similarly, line 1305 has PRINT ;10,0;" ". These may print incorrectly or cause errors at runtime.
  • The memory diagnostic at line 9500 is unreachable during normal play.
  • Line 8500 jumps to line 28, which does not exist; execution falls through to line 30, starting the second innings — an intentional non-existent-line technique.
  • Line 85 is referenced from line 4510 but does not exist in the listing; control falls through to line 96, beginning the delivery sequence.

Content

Related Products

Related Articles

Related Content

Image Gallery

Source Code

    1 REM Cricket
    2 GO SUB 9000
    3 BORDER 4: PAPER 4
    5 PRINT AT 0,10;"Cricket"
    7 PRINT AT 7,0;"Operating Instructions"
    8 PRINT AT 9,2;"7 for next delivery"
    9 PRINT AT 11,2;"5 to strike ball on Off-Side"
   10 PRINT AT 13,2;"8 to strike ball on On-Side"
   11 PRINT AT 15,0;"  If you don't bat straight you may get bowled or caught behind! Try not to get a Duck!"
   12 INPUT "Level of difficulty? 1-3?";d
   13 IF d<>1 AND d<>2 AND d<>3 THEN GO TO 12
   15 IF d=1 THEN LET p=5
   16 IF d=2 THEN LET p=3
   17 IF d=3 THEN LET p=1
   19 DIM t(2)
   20 DIM h$(2,12)
   21 LET tt=1
   22 FOR o=1 TO 2
   25 INPUT "Team?";h$(o)
   27 NEXT o
   30 LET o=1
   31 IF tt=2 THEN LET o=2
   32 PRINT AT 21,0;"Innings of ";h$(o)
   40 PAUSE 25
   50 CLS 
   65 GO SUB 8505
   72 LET rr=0: LET ss=0: LET w=0: LET r=0
   75 GO TO 4500
   96 INK 7: LET k=0: PRINT AT 20,14;"\f": PRINT AT 21,14;"\g"
  100 LET x=19: LET y=15
  110 FOR n=1 TO 20: INK 2: PRINT AT x,y;"\e"
  115 PAUSE p
  120 PRINT AT x,y;" ": LET x=x-1
  130 IF n=10 THEN LET q=INT (RND*5-3): LET y=y+q
  140 IF n<>12 AND INKEY$="0" THEN LET n=13
  145 IF x<=3 THEN LET x=3
  150 IF n=12 AND y<=15 AND INKEY$="5" THEN GO TO 5001
  155 IF n=12 AND y>=16 AND INKEY$="8" THEN GO TO 5001
  160 IF y<=14 AND n=12 AND INKEY$="8" THEN GO TO 3000
  170 IF y>=16 AND n=12 AND INKEY$="5" THEN GO TO 3000
 1200 NEXT n
 1210 IF y=b THEN GO TO 1300
 1220 IF y=b+1 THEN GO TO 1300
 1250 GO TO 4500
 1300 PRINT AT 10,0;"BOWLED"
 1303 GO SUB 8555
 1305 PRINT ;10,0;"      "
 1308 GO TO 6095
 2000 LET k=1+INT (RND*2)
 2010 IF k=1 THEN GO TO 2200
 2020 IF k=2 THEN GO TO 2050
 2050 GO SUB 8555
 2060 PRINT AT 10,0;"DROPPED"
 2070 BEEP .1,-10: BEEP .1,-10
 2075 PAUSE 5
 2080 PRINT AT 10,0;"       "
 2090 GO TO 6095
 2200 PRINT AT 10,0;"CAUGHT"
 2210 GO SUB 8555
 2220 PRINT AT 10,0;"      "
 2250 GO TO 6095
 3000 PRINT AT 13,5;"\e";AT 13,0;"CAUGHT BEHIND"
 3010 GO SUB 8555
 3020 PRINT AT 3,15;" ";AT 13,0;"             "
 3035 GO TO 6095
 4410 GO TO 4500
 4500 PRINT AT 10,b;"  "
 4505 INPUT INKEY$
 4510 IF INKEY$="7" THEN GO TO 85
 4520 IF INKEY$<>"7" THEN GO TO 4500
 5000 GO TO 4500
 5002 INK 7: PRINT AT 7,m;"\l";AT 8,m;"\m"
 5003 BEEP .03,0
 5005 LET c=x: LET d=y
 5006 LET s=INT (RND*15)
 5010 LET h=INT (1+4*RND)
 5015 FOR n=1 TO s
 5020 IF h=1 THEN GO TO 5100
 5030 IF h=2 THEN GO TO 5110
 5040 IF h=3 THEN GO TO 5120
 5050 IF h=4 THEN GO TO 5130
 5100 LET d=d-1: LET c=c-1: GO TO 6000
 5110 LET d=d-1: LET c=c+1: GO TO 6000
 5120 LET d=d+1: LET c=c-1: GO TO 6000
 5130 LET d=d+1: LET c=c+1
 6000 IF c=2 AND d=9 THEN GO TO 2000
 6005 IF c=10 AND d=10 THEN GO TO 2000
 6010 IF c=0 AND d=20 THEN GO TO 2000
 6015 IF c=15 AND d=22 THEN GO TO 2000
 6040 INK 2: PRINT AT c,d;"\e"
 6045 PAUSE 10
 6047 IF c<=0 THEN LET n=s: IF c>=20 THEN LET n=s
 6048 IF d<=0 THEN LET n=s: IF d>=32 THEN LET n=s
 6050 PRINT AT c,d;" "
 6055 GO SUB 8525
 6060 NEXT n
 6061 IF s>=0 AND s<=3 THEN LET r=1
 6062 IF s>=4 AND s<=7 THEN LET r=2
 6063 IF s>=8 AND s<=10 THEN LET r=3
 6064 IF s>=11 AND s<=13 THEN LET r=4
 6078 IF s>=14 THEN LET r=6
 6082 INK 1: PRINT AT 10,b;r
 6084 PAUSE 10
 6086 LET t(o)=t(o)+r
 6088 LET rr=t(o)
 6095 INK 1: PRINT AT 0,1;h$(o)
 6096 PRINT AT 1,2;t(o)
 6097 PRINT AT 2,1;"For"
 6098 PRINT AT 3,2;w
 6099 INK 7
 7000 IF w=10 THEN GO TO 8200
 7010 GO SUB 8505
 8000 GO TO 4500
 8200 CLS 
 8210 PRINT AT 5,5;"All Out"
 8220 PRINT AT 7,5;h$(o);" Scored ";t(o)
 8222 IF o=2 THEN GO TO 8630
 8250 INPUT "ENTER for next innings";i$
 8260 LET tt=2
 8300 CLS 
 8500 GO TO 28
 8505 INK 7: PRINT AT 1,15;"\f";AT 2,15;"\n";AT 0,13;"\f";AT 1,13;"\n"
 8510 PRINT AT 4,27;"\f";AT 5,27;"\g";AT 17,7;"\f";AT 18,7;"\g"
 8515 PRINT AT 5,5;"\f";AT 6,5;"\g";AT 20,14;"\h";AT 21,14;"\g"
 8520 LET m=17: LET a=5: LET b=15
 8525 INK 7: PRINT AT a,b;"\a\b";AT 6,b;"\d\c";AT 21,b;"\a\b"
 8530 PRINT AT 7,m;"\j";AT 8,m;"\k"
 8535 PRINT AT 2,9;"\f";AT 3,9;"\n";AT 10,10;"\f";AT 11,10;"\g"
 8540 PRINT AT 1,11;"\f";AT 2,11;"\n"
 8545 PRINT AT 0,20;"\f";AT 1,20;"\g";AT 15,22;"\f";AT 16,22;"\g"
 8550 RETURN 
 8555 INK 7: PRINT ;2,9;"\h";AT 0,13;"\h";AT 1,b;"\h";AT 5,5;"\h"
 8560 PRINT AT 1,11;"\h";AT 20,14;"\h";AT 21,14;"\n"
 8565 PRINT AT 15,22;"\h";AT 0,20;"\h";AT 10,10;"\h"
 8567 BEEP .1,12: BEEP .1,10: BEEP .1,12: BEEP .1,10
 8569 IF k=2 THEN RETURN 
 8575 LET w=w+1
 8578 IF ss=rr THEN GO TO 9200
 8579 LET ss=t(o)
 8580 FOR v=1 TO 17
 8585 INK 7: PRINT AT 8,m;"\k";AT 7,m;"\j"
 8590 PAUSE 6
 8595 PRINT AT 8,m;"\n"
 8600 PAUSE 6
 8605 PRINT AT 7,m;" ";AT 8,m;" "
 8610 LET m=m-1
 8615 NEXT v
 8620 RETURN 
 8625 STOP 
 8630 PAUSE 20
 8635 CLS 
 8640 IF t(1)>t(2) THEN GO TO 8650
 8642 IF t(1)=t(2) THEN GO TO 8672
 8645 IF t(1)<t(2) THEN GO TO 8665
 8650 LET u=t(1)-t(2)
 8655 PRINT AT 10,0;h$(2);" wins by ";u;" runs"
 8660 STOP 
 8665 LET u=t(2)-t(1)
 8670 PRINT AT 10,0;h$(2);" wins by ";u;" runs"
 8671 STOP 
 8672 PRINT AT 10,0;"MATCH DRAWN"
 8675 STOP 
 9000 RESTORE 9000: FOR a=USR "a" TO USR "q"+7
 9005 READ user: POKE a,user
 9010 NEXT a
 9020 DATA 0,0,0,31,25,25,25,25
 9025 DATA 0,0,0,248,152,152,152,152
 9030 DATA 152,152,152,152,152,152,152,152
 9035 DATA 25,25,25,25,25,25,25,28
 9040 DATA 0,24,60,126,126,126,60,24,0
 9045 DATA 24,36,36,24,126,126,189,189
 9050 DATA 189,126,60,60,60,60,60,60
 9055 DATA 3,3,6,54,78,54,254,190
 9060 DATA 124,60,60,60,60,60,60,60
 9065 DATA 6,9,6,14,31,31,55,111
 9070 DATA 78,78,255,232,238,238,238,94
 9075 DATA 102,105,102,103,103,103,39,63
 9080 DATA 7,7,7,7,7,7,7,15
 9085 DATA 60,60,126,102,102,102,102,238
 9090 DATA 0,0,0,48,120,24,25,31
 9095 DATA 31,30,31,30,14,4,4,12
 9100 DATA 31,30,30,30,14,10,10,10
 9105 REM a b c d e f g h i j k 
 9110 REM \a \b \c \d \e \f \g \h \i \j \k
 9115 REM l m n o p q 
 9120 REM \l \m \n \o \p \q
 9130 RETURN 
 9200 FOR v=1 TO 17
 9210 INK 7: PRINT AT 8,m;"\p";AT 7,m;"\o"
 9220 PAUSE 6
 9230 PRINT AT 8,m;"\q"
 9240 BEEP .1,-10
 9250 PRINT AT 7,m;" ";AT 8,m;" "
 9260 LET m=m-1
 9270 NEXT v
 9280 GO TO 8620
 9500 CLS : LET z=(PEEK 23670+(256*PEEK 23731))-(PEEK 23653+(256*PEEK 23654)): PRINT "SPARE MEMORY=";z
 9998 SAVE "Cricket" LINE 0: BEEP .4,15
 9999 VERIFY ""

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

People

No people associated with this content.

Scroll to Top