]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/malloc.s
Added author hint - as contained in the other source files.
[cc65] / libsrc / common / malloc.s
index fa1bd6e7c36143c1c762415efe7242fb893ec3b5..0f22090bbc5282028f311677cb54671bd02504f9 100644 (file)
@@ -214,7 +214,7 @@ TakeFromTop:
 
 BlockFound:
                bne     SliceBlock              ; Block is large enough to slice
-       cpx     #HEAP_MIN_BLOCKSIZE+1   ; Check low byte
+               cpx     #HEAP_MIN_BLOCKSIZE     ; Check low byte
                bcs     SliceBlock              ; Jump if block is large enough to slice
 
 ; The block is too small to slice it. Use the block in full. The block
@@ -309,17 +309,27 @@ SliceBlock:
        stx     ptr2
        sta     ptr2+1
 
-; Fill the size into the admin space of the block and return the user pointer
+; Fill the size and start address into the admin space of the block
+; (struct usedblock) and return the user pointer
 
 FillSizeAndRet:
-       ldy     #freeblock::size        ; *p = size;
-       lda     ptr1                    ; Low byte of block size
+       ldy     #usedblock::size        ; p->size = size;
+       lda     ptr1                    ; Low byte of block size
        sta     (ptr2),y
-       iny                             ; Points to freeblock::size+1
+       iny                             ; Points to freeblock::size+1
        lda     ptr1+1
        sta     (ptr2),y
 
 RetUserPtr:
+        ldy     #usedblock::start       ; p->start = p
+        lda     ptr2
+        sta     (ptr2),y
+        iny
+        lda     ptr2+1
+        sta     (ptr2),y
+
+; Return the user pointer, which points behind the struct usedblock
+
        lda     ptr2                    ; return ++p;
        ldx     ptr2+1
        add     #HEAP_ADMIN_SPACE