Get_CAMAC     IDNT                            ; Title Get CAMAC.

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

***************************************************************************
*   Get CAMAC                                     Rev.  9-MAY-1991    MT  *
*                                                                         *
*   When you enter this routine Address Register A0 will contain the      *
*   base address in the MVME-214 memory module where the CAMAC data       *
*   should be stored.                                                     *
***************************************************************************

***************************************************************************
*                                                                         *
*   D0 Hall CAMAC TDC is defined to be:  Branch 0,  Crate 1,  Slot 5      *
*                                                                         *
***************************************************************************

***************************************************************************
*                                                                         *
*  Clear the error flag.  This flag will be set to a non-zero value if    *
*  any of the VME-CAMAC cycles times out and the bus error exception      *
*  handler is called.                                                     *
*                                                                         *
*  Change the Bus Error Vector to point to our own Bus Error exception    *
*  handler.   This routing starts at BUSEREXHD.                           *
***************************************************************************

Begin_Get_CAMAC     CLR.L   GetCAMACError       ; Clear the Error Flag that
                                                ; indicates a Bus Error
                                                ; during CAMAC read.

          MOVE.L  #BUSEREXHD,$00000008          ; point the Bus Error vector
                                                ; to our exception handler.

***************************************************************************
*                                                                         *
*   Do VME cycles to read the CAMAC data and then store this data in      *
*   locations pointed to register A0.                                     *
***************************************************************************

       MOVE    $81280A,D0         ; CH 0    [F=2, A=0]
       MOVE.W  D0,(A0)+

       MOVE    $81288A,D0         ; CH 1    [F=2, A=1]
       MOVE.W  D0,(A0)+

       MOVE    $81290A,D0         ; CH 2    [F=2, A=2]
       MOVE.W  D0,(A0)+

       MOVE    $81298A,D0         ; CH 3    [F=2, A=3]
       MOVE.W  D0,(A0)+

       MOVE    $812A0A,D0         ; CH 4    [F=2, A=4]
       MOVE.W  D0,(A0)+

       MOVE    $812A8A,D0         ; CH 5    [F=2, A=5]
       MOVE.W  D0,(A0)+

       MOVE    $812B0A,D0         ; CH 6    [F=2, A=6]
       MOVE.W  D0,(A0)+

       MOVE    $812B8A,D0         ; CH 7    [F=2, A=7  Clears Module]
       MOVE.W  D0,(A0)+

***************************************************************************
*                                                                         *
*  We are finished doing VME cycles to read CAMAC data  so restore the    *
*  normal 133A Bug Bus Error Vector.                                      *
***************************************************************************

       MOVE.L  #$FFF149E2,$00000008         ; Restore normal 133A Bug
                                            ; Bus Error vector.

                  RTS                       ; RETURN from Get_CAMAC Subroutine


***************************************************************************
*  Bus Error Exception Handler                                            *
*                                                                         *
*  Mask the rerun bit in the Special Status Word and then:                *
*  Load $FFFFFFFF into register D0.  The contents of D0 are stored as the *
*  data "read" from the CAMAC system.   Load a non-zero value into        *
*  GetCAMACError to flag that there has been an error reading CAMAC data. *
***************************************************************************

BUSEREXHD  MOVE.W  (SP)+,D0                ; pull the Status Register
           MOVE.L  (SP)+,D1                ; pull the Program Counter
           MOVE.W  (SP)+,D2                ; pull the Format - Vector Offset
           MOVE.W  (SP)+,D3                ; pull the Internal Register
           MOVE.W  (SP)+,D4                ; pull the Special Status Register

           ANDI.W  #$FEFF,D4               ; Mask the rerun bus cycle bit

           MOVE.W  D4,-(SP)                ; push the Special Status Register
           MOVE.W  D3,-(SP)                ; push the Internal Register
           MOVE.W  D2,-(SP)                ; push the Format - Vector Offset
           MOVE.L  D1,-(SP)                ; push the Program Counter
           MOVE.W  D0,-(SP)                ; push the Status Register

           MOVE.L  #$FFFFFFFF,D0           ; Load data that will be stored
                                           ; as the data "read" from CAMAC.

           MOVE.L  #$000000FF,GetCAMACError   ; Set the Bus Error during CAMAC
                                              ; read Flag to a non-zero value.

           RTE                             ; RETURN from the Bus Error
                                           ; exception handler.


***************************************************************************
*                                                                         *
*   Constants Section for  Get CAMAC                                      *
*                                                                         *
***************************************************************************

       XDEF   Begin_Get_CAMAC                 ; Export this symbol
                                              ; to other modules.

       XREF   GetCAMACError                   ; Symbol used in this module
                                              ; but defined in another module.

                 END

