hp41programs

Blackjack

Blackjack for the HP-41


Overview
 

 1°)  Program#1 ( Standard Rules )
 2°)  Program#2 ( Modified Rules )
 

Program#1
 

-This program allows you to play Blackjack against your HP-41
-The calculator is always the bank.

-Place your bet in X-register and XEQ "BLJ"
-The HP-41 deals 2 cards for you and 1 for itself.
-If you have 21 points with these 2 cards, you win 1.5 times your bet ( unless the HP-41 has also 21 points in 2 cards ), otherwise:

   -Press the SIGMA+ key to double your bet ( line 74 ): in this case, you receive one card only.
   -Press ENTER^  to hit ( line 65 ): you can receive as many cards as you want ( provided your points do not exceed 21 - otherwise, you lose )
   -Press any other key to stand.

-If you have no Blackjack and if your total does not exceed 21,
  the HP-41 deals cards for itself until its total exceeds 16

-Then, the 2 hands are compared and your new cash is displayed.

-Place another bet and R/S to continue the game
 or simply press R/S without any digit entry to place the same bet.

-Ace = 1 or 11 points
-2 = 2 , 3 = 3 , ....... , 9 = 9 points
-T = J = Q = K = 10 points

-So the possible Blackjacks are  AT  AJ  AQ  AK

Notes:

-"Split" and "Insurance" are not covered by this program.
-A deck of an infinite number of one-suit cards is used.
  ( In other words, the probability of each card = 1/13 )
-The GETKEY function of the X-functions module is used.
 
 

Data Registers:                       ( Registers R00 & R01 are to be initialized before executing "BLJ" )

                            •  R00 = random numbers
                            •  R01 = your cash                        R02 thru R09: temp

Flags:  F22  F29
Subroutines: /

-The "append" character is denoted "~"
-Line 118 = one space
-Line 157 = two spaces
 
 

  01  LBL "BLJ"
  02  FS?C 22
  03  STO 09   
  04  21
  05  STO 02
  06  STO 03
  07  CLA
  08  ASTO 04
  09  ASTO 05
  10  2
  11  STO 06
  12  CLX
  13  STO 07
  14  STO 08
  15  FIX 0
  16  CF 29
  17  XEQ 05
  18  XEQ 06
  19  XEQ 05
  20  RCL 07
  21  *
  22  X#Y?
  23  GTO 02
  24  CHS
  25  STO 02
  26  1.5
  27  STO 06
  28  GTO 04
  29  LBL 01
  30  RCL 00
  31  R-D
  32  FRC
  33  STO 00
  34  9
  35  +
  36  10^X
  37  13
  38  MOD
  39  X=0?
  40  LASTX 
  41  CLA
  42  ARCL X
  43  LASTX
  44  X=Y?
  45  "K"
  46  DSE X
  47  X=Y?
  48  "Q"
  49  DSE X
  50  X=Y?
  51  "J"
  52  DSE X
  53  X=Y?
  54  "T"
  55  X<Y?
  56  X<>Y
  57  SIGN
  58  X=Y?
  59  "A"
  60  X<>Y
  61  ASTO Z
  62  CLA
  63  RTN
  64  LBL 02   
  65  41
  66  GETKEY
  67  X#Y?
  68  GTO 03
  69  XEQ 05
  70  CLX
  71  X<Y?
  72  GTO 02
  73  LBL 03
  74  11
  75  X#Y?
  76  DSE 06
  77  X=Y?
  78  XEQ 05
  79  RCL 02
  80  10
  81  RCL 07 
  82  *
  83  X>Y?
  84  CLX
  85  -
  86  X<0?
  87  21
  88  STO 02
  89  LBL 04
  90  XEQ 06
  91  RCL 08   
  92  *
  93  X#Y?
  94  GTO 09
  95  CHS
  96  STO 03
  97  GTO 10
  98  LBL 05
  99  XEQ 01
