
;---------------------------------------------
;	str_subi(str1,str2) - case insensitive substring finder
		xdef	_str_subi

_str_subi
		movem.l	d2/d4/d5/a2/a3,-(sp)

		move.l	24(sp),a2		; str1 currently at 24(sp) [20 + 4]
		move.l	a2,a0
		moveq	#-1,d4			; d4 has str_len of str1
5$		addq.l	#1,d4
		tst.b	(a0)+
		bne.s	5$

		move.l	28(sp),a3		; str2 currently at 28(sp) [20 + 8]
		move.l	a3,a0
		moveq	#-1,d5
6$		addq.l	#1,d5			; d5 has str_len of str2
		tst.b	(a0)+
		bne.s	6$

2$		cmp.l	d5,d4			; is str2 longer than whats left of str1?
		blt.s	1$				; yes, exit loop

		subq.l	#1,d4			; reduce str1 length

		move.l	a2,a0			; do a str_ncmp
		addq.w	#1,a2			; increment address
		move.l	a3,a1
		move.l	d5,d2
		bra.s	11$

10$		move.b	(a0)+,d1		; are current bytes different?
		cmp.b	#'a',d1
		blt.s	20$
		sub.b	#'a'-'A',d1
20$		move.b	(a1)+,d0
		cmp.b	#'a',d0
		blt.s	21$
		sub.b	#'a'-'A',d0
21$		sub.b	d1,d0
		bne.s	2$				; yes, so failed on this check

11$
	ifnd	BIGSTRING
		dbra	d2,10$			; continue loop
	else
		subq.w	#1,d2
		bpl.s	10$
	endc

		move.l	a2,d0			; found a match, so save as return value
		subq.l	#1,d0			; but we did increment it
		bra.s	4$

1$		moveq	#0,d0
4$		movem.l (sp)+,d2/d4/d5/a2/a3
		rts
