
 section blitter,code_c          ; Put into chip memory.
 opt     c-,o+                   ; No case sensitivity, optimize on.

        lea     gfxlib,a1
        moveq   #0,d0
        move.l  4.w,a6
        jsr     -$228(a6)       ; Open graphics library.
        tst     d0
        beq     error
        move.l  D0,gfxbse

        move.l  #screen,d0      ; Store screen address in
        move.w  d0,pl0l         ; copper list.
        swap    d0
        move.w  d0,pl0h

        move.l  gfxbse,a6       ; Set up copper list.
        add.l   #$32,a6
        move.w  #$80,$dff096
        move.l  (a6),oldcpr
        move.l  #newcpr,(a6)
        move.w  #$8080,$dff096
        move.w  #$8010,$dff09a
        move.l  $6c.w,old
        move.l  #new,$6c.w

wait:   btst    #6,$bfe001      ; Test for left mouse button.
        bne.s   wait

        move.l  old,$6c.w       ; Return to workbench.
        move.l  gfxbse,a6       ; Copper list.
        add.l   #$32,a6
        move.w  #$0080,$dff096
        move.l  oldcpr,(a6)
        move.w  #$8080,$dff096

        move.l  gfxbse,a1       ; Close graphics library.
        move.l  $4.w,a6
        jsr     -$19e(a6)

error:  clr.l   d0              ; Exit routine.
        rts

new:    movem.l d0-d7/a0-a6,-(sp) ; Save all registers.
        and.w   #$10,$dff01e      ; Check if it is.
        beq.s   out
        move.w  #$10,$dff09c

        bsr     movbts            ; Enter a new line.
        bsr     blitit

out:    movem.l (sp)+,d0-d7/a0-a6
        dc.w    $4ef9             ; jsr instruction.
old:    dc.l    0

movbts: lea     endlin,a0         ; Move 40 bytes to
        addq.b  #1,bytval         ; bottom of screen.
        move.b  bytval,d1
        moveq   #39,d0
movlp:  move.b  d1,(a0)+
        dbra    d0,movlp
        rts

blitit: btst    #14,$dff002
        bne.s   blitit
        move.l  #screen+40,$dff050      ; BLTAPTR.
        move.l  #screen,$dff054         ; BLTBPTR.
        clr.l   $dff064                 ; Clear BLTAMOD and BLTDMOD.
        move.l  #-1,$dff044             ; This moves $ffff into
                                        ; BLTAFWM and BLTALWM.
        move.w  #%100111110000,$dff040  ; BLTCON0.
*                 |__||______|
*                  /     /
*              %1001    /               ; %1001 = Enable A and D DMA.
*                    %11110000          ; Minterm Val = $f0, D=A.

        clr.l   $dff042                 ; BLTCON1.
        move.w  #20+64*101,$dff058      ; BLTSIZE.
        rts

bytval: dc.b    0,0
oldcpr: dc.l    0                       ; Workbench copper list.

newcpr: dc.w    $100,$1200,$102,$0,$104,$a,$108,0,$10a,0
        dc.w    $92,$38,$94,$d0,$8e,$7c81,$90,$e0c1
        dc.w    $180,0,$182,$fff,$e0
pl0h:   dc.w    0,$e2
pl0l:   dc.w    0
        dc.w    $e209,$fffe,$9c,$8010
        dc.w    $ffff,$fffe             ; End copper.

gfxlib: dc.b    "graphics.library",0    ; Library name.
        even
gfxbse: dc.l    0
screen: ds.b    4000
endlin: ds.b    40
