--- title: "Black Jack" id: 55181 type: "computer_media" slug: "black-jack" url: "http://localhost/computer_media/black-jack/" markdown_url: "http://localhost/computer_media/black-jack.md" published_at: "2024-06-20T11:49:56+00:00" modified_at: "2026-03-30T21:29:14+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2019/02/20230809-041332.jpg" excerpt: "Deal yourself in: this Blackjack game renders suit symbols as custom characters, shuffles a full 52-card deck, and pits you against a house dealer for cold hard virtual cash." 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 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" genre: - name: "Card Game" slug: "card-game" taxonomy: "genre" url: "http://localhost/type/card-game/" media_contents: - id: 55220 title: "Long Island Sinclair Timex (LIST) User Group Library Tape #7" type: "computer_media" url: "http://localhost/computer_media/long-island-sinclair-timex-list-user-group-library-tape-7/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Black%20Jack%20%28198x%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/06/blackjack.png" media_type_tags: "Card Game" --- # Black Jack This program implements a text-based Blackjack card game for one player against a computer house dealer. It defines four custom UDG characters (H, C, D, S) to represent the card suit symbols Hearts, Clubs, Diamonds, and Spades, loaded via POKE USR. The deck is represented as an array of 52 cards shuffled using a Fisher-Yates-style random swap loop, with suit and value extracted arithmetically. Card display uses color-coded INK (red for even-numbered suits, black for odd) and each card is outlined with PLOT/DRAW box-drawing. The game tracks a running money total, animates winnings/losses with a counting loop and BEEP tones, and supports multiple hands per session with a replay option. *** ## Program Analysis ### Program Structure The program is organized into a main game loop (lines 200–410) with several subroutines handling distinct responsibilities. Execution flows from initialization (lines 10–140) into a 5-hand game loop, calling subroutines for screen clearing, card dealing, and money animation. The subroutine layout is: - Lines 500–540: Draw a single card at a given screen position - Lines 650–690: Animate the money counter up or down - Lines 800–840: Deal the initial two-card hand for player or house - Lines 850–880: Deal one additional “twist” card - Lines 900–930: Clear the message and card areas of the screen ### UDG Suit Symbols Lines 20–30 load four custom UDG characters corresponding to the letters `H`, `C`, `D`, and `S` (Hearts, Clubs, Diamonds, Spades). Each character is defined by 8 bytes POKEd into memory starting at `USR x$`, where `x$` is the character letter. Line 60 pre-computes the character codes for display: `s(i)=CODE s$(i)+79` shifts each letter’s ASCII code into the UDG character range so the correct symbol is printed with `CHR$ s(sn)` in line 510. ### Deck Representation and Shuffling The 52-card deck is stored in array `c()`, initialized to values 1–52 (line 70). Shuffling (line 80) uses a simple random-swap approach: for each position `i`, a random index `r` is chosen from the full range 1–52 and the cards at positions `i` and `r` are swapped. This is not a strict Fisher-Yates shuffle (which would restrict `r` to `i..52`), so the distribution is slightly biased, though practically acceptable for a card game. Lines 90 decode each shuffled card into suit `t(i)` (1–4) and value `v(i)` (1–13) using integer division and modular arithmetic. ### Card Display Subroutine (Lines 500–540) Each card is printed at screen row `l1`, column `c1`. The value character is taken from `V$="A23456789TJQK"` using `v$(vn)`, and the suit UDG is printed on the line below. INK color is determined by the expression `INK 2-(sn=2*INT(sn/2))*2`: for even-numbered suits (Clubs=2, Spades=4) this evaluates to INK 0 (black), and for odd suits (Hearts=1, Diamonds=3) it gives INK 2 (red). A 17×17-pixel box is drawn around each card using PLOT/DRAW. A short BEEP tone accompanies each card dealt. ### Money Animation (Lines 650–690) The subroutine at line 650 animates the player’s balance `m` counting toward its new value `m1`. The FOR loop step is computed as `1-2*(m121 THEN PRINT AT 6,2; INVERSE 1; INK 2;"BUST": PRINT AT 18,6;"You bust! The house wins.": GO TO 380 260 IF pt=21 THEN PRINT AT 16,6;"You have exactly 21!": GO TO 310 270 INPUT "Press ENTER to stick, any other key to twist"; LINE z$: IF z$="" THEN GO TO 300 280 GO SUB 850: LET pt=pt+inct: PRINT AT 7,4;pt: GO TO 250 300 PRINT AT 16,8;"You stick with ";pt 310 PAUSE 200 320 LET playersgo=0: GO SUB 800: LET ht=total 330 IF ht>21 THEN PRINT AT 12,2; INVERSE 1; INK 2;"BUST";AT 18,6;"The house bust! You win.": GO TO 370 340 IF ht<=pt AND ht<19 THEN GO SUB 850: LET ht=ht+inct: PRINT AT 13,4;ht: GO TO 330 350 IF ht>pt THEN PRINT AT 18,8;"The house wins": GO TO 380 360 IF ht=pt THEN PRINT AT 18,9;"It is a draw": LET incm=b: GO SUB 650: GO TO 380 370 PRINT AT 19,11;"You gain $";2*b: LET incm=2*b: GO SUB 650 380 INPUT "Press ENTER to continue"; LINE z$ 390 NEXT g: PRINT AT 20,3;"That's it. You have $";m 400 PAUSE 150: INPUT "Press ENTER to play again, or 0 to stop"; LINE z$: IF z$="" THEN RUN 410 STOP 500 PAPER 7: LET vn=v(n): LET sn=t(n): INK 2-(sn=2*INT (sn/2))*2 510 PRINT AT l1,c1;v$(vn);" ";AT l1+1,c1;" ";CHR$ s(sn) 520 INK 0 530 PLOT c1*8-1,176-8*l1: DRAW 17,0: DRAW 0,-17: DRAW -17,0: DRAW 0,17 540 BEEP 1,5: RETURN 650 LET m1=+incm 660 FOR i=m TO m1 STEP 1-2*(m1