100  ST- 02
101  X=Y?
102  STO 07
103  ARCL 04
104  ARCL Z
105  ASTO 04
106  RCL 02
107  GTO 07
108  LBL 06
109  XEQ 01
110  ST- 03
111  X=Y?
112  STO 08 
113  ARCL 05
114  ARCL Z
115  ASTO 05
116  RCL 03   
117  LBL 07
118  " "
119  ARCL 04
120  "~/"
121  ARCL 05
122  AVIEW
123  10
124  RTN
125  LBL 08
126  XEQ 06
127  LBL 09
128  RCL 08
129  *
130  X>Y?
131  CLX
132  -
133  21
134  RCL 02
135  X#Y?
136  X<0?
137  GTO 10
138  4
139  R^
140  X>Y?
141  GTO 08
142  X<0?
143  R^
144  STO 03 
145  LBL 10
146  RCL 03
147  RCL 02   
148  -
149  X#0?
150  SIGN
151  RCL 06
152  *
153  RCL 09
154  *
155  ST+ 01
156  RCL 01
157  "  "
158  X>0?
159  "~+"
160  ARCL 01
161  "~ $"
162  FIX 4
163  SF 29
164  AVIEW
165  END

 
   ( 251 bytes / SIZE 010 )
 
 

      STACK        INPUT      OUTPUT
           X             /          Cash

 
Example:      7  STO 00     CLX  STO 01

-Place you bet, for instance  12000$ , in X-register

    12000    XEQ "BLJ"    the HP-41 displays:

                      " 6/"
                      " 6/5"
                      " 62/5"

-Press  ENTER^ to hit, you get:      " 62A/5"

-You have 19 points, so you stand: press any key except ENTER^  and  SIGMA+

                  " 62A/5K"              the HP-41 continues until its points exceed 16
                  " 62A/5KK"          Busted !  HP-41 exceeds 21: you win
                  "  +12000 $"

-----------------------------------------------------------------------------------------------------

-Simply press R/S to continue with the same bet:

                    " 5/"
                    " 5/3"
                    " 56/3"

-Press the SIGMA+ key to double your bet:

                    " 56A/3"
                    " 56A/3J"
                    " 56A/3JA"
                    " 56A/3JA9"           Busted again: you win 24000 $ and your cash is:
                    "  +36000 $"
 

Remarks:

-Do not store PI in register R00, the "random" numbers wouldn't be randomized at all...

-The display is very minimalist!
-You could for example:

       add    " TIE-PUSH"  X=Y?   AVIEW   after line  147
       add    " BLACKJACK"  AVIEW  after line 96  and after line 27

-One register only is used to store each hand so the HP-41 will not display all the cards if you ( or the HP-41 ) have more than 6 cards.
-To overcome this limitation:

       add  ARCL 11 after line 121
       add  ARCL 10 after line 119
       replace lines  113 to 115 by  ARCL 05  ARCL 11  ARCL Z  ASTO 05  ASHF  ASTO 11
       replace lines  103 to 105 by  ARCL 04  ARCL 10  ARCL Z  ASTO 04  ASHF  ASTO 10
       add  ASTO 10  ASTO 11  after line 09
 

Program#2
 

-If flag F07 is clear, the rules are identical to those used in "BLJ"
-If flag F07 is set, there is no BUST.
-The winner is the one who is the closest to 21 ( for example, you win with  "K2Q"  against  "T8" ).
 

Data Registers:           •  R00 = random numbers              ( Registers R00 & R01 are to be initialized before executing "BLJ" )
                                      •  R01 = your cash

                                          R02 thru R09: temp

Flags:  F22  F29  F07  F08  F09

  CF 07 = Standard rules
  SF 07 = No Bust

Subroutines:  /

