]> git.sur5r.net Git - cc65/blob - libsrc/common/_hadd.s
Reintroduce a patch for a bug that has been lost between version 1.2 and 1.3
[cc65] / libsrc / common / _hadd.s
1 ;
2 ; Ullrich von Bassewitz, 21.7.2000
3 ;
4 ; Add a block to the heap free list
5 ;
6 ; void __fastcall__ _hadd (void* mem, size_t size);
7 ;
8 ;
9
10         .importzp       ptr1, ptr2
11         .import         popax
12         .import         hadd
13         .export         _hadd
14
15         .macpack        generic
16
17 ; Offsets into struct freeblock and other constant stuff
18
19 size            = 0
20 next            = 2
21 prev            = 4
22 admin_space     = 2
23 min_size        = 6
24
25
26 ; Code
27
28 _hadd:  sta     ptr1            ; Store size in ptr1
29         stx     ptr1+1
30         jsr     popax           ; Get the block pointer
31         sta     ptr2
32         stx     ptr2+1          ; Store block pointer in ptr2
33
34 ; Check if size is greater or equal than min_size. Otherwise we don't care
35 ; about the block (this may only happen for user supplied blocks, blocks
36 ; from the heap are always large enough to hold a freeblock structure).
37
38         lda     ptr1            ; Load low byte
39         ldx     ptr1+1          ; Load/check high byte
40         bne     @L1
41         cmp     #min_size
42         bcs     @L1
43
44         rts                     ; Block not large enough
45
46 ; The block is large enough. Set the size field in the block.
47
48 @L1:    ldy     #size
49         sta     (ptr2),y
50         iny
51         txa
52         sta     (ptr2),y
53
54 ; Call the internal function since variables are now setup correctly
55
56         jmp     hadd
57
58
59