2000-07-21 21:36:06 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 21.7.2000
|
|
|
|
;
|
|
|
|
; Add a block to the heap free list
|
|
|
|
;
|
2003-02-01 10:20:35 +00:00
|
|
|
; void __fastcall__ _heapadd (void* mem, size_t size);
|
2000-07-21 21:36:06 +00:00
|
|
|
;
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.importzp ptr1, ptr2
|
|
|
|
.import popax
|
|
|
|
.import heapadd
|
2022-08-29 17:55:48 +00:00
|
|
|
.export ___heapadd
|
2000-07-21 21:36:06 +00:00
|
|
|
|
2003-02-01 12:22:09 +00:00
|
|
|
.include "_heap.inc"
|
2000-07-21 21:36:06 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.macpack generic
|
2000-07-21 21:36:06 +00:00
|
|
|
|
2003-02-01 12:22:09 +00:00
|
|
|
;-----------------------------------------------------------------------------
|
2000-07-21 21:36:06 +00:00
|
|
|
; Code
|
|
|
|
|
2022-08-29 17:55:48 +00:00
|
|
|
___heapadd:
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr1 ; Store size in ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
jsr popax ; Get the block pointer
|
|
|
|
sta ptr2
|
|
|
|
stx ptr2+1 ; Store block pointer in ptr2
|
2000-07-21 21:36:06 +00:00
|
|
|
|
|
|
|
; Check if size is greater or equal than min_size. Otherwise we don't care
|
|
|
|
; about the block (this may only happen for user supplied blocks, blocks
|
|
|
|
; from the heap are always large enough to hold a freeblock structure).
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda ptr1 ; Load low byte
|
|
|
|
ldx ptr1+1 ; Load/check high byte
|
|
|
|
bne @L1
|
|
|
|
cmp #HEAP_MIN_BLOCKSIZE
|
|
|
|
bcs @L1
|
2000-07-21 21:36:06 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
rts ; Block not large enough
|
2000-07-21 21:36:06 +00:00
|
|
|
|
|
|
|
; The block is large enough. Set the size field in the block.
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
@L1: ldy #usedblock::size
|
|
|
|
sta (ptr2),y
|
|
|
|
iny
|
|
|
|
txa
|
|
|
|
sta (ptr2),y
|
2000-07-21 21:36:06 +00:00
|
|
|
|
|
|
|
; Call the internal function since variables are now setup correctly
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
jmp heapadd
|
2000-07-21 21:36:06 +00:00
|
|
|
|