void* __fastcall__ calloc (size_t count, size_t size);
void* __fastcall__ realloc (void* block, size_t size);
void __fastcall__ free (void* block);
-void __fastcall__ _hadd (void* mem, size_t size); /* Non-standard */
+/* Non standard functions */
+void __fastcall__ _heapadd (void* mem, size_t size);
/* Random numbers */
#define RAND_MAX 0x7FFF
void* bsearch (const void* key, const void* base, size_t n,
size_t size, int (*cmp) (const void*, const void*));
div_t __fastcall__ div (int numer, int denom);
-void __fastcall__ exit (int ret);
+void __fastcall__ exit (int ret);
char* __fastcall__ getenv (const char* name);
void qsort (void* base, size_t count, size_t size,
int (*compare) (const void*, const void*));
S_OBJS = _fdesc.o \
_file.o \
_fopen.o \
- _hadd.o \
_heap.o \
+ _heapadd.o \
_oserror.o \
_printf.o \
_swap.o \
+++ /dev/null
-;
-; Ullrich von Bassewitz, 21.7.2000
-;
-; Add a block to the heap free list
-;
-; void __fastcall__ _hadd (void* mem, size_t size);
-;
-;
-
- .importzp ptr1, ptr2
- .import popax
- .import hadd
- .export _hadd
-
- .macpack generic
-
-; Offsets into struct freeblock and other constant stuff
-
-size = 0
-next = 2
-prev = 4
-admin_space = 2
-min_size = 6
-
-
-; Code
-
-_hadd: 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
-
-; 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).
-
- lda ptr1 ; Load low byte
- ldx ptr1+1 ; Load/check high byte
- bne @L1
- cmp #min_size
- bcs @L1
-
- rts ; Block not large enough
-
-; The block is large enough. Set the size field in the block.
-
-@L1: ldy #size
- sta (ptr2),y
- iny
- txa
- sta (ptr2),y
-
-; Call the internal function since variables are now setup correctly
-
- jmp hadd
-
-
-
--- /dev/null
+;
+; Ullrich von Bassewitz, 21.7.2000
+;
+; Add a block to the heap free list
+;
+; void __fastcall__ _heapadd (void* mem, size_t size);
+;
+;
+
+ .importzp ptr1, ptr2
+ .import popax
+ .import heapadd
+ .export _heapadd
+
+ .macpack generic
+
+; Offsets into struct freeblock and other constant stuff
+
+size = 0
+next = 2
+prev = 4
+admin_space = 2
+min_size = 6
+
+
+; Code
+
+_heapadd:
+ 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
+
+; 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).
+
+ lda ptr1 ; Load low byte
+ ldx ptr1+1 ; Load/check high byte
+ bne @L1
+ cmp #min_size
+ bcs @L1
+
+ rts ; Block not large enough
+
+; The block is large enough. Set the size field in the block.
+
+@L1: ldy #size
+ sta (ptr2),y
+ iny
+ txa
+ sta (ptr2),y
+
+; Call the internal function since variables are now setup correctly
+
+ jmp heapadd
+
+
+
.importzp ptr1, ptr2, ptr3, ptr4
.import __hptr, __hfirst, __hlast, __hend
- .export _free, hadd
+ .export _free, heapadd
.macpack generic
lda ptr2+1
adc ptr1+1
cpy __hptr
- bne hadd ; Add to free list
+ bne heapadd ; Add to free list
cmp __hptr+1
- bne hadd
+ bne heapadd
; The pointer is located at the heap top. Lower the heap top pointer to
; release the block.
; Check if the free list is empty, storing _hfirst into ptr3 for later
-hadd: lda __hfirst
+heapadd:
+ lda __hfirst
sta ptr3
lda __hfirst+1
sta ptr3+1
; The free list is empty, so this is the first and only block. A contains
; zero if we come here.
-
+
ldy #next-1
@L2: iny ; f->next = f->prev = 0;
sta (ptr2),y