From: jrlatala@shell.golden.net (john R. Latala)
Newsgroups: comp.sys.hp48
Subject: update: formatted display of top of the stack using vectored enter
Date: 5 Sep 1998 11:11:28 GMT
Organization: Golden Triangle Online
Lines: 376
Message-ID: <6sr690$c9v$1@cougar.golden.net>
NNTP-Posting-Host: 199.166.210.4
X-Newsreader: TIN [version 1.2 PL2]
Xref: republic.btigate.com comp.sys.hp48:15526

    Somebody pointed out to me that the FEET display mode gets a little
confused when it's given a negative number.  The way the MOD operator was
used during the calculation would force the number to be converted to it's
positive equivalent.

    I had to restructure the code slightly but it looks like this version is
behaving itself.

    Again ...  if anybody else has comments, improvements or bugs please let
me know!  Thnx.

    Below is the new version with the corrected FEET code.

------------------------------------------------------------------------

    The following custom menu uses vectored enter to redefine how the top
item of the stack is displayed.  If the top item on the stack is a real
number it can be displayed in one of six special formats:

    Format          Description
    ------          -----------
    COMMA           Normal comma seperated triplets
    DMS             Degrees/minutes/seconds
    DOLLAR          Normal comma seperated triplets with a dollar sign
                    and rounded to two decimal places
    ENG             Scientific notation with powers as multiples of three
    FEET            feet/inches/fraction
    HMST            Hours/minutes/seconds/ticks

    Examples of the formats are:
    
    Label           Top of Stack            Display
    -----           ------------            -------
    COMMA           1234.5678               1,234.5678
    DMS             123.45678               123o45'67" (o=deg char)
    DOLLAR          1234.5678               $1,234.57
    ENG             1234.5678               1.2345678E3
    FEET            1234.5678               1234' 6" 13/16
    HMST            12.345678               12:34:56.78

    Only the DMS and HMST formats limit the range of the number.  The number
will be displayed in DMS or HMST only if it's in the range -999 ...  999.
This was an arbitrary choice on my part because numbers out of that range are
a bit of a hassle to fit in the display properly.

    Left shifting any of the keys cancels the special format so the HP48 uses
it's builtin stack display code.  All of the cancel programs are the same so
you can use any one of them.

    The code is based on a routine posted by Joe Horn that would allow input
in feet/inches/fractions.  I had code to convert a real number to a string
with commas and the two of them sort of got smushed together!  When I saw
that it was good I added the other formats.

    You can download it into it's own directory and store it in a variable
called CST.  You then change to that directory hit the CST key and press a
menu key and you're off and running.

    You can turn the display mode on/off by turning the USER mode keyboard
on/off.  To turn the mode off and cleanup you return to the directory that
has the custom menu, press CST and then use any of the left shifted menu
keys.

    If you want it as a standalone program you could wrap it up in something
like:

        \<< {...} TMENU \>>

    where the {...} is replaced by the custom menu.  By sticking this program
in your HOME directory you'll be able to access it from anywhere.

    While the program is running it puts a variable '\GbENTER' in your HOME
directory.  When you cancel the display mode the variable is removed.

