							;BY BLAINE EVANS
							;1 ERITH WAY
							;PONTYBODKIN
							;NR MOLD
							;CLWYD
							;CH7 4TR
							;TEL O352-771673
		Opt	C-,D+

Height			equ	256
Width			equ	40
Depth			equ	5

ScreenSize		equ	Height*Width
MemoryRequired		equ	ScreenSize*Depth

BlockHeight		equ	16
BlockWidth		equ	4
BlockSize		equ	BlockHeight*BlockWidth

	Move.l	4.w,a6			;FIND EXEC BASE
	Lea	Gfxlib(pc),a1		;LOAD GRAPHICS LIBRARY IN A1
	Moveq.l	#$00,d0			;VERSION 0
	Jsr	-552(a6)		;OPEN LIBRARY
	Move.l	d0,_Gfxbase		;STORE D0 (GFX ADDRESS )
	Beq.s	NoLib_Exit		;ELSE EXIT

	Move.l	4.w,a6
	Move.l	#MemoryRequired,d0	; Amount of memory
	Moveq.l	#2,d1			; Chip memory
	Jsr	-198(a6)		; Allocate memory
	Move.l	d0,ScreenPointer	; Save area of memory
	Beq.s	NoMem_Exit		; Error-End

	Bsr	Plane_Addresses		
	Bsr	Clear_Display
	Bsr	Build_Display

	Lea	$dff000,a6
	Move.l	_Gfxbase,a0		;LOAD ADDRESS OF GRAPHICS LIB IN A0
	Move.l	50(a0),Oldcop		;STORE CURRENT COPPER,ETC TO RETRIEVE LATER
S
	Move.l	#Newcop,50(a0)		;POINT TO OUR COPPERLIST

Wait					;WAIT LOOP
	Cmp.b	#255,$dff006		;VERTICAL BLANKING GAP 
	Bne.s	wait			;
;	Move.w	#$fff,$180(a6)		;REMove TO MEASURE RASTER TIME

;	Move.w	#$000,$180(a6)		;REMove TO MEASURE RASTER TIME
	Btst	#$6,$bfe001		;QUIT LEFT MOUSE PRESSED
	Bne.s	wait
Ended					;ELSE LOOP TO WAIT
	Move.l	_Gfxbase,a0		;LOAD GRAPHICS LIB ADDRESS IN A0
	Move.l	Oldcop,50(a0)		;RESTORE OLD COPPER TO RETURN TO EDITTER
NoMem_Exit	
	Move.l	4.w,a6
	Move.l	ScreenPointer,a1	; Address to release from
	Move.l	#MemoryRequired,d0	; Size to release
	Jsr	-210(a6)		; Free memory
NoLib_Exit
	Move.l	4.w,a6			;FIND EXEC BASE
	Move.l	_Gfxbase,a1		;LOAD GRAPHICS BASE IN A1
	Jsr	-414(a6)		;CLOSE LIBRARY
Exit
	Rts				;RETURN TO EDITER

Plane_Addresses				
	Move.l	ScreenPointer,d0	; Start of Screen Memory
	Lea	Planes,a0		; BitPlane Control Words
	Moveq.l	#(Depth)-1,d1		; Number of Planes-1
PlaneLoop
	Move.w	d0,6(a0)		; Low Word of Bit-Plane 
	Swap	d0				
	Move.w	d0,2(a0)		; High Word of Bit-Plane
	Swap	d0
	Add.l	#ScreenSize,d0
	Add.l	#8,a0			; Increment to Next Control Word
	DBra	d1,PlaneLoop
	Rts

Clear_Display
	Move.l	ScreenPointer,a0	; Start of Screen memory
	Move.l	#(MemoryRequired/4)-1,d0; Number of long words 
Clear
	Move.l	#0,(a0)+		; Transfer Data
	DBra	d0,Clear		; Loop till 0
	Rts

Build_Display
	Move.l	ScreenPointer,a2	; Start of Screen memory
	Move.l	#BlockGraphics,a1	; Start of Graphics
	Move.l	a2,a0			; Save Start Address
	Moveq.l	#(Depth)-1,d1
