postpischil@alien.dec.com (Always mount a scratch monkey.) (03/25/88)
Dr. W. Mier-Jedrzejowicz mentioned the possibility of calendar routines for the HP-28, and I have implemented a simple clock/calendar. To set the clock, enter the full year (1988, not 88), month, day, and time and execute CS. The time is in the 24-hour format hh.mmss. To read the clock, just execute CLOCK. I have left some rough edges, like assuming the word size is set to something large enough. In particular, the ->HMS function sometimes returns 60 in the seconds or minutes positions. The total space occupied is less than 900 bytes. Credit for the formulas used for the date conversions goes to the PPC ROM User's Manual, specifically Roger Hill and Fernando Lopez-Lopez. However, I have modified them, so blame for errors is mine. -- edp (Eric Postpischil) "Always mount a scratch monkey." CLOCK << RCLF TIME CLLCD TC + DUP TPD / DUP TPD * ROT SWAP - B->R TT 1 DISP B->R JC 2 DISP STOF >> CS (Clock Set) << TIME -> t b << CJ TPD R->B * t HMS-> TPD * 24 / + b - 'TC' STO >> >> TT (Ticks to Time) << 4 FIX TPD / 24 * ->HMS ->STR >> CJ (Calendar to modified Julian day number) << ROT ROT 2.85 - 12 / + -> d y << 367 y * IP y IP - .75 y IP * - IP d + y .01 * IP .75 * - IP >> JC (modified Julian day number to Calendar) << JI IC >> JI (Julian to Internal) << 4.2 - DUP 36524.25 / IP .75 * CEIL + CEIL .2 365.25 AB .2 + CEIL .5 30.6 AB CEIL >> IC (Internal to Calendar) << STD -> y m d << d ->STR "." + y IF m 9 <= THEN m 3 + ELSE 1 + m 9 - END ->STR "." + SWAP ->STR + + >> >> AB << -> b << - DUP b / IP SWAP b MOD >> >> TIME << #123E SYSEVAL >> for version 1BB << #1266 SYSEVAL >> for version 1CC << #11CAh SYSEVAL >> for version 2BB TC (Time Correction) (no initial value needed) TPD (Ticks Per Day) 707788800