]> git.sur5r.net Git - cc65/commitdiff
New function heapblocksize()
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 17 Jul 2004 12:05:36 +0000 (12:05 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 17 Jul 2004 12:05:36 +0000 (12:05 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3157 b7a2c559-68d2-44c3-8de9-860c34a00d81

include/stdlib.h
libsrc/common/Makefile
libsrc/common/_heapblocksize.s [new file with mode: 0644]

index eae18673675c499790f5e53958b4ca026ba0821f..f18421a414597445056927c264ce492b1011e404 100644 (file)
@@ -65,12 +65,16 @@ void __fastcall__ free (void* block);
 void __fastcall__ _heapadd (void* mem, size_t size);
 /* Add a block to the heap */
 
+size_t __fastcall__ _heapblocksize (const void* block);
+/* Return the size of an allocated block */
+
 size_t __fastcall__ _heapmemavail (void);
 /* Return the total free heap space */
 
 size_t __fastcall__ _heapmaxavail (void);
 /* Return the size of the largest free block on the heap */
 
+
 /* Random numbers */
 #define        RAND_MAX        0x7FFF
 int rand (void);
index 63e5a5b2cfee3f7832918ade729f4cea911d5687..312e6bf6a5a82d98affdd1851182e8e40c8020b6 100644 (file)
@@ -63,6 +63,7 @@ S_OBJS =      _cwd.o          \
                _fopen.o        \
                _heap.o         \
                        _heapadd.o      \
+                _heapblocksize.o\
                 _heapmaxavail.o \
                 _heapmemavail.o \
                _oserror.o      \
diff --git a/libsrc/common/_heapblocksize.s b/libsrc/common/_heapblocksize.s
new file mode 100644 (file)
index 0000000..8db62e0
--- /dev/null
@@ -0,0 +1,39 @@
+;
+; Ullrich von Bassewitz, 2004-07-17
+;
+; size_t __fastcall__ _heapblocksize (const void* ptr);
+;
+; Return the size of an allocated block.
+;
+
+       .importzp       ptr1
+               .export         __heapblocksize
+
+        .include        "_heap.inc"
+
+;-----------------------------------------------------------------------------
+; Code
+
+__heapblocksize:
+
+; Decrement the block pointer so it points to the admin data
+
+        sec
+        sbc     #HEAP_ADMIN_SPACE       ; Assume it's less than 256
+        bcs     L1
+        dex
+L1:     sta     ptr1
+        stx     ptr1+1
+
+; Load the size from the given block
+
+        ldy     #1
+        lda     (ptr1),y
+        tax
+        dey
+        lda     (ptr1),y
+
+; Done
+
+        rts
+