11' ----------------------------------------------------------------
22' This file is released under the MIT License
3- '
3+ '
44' Copyleft (k) 2008
55' by Jose Rodriguez-Rosa (a.k.a. Boriel) <http://www.boriel.com>
66' ----------------------------------------------------------------
@@ -20,8 +20,8 @@ REM Avoid recursive / multiple inclusion
2020' Allocates the requested bytes in the heap (dynamic memory) and
2121' returns the address (16 bit, unsigned) of the new bloc. If
2222' no memory, NULL (0) is returned.
23- '
24- ' Parameters:
23+ '
24+ ' Parameters:
2525' n: number of bytes
2626'
2727' Returns:
@@ -34,9 +34,11 @@ function FASTCALL allocate(byval n as uinteger) as uinteger
3434 ' 2.- Can return at any point with "ret"
3535 ' 3.- The result (16bit) must be returned in HL
3636 asm
37- ld b, h
38- ld c, l
39- jp __MEM_ALLOC ; Since malloc is FASTCALL, we can return from there
37+ push namespace core
38+ ld b, h
39+ ld c, l
40+ jp __MEM_ALLOC ; Since malloc is FASTCALL, we can return from there
41+ pop namespace
4042 end asm
4143end function
4244
@@ -62,9 +64,11 @@ function FASTCALL callocate(byval n as uinteger) as uinteger
6264 ' 2.- Can return at any point with "ret"
6365 ' 3.- The result (16bit) must be returned in HL
6466 asm
65- ld b, h
66- ld c, l
67- jp __MEM_CALLOC ; Since calloc is FASTCALL, we can return from there
67+ push namespace core
68+ ld b, h
69+ ld c, l
70+ jp __MEM_CALLOC ; Since calloc is FASTCALL, we can return from there
71+ pop namespace
6872 end asm
6973end function
7074
@@ -80,7 +84,9 @@ sub FASTCALL deallocate(byval addr as integer)
8084 ' 1.- The 16 bit 'n' parameter is received in hl
8185 ' 2.- Can return at any point with "ret"
8286 asm
83- jp __MEM_FREE
87+ push namespace core
88+ jp __MEM_FREE
89+ pop namespace
8490 end asm
8591end sub
8692
@@ -91,8 +97,8 @@ end sub
9197' Reallocates the requested bytes in the heap (dynamic memory) and
9298' returns the address (16 bit, unsigned) of the new bloc. If
9399' no memory, NULL (0) is returned.
94- '
95- ' Parameters:
100+ '
101+ ' Parameters:
96102' n: number of bytes for the new size to reallocate
97103'
98104' Returns:
@@ -102,17 +108,19 @@ end sub
102108function FASTCALL reallocate( byval addr as uinteger, byval n as uinteger) as uinteger
103109 ' This is a FastCall function. This means:
104110 ' 1.- The 16 bit 'n' parameter is received in hl
105- ' 2.- The 2nd parameter is in the stack (16 bit)
111+ ' 2.- The 2nd parameter is in the stack (16 bit)
106112 ' 3.- Can return at any point with "ret"
107113 ' 4.- The result (16bit) must be returned in HL
108114 asm
109- ex de, hl ; saves 'n' parameter in de
110- pop hl ; return address
111- ex (sp), hl ; hl -> now contains the 2 nd parameter ( new length)
112- ld b, h
113- ld c, l
114- ex de, hl ; recovers hl (current pointer)
115- jp __REALLOC ; Since realloc is FASTCALL, we can return from there
115+ push namespace core
116+ ex de, hl ; saves 'n' parameter in de
117+ pop hl ; return address
118+ ex (sp), hl ; hl -> now contains the 2 nd parameter ( new length)
119+ ld b, h
120+ ld c, l
121+ ex de, hl ; recovers hl (current pointer)
122+ jp __REALLOC ; Since realloc is FASTCALL, we can return from there
123+ pop namespace
116124 end asm
117125end function
118126
@@ -125,6 +133,7 @@ end function
125133' ----------------------------------------------------------------
126134function FASTCALL memavail as uInteger
127135 asm
136+ push namespace core
128137 PROC
129138
130139 LOCAL LOOP
@@ -143,10 +152,10 @@ LOOP:
143152 ld a, (hl)
144153 inc hl
145154 ld h, (hl)
146- ld l, a
155+ ld l, a
147156
148157 ; DE += BC => Accum += Block size
149- ex de, hl
158+ ex de, hl
150159 add hl, bc
151160 ex de, hl
152161
@@ -156,8 +165,9 @@ LOOP:
156165 jr nz, LOOP
157166
158167 ex de, hl
159-
160- ENDP
168+
169+ ENDP
170+ pop namespace
161171 end asm
162172end function
163173
@@ -169,6 +179,7 @@ end function
169179' ----------------------------------------------------------------
170180function FASTCALL maxavail as uInteger
171181 asm
182+ push namespace core
172183 PROC
173184
174185 LOCAL LOOP , CONT
@@ -187,19 +198,19 @@ LOOP:
187198 ld a, (hl)
188199 inc hl
189200 ld h, (hl)
190- ld l, a
201+ ld l, a
191202
192203 ; Test if DE >= BC
193204 ; DE -= BC => Accum -= Block size
194- ex de, hl
205+ ex de, hl
195206 or a
196207 sbc hl, bc ; set C if HL < BC
197208 add hl, bc ; Restores current value
198209 ex de, hl
199210
200211 ; if not C skip this step
201212 jr nc, CONT
202- ; DE < BC => SET DE = BC
213+ ; DE < BC => SET DE = BC
203214 ld d, b
204215 ld e, c
205216
@@ -210,8 +221,9 @@ CONT:
210221 jr nz, LOOP
211222
212223 ex de, hl
213-
214- ENDP
224+
225+ ENDP
226+ pop namespace
215227 end asm
216228end function
217229
@@ -223,5 +235,4 @@ end function
223235#require "realloc.asm"
224236#require "calloc.asm"
225237
226- # endif
227-
238+ # endif
0 commit comments