# File: downlink.src
#
program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "downlink.ips"
descr "downlink - DLs a single DP in p8 or pp 12-13"
#
# DSBQUE                ; Disable Queue
tcblock mbipldin 0x0154 
#
#=======================================================
#
#
#;
#; FILE:    downlink.ips
#; PURPOSE: To dowlink a single data product in page 8 or two prod
#;	   When on the redundant side, use pages 12 and 13.
#; METHOD:  
#;	Input:	$IPRL_DL_PARAM		- high word of page to downlink
#;		$IPRL_DL_PARAM+1	- OPTIONAL high word of second page to downli
#; HISTORY: Written 25-Aug-95 by M.Morrison
#;	   30-Aug-95 (MDM) - Changed the name and allowed either of the
#;			     two pages to be downlinked 
#;	    7-Sep-95 (MDM) - Changes to make it work
#;	   18-Sep-95 (MDM) - More changes to get it to work
#;	   18-Oct-95 (MDM) - Moved how 550 word math is done
#;			   - Called subroutine to check if the previous downlink is f
#;			     and to abort it if it is not finished
#;			   - Fixed up how HRDINIT work is done (in other routines)
#;	   26-Oct-95 (MDM) - Corrected error where I was looking at R30
#;			     instead of R3075 (DEP Reg 3) to see if VC mode was activ
#;
#QSR_DL_1PAGE::
#    SETREG $IPRL_DL_NPAGE 1
tcblock mbipcmd 0x0091 0x1320   0x0140 0x113D 0x0001 
#    GOTO &COMMON_CODE
tcblock mbipcmd 0x0091 0x1323   0x0156 0x132A 
#
#QSR_DL_2PAGE::
#    SETREG $IPRL_DL_NPAGE 2
tcblock mbipcmd 0x0091 0x1325   0x0140 0x113D 0x0002 
#    GOTO &COMMON_CODE
tcblock mbipcmd 0x0091 0x1328   0x0156 0x132A 
#
#COMMON_CODE:
#    SETREG   $IPRL_DL_CHECKED 0				;Initialized the "waited alrea
tcblock mbipcmd 0x0091 0x132A   0x0140 0x1151 0x0000 
#
#    GETQADR  $IPRL_DEBUG_ADDR
tcblock mbipcmd 0x0091 0x132D   0x015C 0x1FFD 
#    CALLQUE  $QSR_DUMP_IPREG                        
tcblock mbipcmd 0x0091 0x132F   0x01F8 0x1028 
#
#    BRANCHIF  R3075  &DONE				;if no VC = 0 then don't bother
tcblock mbipcmd 0x0091 0x1331   0x015A 0x0C03 0x142D 
#    ;NEEDED??        AVGTEMPS  0:0x00134 12
#
#
#    SETREGS $IPRL_DL_DLPAGE_LST 2 0x4000 0x4800		;pages 8 and 9 a
tcblock mbipcmd 0x0091 0x1334   0x01B2 0x113E 0x0002 0x4000 \
                                0x4800 
#    BRANCHEQ  R33    0   &USE_PRIMARY_LST
tcblock mbipcmd 0x0091 0x1339   0x01AE 0x0021 0x0000 0x1342 
#    SETREGS $IPRL_DL_DLPAGE_LST 2 0x6000 0x6800		;pages 12 and 13
tcblock mbipcmd 0x0091 0x133D   0x01B2 0x113E 0x0002 0x6000 \
                                0x6800 
