]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/free.s
The spans do now contain the size of a span, no longer the end offset.
[cc65] / libsrc / common / free.s
index fe119d9ed9a2fd81ebf2f6b279420da82b7d8e4c..4ac96f1af67cc779d66252aca2440edd16280d20 100644 (file)
@@ -75,19 +75,16 @@ _free:      sta     ptr2
 ; Is the argument NULL? If so, bail out.
 
        ora     ptr2+1                  ; Is the argument NULL?
-               bne     @L0                     ; Jump if no
+               bne     @L1                     ; Jump if no
         rts                             ; Bail out if yes
 
 ; There's a pointer below the user space that points to the real start of the
-; raw block. The first word of the raw block is the total size of the block.
-; Remember the block size in ptr1.
-
-@L0:    lda    ptr2
-       sub     #2
-       sta     ptr2
-       bcs     @L1
-       dec     ptr2+1
-@L1:           ldy     #1
+; raw block. We will decrement the high pointer byte and use an offset of 254
+; to save some code. The first word of the raw block is the total size of the
+; block. Remember the block size in ptr1.
+
+@L1:    dec     ptr2+1                  ; Decrement high pointer byte
+       ldy     #$FF
         lda     (ptr2),y                ; High byte of real block address
         tax
         dey
@@ -277,6 +274,11 @@ _free:     sta     ptr2
 ;     }
 ; }
 ;
+; 
+; On entry, ptr2 must contain a pointer to the block, which must be at least
+; HEAP_MIN_BLOCKSIZE bytes in size, and ptr1 contains the total size of the
+; block.
+;
 
 ; Check if the free list is empty, storing _hfirst into ptr3 for later
 
@@ -333,7 +335,7 @@ SearchFreeList:
                dey                             ; Points to next
                lda     (ptr3),y                ; right = right->next;
        tax
-       iny                             ; Points to next+1
+       iny                             ; Points to next+1
        lda     (ptr3),y
        stx     ptr3
        sta     ptr3+1
@@ -497,13 +499,13 @@ CheckLeftMerge2:
 
 ; Do left->next->prev = left
 
-       iny                             ; Points to prev
+       iny                             ; Points to prev
        lda     ptr4                    ; Low byte of left
        sta     (ptr1),y
        iny
        lda     ptr4+1                  ; High byte of left
        sta     (ptr1),y
-       rts                             ; Done
+       rts                             ; Done
 
 ; This is now the last block, do _heaplast = left
 
@@ -517,7 +519,7 @@ CheckLeftMerge2:
 ; we come here. Do left->next = f.
 
 NoLeftMerge:
-       iny                             ; Points to next
+       iny                             ; Points to next
        lda     ptr2                    ; Low byte of left
        sta     (ptr4),y
        iny
@@ -526,13 +528,13 @@ NoLeftMerge:
 
 ; Do f->prev = left
 
-       iny                             ; Points to prev
+       iny                             ; Points to prev
        lda     ptr4
        sta     (ptr2),y
        iny
        lda     ptr4+1
        sta     (ptr2),y
-       rts                             ; Done
+       rts                             ; Done