2 ; void* memset (void* ptr, int c, size_t n);
3 ; void* _bzero (void* ptr, size_t n);
4 ; void bzero (void* ptr, size_t n);
6 ; Ullrich von Bassewitz, 29.05.1998
8 ; NOTE: bzero will return it's first argument as memset does. It is no problem
9 ; to declare the return value as void, since it may be ignored. _bzero
10 ; (note the leading underscore) is declared with the proper return type,
11 ; because the compiler will replace memset by _bzero if the fill value
12 ; is zero, and the optimizer looks at the return type to see if the value
13 ; in a/x is of any use.
16 .export _memset, _bzero, __bzero
18 .importzp sp, ptr1, ptr2, ptr3, tmp1
25 sta tmp1 ; fill with zeros
34 ; Common stuff for memset and bzero from here
43 stx ptr1+1 ; Save work copy
45 lda tmp1 ; Load fill value
47 ldx ptr3+1 ; Get high byte of n
52 L1: sta (ptr1),y ; Set one byte
54 sta (ptr1),y ; Unroll this a bit to make it faster
58 dex ; Next 256 byte block
59 bne L1 ; Repeat if any
61 ; Set the remaining bytes if any
63 L2: ldx ptr3 ; Get the low byte of n
64 beq L9 ; Low byte is zero
66 L3: sta (ptr1),y ; Set one byte
71 L9: jmp popax ; Pop ptr and return as result