[comp.sys.handhelds] HP48sx program: overnight processing and backups

lishka@uwslh.slh.wisc.edu (Chris Lishka (a.k.a. Chri) ) (03/15/90)

After reading through the manuals, I wanted to try out the hp48sx programmable
alarm facility and ports.  One thing I wanted to do was save a backup copy of
the system in case I accidentally blow something away (or overwrite it).  This
was a perfect job for an overnight programmable alarm!  So I sat down and wrote
these programs as a general way to run overnight processing.

This set of programs sets up a job to run at 3:00am, when I am the least likely
to be programming on it.  The calculator "wakes up," performs a backup and
keypack, and then shuts off again.  The alarm is rescheduled automatically to
run the next night.  I thought others might like to use this technique to run
their own stuff, so I am posting these programs.

There are five programs included in this set.  The first three implement the
overnight processing functions:
    * SCHEDULE will set up the alarm.  It should only be run if no overnight
      processing is being done routinely.  I have not tested what happens if
      you try to schedule two or more alarms at the same time.
    * JOB contains the job to be run overnight.  This program is used to call
      other programs (which do the real processing), turn the machine off, and
      print a report (when the machine is turned on again) to let the user know
      the overnight processing ran.
    * REPORT prints a report stating when the overnight processing was run.

The other two programs perform specific functions in the overnight processing:
    * BACKUP creates an archive of all memory in the computer and stores it in
      PORT0.  Note that using a straight archive like this effectively reduces
      your usable memory by 50% (half for you to use, half for the archive).
      Since memory is not a big concern to me, I have kept this simple.  You
      will likely want to replace the archive with some smarter scheme that
      uses less memory (possibly something on the order of Bob Peraino's
      archive program for the hp28).  Also note that NO memory checking is done
      to see if enough exists for the new archive.  I leave this as an exercise
      for the reader.
    * KEYPACK reclaims memory used by old programmable (i.e. USER) key
      definitions.  The user's manual mentions that this should be done
      periodically, and early in the morning seems like the best time to do it.
      Note that this should be run before the BACKUP command to free useless
      memory before it is archived.

Only the JOB program takes an argument (the number returned by the alarm).
None of the programs return an values.  Accompanying each program name is the
checksum and byte-count as computed by the BYTES command.

I have all of this set up in one directory (path = {HOME root LIB NIGHT}).  You
will most likely have a different directory structure than mine, and therefore
you will need to edit the programs to match your system.  Also, make sure the
repeat interval is correct.  I have know idea what a super-short repeat
interval (i.e. less than one second) will do, nor do I really want to find out.

I hope you find this helpful.  I really like the programmable alarm feature,
which is much like the Unix CRON facility, except that it is much easier to
start hp48sx alarms than edit a crontab file!

					.oO Chris Oo.

Note: I don't yet have a serial cable, and my manuals are at home, so I have
*not* used the HP back-slash sequences for the non-ascii characters.  Here are
the substitutions I used:

    << = Program-begin
    >> = Program-end
    -> = Right-pointing-arrow


  # SCHEDULE sets an alarm to occur at 3am in the morning, with a reschedule/
  # repeat interval of one day.  The contents of the variable JOB (in the
  # current path) are used as the program to be executed.