#USE_PRIMARY_LST:
#
#    COPYREG $IPRL_DL_DLPAGE_LST   $IPRL_TLM_PAGE
tcblock mbipcmd 0x0091 0x1342   0x0142 0x113E 0x1FFB 
#    CALLQUE $QSR_TLM_RESET				;check to see if there is something
tcblock mbipcmd 0x0091 0x1345   0x01F8 0x12BD 
#    COPYREG $IPRL_DL_DLPAGE_LST+1 $IPRL_TLM_PAGE	;abort if necess
tcblock mbipcmd 0x0091 0x1347   0x0142 0x113F 0x1FFB 
#    CALLQUE $QSR_TLM_RESET
tcblock mbipcmd 0x0091 0x134A   0x01F8 0x12BD 
#
#    SETREG  $IPRL_DL_LOOP 0				;first loop through
tcblock mbipcmd 0x0091 0x134C   0x0140 0x113C 0x0000 
#    COPYREG $IPRL_DL_DLPAGE_LST $IPRL_DL_DLPAGE		;one downlink pa
tcblock mbipcmd 0x0091 0x134F   0x0142 0x113E 0x1140 
#    COPYREG $IPRL_DL_PARAM $IPRL_DL_INPAGE		;copy the input sourc
tcblock mbipcmd 0x0091 0x1352   0x0142 0x113A 0x1141 
#    SETREG  $IPRP_DL_NWORDS_PNTR $IPRL_DL_NWORDS	;where to save t
tcblock mbipcmd 0x0091 0x1355   0x0140 0x1142 0x1143 
#
#    GETQADR  $IPRL_DEBUG_ADDR
tcblock mbipcmd 0x0091 0x1358   0x015C 0x1FFD 
#    CALLQUE  $QSR_DUMP_IPREG                        
tcblock mbipcmd 0x0091 0x135A   0x01F8 0x1028 
#
#LOOP_CODE:
#    ;-------- decode the source page info
#    COPYREG  $IPRL_DL_INPAGE  $IPRL_HDECODE_PARAM  ;copy the sour
tcblock mbipcmd 0x0091 0x135C   0x0142 0x1141 0x10C8 
#    SETREG   $IPRL_HDECODE_PARAM+1 0x0000               ;there is
tcblock mbipcmd 0x0091 0x135F   0x0140 0x10C9 0x0000 
#							;CAUTION: HDECODE copies the source params into the destin
#    GETQADR  $IPRL_DEBUG_ADDR
tcblock mbipcmd 0x0091 0x1362   0x015C 0x1FFD 
#    CALLQUE  $QSR_DUMP_IPREG                        
tcblock mbipcmd 0x0091 0x1364   0x01F8 0x1028 
#
#    CALLQUE  $QSR_DO_HDECODE                            ;decode t
tcblock mbipcmd 0x0091 0x1366   0x01F8 0x1068 
#
#    COPYRI2D $IPRP_HDECODE_ADDR $IPRL_HEAD_WORK 10	;copy the regi
tcblock mbipcmd 0x0091 0x1368   0x01AC 0x10CC 0x10CF 0x000A 
#
#    ;------- Copy the data to the downlink page (if necessary)
#
#    COPYRD2D $IPRL_HEAD_WORK $IPRL_DL_COPY 3		;copy the source pa
tcblock mbipcmd 0x0091 0x136C   0x0144 0x10CF 0x114A 0x0003 
#    ;;ADDADR   $IPRL_DL_COPY $IPRL_NEG_550W $IPRL_DL_COPY  ;shift
#    REGADD   $IPRL_DL_COPY $IPRL_NEG_550W $IPRL_DL_COPY    ;shift
tcblock mbipcmd 0x0091 0x1370   0x0146 0x114A 0x10E1 0x114A 
#    SETREG   $IPRL_DL_COPY+2 0				;set the destination low word t
tcblock mbipcmd 0x0091 0x1374   0x0140 0x114C 0x0000 
#    COPYREG  $IPRL_DL_DLPAGE $IPRL_DL_COPY+3 		;copy the high wor
tcblock mbipcmd 0x0091 0x1377   0x0142 0x1140 0x114D 
#    COPYRD2D $IPRL_HEAD_WORK+8 $IPRL_DL_COPY+4 3	;copy the number
tcblock mbipcmd 0x0091 0x137A   0x0144 0x10D7 0x114E 0x0003 
#    COPYRD2I $IPRL_DL_COPY+4  $IPRP_DL_NWORDS_PNTR 3	;copy how ma
tcblock mbipcmd 0x0091 0x137E   0x01AA 0x114E 0x1142 0x0003 
#    ADDADR   $IPRL_DL_COPY+4  $IPRL_POS_550W $IPRL_DL_COPY+4     
tcblock mbipcmd 0x0091 0x1382   0x0148 0x114E 0x10DF 0x114E 
#
#
#    ;------- Check to see if a copy is even needed
#    REGSUB   $IPRL_HEAD_WORK+1 $IPRL_DL_DLPAGE $IPRL_DL_TEMP	;com
tcblock mbipcmd 0x0091 0x1386   0x2146 0x10D0 0x1140 0x1149 
#    BRANCHEQ $IPRL_DL_TEMP 0 &NO_COPY_NEEDED		;if data is already
tcblock mbipcmd 0x0091 0x138A   0x01AE 0x1149 0x0000 0x1394 
#
#    GETQADR  $IPRL_DEBUG_ADDR
tcblock mbipcmd 0x0091 0x138E   0x015C 0x1FFD 
#    CALLQUE  $QSR_DUMP_IPREG                        
tcblock mbipcmd 0x0091 0x1390   0x01F8 0x1028 
#
#    _MOVBLKI $IPRL_DL_COPY				;move the data to the page
tcblock mbipcmd 0x0091 0x1392   0x8166 0x114A 
#
#NO_COPY_NEEDED:
#    BRANCHEQ $IPRL_DL_NPAGE 1 &DL1PAGE
tcblock mbipcmd 0x0091 0x1394   0x01AE 0x113D 0x0001 0x13E0 
#
#    COPYREG  $IPRL_DL_DLPAGE_LST+1 $IPRL_DL_DLPAGE	;one downlink 
tcblock mbipcmd 0x0091 0x1398   0x0142 0x113F 0x1140 
#    COPYREG  $IPRL_DL_PARAM+1 $IPRL_DL_INPAGE		;copy the input so
tcblock mbipcmd 0x0091 0x139B   0x0142 0x113B 0x1141 
#    SETREG   $IPRP_DL_NWORDS_PNTR $IPRL_DL_NWORDS+3	;where to sav
tcblock mbipcmd 0x0091 0x139E   0x0140 0x1142 0x1146 
#
#    ADDREGD  $IPRL_DL_LOOP 1				;increment the loop counter
tcblock mbipcmd 0x0091 0x13A1   0x01BC 0x113C 0x0001 
#    BRANCHEQ $IPRL_DL_LOOP 1 &LOOP_CODE			;do the copy portion of
tcblock mbipcmd 0x0091 0x13A4   0x01AE 0x113C 0x0001 0x135C 
#
#
#    ;------------ Two page downlink command 
#DL2PAGE:
#    GETQADR  $IPRL_DEBUG_ADDR
tcblock mbipcmd 0x0091 0x13A8   0x015C 0x1FFD 
#    CALLQUE  $QSR_DUMP_IPREG                        
tcblock mbipcmd 0x0091 0x13AA   0x01F8 0x1028 
#
#    BRANCHEQ  $IPRL_HEAD_WORK+3 0 &DL2_RAW
tcblock mbipcmd 0x0091 0x13AC   0x01AE 0x10D2 0x0000 0x13C8 
#
#DL2_COMP:					;--------------- Downlink 2 Pages in COMPRESSED mod
#    BRANCHEQ  R33    0   &DL2_COMP_PRIM
tcblock mbipcmd 0x0091 0x13B0   0x01AE 0x0021 0x0000 0x13BE 
#
#DL2_COMP_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x13B4   0x015C 0x1152 
#    START2HR 0x49 0x6000 0x6800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipcmd 0x0091 0x13B6   0x019A 0x0049 0x6000 0x6800 \
                                0x1143 0x1146 
