* access to qdos traps (1,2,and 3) for   BCPL
*
* Dr.A.J.Finch 27/5/87
*  Physics Dept.,
*   Lancaster University,
*    Lancaster
*
       rorg  $0
qtrap equ 276  this is the global to be assigned to this routine
*                in global vector - alter kermain routine accordingly!
* i.e. 
* global $(
* qtrap :  ug + 176
* $)
*

first dc.l  (endmod-first)/4

   cnop  0,4

label
   BRA      start           
   DC.B     'QTRAP'     THIS HELPS FOR DEBUGGING WITH C1 MONITOR!
   CNOP      0,4
 
start      
   movem.l  d0-d7/a0-a6,-(sp)  just to be safe !
*    
*set up registers for trap 
*     
   move.l   d1,d4           save trap   number
   lsl.l #2,d2              bcpl address *4 for byte addresses
   move.l   d2,a5           save address of input regs.     
   lsl.l #2,d3              bcpl address *4 for byte addresses
   move.l   d3,a6           save address of output regs.        
     
*
* copy over input register
*
   move.l   0(a5),d0
   move.l   4(a5),d1
   move.l   8(a5),d2
   move.l   12(a5),d3
   move.l   16(a5),a0
   move.l   20(a5),a1
   move.l   24(a5),a2
   move.l   28(a5),a3
*
* just in case  - save register needed to  return values
*                   of output registers
*    
   move.l  a6,-(sp)
     
   cmpi.w   #1,d4 
   beq      trap1
   cmpi.w   #2,d4
   beq      trap2
   cmpi.w   #3,d4   
   beq      trap3
   bra      endtrap
   
trap1 trap  #1  
      bra   endtrap 
trap2 trap  #2  
      bra   endtrap
trap3 trap  #3  
* 
endtrap
*
* return registers
*     
   move.l  (sp)+,a6  restore address of output vector
*
* and copy over registers
*
   move.l   d0,0(a6)  
   move.l   d1,4(a6)
   move.l   d2,8(a6) 
   move.l   d3,12(a6) 
   move.l   a0,16(a6)
   move.l   a1,20(a6)
   move.l   a2,24(a6)
   move.l   a3,28(a6)
     
*
* restore previously saved registers
*
   movem.l  (sp)+,d0-d7/a0-a6
*
* and finally return to bcpl
*      
   jmp   (a6)
*      
*
* globals
*    
   cnop  0,4
   dc.l  0 
   dc.l  qtrap,(label-first)
   dc.  qtrap
      
endmod  end     
