
**********************************************************
rxmin:	equ	96
rxmax:	equ	303
rymin:	equ	10
rymax:	equ	100
reccolor:	blk.w	1,0
**********************************************************
*	my filled rectangle routine
**********************************************************
rectangle:
	movem.l	d0-d7/a0-a4,-(sp)
	move.w	x1,d2		;get x do clipping
	move.w	y1,d0		;get y
	move.w	x2,d4		;get x do clipping
	move.w	y2,d6		;get y

	cmpi.w	#rxmin,d2
	bgt	rclip1
	move.w	#rxmin,d2
	bra	rclip2

rclip1:	cmpi.w	#rxmax,d2
	blt	rclip2
	bra	recback
			;none visible
rclip2:	cmpi.w	#rymin,d0
	bgt	rclip3
	move.w	#rymin,d0
	bra	rclip4		
rclip3:
	cmpi.w	#rymax,d0
	blt	rclip4
	bra	recback

rclip4:
	cmpi.w	#rxmin,d4
	bgt	rclip5
	bra	recback

rclip5:	cmpi.w	#rxmax,d4
	blt	rclip6
	move.w	#rxmax,d4

rclip6:	cmpi.w	#rymin,d6
	bgt	rclip7
	bra	recback

rclip7:
	cmpi.w	#rymax,d6
	blt	rclip8
	move.w	#rymax,d6
rclip8:
	move.w	d2,x1
	move.w	d4,x2	
	move.w	reccolor,d7
	bsr	init_hcol
	move.l	ytable,a0	;add of tab with y addresses
	move.w	d0,d1		;get a copy of it
	lsl.w	#2,d0		;mult by 4
	move.l	(a0,d0.w),a0	;a0 has add of start of line
	move.w	d2,d3		;make a copy x1
	and.w	#$fff0,d2
	lsr.w	#1,d2	
	add.w	d2,a0		;a0 has add of start of line
	move.w	d4,d5		;d5 has x2
	and.w	#$fff0,d4
	lsr.w	#4,d4
	move.w	d3,d2
	and.w	#$fff0,d2
	lsr.w	#4,d2
	sub.w	d2,d4		;gives number of words across
	sub.w	d1,d6		;gives number of y
	move.l	#endmask,a1
	and.w	#15,d3
	lsl.w	#1,d3
	move.w	(a1,d3.w),d0	;d0 start mask
	move.l	#startmask,a1
	and.w	#15,d5
	lsl.w	#1,d5
	move.w	(a1,d5.w),d1	;d1 end mask
	move.l	a0,a1
*	draw the start section
	subq.w	#1,d6
drawlineloop:
	bsr	drawhline
	adda.l	#160,a1
	move.l	a1,a0
	dbf	d6,drawlineloop
recback:
	movem.l	(sp)+,d0-d7/a0-a4
	rts

*******************
*	d0=start mask
*	d1=end mask
*	d4=words across may have to sub 1 or 2 ????
*	d6=number of y positions
*	a0=start address
*	a1=copy of a0
*	a3=color table
*******************
drawhline:
*	move.w	x2,d3
*	sub.w	x1,d3
*ble	allline	
	cmpi.w	#1,d4
	blt	allline
	beq	spechline
	bsr	drawstart
	bsr	drawmid
	bsr	drawend
	rts

spechline:
	bsr	drawstart
	bsr	drawend
	rts

