*******************************************************************************
* NiPPY-ZiPPY $1.01 (aSSeMBLY-sOURCE-cODE!)
* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
* After seeing "Turbo Zippy`s" claims to be the fastest MC68k search routine
* ever to be devised I looked at it with interest. Does it live upto its claims
* to be the FASTEST search ever?? NO!!! Introducing "NiPPY-ZiPPY"... Now I
* myself *WONT* make any foolish claims that *MY* search routine is the fastest
* ever made like "Turbo Zippy" did but I will say that my one is MUCH MUCH 
* faster that Turbo Zippy`s search routine ever dreamed of being!
*
* "NiPPY-ZiPPY" reaches search speeds of around 700kb per second!!!
* Tested on a standard A12oo, 14Mz MC68o2o without fastmem. As I cannot be
* bothered to write an Ami-Express "Z"ippy door at the moment I have decided
* to release my search routine for all to see. Hopefully someone will bother
* to use the searching source in their zippy door and you`ll be searching like
* you never searched before...VIRTUALLY INSTANTLY (hehe)
*
* Okay so the code isn`t very well structured and could be reduced in size
* but I could only see reductions in the code size slowing down the search
* routine... 2k isn`t that bad... Think of it this way.. if it where written
* in C it would be the same size and STILL be slow.. (hahaha)
*
* INPUTS ;	a0.l=start address for search
*	 	a1.l=end address for search
*	 	a2.l=string to search for
*
* OUTPUTS;	d0.b=If failed to located string =$FF.B, else =$00.B FOUND!
*		a0.l=ptr to string
*******************************************************************************
cmp4bytesd2:	macro
		cmp.b	(a0)+,d2		;do these 4 bytes match source?
		beq.s	\1
		cmp.b	(a0)+,d2		;do these 4 bytes match source?
		beq.s	\1
		cmp.b	(a0)+,d2		;do these 4 bytes match source?
		beq.s	\1
		cmp.b	(a0)+,d2		;do these 4 bytes match source?
		beq.s	\1
		endm
cmp32bytes	macro
		cmp4bytesd2 .yup
		cmp4bytesd2 .yup
		cmp4bytesd2 .yup
		cmp4bytesd2 .yup
		cmp4bytesd2 .yup
		cmp4bytesd2 .yup
		cmp4bytesd2 .yup
		cmp4bytesd2 .yup
		bra.s	\1
.yup:		move.l	d4,d3
.cmp:		cmpm.b	(a2)+,(a0)+
		dbne	d3,.cmp
		bne.w	_Not_It
		sub.l	d6,a0
		rts
		endm

ExampleCall:	lea	$0.w,a0			;a0=start addr for search
		lea	$1a0000.l,a1		;a2=end addr for search
		lea	string(pc),a2		;a3=string to search for
		bsr.s	Search	
		rts

string:		dc.b	"STRING",0
		cnop	0,8			;longword align

Search:		move.l	a2,a3
		moveq	#-3,d4			;d4=0
.getlen		addq.l	#1,d4			;increase string length by 1
		tst.b	(a2)+			;increase position
		bne.s	.getlen			;nope not found, so keep on
		move.l	a3,a2
		move.l	d4,d6
		addq.l	#2,d6
		moveq	#0,d5			;d5=0
		move.b	(a2)+,d2
_Not_It		move.l	a3,a2			;a3=search string ptr
		tst.b	(a0)+			;incr search pos
		tst.b	(a2)+
_contt		lea	-512(a1),a4		;>512 bytes left to search?
		cmp.l	a4,a0
		blt.s	fastcmp			;if so do a 512 byte search...
_cmpcontt	cmp.b	(a0)+,d2		;does this byte match string byte?
		beq.s	_nbyte			;yes!,lets investigate more...
		cmp.l	a1,a0			;end of Memory region reached?
		blt.s	_cmpcontt		;yes,so string wasn`t found!
		st	d0			;d0=not found!
		rts
_nbyte:		move.l	d4,d3
_nloop:		cmpm.b	(a2)+,(a0)+
		dbne	d3,_nloop
		bne.s	_Not_It
		sub.l	d6,a0
		rts
fastcmp		cmp32bytes _1			;test 512 Bytes FAAAAST
_1		cmp32bytes _2
_2		cmp32bytes _3
_3		cmp32bytes _4
_4		cmp32bytes _5
_5		cmp32bytes _6
_6		cmp32bytes _7
_7		cmp32bytes _8
_8		cmp32bytes _9
_9		cmp32bytes _10
_10		cmp32bytes _11
_11		cmp32bytes _12
_12		cmp32bytes _13
_13		cmp32bytes _14
_14		cmp32bytes _15
_15		cmp32bytes _16
_16		cmp.l	a4,a0
		blt.w	fastcmp
		bra.w	_cmpcontt

		end
