File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1313 calloc
1414 memset
1515 memcheck
16+ memoryAvailable
1617 memSeekToStart
1718 memSeekToEnd
1819 reassignMemory
Original file line number Diff line number Diff line change @@ -216,6 +216,61 @@ _: pop af
216216 or 1
217217 ret
218218
219+ ;; memoryAvailable [System]
220+ ;; Finds the amount of memory available for use.
221+ ;; Outputs:
222+ ;; BC: Total memory availble
223+ ;; DE: Largest allocatable sum
224+ memoryAvailable:
225+ #define total_mem kernelGarbage
226+ #define max_alloc kernelGarbage + 2
227+ push hl
228+ push af
229+ ld a , i
230+ push af
231+ di
232+ ld hl , 0
233+ ld (total_mem) , hl
234+ ld (max_alloc) , hl
235+ ld hl , userMemory
236+ . loop :
237+ ld a , (hl) \ inc hl ; Owner ID to A
238+ ld c , (hl) \ inc hl
239+ ld b , (hl) \ inc hl ; Size to BC
240+ add hl , bc
241+ inc hl \ inc hl ; Move to next block
242+ cp 0xFF
243+ jr nz , . loop
244+ ; Free block
245+ push hl
246+ ld hl , (total_mem)
247+ add hl , bc
248+ ld (total_mem) , hl
249+
250+ ld hl , (max_alloc)
251+ or a ; reset c
252+ sbc hl , bc
253+ jr nc , _
254+ ld h , b \ ld l , c
255+ ld (max_alloc) , hl
256+ _: pop hl
257+ xor a
258+ cp h
259+ jr nz , . loop
260+ pop af
261+ jp po , _
262+ ei
263+ _: pop af
264+
265+ ld hl , (total_mem)
266+ ld b , h \ ld c , l
267+ ld hl , (max_alloc)
268+ ex de , hl
269+ pop hl
270+ ret
271+ #undefine total_mem
272+ #undefine max_alloc
273+
219274;; malloc [System]
220275;; Allocates the specified amount of memory.
221276;; Inputs:
You can’t perform that action at this time.
0 commit comments