Slot Machine

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

This program implements a one-armed bandit (slot machine) game with a graphical reel display and simple betting mechanics. The reels are drawn using ZX Spectrum block graphics characters, with each of three reel positions generated by the subroutine at line 500 using RND to pick from six symbols (CHR$ 128–133). Betting accepts $1 to $5, validated by checking the input against the range 1–5 using the expression BE+F (where E=2, F=3). Wins are determined when the first reel shows a 7 (value F=3), with a multiplier of 2× for a partial match, 5× for two 7s, and 20× for three 7s. A flashing “YOU WIN” celebration routine at line 550 alternates between normal and inverse video text using a short delay loop at line 670.


Program Analysis

Program Structure

The program is organised into a main game loop and three subroutines. Execution flows from initialisation (lines 10–40), through spin and display (lines 50–310), reel generation (lines 320–400), win/loss logic (lines 410–490), and then loops back to line 80 to update the balance display.

LinesRole
10–40Initialise constants E=2, F=3, money M=0, RAND
50–80Generate outcome D, display win/loss message, reset D to 20 (jackpot multiplier)
90–110Display balance and bet prompt, accept INPUT B
120Validate bet: 1 ≤ B ≤ 5
130–310Draw slot machine graphic and clear message area
320–400Call GOSUB 500 three times to generate and display reel symbols X, Y, Z
410–490Deduct bet, evaluate win, update balance, display payout
500–540Subroutine: generate random reel value A (0–5), animate, print block graphic
550–660Subroutine: flash “YOU WIN” message in normal/inverse video
670–700Subroutine: short busy-wait delay loop (counts to 3)
710–730CLEAR, SAVE with auto-run flag, RUN

Constant Encoding and BASIC Idioms

Rather than using numeric literals directly, the program encodes constants through two variables: E=2 and F=3. This allows derived values without extra variables:

  • F-E = 1 (minimum bet, also used as the threshold for a win when D<1 is “lose”)
  • E+F = 5 (maximum bet)
  • E*F = 6 (number of reel symbols, 0–5)
  • E-E = 0 (used to initialise M and as the FOR loop start)

This is a space-saving technique common in hobbyist BASIC, reducing the number of literal numbers stored in the tokenised line.

Reel Symbol Generation (GOSUB 500)

The subroutine at line 500 picks a random integer A in 0–5 via INT(RND*(E*F)), then runs a FOR loop from 0 TO 65 as a visible spinning delay. It then prints CHR$(128+A*E), i.e. CHR$ 128, 130, 132, 134, 136, or 138 — every other block graphic character. The A*E (A×2) step means only even-numbered UDG/block-graphic slots are used, skipping alternates, which may give a more varied visual appearance. The return value A is then captured by the caller into X, Y, or Z.

Win Logic

The game checks for a win only when reel 1 (X) equals F (=3, the “7” position). The logic at line 420 discards the spin as a loss if X≠F or if X≤Y or X≤Z, i.e. either of the other reels has a symbol value ≥ X. A win is declared when X=F=3 and both Y and Z are less than 3.

Payouts are set at line 440 onwards:

  • Base win: C=2 (×2 payout, line 440)
  • If Y=F (second reel also a 7): C=5 (E+F, line 450)
  • If X=Y=Z=F (all three 7s): C=20 (D, set at line 80, line 460)

Win/Loss Display and Animation

The initial outcome display at lines 60–70 uses D=RND*E (0.0–2.0) compared to 1: D<F-E (i.e. D<1) shows “YOU LOST”, otherwise “TRY YOUR LUCK”. This early random check is purely cosmetic — the actual reel outcome is determined later at line 500.

The “YOU WIN” flash subroutine (lines 550–660) alternates between normal text and inverse-video text (%Y%O%U% %W%I%N) six times, using the delay subroutine at line 670 (a loop counting T from 0 to 3) between each flash.

Slot Machine Graphic

The cabinet graphic (lines 130–280) is built from % (inverse space, a solid block) and ZX Spectrum block graphic characters (\''=▀, \..=▄, \: =▌, etc.) to draw a stylised three-reel slot machine frame. Lines 260 and 280 use top and bottom half-block characters to form reel windows. Lines 290–310 clear the message area before printing results.

