/RTS-8 POWER FAIL RECOVERY TASK
/
/
/
/
/
/
/
/
/
/COPYRIGHT  (C)  1974 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.
/
/
/
/
/
/
/
/
/
/

/THIS TASK IS EXECUTED WHEN POWER RETURNS AFTER A POWER FAILURE.  IT
/RESTORES THE CLOCK AND TELETYPE FLAGS ITSELF, BUT DEPENDS ON OTHER
/RTS-8 HANDLERS TO PROVIDE A ROUTINE WHICH, WHEN CALLED, RE-INITIALIZES
/THEIR DEVICE.

/THE ACTION TO BE TAKEN ON POWER FAILURE IS DETERMINED BY THE
/CONTENTS OF THE TABLE "PFLTBL", WHICH CONTAINS ONE WORD
/PER TASK.  A TASK MAY ALTER ITS WORD IN THIS TABLE BY SENDING A
/MESSAGE TO THE POWER-FAIL TASK. THE FORMAT OF THE MESSAGE IS:

/WORD 1		EVENT FLAG (RTS-8 PUTS TASK NUMBER IN LOW BITS)
/WORDS 2-3	RESERVED FOR RTS-8
/WORD 4		NEW TABLE ENTRY VALUE

/IF THE TABLE ENTRY VALUE IS 0, NOTHING WILL BE DONE FOR THE
/CORRESPONDING TASK.  IF THE VALUE IS 7777, THE TASK'S EVENT FLAG
/WAIT BIT WILL BE CLEARED.  IF THE VALUE IS BETWEEN 0 AND 7777, IT
/IS CONSIDERED TO BE THE ADDRESS OF A SUBROUTINE IN THE TASK'S FIELD
/TO WHICH THE TASK WILL BE DERAILED WITH ITS EVENT FLAG WAIT BIT CLEARED.

TASK=	PWRF
CUR=	10
INIWT=	0
/INITIALIZATION CODE

	FIELD	CUR%10
	*200

