##########################                                            ##-#
#                                                                     ##-#
# Assembled by checkpoint, 1.18.2 (23-Sep-99).                        ##-#
# (EDIT THE ORIGINAL SOURCE, NOT THIS FILE!)                          ##-#
# Date-assembled: Mon Nov 29 17:06:17 EST 1999                        ##-#
# Orig-source: /mdisw/cfl/flight/src/runstr_v28.src                   ##-#
#                                                                     ##-#
##########################                                            ##-#
# File: runstr.src
#
#-------------------
# Executes procedures to construct and downlink observables(velocity, 
# line depth and continuum).
# 
# Note: 1. mkobstbl, 5ktst and strdp control files must have been executed 
#          before running this procedure
#       2. !GI9 must contain the address of entry point into strdp
#          !GI8 must contain the address of entry point in 5ktst
#
# V6 - Change Prime60 and Prime30 addresses
#	12-Dec-95 (MDM) - Commented out setting IPvector for 2,3, and 6
# Modified to v04 by CED 12/17/95
#  --removed VC flag commands (those are handled for us by the FOT
#  when they run k_mmtoidl and k_idltomm).
# 11-Jan-96 (MDM) - Replace clearing R4 campaign flag (CED had removed
#		    it on 17-Dec-95)
# 31-Jan-96 Dnyanesh Mathur
#    1. Removed all waits!!
#    2. Clear R81 (Bad HK board indicator)
# 31-Jan-96 (MDM) - Added setting of all campaign addresses since it is
#		    being removed from the sequence startup
#		  - Removed the setting of the IP vectors (into set_ipvec_str.src)
#  6-Feb-96 (MDM) - Made setting of the ALT flag the default
#
# 27 Mar 96 (DPM) - Initialize register lists for str/mag
# 28-Mar-96 (MDM) - Changed the MAG_TELEM default setting to 0 (from 1) (reg 5)
#                
#  9-Apr-96 (DPM) - IP Register setup occurs in str_setup routine
# 23-Apr-96 (MDM) - Put wait before execution of STRDPC
# 30-Apr-96 (DPM) - Removed wait before execution of STRDPC and figured out
#                   the real problem. STRDPC is now called first and STR_RLINIT
#                   has been modified to be consistant.
# 17-May-96 (MDM) - Added call to set_alt_time control file at the end
#
# 24-May-96 (DPM) - STRDPC is again called last!! 
#
# 26-Jul-96 (DPM) - Set Mag D/L Reg (R5) to 1
#                   Set Chain Address to 88 using R151; Clear R152-R158
# 12-Aug-96 (DPM) - Set chain addresses to 88.
# 13-Aug-96 (DPM) - Initialize DEP registers by memory load commands to
#                   cut down on number of telecommands required.
#  3-Oct-96 (DPM) - Changed address of initmag due to change to mag30.
#
#  7-Apr-97 (DPM) - Changed ALT address
#
# 10-Apr-97 (DPM) - Made Continuum downlink during Dynamics the default
#
program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/flight/src/q_runstr_v28.src"
descr "q_runstr - execute macros from mkstr."
                                                                      ##-#
#=#=#=#=#=#=#=#=#=#=# src ln 54.  (Open Log file)                     ##-#
if !GS9 = "" then                                                     ##-#
  display "Opening logfile from q_runstr_v28"                         ##-#
  perf openlog                                                        ##-#
end if                                                                ##-#
write !GS9 "%s q_runstr_v28:" !TIME                                   ##-#
writen !GS9 "Starting..."                                             ##-#
#=#=#=#=#=#=#=#=#=#=#+ src ln 56.  Block 0  Next line is #70          ##-#
 display "Running block 0 of q_runstr_v28."                           ##-#
set !LI0 = getint(mktccnt)                                            ##-#
queue on ## Queue next 17 commands.                                   ##-#
display "Executing procedure  runstr."

tcblock mbipldin 0x136            ## Enable Queue
tcblock mbdpmod 3                 ## Set 5k mode
tcblock mbipldin 0x134            ## Enable interrupts

tcblock mbipldin 0x11C              ## Initialize subroutine stack

# Initialize Error Log
tcblock mbipldin 0x1b2 464 3  0x0000  0x2011 4800
tcblock mbipldin 0x01EC  464
#
# Initialize Register Lists and data buffers
tcblock mbipldin 0x152 0x0F00       ## Call QSR_STR_SETUP 
tcblock mbipldin 0x152 0x0F80       ## Call QSR_STR_SETDPC
tcblock mbipldin 0x152 0x0600       ## Call QSR_STR_RLINIT 
tcblock mbipldin 0x152 0x0A2A       ## 0x0A38 Call QSR_MAG_INITMAG
#tcblock mbipldin 0x152 0x0F80       ## Call QSR_STR_SETDPC

tcblock mbipldin 0x140 1683 0       ## D/L continuum
#

# Initialize DEP Registers - 
#   (DEP registers are located at 1000:8CB4 in DFC100a)

