2003-02-01 12:22:09 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2003-02-01
|
|
|
|
;
|
|
|
|
; Return the size of the largest free block on the heap.
|
|
|
|
;
|
2012-03-04 13:08:54 +00:00
|
|
|
; size_t _heapmaxavail (void);
|
2003-02-01 12:22:09 +00:00
|
|
|
;
|
|
|
|
;
|
2022-04-17 14:06:22 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.importzp ptr1, ptr2
|
2022-08-29 17:55:48 +00:00
|
|
|
.export ___heapmaxavail
|
2003-02-01 12:22:09 +00:00
|
|
|
|
|
|
|
.include "_heap.inc"
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.macpack generic
|
2003-02-01 12:22:09 +00:00
|
|
|
|
|
|
|
;-----------------------------------------------------------------------------
|
|
|
|
; Code
|
|
|
|
|
2022-08-29 17:55:48 +00:00
|
|
|
___heapmaxavail:
|
2003-02-01 12:22:09 +00:00
|
|
|
|
|
|
|
; size_t Size = (_heapend - _heapptr) * sizeof (*_heapend);
|
|
|
|
|
2022-08-29 17:55:48 +00:00
|
|
|
lda ___heapend
|
|
|
|
sub ___heapptr
|
2003-02-01 12:22:09 +00:00
|
|
|
sta ptr2
|
2022-08-29 17:55:48 +00:00
|
|
|
lda ___heapend+1
|
|
|
|
sbc ___heapptr+1
|
2003-02-01 12:22:09 +00:00
|
|
|
sta ptr2+1
|
|
|
|
|
|
|
|
; struct freeblock* F = _heapfirst;
|
|
|
|
|
2022-08-29 17:55:48 +00:00
|
|
|
lda ___heapfirst
|
2003-02-01 12:22:09 +00:00
|
|
|
sta ptr1
|
2022-08-29 17:55:48 +00:00
|
|
|
lda ___heapfirst+1
|
2003-02-01 12:22:09 +00:00
|
|
|
@L1: sta ptr1+1
|
|
|
|
|
|
|
|
; while (F) {
|
|
|
|
|
|
|
|
ora ptr1
|
|
|
|
beq @L3 ; Jump if end of free list reached
|
|
|
|
|
|
|
|
; if (Size < F->size) {
|
|
|
|
|
2003-12-03 10:15:33 +00:00
|
|
|
ldy #freeblock::size
|
2003-02-01 12:22:09 +00:00
|
|
|
lda ptr2
|
|
|
|
sub (ptr1),y
|
|
|
|
iny
|
|
|
|
lda ptr2+1
|
|
|
|
sbc (ptr1),y
|
|
|
|
bcs @L2
|
|
|
|
|
|
|
|
; Size = F->size;
|
|
|
|
|
2003-12-03 10:15:33 +00:00
|
|
|
ldy #freeblock::size
|
2003-02-01 12:22:09 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
sta ptr2
|
|
|
|
iny
|
|
|
|
lda (ptr1),y
|
|
|
|
sta ptr2+1
|
|
|
|
|
|
|
|
; F = F->next;
|
|
|
|
|
2014-02-20 20:03:52 +00:00
|
|
|
@L2: iny ; Points to F->next
|
2003-02-01 12:22:09 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
tax
|
|
|
|
iny
|
|
|
|
lda (ptr1),y
|
|
|
|
stx ptr1
|
|
|
|
jmp @L1
|
|
|
|
|
2014-02-20 20:03:52 +00:00
|
|
|
; if (Size < HEAP_ADMIN_SPACE) return 0;
|
2003-02-01 12:22:09 +00:00
|
|
|
|
|
|
|
@L3: lda ptr2
|
2014-02-20 20:03:52 +00:00
|
|
|
sub #HEAP_ADMIN_SPACE
|
2003-02-01 12:22:09 +00:00
|
|
|
ldx ptr2+1
|
2014-02-20 20:03:52 +00:00
|
|
|
bcs @L5
|
|
|
|
bne @L4
|
|
|
|
txa
|
2003-02-01 12:22:09 +00:00
|
|
|
rts
|
2014-02-20 20:03:52 +00:00
|
|
|
|
|
|
|
; return Size - HEAP_ADMIN_SPACE;
|
|
|
|
|
|
|
|
@L4: dex
|
|
|
|
@L5: rts
|