SCHEDULE  [ #18746d, 74.5 ]

<<
  { }				# * Construct a list of arguments for STOALARM
  DATE 1 DATE+ +		# * Make sure it runs *tomorrow* morning.  This
				#   will need to be changed if you run it
				#   *before* midnight.
  3 +				# * Run the job at 3am.
  'JOB' RCL +			# * Store the program to be run.  I use the
				#   contents of variable JOB in the current
				#   directory.
  707788800 +			# * Repeat interval (1 day)
				#   = 8192ticks/sec * 60sec * 60min * 24hr
  STOALARM			# * Use the constructed list to set the alarm.
>> 'SCHEDULE' STO

  
  # JOB contains the program to be run every night.  It is only accessed by
  # SCHEDULE.  Note that schedule *could* just hand off the name 'JOB' to the
  # alarm, but giving the actual program (i.e. contents of JOB) is safer
  # because the alarm does not have to change to the directory where JOB is
  # located (although currently it does anyway in order to run the KEYPACK
  # and BACKUP programs).
JOB [ #34504d, 87 ]

<<
  DROP				# * Drop the value returned by the alarm.
  HOME root LIB NIGHT		# * Switch to the directory which contains the
				#   programs to run at night.  You will need
				#   need to change this to suit your system.
  KEYPACK			# * Run the program to free up USER memory.
  BACKUP			# * Run the nightly backup script.
  OFF				# * Put the hp48 back to sleep.
  REPORT			# * Print a report next time the calculator
				#   is turned on.
  HOME root			# * Change back to the "root" directory. Again,
				#   you will need to change this to your
				#   match the directories of your system.
>> 'JOB' STO


  # REPORT prints a message indicating that the overnight processing was run.
  # If it is run right after the OFF command (in JOB), the message will be
  # displayed the next the calculator is turned on.
REPORT  [ #55113d, 93 ]

<<
  CLLCD				# * Clear the screen.
  "Night processing:" 4 DISP	# * Display the message
  DATE TIME TSTR 5 DISP		# * Show the date and time the overnight
				#   processing ran.
  "Memory: " MEM ->STR +	# 
  6 DISP			# * Also display the remaining memory
  2 FREEZE			# * Keep the information around
>> 'REPORT' STO


  # BACKUP creates an archive of the current memory in a file in PORT0.  The
  # time the backup was created is also stored.  If you have extra RAM, you may
  # want to change this to save in a different port (swap :1: or :2: for :0:).
  # Also, if you don't want to save the entire memory contents, you can
  # substitute some other command sequence for the ARCHIVE command.
BACKUP  [ #52737d, 92 ]

<<
  :0:BACKUP PURGE		# * Remove the previous backup and the record
  :0:BTIME  PURGE		#   of when it was created.
  :0:BACKUP ARCHIVE		# * Create a new archive of the current memory
  DATE TIME TSTR		# * Grab the current date and time.
  :0:BTIME STO			# * Save the time that the backup was run for
				#   future reference.
>> 'BACKUP' STO


  # KEYPACK packs the programmable key definitions.  The user's manuals (in the
  # customization chapter, I believe) states that this should be done from time
  # to time to keep memory from chewed up with old key definitions.  The code
  # in this program is straight out of the user's manaul example.
KEYPACK  [ #64094d, 31.5 ]

<<
  RCLKEYS 0 DELKEYS STOKEYS	# * Straight from the user's manuals!
>> 'KEYPACK' STO
-- 
Christopher Lishka 608-262-4485  "Somebody said to me, `But the Beatles were
Wisconsin State Lab. of Hygiene  antimaterialistic.'  That's a huge myth.  John
   lishka@uwslh.slh.wisc.edu     and I literally used to sit down and say `Now,
   uunet!uwvax!uwslh!lishka      let's write a swimming pool'."--Paul McCartney

madler@tybalt.caltech.edu (Mark Adler) (03/15/90)

A quick note about ARCHIVE on the 48sx: it doesn't back up all of user
memory, like it says it does.  They forgot to back up the user and system
flags.  I was really ecstatic about archiving, wiping out memory, and
restoring everything from my PC, until I noticed the clock was missing.
I then had to go back through the list of system flags and remember what
I had set while reading through the tomes that come with the calculator.
(Like -2 for numeric pi, error beeps off, etc.)

I wrote a backup that saves the flags in a variable before the ARCHIVE.
I also have a small program that copies that variable into the flags,
that I have to remember to run after a RESTORE.

It is really neat to be able to nonchalantly clear the memory.  Especially
after having numerous, very annoying Memory Lost episodes with my 28S.

Mark Adler
madler@hamlet.caltech.edu