START,	STA
PTR,	CDF 0
CTR,	TAD I	(3	/GET POINTER TO POWER-FAIL EVENT FLAG
PWFLEF,	DCA	PWFLEF	/WHICH IS ONE LOC BEFORE POWER-UP ROUTINE
	TAD	(4000+TASK
	DCA I	PWFLEF	/INITIALIZE IT TO "WAITING"

PWFLLP,	IOF		/TESTING TWO THINGS - MUST HAVE IOF
	CDF 0
	TAD I	PWFLEF	/HAS POWER GONE DOWN AND COME UP?
	SNA CLA
	JMP	POWRUP	/YES
	TAD I	(TASK^2+MSGTBL
	SZA CLA		/ANY MESSAGES FOR ME?
	JMP	GETMSG	/YES - GO READ MAIL
	CIF 0
	CDF CUR		/NOTHING TO DO -
	WAITM		/WAIT FOR SOMETHING TO HAPPEN
	EORMWT
	JMP	PWFLLP	/ARISE, FAIR DAMSEL!

GETMSG,	ION
	CAL
	RECEIVE		/GET PENDING MESSAGE
MADDR,	0
DCA	.+1
MEFPTR,
MSGCDF,	HLT		/SET DF TO MESSAGE FIELD
	TAD	MSGCDF
	DCA	MEFCDF	/SAVE CDF FOR POST CAL
	AC7775
	TAD	MADDR
	DCA	MEFPTR	/POINT TO MESSAGE EVENT FLAG
	TAD I	MEFPTR	/WHICH CONTAINS SENDING TASK NUMBER
	AND	(177	/IN LOW ORDER 7 BITS
	TAD	(PFLTBL
	DCA	PTR
	TAD I	MADDR	/GET NEW TABLE ENTRY
	CDF CUR
	DCA I	PTR	/STORE IT
	TAD	MEFPTR
	CAL
	POST		/POST MESSAGE EVENT FLAG
MEFCDF,	0
	JMP	PWFLLP
/HERE ON POWER UP

POWRUP,	TAD	(4000+TASK
	DCA I	PWFLEF	/RESET FLAG FOR NEXT POWER FAILURE
	CDF CUR
	ION		/RESTORE INTERRUPTS

/RESTORE CLOCK AND TELETYPE FLAGS AND INTERRUPT ENABLES

	IFDEF	TTY	<TLS>	/ONLY SURE WAY TO SET TTY FLAG
	IFDEF	OS8	<OSTTDV^10+6006>	/DITTO FOR OS/8 TTY
	IFDEF	CLOCK	<
TICKS=	HERTZ%SHERTZ
	IFZERO	CLKTYP	<6131>	/ENABLE CLOCK INTS FOR DK8EA,C
	IFNZRO	CLKTYP&1	<	/COMMON DK8EP, KW12 INIT CODE
TICKS=	1750%SHERTZ
	IFZERO	CLKTYP-3	<	/SPECIFIC DK8EP INIT CODE
CLZE=	6130
	STA
	CLZE		/ZERO COMMAND REGISTER ON DK8EP
	TAD	(5311-4100	/5310 = ENABLE INTS, 1 KHZ, MODE 1
	>
CLLR=	6132	/CALLED CLDE ON DK8EP
CLAB=	6133
	TAD	(4100	/4100 = 1 KHZ, MODE 1
	CLLR		/LOAD COMMAND REGISTER
	CLA		/CLLR DOESN'T CLEAR AC
	TAD	(-TICKS
	CLAB		/SCALE DOWN CLOCK TO SOFTWARE RATE
	CLA		/DOES NOT CLEAR AC
	>
	IFZERO	CLKTYP-1	<	/SPECIFIC KW12 INIT CODE
CLEN=	6134
	TAD	(300	/FORCE CLOCK BUFFER INTO COUNTER AND
	CLEN		/ENABLE KW12 INTERRUPTS
	CLA		/THIS DOESN'T CLEAR AC EITHER
	>
	IFZERO	CLKTYP-2	<	/VT8E INIT CODE
DPGO=	6051
DPSM=	6052	/VT8E INSTRUCTIONS TO START AND STOP DISPLAY
	CLA IAC
	DPGO		/START VT8E AT A RANDOM ADDRESS,
	DPSM		/ENABLING INTERRUPTS - THEN STOP IT IMMEDIATELY
	CLA		/(JUST IN CASE)
	>
	>		/END OF CLOCK CONDITIONAL
	CLA IAC
	DCA	CTR
/PERFORM TASK-DEPENDENT ACTIONS

PWRUPL,	TAD	CTR
	TAD	(PFLTBL
	DCA	PTR
	TAD I	PTR	/GET CONTROL WORD FOR THIS TASK
	SNA
	JMP	PWRUPN	/NOTHING TO DO
	CMA
	SNA
	JMP	PWRUPE	/JUST CLEAR EVENT FLAG WAIT
	CMA
	DCA	DRLADR
	TAD	CTR
	CAL		/DERAIL THE TASK
	DERAIL		/INTO THE SUBROUTINE OF ITS CHOICE
DRLADR,	0
PWRUPE,	TAD	CTR
	CAL
	UNBARG
	EFWT!EORMWT	/CLEAR ALL FLAGS DEPENDING ON EFWT
PWRUPN,	TAD	CTR
	TAD	(-NTASKS
	SNA CLA		/THROUGH?
	JMP	PWFLLP	/YES
	ISZ	CTR
	JMP	PWRUPL
	IFZERO	NTASKS-40&4000	<PAGE>
PFLTBL,	ZBLOCK	NTASKS+1	/FIRST WORD NOT USED
	IFDEF	DTA	<
	*PFLTBL+DTA
	-1
	>
	IFDEF	RK8	<
	*PFLTBL+RK8
	-1
	>
	IFDEF	RF08	<
	*PFLTBL+RF08
	-1
	>
	IFDEF	DF32	<
	*PFLTBL+DF32
	-1
	>
	IFDEF	LPT	<
	*PFLTBL+LPT
	-1
	>
	PAGE
	$-$-$
