  ;Divide by zero cpu exeption trap
  ;cpu exeption 5 ,will cause a Guru 00000005.xxxxxxxx
  ;Div by zero error will come up when the cpu uses Divs,Divu if the 
  ;denominator is so small that the cpu rounds it to zero,if it is
  ;smaller then a word because Divs,Divu only uses words.
  ;this little bit of code stops guru 5 and sets the answer to Div by zero
  ;to computer infinity i.e. for Divs $FFF and for Divu $FFFF. you may say 
  ;why do this, well if the number in the denominator is so small anyway then 
  ;the answer to the division will be very large so we set the answer to
  ;infinity,and go on. in almost all cases the program that caused the div by
  ;zero will work just fine with the answer at infinity.  
  ;to use this program just put Divzero in your startup-sequence
  ;it will do the work of traping the exception 5 and stopping guru


Init_Trap:
  Move.l 4,A6
  Move.l #Div_End-Div,D0

  MoveQ  #1,D1
  Jsr    -198(a6)
  Move.l  D0,New_Trap

  Beq.s  Init_End
  Move.l D0,A1
  Lea    Div,A0

  MoveQ  #(Div_End-Div)-1,D0
Copy_Code:
  Move.b (A0)+,(A1)+
  DBra   D0,Copy_Code
  Move.l New_Trap,20


Init_End:
  MoveQ  #0,D0
  Divu   D0,D1
  rts

New_Trap:
  dc.l   0

Div:
  MoveM.l D0-A6,-(sp)
  Move.l  62(sp),A0
  Move.w  -2(A0),D0
  Move.l  #$ffff,D1

  Btst    #8,D0
  Beq.s   GoOn
  Move.l  #$7fff,D1

GoOn:
  Lsr.w   #7,D0
  AndI.l  #28,D0

  Move.l  D1,0(sp,d0.l)
  MoveM.l (sp)+,D0-A6
  Rte
Div_End:

  END 