]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/free.s
Changed the way, used blocks are managed
[cc65] / libsrc / common / free.s
index 8c39bef78812c894f9b4dce5d1e8e68ffb14e8a4..fe119d9ed9a2fd81ebf2f6b279420da82b7d8e4c 100644 (file)
 _free:         sta     ptr2
        stx     ptr2+1                  ; Save block
 
-; Is the argument NULL?
+; Is the argument NULL? If so, bail out.
 
        ora     ptr2+1                  ; Is the argument NULL?
-               beq     @L9                     ; Jump if yes
+               bne     @L0                     ; Jump if no
+        rts                             ; Bail out if yes
 
-; Decrement the given pointer by the admin space amount, so it points to the
-; real block allocated. The size of the block is stored in the admin space.
+; 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.
 
-       lda     ptr2
-       sub     #HEAP_ADMIN_SPACE
+@L0:    lda    ptr2
+       sub     #2
        sta     ptr2
        bcs     @L1
        dec     ptr2+1
-@L1:   ldy     #freeblock::size+1
+@L1:           ldy     #1
+        lda     (ptr2),y                ; High byte of real block address
+        tax
+        dey
+        lda     (ptr2),y
+        stx     ptr2+1
+        sta     ptr2                    ; Set ptr2 to start of real block
+
+        ldy     #usedblock::size+1
        lda     (ptr2),y                ; High byte of size
-       sta     ptr1+1                  ; Save it
+               sta     ptr1+1                  ; Save it
        dey
        lda     (ptr2),y
        sta     ptr1
@@ -261,7 +270,7 @@ _free:      sta     ptr2
 ;              }
 ;          } else {
 ;              f->prev = 0;
-;              /* Special case: This is the new freelist start */
+;              /* Special case: This is the new freelist start */
 ;              _hfirst = f;
 ;          }
 ;      }
@@ -530,3 +539,4 @@ NoLeftMerge:
 
 
 
+