10
20
30
40
50
60
70
80
90
100 :
110
120
130
140 :
150 :
160 DEFFNm_alloc(size%):LOCALA%,B%,E%:m_heap%=m_heap% :
170 IFm_heap%=0:PROCm_free(0) :
180 size%=(size%+3)AND-4:DIME%-1:IFsize%=0:=HIMEM-E%-1280 :
190 A%=m_heap%
200 IFA%:IF!A%<size%:REPEATB%=A%:A%=A%!4:UNTIL!A%>=size%ORA%=0 :
210 :
220 IFA%:IF!A%<=size%:IFA%+!A%+4=E%:DIME%size%-!A%:!A%=size%:m_heap%=A%!4:=A%+4
230 :
240 IFA%:IF!A%>size%+7:A%!(size%+8)=A%!4:A%!(size%+4)=!A%-size%-4:A%!4=A%+size%+4:!A%=size%
250 IFA%=0:IFHIMEM-E%-size%-1280<0:=0 :
260 IFA%=0:DIMA%size%+3:!A%=size%:=A%+4 :
270 IFB%:B%!4=A%!4 ELSE m_heap%=A%!4 :
280 =A%+4 :
290 :
300 DEFPROCm_free(ptr%):m_heap%=m_heap%:IFptr%=0:ENDPROC
310 !ptr%=m_heap%:m_heap%=ptr%-4
320 IF!ptr%=ptr%+ptr%!-4:ptr%!-4=ptr%!-4+!!ptr%+4:!ptr%=!(!ptr%+4)
330 ENDPROC
340 :
350 DEFFNm_realloc(ptr%,size%):PROCm_free(ptr%):=FNm_alloc(size%)
360 :
370 DEFFNm_zalloc(size%):LOCALA%:A%=FNm_alloc(size%):IFA%=0ORsize%<1:=A%
380 REPEATsize%=size%-1:A%?size%=0:UNTILsize%<0:=A%