Depth1
	Move.l	#(BlockHeight)-1,d0; Number of long words 
Build
	Move.l	(a1)+,(a0)		; Transfer Data
	Add.w	#Width,a0
	DBra	d0,Build		; Loop till 0
	Move.l	a2,a0			; Restore Start of Plane Address
	Add.l	#ScreenSize,a0		; Next Plane
	Move.l	a0,a2			; Save Start of That Plane
	Dbra	d1,Depth1		; Loop till 0
	Rts

Gfxlib		Dc.b	"graphics.library",0	
	Even
_Gfxbase	Dc.l	0			;LONG WORD TO STORE GFX ADDRESS
Oldcop		Dc.l	0			;OLD COPPERLIST ADDRESS
ScreenPointer	Dc.l	0
	Even
	SECTION		chipmemory,data_c	


Newcop
	Dc.w	$0100,%0101001000000000		
	Dc.w	$0102
Scroll	Dc.w	$0000				;SCROLL VALUE
	Dc.w	$0104,%0000000000000001		;NO PRIORITIES
	Dc.w	$0108,$0000,$010a,$0000		;MODULAS
	Dc.w	$0092,$0038,$0094,$00d0		;256*40 SCREEN
	Dc.w	$008e,$2c81,$0090,$2cc1		;VISIBLE AREA
						
Planes
	Dc.w	$00e0
Bpl0pth	Dc.w	$0000,$00e2
Bpl0ptl	Dc.w	$0000,$00e4
Bpl1pth	Dc.w	$0000,$00e6
Bpl1ptl	Dc.w	$0000,$00e8
Bpl2pth	Dc.w	$0000,$00ea
Bpl2ptl	Dc.w	$0000,$00ec
Bpl3pth	Dc.w	$0000,$00ee
Bpl3ptl	Dc.w	$0000,$00f0
Bpl4pth	Dc.w	$0000,$00f2
Bpl4ptl	Dc.w	$0000,$00f4
Bpl5pth	Dc.w	$0000,$00f6
Bpl5ptl	Dc.w	$0000

Sprites						;SPRITES
	Dc.w	$0120
Spl0pth	Dc.w	$0000,$0122
Spl0ptl	Dc.w	$0000,$0124
Spl1pth	Dc.w	$0000,$0126
Spl1ptl	Dc.w	$0000
	Dc.w	$0128,$0000,$012a,$0000
	Dc.w	$012c,$0000,$012e,$0000
	Dc.w	$0130,$0000,$0132,$0000
	Dc.w	$0134,$0000,$0136,$0000
	Dc.w	$0138,$0000,$013a,$0000
	Dc.w	$013c,$0000,$013e,$0000

	Dc.w	$0180,$0000,$0182,$0fff		;COLORS PLAY 1
	Dc.w	$0184,$0d00,$0186,$0f80
	Dc.w	$0188,$0ff0,$018a,$00ff
	Dc.w	$018c,$008f,$018e,$0095

	Dc.w	$0190,$0000,$0192,$0283		;COLORS PLAY 2
	Dc.w	$0194,$08f4,$0196,$0095
	Dc.w	$0198,$0243,$019a,$00ff
	Dc.w	$019c,$0ff0,$019e,$0fa0

	Dc.w	$01a0,$0000,$01a2,$0fff		;SPRITE COLORS
	Dc.w	$01a4,$0f00,$01a6,$0b00
	Dc.w	$01a8,$0600,$01aa,$0F40
	Dc.w	$01ac,$0F80,$01ae,$0Fa0
	Dc.w	$01b0,$0Ff0,$01b2,$000f
	Dc.w	$01b4,$004f,$01b6,$008f
	Dc.w	$01b8,$00ff,$01ba,$00f0
	Dc.w	$01bc,$0283,$01be,$0f00

	Dc.w	$ffff,$fffe			;END OF COPPERLIST

BlockGraphics	Dcb.b	BlockSize*Depth,$ff

