***************************************************
*       Blitter Beispielprogramm (8.3.1993)       *
*     von G. Herbold, A. Kochann und O. Reiff     *
*	     Assembler: DevPacII 	      *
*               tabulator size: 11	      *
***************************************************

dmablt  = $dff040
bltcon0 = $0
bltcon1 = $2
bltafwm = $4
bltalwm = $6
bltcpth = $8
bltbpth = $c
bltapth = $10
bltaptl = $12
bltdpth = $14
bltsize = $18
bltcmod = $20
bltbmod = $22
bltamod = $24
bltdmod = $26
bltcdat = $30
bltbdat = $32
bltadat = $34
bltddat = $36

	move.l	4.w,a6
	lea	intname,a1
	jsr	-408(a6)		openlib
	lea	IntBase,a0
	move.l	d0,(a0)
	move.l	d0,a6
	lea	screens,a0
	jsr	-198(a6)		OpenScreen
	lea	Screen_1,a0
	move.l	d0,(a0)
	beq	NoScreen
	move.l	d0,a0
	add.l	#84,a0		84=Rastport
	lea	RastP1,a1
	move.l	a0,(a1)
	move.l	4.w,a6
	jsr	-132(a6)		Forbid

rechteck	bsr	fill

.1	btst	#10,$dff016.l	rechte Maustaste
	bne.s	.1

rechtecke	lea	aktfarbe(pc),a0
	move.l	#271,d0
	move.l	#169,d1
.2	bsr	copy
	move.b	d0,(a0)
	subq.w	#1,d0
	dbra	d1,.2

.3	btst	#10,($dff016).l	rechte Maustaste
	bne.s	.3

linien	move.l	#319,d4
.4	move.l	d4,d0
	moveq	#0,d2
	move.b	d4,(a0)
	bsr	line
	dbra	d4,.4
	move.l	#199,d4
.5	move.l	d4,d2
	moveq	#0,d0
	move.b	d4,(a0)
	bsr	line
	dbra	d4,.5
	move.l	#319,d4
.6	move.l	d4,d0
	move.l	#199,d2
	move.b	d4,(a0)
	bsr	line
	dbra	d4,.6
	move.l	#199,d4
.7	move.l	d4,d2
	move.l	#319,d0
	move.b	d4,(a0)
	bsr	line
	dbra	d4,.7

	move.l	4.w,a6
	jsr	-138(a6)		Permit

Wait	btst	#10,($dff016).l	rechte Maustaste
	bne.s	Wait

Ende	move.l	intbase,a6
	move.l	Screen_1,a0
	jsr	-66(a6)		CloseScreen
NoScreen	move.l	4.w,a6
	movea.l	intbase,a1
	jsr	-414(a6)		closelib
	rts

*---------------------------------------------
*---------------------------------------------
fill	movem.l	d0-a6,-(sp)
	lea	buffer(pc),a6
	move.w	#$09f0,bltcon0(a6)	AD an
	move.w	#$000e,bltcon1(a6)	IFE,FCI,DESC
	move.w	#$ffff,bltbdat(a6)	Maske
	move.l	#$ffffffff,bltafwm(a6)	
	move.w	#34,bltamod(a6)
	move.w	#34,bltdmod(a6)
	moveq	#30,d7
	lsl.l	#6,d7
	addq.w	#3,d7
	move.w	d7,bltsize(a6)	30*64+3
	move.l	rastp1,a0
	move.l	4(a0),a0		BitMap
	lea	8(a0),a0
	move.l	#1165,d4		Endadresse
	move.l	(a0)+,d7
	add.l	d4,d7
	move.l	d7,bltdpth(a6)
	move.l	d7,bltapth(a6)
	bsr	Startblitter
	movem.l	(sp)+,d0-a6
	bra	Clearblitter
*----------------------------------------------------
copy	movem.l	d0-a6,-(sp)	d0,d1 x,y
	lea	buffer(pc),a6
	moveq	#0,d5
	muls	#40,d1
	move.w	d0,d5
	and.b	#$f0,d5
	sub.w	d5,d0
	lsr.w	#3,d5
	add.l	d1,d5
	ror.w	#4,d0
	move.w	#$0bca,bltcon0(a6)	ACD an, Kopieren
	add.w	d0,bltcon0(a6)	+Verschiebung
	move.l	#$ffffffff,bltafwm(a6)	Maske
	moveq	#30,d7
	lsl.l	#6,d7
	addq.w	#3,d7
	moveq	#34,d1
	tst.w	d0		Verschiebung ?
	beq.s	.1
	subq.w	#2,d1
	addq.w	#1,d7
.1	move.w	d1,bltamod(a6)
	move.w	d1,bltdmod(a6)
	move.w	d1,bltcmod(a6)
	move.w	d7,bltsize(a6)
	moveq	#0,d0
	move.l	rastp1,a0
	move.l	4(a0),a0		BitMap
	move.b	5(a0),d0
	subq.b	#1,d0
	lea	8(a0),a0
	lea	aktfarbe,a5
	move.b	(a5),d1
	move.l	(a0)+,d7
	move.l	d7,d3
	move.l	d3,bltapth(a6)	von 0,0
copyloop2	add.l	d5,d7
	move.l	d7,bltdpth(a6)	nach x,y
	move.l	d7,bltcpth(a6)
	move.w	#$ffff,bltbdat(a6)
	move.l	(a0)+,d7
	move.b	d1,d2
	andi.b	#1,d2
	bne.s	copyein2
	move.w	#0,bltbdat(a6)
