From: cuz Date: Wed, 5 Jan 2005 21:05:11 +0000 (+0000) Subject: New used block structure for the heap X-Git-Tag: V2.12.0~489 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=842ff39d4ce86bf72e4d2b1bdde342522187fdb4;p=cc65 New used block structure for the heap git-svn-id: svn://svn.cc65.org/cc65/trunk@3347 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/common/_heapblocksize.s b/libsrc/common/_heapblocksize.s index 0a39f9abc..2be32fef4 100644 --- a/libsrc/common/_heapblocksize.s +++ b/libsrc/common/_heapblocksize.s @@ -6,7 +6,7 @@ ; Return the size of an allocated block. ; - .importzp ptr1 + .importzp ptr1, ptr2 .export __heapblocksize .include "_heap.inc" @@ -19,33 +19,57 @@ __heapblocksize: -; Decrement the block pointer so it points to the admin data +; Below the user data is a pointer that points to the start of the real +; (raw) memory block. The first word of this block is the size. To access +; the raw block pointer, we will decrement the high byte of the pointer, +; the pointer is then at offset 254/255. - sub #HEAP_ADMIN_SPACE ; Assume it's less than 256 - bcs L1 + sta ptr1 dex -L1: sta ptr1 stx ptr1+1 + ldy #$FE + lda (ptr1),y + sta ptr2 ; Place the raw block pointer into ptr2 + iny + lda (ptr1),y + sta ptr2+2 -; Load the size from the given block +; Load the size from the raw block - ldy #1 - lda (ptr1),y + ldy #usedblock::size+1 + lda (ptr2),y tax .if (.cpu .bitand CPU_ISET_65SC02) - lda (ptr1) + lda (ptr2) .else dey - lda (ptr1),y + lda (ptr2),y .endif -; Adjust it to the user visible size +; Correct the raw block size so that is shows the user visible portion. To +; do that, we must decrease the size by the amount of unused memory, which is +; the difference between the user space pointer and the raw memory block +; pointer. Since we have decremented the user space pointer by 256, we will +; have to correct the result. +; +; return size - (ptr1 + 256 - ptr2) +; return size - ptr1 - 256 + ptr2 - sub #HEAP_ADMIN_SPACE - bcs L9 - dex + dex ; - 256 + add ptr2 + pha + txa + adc ptr2+1 + tax + pla + sub ptr1 + pha + txa + sbc ptr1+1 + tax + pla ; Done -L9: rts + rts