Notable Anomalies and Observations

  • The RAND at line 40 (without an argument) re-seeds the random number generator each game cycle, making outcomes less predictable than a fixed seed but also resetting the RNG state on every spin.
  • The delay loop at line 670 only counts to 3, making it extremely short — effectively a near-instant “delay” on real hardware.
  • Line 420’s condition X<=Y OR X<=Z means a win requires X=3 and both Y<3 and Z<3; equal values on the second or third reel cause a loss unless the triple-match condition (line 460) also holds — but that path is only reached after 430, so a tie at X=Y=Z=F=3 would survive 420 only if Y<X and Z<X, which contradicts Y=Z=F=X. This is a logical bug: three 7s should be the jackpot but the condition at 420 would discard it as a loss (since X≤Y when X=Y=3).
  • Lines 710–730 (CLEAR, SAVE, RUN) are unreachable from normal program flow, serving only as a loader block at the end of the listing.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10252 – 10293.

Related Products

Related Articles

Related Content

Image Gallery

Slot Machine

Source Code

  10 LET E=2
  20 LET F=3
  30 LET M=E-E
  40 RAND 
  50 LET D=RND*E
  60 IF D>=F-E THEN PRINT AT 12,8;"TRY YOUR LUCK"
  70 IF D<F-E THEN   PRINT AT 12,8;" *YOU LOST* "
  80 LET D=20
  90 PRINT AT 13,9;"NOW AT $";M
 100 PRINT AT 14,8;"PLAY $1 TO $5"
 110 INPUT B
 120 IF B<F-E OR B>E+F THEN GOTO 110
 130 PRINT AT 9,22;"% "
 140 PRINT AT 3,22;"\ :"
 150 PRINT AT 4,22;"\ :"
 160 PRINT AT 5,22;"% "
 170 PRINT AT 6,22;"% "
 180 PRINT AT 8,22;"% "
 190 PRINT AT 7,21;"% % "
 200 PRINT AT 3,10;"% % % %$%$%$% % % "
 210 PRINT AT 4,10;"% % % % % % % % % "
 220 PRINT AT 5,9;"% % % % % % % % % % % "
 230 PRINT AT 6,8;"% % % % % % % % % % % % % "
 240 PRINT AT 7,8;"% % % % % % % % % % % % % "
 250 PRINT AT 8,8;"% % % % % % % % % % % % % "
 260 PRINT AT 9,8;"% \''\''\''% \''\''\''% \''\''\''% "
 270 PRINT AT 10,8;"%    %    %    % "
 280 PRINT AT 11,8;"% \..\..\..% \..\..\..% \..\..\..% "
 290 PRINT AT 12,8;"             "
 300 PRINT AT 13,8;"             "
 310 PRINT AT 14,8;"             "
 320 PRINT AT 10,10;
 330 GOSUB 500
 340 LET X=A
 350 PRINT TAB 14;
 360 GOSUB 500
 370 LET Y=A
 380 PRINT TAB 18;
 390 GOSUB 500
 400 LET Z=A
 410 LET M=M-B
 420 IF X<>F THEN IF X<=Y OR X<=Z THEN GOTO 40
 430 GOSUB 550
 440 LET C=E
 450 IF Y=F THEN LET C=E+F
 460 IF X=Y AND X=Z THEN LET C=D
 470 LET M=M+C*B
 480 PRINT C*B
 490 GOTO 80
 500 LET A=INT (RND*(E*F))
 510 FOR Z=E-E TO 65
 520 NEXT Z
 530 PRINT CHR$ (128+A*E);
 540 RETURN 
 550 PRINT AT 6,11;"       "
 560 PRINT AT 6,11;"YOU WIN" 
 570 LET P=0
 580 GOSUB 670
 590 PRINT AT 6,11;"%Y%O%U% %W%I%N"
 600 GOSUB 670
 610 PRINT AT 6,11;"YOU WIN"
 620 PRINT AT 7,13;"   "
 630 PRINT AT 7,13;"$";
 640 LET P=P+1
 650 IF P=6 THEN RETURN 
 660 GOTO 590
 670 LET T=0
 680 LET T=T+1
 690 IF T=3 THEN RETURN 
 700 GOTO 680
 710 CLEAR 
 720 SAVE "1027%8"
 730 RUN 

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

People

No people associated with this content.

Scroll to Top