Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199801_2.adf » Regulars2 » StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/HeapLib

StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/HeapLib

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Recent acquisitions » Acorn ADFS disks » adfs_AcornUser_199801_2.adf » Regulars2
Filename: StarInfo/Fletcher/!Setup/Files/Disc1/Program/NetGame/!NetGame/BasicLib/HeapLib
Read OK:
File size: 149B bytes
Load address: 0000
Exec address: 0000
File contents
   10REM >HeapLib
   20REM LEN Justin Fletcher
   30REM Version : 1.04 (18 Jan 1997)
   40REM Heap control library
   50REM Load this after WimpLib to replace the claim/release calls
   60:
   70REM PROCinitheap : Initialise the Heap manager
   80DEFPROCinitheap
   90SYS "OS_ReadMemMapInfo" TO h_page
  100h_size=h_page:h_start=HIMEM
  110h_rsize=2:REM Space 2 relocatable entries
  120h_full=0:REM current number of entries
  130SYS "Wimp_SlotSize",-1,-1 TO h_appbase
  140SYS "Wimp_SlotSize",h_appbase+h_size,-1
  150SYS "OS_Heap",0,h_start,,h_size
  160SYS "OS_Heap",2,h_start,,4*h_rsize+4 TO ,,h_reloc
  170h_reloc+=4:h_reloc!-4=&434F4C52
  180FORI=0TO h_rsize*4-4 STEP4:h_reloc!I=-1:NEXT
  190ENDPROC
  200:
  210REM PROCheap_free : Return amount of free space in heap
  220DEFPROCheap_free(RETURN max,RETURN free)
  230SYS "OS_Heap",1,h_start TO ,,,free:max=h_size
  240ENDPROC
  250:
  260REM FNenlargeheap : Tries to increase heap size, TRUE if ok
  270DEFFNenlargeheap
  280LOCAL ok,new
  290SYS "XWimp_SlotSize",h_appbase+h_size+h_page,-1 TO new;ok
  300IF (ok AND 1)=1 OR new=h_appbase+h_size THEN=FALSE
  310h_size+=h_page:SYS "OS_Heap",5,h_start,,h_page
  320=TRUE
  330:
  340REM FNclaimRMA : Claim an RMA block (in replacement of WimpLib FN)
  350DEFFNclaimRMA(length%)
  360LOCAL flags:IF length%<1THENERROR &802,"Cannot claim negative RMA"
  370SYS "XOS_Module",6,,,length% TO ,,area%;flags
  380IF (flags AND1)>0 THENarea%=-1
  390=area%
  400:
  410REM FNclaim : Claim a block from the heap
  420REM use -ve to claim a relocatable block
  430DEFFNclaim(size)
  440LOCAL loc,big,ok,r:ok=TRUE
  450IF size<0 THENr=TRUE:size=ABS(size)+4 ELSEr=FALSE
  460SYS "OS_Heap",1,h_start TO ,,big
  470WHILE size>big AND ok
  480 ok=FNenlargeheap:SYS "OS_Heap",1,h_start TO ,,big
  490ENDWHILE
  500IF NOT ok THEN=-1
  510SYS "XOS_Heap",2,h_start,,size TO ,,loc;ok
  520IF (ok AND1)=1 THEN=-1
  530IF r THEN
  540 !loc=&434F4C52:loc+=4
  550 IF h_full=h_rsize THEN
  560  h_reloc=FNextend(h_reloc,4*16):h_rsize+=16
  570  IF(h_reloc AND1)=0 THENFORr=h_full TO h_rsize-1:h_reloc!(r*4)=-1:NEXT ELSEh_reloc-=1:SYS "OS_Heap",3,h_start,loc-4:=-1
  580 ENDIF
  590 h_reloc!(h_full*4)=loc:h_full+=1
  600ENDIF
  610=loc
  620:
  630REM PROCrelease : release a heap block
  640DEFPROCrelease(RETURN loc)
  650LOCAL full
  660IF loc>0 THEN
  670 IF loc>h_start+h_size THEN
  680  SYS "OS_Module",7,,loc
  690 ELSE
  700  IF loc!-4=&434F4C52 THEN
  710   full=0
  720   WHILE full<h_full AND h_reloc!(full*4)<>loc:full+=1:ENDWHILE
  730   IF full=h_full THENERROR &802,"Attempt to release unknown relocatable heap block"
  740   loc-=4:h_full-=1:h_reloc!(full*4)=h_reloc!(h_full*4)
  750   h_reloc!(h_full*4)=-1
  760  ENDIF
  770  SYS "OS_Heap",3,h_start,loc
  780 ENDIF
  790 loc=-1
  800ENDIF
  810ENDPROC
  820:
  830REM FNextend : Change size of a relocatable block
  840REM returns with bit 1 set if error (should be word aligned
  850REM otherwise)
  860DEFFNextend(loc,size)
  870LOCAL new,ok,full:full=FALSE
  880IF loc!-4<>&434F4C52 THENERROR &802,"Attempt to extend non-relocatable heap block"
  890REPEAT
  900 SYS "XOS_Heap",4,h_start,loc-4,size TO k,,new;ok
  910 IF (ok AND1)=1 THENfull=NOT FNenlargeheap
  920UNTIL (ok AND1)=0 OR full
  930IF full THEN
  940 new=loc-3
  950ELSE
  960 IF loc<>h_reloc THEN
  970  full=0
  980  WHILE full<h_full AND h_reloc!(full*4)<>loc:full+=1:ENDWHILE
  990  IF full=h_full THENERROR &802,"Unknown relocatable heap block"
 1000  h_reloc!(full*4)=new+4
 1010 ENDIF
 1020ENDIF
 1030=new+4
 1040:
 1050REM PROClockblock   : Prevent a block from being moved
 1060REM PROCunlockblock : Enable a block to be relocated
 1070DEFPROClockblock(loc)
 1080IF loc!-4<>&434F4C52 THENERROR &802,"Attempt to lock non-relocatable heap block" ELSEloc!-4=&4B434F4C
 1090ENDPROC
 1100DEFPROCunlockblock(loc)
 1110IF loc!-4<>&4B434F4C THENERROR &802,"Attempt to unlock non-relocatable heap block" ELSEloc!-4=&434F4C52
 1120ENDPROC
 1130:
 1140REM PROCheap_rsort : sort relocatable heap table
 1150DEFPROCheap_rsort:SYS "OS_HeapSort",h_rsize,h_reloc,0:ENDPROC
 1160:
 1170REM PROCheap_garbage : perform garbage collection on heap
 1180REM will call PROCheap_relocate(block,size) for each to be
 1190REM moved, so program must include a routine to update pointers
 1200DEFPROCheap_garbage
 1210LOCAL h_rblk,block,largest,ok,maxfree,b,
 1220SYS "OS_Heap",2,h_start,,8+h_full*4 TO ,,block;ok
 1230IF (ok AND1)=0 THEN
 1240 IF block>h_reloc THEN
 1250  SYS "OS_Heap",3,h_start,block
 1260 ELSE
 1270  h_rsize=h_full+1:!block=&434F4C52:block+=4
 1280  FOR b=0 TO h_full*4 STEP 4:block!b=h_reloc!b:NEXT
 1290  SYS "OS_Heap",3,h_start,h_reloc-4:h_reloc=block
 1300 ENDIF
 1310ENDIF
 1320PROCheap_rsort
 1330SYS "Hourglass_On"
 1340IF h_full>0 THEN
 1350 SYS "OS_Heap",1,h_start TO ,,largest
 1360 FORh_rblk=h_full-1 TO 0 STEP-1
 1370  block=h_reloc!(h_rblk*4)
 1380  IF block!-4<>&4B434F4C THEN
 1390   SYS "OS_Heap",6,h_start,block-4 TO ,,,size
 1400   ok=FALSE
 1410   REPEAT
 1420    IF size<largest THEN
 1430     PROCheap_relocate(block,size-8):SYS "OS_Heap",1,h_start TO ,,largest,maxfree:IF h_reloc!(h_rblk*4)=block THENok=TRUE ELSEblock=h_reloc!(h_rblk*4)
 1440    ELSE
 1450     ok=TRUE
 1460    ENDIF
 1470   UNTIL ok
 1480  ENDIF
 1490 NEXT
 1500ENDIF
 1510SYS "Hourglass_Off"
 1520PROCheap_reduce
 1530ENDPROC
 1540:
 1550REM PROCheap_reduce : reduce the heap to it's smallest size
 1560DEFPROCheap_reduce
 1570LOCAL maxfree,ok
 1580maxfree=h_size-h_start!8
 1590WHILE maxfree>h_page
 1600 SYS "XOS_Heap",5,h_start,,-h_page TO ;ok
 1610 IF (ok AND 1)=1 THENmaxfree=0 ELSEh_size-=h_page:maxfree-=h_page
 1620 SYS "XWimp_SlotSize",h_appbase+h_size,-1 TO ;ok
 1630ENDWHILE
 1640ENDPROC
 1650:
 1660REM PROCheap_oktomove : move a relocatable heap block
 1670REM Only called within PROCheap_garbage, from PROCheap_relocate
 1680DEFPROCheap_oktomove(RETURN block,size)
 1690LOCAL loc,b
 1700SYS "OS_Heap",2,h_start,,size+4 TO ,,loc
 1710IF loc>block THENSYS "OS_Heap",3,h_start,loc:ENDPROC
 1720!loc=&434F4C52:loc+=4
 1730FOR b=0 TO size-4 STEP 4:loc!b=block!b:NEXT
 1740SYS "OS_Heap",3,h_start,block-4:block=loc:h_reloc!(h_rblk*4)=loc
 1750ENDPROC
 1760:
 1770REM FNstrdup : Duplicate a string
 1780DEFFNstrdup(a$):LOCAL p%:p%=FNclaim(LEN(a$)+1)
 1790IF p%<>-1 THEN$(p%)=a$
 1800=p%

