;+++++ Creating a 24 bits copperlist
;+++++ Code by Yragael (April 1993)

	section prg,code_c
	include "df1:sources/registres.s"

;*************** INDEX FONCTIONS ***************

openlib=-552
closelib=-414
allocmem=-198
freemem=-210
permit=-138
forbid=-132

;*************** CONSTANTES ***************

starty=45
sizey=180
memory=2+$10000
copsize=sizey*(4+4+4+4+4)+4

;sizey*(4+4+4+4+4) (wait, $0106, $0180, $0106, $0180)
;4 ($FFFFFFFE)

;*************** PROGRAMME PRINCIPAL ***************

	bsr.w init
boucle:
	btst #6,$bfe001
	bne boucle
	bsr fin
	rts

;*************** INITIALISATION ***************

init:

;reservation de la memoire copper

	move.l $4,a6
	move.l #copsize,d0
	move.l #memory,d1
	jsr allocmem(a6)
	move.l d0,copadr

;creation de la copperlist

	move.l copadr,a0

	moveq #0,d1
	move.w #starty,d0
	lsl.w #8,d0
	or.w #$01,d0
	move.w #sizey-1,d2
coploop0:
	move.w d0,(a0)+
	addi.w #$0100,d0
	move.w #$FFFE,(a0)+
	move.w #$0106,(a0)+
	move.w #$0000,(a0)+
	move.w #$0180,(a0)+
	move.l d1,d3
	lsr.l #4,d3
	move.l d3,d4
	lsr.l #4,d4
	move.w d4,d5
	lsr.w #4,d5	
	and.w #$000F,d3
	and.w #$00F0,d4
	and.w #$0F00,d5
	or.w d5,d4
	or.w d4,d3
	move.w d3,(a0)+
	move.w #$0106,(a0)+
	move.w #$0200,(a0)+
	move.w #$0180,(a0)+
	move.w d1,d3
	move.l d1,d4
	lsr.l #4,d4
	move.w d4,d5
	lsr.w #4,d5	
	and.w #$000F,d3
	and.w #$00F0,d4
	and.w #$0F00,d5
	or.w d5,d4
	or.w d4,d3
	move.w d3,(a0)+
	addq.l #1,d1
	dbf d2,coploop0

	move.l #$FFFFFFFE,(a0)

;modif DMA,...
	
	jsr forbid(a6)
	move.w #$03F0,dmacon		;couper tous les DMA
	move.l copadr,cop1lch		;adresse coplist1
	clr.w copjmp1			;copjump1
	move.w #$86C0,dmacon		;COPEN et BPLEN et BLTPRI et BLTEN

	rts

;*************** WAIT VBL ***************

waitvbl:
	cmp.b #$FF,vhposr
	bne waitvbl
	rts

;*************** WAIT BLITTER ***************

waitblit:
	btst #14,dmaconr
	bne.b waitblit
	rts

;*************** FIN DE PROGRAMME ***************

fin:	

;restaurer les anciennes preferences

	move.l $4,a6
	move.l #gfxname,a1
	clr.l d0
	jsr openlib(a6)
	move.l d0,a1		
	move.l 38(a1),cop1lch
	clr.w copjmp1			;copjump1
	move.w #$83F0,dmacon		;active tous les DMA
	jsr permit(a6)

;liberation de la memoire copper

	move.l copadr,a1
	move.l #copsize,d0
	jsr freemem(a6)

	rts

;*************** VARIABLES ***************

copadr:		dc.l 0
gfxname:	dc.b "graphics.library",0
	even
