]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/strncpy.s
The spans do now contain the size of a span, no longer the end offset.
[cc65] / libsrc / common / strncpy.s
index 3ba03301b1f792d59df5301dcbe9a1ef4d97bbab..21de3a15954824412f7d7a6a442bb585293c8c34 100644 (file)
@@ -35,26 +35,28 @@ L1:     inx
 
 L2:     lda     (ptr1),y        ; Copy one character
         sta     (ptr2),y
-        beq     L3              ; Bail out if terminator reached
+        beq     L5              ; Bail out if terminator reached (A = 0)
         iny
         bne     L1
         inc     ptr1+1
         inc     ptr2+1          ; Bump high bytes
         bne     L1              ; Branch always
 
-; Fill the remaining bytes. A is zero if we come here
+; Fill the remaining bytes.
 
-L3:     inx
-        bne     L4
-        inc     tmp2
-        beq     L9
-
-L4:     sta     (ptr2),y
-        iny
+L3:     inx                     ; Counter low byte
+        beq     L6              ; Branch on overflow
+L4:     sta     (ptr2),y        ; Clear one byte
+L5:     iny                     ; Bump pointer
         bne     L3
         inc     ptr2+1          ; Bump high byte
         bne     L3              ; Branch always
 
+; Bump the counter high byte
+
+L6:     inc     tmp2
+        bne     L4
+
 ; Done, return dest
 
 L9:     lda     ptr2            ; Get low byte