2 ; Ullrich von Bassewitz, 2004-07-17
4 ; size_t __fastcall__ _heapblocksize (const void* ptr);
6 ; Return the size of an allocated block.
10 .export __heapblocksize
17 ;-----------------------------------------------------------------------------
22 ; Below the user data is a pointer that points to the start of the real
23 ; (raw) memory block. The first word of this block is the size. To access
24 ; the raw block pointer, we will decrement the high byte of the pointer,
25 ; the pointer is then at offset 254/255.
32 sta ptr2 ; Place the raw block pointer into ptr2
37 ; Load the size from the raw block
39 ldy #usedblock::size+1
42 .if (.cpu .bitand CPU_ISET_65SC02)
49 ; Correct the raw block size so that is shows the user visible portion. To
50 ; do that, we must decrease the size by the amount of unused memory, which is
51 ; the difference between the user space pointer and the raw memory block
52 ; pointer. Since we have decremented the user space pointer by 256, we will
53 ; have to correct the result.
55 ; return size - (ptr1 + 256 - ptr2)
56 ; return size - ptr1 - 256 + ptr2