LEX 'HMSLEX' Hour-minute-second conversions (HP71) * LEX ID 94, tokens 3-4 * Tapani Tarvainen 85/07/25 * * Function HMS converts decimal hours to * hours-minutes-seconds (hh.mmssttt), HR vice versa * HR does not give error for an input like 0.9999, but * interprets it as 99 min 99 s * ID #5E 94 dec MSG 0 POLL POLLH ARGPR+ EQU #0E8EB Read modes, pop & norm real OUTRES EQU #0BC84 15-f to 12-f & return INFR15 EQU #0C73D Integer/fraction split FINITA EQU #0CD03 Finiteness test fSEC EQU 3 Flag used as counter in HR ENTRY HMS CHAR #F ENTRY HR CHAR #F KEY 'HMS' TOKEN 3 KEY 'HR' TOKEN 4 ENDTXT * Poll handler for VER$ POLLH ?B=0 B pVER$? GOYES VER$ RTNSXM VER$ C=R3 stk pt D1=C D1=D1- 12 2*#chars CD1EX A=R2 AVMEMS ?C5 (e.g. 0.09) * (also possible for abnormal inputs like 1.7) GONC HR2 B.E.T. * division loop; see DV15-2 (DIV120-) in IDS 3 HR1 A=A+1 P incr quotient digit HR2 C=C-D W dividend-divisor; borrow? GONC HR1 no, repeat C=C+D W yes, restore dividend CSL W dividend left for next decade P=P-1 pt to next digit. Done? GONC HR2 no B=B+A W add result to ip * might've built quotient to B directly - only * cases like 9.9 would give incomprehensible results (0.5!) * now all cases are interpreted reasonably (.9=90min, etc) ?C=0 W remainder? GOYES HR3 none D=D+1 A nonzero, set SB DSR A HR3 A=R0 restore exp ?B=0 S 16-digit mantissa? GOYES HRNORM no A=A+1 A yes, normalize BSR W if this sets SB, result IS inexact R0=A HRNORM ?ST=0 fSEC minutes left? GOYES outrC no, we're done ST=0 fSEC GONC HR0 (BET) 2nd round: minutes END