copyein2	lsr.b	#1,d1
	bsr	Startblitter
	dbra	d0,copyloop2
	movem.l	(sp)+,d0-a6
	bra	Clearblitter
*-------------------------------
line	movem.l	d0-a6,-(sp)	d0,d1 x d2,d3 y .w
	lea	buffer(pc),a6
	lea	Mittelpunkt,a5
	move.w	(a5)+,d1
	move.w	(a5),d3
	cmp.w	d0,d1
	bgt.s	.02
	beq.s	.01
	exg	d0,d1
	exg	d2,d3
	bra.s	.02
.01	cmp.w	d2,d3
	beq	Lineende
.02	move.l	#-1,bltafwm(a6)	Maske
	cmp.w	d2,d3
	bge.s	.03
	exg	d0,d1
	exg	d2,d3
.03	move.w	d1,d4		d0 dx
	sub.w	d0,d4
	move.w	d3,d6		d6 dy
	sub.w	d2,d6
	moveq	#0,d7		Oktant wird bestimmt
	tst.w	d4
	bpl.s	.06
	neg.w	d4
	cmp.w	d4,d6
	bge.s	.05
	moveq	#5,d7
	bra.s	.07
.05	moveq	#2,d7
	bra.s	.07
.06	cmp.w	d4,d6
	bge.s	.07
	moveq	#4,d7
.07	cmp.w	d4,d6
	bge.s	.08
	exg	d6,d4
.08	add.w	d7,d7		d7 Oktant*4 
	add.w	d7,d7
	addq.w	#1,d7
	add.w	d4,d4		d0 Klein*2
	move.w	d4,bltbmod(a6)	BltBMOD
	sub.w	d6,d4		Klein*2-Gro
	bgt.s	.09
	addi.w	#64,d7
.09	move.w	d4,bltaptl(a6)	Klein*-Gro BltAPtL
	sub.w	d6,d4
	move.w	d4,bltamod(a6)	Klein*2-Gro*2 BltAMOD
	move.w	#$8000,bltadat(a6)	BltADat
	moveq	#40,d4
	move.w	d4,bltcmod(a6)	BltCMod
	move.w	d4,bltdmod(a6)	BltDMod
	lsl.w	#3,d2		Adresse ausrechnen
	move.w	d2,d4
	add.w	d2,d2
	add.w	d2,d2
	add.w	d4,d2
	move.w	d2,d4
	move.w	d0,d2
	lsr.w	#4,d2		Verschiebung(x) ausrechnen
	add.w	d2,d2
	add.w	d2,d4
	lsl.w	#3,d2
	sub.w	d2,d0
	ror.w	#4,d0
	add.w	d0,d7
	move.w	d7,bltcon1(a6)
	move.w	#$bca,bltcon0(a6)	Überschreibt Hintergrund
	or.w	d0,bltcon0(a6)
	addq.w	#1,d6		Länge der Linie +1
	lsl.w	#6,d6
	addq.w	#2,d6
	move.w	d6,bltsize(a6)	BltSize
	ext.l	d4
	moveq	#0,d0
	move.l	rastp1,a0
	move.l	4(a0),a0		BitMap
	move.b	5(a0),d0
	subq.l	#1,d0
	lea	8(a0),a0
	lea	aktfarbe,a5
	move.b	(a5),d1	
lineloop2	move.l	(a0)+,d3
	add.l	d4,d3
	move.l	d3,bltcpth(a6)
	move.l	d3,bltdpth(a6)
	move.w	#$ffff,bltbdat(a6)
	move.b	d1,d2
	andi.b	#1,d2
	bne.s	lineein2
	move.w	#0,bltbdat(a6)
lineein2	lsr.b	#1,d1
	bsr.s	Startblitter
	dbra	d0,lineloop2
Lineende	movem.l	(sp)+,d0-a6
	bra.s	Clearblitter
*----------
Startblitter
	movem.l	d0/a0-a2,-(sp)	Startet den Blitter
	bsr.s	Waitblitter	lädt Bl.-Zwischenspeicher -> DMA
	lea	buffer(pc),a0
	lea	(DMABLT).l,a1
	move.l	a0,a2
	moveq	#5,d0
.01	move.l	(a0)+,(a1)+
	dbra	d0,.01
	addq.l	#8,a0
	addq.l	#8,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
	addq.l	#8,a1
	addq.l	#8,a0
	move.l	(a0)+,(a1)+
	move.w	(a0),(a1)
	move.w	$18(a2),$DFF058.l	StartBlitter(BltSize)
	movem.l	(sp)+,d0/a0-a2
	rts
*----------
Waitblitter
	btst.b	#14,$dff002.l
	bne.s	Waitblitter
	rts
*----------
Clearblitter
	movem.l	d0/d1/a0,-(sp)	löscht Blitter-Zwischenspeicher
	lea	buffer(pc),a0
	moveq	#0,d0
	moveq	#13,d1
.01	move.l	d0,(a0)+
	dbra	d1,.01
	movem.l	(sp)+,d0/d1/a0
	rts
*--------------------------------------------------
buffer	ds.b	$3a
Mittelpunkt
	dc.w	100,100
aktfarbe	dc.b	0,0
intname	dc.b	'intuition.library',0
intbase	dc.l	0
rastp1	dc.l	0
Screen_1	dc.l	0
Screens	dc.w	0,0,320,200,6,0,$80,$110f
	dc.l	0,0,0,0,ScreenTags
ScreenTags	dc.l	$80000032,$11080
	dc.l	0

