]> git.sur5r.net Git - cc65/commitdiff
Sqeezed a few bytes out of the copydata function
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 1 Dec 2004 12:00:50 +0000 (12:00 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 1 Dec 2004 12:00:50 +0000 (12:00 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3320 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/common/copydata.s

index 10f409ca9d69d4425b5f4fb2ad7fb8d420f7261a..b0a9987fdf887bda61d55bd93c7073a29ee5da4a 100644 (file)
@@ -1,53 +1,49 @@
 ;
-; Ullrich von Bassewitz, 07.12.1998
+; Ullrich von Bassewitz, 1998-12-07, 2004-12-01
 ;
 ; Copy the data segment from the LOAD to the RUN location
 ;
 
        .export         copydata
        .import         __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
-       .importzp       ptr1, ptr2
+       .importzp       ptr1, ptr2, tmp1
 
 
 copydata:
-       lda     #<__DATA_LOAD__ ; Source pointer
+       lda     #<__DATA_LOAD__         ; Source pointer
        sta     ptr1
        lda     #>__DATA_LOAD__
        sta     ptr1+1
 
-       lda     #<__DATA_RUN__  ; Target pointer
+       lda     #<__DATA_RUN__          ; Target pointer
        sta     ptr2
        lda     #>__DATA_RUN__
        sta     ptr2+1
 
-       ldy     #$00
-       ldx     #>__DATA_SIZE__ ; Get page count
-       beq     @L2             ; No full pages
+        ldx     #<~__DATA_SIZE__
+        lda     #>~__DATA_SIZE__        ; Use -(__DATASIZE__+1)
+        sta     tmp1
+        ldy     #$00
 
-; Copy full pages
+; Copy loop
 
-@L1:   lda     (ptr1),y
-       sta     (ptr2),y
-       iny
-       bne     @L1
-       inc     ptr1+1
-       inc     ptr2+1          ; Bump pointers
-       dex
-       bne     @L1
+@L1:    inx
+        beq     @L3
 
-; Copy last page (remember: y contains zero)
+@L2:    lda    (ptr1),y
+        sta    (ptr2),y
+        iny
+        bne     @L1
+        inc    ptr1+1
+        inc    ptr2+1                  ; Bump pointers
+        bne    @L1                     ; Branch always (hopefully)
 
-@L2:   ldx     #<__DATA_SIZE__ ; Get remaining bytes
-       beq     @L4
+; Bump the high counter byte
 
-@L3:   lda     (ptr1),y
-       sta     (ptr2),y
-       iny
-       dex
-       bne     @L3
+@L3:    inc     tmp1
+        bne     @L2
 
 ; Done
 
-@L4:   rts
-
+        rts