2 ; Ullrich von Bassewitz, 2003-05-04
4 ; char* __fastcall__ strncpy (char* dest, const char* src, unsigned size);
9 .importzp ptr1, ptr2, tmp1, tmp2, tmp3
17 sta tmp2 ; Store -size - 1
23 stx tmp3 ; remember for function return
25 ; Copy src -> dest up to size bytes
27 ldx tmp1 ; Load low byte of ones complement of size
34 L2: lda (ptr1),y ; Copy one character
36 beq L5 ; Bail out if terminator reached (A = 0)
40 inc ptr2+1 ; Bump high bytes
41 bne L1 ; Branch always
43 ; Fill the remaining bytes.
45 L3: inx ; Counter low byte
46 beq L6 ; Branch on overflow
47 L4: sta (ptr2),y ; Clear one byte
48 L5: iny ; Bump pointer
50 inc ptr2+1 ; Bump high byte
51 bne L3 ; Branch always
53 ; Bump the counter high byte
60 L9: lda ptr2 ; Get low byte
61 ldx tmp3 ; Get unchanged high byte