drawstart:
	move.w	d0,d7
	not	d7
	and.w	d0,(a0)
	move.w	(a3),d5
	and.w	d7,d5
	or	d5,(a0)+

	and.w	d0,(a0)
	move.w	2(a3),d5
	and.w	d7,d5
	or	d5,(a0)+

	and.w	d0,(a0)
	move.w	4(a3),d5
	and.w	d7,d5
	or	d5,(a0)+

	and.w	d0,(a0)
	move.w	6(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	rts
*******************
*	d0=start mask
*	d1=end mask
*	d4=words across may have to sub 1 or 2 ????
*	d6=number of y positions
*	a0=start address
*	a1=copy of a0
*	a3=color table
*******************
drawmid:
	move.w	d4,d2	;copy width
	subq.w	#2,d2
dml:
	move.w	(a3),(a0)+
	move.w	2(a3),(a0)+
	move.w	4(a3),(a0)+
	move.w	6(a3),(a0)+
	dbf	d2,dml
	rts
drawend:
	move.w	d1,d7
	not	d7
	and.w	d1,(a0)
	move.w	(a3),d5
	and.w	d7,d5
	or	d5,(a0)+

	and.w	d1,(a0)
	move.w	2(a3),d5
	and.w	d7,d5
	or	d5,(a0)+

	and.w	d1,(a0)
	move.w	4(a3),d5
	and.w	d7,d5
	or	d5,(a0)+

	and.w	d1,(a0)
	move.w	6(a3),d5
	and.w	d7,d5
	or	d5,(a0)+
	rts
drhs:
	bsr	drawstart
	bra	drawend

allline:
*	move.w	$cccc,(a0)
*	rts
	move.w	x1,d2
	and.w	#15,d2
	move.w	x2,d5
	and.w	#15,d5
*	addq.w	#1,d5
	add.w	d2,d2
	add.w	d5,d5
*	cmp.w	d2,d5
*	bmi	drhs

	move.l	#startmask,a4
	move.w	(a4,d2.w),d0	
	move.l	#endmask,a4
	and.w	(a4,d5.w),d0	
	move.w	d0,d7
	not	d7

	and.w	d7,(a0)
	move.w	(a3),d5
	and.w	d0,d5
	or	d5,(a0)+

	and.w	d7,(a0)
	move.w	2(a3),d5
	and.w	d0,d5
	or	d5,(a0)+

	and.w	d7,(a0)
	move.w	4(a3),d5
	and.w	d0,d5
	or	d5,(a0)+

	and.w	d7,(a0)
	move.w	6(a3),d5
	and.w	d0,d5
	or	d5,(a0)+
	rts

startmask:
	dc.w	$ffff,$7fff,$3fff,$1fff
	dc.w	$0fff,$07ff,$03ff,$01ff
	dc.w	$00ff,$007f,$003f,$001f
	dc.w	$000f,$0007,$0003,$0001
	dc.w	$0000
endmask:
	dc.w	$0000,$8000,$c000,$e000
	dc.w	$f000,$f800,$fc00,$fe00
	dc.w	$ff00,$ff80,$ffc0,$ffe0
	dc.w	$fff0,$fff8,$fffc,$fffe
	dc.w	$ffff

patmsk:	dc.w	$cccc
	dc.w	$3333

***************************************************************************
*               INITIALISE HORIZONTAL LINE COLOUR
*               On entry,     D0 = a3 number
*               On exit , a3 = a3 start address
*       Initialise the a3 pointer to the correct a3 planes.
************************************************************************
init_hcol:
		asl.w   #3,D7		;index a3 table
                lea     col_table,a3
                lea     (a3,D7.w),a3 
                rts
                
col_table:
		DC.w      00,00,00,00     ;Colour 0
                DC.w      -1,00,00,00     ;Colour 1
                DC.w      00,-1,00,00     ;Colour 2
                DC.w      -1,-1,00,00     ;Colour 3
                DC.w      00,00,-1,00     ;Colour 4        
                DC.w      -1,00,-1,00     ;Colour 5        
                DC.w      00,-1,-1,00     ;Colour 6        
                DC.w      -1,-1,-1,00     ;Colour 7        
                DC.w      00,00,00,-1     ;Colour 8        
                DC.w      -1,00,00,-1     ;Colour 9
                DC.w      00,-1,00,-1     ;Colour 10
                DC.w      -1,-1,00,-1     ;Colour 11
                DC.w      00,00,-1,-1     ;Colour 12
                DC.w      -1,00,-1,-1     ;Colour 13
                DC.w      00,-1,-1,-1     ;Colour 14       
                DC.w      -1,-1,-1,-1     ;Colour 15