%%HP: T(3)A(D)F(.);
{
  {
    "COMMA"
    {
      \<<
        PATH
        \<<
          DROP
          IF DEPTH 0 > THEN
            IF DUP TYPE 0 == THEN
              # 39C1Bh SYSEVAL
              DUP
              IF DUP 0 == THEN
                DROP "0"
              ELSE
                DUP ABS SWAP DUP SIGN SWAP XPON
                \-> n s e
                \<<
                  IF e 0 < e 11 > OR THEN
                    n s * \->STR
                  ELSE
                    s -1 == "-" "" IFTE n IP \->STR "" SWAP
                    WHILE DUP "" \=/ REPEAT
                      SWAP
                      IF DUP "" \=/ THEN
                        "," SWAP +
                      END
                      OVER DUP SIZE DUP 2 - SWAP SUB SWAP + SWAP 1 OVER
                      SIZE 3 - SUB
                    END
                    DROP +
                    IF n FP 0 \=/ THEN
                      n FP \->STR +
                    END
                  END
                \>>
              END
              "1:                    " OVER SIZE 22 SWAP - 1 SWAP SUB SWAP +
              # 123E5h SYSEVAL # 3915Dh SYSEVAL
            END
          END
        \>>
        HOME '\GbENTER' STO EVAL
        -62 SF -63 SF
      \>>
      \<< PATH HOME '\GbENTER' PURGE EVAL -62 CF -63 CF \>>
    }
  }
  {
    "DMS"
    {
      \<<
        PATH
        \<<
          DROP
          IF DEPTH 0 > THEN
            IF DUP TYPE 0 == THEN
              # 39C1Bh SYSEVAL DUP
              RCLF
              \-> n f
              \<<
                -55 CF
                IF n ABS 10000 * IP 0 == THEN
                  C$ 9 00\^o00'00"
                ELSE
                  IF n ABS LOG 3 > THEN
                    n \->STR
                  ELSE
                    n SIGN
                    n ABS IP
                    LASTARG FP 100 * IP
                    LASTARG FP 100 * IP
                    \<<
                      DUP 0 < "-" "" IFTE SWAP ABS IP
                      DUP 10 < "0" "" IFTE SWAP \->STR + +
                    \>>
                    \-> s dd mm ss fmt99
                    \<<
                      s -1 == "-" "" IFTE
                      dd fmt99 EVAL + "\^o" +
                      mm fmt99 EVAL + "'" +
                      ss fmt99 EVAL + C$ 1 " +
                    \>>
                  END
                END
                f STOF
              \>>
              "1:                    " OVER SIZE 22 SWAP - 1 SWAP SUB SWAP +
              # 123E5h SYSEVAL # 3915Dh SYSEVAL
            END
          END
        \>>
        HOME '\GbENTER' STO EVAL -62 SF -63 SF
      \>>
      \<< PATH HOME '\GbENTER' PURGE EVAL -62 CF -63 CF \>>
    }
  }
  {
    "DOLLAR"
    {
      \<<
        PATH
        \<<
          DROP
          IF DEPTH 0 > THEN
            IF DUP TYPE 0 == THEN
              # 39C1Bh SYSEVAL DUP 2 RND
              IF DUP 0 == THEN
                DROP "0"
              ELSE
                DUP ABS SWAP DUP SIGN SWAP XPON
                \-> n s e
                \<<
                  IF e 0 < e 11 > OR THEN
                    n s * \->STR
                  ELSE
                    s -1 == "-" "" IFTE
                    n IP \->STR "" SWAP
                    WHILE DUP "" \=/ REPEAT
                      SWAP
                      IF DUP "" \=/ THEN
                        "," SWAP +
                      END
                      OVER DUP SIZE DUP 2 - SWAP SUB SWAP + SWAP 1 OVER
                      SIZE 3 - SUB
                    END
                    DROP +
                    IF n FP 0 \=/ THEN
                      n FP \->STR +
                    END
                  END
                \>>
              END
              IF DUP "E" POS 0 == THEN
                DUP "." POS
                \-> p
                \<<
                  IF p 0 == THEN
                    ".00" +
                  ELSE
                    "00" + 1 OVER "." POS 2 + SUB
                  END
                \>>
              END
              "$" SWAP +
              "1:                    " OVER SIZE 22 SWAP - 1 SWAP SUB SWAP +
              # 123E5h SYSEVAL # 3915Dh SYSEVAL
            END
          END
        \>>
        HOME '\GbENTER' STO EVAL -62 SF -63 SF
      \>>
      \<< PATH HOME '\GbENTER' PURGE EVAL -62 CF -63 CF \>>
    }
  }
  {
    "ENG"
    {
      \<<
        PATH
        \<<
          DROP
          IF DEPTH 0 > THEN
            IF DUP TYPE 0 == THEN
              # 39C1Bh SYSEVAL DUP
              IF DUP 0 == THEN
                DROP "0"
              ELSE
                DUP ABS SWAP DUP SIGN SWAP DUP XPON SWAP MANT
                \-> n s e m
                \<<
                  e 3 MOD
                  \-> n
                  \<<
                    e n - 'e' STO
                    m n ALOG * 'm' STO
                  \>>
                  s -1 == "-" "" IFTE m \->STR +
                  IF e 0 \=/ THEN
                    "E" + e \->STR +
                  END
                \>>
              END
              "1:                    " OVER SIZE 22 SWAP - 1 SWAP SUB SWAP +
              # 123E5h SYSEVAL # 3915Dh SYSEVAL
            END
          END
        \>>
        HOME '\GbENTER' STO EVAL -62 SF -63 SF
      \>>
      \<< PATH HOME '\GbENTER' PURGE EVAL -62 CF -63 CF \>>
    }
  }
  {
    "FEET"
    {
      \<<
        PATH
        \<<
          DROP
          IF DEPTH 0 > THEN
            IF DUP TYPE 0 == THEN
              # 39C1Bh SYSEVAL DUP RCLF
              \-> f
              \<<
                STD
                -55 CF
                DUP SIGN 
                SWAP ABS 768 * 0 RND 
                64 MOD 
                LASTARG / IP 12 MOD
                LASTARG / IP 
                \-> s fr inn ft
                \<<
                  s -1 == "-" "" IFTE
                  ft + "' " +
                  in + C$ 1 " +
                  IF fr 0 \=/ THEN
                    " " + fr 64
                    \-> U V
                    \<<
                      WHILE V 0 \=/ REPEAT
                        u v MOD v 'u' STO 'v' STO
                      END
                      u
                    \>>
                    \-> gcd
                    \<<
                      fr gcd / \->STR + "/" +
                      64 gcd / \->STR + 
                    \>>
                  END
                \>>
                f STOF
              \>>
              "1:                    " OVER SIZE 22 SWAP - 1 SWAP SUB SWAP +
              # 123E5h SYSEVAL # 3915Dh SYSEVAL
            END
          END
        \>>
        HOME '\GbENTER' STO EVAL -62 SF -63 SF
      \>>
      \<< PATH HOME '\GbENTER' PURGE EVAL -62 CF -63 CF \>>
    }
  }
  {
    "HMST"
    {
      \<<
        PATH
        \<<
          DROP
          IF DEPTH 0 > THEN
            IF DUP TYPE 0 == THEN
              # 39C1Bh SYSEVAL
              DUP RCLF
              \-> n f
              \<<
                -55 CF
                IF n ABS 1000000 * IP 0 == THEN
                  "00:00:00.00"
                ELSE
                  IF n ABS LOG 3 > THEN
                    n \->STR
                  ELSE
                    n SIGN
                    n ABS IP
                    LASTARG FP 100 * IP
                    LASTARG FP 100 * IP
                    LASTARG FP 100 *
                    \<<
                      DUP 0 < "-" "" IFTE SWAP ABS IP
                      DUP 10 < "0" "" IFTE SWAP \->STR + +
                    \>>
                    \-> s hh mm ss tt fmt99
                    \<<
                      s -1 == "-" "" IFTE
                      hh fmt99 EVAL + ":" +
                      mm fmt99 EVAL + ":" +
                      ss fmt99 EVAL + "." +
                      tt fmt99 EVAL +
                    \>>
                  END
                END
                f STOF
              \>>
              "1:                    " OVER SIZE 22 SWAP - 1 SWAP SUB SWAP +
              # 123E5h SYSEVAL # 3915Dh SYSEVAL
            END
          END
        \>>
        HOME '\GbENTER' STO EVAL -62 SF -63 SF
      \>>
      \<< PATH HOME '\GbENTER' PURGE EVAL -62 CF -63 CF \>>
    }
  }
}

--
john R. Latala
jrlatala@golden.net