� >HeapLib
� � Justin Fletcher
"� Version : 1.04 (18 Jan 1997)
(� Heap control library
2@� Load this after WimpLib to replace the claim/release calls
<:
F0� PROCinitheap : Initialise the Heap manager
P��initheap
Z#ș "OS_ReadMemMapInfo" � h_page
dh_size=h_page:h_start=�
n+h_rsize=2:� Space 2 relocatable entries
x(h_full=0:� current number of entries
�(ș "Wimp_SlotSize",-1,-1 � h_appbase
�*ș "Wimp_SlotSize",h_appbase+h_size,-1
�"ș "OS_Heap",0,h_start,,h_size
�3ș "OS_Heap",2,h_start,,4*h_rsize+4 � ,,h_reloc
�#h_reloc+=4:h_reloc!-4=&434F4C52
�'�I=0� h_rsize*4-4 �4:h_reloc!I=-1:�
��
�:
�9� PROCheap_free : Return amount of free space in heap
���heap_free(� max,� free)
�/ș "OS_Heap",1,h_start � ,,,free:max=h_size
��
�:
=� FNenlargeheap : Tries to increase heap size, TRUE if ok
ݤenlargeheap
� ok,new
";ș "XWimp_SlotSize",h_appbase+h_size+h_page,-1 � new;ok
,+� (ok � 1)=1 � new=h_appbase+h_size �=�
61h_size+=h_page:ș "OS_Heap",5,h_start,,h_page
@=�
J:
TD� FNclaimRMA : Claim an RMA block (in replacement of WimpLib FN)
^ݤclaimRMA(length%)
h:� flags:� length%<1�� &802,"Cannot claim negative RMA"
r/ș "XOS_Module",6,,,length% � ,,area%;flags
|� (flags �1)>0 �area%=-1
�
=area%
�:
�+� FNclaim : Claim a block from the heap
�*� use -ve to claim a relocatable block
�ݤclaim(size)
�� loc,big,ok,r:ok=�
�%� size<0 �r=�:size=�(size)+4 �r=�
�"ș "OS_Heap",1,h_start � ,,big
�ȕ size>big � ok
�3 ok=�enlargeheap:ș "OS_Heap",1,h_start � ,,big
��
�� � ok �=-1
�,ș "XOS_Heap",2,h_start,,size � ,,loc;ok
� (ok �1)=1 �=-1
	� r �
 !loc=&434F4C52:loc+=4
& � h_full=h_rsize �
0/  h_reloc=�extend(h_reloc,4*16):h_rsize+=16
:l  �(h_reloc �1)=0 ��r=h_full � h_rsize-1:h_reloc!(r*4)=-1:� �h_reloc-=1:ș "OS_Heap",3,h_start,loc-4:=-1
D �
N% h_reloc!(h_full*4)=loc:h_full+=1
X�
b=loc
l:
v(� PROCrelease : release a heap block
���release(� loc)
�
� full
�
� loc>0 �
� � loc>h_start+h_size �
�  ș "OS_Module",7,,loc
� �
�  � loc!-4=&434F4C52 �
�
   full=0
�7   ȕ full<h_full � h_reloc!(full*4)<>loc:full+=1:�
�P   � full=h_full �� &802,"Attempt to release unknown relocatable heap block"
�;   loc-=4:h_full-=1:h_reloc!(full*4)=h_reloc!(h_full*4)
�   h_reloc!(h_full*4)=-1
�  �
   ș "OS_Heap",3,h_start,loc
 �
 loc=-1
 �
*�
4:
>3� FNextend : Change size of a relocatable block
H=� returns with bit 1 set if error (should be word aligned
R� otherwise)
\ݤextend(loc,size)
f� new,ok,full:full=�
pN� loc!-4<>&434F4C52 �� &802,"Attempt to extend non-relocatable heap block"
z�
�3 ș "XOS_Heap",4,h_start,loc-4,size � k,,new;ok
�% � (ok �1)=1 �full=� �enlargeheap
�� (ok �1)=0 � full
�� full �
� new=loc-3
��
� � loc<>h_reloc �
�  full=0
�6  ȕ full<h_full � h_reloc!(full*4)<>loc:full+=1:�
�<  � full=h_full �� &802,"Unknown relocatable heap block"
�  h_reloc!(full*4)=new+4
� �
��

=new+4
:
8� PROClockblock   : Prevent a block from being moved
$6� PROCunlockblock : Enable a block to be relocated
.��lockblock(loc)
8^� loc!-4<>&434F4C52 �� &802,"Attempt to lock non-relocatable heap block" �loc!-4=&4B434F4C
B�
L��unlockblock(loc)
V`� loc!-4<>&4B434F4C �� &802,"Attempt to unlock non-relocatable heap block" �loc!-4=&434F4C52
`�
j:
t2� PROCheap_rsort : sort relocatable heap table
~5��heap_rsort:ș "OS_HeapSort",h_rsize,h_reloc,0:�
�:
�;� PROCheap_garbage : perform garbage collection on heap
�<� will call PROCheap_relocate(block,size) for each to be
�A� moved, so program must include a routine to update pointers
���heap_garbage
�(� h_rblk,block,largest,ok,maxfree,b,
�3ș "OS_Heap",2,h_start,,8+h_full*4 � ,,block;ok
�� (ok �1)=0 �
� � block>h_reloc �
�"  ș "OS_Heap",3,h_start,block
� �
�0  h_rsize=h_full+1:!block=&434F4C52:block+=4
.  � b=0 � h_full*4 � 4:block!b=h_reloc!b:�

4  ș "OS_Heap",3,h_start,h_reloc-4:h_reloc=block
 �
�
(�heap_rsort
2ș "Hourglass_On"
<� h_full>0 �
F' ș "OS_Heap",1,h_start � ,,largest
P �h_rblk=h_full-1 � 0 �-1
Z  block=h_reloc!(h_rblk*4)
d  � block!-4<>&4B434F4C �
n/   ș "OS_Heap",6,h_start,block-4 � ,,,size
x   ok=�
�   �
�    � size<largest �
��     �heap_relocate(block,size-8):ș "OS_Heap",1,h_start � ,,largest,maxfree:� h_reloc!(h_rblk*4)=block �ok=� �block=h_reloc!(h_rblk*4)
�	    �
�
     ok=�
�	    �
�   � ok
�  �
� �
��
�ș "Hourglass_Off"
��heap_reduce
��
:
=� PROCheap_reduce : reduce the heap to it's smallest size
��heap_reduce
"� maxfree,ok
,maxfree=h_size-h_start!8
6ȕ maxfree>h_page
@+ ș "XOS_Heap",5,h_start,,-h_page � ;ok
J< � (ok � 1)=1 �maxfree=0 �h_size-=h_page:maxfree-=h_page
T2 ș "XWimp_SlotSize",h_appbase+h_size,-1 � ;ok
^�
h�
r:
|7� PROCheap_oktomove : move a relocatable heap block
�A� Only called within PROCheap_garbage, from PROCheap_relocate
�!��heap_oktomove(� block,size)
�� loc,b
�*ș "OS_Heap",2,h_start,,size+4 � ,,loc
�-� loc>block �ș "OS_Heap",3,h_start,loc:�
�!loc=&434F4C52:loc+=4
�&� b=0 � size-4 � 4:loc!b=block!b:�
�Cș "OS_Heap",3,h_start,block-4:block=loc:h_reloc!(h_rblk*4)=loc
��
�:
�#� FNstrdup : Duplicate a string
�(ݤstrdup(a$):� p%:p%=�claim(�(a$)+1)
�� p%<>-1 �$(p%)=a$
=p%
�
00000000  0d 00 0a 0e f4 20 3e 48  65 61 70 4c 69 62 0d 00  |..... >HeapLib..|
00000010  14 17 f4 20 a9 20 4a 75  73 74 69 6e 20 46 6c 65  |... . Justin Fle|
00000020  74 63 68 65 72 0d 00 1e  22 f4 20 56 65 72 73 69  |tcher...". Versi|
00000030  6f 6e 20 3a 20 31 2e 30  34 20 28 31 38 20 4a 61  |on : 1.04 (18 Ja|
00000040  6e 20 31 39 39 37 29 0d  00 28 1a f4 20 48 65 61  |n 1997)..(.. Hea|
00000050  70 20 63 6f 6e 74 72 6f  6c 20 6c 69 62 72 61 72  |p control librar|
00000060  79 0d 00 32 40 f4 20 4c  6f 61 64 20 74 68 69 73  |y..2@. Load this|
00000070  20 61 66 74 65 72 20 57  69 6d 70 4c 69 62 20 74  | after WimpLib t|
00000080  6f 20 72 65 70 6c 61 63  65 20 74 68 65 20 63 6c  |o replace the cl|
00000090  61 69 6d 2f 72 65 6c 65  61 73 65 20 63 61 6c 6c  |aim/release call|
000000a0  73 0d 00 3c 05 3a 0d 00  46 30 f4 20 50 52 4f 43  |s..<.:..F0. PROC|
000000b0  69 6e 69 74 68 65 61 70  20 3a 20 49 6e 69 74 69  |initheap : Initi|
000000c0  61 6c 69 73 65 20 74 68  65 20 48 65 61 70 20 6d  |alise the Heap m|
000000d0  61 6e 61 67 65 72 0d 00  50 0e dd f2 69 6e 69 74  |anager..P...init|
000000e0  68 65 61 70 0d 00 5a 23  c8 99 20 22 4f 53 5f 52  |heap..Z#.. "OS_R|
000000f0  65 61 64 4d 65 6d 4d 61  70 49 6e 66 6f 22 20 b8  |eadMemMapInfo" .|
00000100  20 68 5f 70 61 67 65 0d  00 64 1b 68 5f 73 69 7a  | h_page..d.h_siz|
00000110  65 3d 68 5f 70 61 67 65  3a 68 5f 73 74 61 72 74  |e=h_page:h_start|
00000120  3d 93 0d 00 6e 2b 68 5f  72 73 69 7a 65 3d 32 3a  |=...n+h_rsize=2:|
00000130  f4 20 53 70 61 63 65 20  32 20 72 65 6c 6f 63 61  |. Space 2 reloca|
00000140  74 61 62 6c 65 20 65 6e  74 72 69 65 73 0d 00 78  |table entries..x|
00000150  28 68 5f 66 75 6c 6c 3d  30 3a f4 20 63 75 72 72  |(h_full=0:. curr|
00000160  65 6e 74 20 6e 75 6d 62  65 72 20 6f 66 20 65 6e  |ent number of en|
00000170  74 72 69 65 73 0d 00 82  28 c8 99 20 22 57 69 6d  |tries...(.. "Wim|
00000180  70 5f 53 6c 6f 74 53 69  7a 65 22 2c 2d 31 2c 2d  |p_SlotSize",-1,-|
00000190  31 20 b8 20 68 5f 61 70  70 62 61 73 65 0d 00 8c  |1 . h_appbase...|
000001a0  2a c8 99 20 22 57 69 6d  70 5f 53 6c 6f 74 53 69  |*.. "Wimp_SlotSi|
000001b0  7a 65 22 2c 68 5f 61 70  70 62 61 73 65 2b 68 5f  |ze",h_appbase+h_|
000001c0  73 69 7a 65 2c 2d 31 0d  00 96 22 c8 99 20 22 4f  |size,-1...".. "O|
000001d0  53 5f 48 65 61 70 22 2c  30 2c 68 5f 73 74 61 72  |S_Heap",0,h_star|
000001e0  74 2c 2c 68 5f 73 69 7a  65 0d 00 a0 33 c8 99 20  |t,,h_size...3.. |
000001f0  22 4f 53 5f 48 65 61 70  22 2c 32 2c 68 5f 73 74  |"OS_Heap",2,h_st|
00000200  61 72 74 2c 2c 34 2a 68  5f 72 73 69 7a 65 2b 34  |art,,4*h_rsize+4|
00000210  20 b8 20 2c 2c 68 5f 72  65 6c 6f 63 0d 00 aa 23  | . ,,h_reloc...#|
00000220  68 5f 72 65 6c 6f 63 2b  3d 34 3a 68 5f 72 65 6c  |h_reloc+=4:h_rel|
00000230  6f 63 21 2d 34 3d 26 34  33 34 46 34 43 35 32 0d  |oc!-4=&434F4C52.|
00000240  00 b4 27 e3 49 3d 30 b8  20 68 5f 72 73 69 7a 65  |..'.I=0. h_rsize|
00000250  2a 34 2d 34 20 88 34 3a  68 5f 72 65 6c 6f 63 21  |*4-4 .4:h_reloc!|
00000260  49 3d 2d 31 3a ed 0d 00  be 05 e1 0d 00 c8 05 3a  |I=-1:..........:|
00000270  0d 00 d2 39 f4 20 50 52  4f 43 68 65 61 70 5f 66  |...9. PROCheap_f|
00000280  72 65 65 20 3a 20 52 65  74 75 72 6e 20 61 6d 6f  |ree : Return amo|
00000290  75 6e 74 20 6f 66 20 66  72 65 65 20 73 70 61 63  |unt of free spac|
000002a0  65 20 69 6e 20 68 65 61  70 0d 00 dc 1d dd f2 68  |e in heap......h|
000002b0  65 61 70 5f 66 72 65 65  28 f8 20 6d 61 78 2c f8  |eap_free(. max,.|
000002c0  20 66 72 65 65 29 0d 00  e6 2f c8 99 20 22 4f 53  | free).../.. "OS|
000002d0  5f 48 65 61 70 22 2c 31  2c 68 5f 73 74 61 72 74  |_Heap",1,h_start|
000002e0  20 b8 20 2c 2c 2c 66 72  65 65 3a 6d 61 78 3d 68  | . ,,,free:max=h|
000002f0  5f 73 69 7a 65 0d 00 f0  05 e1 0d 00 fa 05 3a 0d  |_size.........:.|
00000300  01 04 3d f4 20 46 4e 65  6e 6c 61 72 67 65 68 65  |..=. FNenlargehe|
00000310  61 70 20 3a 20 54 72 69  65 73 20 74 6f 20 69 6e  |ap : Tries to in|
00000320  63 72 65 61 73 65 20 68  65 61 70 20 73 69 7a 65  |crease heap size|
00000330  2c 20 54 52 55 45 20 69  66 20 6f 6b 0d 01 0e 11  |, TRUE if ok....|
00000340  dd a4 65 6e 6c 61 72 67  65 68 65 61 70 0d 01 18  |..enlargeheap...|
00000350  0c ea 20 6f 6b 2c 6e 65  77 0d 01 22 3b c8 99 20  |.. ok,new..";.. |
00000360  22 58 57 69 6d 70 5f 53  6c 6f 74 53 69 7a 65 22  |"XWimp_SlotSize"|
00000370  2c 68 5f 61 70 70 62 61  73 65 2b 68 5f 73 69 7a  |,h_appbase+h_siz|
00000380  65 2b 68 5f 70 61 67 65  2c 2d 31 20 b8 20 6e 65  |e+h_page,-1 . ne|
00000390  77 3b 6f 6b 0d 01 2c 2b  e7 20 28 6f 6b 20 80 20  |w;ok..,+. (ok . |
000003a0  31 29 3d 31 20 84 20 6e  65 77 3d 68 5f 61 70 70  |1)=1 . new=h_app|
000003b0  62 61 73 65 2b 68 5f 73  69 7a 65 20 8c 3d a3 0d  |base+h_size .=..|
000003c0  01 36 31 68 5f 73 69 7a  65 2b 3d 68 5f 70 61 67  |.61h_size+=h_pag|
000003d0  65 3a c8 99 20 22 4f 53  5f 48 65 61 70 22 2c 35  |e:.. "OS_Heap",5|
000003e0  2c 68 5f 73 74 61 72 74  2c 2c 68 5f 70 61 67 65  |,h_start,,h_page|
000003f0  0d 01 40 06 3d b9 0d 01  4a 05 3a 0d 01 54 44 f4  |..@.=...J.:..TD.|
00000400  20 46 4e 63 6c 61 69 6d  52 4d 41 20 3a 20 43 6c  | FNclaimRMA : Cl|
00000410  61 69 6d 20 61 6e 20 52  4d 41 20 62 6c 6f 63 6b  |aim an RMA block|
00000420  20 28 69 6e 20 72 65 70  6c 61 63 65 6d 65 6e 74  | (in replacement|
00000430  20 6f 66 20 57 69 6d 70  4c 69 62 20 46 4e 29 0d  | of WimpLib FN).|
00000440  01 5e 17 dd a4 63 6c 61  69 6d 52 4d 41 28 6c 65  |.^...claimRMA(le|
00000450  6e 67 74 68 25 29 0d 01  68 3a ea 20 66 6c 61 67  |ngth%)..h:. flag|
00000460  73 3a e7 20 6c 65 6e 67  74 68 25 3c 31 8c 85 20  |s:. length%<1.. |
00000470  26 38 30 32 2c 22 43 61  6e 6e 6f 74 20 63 6c 61  |&802,"Cannot cla|
00000480  69 6d 20 6e 65 67 61 74  69 76 65 20 52 4d 41 22  |im negative RMA"|
00000490  0d 01 72 2f c8 99 20 22  58 4f 53 5f 4d 6f 64 75  |..r/.. "XOS_Modu|
000004a0  6c 65 22 2c 36 2c 2c 2c  6c 65 6e 67 74 68 25 20  |le",6,,,length% |
000004b0  b8 20 2c 2c 61 72 65 61  25 3b 66 6c 61 67 73 0d  |. ,,area%;flags.|
000004c0  01 7c 1c e7 20 28 66 6c  61 67 73 20 80 31 29 3e  |.|.. (flags .1)>|
000004d0  30 20 8c 61 72 65 61 25  3d 2d 31 0d 01 86 0a 3d  |0 .area%=-1....=|
000004e0  61 72 65 61 25 0d 01 90  05 3a 0d 01 9a 2b f4 20  |area%....:...+. |
000004f0  46 4e 63 6c 61 69 6d 20  3a 20 43 6c 61 69 6d 20  |FNclaim : Claim |
00000500  61 20 62 6c 6f 63 6b 20  66 72 6f 6d 20 74 68 65  |a block from the|
00000510  20 68 65 61 70 0d 01 a4  2a f4 20 75 73 65 20 2d  | heap...*. use -|
00000520  76 65 20 74 6f 20 63 6c  61 69 6d 20 61 20 72 65  |ve to claim a re|
00000530  6c 6f 63 61 74 61 62 6c  65 20 62 6c 6f 63 6b 0d  |locatable block.|
00000540  01 ae 11 dd a4 63 6c 61  69 6d 28 73 69 7a 65 29  |.....claim(size)|
00000550  0d 01 b8 17 ea 20 6c 6f  63 2c 62 69 67 2c 6f 6b  |..... loc,big,ok|
00000560  2c 72 3a 6f 6b 3d b9 0d  01 c2 25 e7 20 73 69 7a  |,r:ok=....%. siz|
00000570  65 3c 30 20 8c 72 3d b9  3a 73 69 7a 65 3d 94 28  |e<0 .r=.:size=.(|
00000580  73 69 7a 65 29 2b 34 20  8b 72 3d a3 0d 01 cc 22  |size)+4 .r=...."|
00000590  c8 99 20 22 4f 53 5f 48  65 61 70 22 2c 31 2c 68  |.. "OS_Heap",1,h|
000005a0  5f 73 74 61 72 74 20 b8  20 2c 2c 62 69 67 0d 01  |_start . ,,big..|
000005b0  d6 14 c8 95 20 73 69 7a  65 3e 62 69 67 20 80 20  |.... size>big . |
000005c0  6f 6b 0d 01 e0 33 20 6f  6b 3d a4 65 6e 6c 61 72  |ok...3 ok=.enlar|
000005d0  67 65 68 65 61 70 3a c8  99 20 22 4f 53 5f 48 65  |geheap:.. "OS_He|
000005e0  61 70 22 2c 31 2c 68 5f  73 74 61 72 74 20 b8 20  |ap",1,h_start . |
000005f0  2c 2c 62 69 67 0d 01 ea  05 ce 0d 01 f4 0f e7 20  |,,big.......... |
00000600  ac 20 6f 6b 20 8c 3d 2d  31 0d 01 fe 2c c8 99 20  |. ok .=-1...,.. |
00000610  22 58 4f 53 5f 48 65 61  70 22 2c 32 2c 68 5f 73  |"XOS_Heap",2,h_s|
00000620  74 61 72 74 2c 2c 73 69  7a 65 20 b8 20 2c 2c 6c  |tart,,size . ,,l|
00000630  6f 63 3b 6f 6b 0d 02 08  14 e7 20 28 6f 6b 20 80  |oc;ok..... (ok .|
00000640  31 29 3d 31 20 8c 3d 2d  31 0d 02 12 09 e7 20 72  |1)=1 .=-1..... r|
00000650  20 8c 0d 02 1c 1a 20 21  6c 6f 63 3d 26 34 33 34  | ..... !loc=&434|
00000660  46 34 43 35 32 3a 6c 6f  63 2b 3d 34 0d 02 26 17  |F4C52:loc+=4..&.|
00000670  20 e7 20 68 5f 66 75 6c  6c 3d 68 5f 72 73 69 7a  | . h_full=h_rsiz|
00000680  65 20 8c 0d 02 30 2f 20  20 68 5f 72 65 6c 6f 63  |e ...0/  h_reloc|
00000690  3d a4 65 78 74 65 6e 64  28 68 5f 72 65 6c 6f 63  |=.extend(h_reloc|
000006a0  2c 34 2a 31 36 29 3a 68  5f 72 73 69 7a 65 2b 3d  |,4*16):h_rsize+=|
000006b0  31 36 0d 02 3a 6c 20 20  e7 28 68 5f 72 65 6c 6f  |16..:l  .(h_relo|
000006c0  63 20 80 31 29 3d 30 20  8c e3 72 3d 68 5f 66 75  |c .1)=0 ..r=h_fu|
000006d0  6c 6c 20 b8 20 68 5f 72  73 69 7a 65 2d 31 3a 68  |ll . h_rsize-1:h|
000006e0  5f 72 65 6c 6f 63 21 28  72 2a 34 29 3d 2d 31 3a  |_reloc!(r*4)=-1:|
000006f0  ed 20 8b 68 5f 72 65 6c  6f 63 2d 3d 31 3a c8 99  |. .h_reloc-=1:..|
00000700  20 22 4f 53 5f 48 65 61  70 22 2c 33 2c 68 5f 73  | "OS_Heap",3,h_s|
00000710  74 61 72 74 2c 6c 6f 63  2d 34 3a 3d 2d 31 0d 02  |tart,loc-4:=-1..|
00000720  44 06 20 cd 0d 02 4e 25  20 68 5f 72 65 6c 6f 63  |D. ...N% h_reloc|
00000730  21 28 68 5f 66 75 6c 6c  2a 34 29 3d 6c 6f 63 3a  |!(h_full*4)=loc:|
00000740  68 5f 66 75 6c 6c 2b 3d  31 0d 02 58 05 cd 0d 02  |h_full+=1..X....|
00000750  62 08 3d 6c 6f 63 0d 02  6c 05 3a 0d 02 76 28 f4  |b.=loc..l.:..v(.|
00000760  20 50 52 4f 43 72 65 6c  65 61 73 65 20 3a 20 72  | PROCrelease : r|
00000770  65 6c 65 61 73 65 20 61  20 68 65 61 70 20 62 6c  |elease a heap bl|
00000780  6f 63 6b 0d 02 80 14 dd  f2 72 65 6c 65 61 73 65  |ock......release|
00000790  28 f8 20 6c 6f 63 29 0d  02 8a 0a ea 20 66 75 6c  |(. loc)..... ful|
000007a0  6c 0d 02 94 0d e7 20 6c  6f 63 3e 30 20 8c 0d 02  |l..... loc>0 ...|
000007b0  9e 1b 20 e7 20 6c 6f 63  3e 68 5f 73 74 61 72 74  |.. . loc>h_start|
000007c0  2b 68 5f 73 69 7a 65 20  8c 0d 02 a8 1b 20 20 c8  |+h_size .....  .|
000007d0  99 20 22 4f 53 5f 4d 6f  64 75 6c 65 22 2c 37 2c  |. "OS_Module",7,|
000007e0  2c 6c 6f 63 0d 02 b2 06  20 cc 0d 02 bc 1a 20 20  |,loc.... .....  |
000007f0  e7 20 6c 6f 63 21 2d 34  3d 26 34 33 34 46 34 43  |. loc!-4=&434F4C|
00000800  35 32 20 8c 0d 02 c6 0d  20 20 20 66 75 6c 6c 3d  |52 .....   full=|
00000810  30 0d 02 d0 37 20 20 20  c8 95 20 66 75 6c 6c 3c  |0...7   .. full<|
00000820  68 5f 66 75 6c 6c 20 80  20 68 5f 72 65 6c 6f 63  |h_full . h_reloc|
00000830  21 28 66 75 6c 6c 2a 34  29 3c 3e 6c 6f 63 3a 66  |!(full*4)<>loc:f|
00000840  75 6c 6c 2b 3d 31 3a ce  0d 02 da 50 20 20 20 e7  |ull+=1:....P   .|
00000850  20 66 75 6c 6c 3d 68 5f  66 75 6c 6c 20 8c 85 20  | full=h_full .. |
00000860  26 38 30 32 2c 22 41 74  74 65 6d 70 74 20 74 6f  |&802,"Attempt to|
00000870  20 72 65 6c 65 61 73 65  20 75 6e 6b 6e 6f 77 6e  | release unknown|
00000880  20 72 65 6c 6f 63 61 74  61 62 6c 65 20 68 65 61  | relocatable hea|
00000890  70 20 62 6c 6f 63 6b 22  0d 02 e4 3b 20 20 20 6c  |p block"...;   l|
000008a0  6f 63 2d 3d 34 3a 68 5f  66 75 6c 6c 2d 3d 31 3a  |oc-=4:h_full-=1:|
000008b0  68 5f 72 65 6c 6f 63 21  28 66 75 6c 6c 2a 34 29  |h_reloc!(full*4)|
000008c0  3d 68 5f 72 65 6c 6f 63  21 28 68 5f 66 75 6c 6c  |=h_reloc!(h_full|
000008d0  2a 34 29 0d 02 ee 1c 20  20 20 68 5f 72 65 6c 6f  |*4)....   h_relo|
000008e0  63 21 28 68 5f 66 75 6c  6c 2a 34 29 3d 2d 31 0d  |c!(h_full*4)=-1.|
000008f0  02 f8 07 20 20 cd 0d 03  02 20 20 20 c8 99 20 22  |...  ....   .. "|
00000900  4f 53 5f 48 65 61 70 22  2c 33 2c 68 5f 73 74 61  |OS_Heap",3,h_sta|
00000910  72 74 2c 6c 6f 63 0d 03  0c 06 20 cd 0d 03 16 0b  |rt,loc.... .....|
00000920  20 6c 6f 63 3d 2d 31 0d  03 20 05 cd 0d 03 2a 05  | loc=-1.. ....*.|
00000930  e1 0d 03 34 05 3a 0d 03  3e 33 f4 20 46 4e 65 78  |...4.:..>3. FNex|
00000940  74 65 6e 64 20 3a 20 43  68 61 6e 67 65 20 73 69  |tend : Change si|
00000950  7a 65 20 6f 66 20 61 20  72 65 6c 6f 63 61 74 61  |ze of a relocata|
00000960  62 6c 65 20 62 6c 6f 63  6b 0d 03 48 3d f4 20 72  |ble block..H=. r|
00000970  65 74 75 72 6e 73 20 77  69 74 68 20 62 69 74 20  |eturns with bit |
00000980  31 20 73 65 74 20 69 66  20 65 72 72 6f 72 20 28  |1 set if error (|
00000990  73 68 6f 75 6c 64 20 62  65 20 77 6f 72 64 20 61  |should be word a|
000009a0  6c 69 67 6e 65 64 0d 03  52 10 f4 20 6f 74 68 65  |ligned..R.. othe|
000009b0  72 77 69 73 65 29 0d 03  5c 16 dd a4 65 78 74 65  |rwise)..\...exte|
000009c0  6e 64 28 6c 6f 63 2c 73  69 7a 65 29 0d 03 66 18  |nd(loc,size)..f.|
000009d0  ea 20 6e 65 77 2c 6f 6b  2c 66 75 6c 6c 3a 66 75  |. new,ok,full:fu|
000009e0  6c 6c 3d a3 0d 03 70 4e  e7 20 6c 6f 63 21 2d 34  |ll=...pN. loc!-4|
000009f0  3c 3e 26 34 33 34 46 34  43 35 32 20 8c 85 20 26  |<>&434F4C52 .. &|
00000a00  38 30 32 2c 22 41 74 74  65 6d 70 74 20 74 6f 20  |802,"Attempt to |
00000a10  65 78 74 65 6e 64 20 6e  6f 6e 2d 72 65 6c 6f 63  |extend non-reloc|
00000a20  61 74 61 62 6c 65 20 68  65 61 70 20 62 6c 6f 63  |atable heap bloc|
00000a30  6b 22 0d 03 7a 05 f5 0d  03 84 33 20 c8 99 20 22  |k"..z.....3 .. "|
00000a40  58 4f 53 5f 48 65 61 70  22 2c 34 2c 68 5f 73 74  |XOS_Heap",4,h_st|
00000a50  61 72 74 2c 6c 6f 63 2d  34 2c 73 69 7a 65 20 b8  |art,loc-4,size .|
00000a60  20 6b 2c 2c 6e 65 77 3b  6f 6b 0d 03 8e 25 20 e7  | k,,new;ok...% .|
00000a70  20 28 6f 6b 20 80 31 29  3d 31 20 8c 66 75 6c 6c  | (ok .1)=1 .full|
00000a80  3d ac 20 a4 65 6e 6c 61  72 67 65 68 65 61 70 0d  |=. .enlargeheap.|
00000a90  03 98 16 fd 20 28 6f 6b  20 80 31 29 3d 30 20 84  |.... (ok .1)=0 .|
00000aa0  20 66 75 6c 6c 0d 03 a2  0c e7 20 66 75 6c 6c 20  | full..... full |
00000ab0  8c 0d 03 ac 0e 20 6e 65  77 3d 6c 6f 63 2d 33 0d  |..... new=loc-3.|
00000ac0  03 b6 05 cc 0d 03 c0 15  20 e7 20 6c 6f 63 3c 3e  |........ . loc<>|
00000ad0  68 5f 72 65 6c 6f 63 20  8c 0d 03 ca 0c 20 20 66  |h_reloc .....  f|
00000ae0  75 6c 6c 3d 30 0d 03 d4  36 20 20 c8 95 20 66 75  |ull=0...6  .. fu|
00000af0  6c 6c 3c 68 5f 66 75 6c  6c 20 80 20 68 5f 72 65  |ll<h_full . h_re|
00000b00  6c 6f 63 21 28 66 75 6c  6c 2a 34 29 3c 3e 6c 6f  |loc!(full*4)<>lo|
00000b10  63 3a 66 75 6c 6c 2b 3d  31 3a ce 0d 03 de 3c 20  |c:full+=1:....< |
00000b20  20 e7 20 66 75 6c 6c 3d  68 5f 66 75 6c 6c 20 8c  | . full=h_full .|
00000b30  85 20 26 38 30 32 2c 22  55 6e 6b 6e 6f 77 6e 20  |. &802,"Unknown |
00000b40  72 65 6c 6f 63 61 74 61  62 6c 65 20 68 65 61 70  |relocatable heap|
00000b50  20 62 6c 6f 63 6b 22 0d  03 e8 1c 20 20 68 5f 72  | block"....  h_r|
00000b60  65 6c 6f 63 21 28 66 75  6c 6c 2a 34 29 3d 6e 65  |eloc!(full*4)=ne|
00000b70  77 2b 34 0d 03 f2 06 20  cd 0d 03 fc 05 cd 0d 04  |w+4.... ........|
00000b80  06 0a 3d 6e 65 77 2b 34  0d 04 10 05 3a 0d 04 1a  |..=new+4....:...|
00000b90  38 f4 20 50 52 4f 43 6c  6f 63 6b 62 6c 6f 63 6b  |8. PROClockblock|
00000ba0  20 20 20 3a 20 50 72 65  76 65 6e 74 20 61 20 62  |   : Prevent a b|
00000bb0  6c 6f 63 6b 20 66 72 6f  6d 20 62 65 69 6e 67 20  |lock from being |
00000bc0  6d 6f 76 65 64 0d 04 24  36 f4 20 50 52 4f 43 75  |moved..$6. PROCu|
00000bd0  6e 6c 6f 63 6b 62 6c 6f  63 6b 20 3a 20 45 6e 61  |nlockblock : Ena|
00000be0  62 6c 65 20 61 20 62 6c  6f 63 6b 20 74 6f 20 62  |ble a block to b|
00000bf0  65 20 72 65 6c 6f 63 61  74 65 64 0d 04 2e 14 dd  |e relocated.....|
00000c00  f2 6c 6f 63 6b 62 6c 6f  63 6b 28 6c 6f 63 29 0d  |.lockblock(loc).|
00000c10  04 38 5e e7 20 6c 6f 63  21 2d 34 3c 3e 26 34 33  |.8^. loc!-4<>&43|
00000c20  34 46 34 43 35 32 20 8c  85 20 26 38 30 32 2c 22  |4F4C52 .. &802,"|
00000c30  41 74 74 65 6d 70 74 20  74 6f 20 6c 6f 63 6b 20  |Attempt to lock |
00000c40  6e 6f 6e 2d 72 65 6c 6f  63 61 74 61 62 6c 65 20  |non-relocatable |
00000c50  68 65 61 70 20 62 6c 6f  63 6b 22 20 8b 6c 6f 63  |heap block" .loc|
00000c60  21 2d 34 3d 26 34 42 34  33 34 46 34 43 0d 04 42  |!-4=&4B434F4C..B|
00000c70  05 e1 0d 04 4c 16 dd f2  75 6e 6c 6f 63 6b 62 6c  |....L...unlockbl|
00000c80  6f 63 6b 28 6c 6f 63 29  0d 04 56 60 e7 20 6c 6f  |ock(loc)..V`. lo|
00000c90  63 21 2d 34 3c 3e 26 34  42 34 33 34 46 34 43 20  |c!-4<>&4B434F4C |
00000ca0  8c 85 20 26 38 30 32 2c  22 41 74 74 65 6d 70 74  |.. &802,"Attempt|
00000cb0  20 74 6f 20 75 6e 6c 6f  63 6b 20 6e 6f 6e 2d 72  | to unlock non-r|
00000cc0  65 6c 6f 63 61 74 61 62  6c 65 20 68 65 61 70 20  |elocatable heap |
00000cd0  62 6c 6f 63 6b 22 20 8b  6c 6f 63 21 2d 34 3d 26  |block" .loc!-4=&|
00000ce0  34 33 34 46 34 43 35 32  0d 04 60 05 e1 0d 04 6a  |434F4C52..`....j|
00000cf0  05 3a 0d 04 74 32 f4 20  50 52 4f 43 68 65 61 70  |.:..t2. PROCheap|
00000d00  5f 72 73 6f 72 74 20 3a  20 73 6f 72 74 20 72 65  |_rsort : sort re|
00000d10  6c 6f 63 61 74 61 62 6c  65 20 68 65 61 70 20 74  |locatable heap t|
00000d20  61 62 6c 65 0d 04 7e 35  dd f2 68 65 61 70 5f 72  |able..~5..heap_r|
00000d30  73 6f 72 74 3a c8 99 20  22 4f 53 5f 48 65 61 70  |sort:.. "OS_Heap|
00000d40  53 6f 72 74 22 2c 68 5f  72 73 69 7a 65 2c 68 5f  |Sort",h_rsize,h_|
00000d50  72 65 6c 6f 63 2c 30 3a  e1 0d 04 88 05 3a 0d 04  |reloc,0:.....:..|
00000d60  92 3b f4 20 50 52 4f 43  68 65 61 70 5f 67 61 72  |.;. PROCheap_gar|
00000d70  62 61 67 65 20 3a 20 70  65 72 66 6f 72 6d 20 67  |bage : perform g|
00000d80  61 72 62 61 67 65 20 63  6f 6c 6c 65 63 74 69 6f  |arbage collectio|
00000d90  6e 20 6f 6e 20 68 65 61  70 0d 04 9c 3c f4 20 77  |n on heap...<. w|
00000da0  69 6c 6c 20 63 61 6c 6c  20 50 52 4f 43 68 65 61  |ill call PROChea|
00000db0  70 5f 72 65 6c 6f 63 61  74 65 28 62 6c 6f 63 6b  |p_relocate(block|
00000dc0  2c 73 69 7a 65 29 20 66  6f 72 20 65 61 63 68 20  |,size) for each |
00000dd0  74 6f 20 62 65 0d 04 a6  41 f4 20 6d 6f 76 65 64  |to be...A. moved|
00000de0  2c 20 73 6f 20 70 72 6f  67 72 61 6d 20 6d 75 73  |, so program mus|
00000df0  74 20 69 6e 63 6c 75 64  65 20 61 20 72 6f 75 74  |t include a rout|
00000e00  69 6e 65 20 74 6f 20 75  70 64 61 74 65 20 70 6f  |ine to update po|
00000e10  69 6e 74 65 72 73 0d 04  b0 12 dd f2 68 65 61 70  |inters......heap|
00000e20  5f 67 61 72 62 61 67 65  0d 04 ba 28 ea 20 68 5f  |_garbage...(. h_|
00000e30  72 62 6c 6b 2c 62 6c 6f  63 6b 2c 6c 61 72 67 65  |rblk,block,large|
00000e40  73 74 2c 6f 6b 2c 6d 61  78 66 72 65 65 2c 62 2c  |st,ok,maxfree,b,|
00000e50  0d 04 c4 33 c8 99 20 22  4f 53 5f 48 65 61 70 22  |...3.. "OS_Heap"|
00000e60  2c 32 2c 68 5f 73 74 61  72 74 2c 2c 38 2b 68 5f  |,2,h_start,,8+h_|
00000e70  66 75 6c 6c 2a 34 20 b8  20 2c 2c 62 6c 6f 63 6b  |full*4 . ,,block|
00000e80  3b 6f 6b 0d 04 ce 11 e7  20 28 6f 6b 20 80 31 29  |;ok..... (ok .1)|
00000e90  3d 30 20 8c 0d 04 d8 16  20 e7 20 62 6c 6f 63 6b  |=0 ..... . block|
00000ea0  3e 68 5f 72 65 6c 6f 63  20 8c 0d 04 e2 22 20 20  |>h_reloc ...."  |
00000eb0  c8 99 20 22 4f 53 5f 48  65 61 70 22 2c 33 2c 68  |.. "OS_Heap",3,h|
00000ec0  5f 73 74 61 72 74 2c 62  6c 6f 63 6b 0d 04 ec 06  |_start,block....|
00000ed0  20 cc 0d 04 f6 30 20 20  68 5f 72 73 69 7a 65 3d  | ....0  h_rsize=|
00000ee0  68 5f 66 75 6c 6c 2b 31  3a 21 62 6c 6f 63 6b 3d  |h_full+1:!block=|
00000ef0  26 34 33 34 46 34 43 35  32 3a 62 6c 6f 63 6b 2b  |&434F4C52:block+|
00000f00  3d 34 0d 05 00 2e 20 20  e3 20 62 3d 30 20 b8 20  |=4....  . b=0 . |
00000f10  68 5f 66 75 6c 6c 2a 34  20 88 20 34 3a 62 6c 6f  |h_full*4 . 4:blo|
00000f20  63 6b 21 62 3d 68 5f 72  65 6c 6f 63 21 62 3a ed  |ck!b=h_reloc!b:.|
00000f30  0d 05 0a 34 20 20 c8 99  20 22 4f 53 5f 48 65 61  |...4  .. "OS_Hea|
00000f40  70 22 2c 33 2c 68 5f 73  74 61 72 74 2c 68 5f 72  |p",3,h_start,h_r|
00000f50  65 6c 6f 63 2d 34 3a 68  5f 72 65 6c 6f 63 3d 62  |eloc-4:h_reloc=b|
00000f60  6c 6f 63 6b 0d 05 14 06  20 cd 0d 05 1e 05 cd 0d  |lock.... .......|
00000f70  05 28 0f f2 68 65 61 70  5f 72 73 6f 72 74 0d 05  |.(..heap_rsort..|
00000f80  32 15 c8 99 20 22 48 6f  75 72 67 6c 61 73 73 5f  |2... "Hourglass_|
00000f90  4f 6e 22 0d 05 3c 10 e7  20 68 5f 66 75 6c 6c 3e  |On"..<.. h_full>|
00000fa0  30 20 8c 0d 05 46 27 20  c8 99 20 22 4f 53 5f 48  |0 ...F' .. "OS_H|
00000fb0  65 61 70 22 2c 31 2c 68  5f 73 74 61 72 74 20 b8  |eap",1,h_start .|
00000fc0  20 2c 2c 6c 61 72 67 65  73 74 0d 05 50 1d 20 e3  | ,,largest..P. .|
00000fd0  68 5f 72 62 6c 6b 3d 68  5f 66 75 6c 6c 2d 31 20  |h_rblk=h_full-1 |
00000fe0  b8 20 30 20 88 2d 31 0d  05 5a 1e 20 20 62 6c 6f  |. 0 .-1..Z.  blo|
00000ff0  63 6b 3d 68 5f 72 65 6c  6f 63 21 28 68 5f 72 62  |ck=h_reloc!(h_rb|
00001000  6c 6b 2a 34 29 0d 05 64  1d 20 20 e7 20 62 6c 6f  |lk*4)..d.  . blo|
00001010  63 6b 21 2d 34 3c 3e 26  34 42 34 33 34 46 34 43  |ck!-4<>&4B434F4C|
00001020  20 8c 0d 05 6e 2f 20 20  20 c8 99 20 22 4f 53 5f  | ...n/   .. "OS_|
00001030  48 65 61 70 22 2c 36 2c  68 5f 73 74 61 72 74 2c  |Heap",6,h_start,|
00001040  62 6c 6f 63 6b 2d 34 20  b8 20 2c 2c 2c 73 69 7a  |block-4 . ,,,siz|
00001050  65 0d 05 78 0b 20 20 20  6f 6b 3d a3 0d 05 82 08  |e..x.   ok=.....|
00001060  20 20 20 f5 0d 05 8c 18  20 20 20 20 e7 20 73 69  |   .....    . si|
00001070  7a 65 3c 6c 61 72 67 65  73 74 20 8c 0d 05 96 8b  |ze<largest .....|
00001080  20 20 20 20 20 f2 68 65  61 70 5f 72 65 6c 6f 63  |     .heap_reloc|
00001090  61 74 65 28 62 6c 6f 63  6b 2c 73 69 7a 65 2d 38  |ate(block,size-8|
000010a0  29 3a c8 99 20 22 4f 53  5f 48 65 61 70 22 2c 31  |):.. "OS_Heap",1|
000010b0  2c 68 5f 73 74 61 72 74  20 b8 20 2c 2c 6c 61 72  |,h_start . ,,lar|
000010c0  67 65 73 74 2c 6d 61 78  66 72 65 65 3a e7 20 68  |gest,maxfree:. h|
000010d0  5f 72 65 6c 6f 63 21 28  68 5f 72 62 6c 6b 2a 34  |_reloc!(h_rblk*4|
000010e0  29 3d 62 6c 6f 63 6b 20  8c 6f 6b 3d b9 20 8b 62  |)=block .ok=. .b|
000010f0  6c 6f 63 6b 3d 68 5f 72  65 6c 6f 63 21 28 68 5f  |lock=h_reloc!(h_|
00001100  72 62 6c 6b 2a 34 29 0d  05 a0 09 20 20 20 20 cc  |rblk*4)....    .|
00001110  0d 05 aa 0d 20 20 20 20  20 6f 6b 3d b9 0d 05 b4  |....     ok=....|
00001120  09 20 20 20 20 cd 0d 05  be 0b 20 20 20 fd 20 6f  |.    .....   . o|
00001130  6b 0d 05 c8 07 20 20 cd  0d 05 d2 06 20 ed 0d 05  |k....  ..... ...|
00001140  dc 05 cd 0d 05 e6 16 c8  99 20 22 48 6f 75 72 67  |......... "Hourg|
00001150  6c 61 73 73 5f 4f 66 66  22 0d 05 f0 10 f2 68 65  |lass_Off".....he|
00001160  61 70 5f 72 65 64 75 63  65 0d 05 fa 05 e1 0d 06  |ap_reduce.......|
00001170  04 05 3a 0d 06 0e 3d f4  20 50 52 4f 43 68 65 61  |..:...=. PROChea|
00001180  70 5f 72 65 64 75 63 65  20 3a 20 72 65 64 75 63  |p_reduce : reduc|
00001190  65 20 74 68 65 20 68 65  61 70 20 74 6f 20 69 74  |e the heap to it|
000011a0  27 73 20 73 6d 61 6c 6c  65 73 74 20 73 69 7a 65  |'s smallest size|
000011b0  0d 06 18 11 dd f2 68 65  61 70 5f 72 65 64 75 63  |......heap_reduc|
000011c0  65 0d 06 22 10 ea 20 6d  61 78 66 72 65 65 2c 6f  |e..".. maxfree,o|
000011d0  6b 0d 06 2c 1c 6d 61 78  66 72 65 65 3d 68 5f 73  |k..,.maxfree=h_s|
000011e0  69 7a 65 2d 68 5f 73 74  61 72 74 21 38 0d 06 36  |ize-h_start!8..6|
000011f0  15 c8 95 20 6d 61 78 66  72 65 65 3e 68 5f 70 61  |... maxfree>h_pa|
00001200  67 65 0d 06 40 2b 20 c8  99 20 22 58 4f 53 5f 48  |ge..@+ .. "XOS_H|
00001210  65 61 70 22 2c 35 2c 68  5f 73 74 61 72 74 2c 2c  |eap",5,h_start,,|
00001220  2d 68 5f 70 61 67 65 20  b8 20 3b 6f 6b 0d 06 4a  |-h_page . ;ok..J|
00001230  3c 20 e7 20 28 6f 6b 20  80 20 31 29 3d 31 20 8c  |< . (ok . 1)=1 .|
00001240  6d 61 78 66 72 65 65 3d  30 20 8b 68 5f 73 69 7a  |maxfree=0 .h_siz|
00001250  65 2d 3d 68 5f 70 61 67  65 3a 6d 61 78 66 72 65  |e-=h_page:maxfre|
00001260  65 2d 3d 68 5f 70 61 67  65 0d 06 54 32 20 c8 99  |e-=h_page..T2 ..|
00001270  20 22 58 57 69 6d 70 5f  53 6c 6f 74 53 69 7a 65  | "XWimp_SlotSize|
00001280  22 2c 68 5f 61 70 70 62  61 73 65 2b 68 5f 73 69  |",h_appbase+h_si|
00001290  7a 65 2c 2d 31 20 b8 20  3b 6f 6b 0d 06 5e 05 ce  |ze,-1 . ;ok..^..|
000012a0  0d 06 68 05 e1 0d 06 72  05 3a 0d 06 7c 37 f4 20  |..h....r.:..|7. |
000012b0  50 52 4f 43 68 65 61 70  5f 6f 6b 74 6f 6d 6f 76  |PROCheap_oktomov|
000012c0  65 20 3a 20 6d 6f 76 65  20 61 20 72 65 6c 6f 63  |e : move a reloc|
000012d0  61 74 61 62 6c 65 20 68  65 61 70 20 62 6c 6f 63  |atable heap bloc|
000012e0  6b 0d 06 86 41 f4 20 4f  6e 6c 79 20 63 61 6c 6c  |k...A. Only call|
000012f0  65 64 20 77 69 74 68 69  6e 20 50 52 4f 43 68 65  |ed within PROChe|
00001300  61 70 5f 67 61 72 62 61  67 65 2c 20 66 72 6f 6d  |ap_garbage, from|
00001310  20 50 52 4f 43 68 65 61  70 5f 72 65 6c 6f 63 61  | PROCheap_reloca|
00001320  74 65 0d 06 90 21 dd f2  68 65 61 70 5f 6f 6b 74  |te...!..heap_okt|
00001330  6f 6d 6f 76 65 28 f8 20  62 6c 6f 63 6b 2c 73 69  |omove(. block,si|
00001340  7a 65 29 0d 06 9a 0b ea  20 6c 6f 63 2c 62 0d 06  |ze)..... loc,b..|
00001350  a4 2a c8 99 20 22 4f 53  5f 48 65 61 70 22 2c 32  |.*.. "OS_Heap",2|
00001360  2c 68 5f 73 74 61 72 74  2c 2c 73 69 7a 65 2b 34  |,h_start,,size+4|
00001370  20 b8 20 2c 2c 6c 6f 63  0d 06 ae 2d e7 20 6c 6f  | . ,,loc...-. lo|
00001380  63 3e 62 6c 6f 63 6b 20  8c c8 99 20 22 4f 53 5f  |c>block ... "OS_|
00001390  48 65 61 70 22 2c 33 2c  68 5f 73 74 61 72 74 2c  |Heap",3,h_start,|
000013a0  6c 6f 63 3a e1 0d 06 b8  19 21 6c 6f 63 3d 26 34  |loc:.....!loc=&4|
000013b0  33 34 46 34 43 35 32 3a  6c 6f 63 2b 3d 34 0d 06  |34F4C52:loc+=4..|
000013c0  c2 26 e3 20 62 3d 30 20  b8 20 73 69 7a 65 2d 34  |.&. b=0 . size-4|
000013d0  20 88 20 34 3a 6c 6f 63  21 62 3d 62 6c 6f 63 6b  | . 4:loc!b=block|
000013e0  21 62 3a ed 0d 06 cc 43  c8 99 20 22 4f 53 5f 48  |!b:....C.. "OS_H|
000013f0  65 61 70 22 2c 33 2c 68  5f 73 74 61 72 74 2c 62  |eap",3,h_start,b|
00001400  6c 6f 63 6b 2d 34 3a 62  6c 6f 63 6b 3d 6c 6f 63  |lock-4:block=loc|
00001410  3a 68 5f 72 65 6c 6f 63  21 28 68 5f 72 62 6c 6b  |:h_reloc!(h_rblk|
00001420  2a 34 29 3d 6c 6f 63 0d  06 d6 05 e1 0d 06 e0 05  |*4)=loc.........|
00001430  3a 0d 06 ea 23 f4 20 46  4e 73 74 72 64 75 70 20  |:...#. FNstrdup |
00001440  3a 20 44 75 70 6c 69 63  61 74 65 20 61 20 73 74  |: Duplicate a st|
00001450  72 69 6e 67 0d 06 f4 28  dd a4 73 74 72 64 75 70  |ring...(..strdup|
00001460  28 61 24 29 3a ea 20 70  25 3a 70 25 3d a4 63 6c  |(a$):. p%:p%=.cl|
00001470  61 69 6d 28 a9 28 61 24  29 2b 31 29 0d 06 fe 16  |aim(.(a$)+1)....|
00001480  e7 20 70 25 3c 3e 2d 31  20 8c 24 28 70 25 29 3d  |. p%<>-1 .$(p%)=|
00001490  61 24 0d 07 08 07 3d 70  25 0d ff                 |a$....=p%..|
0000149b