	SECTION		chipmemory,data_c	
							;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

MemRequired		equ	ScreenSize*Depth


	move.l	4.w,a6			;FIND EXEC BASE
	lea	gfxlib(pc),a1		;LOAD GRAPHICS LIBRARY IN A1
	moveq	#$00,d0			;VERSION 0
	jsr	-552(a6)		;OPEN LIBRARY
	move.l	d0,_gfxbase		;STORE D0 (GFX ADDRESS )
	beq	nolib_exit		;ELSE EXIT
	bsr	Foreground_addresses	;BRANCH TO FOREGROUND ADDRESSES
	bsr	Init
	bsr	Place_Char
	bsr	Get_Font
	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
	bsr	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			;FIND EXEC BASE
	move.l	_gfxbase,a1		;LOAD GRAPHICS BASE IN A1
	jsr	-414(a6)		;CLOSE LIBRARY
nolib_exit
	rts				;RETURN TO EDITER
Foreground_addresses			;START OF FOREGROUND DATA
	move.l	#Foreground,d0
	move.w	d0,Bpl0ptl		;LOW WORD IN BIT PLANE 0 LOW
	swap	d0				
	move.w	d0,Bpl0pth		;HIGH WORD IN BIT PLANE 0 HIGH
	swap	d0
	add.l	#ScreenSize,d0
	move.w	d0,Bpl1ptl		;LOW WORD IN BIT PLANE 2 LOW
	swap	d0				
	move.w	d0,Bpl1pth		;HIGH WORD IN BIT PLANE 2 HIGH
	swap	d0
	add.l	#ScreenSize,d0
	move.w	d0,Bpl2ptl		;LOW WORD IN BIT PLANE 4 LOW
	swap	d0				
	move.w	d0,Bpl2pth		;HIGH WORD IN BIT PLANE 4 HIGH
	swap	d0
	add.l	#ScreenSize,d0
	move.w	d0,Bpl3ptl		;LOW WORD IN BIT PLANE 4 LOW
	swap	d0				
	move.w	d0,Bpl3pth		;HIGH WORD IN BIT PLANE 4 HIGH
	swap	d0
	add.l	#ScreenSize,d0
	move.w	d0,Bpl4ptl		;LOW WORD IN BIT PLANE 4 LOW
	swap	d0				
	move.w	d0,Bpl4pth		;HIGH WORD IN BIT PLANE 4 HIGH
	swap	d0
	rts
Init
	move.l	#Foreground,d0
	add.l	#(100*Width)+20,d0
	move.l	d0,Timer_Address	; Address to put time
	move.w	#0,Count
	move.w	#0,Seconds
	move.w	#0,Seconds_10
	move.w	#0,Minute
	move.w	#0,Minute_10
	rts
Time
	add.w	#1,Count		; = to 1 second
	cmp.w	#150,Count
	bge	Second
	rts
Second
	move.w	#0,Count		; clear count
	add.w	#1,Seconds
	cmp.w	#10,Seconds
	beq	Second_10
	bsr	Place_Char
	bsr	Get_Font
	rts
Second_10
	move.w	#0,Seconds
	add.w	#1,Seconds_10
	cmp.w	#6,Seconds_10
	beq	Minutes
	bsr	Place_Char
	bsr	Get_Font
	rts
Minutes
	move.w	#0,Seconds_10
	add.w	#1,Minute
	cmp.w	#10,Minute
	beq	Minutes_10
	bsr	Place_Char
	bsr	Get_Font
	rts
Minutes_10
	move.w	#0,Minute
	add.w	#1,Minute_10
	cmp.w	#10,Minute_10
	beq	Reset
	bsr	Place_Char
	bsr	Get_Font
	rts
Reset
	move.w	#0,Minute_10
	rts
Place_Char
	moveq.l	#0,d0
	moveq.l	#0,d1
	move.w	Seconds,d0
	move.w	Seconds_10,d1
	move.w	#":",d4
	move.w	Minute,d2
	move.w	Minute_10,d3
	lsl.l	#8,d4
	lsl.l	#8,d2			; place Minute in place
	lsl.l	#8,d2			; 3rd byte of the long word
	lsl.l	#8,d3			; place Minute_10 in place
	lsl.l	#8,d3			; 4th byte of the long word
	lsl.l	#8,d3
	or.w	d4,d1
	or.l	d2,d1			; by or ing 
	or.l	d3,d1
	move.l	#Timer,a0
	move.l	d1,0(a0)
	move.b	d0,4(a0)
	rts
Get_Font
	moveq.l	#0,d0
	move.l	Timer_Address,a1	; address in a1
	move.l	#Timer,a0		;
	move.w	#1-1,d3			; number of planes -1
NoPlanes
        moveq	#5-1,d1     		; no of chars per line-1
LP1      
	;ILLEGAL
	move.b	(a0)+,d0
	cmp.b	#$3a,d0
	beq	Colon_it
        mulu	#8,d0		   	; to find font gfx
        lea	Number_Font(pc),a2	; font gfx in a2
	bsr	Blit_Font
	rts
Blit_Font
        add.l	d0,a2	         	; add offset
        moveq	#7,d2	         	; no of lines high font is
        move.l	a1,a3			; a3 now =address
LP2      
	move.b	(a2)+,(a3)	    	; font gfx into memory
        add.l	#40,a3	        	; add 1 line across
        dbra	d2,LP2	        	; loop till 0
        addq.l	#1,a1	         	; increase address by 1 byte
        dbra	d1,LP1	        	;	
	add.l	#ScreenSize,a1
	dbra	d3,NoPlanes
	rts
Colon_it
	moveq.l	#0,d0
	lea	Colon(pc),a2
	bsr	Blit_Font
	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
Timer_Address	dc.l	0
Count		dc.w	0
Seconds		dc.w	0
Seconds_10	dc.w	0
Minute		dc.w	0
Minute_10	dc.w	0
Timer		dc.l	0
		dc.l	0
	even

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,$0f0f

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

Number_Font
         DC.B      $7C,$C6,$CE,$DE,$F6,$E6,$7C,$00	;0
         DC.B      $38,$78,$18,$18,$18,$18,$7E,$00	;1
         DC.B      $7C,$C6,$06,$7C,$C0,$C0,$FE,$00	;2
         DC.B      $FC,$06,$06,$7C,$06,$06,$FC,$00	;3
         DC.B      $1C,$3C,$6C,$CC,$FE,$0C,$0C,$00	;4
         DC.B      $FE,$C0,$C0,$FC,$06,$06,$FC,$00	;5
         DC.B      $7E,$C0,$C0,$FC,$C6,$C6,$7C,$00	;6
         DC.B      $FE,$06,$06,$0C,$0C,$18,$18,$00	;7
         DC.B      $7C,$C6,$C6,$7C,$C6,$C6,$7C,$00	;8
         DC.B      $7C,$C6,$C6,$7E,$06,$06,$06,$00	;9
Colon
         DC.B      $00,$18,$18,$00,$00,$18,$18,$00	;:

Foreground
		dcb.b	ScreenSize*1,$00
		dcb.b	ScreenSize*1,$00
		dcb.b	ScreenSize*1,$00
		dcb.b	ScreenSize*1,$00
		dcb.b	ScreenSize*1,$00

