* BUPORT 1.0 2nov91 phk@data.fls.dk
* ==========
*
* Backup port to remote computer.
*
* ARGS:
*	real	-- Port number
*
* RETURNS:
*	<nothing>
*
* FUNCTION:
*	recals all items in the port, and for each one constructs a new name
*	stores the item in a LAM and uses SEND to transmit it to the remote
*	computer under the new name.  Builds a secondary to pull things back
*	into the calculator.
*
* COPYLEFT:
*	Feel free to use this any way you like, as long as you do give credit
*	where credit is due.
*
ASSEMBLE
    NIBASC /HPHP48-Z/

*
* UnDocumented entrypoints.  Picked up from disassembly of Rev.E Firmware:
*
RclPort		EQU	#21922
LibNbr		EQU	#081ee
LibName		EQU	#081d9
xSEND		EQU	#21ef0
xKGET		EQU	#21f24
xSTO		EQU	#20ccd
x>>O		EQU	#23639
x>>I		EQU	#235FE
x->		EQU	#234c1
xQU		EQU	#23654
xUNQU		EQU	#23679
xPURGE		EQU	#20EFE
xSF		EQU	#1C274

RPL
    ::
    CK1NOLASTWD
    CK&DISPATCH1
    real
	::
	THIRTYFIVE TestSysFlag SWAP
	THIRTYFIVE SetSysFlag
	COERCE
	DUP #>$ ".p_" SWAP&$ 1LAMBIND
	RclPort
	DUP ZERO 1GETABND
	ROT
	{ LAM guf NULLLAM NULLLAM } BIND
	' :: x<< % -36 xSF x-> LAM port x<< ; 
	SWAP
	ZERO_DO (DO)
	    ::
	    SWAP
	    DUP ' LAM guf STO
		::
		CK&DISPATCH1
		    #8f ( Library )
			::
			DUP
			LibName DROP ID>$
			SEVEN SEVEN SUB$ ":" EQUAL ITE
			    ::
			    LibName DROP ID>$
			    DUP " " ONE POS$ DUP#0= ITE
				DROP
				:: #1- ONE SWAP SUB$ ;
			    "l_" SWAP&$ ONE EIGHT SUB$ 2GETLAM &$
			    ;
			    ::
			    LibNbr DROP 
			    #2710 #+ #>$ TWO FIVE SUB$
			    "l_" SWAP&$ ONE EIGHT SUB$ 2GETLAM &$
			    ;
			;
		    #9f ( Backup )
			::
			LibName DROP ID>$
			"b_" SWAP&$ ONE EIGHT SUB$ 2GETLAM &$
			;
		;
	    DUP
	    ' LAM guf SWAP TWO {}N ONE{}N xSEND
	    ' ID tmpvar TWO {}N ONE{}N
	    ' xKGET 
	    ' ID tmpvar
	    ' LAM port
	    ' xSTO 
	    FIVE ::N &COMP
	    ;
	LOOP
	' :: x>>I xQU ID tmpvar xUNQU xPURGE x>>O ; &COMP
	' LAM guf STO
	{ LAM guf }
	THIRTYFIVE ClrSysFlag
	"restore" 2GETLAM &$ >TCOMP ONE{}N xSEND
	ABND
	DROP
	IT
	    :: THIRTYFIVE SetSysFlag ;
	;
    ;
