
Prepair_Data   IDNT                      ; Title of  Cyclic Section

     SECTION   Sect_Prepair_Data,4,C     ; Declare a noncommon code section.
                                         ; Align to Longwords.

***************************************************************************
*                                                                         *
*   Prepair Data Cyclic Event by Event Processing      Rev.  3-NOV-1993   *
*                                                                         *
***************************************************************************

***************************************************************************
*                                                                         *
*  Prepair Data Cyclic Operation section.                                 *
*                                                                         *
*     Set state PrepData.                                                 *
*                                                                         *
*     Read the Specific Triggers Fired and make a Specific Triggers       *
*        Fired list in a longword. Based on which Spec Trig's have        *
*        fired this is either a Monitor Data Only Event or else it is     *
*        a "Normal" event, or else an error (i.e. no trigs fired).        *
*                                                                         *
*     If no Spec Trig's have fired then:                                  *
*          Put an error message on the VTC console screen, and            *
*          Set the global flag that says that this is a "Monitor Only"    *
*          trigger (so that later routines will not try to transfer it).  *
*          Clear all the state bits and return.                           *
*                                                                         *
*     If this event is only a monitor Specific Trigger then:              *
*        Set the global flag that says that this is a "Monitor Only"      *
*        trigger.                                                         *
*        Send the "Monitor Data Only" message to VTC console screen.      *
*        Test to see if you could transfer to L2 is you wanted to, i.e.   *
*        is there a free VBD Buffer?  If there is a free VBD Buffer       *
*        then,  clear the TWB that say that "Stuck transfering to L2".    *
*        The "Stuck transfering to L2" TWB may or may not have been set.  *
*        Clear all State Bits and return to the calling routine.          *
*                                                                         *
*     If this event is any combination of Specific Triggers that          *
*        includes at least one "normal" Specific Trigger then:            *
*        Make a 16 bit Event Number for the VBD to read and save          *
*           information to display the Sync Bits if there is time.        *
*        Build the Crate Header words #1 (the sync word) and Crate        *
*           Header word #5 (the list of Specific Triggers Fired).         *
*        Call the routine to move the CTFE Et data to where the           *
*           VBD will read it from (i.e. to put zero energy response       *
*           in |eta| regions that are not operating in hardware).         *
*        Set the global flag that says that this is a normal event.       *
*        Clear all State Bits and Return to the calling routine.          *
*                                                                         *
*                                                                         *
*                                                                         *
*  Control of the Trouble Warning Bits                                    *
*     The only control of the TWB's is in the routine for handling        *
*     Monitor Data Only triggers.  In this routine check to see if there  *
*     is a free VBD Buffer and if there is then clear the "Stuck          *
*     Transfering to L2"  TWB.                                            *
*                                                                         *
*                                                                         *
*  Control of the State Bits                                              *
*     The state  StatePrepData  is set as soon as you enter this routine. *
*     All state bits are cleared whenever you exit this routine.          *
*                                                                         *
***************************************************************************


*************************************************************************
*       This section defines program-specific macros:                   *
*                                                                       *
*            WRIO:  Write bit(s) to the IRONICS I/O card                *
*                                                                       *
*************************************************************************

WrIO    MACRO                             ; Write byte to Ironics I/O Port.
        NOT.B   \1                        ; Complement data byte \1.
        MOVE.B  \1,\2                     ; Move to Ironics port at adrs \2.
        ENDM




