-----------------------------------------------------------------------
        FastPixels created for UGA PD by Brian Postma in 1989
-----------------------------------------------------------------------
start:	movem.l		d0-d7/a0-a6,-(a7)
	move.l		#plane,d0	;my bitplane
	lea		pl,a0		;copper planes
	move.w		d0,6(a0)	;in copperlist ->low word
	swap		d0
	move.w		d0,2(a0)	;and hi word
	lea		gfxname,a1	;OpenGraphics lib
	move.l		4,a6
	jsr		-408(a6)
	move.l		d0,gfxbase
	move.l		d0,a0		;Need graphics lib
	move.l		$32(a0),oldcop	;for pointer to
	move.l		#newcop,$32(a0)	;copperlist->my clist
	move.l		$6c,oldirq	;Save oldirq pointer
	move.l		#newirq,$6c	;my interrupt
wait:	btst		#6,$bfe001	;check for
	bne		wait		;left mouse-button
	move.l		oldirq,$6c	;oldirq pointer back
	move.l		gfxbase,a1	;old copper
	move.l		oldcop,$32(a1)	;pointer back
	move.l		4,a6		;and close
	jsr		-414(a6)	;the graphics library
	movem.l		(a7)+,d0-d7/a0-a6
	rts

newirq:	bsr		bounce
	dc.w		$4ef9		;code for JMP
oldirq:	dc.l		0		;to old irq

bounce:	move.w		x,d0		;x coord
	move.w		y,d1		;y coord
	move.w		#40,d2		;Screen width
	lea		plane,a0	;bitplane pointer
	bsr		clrpixel	;clear old
back:	move.w		dx,d0		;delta x
	add.w		d0,x		;new x coord
	move.w		dy,d0		;delta y
	add.w		d0,y		;new y coord
	tst.w		x		;left border reached
	ble		negx		;Yes ??
	cmpi.w		#319,x		;right border reached
	bge		negx		;Yes ??
	tst.w		y		;Top border reached
	ble		negy		;Yes ??
	cmpi.w		#255,y		;Bottom border reached
	bge		negy		;Yes ??
	move.w		x,d0		;x coord
	move.w		y,d1		;y coord
	move.w		#40,d2		;Screen width
	lea		plane,a0	;bitplane pointer
	bsr		writepixel	;Write new
	rts
negx:	neg.w		dx
	bra		back
negy:	neg.w		dy
	bra		back
x:	dc.w	100
y:	dc.w	200
dx:	dc.w	2
dy:	dc.w	-2

; d0=x coord, d1=y coord, a0 = pointer to bitplane
; d2=screen width in bytes
; no other registers are used
clrpixel:
	move.b		#$b0,l+1	;change bset to bclr
writepixel:
	mulu		d2,d1		;y coord*screenwidth
	add.l		d1,a0		;Y Position
	move.w		d0,d1		;save x coord
	lsr.w		#3,d1		;Divide by 8
	and.w		#7,d0		;Which Bit
	move.w		#7,d2		;substract from 7
	sub.w		d0,d2		;coz pixel 0 = bit 7
l:	bset		d2,(a0,d1.w)	;set it
	move.b		#$f0,l+1	;reset to bset
	rts

newcop:	dc.w	$0092,$0038,$0094,$00d0	;DFFStart,DFFStop
	dc.w	$008e,$296a,$0090,$29fa	;DIWStart,DIWStop
	dc.w	$0180,$0000,$0182,$0fff	;Colors
pl:	dc.w	$00e0,$0000,$00e2,$0000	;BitPlane 1 pointer
	dc.w	$0100,$1000		;Bitplane 1 On
	dc.w	$ffff,$fffe		;End of Copperlist

plane:	blk.b	10240,0			;256 lines x 40 bytes

oldcop:		dc.l	0
gfxbase:	dc.l	0
gfxname:	dc.b	"graphics.library",0
-----------------------------------------------------------------------
<Hi, Guys>

This little program features my fast writepixel routine (it's a lot
faster than the system routine 'WritePixel'). The routine can clear
pixels (jump to 'clrpixel') or write pixels (jump to 'writepixel'). The
routine needs a x-coord in D0, a y-coord in D1, the screensize in D2
and a pointer to a bitplane in A0. This one only works with 1 bitplane,
but it is very easy to rewrite it for more bitplanes (that's up to you)

Load the source from this disk named 'FastPixels.S' and assemble it
with an assembler (I used seka). You should 'run nofastmem' first when
you have 1 meg and don't have a version 2.0 or higher from seka. This
is because the copperlist must be in Chip-Mem.


Any comments, questions can be send to:

Brian Postma
J.v.Hartenstraat 51
7576 VX Oldenzaal
Tel:05410-14763
