[comp.sys.handhelds] Constants Library in Equation Cartridge

HUBER@gacvx1.gac.edu (11/30/90)

I would like to have a menu (similar to the constants library menu in the
equation cartridge) of constants which I use frequently.  Is it possible to 
use the catalog program which is on the equation library card for a different
list of constants (by some appropriate SYSEVALS?).  Alternately, has anyone
written a similar program which will display a list of labels and then put
the extracted value to the stack.  Thanks

	Dr. Thomas M. Huber,   Physics Department 
	Gustavus Adolphus College,   St. Peter, MN  56082
	Bitnet: HUBER@GACVAX1   Internet: HUBER@GAC.EDU  (507)931-7036
	

brent@oak.circa.ufl.edu (11/30/90)

You may be interested in the PHYCONST.Z program on Wayne Scott's mail server.
This program allows you to create menus (similar to the normal HP48 menus, only
it is 6 keys across and 5 ROWS down) which contain constants or units.  You 
simply press the key which corresponds to the label on the display and the
program puts whatever you stored into the program onto the stack.  Not only can
it handle constants and units, but I've found it can even execute programs.
Further, I've found that I could modify the program to handle 8 row menus (I
might try to get 9 rows, the total numbeer of rows on the keyboard, but it would
probably be more difficult).


					Brent Nelson
					University of Florida

woodhams@phoenix.Princeton.EDU (Michael Woodhams) (12/02/90)

In article <17A5DF63A0002403@gacvx1.gac.edu> HUBER@gacvx1.gac.edu writes:
>I would like to have a menu (similar to the constants library menu in the
>equation cartridge) of constants which I use frequently.

I wrote a program for my own use which I think does what you want. I
started to prepare it for posting, but never quite got around to doing
it. It is a relatively crude program, in that little error checking is
done, and the structure is somewhat inelegant. I store the program in
"0:doit" and assign the "cst" key to run "0:doit", as this seemed more
elegant than assigning a large program to a key. The program could be
modified to have several full screen menus with the "next" key moving
between the screens.

This is what I wrote several months ago:

Below are listings of two programs for the HP-48SX. The second one
acts as a full-screen menu of physical constants and units. Running
the program turns the top 5 rows of the keyboard into menu keys, and
displays the menu items in the top part of the screen, leaving the
level 1 stack entry visable. After a key press, this menu display
disappears, and if the key was from the top 5 rows, the appropriate
constant is put on the stack or a unit is applied in the normal
manner. (unshifted - multiply by the unit, right shift - divide by the
unit, left shift - convert level 1 entry to this unit.) I assign this
program to the 'CST' key and leave my calculator in user mode, but it
could be used in other ways. (Warning - whatever is on the graphics
screen is overwritten.)

I am an astrophysics student, and this is reflected in the choice of
units and constants in my menu. Other people will have different
preferences, so the first program is one that will create a program
like the second one, with your own choice of menu items. It first
prompts for labels for the menu display, and then for the commands to
be executed by each key. There is no error checking in creating the
display, so make sure your labels are short enough to fit in an
ordinary menu box. (Except for the enter key, which has a larger box.)
If you avoid wide characters like "M" and "W", this should be 5
characters per label. The command for each key is assumed to be either
a unit or a constant. For units, enter the standard abbreviation. For
constants, enter the constant. I think the program would work if you
entered a command instead of a constant, but I haven't tried it.
Finally, note that the program refers to the "+/-" key (to the right
of the enter key) as "5,3" because it seems more intuitive to me, and
because it simplifies the program logic. The calculator, however,
thinks this is key 5,2 because it is the second key in the 5th row.

I have not make allowance for shifted keys except for units. For just
a few keys, this could be done by editing the menu program and
inserting the desired commands in the hierarchical list. If you press
a shifted key for an ordinary command, or an alpha key for a unit
command, the program will crash with several new items on the stack.
These can be dropped, and the calculator will be back in its original state.

The programs are entered by hand, as I don't have the hardware
required to dump the program to computer electronically. There may be
typos. Anything following a "%" in the listing is a comment.


The Compiler Program:


<<
  " << PICT LCD-> {#0 #0}"	% enter the first part of the menu
				% program onto the stack as a string
  GROB 21 7 FFFFF1FFFFF1FFFFF1FFFFF1FFFFF1FFFFF1FFFFF1
  -> block			% store a 27 by 7 black block
    <<
      ERASE			% clear screen
      0 32 FOR J		% vertical loop (step 8)
        0 110 FOR I		% horizontal loop (step 22)
          PICT
          I R->B J R->B 2 ->LIST	% turn I, J into co-ordinates
          block
          REPL			% draw block at I, J
          PICT			% put PICT on stack for latter use
          J 8 / 1 + ->STR	% turn J (position in pixels) into a 
				% keyboard position
          "," +
          I 22 / 1 + ->STR +	% same for I
          " Label?" +		% construct prompt string
          { \alpha }
          INPUT			% input label
          1 ->GROB		% turn label into small lettering GROB
          DUP SIZE		% extract the size of the label
          #2 /			% divide height by 2
          J 4 + R->B		% find the middle of the box vertically
          SWAP -		% take difference to center string in box
          SWAP			% swap to get the horizontal size
          #2 /			% divide width by 2
          I
          IF 'I!=0 OR J!=32' ->NUM 	% special case: enter key
          THEN
            11			% normal key is 21 pixels wide, half
				% this is 11.
          ELSE
            22 'I' STO+		% enter key. Increment I.
            PICT
            I R->B J R_B 2 ->LIST
            block		% draw next box over
            REPL
            {#21 #32} {#21 #38} LINE	% fill in the pixels between
				% the boxes to make one big box.
            22			% half of the big box is size 22
          END
          SWAP -		% take the difference to center horizontally
          SWAP			% swap to get the order of co-ords right
          2 ->LIST		% turn them into a coordinate list.
				% Now we have the coords to draw the
				% label centered in the box.
          SWAP			% swap co-ords with the label GROB
          GXOR			% draw the label (using PICT from
				% the stack at level 3.)
        22 STEP			% step in the horizontal direction
      8 STEP			% step in the vertical direction
    >>
  PICT				% extract the menu display from the
  {#0 #0} {#130 #39}		% graphics screen
  SUB				
  ->STR +			% turn it into a string and concatenate
				% to the program segment above.
  " REPL {#0 #0} SWAP REPL	% the next program segment
    {#0 #0} PVIEW 0 WAIT
    IF DUP 60 > THEN DROP ELSE "
  +				% concatenate with the rest of the program
  { }				% Start the outer-most (menu) level of
				% the commands list
  1 5 FOR row
    { }				% start a row-level commands list
    1 6 FOR col
      IF 'row==5 AND col==2' ->NUM
      THEN			% special case for "enter" again
        3 'col' STO
      END
      "(C) M Woodhams.		% a random item to be put on the stack
       May be copied		% and dropped immediately inside the 
       May not be sold."	% loop.
      DO
        DROP			% drop top of stack (junk or previous
				% incorrect keystroke)
        "UNIT (Y/N)?" 3 DISP	
        0 WAIT			% get keystroke
      UNTIL
        DUP DUP 32.1 ==
        SWAP 52.1 == OR		% keep looping until "Y" or "N"
      END			% leave loop with either 32.1 ("N")
				% or 52.1 ("Y") on stack.
      row ->STR			% start building prompt string
      "," +
      col ->STR +
      SWAP			% swap Y or N to top of stack
      IF
        32.1 ==			% if "N" then constant
      THEN
        " Const" +		% finish prompt string
        { V } INPUT
        ->OBJ 1 ->LIST		% turn the result into a one item list
      ELSE			% a unit has been requested
        " Unit" +		% finish prompt string
        { \alpha } INPUT
        -> unit			% store in unit temporarily.
          <<			% build a list of three programs to
				% perform the unshifted and shifted
				% functions of a unit menu key.
            " << 1_" unit + " * >>" +
            OBJ->		% make unit multiply program
            " << 1_" unit + " CONVERT >>" +
            OBJ->		% make unit convert program
            " << 1_" unit + " / >>" +
            OBJ->		% make unit divide program
            3 ->LIST		% turn them into a list.
          >>
      END
      1 ->LIST +		% add the newly formed list (which
				% contains the commands for one key)
				% to the list of commands for keys
				% for the whole row. (This is a list
				% of lists.)
    NEXT			% next row
    1 ->LIST +			% add the newly formed row list
				% (with the commands for all the keys
				% in one row) to the master list. (This
				% is a list of lists of lists.)
  NEXT	
  -> STR +			% turn into a string, and concatenate
				% with the program so far.
  " OVER 10 / IP GET		% the final menu program segment.
    OVER 10 / FP 10 * IP GET
    SWAP FP 10 * GET
    EVAL END
    >> "
  +				% concatenate with program so far
  ->OBJ				% convert from a string to a program
>>				% exit with the menu program on the stack.


Sample menu program:

<<
  PICT				% PICT on stack for latter use
  LCD->				% make copy of stack display
  {#0 #0}
				% this is the display made by the
				% compile program. I have not typed it
				% out in full.
  GROB 131 40 FFFFFDFFFF7FFFFFDFFFF7FFFFFDFFFF70
              FF3FFDFF8F7FF5FFDA3737FF1FFDF7BF70
              FFDFFDF7FF7FF5FFDABAA6FFDFFDF7DF70
              FFDFFDF79F7FF1FFD83327FF1FFDF7EF70
              etc.
  REPL				% put menu display over stack display
  {#0 #0}
  SWAP
  REPL				% put stack + menu in PICT
  {#0 #0} PVIEW			% display PICT
  0 WAIT			% wait for keystroke
  IF				% if in row 6 or greater, quit
    DUP 60 >
  THEN
    DROP
  ELSE				% otherwise, put hierarchical list
				% onto the stack.
    {				% start of main list
      {				% start of first row sub-list
        {'299792458_m/s'}	% first row, first key command sub-sub-list
        {'6.672E-11_N*m^2/kg^2'}% etc. First row is all constants.
        {'6.62618E-34_J*s'}
        {'1.054589E-34_J*s'}
        {'1.602189E-19_C'}
        {'1.38066E-23_J/K'}
      }				% end of first row sub-list
      {				% start of second row sub-list
        {'.000000056703_W/(m^2*K^4)'}
        {'1.672649E-27_kg'}	% all constants again
        {'9.010953E-31_kg'}
        {'1.989E30_kg'}
        {'695990000_m'}
        {'3.826E26_W'}
      }				% end of second row sub-list
      {				% start of third row sub-list
        { << '1_s' * >> << '1_s' CONVERT >> << '1_s' / >> }
				% a sub-sub-list of three programs for
				% the first key of the third row. These
				% execute the normal unit commands.
        { << '1_m' * >> << '1_m' CONVERT >> << '1_m' / >> }
				% all the third and remaining rows are
				% unit keys.
        { << '1_kg' * >> << '1_kg' CONVERT >> << '1_kg' / >> }
        { << '1_m/s' * >> << '1_m/s' CONVERT >> << '1_m/s' / >> }
        { << '1_J' * >> << '1_J' CONVERT >> << '1_J' / >> }
        { << '1_K' * >> << '1_K' CONVERT >> << '1_K' / >> }
      }				% end of third row sub-list
      {				% start of fourth row sub-list
        { << '1_yr' * >> << '1_yr' CONVERT >> << '1_yr' / >> }
        { << '1_cm' * >> << '1_cm' CONVERT >> << '1_cm' / >> }
        { << '1_g' * >> << '1_g' CONVERT >> << '1_g' / >> }
        { << '1_cm/s' * >> << '1_cm/s' CONVERT >> << '1_cm/s' / >> }
        { << '1_erg' * >> << '1_erg' CONVERT >> << '1_erg' / >> }
        { << '1_W' * >> << '1_W' CONVERT >> << '1_W' / >> }
      }				% end of fourth row sub-list
      {				% start of fifth row sub-list
				% contains only 5 items, as fifth row
				% has only 5 keys.
        { << '1_pc' * >> << '1_pc' CONVERT >> << '1_pc' / >> }
        { << '1_\angstm' * >> << '1_\angstm' CONVERT >> << '1_\angstm' / >> }
        { << '1_c' * >> << '1_c' CONVERT >> << '1_c' / >> }
        { << '1_eV' * >> << '1_eV' CONVERT >> << '1_eV' / >> }
        { << '1_b' * >> << '1_b' CONVERT >> << '1_b' / >> }
      }				% end of fifth row sub-list
    }				% end of main list
    OVER 10 / IP GET		% get key co-ords, extract tens digit,
				% and use this to get the correct row
				% sub-list
    OVER 10 / FP 10 * IP GET	% get the key co-ord, extract ones digit,
				% and use this to get the correct key
				% sub-sub-list form the row sub-list.
    SWAP FP 10 * GET		% get the tenths digit, and use it
				% to extract the correct item from the
				% key sub-sub-list
    EVAL			% execute/evaluate this item.
  END
>>

cloos@acsu.buffalo.edu (James H. Cloos) (12/04/90)

In order to use the catalog program that is in the EQ card, you need
to look at each of the XLIB's in lib#266, determine their argument
requirements, and then put together a short set of routines of the
form:
	::			(start a rpl routine)
	swith_on_?_args		(depending on how many the XLIB expects)
	ROMPTR 10A XXX		(XXX = the XLIB's command number, 10Ah=266d)
	;			(end a rpl routine)

and either STO them in global vars, or do that & then run a DIR of
those globals thru usrlib.  These routines would of course require
that the EQLIB cart was installed and that lib 266d was ATTACHed to a
DIR in the current PATH (it ATTACHs itself to HOMEDIR at each SYS_HALT).

It may be easier just to use one of the other catalog utils, such a
LBROWSE, BROWSE, or the ones that come in Jim Donnelly's Tool Library.

-JimC
--
James H. Cloos, Jr.		Phone:  +1 716 673-1250
cloos@ACSU.Buffalo.EDU		Snail:  PersonalZipCode:  14048-0772, USA
cloos@ub.UUCP			Quote:  <>