@@ -26,7 +26,7 @@ REM Avoid recursive / multiple inclusion
2626'
2727' Returns:
2828' 16 bits (pointer) unsigned integer. NULL is returned if not
29- ' enough memory to alloc the block
29+ ' enough memory to allocate the block
3030' ----------------------------------------------------------------
3131function FASTCALL allocate( byval n as uinteger) as uinteger
3232 ' This is a FastCall function. This means:
@@ -41,6 +41,34 @@ function FASTCALL allocate(byval n as uinteger) as uinteger
4141end function
4242
4343
44+ ' ----------------------------------------------------------------
45+ ' function calloc
46+ '
47+ ' Allocates the requested bytes in the heap (dynamic memory) and
48+ ' returns the address (16 bit, unsigned) of the new bloc. If
49+ ' no memory, NULL (0) is returned.
50+ ' The allocated block is cleared (filled with 0's) upon return.
51+ '
52+ ' Parameters:
53+ ' n: number of bytes
54+ '
55+ ' Returns:
56+ ' 16 bits (pointer) unsigned integer. NULL is returned if not
57+ ' enough memory to allocate the block
58+ ' ----------------------------------------------------------------
59+ function FASTCALL callocate( byval n as uinteger) as uinteger
60+ ' This is a FastCall function. This means:
61+ ' 1.- The 16 bit 'n' parameter is received in hl
62+ ' 2.- Can return at any point with "ret"
63+ ' 3.- The result (16bit) must be returned in HL
64+ asm
65+ ld b, h
66+ ld c, l
67+ jp __MEM_CALLOC ; Since calloc is FASTCALL, we can return from there
68+ end asm
69+ end function
70+
71+
4472' ----------------------------------------------------------------
4573' sub free
4674'
@@ -146,7 +174,7 @@ function FASTCALL maxavail as uInteger
146174 LOCAL LOOP , CONT
147175
148176 ld hl, ZXBASIC_MEM_HEAP
149- ld de, 0 ; Size acumulator
177+ ld de, 0 ; Size accumulator
150178
151179LOOP :
152180 ; BC = (HL) = Block size
@@ -193,6 +221,7 @@ end function
193221#require "alloc.asm"
194222#require "free.asm"
195223#require "realloc.asm"
224+ #require "calloc.asm"
196225
197226# endif
198227
0 commit comments