The Poker Machine

Type
Game
Category
Video draw poker (casino machine)
Author
Joe McManus
Published in
Antic, May 1987 (Vol. 6, No. 1)
Year
1987
Language
Atari BASIC
Requirements
48K RAM, Atari BASIC, disk drive (per the article; the program itself never touches the disk)
Five playing cards on white card faces against a green felt background, with QUARTERS and BET counters at the top and discard instructions below

About the program

The Poker Machine turns the Atari into one of the draw poker machines found in Las Vegas casinos. You play for make-believe quarters. Feed in a stake, bet up to eight coins a hand, take a five-card deal, throw away what you don't want and draw again. Then the machine pays out according to a fixed table. Joe McManus, who played in a top-40 band in Pennsylvania, wrote it for Antic's fifth-anniversary issue, May 1987. He said he'd once turned a 20-quarter stake into nearly 200.

It looks good for a BASIC program. The cards are big GRAPHICS 1 characters drawn on white player-missile "card faces", and the suit symbols and the "10" are custom characters.

Typing it in

Don't renumber the program, as line 8 warns. The card routines are called with computed line numbers such as GOSUB I*1000+100.

Several lines are very hard to type. Line 11 (a memory-move routine), line 19000 (the card shuffler) and line 25070 (the new character shapes) are machine code and data packed into strings full of inverse and control characters. In this site's notation, {inv}…{/inv} means press the Atari (inverse) key before and after, {CTRL-E} means hold CTRL and press E, {CTRL-,} is CTRL-comma, and {TAB}, {UP}, {BACK S} and {INS LINE} are those keys typed after pressing ESC. The REMs in lines 805–808 tell you which keys make each suit character. In the magazine, these lines came as a separate Listing 2, LINES.BAS. That program wrote them to a file called LINES.LST, which you then ENTERed on top of POKER.BAS. The disk version printed here already has them merged in.

How to play

  1. Press the space bar once for each quarter you want to start with, then press START.
  2. At the flashing BET PLEASE, press space once per quarter, up to eight, then D to deal.
  3. Press 1–5 to discard cards. Each discarded card disappears from its white card face. C cancels and brings the hand back, and D draws the replacements. If you're happy with the hand as dealt, press S to stand.
  4. Winning hands flash WINNER and the coins are counted back onto your stake with a click each. The payouts are: a pair of aces 1 to 1, two pair 2 to 1, three of a kind 3 to 1, straight 5 to 1, flush 8 to 1, full house 10 to 1, four of a kind 25 to 1 and straight flush 50 to 1. Unlike most real machines, only a pair of aces pays. A pair of kings loses.

If you go broke, it offers you another game. Hold OPTION while typing RUN to leave the BREAK key working. Otherwise the program disables it (line 9 and the POKEs to 16 and 53774 in line 6002).

How it works

  • Shuffling in machine code. Lines 19000–19120 copy a short routine into page 6 (address 1536). A=USR(1536) at line 20040 shuffles a deck stored from address 1590. BASIC then reads ten cards at a time and turns each value from 1 to 52 into a rank and a suit by subtracting 13 repeatedly.
  • Evaluating the hand. Lines 900–920 turn ranks into numbers (ace = 1, J/Q/K = 11–13) and lines 950–970 sort them. The tests at 800–852 then just compare neighbours. For example, four of a kind is cards 1–4 or 2–5 equal, a full house is 3+2 or 2+3, and a straight is four "next card is one higher" steps (with a special case for 10-J-Q-K-A). A flush is spotted by comparing the five suit characters with a five-character string.
  • Card faces. Lines 8000–8060 set up player-missile graphics just below the top of memory, fill all four players and the missiles with solid blocks, and set them to white. Discarding a card moves its player away (POKE 53248,5 and so on).
  • Custom characters. Line 25030 copies the ROM font to RAM with the line-11 move routine, and line 25070 rewrites five characters there: the four suits and a one-character "10". In GRAPHICS 1, characters 59–63 are ; < = > ?, which is why the suits are typed as inverse CTRL-; and the like, and why a ten is the underscore, CHR$(95).

