| 
| FreeMiNT memset function
| 
| This file belongs to FreeMiNT,
| it is not a part of the original MiNT distribution
| 
| 8.II.2000, draco@atari.org
| 
| 
| void * _mint_memset(void *s, int val, long len)
| 
	.text

	.globl	_memset

_memset:
	move.l	4(sp),a1
	move.l	10(sp),d2
	beq.s	L_exit
	move.l	a1,a0
	move.w	8(sp),d1
#ifdef ONLY030
	move.b	d1,d0		| expand d1 to longword
	lsl.w	#0x8,d1
	move.b	d0,d1
	move.w	d1,d0
	swap	d1
	move.w	d0,d1

	move.l	d2,d0
	lsr.l	#0x2,d0		| number of longwords
	beq.s	L_nolong
L_long:
	move.l	d1,(a0)+	| fill...
	subq.l	#0x1,d0
	bne.s	L_long
	move.l	d2,d0
	and.w	#0xfffc,d0
	sub.l	d0,d2

L_nolong:
	move.l	d2,d0		| fill remaining word...
	lsr.l	#0x1,d0
	beq.s	L_noword
	move.w	d1,(a0)+
	subq.l	#0x2,d2

L_noword:
	tst.l	d2		| ... and byte
	beq.s	L_exit
	move.b	d1,(a0)+
#else
L_byte:
	move.b	d1,(a0)+
	subq.l	#0x1,d2
	bne.s	L_byte
#endif
L_exit:
	move.l	a1,d0		| return value
	rts
