2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 31.05.1998
|
2017-03-05 01:09:12 +00:00
|
|
|
; Christian Krueger: 12-Aug-2013, minor optimizations
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; char* strncat (char* dest, const char* src, size_t n);
|
|
|
|
;
|
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
.export _strncat
|
|
|
|
.import popax, popptr1
|
|
|
|
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
|
|
|
|
.macpack cpu
|
2017-03-05 10:38:55 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
_strncat:
|
2020-11-01 21:59:07 +00:00
|
|
|
inx
|
|
|
|
stx tmp2
|
|
|
|
tax
|
|
|
|
inx
|
|
|
|
stx tmp1 ; save count with each byte incremented separately
|
2017-03-05 01:09:12 +00:00
|
|
|
|
2018-05-20 13:30:18 +00:00
|
|
|
jsr popptr1 ; get src
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
jsr popax ; get dest
|
|
|
|
sta ptr3 ; remember for function return
|
|
|
|
stx ptr3+1
|
|
|
|
stx ptr2+1
|
|
|
|
tay ; low byte as offset in Y
|
|
|
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
|
|
|
stz ptr2
|
|
|
|
.else
|
|
|
|
ldx #0
|
|
|
|
stx ptr2 ; destination on page boundary
|
|
|
|
.endif
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
; find end of dest
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
L1: lda (ptr2),y
|
|
|
|
beq L2
|
|
|
|
iny
|
|
|
|
bne L1
|
|
|
|
inc ptr2+1
|
|
|
|
bne L1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
; end found, apply offset to dest ptr and reset y
|
|
|
|
L2: sty ptr2
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; copy src. We've put the ones complement of the count into the counter, so
|
|
|
|
; we'll increment the counter on top of the loop
|
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
L3: ldy #0
|
|
|
|
ldx tmp1 ; low counter byte
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2020-11-01 21:59:07 +00:00
|
|
|
L4: dex
|
2017-03-05 01:09:12 +00:00
|
|
|
bne L5
|
2020-11-01 21:59:07 +00:00
|
|
|
dec tmp2
|
2017-03-05 01:09:12 +00:00
|
|
|
beq L6 ; jump if done
|
|
|
|
L5: lda (ptr1),y
|
|
|
|
sta (ptr2),y
|
|
|
|
beq L7
|
|
|
|
iny
|
|
|
|
bne L4
|
|
|
|
inc ptr1+1
|
|
|
|
inc ptr2+1
|
|
|
|
bne L4
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
; done, set the trailing zero and return pointer to dest
|
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
L6: lda #0
|
|
|
|
sta (ptr2),y
|
|
|
|
L7: lda ptr3
|
|
|
|
ldx ptr3+1
|
|
|
|
rts
|