* This program should be run during the
* System startup of APMs with 68010 CPUs.
* Its purpose is to convert bus/address errors
* into a software signal (Imp-style event, sorry).
* Required because 68010s and 68000s behave differently.

        incl    inc:module.asm
        module  bus and address error conversion

freebot equ     $3ff0
signal  equ     $3f00-6
berrvec equ     $1008
aerrvec equ     $100c
dif     equ     50

        code

reset   rts                Null module-reset-routine

* Main program.
* Lock ourselves in store.
* Replace existing BE/AE handlers.
begin   lea     end,a0
        move.l  a0,freebot
        lea     aerr,a0
        move.l  a0,aerrvec
        lea     berr,a0
        move.l  a0,berrvec
        rts

* Bus error handler.
* Convert to event 0,2,address.
berr    move.l  10(sp),d2
        moveq   #2,d1
        moveq   #$30,d0
        move.w  (sp),dif(sp)
        move.w  6(sp),6+dif(sp)
        bclr    #7,6+dif(sp)
        move.l  #signal,2+dif(sp)
        lea     dif(sp),sp
        rte

* Address error handler.
* Convert to event 0,3,address.
aerr    move.l  10(sp),d2
        moveq   #3,d1
        moveq   #$30,d0
        move.w  (sp),dif(sp)
        move.w  6(sp),6+dif(sp)
        bclr    #7,6+dif(sp)
        move.l  #signal,2+dif(sp)
        lea     dif(sp),sp
        rte

        endmodule

end     equ     *

        end