Variations to try

  • Make a pair of jacks or better pay, as on real casino machines. Change line 850 to test for a pair whose value is 11 or more, or 1.
  • Change the odds table (the ODDS= values) and see how fast your stake grows or shrinks.

Listing

2 REM THE POKER MACHINE
4 REM BY JOE McMANUS
6 REM (c) 1987, ANTIC PUBLISHING
8 REM (DO NOT RENUMBER THIS PROGRAM!)
9 BRK=1:IF PEEK(53279)=5 THEN BRK=0
10 DIM B(10),CARD$(10),SUIT$(10),HAND(5),FLUSH$(5),HAND$(6),H(10),X$(1),Y$(1),CHAR$(1),BUF$(320),BET(1)
11 MOV=ADR("hh{inv}{CTRL-E}q{/inv}h{inv}{CTRL-E}p{/inv}h{inv}{CTRL-E}U{/inv}h{inv}{CTRL-E}T{/inv}h{inv}{CTRL-E}o{/inv}h{inv}{CTRL-E}n {/inv}{CTRL-,}{inv}1p{CTRL-Q}TfTP{/inv}{CTRL-B}{inv}fUfpP{/inv}{CTRL-B}{inv}fqFnPjFo{/inv}{CTRL-P}{inv}f{/inv}{CTRL-.}"):Y=47:B=5:FIN=0:Z=1
12 DIM DRAW$(5):DECK=1589
13 GRAPHICS 1:POKE 712,182:POKE 708,2:POKE 711,50:POKE 710,182:POKE 709,66:POKE 752,1
14 POSITION 8,3:? #6;"THE":POSITION 7,5:? #6;"POKER":POSITION 6,7:? #6;"MACHINE"
15 ? ,"     by":? ," Joe McManus":? :GOSUB 19000:GOSUB 25000:GOSUB 8000
16 POSITION 8,3:? #6;"     ":POSITION 7,5:? #6;"     ":POSITION 6,7:? #6;"       "
17 POSITION 1,0:? #6;"{inv}quarters{/inv}":POSITION 17,0:? #6;"{inv}bet{/inv}":POSITION 5,2:? #6;SCORE:POSITION 18,2:COLOR +64:? #6;BET
18 POSITION 1,18:? #6;" HOW MANY QUARTERS ":? :? ,"{LEFT}{LEFT}{LEFT}PRESS SPACE FOR QUARTERS":? :? ,"{LEFT}PRESS START TO BEGIN"
19 OPEN #1,4,0,"K:"
20 POKE 731,255:REM KEY CLICK OFF
21 GOSUB 6000
22 IF PEEK(53279)=6 AND SCORE>0 THEN 30
24 IF CHAR$=" " THEN SCORE=SCORE+1:SOUND 0,80,10,6:GOSUB 1180:SOUND 0,0,0,0
26 POKE 764,255:CHAR$="2":GOTO 21
27 IF FIN=1 THEN 50
30 GOSUB 2500:REM BETTING ROUTINE
40 DRAW$="     "
50 FOR I=1 TO 5:GOSUB I*1000+100:NEXT I
60 FOR I=1 TO 500:NEXT I
100 CARD=CARD+1
200 FOR Z=1 TO 5:GOSUB Z*1000
202 HAND$(Z,Z)=CARD$(CARD,CARD):FLUSH$(Z,Z)=SUIT$(CARD,CARD)
203 CARD=CARD+1
206 NEXT Z
207 GOSUB 900:GOSUB 950
265 GOSUB 800
275 POKE 764,255:CHAR$=" "
280 GOSUB 6000
282 IF CHAR$="S" AND DRAW$="     " THEN FIN=2:GOTO 800
284 IF CHAR$="1" THEN X=1:GOSUB 1100:GOSUB 400
286 IF CHAR$="2" THEN X=2:GOSUB 2100:GOSUB 400
288 IF CHAR$="3" THEN X=3:GOSUB 3100:GOSUB 400
290 IF CHAR$="4" THEN X=4:GOSUB 4100:GOSUB 400
292 IF CHAR$="5" THEN X=5:GOSUB 5100:GOSUB 400
294 IF CHAR$="C" THEN 450
296 IF CHAR$="D" AND DRAW$<>"     " THEN 500
300 GOTO 280
400 DRAW$(X,X)="D":RETURN
450 FOR I=1 TO 5:IF DRAW$(I,I)=" " THEN 465
460 T=CARD:CARD=CARD-6+I:GOSUB I*1000
462 CARD=T
465 NEXT I:DRAW$="     ":GOTO 275
500 FOR I=1 TO 5
505 IF DRAW$(I,I)="D" THEN GOSUB I*1000:HAND$(I,I)=CARD$(CARD,CARD):FLUSH$(I,I)=SUIT$(CARD,CARD):CARD=CARD+1
506 NEXT I
510 FIN=2:GOSUB 900:GOSUB 950:GOTO 800
750 REM TALLY HAND/CLEAR VARIABLES/CHECK MONEY/INCREMENT CARD
751 IF ODDS=0 THEN 786
760 GAIN=BET*(ODDS+1):FOR I=1 TO GAIN:SCORE=SCORE+1:SOUND 0,80,10,8:FOR J=1 TO 100:NEXT J:GOSUB 1180
761 SOUND 0,0,0,0:NEXT I
762 POSITION 7,18:? #6;"       ":GOTO 795
786 IF SCORE=0 THEN POSITION 4,18:? #6;"YOU'RE BUSTED":? :? :? :GOTO 26000
787 GOSUB 27000:GOTO 795
788 IF PEEK(53279)=6 THEN CLR :POKE 53277,0:RUN
791 GOTO 788
795 BET=0:FIN=0:IF CARD>4 THEN FOR I=1 TO 5:GOSUB I*1000+100:NEXT I:GOSUB 20000:CARD=0
796 GOSUB 1180:GOTO 30
800 REM CHECK HAND
802 ODDS=0
803 POSITION 7,18:? #6;"      "
805 IF FLUSH$="{inv}^^^^^{/inv}" THEN ODDS=8:GOTO 810:REM {inv}^{/inv} IS INVERSE-SHIFT "*"
806 IF FLUSH$="{inv}]]]]]{/inv}" THEN ODDS=8:GOTO 810:REM {inv}]{/inv} IS INVERSE-SHIFT "."
807 IF FLUSH$="{inv}|||||{/inv}" THEN ODDS=8:GOTO 810:REM {inv}|{/inv} IS INVERSE-SHIFT "="
808 IF FLUSH$="{inv}{CTRL-;}{CTRL-;}{CTRL-;}{CTRL-;}{CTRL-;}{/inv}" THEN ODDS=8:REM {inv}{CTRL-;}{/inv} IS INVERSE-CTRL ";"
810 IF HAND(1)=1 AND HAND(2)=10 AND HAND(3)=11 AND HAND(4)=12 AND HAND(5)=13 THEN STRAIGHT=4:GOTO 817
813 STRAIGHT=0:FOR I=1 TO 4:IF HAND(I)+1=HAND(I+1) THEN STRAIGHT=STRAIGHT+1
814 NEXT I
817 IF STRAIGHT=4 AND ODDS=8 THEN ODDS=50:GOTO 860
818 IF ODDS=8 THEN 860
819 IF STRAIGHT=4 THEN ODDS=5:GOTO 860
820 IF HAND(1)=HAND(2) AND HAND(2)=HAND(3) AND HAND(3)=HAND(4) THEN ODDS=25
822 IF HAND(2)=HAND(3) AND HAND(3)=HAND(4) AND HAND(4)=HAND(5) THEN ODDS=25
824 IF ODDS=25 THEN 860
826 IF HAND(1)=HAND(2) AND HAND(2)=HAND(3) AND HAND(4)=HAND(5) THEN ODDS=10
828 IF HAND(1)=HAND(2) AND HAND(3)=HAND(4) AND HAND(4)=HAND(5) THEN ODDS=10
830 IF ODDS=10 THEN 860
832 IF HAND(1)=HAND(2) AND HAND(2)=HAND(3) THEN ODDS=3
833 IF HAND(2)=HAND(3) AND HAND(3)=HAND(4) THEN ODDS=3
834 IF HAND(3)=HAND(4) AND HAND(4)=HAND(5) THEN ODDS=3
835 IF ODDS=3 THEN 860
840 IF HAND(1)=HAND(2) AND HAND(3)=HAND(4) THEN ODDS=2
842 IF HAND(2)=HAND(3) AND HAND(4)=HAND(5) THEN ODDS=2
844 IF HAND(1)=HAND(2) AND HAND(4)=HAND(5) THEN ODDS=2
845 IF ODDS=2 THEN 860
850 IF HAND(1)=1 AND HAND(2)=1 THEN ODDS=1:GOTO 860
851 IF FIN=2 THEN 750
852 RETURN
860 POSITION 7,18:? #6;"{inv}winner{/inv}"
865 IF FIN=2 THEN 750
870 RETURN
900 REM GIVES NUMBER VALUES TO FACE CARDS
905 FOR I=1 TO 5
910 IF HAND$(I,I)=CHR$(95) THEN HAND(I)=10:GOTO 920
912 IF HAND$(I,I)="J" THEN HAND(I)=11:GOTO 920
914 IF HAND$(I,I)="Q" THEN HAND(I)=12:GOTO 920
915 IF HAND$(I,I)="K" THEN HAND(I)=13:GOTO 920
916 IF HAND$(I,I)="A" THEN HAND(I)=1:GOTO 920
917 HAND(I)=ASC(HAND$(I,I))-48
920 NEXT I:RETURN
950 REM SORTS HAND FROM LOW TO HIGH
952 FOR I=1 TO 4
954 F=1
956 IF F=2 THEN RETURN
957 FOR I1=5 TO I STEP -1
958 IF HAND(I1)>HAND(I1-1) THEN 966
959 X=HAND(I1-1)
962 HAND(I1-1)=HAND(I1)
964 HAND(I1)=X:F=2
966 NEXT I1
968 NEXT I
970 RETURN
1000 POKE 53248,48
1010 FOR I1=1 TO 10:SOUND 1,120,10,8:NEXT I1:SOUND 1,0,0,0
1020 POSITION 1,8:? #6;CARD$(CARD,CARD):POSITION 2,10:PUT #6,ASC(SUIT$(CARD,CARD))
1022 POSITION 3,12:? #6;CARD$(CARD,CARD):RETURN
1100 POKE 53248,5
1120 POSITION 1,8:? #6;" ":POSITION 2,10:? #6;" ":POSITION 3,12:? #6;" ":RETURN
1180 IF SCORE>9 THEN B=4
1181 IF SCORE>99 THEN B=3
1182 IF SCORE<100 THEN POSITION 3,2:? #6;" ":B=4
1183 IF SCORE<10 THEN POSITION 4,2:? #6;" ":B=5
1185 POSITION 1,0:? #6;"{inv}quarters{/inv}":POSITION 17,0:? #6;"{inv}bet{/inv}":POSITION B,2:? #6;SCORE
1186 POSITION 18,2:COLOR +64:? #6;BET
1187 RETURN
2000 POKE 53249,80
2010 FOR I1=1 TO 10:SOUND 1,120,10,8:NEXT I1:SOUND 1,0,0,0
2020 POSITION 5,8:? #6;CARD$(CARD,CARD):POSITION 6,10:PUT #6,ASC(SUIT$(CARD,CARD))
2022 POSITION 7,12:? #6;CARD$(CARD,CARD):RETURN
2100 POKE 53249,5
2120 POSITION 5,8:? #6;" ":POSITION 6,10:? #6;" ":POSITION 7,12:? #6;" ":RETURN
2190 POSITION 8,18:? #6;"winner":RETURN
2195 POSITION 8,18:? #6;"      ":RETURN
2500 FOR II=1 TO 4:? :NEXT II:? :? ,"{LEFT}PRESS SPACE TO BET":? ,"PRESS D TO DEAL"
2520 POKE 764,255:CHAR$="":POSITION 1,18:? #6;"    BET PLEASE     ":GOSUB 6000
2557 POKE 764,255:POSITION 1,18:? #6;"    {inv}bet please{/inv}     ":GOSUB 6000
2558 IF CHAR$="D" AND BET THEN POSITION 4,18:? #6;"            ":GOSUB 2800:RETURN
2559 IF CHAR$=" " THEN BET=BET+1:SCORE=SCORE-1:FOR I=15 TO 1 STEP -1:SOUND 3,40,10,I:GOSUB 1180:SOUND 3,0,0,0
2560 IF SCORE=0 THEN POSITION 4,18:? #6;"            ":GOTO 2800
2561 IF BET>7 THEN POSITION 4,18:? #6;"            ":GOTO 2800
2562 CHAR$="X":GOTO 2520
2800 ? :? ,"    DISCARD":? "  1        2       3       4       5":? "    S=STAND    C=CANCEL    D=DRAW":RETURN
3000 POKE 53250,112
3010 FOR I1=1 TO 10:SOUND 1,120,10,8:NEXT I1:SOUND 1,0,0,0
3020 POSITION 9,8:? #6;CARD$(CARD,CARD):POSITION 10,10:PUT #6,ASC(SUIT$(CARD,CARD))
3022 POSITION 11,12:? #6;CARD$(CARD,CARD):RETURN
3100 POKE 53250,5
3120 POSITION 9,8:? #6;" ":POSITION 10,10:? #6;" ":POSITION 11,12:? #6;" ":RETURN
4000 POKE 53251,144
4010 FOR I1=1 TO 10:SOUND 1,120,10,8:NEXT I1:SOUND 1,0,0,0
4020 POSITION 13,8:? #6;CARD$(CARD,CARD):POSITION 14,10:PUT #6,ASC(SUIT$(CARD,CARD))
4022 POSITION 15,12:? #6;CARD$(CARD,CARD):RETURN
4100 POKE 53251,5
4120 POSITION 13,8:? #6;" ":POSITION 14,10:? #6;" ":POSITION 15,12:? #6;" ":RETURN
5000 POKE 53252,184:POKE 53253,192:POKE 53254,200
5010 FOR I1=1 TO 10:SOUND 1,120,10,8:NEXT I1:SOUND 1,0,0,0
5020 POSITION 17,8:? #6;CARD$(CARD,CARD):POSITION 18,10:PUT #6,ASC(SUIT$(CARD,CARD))
5022 POSITION 19,12:? #6;CARD$(CARD,CARD):RETURN
5100 POKE 53252,5:POKE 53253,5:POKE 53254,5
5120 POSITION 17,8:? #6;" ":POSITION 18,10:? #6;" ":POSITION 19,12:? #6;" ":RETURN
6000 CHAR=0:I=0
6002 POKE 77,0:IF BRK THEN POKE 16,112:POKE 53774,112
6005 I=I+1
6010 IF PEEK(764)<>255 THEN GET #1,CHAR:CHAR$=CHR$(CHAR)
6011 IF CHAR=0 AND I<10 THEN 6005
6020 RETURN
8000 IF R=2 THEN POKE 53277,3:RETURN
8005 A=PEEK(106)-16:POKE 54279,A:PMBASE=256*A:POKE 559,46:POKE 53277,3:POKE 623,4
8006 BUF$(1)="{CTRL-,}":BUF$(320)=BUF$:BUF$(2)=BUF$
8010 JNK=USR(MOV,ADR(BUF$),PMBASE+384,320):JNK=USR(MOV,ADR(BUF$),PMBASE+704,320)
8020 FOR I=704 TO 707:POKE I,14:NEXT I
8025 BUF$(1)="?":BUF$(320)=BUF$:BUF$(2)=BUF$
8030 FOR I=0 TO 4
8035 I1=384+128*I
8040 JNK=USR(MOV,ADR(BUF$),PMBASE+I1+Y+1,20):NEXT I
8050 FOR I=53256 TO 53259:POKE I,3:NEXT I:POKE 53260,255
8060 RETURN
19000 JNK=USR(MOV,ADR("h{inv}X){/inv}{CTRL-,}{inv}"{/inv}{CTRL-J}{INS LINE}5{CTRL-F}{inv}JPz {/inv}{CTRL-J}{inv}-{/inv}{CTRL-J}{inv}RI{/inv}5{inv}{CTRL-P}{/inv}{CTRL-C}L{CTRL-M}{CTRL-F}{inv}{CTRL-E}K"{/inv}{CTRL-J}{inv}={/inv}5{CTRL-F}{inv}EKpk){/inv}{CTRL-,}{inv}JPt%K{CTRL-Y}{/inv}5{CTRL-F}{inv}{CTRL-H}P^{/inv}{CTRL-.}"),1536,49)
19500 POKE 77,0:IF BRK THEN POKE 16,112:POKE 53774,112
20000 REM SHUFFLING ROUTINE
20010 POSITION 5,10:? #6;"{inv}shuffling{/inv}"
20040 A=USR(1536)
20050 FOR X=1 TO 10
20051 IF X/3=INT(X/3) THEN FOR A=250 TO 100 STEP -10:SOUND 0,A,0,14:NEXT A:SOUND 0,0,0,0
20052 B(X)=PEEK(DECK+X)
20055 K=1
20060 IF B(X)<=13 THEN 20075
20065 B(X)=B(X)-13:K=K+1
20070 GOTO 20060
20075 H(X)=B(X):ON B(X) GOTO 20080,20085,20090,20095,20100,20105,20110,20115,20120,20125,20130,20135,20140
20080 X$="A":GOTO 20145
20085 X$="2":GOTO 20145
20090 X$="3":GOTO 20145
20095 X$="4":GOTO 20145
20100 X$="5":GOTO 20145
20105 X$="6":GOTO 20145
20110 X$="7":GOTO 20145
20115 X$="8":GOTO 20145
20120 X$="9":GOTO 20145
20125 X$="_":GOTO 20145
20130 X$="J":GOTO 20145
20135 X$="Q":GOTO 20145
20140 X$="K":GOTO 20145
20145 ON K GOTO 20150,20155,20160,20165
20150 Y$="{inv}{CTRL-;}{/inv}":GOTO 20170:REM INVERSE-CTRL ";"
20155 Y$="{inv}|{/inv}":GOTO 20170:REM INVERSE-SHIFT "="
20160 Y$="{inv}]{/inv}":GOTO 20170
20165 Y$="{inv}^{/inv}"
20170 CARD$(X)=X$:SUIT$(X)=Y$
20175 NEXT X
20177 POSITION 5,10:? #6;"          "
20180 RETURN
25000 J=(PEEK(106)-8)*256
25020 IF J<=PEEK(144)+256*PEEK(145) THEN ? #6;"PROGRAM TOO LARGE TO REDEFINE CHARS":GOTO 25120
25030 JNK=USR(MOV,57344,J,1024)
25050 J=J+472
25060 TRAP 25070:DIM ST$(40):TRAP 40000
25070 ST$="{CTRL-,}6{TAB}{TAB}>{UP}{CTRL-H}{CTRL-,}{CTRL-,}{CTRL-X}<{BACK S}{BACK S}<{CTRL-X}{CTRL-,}{CTRL-,}{UP}{UP}ww{CTRL-H}{UP}{CTRL-,}{CTRL-,}{CTRL-X}<{BACK S}{BACK S}{CTRL-X}<{CTRL-,}{CTRL-,}&i)))&{CTRL-,}"
25090 JNK=USR(MOV,ADR(ST$),J,40)
25110 POKE 756,PEEK(106)-8
25999 RETURN
26000 ? "         PLAY AGAIN? (Y OR N)":GET #1,ANS
26005 IF ANS=89 THEN 26010
26007 GRAPHICS 0:END
26010 CLOSE #1:POSITION 4,18:? #6;"             ":BET=0:FIN=1:? CHR$(125)
26012 FOR I=1 TO 5:GOSUB I*1000+100:NEXT I:GOSUB 20000:CARD=0:GOTO 16
27000 FOR S=50 TO 120
27020 SOUND 0,S,10,10:NEXT S
27030 SOUND 0,0,0,0:RETURN

Download

The original program from the Antic disk, to LOAD or ENTER instead of typing it: POKER.BAS.

Credits