*************************************************************************
*  Prepair Data  Cyclic Event Section:     Begining of Process Event    *
*                                                                       *
*                                                                       *
*  Set the State Bits to StatePrepData to indicate that the portion of  *
*  the VTC program that: builds jet lists, moves data, and builds       *
*  headers is now running.                                              *
*                                                                       *
*  Call the Spec_Trig_Prog_Fired routine.  This routine will build the  *
*  a long word which shows which Spec Trigs fired for this event and    *
*  it will store this information at location TrgsFired and return it   *
*  in data register D1.                                                 *
*                                                                       *
*  AND the Specific Triggers Fired list with the mask of monitor data   *
*  only Specific Triggers.  This is to test for Monitor Data Only       *
*  triggers.  Also test to verify that at least one Spec Trig fired.    *
*                                                                       *
*  If no Spec Trig's at all fired then use the "no triggers" error      *
*  exit routine.  In this routine the "Transfer to L2" flag is          *
*  cleared, and error message is sent to the VTC console screen, all    *
*  State Bits are cleared,  and we return to the calling routine.       *
*                                                                       *
*  If just a monitor Specific Trigger (e.g. #31) fired then this event  *
*  is only L1 monitor data and it should NOT be sent to the VBD or L2.  *
*                                                                       *
*  If any other Specific Trigger(s), besides the monitor data only      *
*  Specific Trigger(s), fired then send this L1 Data Block to the VBD   *
*  and L2.                                                              *
*                                                                       *
*************************************************************************

                ALIGN   4                   ; Align to Longword Address.

Begin_Prepair_Data   Move.B  #StatePrepData,StatePortAdrs    ; Set the State
                                                             ; Bits to
                                                             ; indicate VTC is
                                                             ; prepairing data

        JSR  Begin_Spec_Trig_Prog_Fire      ; Call to build list of Spec Trigs
                                            ; fired.

        AndI.L  #AllBitsHi,D1               ; Test to verify that at least one
                                            ;   Spec Trig fired.  If no trig
        BEQ     NoTrigError                 ;   fired how did we get here??
                                            ;   Go to an error exit.

        AND.L   MskMonSpTrg,D1              ; Test for Spec Trigs besides
                                            ;   just Monitor Spec Triggers.
        BEQ     OnlyMon                     ; Branch to service Monitor data
                                            ;   only "events".

        JMP     OtherTrgs                   ; Jump to service events that have
                                            ;   a Spec Trig besides Mon trigs.


                ALIGN   4                   ; Align to Longword Address.

                                            ; This is the error exit routine
                                            ;   for triggers which have no
                                            ;   bits set in the Specific
                                            ;   Triggers Fired Mask.
NoTrigError   CLR.L   TransEvent            ; We will not transfer this event.

        PEA.L   NoTrigMsg1                  ; Send a message saying that an
        JSR     ChrStrgOut                  ;   event was seen with no bits
                                            ;   set in Spec Trig's Fired Mask.

        Move.B  #AllBitsLow,StatePortAdrs   ; Set all of the State Bits
                                            ;   low to indicate no state.

        RTS                                 ; Return to the calling routine.



*************************************************************************
*  Prep Data Section:           Service for Monitor Data only "events". *
*                                                                       *
*  Service events in which only Monitor Specific Triggers have          *
*    fired.  This implies --> monitor data only events.                 *
*                                                                       *
*  Send a message to the VTC console screen that says that this is      *
*    monitor data only.                                                 *
*                                                                       *
*  Clear the TransEvent flag to indicate that we will not transfer      *
*    this event to Level 2.                                             *
*                                                                       *
*  Update the Trouble Warning Bits.                                     *
*    Test to see if either VBD buffer is free i.e. test to see if       *
*    you could transfer to L2 if you wanted to.  If there is a          *
*    free VBD buffer then you could transfer to L2 if you wanted to     *
*    so clear the  Can't Transfer to L2 Trouble Warning Bit.  If        *
*    there is not a free VBD buffer then do not set or clear the        *
*    Can't Transfer to L2  Trouble Warning Bit.                         *
*                                                                       *
*  Clear all of the State Bits                                          *
*                                                                       *
*  Return to the calling routine.                                       *
*                                                                       *
*************************************************************************

                ALIGN   4               ; Align to Longword Address.

OnlyMon  PEA.L    MonMessage            ; Push monitor data only message
         JSR      ChrStrgOut            ; on the stack and send it out.

        CLR.L   TransEvent              ; We will not transfer this event.

        CLR.L   D0                      ; Clear all bits in data reg 0.
        MOVE.W  VBDCSR2,D0              ; Move the VBD CSR2 into D0.
        AND.L   MskBuf0Sta,D0           ; Mask all but the Buf 0 DMA and
                                        ;   Buf 0 port status bits.
        BEQ     FreBufExist             ; If both CSR bits are 0 then, Buf 0 is
                                        ;   ready to use so beq to FreBufExist.
                                        ; Else test the other buffer.
        CLR.L  D0                       ; Clear all bits in data reg 0.
        MOVE.W  VBDCSR2,D0              ; Move the VBD CSR2 into D0.
        AND.L   MskBuf1Sta,D0           ; Mask all but the Buf 1 DMA and
                                        ;   Buf 1 port status bits.
        BEQ     FreBufExist             ; If both CSR bits are 0 then, Buf 1 is
                                        ;   ready to use so beq to FreBufExist.
                                        ; Else neither buffer is free so
                                        ;   just return.


                                        ; To reach here neither VBD Buffer is
                                        ;   free and ready to use to transfer
                                        ;   an event to L2, so do not change
                                        ;   the Trouble Warning Bits.  Just
                                        ;   clear the State Bits and return.

        Move.B  #AllBitsLow,StatePortAdrs   ; Set all of the State Bits
                                            ;   low to indicate no state.
        RTS                                 ; Return to the calling routine.


                                        ; To reach here a free VBD buffer
                                        ;   Exists so clear the Can't Transfer
                                        ;   to L2 Trouble Warning Bit before
                                        ;   returning to the calling routine.
FreBufExist   MOVE.B  TWBData,D0        ; Get the Trouble Warning Bits and
              ANDI.B  #$F2,D0           ; clear: No Slaves Ready, 68k Not
              MOVE.B  D0,TWBData        ; Running, and Can't Transfer to L2.
              WRIO    D0,TWBPortAdrs    ; Store and output the TWB's.

        Move.B  #AllBitsLow,StatePortAdrs   ; Set all of the State Bits
                                            ;   low to indicate no state.
        RTS                                 ; Return to the calling routine.



*************************************************************************
*  Prepair Data Section:          START of service for normal events.   *
*                                                                       *
*  Service events in which some combination of normal (non-Monitor)     *
*  Specific Triggers have fired.  In addition some Monitor Specific     *
*  Triggers may have fired.                                             *
*                                                                       *
*  Start by building the 16 bit  TAS Number.   The low order 4 bits     *
*  of the TAS Number are the low order 4 bits of the 40 bit Transfer    *
*  Number.  The high order 12 bits of the TAS Number are the low order  *
*  12 bits of the 40 bit Start Digitize Number.                         *
*                                                                       *
*  Make a copy of the 16 bit TAS Number in in Short IO Address Space    *
*  where the VBD can read it.  Also store the TAS Number in location    *
*  TRGNUMSTORE.                                                         *
*                                                                       *
*  Recall the format of the Transfer Number as written in VME memory    *
*  with VMX address line MDA01 inverted.  TrgNum is the symbol for      *
*  the address of the first long word that holds Transfer Number data.  *
*                                                                       *
*                                                                       *
*               3     2 2     1 1                                       *
*               1     4 3     6 5     8 7     0                         *
*    TrgNum    ---------------------------------                        *
*    $300284   |       | 2nd B |       | 1st B |      Bytes of the      *
*              ---------------------------------      Transfer Number   *
*                                                                       *
*               3     2 2     1 1                                       *
*               1     4 3     6 5     8 7     0                         *
*              ---------------------------------                        *
*  TrgNum+4    |       | 4th B |       | 3rd B |      Bytes of the      *
*              ---------------------------------      Transfer Number   *
*                                                                       *
*               3     2 2     1 1                                       *
*               1     4 3     6 5     8 7     0                         *
*              ---------------------------------                        *
*  TrgNum+8    |       | 1st B |       | 5th B |      Bytes of the      *
*              ---------------------------------                        *
*                       StDgNum         Trn Num                         *
*                                                                       *
*               3     2 2     1 1                                       *
*               1     4 3     6 5     8 7     0                         *
*              ---------------------------------                        *
*  TrgNum+12   |       | 3rd B |       | 2nd B |      Bytes of Start    *
*              ---------------------------------      Digitize Number   *
*                                                                       *
*************************************************************************

           ALIGN   4                     ; Align to Longword Address.

OTHERTRGS  MOVE.L  TrgNum,D0             ; Get 2nd and 1st bytes of Trans Num.
           AndI.L  #$0000000F,D0         ; Keep only the Low Order 4 bits of
                                         ; the 1st byte of Transfer Number and
                                         ; store it in the lowest byte of D0.

           Move.L  TrgNum+8,D2           ; Get part of Start Digitize Number.
           Swap    D2                    ; 1st byte of StrDgt Num is now in
                                         ; the lowest byte of register D2.

           Move.L  TrgNum+12,D3          ; Get part of Start Digitize Number.
                                         ; 2nd byte of StrDgt Num in low D3.

           Clr.L   D4                    ; Clear D4 to build part of TAS.
           Move.B  D3,D4                 ; Get 2nd byte of StrDgt Num into D4
           LSL.L   #8,D4                 ; and Shift it up 8 bits.

           Move.B  D2,D4                 ; Get 1st byte of Start Digitize Num.
           LSL.L   #4,D4                 ; Now shift it up 4 bits.
           AndI.L  #$0000FFF0,D4         ; Trim it to 12 bits.

           Or.L    D4,D0                 ; D0 now holds the 16 bit TAS Number.
                                         ; Number in its least significnt word.

           MOVE.W  D0,EvtNmbAdr133       ; Store the 16 bit TAS Num in the
                                         ;   Short IO Address memory space
                                         ;   for the VBD to read.

           MOVE.L  D0,TrgNumStore        ; Store the 16 bit TAS Number
                                         ;   in a longword.

*****************************************************************************
*                                                                           *
*  Prepair Data Section:            Service Data Block for Normal Events    *
*                                                                           *
*  Build the words #1 and #5 of the Crate Header.                           *
*  Words #2, #3, and #4 of the Crate Header are event to event static       *
*  and have been built and stored in the Initialization Section above.      *
*                                                                           *
*    Crate Header Word 1   Sync Word   2 MSByts TAS Num  2 LSByts of F's    *
*    Crate Header Word 2   Controller Word  MSByte is the low byte Crate ID *
*    Crate Header Word 3   Version Number  4-JAN-1990 Document definition   *
*    Crate Header Word 4   Rivision Number   defined in D0 Note #967        *
*    Crate Header Word 5   Specific Triggers Fired list    32 bits          *
*                                                                           *
*****************************************************************************

                                         ; D0 still holds the 16 bit TAS Num.
        SWAP    D0                       ; Move the 16 bit TAS Num into
                                         ;   the high order 16 bits.
        MOVE.W  #$FFFF,D0                ; Pad the Sync Word with F's.
        MOVE.L  D0,CrtHDWord1            ; Store the Sync Word in the
                                         ;   first word of the Crate Header.

        MOVE.L  TrgsFired,CrtHDWord5     ; Store the Specific Triggers Fired
                                         ;   list in the 5th word of the
                                         ;   Crate Header.


*************************************************************************
*                                                                       *
*  Prepair Data  Section:         Service Data Block for Normal Events  *
*                                                                       *
*  Call the subroutine to move the EM and HD CTFE Et data from where    *
*  the COMINT has written it to where the VBD will read it.  This is    *
*  to readout a zero energy response for |eta| regions that do not      *
*  exist in hardware.                                                   *
*                                                                       *
*  NOTE:  We now have hardware for all eta's 1:20 so comment out the    *
*  -----  call to Move_Data.  The Move_Data control parameters in the   *
*         Main_Symbols Include file have been left set for operation    *
*         with hardware for only eta's 1:16.                            *
*                                                                       *
*************************************************************************

;!*:;   JSR  Begin_Move_Data    ; Subroutine call to move CTFE Et data
                                ;   and the CHTCR data  (i.e. to fill
                                ;   in for eta setions of the L1 Calo
                                ;   Trigger that are not yet installed.


*************************************************************************
*                                                                       *
*  Prepair Data  Section:         Service Data Block for Normal Events  *
*                                                                       *
*  This is the exit processing for the normal data events.              *
*    Set the flag which indicates that this event should be transfered  *
*      to the Level 2.                                                  *
*    Clear all of the State bits.                                       *
*    Return to the calling routine.                                     *
*                                                                       *
*************************************************************************

        Move.L  #$0F,TransEvent             ; We will transfer this event
                                            ;   to Level 2 so set the flag.

        Move.B  #AllBitsLow,StatePortAdrs   ; Set all of the State Bits
                                            ;   low to indicate no state.

        RTS                                 ; Return to the calling routine.



*************************************************************************
*  Define Constants:                                                    *
*                                                                       *
*  Data used to send messages to the 68k terminal screen.               *
*                                                                       *
*************************************************************************

              ALIGN   4                ; Align to Longword Address.


NoTrigMsg1  DC.B  49,$0D,$0A,'Event with no Spec Trigs Fired, not transfered.'
MonMessage  DC.B  51,$0D,$0A,'Data Block with only Monitor Data not transfered.'


*************************************************************************
*  Define Constants:                 External References                *
*                                                                       *
*************************************************************************

       XDEF   Begin_Prepair_Data                    ; Export this symbol
                                                    ; to other modules.

       XREF   AllBitsHI                             ; Symbols referenced
       XREF   AllBitsLOW                            ; in this program
       XREF   Begin_Move_Data                       ; module but defined
       XREF   Begin_Spec_Trig_Prog_Fire             ; in another module
       XREF   ChrsTrgOut                            ; Main_Symbols.Include
       XREF   CrtHdWord1
       XREF   CrtHdWord5
       XREF   EvtNmbAdr133
       XREF   MskBuf0Sta
       XREF   MskBuf1Sta
       XREF   MskMonSpTrg
       XREF   StatePortAdrs
       XREF   StatePrepData
       XREF   TransEvent
       XREF   TrgNum
       XREF   TrgNumStore
       XREF   TrgsFired
       XREF   TWBData
       XREF   TWBPortAdrs
       XREF   VBDCSR2

       END