# Set DEP Registers 4 (Cmpg Status) and 5 (MagHR)
tcblock mbdpml 0x1000 0x8cbc  0  0

# Set DEP Registers 65 - 73 
#   (ALTF, CmpgF, CmpgA, NewCmpgF, NewCmpgA, IIF, IIA, ChainF, ChainA)
tcblock mbdpml 0x1000 0x8d36  1  0  0  0 88  0 88  0 88

# Set DEP Registers 151 - 158 (Chain Addresses)
tcblock mbdpml 0x1000 0x8de2 88 88 88 88 88 88 88 88 

# Disable Alternate 2nd data product downlinks
#   (Mag, CBv, CBi, Mem)
tcblock mbipldin 0x1b2 1801 8 0 0 0 0 0 0 0 0 

tcblock mbdpflgs 16 0xffff 0        ## Clear IP Error count

# Run DEP sequence 
tcblock mbsqreg 247 0x7FFF          ## Use Frame List Que pointer only
queue off ## Synchronize w/ POCC                                      ##-#
tcblock mbsqstr 0
#=#=#=#=#=#=#=#=#=#=#- src ln 99.  Block 0   Cmds:18   Total:18       ##-#
wait time 8 ## Wait for hk packet                                     ##-#
set !LI2 = !LI0 + 18                                                  ##-#
if !LI2 > 255 then                                                    ##-#
 set !LI1 = !LI2 - 256                                                ##-#
else                                                                  ##-#
 set !LI1 = !LI2                                                      ##-#
end if                                                                ##-#
set !LI2 = getint(mktccnt)                                            ##-#
if !LI1 <> !LI2 then                                                  ##-#
 write !GS9 "%s q_runstr_v28:" !TIME                                  ##-#
 writen !GS9  "CMD CT ERR in block 0. cmd ctr: %d" !LI2               ##-#
 writen !GS9  "      (Sent 18 cmds; expected cmd ctr: %d)" !LI1       ##-#
 writen !GS9  "      Halted.  (restart at line 70)"                   ##-#
 display "ERR: q_runstr_v28 blk 0: cmd ctr isnt %d. (CONT 70)" !LI1   ##-#
 halt                                                                 ##-#
 write !GS9 "%s q_runstr_v28:" !TIME                                  ##-#
 writen !GS9  "Override.  Continuing past block 0..."                 ##-#
else                                                                  ##-#
 write !GS9 "%s q_runstr_v28:" !TIME                                  ##-#
 writen !GS9  "Block 0 completed OK."                                 ##-#
display "Completed block 0 of q_runstr_v28."                          ##-#
end if                                                                ##-#
#################### END of BLOCK 0 ####################              ##-#
#wait time 120			    ## wait 2 minutes for seq startup
wait time 91 ## (Reduced due to EOB overhead)
#=#=#=#=#=#=#=#=#=#=#+ src ln 101.  Block 1  Next line is #145        ##-#
 display "Running block 1 of q_runstr_v28."                           ##-#
set !LI0 = getint(mktccnt)                                            ##-#
tcblock mbsqreg 59 13               ## Select P30esq ALT frame list
#=#=#=#=#=#=#=#=#=#=#- src ln 102.  Block 1   Cmds:1   Total:19       ##-#
wait time 8 ## Wait for hk packet                                     ##-#
set !LI2 = !LI0 + 1                                                   ##-#
if !LI2 > 255 then                                                    ##-#
 set !LI1 = !LI2 - 256                                                ##-#
else                                                                  ##-#
 set !LI1 = !LI2                                                      ##-#
end if                                                                ##-#
set !LI2 = getint(mktccnt)                                            ##-#
if !LI1 <> !LI2 then                                                  ##-#
 write !GS9 "%s q_runstr_v28:" !TIME                                  ##-#
 writen !GS9  "CMD CT ERR in block 1. cmd ctr: %d" !LI2               ##-#
 writen !GS9  "      (Sent 1 cmds; expected cmd ctr: %d)" !LI1        ##-#
 writen !GS9  "      Halted.  (restart at line 145)"                  ##-#
 display "ERR: q_runstr_v28 blk 1: cmd ctr isnt %d. (CONT 145)" !LI1  ##-#
 halt                                                                 ##-#
 write !GS9 "%s q_runstr_v28:" !TIME                                  ##-#
 writen !GS9  "Override.  Continuing past block 1..."                 ##-#
else                                                                  ##-#
 write !GS9 "%s q_runstr_v28:" !TIME                                  ##-#
 writen !GS9  "Block 1 completed OK."                                 ##-#
display "Completed block 1 of q_runstr_v28."                          ##-#
end if                                                                ##-#
#################### END of BLOCK 1 ####################              ##-#
perf q_set_alt_time_v08
display "Finished procedure runstr"
write !GS9 "%s q_runstr_v28:" !TIME                                   ##-#
writen !GS9 "returning from procedure 'q_runstr_v28'"                 ##-#
return
write !GS9 "%s q_runstr_v28:" !TIME                                   ##-#
writen !GS9 "Falling off the bottom."                                 ##-#
