
                               BACKUP V1.0

                                   by

                                Pat Yagle
                          mailto:yagle@flash.net
                        mailto:Pat.J.Yagle@lmco.com

What this program does:
=======================

You've probably realized what a hassle it is to make a backup of the entire
contents of the calculator's memory.  ARCHIVE does the HOME directory, but
you're still left with the libraries and any other objects stored in memory
ports.  This program takes care of that.  I used Bob Apodaca's BKUP v4.6 as
the inspiration for this program.  I didn't use any of his code.  The only
thing I really borrowed was his naming convention for files sent to the PC.
This program doesn't do everything that BKUP does.  It wont backup the contents
of the stack or lastarg (it could have been done, but I don't need it).  It
doesn't give the option of using XMODEM (again, it could have been done, but
I didn't need it).  What it does do is fix the only shortcoming I found with
BKUP:  it doesn't properly handle port data files that have spaces in their
names (Scribe datafiles have spaces in their names).


DISCLAIMER:
===========

This program was written in User RPL.  So, it shouldn't cause any unusual
behavior on any caclulator.  It was written and tested on my HP48GX Rev. R.
It will probably work on S-series calculators.  I don't remember doing 
anything G-specific.  As always, use at your own risk.  I'm not responsible
for any "bad things" that happen as a result of using this program.


BACK:
=====

This program sends a backup of the HOME directory to the PC as well as all of 
the libraries and port data objects.  

The HOME backup is sent using the ARCHIVE command to a file called 'HPMMMDD.BAK'
where MMM = month and DD = day.  On March 10th, the file would be 'HPMAR10.BAK' 
for example.  

The libraries are sent as individual files named 'LXXX.P' where XXX = library 
number and P = port number.  DM's Tetris library on port 0 would be sent as 
'L769.0' for example.  

Other port objects are sent to a file of the form 'OBJNAME.P' where OBJNAME is 
the actual name of the port object and P is the port number as before.  If 
OBJNAME is longer than 8 characters it is truncated, and all spaces are changed
to the character "X".  Before sending the ARCHIVE of the HOME directory the 
program creates three variables in the Backup program's directory:  

        FLAGS:       A copy of the calculators system and user flags at the 
                     time of the backup.  These are saved so they can be 
                     restored along with the backup.  

        HPXXXDD.BAK: A list of all of the libraries/port objects sent to the PC.
                     This is used to tell the REST program which files to get 
                     from the PC.  

        EXTRA:       A list of all port objects on write protected or ROM cards.
                     The EXTRA variable is there because I don't always need to
                     backup the contents of my RAM card (I don't change it 
                     much).  The contents of write protected cards are NOT 
                     backed up.  The main reason for this is that User RPL wont
                     Allow the contents of port object to be recalled from a
                     write protected card (or ROM card application).  If you 
                     have a card, you'll have to switch it to read/write to 
                     back it up.  REST attempts to restore the port objects
                     listed in EXTRA was well as those in HPXXXDD.BAK.  If, 
                     when restoring from the backup, the contents of a card 
                     have not been lost, you'll need to remove from EXTRA the
                     names of the objects which do not need to be restored 
                     from the PC.

After the archive is sent, the three files described above are deleted so that 
they don't get in the way when the next backup is performed.

To use the program, simply press its softkey.  It requires no inputs.  You will
be prompted to start the SERVER mode on the PC-Kermit.  Server mode allows the
HP to control file transfer in both directions.  Before you press a key to
continue, you need to make sure the cable is hooked up, and all settings for
transfer are correct (the program will set BINARY transfer, so don't worry
about that).  Then type the SERVER command on the PC.  The calculator will 
then transfer all libraries/port objects and then the HOME backup.

REST:
=====

This program retreives all of the libraries port objects that were installed
at the time the backup was made.

To restore the contents of the calculator, first transfer the appropriate
'HPMMMDD.BAK' file to the calculate and use the built-in RESTORE command
to restore the HOME directory.  Then goto the Backup directory (whatever
you've called it).  You shoud see the three extra variables I described 
above.  The REST program takes a single input from the stack, the name
of the HPMMMDD.BAK variable, NOT its contents.  To get the name on the
stack, press the ['] key, the softkey for the HPMMMDD.BAK, then [ENTER].
Then press the softkey for REST.  You will be prompted to start the
SERVER on the PC again.  Do so, and hit any key (NOT the [ON] key!) to
continue.  The calculator will then retrieve all of the libraries/port
objects that were sent to the PC.  At the end, you'll see a message telling
you to warmstart the calculator.  You can just turn it off and then on instead
if you prefer.

PORTS:
======

This contains a list of the ports to backup.  You'll need to change this so
it contains { 0 } if you only have a G (or S) or a GX (SX) with no cards 
installed.

That's it for the use of the program, but I'll describe what the rest of the
variables in the directory do:

FNAME:  
======

Used by BACK and REST.  Takes a tagged object name from the stack and returns
an appropriate variable name for transfer to the PC.  For example, if the input
is:

        :0: 769      Note: The left colon is not seen on the stack; only in EDIT

The output would be:

        'L769.0'

ANAME:
======

Used by BACK.  Returns a name in the form 'HPMMMDD.BAK' based on the current 
date.

SPACEX:
=======

Used by FNAME.  Takes a string from the stack and replaces all spaces with 
the letter X.

UCASE:
======

Used by FNAME.  Takes a string from the stack and converts it to upper case.
Non letters are left unchanged.

That's it!  If you've got any question about this program let me know!

------------------------------- 8< ---------------------------------------------
%%HP: T(3)A(D)F(.);
DIR
  BACK
    \<< 
      CLLCD
"  Beginning Backup!

Execute SERVER Command
   On Remote Kermit

Press a key to proceed"
      1 DISP 0 WAIT DROP CLLCD
"  Performing Backup"
      4 DISP 2 FREEZE RCLF -35 SF ANAME PORTS \-> b p
      \<< 
        { } b STO { } 'EXTRA' STO RCLF 'FLAGS' STO p SIZE DUP
        IF 0 > THEN 
          1 SWAP FOR j 
            p j GET PVARS TYPE
            IF 0 == THEN 
              b RCL + b STO
            ELSE
              EXTRA + 'EXTRA' STO
            END
          NEXT 
          b RCL OBJ\-> 1 SWAP
          START 
            DUP FNAME SWAP DUP RCL
            DUP TYPE 16 ==
            \<< SWAP DROP \>>
            \<< 2 \->LIST \>> 
            IFTE
            OVER STO DUP SEND PURGE
          NEXT
        ELSE 
          DROP
        END 
        b 'IO' \->TAG ARCHIVE FINISH b 'EXTRA' 'FLAGS' 3 \->LIST PURGE
      \>> 
      STOF CLLCD
"  Backup Complete!"
      4 DISP 2 FREEZE
    \>>
  REST
    \<< 
      CLLCD
"  Beginning Restore!

Execute SERVER Command
   On Remote Kermit

Press a key to proceed"
      1 DISP 0 WAIT DROP CLLCD
"  Performing Restore"
      4 DISP 2 FREEZE \-> b
      \<< 
        FLAGS DUP STOF -35 SF b RCL EXTRA + OBJ\-> DUP
        IF 0 > THEN 
          1 SWAP
          START 
            DUP FNAME DUP DUP KGET RCL ROT OBJ\-> OBJ\-> SWAP DROP SWAP 
            DUP TYPE 16 ==
            \<< SWAP STO \>>
            \<< OBJ\-> DROP SWAP STO DROP \>> 
            IFTE
            PURGE
          NEXT
        ELSE 
          DROP
        END 
        FINISH b 'EXTRA' 'FLAGS' 3 \->LIST PURGE STOF
      \>> 
      CLLCD
"  Restore Complete!

 Perform a Warmstart
  (ON-C) to attach
      Libraries"
      2 DISP 7 FREEZE
    \>>
  PORTS 
    { 0 1 }
  FNAME
    \<< 
      STD OBJ\-> SWAP DUP TYPE
      CASE 
        DUP 0 == THEN 
          DROP \->STR "." + "L" SWAP +
        END 
        DUP 6 == THEN 
          DROP "" + SPACEX 1 8 SUB "." +
        END
      END 
      SWAP + UCASE OBJ\->
    \>>
  ANAME
    \<< 
      RCLF STD "HP" "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
      DATE IP 1 - 3 * 1 + DUP 2 + SUB + DATE FP 100 * IP \->STR
      DUP SIZE 1 - NOT
      \<< "0" SWAP + \>> 
      IFT 
      + ".BAK" + OBJ\-> SWAP STOF
    \>>
  SPACEX
    \<<
      WHILE DUP " " POS DUP REPEAT "X" REPL END DROP
    \>>
  UCASE
    \<< 
      "" 1 3 PICK SIZE
      FOR x 
        OVER x DUP SUB DUP "a" \>= SWAP "z" \<= AND 32 * CHR +
      NEXT 
      XOR
    \>>
END
------------------------------- 8< ---------------------------------------------