#    GOTO &DONE
tcblock mbipcmd 0x0091 0x13BC   0x0156 0x142D 
#
#DL2_COMP_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x13BE   0x015C 0x1152 
#    START2HR 0x49 0x4000 0x4800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipcmd 0x0091 0x13C0   0x019A 0x0049 0x4000 0x4800 \
                                0x1143 0x1146 
#    GOTO &DONE
tcblock mbipcmd 0x0091 0x13C6   0x0156 0x142D 
#
#DL2_RAW:					;--------------- Downlink 2 Pages in RAW mode
#    BRANCHEQ  R33    0   &DL2_RAW_PRIM
tcblock mbipcmd 0x0091 0x13C8   0x01AE 0x0021 0x0000 0x13D6 
#
#DL2_RAW_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x13CC   0x015C 0x1152 
#    START2HR 0x4b 0x6000 0x6800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipcmd 0x0091 0x13CE   0x019A 0x004B 0x6000 0x6800 \
                                0x1143 0x1146 
#    GOTO &DONE
tcblock mbipcmd 0x0091 0x13D4   0x0156 0x142D 
#
#DL2_RAW_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x13D6   0x015C 0x1152 
#    START2HR 0x4b 0x4000 0x4800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipcmd 0x0091 0x13D8   0x019A 0x004B 0x4000 0x4800 \
                                0x1143 0x1146 
