]> git.sur5r.net Git - cc65/blob - libsrc/common/_heapblocksize.s
New function heapblocksize()
[cc65] / libsrc / common / _heapblocksize.s
1 ;
2 ; Ullrich von Bassewitz, 2004-07-17
3 ;
4 ; size_t __fastcall__ _heapblocksize (const void* ptr);
5 ;
6 ; Return the size of an allocated block.
7 ;
8
9         .importzp       ptr1
10         .export         __heapblocksize
11
12         .include        "_heap.inc"
13
14 ;-----------------------------------------------------------------------------
15 ; Code
16
17 __heapblocksize:
18
19 ; Decrement the block pointer so it points to the admin data
20
21         sec
22         sbc     #HEAP_ADMIN_SPACE       ; Assume it's less than 256
23         bcs     L1
24         dex
25 L1:     sta     ptr1
26         stx     ptr1+1
27
28 ; Load the size from the given block
29
30         ldy     #1
31         lda     (ptr1),y
32         tax
33         dey
34         lda     (ptr1),y
35
36 ; Done
37
38         rts
39