--- title: "Slot Machine" id: 57523 type: "computer_media" slug: "slot-machine-3" url: "http://localhost/computer_media/slot-machine-3/" markdown_url: "http://localhost/computer_media/slot-machine-3.md" published_at: "2024-10-05T21:26:07+00:00" modified_at: "2026-03-30T21:17:28+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/278_Slot.png" excerpt: "Spin three graphical reels, bet up to $5, and try to hit the jackpot in this block-graphic slot machine with animated win celebrations." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_contents: - id: 56737 title: "Timex Sinclair Public Domain Library Tape 1006" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1006/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/278_Slot.png" media_type_tags: "Game, Software" --- 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. | Lines | Role | | --- | --- | | 10–40 | Initialise constants E=2, F=3, money M=0, RAND | | 50–80 | Generate outcome D, display win/loss message, reset D to 20 (jackpot multiplier) | | 90–110 | Display balance and bet prompt, accept INPUT B | | 120 | Validate bet: 1 ≤ B ≤ 5 | | 130–310 | Draw slot machine graphic and clear message area | | 320–400 | Call GOSUB 500 three times to generate and display reel symbols X, Y, Z | | 410–490 | Deduct bet, evaluate win, update balance, display payout | | 500–540 | Subroutine: generate random reel value A (0–5), animate, print block graphic | | 550–660 | Subroutine: flash “YOU WIN” message in normal/inverse video | | 670–700 | Subroutine: short busy-wait delay loop (counts to 3) | | 710–730 | CLEAR, 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 THEN PRINT AT 12,8;"TRY YOUR LUCK" 70 IF DE+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 ```