#    GOTO &DONE
tcblock mbipcmd 0x0091 0x13DE   0x0156 0x142D 
#
#    ;------------ One page downlink command section
#DL1PAGE:
#    GETQADR  $IPRL_DEBUG_ADDR
tcblock mbipcmd 0x0091 0x13E0   0x015C 0x1FFD 
#    CALLQUE  $QSR_DUMP_IPREG                        
tcblock mbipcmd 0x0091 0x13E2   0x01F8 0x1028 
#
#    BRANCHEQ  $IPRL_HEAD_WORK+3 0 &DL1_RAW
tcblock mbipcmd 0x0091 0x13E4   0x01AE 0x10D2 0x0000 0x13FC 
#
#DL1_COMP:					;--------------- Downlink 1 Page in COMPRESSED mode
#    BRANCHEQ  R33    0   &DL1_COMP_PRIM
tcblock mbipcmd 0x0091 0x13E8   0x01AE 0x0021 0x0000 0x13F4 
#
#DL1_COMP_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x13EC   0x015C 0x1152 
#    START1HR 0x01 0x6000 $IPRL_DL_NWORDS
tcblock mbipcmd 0x0091 0x13EE   0x0174 0x0001 0x6000 0x1143 
#    GOTO &DONE
tcblock mbipcmd 0x0091 0x13F2   0x0156 0x142D 
#
#DL1_COMP_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x13F4   0x015C 0x1152 
#    START1HR 0x01 0x4000 $IPRL_DL_NWORDS
tcblock mbipcmd 0x0091 0x13F6   0x0174 0x0001 0x4000 0x1143 
#    GOTO &DONE
tcblock mbipcmd 0x0091 0x13FA   0x0156 0x142D 
#
#DL1_RAW:					;--------------- Downlink 1 Page in RAW mode
#    BRANCHEQ  R33    0   &DL1_RAW_PRIM
tcblock mbipcmd 0x0091 0x13FC   0x01AE 0x0021 0x0000 0x1408 
#
#DL1_RAW_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x1400   0x015C 0x1152 
#    START1HR 0x03 0x6000 $IPRL_DL_NWORDS
tcblock mbipcmd 0x0091 0x1402   0x0174 0x0003 0x6000 0x1143 
#    GOTO &DONE
tcblock mbipcmd 0x0091 0x1406   0x0156 0x142D 
#
#DL1_RAW_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x1408   0x015C 0x1152 
#    START1HR 0x03 0x4000 $IPRL_DL_NWORDS
tcblock mbipcmd 0x0091 0x140A   0x0174 0x0003 0x4000 0x1143 
#    GOTO &DONE
tcblock mbipcmd 0x0091 0x140E   0x0156 0x142D 
#
#WAITING:					;-------------- Check to see that the downlink actua
#    BRANCHEQ $IPRL_DL_CHECKED 1 &DONE		;already did the wait once
tcblock mbipcmd 0x0091 0x1410   0x01AE 0x1151 0x0001 0x142D 
#    SETREG   $IPRL_DL_CHECKED 1
tcblock mbipcmd 0x0091 0x1414   0x0140 0x1151 0x0001 
#
#    SETREG  R143 16
tcblock mbipcmd 0x0091 0x1417   0x0140 0x008F 0x0010 
#    PURGELST R136				;wait 82 msec before checking the page
tcblock mbipcmd 0x0091 0x141A   0x0190 0x0088 
#
#    BRANCHEQ  R33    0   &CHECK_PRIM
tcblock mbipcmd 0x0091 0x141C   0x01AE 0x0021 0x0000 0x1425 
#
#CHECK_REDUN:
#    BRANCHNR 0x6000 &DONE			;The page got busy ==> all ok
tcblock mbipcmd 0x0091 0x1420   0x01A6 0x6000 0x142D 
#    GOTO &PROBLEM
tcblock mbipcmd 0x0091 0x1423   0x0156 0x142A 
#
#CHECK_PRIM:
#    BRANCHNR 0x4000 &DONE			;The page got busy ==> all ok
tcblock mbipcmd 0x0091 0x1425   0x01A6 0x4000 0x142D 
#    GOTO &PROBLEM
tcblock mbipcmd 0x0091 0x1428   0x0156 0x142A 
#
#PROBLEM:
#    SAVEMODE					;save the state, throw an error and reset the IP
tcblock mbipcmd 0x0091 0x142A   0x01E6 
#    GOTOREG $IPRL_DL_QADDR_REDO			;Go back and issue the command 
tcblock mbipcmd 0x0091 0x142B   0x0158 0x1152 
#
#DONE:
#    RTNQUE
tcblock mbipcmd 0x0091 0x142D   0x01FA 
#=======================================================
#
# ENBQUE                ; Enable Queue
tcblock mbipldin 0x0136
#
#
return
#
#=======================================================
