]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/strncpy.s
Replace hard returns with an "else", add an error for non-IDENT tokens, and test...
[cc65] / libsrc / common / strncpy.s
index 564814599f66c81ceabaf00d2e4e529cb8b46a17..56387f880b6c3344de45b4abde41a4e95d529de6 100644 (file)
@@ -4,9 +4,9 @@
 ; char* __fastcall__ strncpy (char* dest, const char* src, unsigned size);
 ;
 
-       .export         _strncpy
-       .import         popax
-       .importzp       ptr1, ptr2, tmp1, tmp2, tmp3
+        .export         _strncpy
+        .import         popax, popptr1
+        .importzp       ptr1, ptr2, tmp1, tmp2, tmp3
 
 .proc   _strncpy
 
         eor     #$FF
         sta     tmp2            ; Store -size - 1
 
-               jsr     popax           ; get src
-       sta     ptr1
-       stx     ptr1+1
-       jsr     popax           ; get dest
-       sta     ptr2
-       stx     ptr2+1
-               stx     tmp3            ; remember for function return
+        jsr     popptr1         ; get src
+        jsr     popax           ; get dest
+        sta     ptr2
+        stx     ptr2+1
+        stx     tmp3            ; remember for function return
 
 ; Copy src -> dest up to size bytes
 
         ldx     tmp1            ; Load low byte of ones complement of size
-       ldy     #$00
+        ldy     #$00
 L1:     inx
         bne     L2
         inc     tmp2
@@ -42,19 +40,21 @@ L2:     lda     (ptr1),y        ; Copy one character
         inc     ptr2+1          ; Bump high bytes
         bne     L1              ; Branch always
 
-; Fill the remaining bytes. 
+; Fill the remaining bytes.
 
-L3:     inx
-        bne     L4
-        inc     tmp2
-        beq     L9
-
-L4:     sta     (ptr2),y
-L5:     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