/SWAPPER TASK FOR RTS8 V2			8/30/74

/	2-APR-75 CHANGE: FORCE OFF SWPWT AND FORCE ON NONRWT
/	18-JUN-75 FIX GROSS BUG IN NON-CHECKPOINTING VERSION
/	19-JUN-75 FIX BUG IN CHECKPOINTING VERSION

/
/
/
/
/
/
/
/
/
/COPYRIGHT  (C)  1974,1975 BY DIGITAL EQUIPMENT CORPORATION
/
/
/
/
/
/
/
/
/
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE WITHOUT NOTICE
/AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
/CORPORATION.  DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/FOR ANY ERRORS THAT MAY APPEAR IN THIS DOCUMENT.
/
/THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FURNISHED TO THE PURCHASER
/UNDER A LICENSE FOR USE ON A SINGLE COMPUTER SYSTEM AND CAN BE COPIED
/(WITH INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR USE IN SUCH
/SYSTEM, EXCEPT AS MAY OTHERWISE BE PROVIDED IN WRITING BY DIGITAL.
/
/DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY FOR THE USE
/OR RELIABILITY OF ITS SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY
/DIGITAL.
/
/
/
/
/
/
/
/
/
/
	TASK=	SWAPPER		/BY SHAWN 7/25/74
	CUR=	0
	INIWT=	RUNWT
	FIELD	0		/MUST BE FIELD 0
	*COMMAND
	INIT			/ENTRY POINT FOR INITIALIZATION
	XFREE
/
/PARTITION TABLE (PARTBL) ENTRIES:
/MUST BE INITIALIZED BY USER AS EXPLAINED IN THE COMMENTS
/DON'T FORGET TO REMOVE LEADING "/" FROM LINES USED
/
	*PARTBL
	XLIST	1
	IFNZRO	PARTNS		<XLIST	0
/MFLD00=			/MEMORY FIELD OF PARTITION #0 (E.G. 2 IF FIELD 2)
/ADDR00=			/LOWEST ADDRESS IN PARTITION #0
/SIZE00=			/SIZE OF PARTITION #0 (CORE PAGES)
	SIZE00^10+MFLD00^10+4000
	ADDR00
	ZBLOCK	2
	XLIST
	IFNZRO	PARTNS-1	<XLIST	0
/MFLD01=			/MEMORY FIELD OF PARTITION #1
/ADDR01=			/LOWEST ADDRESS IN PARTITION #1
/SIZE01=			/SIZE OF PARTITION #1 (CORE PAGES)
	SIZE01^10+MFLD01^10+4000
	ADDR01
	ZBLOCK	2
	XLIST
	IFNZRO	PARTNS-2	<XLIST	0
/MFLD02=			/MEMORY FIELD OF PARTITION #2
/ADDR02=			/LOWEST ADDRESS IN PARTITION #2
/SIZE02=			/SIZE OF PARTITION #2
	SIZE02^10+MFLD02^10+4000
	ADDR02
	ZBLOCK	2
	XLIST
	IFNZRO	PARTNS-3	<XLIST	0
/MFLD03=		/PARTITION #3
/ADDR03=
/SIZE03=
	SIZE03^10+MFLD03^10+4000
	ADDR03
	ZBLOCK	2
	XLIST
	IFNZRO	PARTNS-4	<XLIST	0
/MFLD04=		/PARTITION #4
/ADDR04=
/SIZE04=
	SIZE04^10+MFLD04^10+4000
	ADDR04
	ZBLOCK	2
	XLIST
	IFNZRO	PARTNS-5	<XLIST	0
/MFLD05=		/PARTITION #5
/ADDR05=
/SIZE05=
	SIZE05^10+MFLD05^10+4000
	ADDR05
	ZBLOCK	2
	XLIST
	IFNZRO	PARTNS-6	<XLIST	0
/MFLD06=		/PARTITION #6
/ADDR06=
/SIZE06=
	SIZE06^10+MFLD06^10+4000
	ADDR06
	ZBLOCK	2
	XLIST
	IFNZRO	PARTNS-7	<XLIST	0
/MFLD07=		/PARTITION #7
/ADDR07=
/SIZE07=
	SIZE07^10+MFLD07^10+4000
	ADDR07
	ZBLOCK	2
	XLIST>>>>>>>>
/
/ADDITIONAL PARTITIONS MAY BE DEFINED BY THE USER AS SHOWN ABOVE
/FURTHERMORE, THE PARTITION TABLE MAY RESIDE ANYWHERE IN FIELD ZERO
/
	XLIST	0
	PAGE
	NRTASK=SWAPPER+1
LOOPNX,	IFZERO	HGHFLD	<ION>
	ISZ	NXTFLG		/BUMP TFTABL POINTER
	ISZ	NFLAGS		/AND TASK COUNTER
	 JMP	LOOPON		/CONTINUE IF ANY TASKS LEFT
SWAPEX,	 CAL
	 SUSPND
START,
SWAPON,	TAD	(NRTASK+TFTABL
	DCA	NXTFLG		/POINTS TO NEXT TFTABL ENTRY
	TAD	(NRTASK-NTASKS
	DCA	NFLAGS		/TFTABL ENTRY OVERFLOW COUNT
LOOPON,	TAD I	NXTFLG		/GET A FLAG WORD
	AND	KSWPWT		/KEEP ONLY THE SWPWT BIT
	SNA CLA			/THIS TASK IN SWPWT?
	 JMP	LOOPNX		/NO: TRY NEXT TASK
	IFZERO	HGHFLD	<IOF>
	IFNZRO	HGHFLD	<CIF CUR>
	TAD I	NXTFLG		/GET THE FLAG WORD
	TAD	(-SWPWT		/LESS THE SWPWT BIT
	SNA			/TASK RUNABLE NOW?
	 JMP	GOTONE		/YES: RESIDENCY CANDIDATE
	TAD	KNRWT		/NO: FLAG HIM NONRESIDENT
	DCA I	NXTFLG		/AND TRY SOMEONE ELSE
	JMP	LOOPNX
GOTONE,	IFZERO	HGHFLD	<ION>
	TAD	NXTFLG
	TAD	(-TFTABL
	CLL RAL			/TASK NUMBER TIMES 2
	TAD	(-NRTASK-NRTASK+RESTBL
	DCA	PTR2		/POINTS TO RESTBL WORD 1
UNBUSY,	TAD I	PTR2
	AND	(7774
	DCA	PTR3		/POINTS TO PARTBL WORD 1
	TAD I	PTR3
	RAR			/PARTITION BUSY BIT TO LINK
	SZL			/PARTITION BUSY?
	 JMP	CHKPT		/YES: CHECKPOINT
	RAL
	DCA	LEVEL		/SAVE IO DRIVER ARG2
	ISZ	PTR2		/POINTS TO RESTBL WORD 2
	ISZ I	PTR3		/FLAG PARTITION BUSY
	ISZ	PTR3		/POINTS TO PARTBL WORD 2
	TAD I	PTR3		/GET PARTITION ADDRESS
	DCA	CORADR
	ISZ	PTR3		/POINTS TO PARTBL WORD 3
	TAD I	PTR3
	SNA			/ANYONE HOME?
	 JMP	NORITE
	DCA	PTR4		/POINTS TO RESTBL WORD 1
	TAD	PTR4
	CMA			/COMPARE WITH SAME POINTER
	TAD	PTR2		/FOR NEW RESIDENT
	SNA CLA			/SAME TASK?
	 JMP	NOREAD		/YES: NO TASK IO
	TAD I	PTR4
	RAR			/"WRITE ME" BIT TO LINK
	SNL CLA			/NEED TO WRITE CURRENT OCCUPANT?
	 JMP	NORITE		/NO: READ IN NEW OCCUPANT
	ISZ	PTR4		/POINTS TO RESTBL WORD 2
	TAD I	PTR4		/AC=DISK ADDRESS FOR WRITE
	DCA	DSKADR
	JMS	SENDIT
NORITE,	CLL CMA RAR		/AC3777
	AND	LEVEL
	DCA	LEVEL		/CLEAR THE WRITE BIT
	TAD I	PTR2
	DCA	DSKADR
	JMS	SENDIT	
NOREAD,	CLA CMA
	TAD	PTR2
	DCA I	PTR3
	TAD I	PTR3
	TAD	(NRTASK+NRTASK-RESTBL
	CLL RAR
	CAL			/CLEAR HIS SWAP WAIT
	 UNBARG
KSWPWT,	 SWPWT
	JMP	SWAPON		/RESCAN FROM THE TOP
	IFDEF	CHECKPT	<
CHKPT,	STL CLA RTL		/AC0002
	TAD	PTR3
	DCA	PTR4
	TAD I	PTR4
	DCA	PTR1		/POINTS TO OWNER'S RESTBL WORD 1
	TAD I	PTR1
	RTR			/"CHECKPOINTABLE" BIT TO LINK
	SNL CLA			/IS HE CHECKPOINTABLE?
	 JMP	LOOPNX		/NO: NEXT REQUEST
	TAD	PTR1
	CLL CMA
	TAD	PTR2		/COMPARE RESTBL POINTERS
	SZL CLA			/NEWCOMER HIGHER PRIORITY?
	 JMP	LOOPNX		/NO: NEXT REQUEST
	TAD	PTR1
	TAD	(NRTASK+NRTASK-RESTBL
	CLL RAR
	CAL
	 BLKARG
	>
KNRWT,	 NONRWT
	IFDEF	CHECKPT	<
	STA			/FLAG PARTITION "FREE"
	TAD I	PTR3
	DCA I	PTR3
	JMP	UNBUSY
	>
	IFNDEF CHECKPT <
CHKPT,	CLA
	JMP	LOOPNX
	>
NXTFLG,	0
NFLAGS,	0
PTR2,	0
PTR3,	0
PTR4,
SENDIT,	0
RETRY,	CAL
	 SENDW
	 SYS
	 SYSMSG
	TAD	ERRORS
	SNA CLA
	 JMP I	SENDIT
	JMP	RETRY
SYSMSG,	ZBLOCK 3
UNIT,	SUNIT
LEVEL,	.
CORADR,	.
DSKADR,	.
PTR1,
ERRORS,	.
	PAGE
	TASKX=	32
	T=	42

/
/THE FOLLOWING CODE IS ACTUALLY PART OF THE EXECUTIVE
/HOWEVER, IT RESIDES HERE FOR COMPATIBILITY WITH VERSION 1.
/ENTER WITH ION, AC=0, LINK=DON'T CARE, SAVE STATE ON INTERRUPTS
/
XFREE,	0			/FREE UP A PARTITION
	TAD	TASKX
	TAD	(-NRTASK
	SPA			/THIS TASK LOWER PRIORITY THAN SWAPPER?
	 JMP I	XFREE		/NO: BAD FREE COMMAND
	CLL RAL
	TAD	(RESTBL
	DCA	T		/POINTS TO RESTBL WORD 1
	TAD I	T
	SNA			/IS TASK REALLY NONRES?
	 JMP I	XFREE		/NO: RETURN
	AND	(7774		/YES: ERASE FLAG BITS
	DCA	T		/POINTS TO PARTBL WORD 1
	AC7776
	AND I	T
	DCA I	T		/FLAG PARTITION "FREE"
	TAD	TASKX
	TAD	(TFTABL
	DCA	T		/POINTS TO TASK'S FLAG WORD
	IFNZRO	HGHFLD	<CIF 0>
	IFZERO	HGHFLD	<IOF>
	STL RAR
	TAD I	T
	DCA I	T		/FLAG TASK NONRESIDENT
	TAD	(-RUNWT-1
	AND I	(SWAPPER+TFTABL
	DCA I	(SWAPPER+TFTABL	/CANCEL SWAPPER RUN WAIT
	IFZERO	HGHFLD	<ION>	/BE NICE SINCE SPACE IS NO PROBLEM
	JMP I	XFREE		/FIND NEXT TASK TO RUN
/
/THE FOLLOWING CODE IS ENTERED AT LOAD TIME AND EXECUTED
/TO INITIALIZE THE RESTBL WITH THE DISK ADDRESS OF EACH
/NONRESIDENT TASK.  ONCE THIS CODE HAS RETURNED TO THE EXEC,
/IT IS NEVER EXECUTED AGAIN.  IT COULD BE PLACED IN ANY
/PARTITION (SINCE ALL ARE EMPTY AT LOAD TIME) IF DESIRED.
/
INIT,	0
	CIF	10
	JMS I	(7700
	 10
NEXTIN,	CIF	10
	JMS I	(200
	 5
	 2326
	CDF	10
	TAD I	(7646
	SNA
	 JMP	NOINPUT
	CLL RAL
	TAD	(-SWAPPER-SWAPPER-1+RESTBL
	DCA	T
	TAD I	(7646	/
	TAD	(TFTABL	/
	DCA	TFPTR	/
	TAD I	(7620
	CDF
	IAC
	DCA I	T
	TAD I	TFPTR	/
	AND	(-SWPWT-NONRWT-1	/FORCE TASK NON-RESIDENT WAIT BIT ON
	TAD	(NONRWT	/
	DCA I	TFPTR	/
	CDF	10
NOINPUT,TAD I	(7642
	CDF
	SMA CLA
	 JMP	NEXTIN
	CIF	10
	JMS I	(200
	 11
	CLA CLL CMA
	TAD	INIT
	DCA	INIT
	TAD	(ION
	DCA I	INIT
	JMP I	(200

TFPTR,	0		/
	$$$$$

