Move _heap.h to the compiler include dir.
Create heap.inc and use that from the assembler code. Rename heap related _h... variables to _heap... Add _heapmaxavail and _heapmemavail functions. git-svn-id: svn://svn.cc65.org/cc65/trunk@1912 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
81
libsrc/common/_heapmemavail.s
Normal file
81
libsrc/common/_heapmemavail.s
Normal file
@@ -0,0 +1,81 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 2003-02-01
|
||||
;
|
||||
; Return the amount of free memory on the heap.
|
||||
;
|
||||
; size_t __fastcall__ _heapmemavail (void);
|
||||
;
|
||||
;
|
||||
|
||||
.importzp ptr1, ptr2
|
||||
.export __heapmemavail
|
||||
|
||||
.include "_heap.inc"
|
||||
|
||||
.macpack generic
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; Code
|
||||
|
||||
__heapmemavail:
|
||||
|
||||
; size_t Size = 0;
|
||||
|
||||
lda #0
|
||||
sta ptr2
|
||||
sta ptr2+1
|
||||
|
||||
; struct freeblock* F = _heapfirst;
|
||||
|
||||
lda __heapfirst
|
||||
sta ptr1
|
||||
lda __heapfirst+1
|
||||
@L1: sta ptr1+1
|
||||
|
||||
; while (F) {
|
||||
|
||||
ora ptr1
|
||||
beq @L2 ; Jump if end of free list reached
|
||||
|
||||
; Size += F->size;
|
||||
|
||||
ldy #freeblock_size
|
||||
lda (ptr1),y
|
||||
add ptr2
|
||||
sta ptr2
|
||||
iny
|
||||
lda (ptr1),y
|
||||
adc ptr2+1
|
||||
sta ptr2+1
|
||||
|
||||
; F = F->next;
|
||||
|
||||
iny ; Points to F->next
|
||||
lda (ptr1),y
|
||||
tax
|
||||
iny
|
||||
lda (ptr1),y
|
||||
stx ptr1
|
||||
jmp @L1
|
||||
|
||||
; return Size + (_heapend - _heapptr) * sizeof (*_heapend);
|
||||
|
||||
@L2: lda ptr2
|
||||
add __heapend
|
||||
sta ptr2
|
||||
lda ptr2+1
|
||||
adc __heapend+1
|
||||
tax
|
||||
|
||||
lda ptr2
|
||||
sub __heapptr
|
||||
sta ptr2
|
||||
txa
|
||||
sbc __heapptr+1
|
||||
tax
|
||||
lda ptr2
|
||||
|
||||
rts
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user