2 TITLE MODIFIED AFREE FOR MUDDLE
8 .GLOBAL CAFREE,CAFRET,PARNEW,AGC,PARBOT,CODTOP,CAFRE1
9 .GLOBAL STOGC,STOSTR,CAFRE,ISTOST,STOLST,SAT,ICONS,BYTDOP
10 .GLOBAL FLIST,STORIC,GPURFL,GCDANG,PVSTOR,SPSTOR
17 GETYP A,(AB) ; get type of it
18 PUSH TP,(AB) ; save a copy
20 PUSH P,[0] ; flag for tupel freeze
22 MOVEI B,0 ; final type
23 CAIN A,SNWORD ; check valid types
24 MOVSI B,TUVEC ; use UVECTOR
34 PUSH P,B ; save final type
37 CAME B,$TCHSTR ; special chars hack
39 HRR B,(AB) ; fixup count
42 MOVEI C,(TB) ; point to it
43 PUSHJ P,BYTDOP ; A==> points to dope word
45 SUBI A,1(B) ; A==> length of block
47 MOVEM B,1(TB) ; and save
51 OK.FR: HLRE A,1(TB) ; get length
55 PUSHJ P,CAFREE ; get storage
56 HRLZ B,1(TB) ; set up to BLT
59 ADDI C,(A) ; compute end
61 HLLOS 1(C) ; INDICATION IN RELOCATION FIELD THAT ITS NOT GARBAGE
71 PUSHJ P,ICONS ; get list element
72 PUSH TP,$TLIST ; and save
74 MOVE A,(P) ; restore length
75 ADDI A,2 ; 2 more for dope words
76 PUSHJ P,CAFREE ; get the core and dope words
77 POP P,B ; restore count
78 MOVNS B ; build AOBJN pointer
82 MOVEM B,1(C) ; save on list
83 MOVSI 0,TSTORA ; and type
85 HRRZM C,STOLST+1 ; and save as new list
92 HRROI B,(A) ; pointer to B
97 CAFREE: IRP AC,,[B,C,D,E]
100 SKIPG A ; make sure arg is a winner
101 FATAL BAD CALL TO CAFREE
102 MOVSI A,(A) ; count to left half for search
103 MOVEI B,FLIST ; get first pointer
104 HRRZ C,(B) ; c points to next block
105 CLOOP: CAMG A,(C) ; skip if not big enough
106 JRST CONLIS ; found one
107 MOVEI D,(B) ; save in case fall out
108 MOVEI B,(C) ; point to new previous
109 HRRZ C,(C) ; next block
110 JUMPN C,CLOOP ; go on through loop
111 HLRZ E,A ; count to E
112 CAMGE E,STORIC ; skip if a area or more
113 MOVE E,STORIC ; else use a whole area
114 MOVE C,PARBOT ; found out if any funny space
115 SUB C,CODTOP ; amount around to C
117 CAMLE C,E ; skip if must GC
118 JRST CHAVIT ; already have it
119 SUBI E,-1(C) ; get needed from agc
120 MOVEM E,PARNEW ; funny arg to AGC
122 MOVE C,[7,,6] ; SET UP AGC INDICATORS
123 SKIPE GPURFL ; DONT GC IF IN DUMPER
125 PUSHJ P,AGC ; collect that garbage
126 SETZM PARNEW ; dont do it again
129 ; Make sure pointers still good after GC
134 HRRZ E,(D) ; next pointer
135 JUMPE E,.+4 ; end of list ok
138 JRST .-4 ; look at next
140 CHAVIT: MOVE C,CODTOP
142 PUSHJ P,%CLNCO ; flush extra pages
143 MOVE E,PARBOT ; find amount obtained
144 SUBI E,1 ; dont use a real pair
145 MOVEI C,(E) ; for reset of CODTOP
147 EXCH C,CODTOP ; store it back
148 CAIE B,(C) ; did we simply grow the last block?
149 JRST CSPLIC ; no, splice it in
150 HLRZ C,(B) ; length of old guy
151 ADDI C,(E) ; total length
152 ADDI B,(E) ; point to new last dope word
153 HRLZM C,(B) ; clobber final length in
154 HRRM B,(D) ; and splice into free list
155 MOVEI C,(B) ; reset acs for reentry into loop
159 ; Here to splice new core onto end of list.
161 CSPLIC: MOVE C,CODTOP ; point to end of new block
162 HRLZM E,(C) ; store length of new block in dope words
163 HRRM C,(D) ; D is old previous, link it up
164 MOVEI B,(D) ; and reset B for reentry into loop
167 ; here if an appropriate block is on the list
169 CONLIS: HLRZS A ; count back to a rh
170 HLRZ D,(C) ; length of proposed block to D
171 CAIN A,(D) ; skip if they are different
172 JRST CEASY ; just splice it out
173 MOVEI B,(C) ; point to block to be chopped up
174 SUBI B,-1(D) ; point to beginning of same
175 SUBI D,(A) ; amount of block to be left to D
176 HRLM D,(C) ; and fix up dope words
177 ADDI B,-1(A) ; point to end of same
179 HRRM B,(B) ; for GC benefit
181 CFREET: CAIE A,1 ; if more than 1
182 SETZM -1(B) ; make tasteful dope worda
185 ACRST: IRP AC,,[E,D,C,B]
190 PURGC: SUB P,[1,,1] ; CLEAN OFF STACK
191 SETOM GCDANG ; INDICATE GC SHOULD HAVE OCCURED
194 CEASY: MOVEI D,(C) ; point to block to return
195 HRRZ C,(C) ; point to next of same
196 HRRM C,(B) ; smash its previous
197 MOVEI B,(D) ; point to block with B
198 HRRM B,(B) ; for GC benefit
201 CAFRET: HRROI B,(B) ; prepare to search list
202 TLC B,-1(A) ; by making an AOBJN pointer
203 HRRZ C,STOLST+1 ; start of list
206 CAFRTL: JUMPE C,CPOPJ ; not founc
207 CAME B,1(C) ; this it?
209 HRRZ C,(C) ; yes splice it out
210 HRRM C,(D) ; smash it
211 CPOPJ: POPJ P, ; dont do anything now
217 ; Here from GC to collect all unused blocks into free list
219 STOGC: SETZB C,E ; zero current length and pointer
220 MOVE A,CODTOP ; get high end of free space
222 STOGCL: CAIG A,STOSTR ; end?
223 JRST STOGCE ; yes, cleanup and leave
225 HLRZ 0,(A) ; get length
227 SKIPGE (A) ; skip if a not used block
228 JRST STOGC1 ; jump if marked
230 ; HERE TO SEE WHETHER AN UNMARKED ITEM IS AN ATOM. IF IT IS IT IS NOT GARBAGE
231 ; AND IT IS PRESERVED WITH ITS VALUE CELLS FLUSHED
233 HLRZ 0,-1(A) ; GET TYPE OF FIRST D.W.
234 ANDI 0,TYPMSK ; FLUSH MONITORS
236 JRST STOGC5 ; NOT AN ATOM COLLECT THE GARBAGE
237 PUSH P,A ; SAVE PTR TO D.W.
239 SUB A,0 ; POINT TO JUST BEFORE ATOM
240 SETZM 1(A) ; ZERO VALUE CELLS
246 JUMPE C,STOGC3 ; jump if no block under construction
247 ADD C,0 ; else add this length to current
250 STOGC3: MOVEI B,(A) ; save pointer
251 MOVE C,0 ; init length
253 STOGC4: SUB A,0 ; point to next block
256 STOGC1: HLLOS (A) ; -1 IS INDICATOR OF FREE SLOT
257 ANDCAM D,(A) ; kill mark bit
258 JUMPE C,STOGC4 ; if no block under cons, dont fix
259 HRLM C,(B) ; store total block length
260 HRRM E,(B) ; next pointer hooked in
261 MOVEI E,(B) ; new next pointer
265 STOGCE: JUMPE C,STGCE1 ; jump if no current block
266 HRLM C,(B) ; smash in count
267 HRRM E,(B) ; smash in next pointer
268 MOVEI E,(B) ; and setup E
270 STGCE1: HRRZM E,FLIST+1 ; final link up