 ; void memclear(const char *addr, unsigned int len)

 ; really does have to be an int for the length.
 ; NOTE: length must be <= $7fff. not much of a problem, do you
 ; ever need to zero out >= 32K of RAM at once?

 ; this is basically bzero(), but optimized for size, not speed.
 ; bzero() is around 2.3x as fast as this, but it's 3.3x as
 ; much code.

 .importzp ptr1, tmp1
 .import popptr1
 .export _memclear

_memclear:
 stx tmp1 ; hi byte of length
 tax      ; lo stays in X
 bne @len_ok
 lda tmp1
 beq @ret ; if len == 0, don't do anything (just return)
@len_ok:
 jsr popptr1 ; addr arg in ptr1. leaves X alone, sets Y=0
 tya ; A=0
@loop:
 sta (ptr1),y
 iny
 bne @y_ok
 inc ptr1+1
@y_ok:
 dex
 bne @loop
 dec tmp1
 bpl @loop
@ret:
 rts
