
#ifdef __GNUC_INLINE__
# ifndef __cplusplus

#if defined(__OPTIMIZE__) && (defined(m68k) || defined(mc68000))

/* in an optimizing run and if we are using an 680x0 processor,
   strcpy etc. will be defined as fast assembler routines */

static __inline__
char *
__strcpy(char *dst, const char *src)
{
	register char *base = dst;
	
	__asm__ volatile ( "\n\
0:	moveb	%1@+,%0@+	\n\
 	bne	0b		\n\
 	"
	: "=a" (dst), "=a" (src)
	: "0" (dst), "1" (src)
	);
	
	return( base );
}

static __inline__
char *
__strcat(char *dst, const char *src)
{
	register char *base = dst;
	
	__asm__ volatile ( "\n\
0:	tstb	%0@+		\n\
	bne	0b		\n\
 	subql	#1,%0		\n\
0:	moveb	%1@+,%0@+	\n\
	bne	0b		\n\
	"
	: "=a" (dst), "=a" (src)
	: "0" (dst), "1" (src)
	);
	
	return( base );
}

static __inline__
size_t
__strlen(const char *scan)
{
	register size_t start = (size_t)scan;
	
	__asm__ volatile ( "\n\
0:	tstb	%0@+		\n\
	bne	0b		\n\
	"
	: "=a" (scan)
	: "0" (scan)
	);
	
	return( (size_t)scan - start - 1 );
}

static __inline__
int
__strcmp(const char *s1, const char *s2)
{
	register int c1, c2;

	__asm__ volatile ( 
#ifdef __MSHORT__
	"\n\
	clrw	%0		\n\
	clrw	%1		\n\
1:	moveb	%2@+,%0		\n\
 	moveb	%3@+,%1		\n\
 	beq	0f		\n\
 	cmpb	%1,%0		\n\
 	beq	1b		\n\
 	subw	%1,%0		\n\
0:				\n\
	"
#else
	"\n\
	moveq	#0,%0		\n\
	moveq	#0,%1		\n\
1:	moveb	%2@+,%0		\n\
 	moveb	%3@+,%1		\n\
 	beq	0f		\n\
 	cmpb	%1,%0		\n\
 	beq	1b		\n\
	subl	%1,%0		\n\
0:				\n\
	"
#endif
	: "=d" (c1), "=d" (c2), "=a" (s1), "=a" (s2)
	: "2" (s1), "3" (s2)
	);
	
	return( c1 );
}

static __inline__
int
__strncmp(const char *s1, const char *s2, size_t n)

/* Attention: dbra works always with 16 bit, but size_t is 32 bit long!
   Therefor this version will not work with strings longer then 65536 Bytes!
*/

{
	register int c1, c2;

	__asm__ volatile (
#ifdef __MSHORT__
	"	clrw	%0		\n\
		clrw	%1		\n\
		subqw	#1,%4	\n\
		bmi	0f		\n\
	 1:	moveb	%2@+,%0		\n\
	 	moveb	%3@+,%1		\n\
	 	beq	0f		\n\
	 	cmpb	%1,%0		\n\
	 	dbne	%4,1b		\n\
	 	bne	0f		\n\
	 	movew	%1,%0		\n\
	 0:	subw	%1,%0		\n\
	"
#else
	"	moveq	#0,%0		\n\
		moveq	#0,%1		\n\
		subql	#1,%4		\n\
		bmi	0f		\n\
	 1:	moveb	%2@+,%0		\n\
	 	moveb	%3@+,%1		\n\
	 	beq	0f		\n\
	 	cmpb	%1,%0		\n\
	 	dbne	%4,1b		\n\
	 	bne	0f		\n\
	 	movel	%1,%0		\n\
	 0:	subl	%1,%0		\n\
	"
#endif
	: "=d" (c1), "=d" (c2), "=a" (s1), "=a" (s2), "=d" (n)
	: "2" (s1), "3" (s2), "4" (n)
	);
	
	return( c1 );
}

static __inline__
int
__streq(const char *s1, const char *s2)
{
	register unsigned char c;

	__asm__ volatile (
	"1:	moveb	%1@+,%0		\n\
		cmpb	%2@+,%0		\n\
		bne	0f		\n\
		tstb	%0		\n\
		bne	1b		\n\
	 0:	seq	%0		\n\
	"
	: "=d" (c), "=a" (s1), "=a" (s2)
	: "1" (s1), "2" (s2)
	);
		
	return( (int)c );
}

static __inline__
int
__strneq(const char *s1, const char *s2)
{
	register unsigned char c;

	__asm__ volatile (
	"1:	moveb	%2@+,%0		\n\
		beq	0f		\n\
		cmpb	%1@+,%0		\n\
		beq	1b		\n\
	 0:	seq	%0		\n\
	"
	: "=d" (c), "=a" (s1), "=a" (s2)
	: "1" (s1), "2" (s2)
	);
		
	return( (int)c );
}

#define strcat 	__strcat
#define strcpy 	__strcpy
#define strlen 	__strlen
#define strcmp	__strcmp
#define strncmp	__strncmp
#define streq	__streq
#define strneq	__strneq


#else /* if !(__OPTIMIZE__ && mc68000) */

static __inline__
char *
__strcat(char *dst, const char *src)
{
	register char *_dscan;

	for (_dscan = dst; *_dscan; _dscan++) ;
	while( (*_dscan++ = *src++) ) ;
	return dst;
}

static __inline__ 
char *
__strcpy(char *dst, const char *src)
{
	register char *_dscan = dst;
	while( (*_dscan++ = *src++) );
	return dst;
}

static __inline__
size_t
__strlen(const char *scan)
{
	register const char *_start = scan+1;
	while (*scan++) ;
	return (size_t)((long)scan - (long)_start);
}

#define strcat 	__strcat
#define strcpy 	__strcpy
#define strlen 	__strlen

#define streq(a,b)	(!strcmp(a,b))
#define strneq(a,b)	(!strncmp(a,b,strlen(b)))


#endif /* !(__OPTIMIZE__ && mc68000) */

# endif /* !__cplusplus */
#endif /* __GNUC_INLINE__ */

/* added by Roman Hodek 1/27/93 (Extension Lib) */

#define lastchar(p) (p[strlen(p)-1])