-Line 125 is    append  /
-Line 190 is    append  +
-Line 192 is    append  $
 
 

  01  LBL "BLJ"
  02  CF 08
  03  CF 09
  04  21
  05  STO 02   
  06  STO 03
  07  CLA
  08  ASTO 04
  09  ASTO 05
  10  2
  11  STO 06
  12  CLX
  13  STO 07
  14  STO 08
  15  FIX 0
  16  CF 29
  17  XEQ 05
  18  XEQ 06
  19  XEQ 05
  20  RCL 07
  21  *
  22  X#Y?
  23  GTO 02
  24  CHS
  25  STO 02
  26  1.5
  27  STO 06
  28  SF 08
  29  GTO 04
  30  LBL 01
  31  RCL 00
  32  R-D
  33  FRC
  34  STO 00   
  35  13
  36  *
  37  INT
  38  1
  39  +
  40  CLA
  41  ARCL X
  42  13
  43  X=Y?
  44  "K"
  45  DSE X
  46  X=Y?
  47  "Q"
  48  DSE X
  49  X=Y?
  50  "J"
  51  DSE X
  52  X=Y?
  53  "T"
  54  X<Y?
  55  X<>Y
  56  SIGN
  57  X=Y?
  58  "A"
  59  X<>Y
  60  ASTO Z
  61  CLA
  62  RTN
  63  LBL 02
  64  41
  65  GETKEY
  66  X#Y?
  67  GTO 03
  68  XEQ 05
  69  CLX
  70  X<Y?
  71  GTO 02
  72  LBL 03
  73  11
  74  X#Y?
  75  DSE 06
  76  X=Y?
  77  XEQ 05
  78  RCL 02   
  79  FS? 07
  80  ST+ X
  81  10
  82  X>Y?
  83  0
  84  RCL 07
  85  *
  86  ST- 02
  87  RCL 02
  88  X<0?
  89  FS? 07
  90  FS? 30
  91  21
  92  STO 02
  93  LBL 04
  94  XEQ 06
  95  RCL 08
  96  *
  97  X#Y?
  98  GTO 09
  99  CHS
100  STO 03
101  1.5
102  FS? 07
103  STO 06
104  SF 09
105  GTO 10
106  LBL 05
107  XEQ 01
108  ST- 02
109  X=Y?
110  STO 07   
111  ARCL 04
112  ARCL Z
113  ASTO 04
114  RCL 02
115  GTO 07
116  LBL 06
117  XEQ 01
118  ST- 03
119  X=Y?
120  STO 08
121  ARCL 05
122  ARCL Z
123  ASTO 05
124  RCL 03
125  LBL 07
126  " "
127  ARCL 04
128  "~/"
129  ARCL 05
130  AVIEW
131  10
132  RTN
133  LBL 08
134  XEQ 06
135  LBL 09
136  3
137  RCL 03
138  STO 09
139  FS? 07
140  +
141  10
142  X>Y?
143  0
144  RCL 08   
145  *
146  ST- 09
147  21
148  RCL 02
149  X#Y?
150  FS? 08
151  GTO 10
152  4
153  FS? 07
154  DSE X
155  RCL 09
156  X>Y?
157  GTO 08
158  X<0?
159  FS? 07
160  FS? 30
161  R^
162  STO 03
163  LBL 10
164  RCL 03
165  FS? 07
166  ABS
167  FS? 09
168  LASTX
169  RCL 02
170  FS? 07
171  FS? 08
172  FS? 30
173  ABS
174  -
175  X#0?
176  SIGN
177  RCL 06   
178  *
179  RCL 00
180  7
181  /
182  4
183  +
184  10^X
185  *
186  ST+ 01
187  RCL 01
188  "  "
189  X>0?
190  "~+"
191  ARCL 01
192  "~ $"
193  FIX 4
194  SF 29
195  AVIEW
196  END

 
     ( 307 bytes / SIZE 010 )

 

      STACK        INPUT      OUTPUT
           X             /          Cash

 
Notes:

-Here, the bets are randomly choosen by the HP-41 ( lines 179 to 184 ) between  10000 $ and ~ 13900 $
-If you want to place your own bets, replace these lines by  RCL 10  and add   FS?C 22   STO 10   after line 01.

-When F07 is set, the HP-41 deal cards for itself until its total exceeds 17 ( lines 153-154 ).
-And if the calculator has blackjack, you lose 1.5 time your bet, unless you have blacjack too ( lines 101 to 103 ).