;*** Example for a simple Copperlist ***

;CustomChip-Register

INTENA  = $9A                ;Interrupt-Enable-Register (write)
DMACON  = $96                ;DMA-control register (write)
COLOR00 = $180               ;Color palette register 0

;Copper Register

COP1LC  = $80                ;Address of 1. Copper list
COP2LC  = $84                ;Address of 2. Copper list
COPJMP1 = $88                ;Jump to Copper list 1
COPJMP2 = $8a                ;Jump to Copper list 2

;CIA-A Port register A (Mouse key)

CIAAPRA = $BFE001

;Exec Library Base Offsets

OpenLibrary = -30-522        ;LibName,Version/a1,d0
Forbid      = -30-102
Permit      = -30-108
AllocMem    = -30-168        ;Byte Size, Requirements/d0,d1
FreeMem     = -30-180        ;Memory Block, Byte Size/a1,d0

;graphics base

StartList = 38

;other Labels

Execbase = 4
Chip = 2                     ;request Chip-RAM

;*** Initialize-programm ***

;Request memory for Copperlist

Start:
 move.l Execbase,a6
 moveq  #Clsize,d0           ;Set Parameter for AllocMem
 moveq  #chip,d1             ;ask for Chip-RAM
 jsr    AllocMem(a6)         ;request memory
 move.l d0,CLadr             ;Address of the RAM-area memory
 beq.s  Ende                 ;Error! -> End

;copy Copperlist to CLadr

 lea    CLstart,a0
 move.l CLadr,a1
 moveq  #CLsize-1,d0         ;set loop value
CLcopy:
 move.b (a0)+,(a1)+          ;copy Copperlist Byte for Byte
 dbf    d0,CLcopy

;*** Main programm ***

 jsr    forbid(a6)           ;Task Switching off
 lea    $dff000,a5           ;Basic address of the Register to A5
 move.w #$03a0,dmacon(a5)    ;DMA offn
 move.l CLadr,cop1lc(a5)     ;Address of the  Copperlist to COP1LC
 clr.w  copjmp1(a5)          ;Load copperlist in program counter

;Switch Copper DMA

 move.w #$8280,dmacon(a5)

;wait for left mouse key

Wait:  btst #6,ciaapra       ;Bit test
 bne.s Wait                  ;done? else continue.

;*** End programm ***

;Restore old Copper list

 move.l #GRname,a1           ;Set parameter for OpenLibrary
 clr.l  d0
 jsr    OpenLibrary(a6)      ;Graphics Library open
 move.l d0,a4                ;Address of GraphicsBase to a4
 move.l StartList(a4),cop1lc(a5) ;load address of Startlist
 clr.w  copjmp1(a5)
 move.w #$83e0,dmacon(a5)    ;all  DMA on
 jsr    permit(a6)           ;Task-Switching on

;Free memory of Copperlist

 move.l CLadr,a1             ;Set parameter for FreeMem
 moveq #CLsize,d0
 jsr   FreeMem(a6)           ;memory freed
Ende: clr.l d0                    ;error flag erased
 rts                         ;end program

;Variables

CLadr: dc.l 0

;Constants

GRname: dc.b "graphics.library",0
 align                       ;even for other assemblers

;Copperlist

CLstart:
 dc.w color00,$0000          ;Background color black
 dc.w $640f,$fffe            ;On line 100 change to
 dc.w color00,$0f00          ;Red. Switch
 dc.w $be0f,$fffe            ;Line 190 to
 dc.w color00,$0fb0          ;Gold
 dc.w $ffff,$fffe            ;Impossible Position: End of the Copperlist
CLend:

CLsize = CLend - CLstart

 end
;End of program

