HP Forums
HP-42 Program Critique - Kinematic Equations (first program) - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: HP-42 Program Critique - Kinematic Equations (first program) (/thread-15187.html)



HP-42 Program Critique - Kinematic Equations (first program) - DM48 - 06-14-2020 12:41 AM

I've been writing small programs trying to get a feel for different areas of Free42/DM42.

Here is my version for the Kinematic equations (three instances). On the menu, the first variable listed is the data you have -> the data you want. Time -> Distance for example.

Don't hold back and let me have it. I welcome any and all suggestions and corrections. My biggest obstacle at the moment is understanding when to use GTO vs XEQ. The difference is GTO goes and stops unless you point it somewhere else to go and XEQ executes and comes back and continues on.

In the early days experimenting with the Menu layout and just have a 1 + option XEQ seemed to fail after four pushes of the soft key. This is why I used GTO here.

Many thanks in advance!

Code:
00 { 137-Byte Prgm }
01▸LBL "KINE"
02 CLMENU
03 "d→t"
04 KEY 1 GTO 01
05 "t→d"
06 KEY 2 GTO 02
07 "t→Vf"
08 KEY 3 GTO 03
09 KEY 9 GTO 09
10 MENU
11 STOP
12▸LBL 01
13 0.5
14 ÷
15 32.17045
16 ÷
17 SQRT
18 CLA
19 ARCL ST X
20 ├" s"
21 AVIEW
22 CLA
23 RTN
24▸LBL 02
25 X↑2
26 0.5
27 ENTER
28 32.17045
29 ×
30 ×
31 CLA
32 ARCL ST X
33 ├"feet"
34 AVIEW
35 CLA
36 RTN
37▸LBL 03
38 32.17045
39 ×
40 5280
41 ÷
42 3600
43 ×
44 CLA
45 ARCL ST X
46 ├" mph"
47 AVIEW
48 CLA
49 RTN
50▸LBL 09
51 EXITALL
52 END



RE: Program Critique - Dave Britten - 06-14-2020 02:26 PM

You might have been running into issues with the KEY XEQ instructions since your menu doesn't loop back to itself. Typically, after MENU, STOP, you'll want a GTO that jumps back to the same menu. This can either be a LBL directly before the MENU instruction, or all the way before the CLMENU (sometimes it depends on the program and whether it needs to refresh the contents of the menu every time it's displayed).

By doing that, and also leaving out the KEY 9 GTO... (i.e. not moving the program pointer when closing the menu), the user can redisplay the last menu by simply pressing R/S. Of course, there are plenty of times where you DO want to handle the EXIT key and RTN or GTO, particularly if you're building a tree of submenus and you want EXIT to go back up a level.


RE: Program Critique - DM48 - 06-14-2020 06:23 PM

Thank you for the insight. I didn't even think about handling the program pointer when closing the menu. Will have to weight that out. I'm still trying to hold on to my 48G roots and soft menus.

I will play around with the looping back to the same menu and the KEY XEQ call you described.

Thank you.


RE: Program Critique - DM48 - 03-18-2021 12:59 AM

Updated. Comments welcome.

This program handles a few kinematic equations and sets a Custom menu (Key 4).

Code:

00 { 230-Byte Prgm }
01▸LBL "KINE"
02 CLMENU
03 "d→t"
04 KEY 1 GTO 01
05 "t→d"
06 KEY 2 GTO 02
07 "t→Vf"
08 KEY 3 GTO 03
09 "Vf→t"
10 KEY 4 GTO 04
11 "G"
12 KEY 5 GTO 05
13 KEY 9 GTO 09
14 MENU
15 STOP
16▸LBL 01
17 0.5
18 ÷
19 32.17045
20 ÷
21 SQRT
22 CLA
23 "t = "
24 ARCL ST X
25 ├" s"
26 AVIEW
27 CLA
28 RTN
29▸LBL 02
30 X^2
31 0.5
32 ENTER
33 32.17045
34 ×
35 ×
36 CLA
37 ARCL ST X
38 ├" ft"
39 AVIEW
40 CLA
41 RTN
42▸LBL 03
43 32.17045
44 ×
45 5280
46 ÷
47 3600
48 ×
49 CLA
50 ARCL ST X
51 ├" mph"
52 AVIEW
53 CLA
54 RTN
55▸LBL 04
56 5280
57 ×
58 3600
59 ÷
60 32.17045
61 ÷
62 CLA
63 ARCL ST X
64 ├" s"
65 AVIEW
66 CLA
67 RTN
68▸LBL 05
69 ASSIGN "R↑" TO 01
70 ASSIGN "X<>" TO 02
71 ASSIGN "%CH" TO 03
72 ASSIGN "ABS" TO 04
73 ASSIGN "Root" TO 05
74 ASSIGN "EXITA••" TO 06
75▸LBL 09
76 EXITALL
77 END



RE: Program Critique - rprosperi - 03-18-2021 03:17 AM

The "00 { Header }" clarifies this program is intended for the 42S/Free42/DM42, but it's a good idea to include that in the posting Subject. This also makes it easier to locate the thread later when looking for this thread.


RE: HP-42 Program Critique - Kine - DM48 - 03-18-2021 11:17 AM

Done and thank you.