Post Reply 
(42S, Free42) Unit Conversion Suite
05-03-2019, 04:08 PM
Post: #15
RE: (42S, Free42) Unit Conversion Suite
(05-03-2019 03:26 PM)Logan Wrote:  Thanks Dave. Were you ever able to think about the idea in post 3? Not a big deal but just curious.

I've thought about it a bit, but hadn't spent tons of time with it. The main problem is that it's not as simple as just redisplaying the alpha register, since it gets clobbered by setting up the menu pages, and so far I haven't come up with an implementation I'm totally happy with.

A few possible approaches:

- Save the alpha register by chopping it up into a matrix so it can be restored after MENU is called. This requires tracking if anything has been entered, and maybe canceled if the user starts doing other things (e.g. flag 22 gets set).
- Save the label number of the last-entered unit, and call that indirectly to fire the "convert to" routine, redisplaying the value. This would require 2 extra steps in each unit label to store that value, and you'd need to be careful of flag 22 causing unintended unit input.
- Just toss a unit label like "cm:" into stack Y, as a crude imitation of RPL tags.

All of these have their warts: needing more global labels, complicating the individual unit conversions, chewing up a stack level, or needing complete alpha save/restore routines (which, in my current implementation, would add about 50 more steps).

It's too bad the 42 doesn't have all the X-MEM features of the 41C, because then you could probably just write the whole alpha register to an ASCII file, and subsequently restore it, making the alpha save/restore much simpler and more appetizing. (Note: I haven't done much with 41C X-MEM, so perhaps it's actually a bit more complicated than that.)

Conceptually, this is probably how I would solve it:

1. Replace all the calls to MENU with XEQ "UMENU".
2. Create a "UMENU" routine that checks for a preserved alpha register (probably by using one of the flags above 81), restores it, calls MENU, then returns. "UMENU" should probably also clear the flag to cancel redisplaying the unit if it detects flags 22 or 23 are now set, under the assumption the user is doing something else now.
3. Modify the "CVT" routine to save alpha and set the appropriate flag.
4. Have each individual unit type program clear the saved alpha on entry, so you're not seeing length measurements in the temperature menu, for instance.

This would all be quite a lot of extra code for a very small feature, so I wouldn't waste bytes and execution time on it if I were running this on a real 42S. Smile
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: (42S, Free42) Unit Conversion Suite - Dave Britten - 05-03-2019 04:08 PM

User(s) browsing this thread: 1 Guest(s)