*	Displays a raw spectrum picture dump using only the COPPER.
*	The Copper changes the Bit plane pointer every scan line to
*	the correct address in the spectrum dump.

*	Left mouse button - exit
*	Right mouse button - invert current byte

*	The Copper list can be made smaller by using:
*	modulo=32*8=$100 on every char line eg (0,7,15...)

***	This means that for emulators, no blitting is needed
***	- the spectrum code writes directly to the amiga screen! 

*	Just discovered - this is how the KGB emulator does it,
*			  but the copperlist is about 1/10 the size.

execbase=4
openlib=-408
closelib=-414

Dmacon=$96
Vposr=$4
Vhposr=$6

*Move raw picture data
	lea data(pc),a0
	lea $70000,a1
	move.w #dataend-data,d0
	divu #4,d0
	
copy1:	move.l (a0)+,(a1)+
	subq #1,d0
	bne.s copy1

*Move start of copperlist		
	lea copper(pc),a0
	lea $68000,a1
	move.w #display-copper,d0
	divu #4,d0

copy2:	move.l (a0)+,(a1)+
	subq #1,d0
	bne.s copy2
	

build:	move.l #$4001fffe,d7
	move.l #$70000,d6	;spectrum pic data here
	move.l d6,d5
	moveq #2,d4		;3 thirds
	moveq #7,d3		;8 char lines / third
	moveq #7,d2		;8 lines / char line

line 	move.l d7,(a1)+
	move.w #$e0,(a1)+
	swap d5
	move.w d5,(a1)+
	move.w #$e2,(a1)+
	swap d5
	move.w d5,(a1)+		;put bp0 adr into cop list
	add.l #32*8,d5		;next line
	add.l #$1000000,d7	;next scan line
	dbf d2,line
	
	moveq #7,d2
	move.l d6,d5
	moveq #8,d1
	sub.b d3,d1
	mulu #32,d1		;next offset for char line
	add.l d1,d5
	dbf d3,line
	
	moveq #7,d3		;next third
	add.l #32*8*8,d6
	move.l d6,d5
	dbf d4,line
	
	move.l #$fffffffe,(a1)+	;copper end

	move.l execbase.w,a6
	lea gfxname(pc),a1
	moveq #0,d0
	jsr openlib(a6)
	move.l d0,a1
	move.l 38(a1),old
	jsr closelib(a6)

	lea $dff000,a6
waitvbl:
	btst #0,Vposr+1(a6)
	bne.s waitvbl
waitvbl2:
	cmp.b #0,Vhposr(a6)
	bne.s waitvbl2
	
	move.l #$68000,$dff080
	move.w #$83f0,Dmacon(a6)
	move.w #$0020,Dmacon(a6)

	lea $70000,a0
	moveq #0,d0
	
wait:	btst #6,$bfe001
	beq.s end
	btst #2,$dff016
	bne.s wait
	
	eor.b #$ff,(a0,d0)	;invert byte
	addq #1,d0
	cmp.w #32*192,d0
	bne.s ok
	moveq #0,d0
ok:	move.w #$80,d1
ok2:	dbf d1,ok2
	bra.s wait

end:	move.l old,$dff080
	move.w #$8020,Dmacon(a6)
	moveq #0,d0
	rts
	
gfxname:dc.b "graphics.library",0
	even 
old:	dc.l 0

copper:
	dc.w $100,$1200		;1 bp
	dc.w $102,$0		;scroll =0
	dc.w $92,$44		;ddfstrt
	dc.w $94,$b8		;ddfstop
	dc.w $8e,$4099		;diwstrt
	dc.w $90,$00a0		;diwstop 256 x 192
display

data:	incbin df1:speccy.pic.bin
dataend