%%HP: T(3)A(D)F(.);
@ BACKALL by Darryl Okahata
DIR
  BACKUP
    \<< STD PATH 0 0 \-> p sz n
      \<< L
        IFERR CCHECK
        THEN p EVAL ERRM DOERR
        END CLLCD "CHECKING" 4 DISP 0 2
        FOR p p
          IFERR PVARS
          THEN DROP { } ""
          END
          IF TYPE 0 ==
          THEN OBJ\->
            IF DUP 0 >
            THEN DUP 'n' STO+ 1 SWAP
              START RCL BYTES SWAP DROP
                IF DUP sz >
                THEN 'sz' STO
                ELSE DROP
                END
              NEXT
            ELSE DROP
            END
          ELSE DROP
          END
        NEXT
        IF sz DUP MEM M + n S * + >
        THEN DROP p EVAL 1 DOERR
        END 'NEEDED' STO RCLF 'FLAGS' STO { } DUP DUP 'PV2' STO 'PV1'
         STO 'PV0' STO OPENIO 0 2
        FOR p p
          IFERR PVARS
          THEN DROP { } ""
          END
          IF TYPE 0 ==
          THEN OBJ\->
            IF DUP 0 >
            THEN 1 SWAP
              FOR i CLLCD "Port " p + C$ 3 : " + OVER + C$ 1 " + 4 DISP
                IF DUP OBJ\-> DROP TYPE 0 \=/
                THEN DUP \->STR
                ELSE p
                END "'PV" p + "'" + OBJ\-> STO+ RCL "'L" p + i + "'" + OBJ\->
                 SWAP OVER STO DUP SEND CLLCD "Wait ..." 4 DISP
                IF DUP VTYPE 15 ==
                THEN PGDIR
                ELSE PURGE
                END
              NEXT
            ELSE DROP
            END
          ELSE DROP
          END
        NEXT CLLCD "Archiving main mem ..." 4 DISP :IO: BACKUP ARCHIVE
         DONE p EVAL
      \>>
    \>>
  RECOVER
    \<< STD PATH \-> p
      \<< L
        IFERR CCHECK
        THEN p EVAL ERRM DOERR
        END
        IF NEEDED MEM >
        THEN p EVAL 1 DOERR
        END OPENIO 0 2
        FOR p "'PV" p + "'" + OBJ\-> RCL OBJ\->
          IF DUP 1 \>=
          THEN 1 SWAP
            FOR i CLLCD \-> n
              \<< "L" p + i + DUP KGET "'" DUP ROT + SWAP + OBJ\-> DUP RCL DUP
                IF n TYPE 0 ==
                THEN 0 p \->TAG STO
                ELSE n OBJ\-> STO
                END CLLCD "Wait ..." 4 DISP
                IF TYPE 15 ==
                THEN PGDIR
                ELSE PURGE
                END
              \>>
            NEXT
          ELSE DROP
          END
        NEXT FLAGS STOF DONE p EVAL
      \>>
    \>>
  M 300
  S 10
  L
    DIR
      FLAGS { # 3808000400100FF0h # 0h }
      PV0 { 0 0 }
      PV1 { }
      PV2 { }
      NEEDED 2955
      CCHECK
        \<<
          IF -40 FS?
          THEN -40 CF "Clock display disabled\010Retry operation" DOERR
          END
        \>>
      DONE
        \<< FINISH CLOSEIO CLLCD "DONE" 1 DISP 1 FREEZE
          IF -56 FC?
          THEN 1400 .1 BEEP
          END
        \>>
    END
END
