Program menu; key press remembered?

Discussion around the Swiss Micros DM42 calculator.
Post Reply
jthole
Posts: 114
Joined: Mon Nov 27, 2017 8:46 pm
Location: Netherlands

Program menu; key press remembered?

Post by jthole »

When I define menu keys in a program with KEYX or KEYG, are the key presses stored in a register?

That means I could do something like this:

"CHOICE 1"
KEY 1 XEQ 01
"CHOICE 2"
KEY 2 XEQ 01
...
LBL 01
<retrieve key number pressed>
<do something with the key number>
RTN

instead of having each key press jumping to its own label.
(Yes, I used the search, and read the manual, but couldn't find it.)

Thanks!
User avatar
Walter
Posts: 1899
Joined: Tue May 02, 2017 11:13 am
Location: Close to FRA, Germany

Re: Program menu; key press remembered?

Post by Walter »

How about using a flag to differentiate between two alternatives?
DM42 SN: 00041 β
WP 43S running on this device

HP-35, HP-45, ..., HP-35S, WP 34S, WP 31S, DM16L
Thomas Okken
Posts: 922
Joined: Tue May 02, 2017 5:48 pm
Location: United States
Contact:

Re: Program menu; key press remembered?

Post by Thomas Okken »

jthole wrote:
Mon Dec 14, 2020 8:36 am
When I define menu keys in a program with KEYX or KEYG, are the key presses stored in a register?
No. You can check whether or not Shift was pressed by testing flag 64, but for which key was pressed, the only information you have is which LBL was called.

(The flag 64 thing is a DM42/Free42 feature. It does not work on a real HP-42S or in Emu42.)
jthole
Posts: 114
Joined: Mon Nov 27, 2017 8:46 pm
Location: Netherlands

Re: Program menu; key press remembered?

Post by jthole »

Walter wrote:
Mon Dec 14, 2020 9:48 am
How about using a flag to differentiate between two alternatives?
In my case, I have five alternatives. I am going to use five different labels, and calling a common subroutine from there (with different values, of course).

Thanks @Walter and @Thomas Okken!
toml_12953
Posts: 714
Joined: Wed May 03, 2017 7:46 pm
Location: Malone, NY USA

Re: Program menu; key press remembered?

Post by toml_12953 »

jthole wrote:
Mon Dec 14, 2020 8:36 am
When I define menu keys in a program with KEYX or KEYG, are the key presses stored in a register?

That means I could do something like this:

"CHOICE 1"
KEY 1 XEQ 01
"CHOICE 2"
KEY 2 XEQ 01
...
LBL 01
<retrieve key number pressed>
<do something with the key number>
RTN

instead of having each key press jumping to its own label.
(Yes, I used the search, and read the manual, but couldn't find it.)

Thanks!
Could each key store a different address in a register rather than XEQ and then do an indirect jump to that address?
Tom L

You can't believe everything you read but can you read everything you believe?
DM10L SN: 059/100
DM41X SN: 00023 (Beta)
DM41X SN: 00506 (Shipping)
DM42 SN: 00025 (Beta)
DM42 SN: 00221 (Shipping)
jthole
Posts: 114
Joined: Mon Nov 27, 2017 8:46 pm
Location: Netherlands

Re: Program menu; key press remembered?

Post by jthole »

toml_12953 wrote:
Mon Dec 14, 2020 2:35 pm
Could each key store a different address in a register rather than XEQ and then do an indirect jump to that address?
Maybe a possibility, but I am not sure that improves my current code. I think I am not going to spend more time on it now :)
ferni123
Posts: 36
Joined: Tue Aug 08, 2017 11:24 am

Re: Program menu; key press remembered?

Post by ferni123 »

In case it helps, I usually solve the issue using a variable like "ik" as in the following code. In that code XEQ 42 can check the key pressed looking at "ik":

// build menu
CLMENU
XEQ D
KEY 1 GTO 01
XEQ D
KEY 2 GTO 02
XEQ D
KEY 3 GTO 03
XEQ D
KEY 4 GTO 04
XEQ D
KEY 5 GTO 05
XEQ D
KEY 6 GTO 06
KEY 7 GTO 07
KEY 8 GTO 07
KEY 9 GTO "UNIT"
// initialisation of ik
XEQ 41
SF 22
MENU
LBL 07
STOP
GTO 07
// identification of key pressed in ik
LBL 06
ISG "ik"
LBL 05
ISG "ik"
LBL 04
ISG "ik"
LBL 03
ISG "ik"
LBL 02
ISG "ik"
LBL 01
// activate/deactivate fix unit mode
XEQ 42
Post Reply