perm filename SPACE.FAI[NEW,AIL] blob sn#408319 filedate 1979-01-08 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	TITLE SPACE   ROUTINES TO CALL CORGET & CORREL
C00004 00003	
C00008 ENDMK
C⊗;
TITLE SPACE   ROUTINES TO CALL CORGET & CORREL;

INTERNAL GETSPACE,FREESPACE,GETSMALL,FREESMALL
INTERNAL LINKSMALL,ADDSIZE,LOPSMALL,BOWNRS

EXTERNAL CORGET,CORREL,X22,X44,X33

COMMENT ⊗
ADR ← GETSPACE(SIZ);
FREESPACE(ADR);

ADR←GETSMALL(SIZ);
ADR←LOPSMALL(OWNR);

FREESMALL(ADR,SIZ);
LINKSMALL(ADR,OWNR);
OWNR←ADDSIZ(SIZE,INCR COUNT(50),OWNR(0));

⊗

OPDEF	ERR.	[5B8]
P←17

GETSPACE:
	HRRZ	3,-1(17)	;GET SIZE
	JUMPLE	3,XIT0		;NOTHING TO DO
	PUSHJ	17,CORGET	;GET SPACE
	JRST	[ 	ERR.	1,[ASCIZ /GETSPACE COULDN'T GET ANY/]
		XIT0:	SETZ	1,
			JRST	XIT1]
	HRRZ	1,2		;GET THE RESULT
ZERXX:	SETZM	(1)		;ZERO FIRST WORD
	CAIG	3,1		;MORE TO DO ?
	JRST	XIT1		;NOPE
ZERIT:	HRLI	2,1(2)
	MOVS	2,2		;BLT PTR
	MOVE	4,1		;START
	ADDI	4,-1(3)		;STOP
	BLT	2,(4)		;GO TO IT
XIT1:	SUB	17,X22
	JRST	@2(17)

FREESPACE:
	HRRZ	2,-1(17)	;ADR TO FREE
	PUSHJ	17,CORREL	;FREE IT
	JRST 	XIT1


SIZSCH:	SKIPN	2,BOWNRS	;PICK UP OWNER LIST
CPOPJ:	POPJ	P,		;NO OWNERS AT ALL
	MOVEI	4,BOWNRS	;THE PREDECESSOR
NXTSIZ:	MOVS	1,(2)		;PICK UP NEXT,,SIZE
	CAIN	3,(1)		;
	JRST	SIZWIN		;
	MOVE	4,2		;REMEMBER THIS AS PREV
	HLRZ	2,1		;POINT AT NEXT
	JUMPN	2,NXTSIZ	;
	POPJ	P,		;LOSE
SIZWIN:	AOS	(P)		;
	POPJ	P,		;WIN

ADDSIZE: MOVE	3,-3(P)		;SEE IF ALREADY HAVE ONE
	MOVE	5,-1(P)		;THE OWNR, IF ANY
	PUSHJ 	P,SIZSCH	;
	JRST	DOADD		;NOPE
	JUMPN	5,[ TRN 3,
		ERR.	3,[ASCIZ/ YOU A1LREADY HAVE BLOCKS OF THAT SIZE/]
		JRST 	AXIT]
	HRRZ	1,2
IUPD:	HRRZ	10,-2(P)		;JUST REVISE INCREMENT COUNT
	HRLM	10,1(1)		
AXIT:	SUB	P,X44
	JRST	@4(P)
DOADD:	JUMPN	5,GOWNR
	MOVEI	3,2
	PUSHJ	P,CORGET	;UGH!
	JRST	[
		ERR.	1,CGLOSSAGE
		JRST	AXIT ]
	MOVE	5,2
GOWNR:	HRRZ	1,5
	EXCH	5,BOWNRS	;NEW OWNER
	HRL	5,-3(P)		;SIZE
	MOVEM	5,(1)		;PUT AWAY
	SETZM	1(1)		;CLEAN
	JRST	IUPD

GETSMALL: MOVE	3,-1(P)		;SIZE
	PUSHJ	P,SIZSCH
	JRST	[TRN 3,
		ERR.	1,SLOSSAGE
		JRST	XIT0]
	SKIPA	5,2
LOPSMALL: MOVE	5,-1(P)		;THE OWNR
LOPPIT:	HRRZ	1,1(5)		;THE BLOCK
	JUMPN	1,LOPOFF	;HAD ONE
	HLRZ	3,(5)		;SIZE
	HLRZ	10,1(5)		;COUNT
	CAIGE	10,1		;AT LEAST 1 YOU CRETIN
	MOVEI	10,1		;HE ISN'T GOING TO LIKE THIS
	IMUL	3,10		;TOTAL SIZE
	PUSHJ	P,CORGET
	JRST	[ERR. 1,CGLOSSAGE
		JRST	XIT0
		]
	HLRZ	3,(5)		;SIZE ONCE AGAIN
	MOVEI	1,0		;NULL LINK
LNK1C:	MOVEM	1,(2)
	MOVE	1,2
	ADD	2,3
	SOJG	10,LNK1C
LOPOFF:	HRRZ	2,(1)		
	HRRM	2,1(5)		;CDR DOWN
	MOVE	2,1
	JRST	ZERXX

FREESMALL: MOVE	3,-1(P)
	PUSHJ	P,SIZSCH
	JRST	[ TRN 3,
		ERR. 1,SLOSSAGE
		JRST XIT2 ]
	SKIPA	5,2
LINKSMALL: MOVE 5,-1(P)
	MOVE	1,-2(P)		;THE  BLOCK
	HRRZ	10,1(5)		;OLD HEAD
	MOVEM	10,(1)
	HRRM	1,1(5)
XIT2:	SUB	P,X33
	JRST	@3(P)

SLOSSAGE:ASCIZ/COULD NOT FIND AN OWNER FOR THAT BLOCK LIST/
CGLOSSAGE:ASCIZ/CORGET LOST. NOW IT IS YOUR TURN/

BOWNRS:	0

INILKZ:	0
	[ SETZM BOWNRS
	  POPJ	P, ]
	0

LINK 7,INILKZ

END