mirror of
https://github.com/cc65/cc65.git
synced 2024-12-22 12:30:41 +00:00
New entry points for bzero and _bzero
git-svn-id: svn://svn.cc65.org/cc65/trunk@1277 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
4cb4751164
commit
009df2d6b5
@ -1,27 +1,50 @@
|
||||
;
|
||||
; void* memset (void* ptr, int c, size_t n);
|
||||
; void* _bzero (void* ptr, size_t n);
|
||||
; void bzero (void* ptr, size_t n);
|
||||
;
|
||||
; Ullrich von Bassewitz, 29.05.1998
|
||||
;
|
||||
; NOTE: bzero will return it's first argument as memset does. It is no problem
|
||||
; to declare the return value as void, since it may be ignored. _bzero
|
||||
; (note the leading underscore) is declared with the proper return type,
|
||||
; because the compiler will replace memset by _bzero if the fill value
|
||||
; is zero, and the optimizer looks at the return type to see if the value
|
||||
; in a/x is of any use.
|
||||
;
|
||||
|
||||
.export _memset
|
||||
.export _memset, _bzero, __bzero
|
||||
.import popax
|
||||
.importzp ptr1, ptr2, tmp1, tmp2, tmp3
|
||||
.importzp sp, ptr1, ptr2, ptr3, tmp1
|
||||
|
||||
_bzero:
|
||||
__bzero:
|
||||
sta ptr3
|
||||
stx ptr3+1 ; Save n
|
||||
lda #0
|
||||
sta tmp1 ; fill with zeros
|
||||
beq common
|
||||
|
||||
_memset:
|
||||
sta tmp1 ; Save n
|
||||
stx tmp2
|
||||
sta ptr3 ; Save n
|
||||
stx ptr3+1
|
||||
jsr popax ; Get c
|
||||
sta tmp3 ; Save c
|
||||
jsr popax ; Get ptr
|
||||
sta tmp1 ; Save c
|
||||
|
||||
; Common stuff for memset and bzero from here
|
||||
|
||||
common:
|
||||
ldy #1
|
||||
lda (sp),y
|
||||
tax
|
||||
dey
|
||||
lda (sp),y ; Get ptr
|
||||
sta ptr1
|
||||
stx ptr1+1 ; Save work copy
|
||||
sta ptr2
|
||||
stx ptr2+1 ; Save a copy for the function result
|
||||
lda tmp3
|
||||
|
||||
lda tmp1 ; Load fill value
|
||||
ldy #0
|
||||
ldx tmp2 ; Get high byte of n
|
||||
ldx ptr3+1 ; Get high byte of n
|
||||
beq L2 ; Jump if zero
|
||||
|
||||
; Set 256 byte blocks
|
||||
@ -36,8 +59,8 @@ L1: sta (ptr1),y ; Set one byte
|
||||
bne L1 ; Repeat if any
|
||||
|
||||
; Set the remaining bytes if any
|
||||
|
||||
L2: ldx tmp1 ; Get the low byte of n
|
||||
|
||||
L2: ldx ptr3 ; Get the low byte of n
|
||||
beq L9 ; Low byte is zero
|
||||
|
||||
L3: sta (ptr1),y ; Set one byte
|
||||
@ -45,8 +68,6 @@ L3: sta (ptr1),y ; Set one byte
|
||||
dex ; Done?
|
||||
bne L3
|
||||
|
||||
L9: lda ptr2 ; Load function result
|
||||
ldx ptr2+1
|
||||
rts
|
||||
L9: jmp popax ; Pop ptr and return as result
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user