********************************************************************************
* Overlay-dispatcher                                                           *
* started : 10.10.1995                                                         *
********************************************************************************
* last changed                                                                 *
* 29.09.96      BS42            changed for IRQ-slots
* xx.06.97      B242            some redesigns

                include "\bjl\js\macro\help.mac"

                MACRO WAITBLITTER
.\wbl           load (r14+$38),OVLhelp
                shrq #1,OVLhelp
                jr cc,.\wbl
                nop
                ENDM

                isyms "\bjl\js\symbols\blit_eq.sym"

                include "dispatch.reg"

; overlay-table fix at
OVLtab::        equ $40004


                run $f03030     ; leave space for irq-slots
* if the gpu-object-irq is used, it overwrites
* the init-code

InitOverlay::   movei #$f04000,SP
                moveta SP,SP                    ; init SPs
                movei #DoOverlay,Overlay
                moveta Overlay,Overlay          ; init hook
                movei #OVLtab-4,NewFunction
                load (NewFunction),NewFunction  ; start with main

DoOverlay       move r14,OVLsave
                movei #$f02200,r14
                WAITBLITTER                     ; wait 'till blitter's idle

                move  NewFunction,CurrentFunction ; current <= new
                shrq  #16,NewFunction
                shlq  #16,CurrentFunction
                movei #OVLtab,OVLhelp
                shrq  #16,CurrentFunction       ; current = new & $ffff
                add   CurrentFunction,OVLhelp   ; OVLhelp = &OVLtab[NewFunction]

                load  (OVLhelp),OVLhelp1        ; src
                addq  #4,OVLhelp
                store OVLhelp1,(r14+$24)        ; A2_BASE = src
                load  (OVLhelp),OVLhelp1        ; len
                addq  #4,OVLhelp
                store OVLhelp1,(r14+$3c)        ; B_COUNT = length
                load  (OVLhelp),OVLhelp         ; dest
                bset  #15,OVLhelp               ; => 32bit Memory
                store OVLhelp,(r14)

                moveq #$f,OVLhelp1
                shlq #20,OVLhelp1               ; OVLhelp1 = $0f00000
                movei #B_PIXEL8|B_WID320,OVLhelp
                or OVLhelp1,NewFunction

                xor OVLhelp1,OVLhelp1           ; zero OVLhelp1
                store OVLhelp,(r14+4)           ; A1_FLAGS
                store OVLhelp,(r14+$28)         ; A2_FLAGS
                movei #1<<23|1<<24|B_SRCEN,OVLhelp
                store OVLhelp1,(r14+$c)         ; A1_PIXEL_PTR
                store OVLhelp1,(r14+$18)        ; A1_PIXEL_PTR_FRAC
                store OVLhelp1,(r14+$30)        ; A2_WINDOW_PTR
                store OVLhelp1,(r14+$8)         ; A1_CLIP
                store OVLhelp,(r14+$38)         ; B_CMD
                WAITBLITTER
                jump (NewFunction)
                move OVLsave,r14                ; restore r14
                align 8
OverlayEnd::
                end

