]> git.sur5r.net Git - cc65/blob - libsrc/common/_heapadd.s
un-remove TABs in doc/using-make.sgml
[cc65] / libsrc / common / _heapadd.s
1 ;
2 ; Ullrich von Bassewitz, 21.7.2000
3 ;
4 ; Add a block to the heap free list
5 ;
6 ; void __fastcall__ _heapadd (void* mem, size_t size);
7 ;
8 ;
9
10         .importzp       ptr1, ptr2
11         .import         popax
12         .import         heapadd
13         .export         __heapadd
14
15         .include        "_heap.inc"
16
17         .macpack        generic
18
19 ;-----------------------------------------------------------------------------
20 ; Code
21
22 __heapadd:
23         sta     ptr1            ; Store size in ptr1
24         stx     ptr1+1
25         jsr     popax           ; Get the block pointer
26         sta     ptr2
27         stx     ptr2+1          ; Store block pointer in ptr2
28
29 ; Check if size is greater or equal than min_size. Otherwise we don't care
30 ; about the block (this may only happen for user supplied blocks, blocks
31 ; from the heap are always large enough to hold a freeblock structure).
32
33         lda     ptr1            ; Load low byte
34         ldx     ptr1+1          ; Load/check high byte
35         bne     @L1
36         cmp     #HEAP_MIN_BLOCKSIZE
37         bcs     @L1
38
39         rts                     ; Block not large enough
40
41 ; The block is large enough. Set the size field in the block.
42
43 @L1:    ldy     #usedblock::size
44         sta     (ptr2),y
45         iny
46         txa
47         sta     (ptr2),y
48
49 ; Call the internal function since variables are now setup correctly
50
51         jmp     heapadd
52