Saturday, July 11, 2020

HP 42S/DM42/Free42: GETKEY Demonstration

HP 42S/DM42/Free42:  GETKEY Demonstration

Good day everyone, hope everything is well with you today!

How GETKEY Works

To find the GETKEY command:  PGM.FCN menu ( [ (shift) ] [  3  ] ), [ ↑ ], (GETK)

GETKEY puts the HP 42S on hold and awaits for you to press a key.  Whatever key you press returns a key code.   Shift+Key combinations are allowed.  Key codes start at the upper left hand corner [ Σ+ ] with key code 1, going right then down, to the bottom right hand corner [ + ] with key code 37.

Hence:
[ Σ+ ] has code 1
[ 1/x ] has code 2
[ √x ] has code 3
[ LOG ] has code 4
and so on.

Shift+Key combinations add 37 to the key code.
[ (shift) ] [ Σ+ ] has code 38
[ (shift) ] [ 1/x ] has code 39
[ (shift) ] [ √x ] has code 40
[ (shift) ] [ LOG ] has code 41
and so on.

There is no key code for the shift key alone.

The key code is returned to the X stack, which can be stored and analyzed.  Pretty simple.

HP 42S/DM42/Free 42 Program:  TABU 

Raw file:  tabulate.raw
Download:  tabulate.raw

Running TABU:

You will see a running total, starting with 0.   Press [ 1 ] to add 1,  [ 2 ] to add 2, or [ 3 ]  to add 3 to the total.   Any other key will exit the program. 

Key codes used:  [ 1 ]:  29,  [ 2 ]:  30,  [ 3 ]:  31

00 { 62-Byte Prgm }
01▸LBL "TABU"
02 0
03 STO 00
04▸LBL 10
05 GETKEY
06 STO 01
07 32
08 X<Y?
09 GTO 11
10 R↓
11 28
12 X>=Y?
13 GTO 11
14 R↓
15 28
16 -
17 STO+ 00
18 CLA
19 "TOTAL: "
20 ARCL 00
21 AVIEW
22 GTO 10
23▸LBL 11
24 CLA
25 "FINAL: "
26 ARCL 00
27 AVIEW
28 .END.

HP 42S/DM42/Free 42 Program:  BUILD

Raw file:  build.raw
Download:  build.raw

Running BUILD:   A mathematical statement is generated with two random integers between -100 and 100.   The RAN command uses the range 0 ≤ n < 1 with n ≠ 1 for all results.   To get the range wanted, I use the subroutine RAN 201 * 100 - IP  (integer(201*RAN) - 100) to get the range -100 ≤ n < 101. 

 Key codes used:  [ + ]:  37,  [ - ]:  32,  [ × ]:  27

Any other key repeats the cycle until one of the acceptable keys are pressed.

00 { 150-Byte Prgm }
01▸LBL "BUILD"
02 ALL
03 XEQ 00
04 STO 01
05 XEQ 00
06 STO 02
07 GTO 01
08▸LBL 00
09 RAN
10 201
11 ×
12 100
13 -
14 IP
15 RTN
16▸LBL 01
17 RCL 01
18 RCL+ 02
19 STO 03
20 RCL 01
21 RCL- 02
22 STO 04
23 RCL 01
24 RCL× 02
25 STO 05
26▸LBL 02
27 CLA
28 "+, -, ×?"
29 AVIEW
30 GETKEY
31 37
32 X=Y?
33 GTO 03
34 R↓
35 32
36 X=Y?
37 GTO 04
38 R↓
39 27
40 X=Y?
41 GTO 05
42 GTO 02
43▸LBL 03
44 CLA
45 ARCL 01
46 ├" + "
47 ARCL 02
48 ├" = "
49 ARCL 03
50 GTO 06
51▸LBL 04
52 CLA
53 ARCL 01
54 ├" - "
55 ARCL 02
56 ├" = "
57 ARCL 04
58 GTO 06
59▸LBL 05
60 CLA
61 ARCL 01
62 ├" × "
63 ARCL 02
64 ├" = "
65 ARCL 05
66 GTO 06
67▸LBL 06
68 AVIEW
69 END

Example results (results will vary):

-53 + -32 = -85
93 - 19 = 74
41 × -15 = -615

And that concludes the demonstration on GETKEY. 

Eddie

All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.