Page 2 of 2

Re: Store and recall display format

Posted: Mon Feb 12, 2018 3:15 pm
by whuyse
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

Re: Store and recall display format

Posted: Mon Feb 12, 2018 3:22 pm
by keithdalby
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.

Re: Store and recall display format

Posted: Thu Feb 15, 2018 2:58 pm
by whuyse
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

Re: Store and recall display format

Posted: Thu Feb 15, 2018 9:25 pm
by rprosperi
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!

Re: Store and recall display format

Posted: Fri Feb 16, 2018 6:40 am
by whuyse
Thanks Bob. Tweaked it a little, and updated the previous post accordingly.
Cheers, Werner

Re: Store and recall display format

Posted: Fri Feb 16, 2018 3:11 pm
by rprosperi
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.

Re: Store and recall display format

Posted: Sat Feb 17, 2018 11:31 am
by whuyse
Updated it again.. 10 bytes less. Guess that's it, but 'never say never'.
Werner

Re: Store and recall display format

Posted: Sat Feb 17, 2018 2:42 pm
by rprosperi
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.

Re: Store and recall display format

Posted: Sat Feb 17, 2018 4:06 pm
by whuyse
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