Store and recall display format

Post here to share useful tips and tricks, to ask questions about using your DM42 or to report software-related problems
whuyse
Posts: 25
Joined: Thu Dec 21, 2017 12:23 pm

Re: Store and recall display format

Post by whuyse » Mon Feb 12, 2018 3:15 pm

Update: code removed as it contained bugs (yes, plural. I'm slipping). See a few posts down for a much improved version.

Hi Bob,
I was referring to this, the POP/PUSH stack program that needs a 4-column matrix to hold the stack levels.
The following program uses that STACK matrix, and will SAVE and RESTORE the mode, and keep the stack - including LastX - intact while doing so. Drawback is that the stack may not hold matrices or complex numbers - use RCLMODE and STOMODE then.
It can be easily adapted to also take into account flags 42 and 43 that hold the DEG/RAD/GRAD mode.

So, you do
XEQ "SAVMODE"
<change things>
XEQ "RSTMODE"

Since the STACK matrix is also used for PUSHing and POPping the stack, make sure there are an equal number of both in the <change things> part ;-)



Cheers, Werner
Last edited by whuyse on Fri Feb 16, 2018 8:13 am, edited 1 time in total.
42S #3249S01123
DM42 #00345

keithdalby
Posts: 489
Joined: Mon Apr 24, 2017 6:38 pm

Re: Store and recall display format

Post by keithdalby » Mon Feb 12, 2018 3:22 pm

By the way, thanks to help from here, the program I wrote now stores the display mode and returns to it after EXITing. I'll post the code later, need to pop to the shop now.

whuyse
Posts: 25
Joined: Thu Dec 21, 2017 12:23 pm

Re: Store and recall display format

Post by whuyse » Thu Feb 15, 2018 2:58 pm

Here's my latest concoction.
I decided to focus solely on Save & Restore functionality, but without use of the STACK matrix.
So, the following programs Save and Restore the Mode (well, display mode FIX/SCI/ENG/ALL, DEGRAD, Thousands separator, comma or decimal point, Rectangular/Polar and Complex or Real results).
Both programs leave the stack intact, whatever it may contain (matrices, complex numbers, ..). Both use the variable 'Mode' and one or two temporary variables that are deleted on exit. Restoring the mode leaves the 'Mode' variable intact.

BTW my previous programs contained a bug, restoring SCI and ENG were swapped. Corrected (and improved) here.

Code: Select all

00 { 200-Byte Prgm }
01▸LBL "RSTMode"
02 STO ".x"
03 R↓
04 STO ".y"
05 CLX
06 RCL "Mode"
07 5
08 DEG
09 BIT?
10 GRAD
11 DSE ST X
12 BIT?
13 RAD
14 DSE ST X
15 RECT
16 BIT?
17 POLAR
18 DSE ST X
19 CPXRES
20 BIT?
21 REALRES
22 DSE ST X
23 CF 28
24 BIT?
25 SF 28
26 CLX
27 CF 29
28 BIT?
29 SF 29
30 CLX
31 64
32 STO÷ ST Y
33 X<> ST L
34 X<>Y
35 IP
36 ABS
37 CLX
38 4
39 STO÷ ST L
40 X<> ST L
41 FP
42 STO+ ST X
43 STO+ ST X
44 SCI IND ST L
45 DSE ST X
46 FIX IND ST L
47 X=0?
48 ENG IND ST L
49 DSE ST X
50 ALL
51 R↓
52 STO ST L
53 GTO 00
54▸LBL "SAVMode"
55 STO ".x"
56 CLX
57 36.043
58 R↓
59 STO ".y"
60 CLX
61 XEQ 04
62 73.074
63 R↓
64 XEQ 04
65 28.029
66 R↓
67 XEQ 04
68 STO "Mode"
69▸LBL 00
70 X<> ".y"
71 RCL ".x"
72 CLV ".x"
73 CLV ".y"
74 RTN
75▸LBL 04
76 STO+ ST X
77 FS? IND ST T
78 ISG ST X
79▸LBL 04
80 ISG ST T
81 GTO 04
82 END
Cheers, Werner
Last edited by whuyse on Sat Feb 17, 2018 11:29 am, edited 2 times in total.
42S #3249S01123
DM42 #00345

rprosperi
Posts: 372
Joined: Mon Apr 24, 2017 5:48 pm
Location: New York

Re: Store and recall display format

Post by rprosperi » Thu Feb 15, 2018 9:25 pm

whuyse wrote:
Thu Feb 15, 2018 2:58 pm
Here's my latest concoction.
...
Bravo Werner!!

This is not only extremely useful for everyday programming, but it also employs advanced techniques with variables and system programming, plus as usual, some lessons in efficient stack juggling.

Though having this provided by new system commands might be a tiny bit more transparent, this is close enough for me and also serves as an instructional tool. I withdraw my request for new save/restore state commands.

Thanks very much!
--bob p

DM42: β00071 & 00282

whuyse
Posts: 25
Joined: Thu Dec 21, 2017 12:23 pm

Re: Store and recall display format

Post by whuyse » Fri Feb 16, 2018 6:40 am

Thanks Bob. Tweaked it a little, and updated the previous post accordingly.
Cheers, Werner
42S #3249S01123
DM42 #00345

rprosperi
Posts: 372
Joined: Mon Apr 24, 2017 5:48 pm
Location: New York

Re: Store and recall display format

Post by rprosperi » Fri Feb 16, 2018 3:11 pm

whuyse wrote:
Fri Feb 16, 2018 6:40 am
Thanks Bob. Tweaked it a little, and updated the previous post accordingly.
I see it's even shorter! Thanks again.
--bob p

DM42: β00071 & 00282

whuyse
Posts: 25
Joined: Thu Dec 21, 2017 12:23 pm

Re: Store and recall display format

Post by whuyse » Sat Feb 17, 2018 11:31 am

Updated it again.. 10 bytes less. Guess that's it, but 'never say never'.
Werner
42S #3249S01123
DM42 #00345

rprosperi
Posts: 372
Joined: Mon Apr 24, 2017 5:48 pm
Location: New York

Re: Store and recall display format

Post by rprosperi » Sat Feb 17, 2018 2:42 pm

whuyse wrote:
Sat Feb 17, 2018 11:31 am
Updated it again.. 10 bytes less. Guess that's it, but 'never say never'.
Werner
Obsession is never pretty... but it often produces shorter programs. Thx for sharing.
--bob p

DM42: β00071 & 00282

whuyse
Posts: 25
Joined: Thu Dec 21, 2017 12:23 pm

Re: Store and recall display format

Post by whuyse » Sat Feb 17, 2018 4:06 pm

But that's the fun part?
The first part is 'make it work'.
Second is to improve it and make short, elegant code - even if today we have memory galore. Old habits die hard.

Cheers, Werner
42S #3249S01123
DM42 #00345

Post Reply