	.TITLE	PULSE
/
/  13 MAR 78 (030; PDH) MULTIACCESS STORES ACSW IN LOCATION 4
/  21 JUL 77 (029; PDH) CHANGE 'CREATE' STRATEGY TO BETTER ITERATIVE METHOD
/  19 JUL 77 (027; PDH) CHECK FOR EXISTENCE OF FILE BEFORE CREATION
/  18 JUL 77 (026; PDH) DISPLAY EXPECTED BLOCK NUMBER FOR FCN=2
/  18 JUL 77 (025; PDH) CORRECT INVALID BLOCK NUMBER WHEN FCN=1 IS 1ST CALL
/  15 JUL 77 (023; PDH) TIDY UP SOME LOOSE ENDS WITH SELECTIVE REPLAY;
/			MAKE CODE FOR TIMED REPLAY CONDITIONAL ON 'FSYNC'
/  11 JUL 77 (022; PDH) KEEP ATTEMPTING 'CREATE' UNTIL IT SUCCEEDS
/   7 JUL 77 (020; PDH) MAKE SELECTIVE REPLAY USE 'FILE1'
/   4 JUL 77 (017; PDH) WORK OUT THE BUGS, INCLUDING 'GET','PUT' TO LUN 1
/  30 JUN 77 (016; PDH) CORRECT A WATRAN ASSEMBLY PARAMETER OVERSIGHT
/  29 JUN 77 (     PDH) PICK UP THE CONTINUATION AGAIN
/   3 MAY 77 (015; PDH) CONTINUE THE CONVERSION
/  26 APR 77 (014; PDH) CONVERT TO XVM/RSX
/   4 MAR 76 (PDH) IMPLEMENT FOR DEC FORTRAN ALSO
/  27 FEB 76 (PDH) CHANGE SELECTIVE REPLAY PHILOSOPHY
/  25 FEB 76 (PDH) REPLAY CORRECT NUMBER OF FRAMES
/  19 FEB 76 (PDH) CONTINUE IMPLEMENTATION OF RE-START CODING
/   6 FEB 76 (PDH) ALLOW RE-START OF PREVIOUSLY STORED DISPLAY FILES
/  16 AUG 74 (PDH) CALL 'FSYNC' FROM WATRAN, ALSO
/  14 AUG 74 (PDH) ALLOW REPLAY FILE SIZE OF 254 MAXIMUM
/  10 JUL 74 (PDH) HAVE 'PULSE' CALL 'FSYNC' FOR 8 USEC CLOCK
/  12 MAR 74 (PDH) ADD MORE VERBOSITY TO WARNING MESSAGE
/  25 FEB 74 (PDH) ISSUE WARNING IF DISK NOT DK4
/  20 FEB 74 (PDH) CONDITIONALIZE FOR WATRAN USE
/
/  A ROUTINE TO AID ANIMATION
/  BY  SAVAGE & COOK FEB.70
/
F4=1
/
	.EJECT
DNOP=200000		/ DISPLAY NO OPERATION
CHRI=000000		/ CHARACTER IMMEDIATE
STP=204000
/
IDX=ISZ			/ INDEX POINTER, SKIP NOT EXPECTED
INC=ISZ			/ INCREMENT COUNTER (POSITIVELY)
ECLA=641000		/ EAE CLEAR AC INSTRUCTION
/
X14=14			/AUTO-INDEX
X15=15
	.DEC
MCR=3
DK=9			/ LUN FOR DISK REPLAY
VT=24
	.OCT
/
	.GLOBL	PULSE,DSPLAY,BEGIN,CLEAR,FILER,CLOUDY,.IOERR
/***	.GLOBL	FSYNC,FWAIT
	.IFUND	F4
	.GLOBL	.ARG,.INTRP,.NEXT
MM=100000			/ INTERPRETER DATA MODE MULTIPLIER
OP=10000			/ INTERPRETER OP CODE MULTIPLIER
X10=10
	.ENDC
	.IFDEF	F4
	.GLOBL	.DA
.ARG=.DA
	.ENDC
/
/  AC 16: UP - STORE; DOWN - CHECK AC 17
/  AC 17: UP - REPLAY; DOWN - RETURN
/
	.EJECT
PULSE	XX
	JMS*	.ARG
	JMP	.SETUP	
FCN	0			/ FUNCTION CODE
FRMCNT	0			/ FRAME COUNTER
/
.SETUP	JMP	DKINIT		/ ONCE-ONLY CODE FOR DISK ALLOCATION
/*
PAST=.
	.IFUND	F4
	DZM	CALLED		/ INDICATE INTERPRETER NOT CALLED
	.ENDC
	LAC	(FILE1
	DAC	GBUFPT		/ INITIALIZE 'GET' BUFFER POINTER
	LAC	(400		/ AND 'GET' CONTROL TABLE WORD COUNT
	DAC	CTRLTBL+3	/ IN CASE OF CHANGES BY FCN=1
	LAC*	FCN
	SPA
	JMP*	PULSE		/ IGNORE NEGATIVE FUNCTION CODE
	AAC	-4
	SMA
	JMP*	PULSE		/ IGNORE FCN .GT. 3
	TAD	(JMP SPLIT+1+4	/ GENERATE VALID ENTRY INTO JUMP TABLE
	DAC	SPLIT
/
SPLIT	XX
	JMP	DISK		/ 0 - STORE ON DISK
	JMP	SEARCH		/ 1 - SEARCH FOR LAST FRAME NUMBER STORED
	JMP	NXFRAME		/ 2 - FETCH SPECIFIED FRAME
	JMP	REPLAY		/ 3 - FORCE A REPLAY
/	JMP*	PULSE		/ 4 - RETURN SIZE OF REPLAY FILE;
				/	PRESERVE REPLAY FILE AFTER USE.
/	JMP*	PULSE		/ 5 - RETURN SIZE OF REPLAY FILE;
				/	DELETE REPLAY FILE AFTER USE.
/
	.EJECT
/  SEARCH FOR LAST BLOCK STORED AND RETURN THE NUMBER TO THE USER
/
SEARCH	LAC	SCHBLK		/ 'SCHBLK' WILL BE NEGATIVE IF NO FRAMES
	SPA			/ HAVE BEEN STORED BY THIS TASK, OR ZERO
	JMP	SRCH1		/ FOR A VIRGIN REPLAY FILE.
	SNA!IAC			/ CONVERT FROM 0-ORIGIN TO 1-ORIGIN INDEXING,
	CLA			/ BUT DO NOT CONVERT A ZERO!
	DAC*	FRMCNT		/ RETURN VALUE TO CALLING PROGRAM
	JMP*	PULSE
/
SRCH1	LAC	MBLKS		/ SEARCH REPLAY FILE FOR STATUS BLOCK
	DAC	BLKSIZE		/ FINISH SEARCH AT END OF AVAILABLE SPACE
	DZM*	FRMCNT		/ INITIALIZE FRAME COUNT
	CLA!IAC			/ SET WORD COUNT TO 1
	DAC	CTRLTBL+3	/ IN 'GET' CONTROL TABLE
	DZM	CURBLK		/ BEGIN SEARCH AT START OF REPLAY AREA
SRCH2	INC	CURBLK		/ CHECK NEXT BLOCK
	JMS	GETBLK
	INC*	FRMCNT		/ UPDATE FRAME COUNT
	LAC	CURBLK
	DAC	SCHBLK		/ KEEP TRACK OF LAST BLOCK SEARCHED
	LAC	FILE1
	SAD	LSTFRAME	/ CHECK FOR LAST BLOCK STORED
	JMP	SRCH3		/ FOUND IT.  DO SOME FINAL CHECKING.
/
	ISZ	BLKSIZE
	JMP	SRCH2
	DZM	CURBLK		/ NO STORED FRAMES.  RESET TO BLOCK 0,
	DZM	SCHBLK
	DZM*	FRMCNT		/ AND ZERO FRAME COUNTER
	JMP*	PULSE
/
SRCH3	ISZ	BLKSIZE		/ LAST BLOCK OF ALLOCATED FILE?
	JMP*	PULSE		/ NO.  HOWEVER, WHEN THE REPLAY FILE OCCUPIES
	LAC	LASTBK		/ THE ENTIRE ALLOCATED DISK SPACE, THE SEARCH
	DAC	SCHBLK		/ WILL GO TO THE END, AND 'CURBLK' AND 'SCHBLK'
	JMP	SRCH4		/ WILL BE TOO LARGE BY 1.  'SCHBLK' MUST BE FIXED
				/ AT 'LASTBK', AND 'CURBLK' RESET TO ZERO.
	.EJECT
NXFRAME	LAC	CURBLK
	DAC	CBLKSV		/ SAVE CURRENT BLOCK NUMBER
	LAC	SCHBLK
	SPA!SNA!TCA
	JMP*	PULSE		/ NOTHING TO REPLAY!
	TAD*	FRMCNT		/ FRMCNT - (HIGHEST BLOCK)
	SPA!CLC
	JMP	NOTBIG
	LAC	SCHBLK		/ SUPPLIED BLOCK NUMBER IS TOO BIG
	SKP
NOTBIG	TAD*	FRMCNT		/ (BLOCK NUMBER) = FRMCNT - 1
	SPA			/ ENSURE POSITIVE BLOCK NUMBER
	CLA			/ DELIVER BLOCK 0 IF -VE FRAME COUNT
	DAC	CURBLK
	JMS	GETBLK		/ INPUT REQUESTED FRAME
	LAC	CBLKSV
	DAC	CURBLK		/ RESTORE PREVIOUS CURRENT BLOCK
	.IFUND	F4
	LAC	(3		/ PREPARE TO DELETE PREVIOUSLY FETCHED FILE
	DAC	FCN
	JMS	CALINT		/ FIRE UP INTERPRETER
	62*OP	1
	43*OP	DSPLAY-T	/ CALL DSPLAY (3,32767,ERR, . . .)
	DARGS-T
	74*OP			/ RETURN TO MACHINE CODE
	CLA!IAC
	DAC	FCN		/ PREPARE TO ADD NEW FILE
	.ENDC
/
	.EJECT
	.IFDEF	F4
	JMS*	DSPLAY
	JMP	NXFRM1
	(3
	(77777
	REPEAT			/ USED AS ERROR RETURN
	.ENDC
NXFRM1	JMS*	CLEAR		/ 'CLEAR' TURNS OFF ALL FILES
	.IFUND	F4
	JMS	CALINT
	62*OP	2
	43*OP	DSPLAY-T	/ CALL DSPLAY (1,32767,ERR,FILE1-1,1,257)
	DARGS-T
	76*OP	1		/ RETURN TO CALLING PROGRAM
	.ENDC
	.IFDEF	F4
	JMS*	DSPLAY
	JMP	XIT1
	(1
	(77777			/ 32767
	REPEAT
	FILE1-1
	(1
	(401
XIT1	JMP*	PULSE
	.ENDC
/
	.EJECT
/  HIGH SPEED CLOCK (VIA 'FSYNC & FWAIT) TIMES REPLAY.
/
/  SEARCH DSPLAY FOR FILES THAT ARE TURNED ON.
/  SEE USER'S MANUAL REGARDING 'DISPLAY FILE MANAGEMENT PHILOSOPHY'
/
DISK	CAL	SPY		/ FIND ABOUT AC SWITCHES
	LAC	ACSW
	RTR
	SNL			/ SAVE IMAGES ONLY IF AC 16 IS A '1'
	JMP	NOSAVE
	LAC	(FILE1-1
	DAC*	(X15
	LAW	-377		/ MAXIMUM SIZE OF FILE WE CAN
	DAC	BLKSIZE		/ STORE IN 1 BLOCK
	LAC*	BEGIN
	DAC	TEMPAD		/ADDRESS OF 1ST DISPLAY FILE
BLOCK	LAC*	TEMPAD		/ 1ST WORD
	DAC	FULL		/ONLY BIT 0 SIGNIFICANT
	RAL			/SHIFT AC 1 TO AC 0
	DAC	LASTFL		/ONLY BIT 0 SIGNIFICANT HERE ALSO
	RAR			/SHIFT BACK TO THE WAY IT WAS
	AND	(77777		/REMOVE POSSIBLE EXTRA BITS
	DAC	SIZE		/SAVE SIZE OF DISPLAY FILE.
	IDX	TEMPAD		/POINT TO 2ND WORD OF 'DSPLAY' FILE
/
/  PROCEED TO GET FILES
/
	LAC	FULL		/HAVE WE AN OCCUPIED BLOCK?
	SMA
	JMP	ENDCHK		/NO.  PERFORM CHECK FOR END OF AREA
	LAC*	TEMPAD		/IS THIS BLOCK TURNED ON?
	SMA
	JMP	ENDCHK		/NO.
/
/  FILE IS PRESENT AND TURNED ON.  MOVE IT TO DISK BUFFER.
/
	LAC	SIZE
	SAD	(5
	JMP	ENDCHK		/ ZERO LENGTH FILE CHECK
	LAC	TEMPAD
	IAC
	DAC*	(X14		/LOAD ADDRESS OF 1ST DISPLAY WORD
	AAC	5		/ POINT TO WORD THAT WOULD
	DAC	TXTCHK		/ BE USED BY 'TEXT'
	TAD	SIZE
	AAC	-5-5		/ SUBTRACT FILE OVERHEAD + TEXT OFFSET
	DAC	END		/ LAST ADRS TO BE TRANS.
	LAC*	TXTCHK
	SAD	(CHRI!10000 52	/ 'TEXT' FILES CAN NOT BE SAVED
	JMP	ENDCHK		/ AT PRESENT.  GO TRY FOR NEXT FILE.
/
	.EJECT
/  LOAD TO FILE1
/
DUMP	LAC*	X14		/MOVE DISPLAY FILE TO DISK BUFFER
	DAC*	X15
	ISZ	BLKSIZE		/ HAVE WE RUN OUT OF ROOM ON THIS BLOCK?
	SKP
	JMP	OVRFLOW		/ YES.  WRAP UP THE BLOCK.
	LAC*	(X14		/ NO.  HAVE WE MOVED ENTIRE FILE YET?
	SAD	END
	JMP	ENDCHK		/YES.
	JMP	DUMP
	.EJECT
/  CHECK FOR END; SET TEMPAD;  CONTINUE
/
ENDCHK	LAC	LASTFL		/IS THIS THE LAST 'DSPLAY' FILE?
	SPA!CLC			/SET AC=-1 FOR LATER
	JMP	FILL		/LAST FILE.  TIDY UP & WRITE TO DISK.
	TAD	TEMPAD
	TAD	SIZE		/ TEMPAD = TEMPAD + SIZE -1
	DAC	TEMPAD		/POINTS TO NEXT FILE
	JMP	BLOCK		/ BACK FOR MORE DATA.
/
FILL	LAC	(DNOP
FILL1	DAC*	X15		/ FILL REST OF BUFFER WITH DISPLAY NO-OP'S
	ISZ	BLKSIZE
	JMP	FILL1
/
OVRFLOW	LAC	(STP		/PUT STOP CODE AT END OF DISPLAY FILE
	DAC*	X15
/
/  PLACE ONTO DISK
/
WRITE	LAC	(FILE1
	DAC	CTRLTBL+2	/ ALWAYS OUTPUT FROM 'FILE1'
	LAC	OUTSIZE		/ WITH WORD COUNT OF 257 UNTIL WRAP-AROUND
	DAC	CTRLTBL+3
	JMS	UNPLAT		/ GENERATE UNIT AND PLATTER NUMBERS
	CAL	PUT		/ THEN WRITE IT OUT
	JMS	WTFOR
	INC*	FRMCNT		/COUNT NUMBER OF FRAMES RECORDED.
LACB	LAC	CURBLK
REMSCH	DAC	SCHBLK		/ REMEMBER LARGEST BLOCK RECORDED.
	SAD	LASTBK		/END OF DISK?
	SKP
	JMP	INCR		/NO.
SRCH4	LAC	(400		/ YES.  NO STATUS BLOCK AFTER WRAP-AROUND
	DAC	OUTSIZE
	LAC	LACB		/ RETAIN MAXIMUM VALUE FOR 'SCHBLK'.
	DAC	REMSCH		/ REPLACE INSTRUCTION WITH HARMLESS ONE.
	CLA!SKP			/ RESTART STORAGE AT BLOCK 0.
INCR	IAC
	DAC	CURBLK
/
/  NOW CHECK AC 17
/
	CAL	SPY
NOSAVE	LAC	ACSW
	RAR
	SNL			/DO WE DO A REPLAY?
	JMP*	PULSE		/NO. EXIT.
	.EJECT
/  REPLAY SECTION
/
REPLAY	LAW	-2		/ MUST HAVE RECORDED AT LEAST 2 FRAMES
	TAD	SCHBLK		/ BEFORE REPLAY IS PERMISSIBLE.
	SPA			/ OTHERWISE, MASS CONFUSION RESULTS!!!
	JMP*	PULSE
/
/  AT THIS POINT WE WANT TO STOP THE DISPLAY CYCLING THROUGH THE
/  MAIN DISPLAY FILE, AND RUN IT ONLY IN THE FILES WE READ IN
/  FROM THE DISK.  IT SO HAPPENS THAT WHEN 'CLOUDY' IS CALLED, THE
/  DISPLAY IS IMMEDIATELY STOPPED, AND THE SUBROUTINE SPECIFIED
/  IN THE ARGUMENT IS ENTERED.  WHEN THE SUBROUTINE RETURNS, THE
/  DISPLAY IS RESTARTED IN THE MAIN DISPLAY SEQUENCE.
/
SET	JMS*	CLOUDY		/ STOP DISPLAY AND INVOKE 'RPLAY'
	JMP	.+2		/ CONTROL RETURNS HERE ONLY AFTER 'RPLAY'
	RPLAY
	.IFDEF	F4
	JMP*	PULSE
	.ENDC
	.IFUND	F4
	JMS	CALINT		/ RE-ENTER INTERPRETER
	76*OP	1		/ EXIT (RETURN)
	.ENDC
/
	.EJECT
/  PREPARE TO START
/
RPLAY	XX
	LAC	CURBLK
	DZM	CURBLK		/ BEGIN REPLAY AT BLOCK 0,
	DAC	CBLKSV		/ BUT REMEMBER LAST RECORDED BLOCK
	LAC	(FILE1
	DAC	GBUFPT		/ BEGIN WITH 'FILE1' BUFFER
	DAC	VTBUFP		/ FOR DISPLAY AS WELL AS INPUT.
IC=REPEAT		/ INNOCUOUS PLACE FOR UNUSED RETURNED ARGUMENT
	.IFUND	F4
	.IFDEF	FSYNC
	JMS	CALINT		/ FIRE UP WATRAN INTERPRETER
	43*OP	FSYNC-T		/ CALL FSYNC (5208,IC)
	ARGS-T
	74*OP			/ RETURN TO ASSEMBLER
	.ENDC
	.ENDC
	.IFDEF	F4
	.IFDEF	FSYNC
	JMS*	FSYNC		/ USE SYSTEM ROUTINE FOR TIME SYNCHRONIZATION
	JMP	.+3
	L5208			/ 41.664 MSEC = 1/24 SEC
	IC
	.ENDC
	.ENDC
	.EJECT
RPL1	JMS	GETBLK		/ FETCH NEXT FRAME
	.IFDEF	FSYNC
	JMS*	FWAIT		/ WAIT FOR CLOCK SYNCHRONIZATION
	.ENDC
	CAL	VTPUT		/ START VT15 IN THE DISPLAY FILE
	LAC	(FILE1
	SAD	GBUFPT
	LAC	(FILE2		/ SWAP BUFFER POINTERS
	DAC	GBUFPT
	DAC	VTBUFP		/ AND UPDATE DISPLAY FILE POINTER
	LAC	CURBLK
	SAD	SCHBLK		/ HAVE ALL FRAMES BEEN SEEN?
	JMP	CHKSW		/ YES.  GO CHECK AC SWITCHES
	INC	CURBLK		/ INCREMENT THE BLOCK NUMBER
	JMP	RPL1		/ AND GO FETCH THE NEXT FRAME.
/
CHKSW	DZM	CURBLK		/ RESET TO BLOCK 0
	CAL	SPY
	LAC	ACSW
	RAR
	SZL
	JMP	RPL1		/ AC17 = 1; CONTINUE REPLAY
/
/  END OF REPLAY.  RESET CURRENT BLOCK INDICATOR, THEN LEAVE.
/
	LAC	CBLKSV
	DAC	CURBLK
	JMP*	RPLAY		/ RETURN TO 'CLOUDY'
/
	.EJECT
/  SUBROUTINES TO FORM UNIT AND PLATTER NUMBERS, AND TO 'GET' A BLOCK FROM DISK.
/
UNPLAT	XX
	LAC	BASEBK		/ GET BASE BLOCK OF DIRECT ACCESS FILE
	TAD	CURBLK		/ ADD CURRENT BLOCK OFFSET
	LMQ
	ECLA!LLSS  10
	XOR	UNIT		/ DON'T FORGET THE PHYSICAL UNIT NUMBER
	DAC	CTRLTBL		/ STORE UNIT AND PLATTER NUMBERS
	LACQ
	DAC	CTRLTBL+1	/ DISK ADDRESS
	JMP*	UNPLAT
/
GETBLK	XX
	JMS	UNPLAT
	CAL	GET		/ FETCH THE BLOCK
	JMS	WTFOR
	JMP*	GETBLK
/
/  SUBROUTINE TO WAIT FOR EVENT VARIABLE 'EVDK' TO BE SET.
/
WTFOR	XX
	CAL	WAITFR
	LAC	EVDK
	SMA
	JMP*	WTFOR		/ NORMAL RETURN WITH EV IN AC
	JMS*	.IOERR		/ TERMINAL ERROR EXIT
/
	.EJECT
/  CPB'S FOR THE I/O
/
GET	13000;	EVDK;	1; CTRLTBL; 0
PUT	13100;	EVDK;	1; CTRLTBL; 0
CTRLTBL	.BLOCK	4;GBUFPT=CTRLTBL+2
VTPUT	3100;	0;	VT; VTCTBL
VTCTBL	7;VTBUFP FILE1
WAITFR	20;	EVDK
SPY	31;	0;	4;ACSW					/(030)
/
/  VARIABLE STORAGE
/
BASEBK;BLKSIZE;CBLKSV;CURBLK;END;EVDK;FULL;LASTBK;LASTFL;MBLKS
REPEAT;SIZE;TEMPAD;TXTCHK;UNIT;XADJ
OUTSIZE	401		/ WORD COUNT FOR 'DKPUT' - CHANGED TO 400 ON WRAP-AROUND
SCHBLK	-1		/ CONTAINS HIGHEST BLOCK NUMBER RECORDED BY THIS TASK.
			/ NEGATIVE VALUE SIGNIFIES NO RECORDED FRAMES THIS RUN,
	.EJECT		/ BUT UNKNOWN NUMBER ON A PREVIOUS RUN.
/  SUBROUTINE TO FIRE UP THE INTERPRETER.  INSTRUCTION FOLLOWING
/  CALLING POINT IS IN INTERPRETER CODE.
/
	.IFUND	F4
CALINT	XX
	LAC	CALLED		/ HAVE WE ALREADY CALLED INTERPRETER?
	SZA!CLC
	JMP	CALLED		/ YES.  DON'T DO IT TWICE
	DAC	CALLED		/ SET 'INTERPRETER CALLED' FLAG
	JMS*	.INTRP
	T
	S-1
S	74*OP			/ RETURN IMMEDIATELY TO MACHINE CODE
CALLED	LAW	-1		/ CLEARED ON ENTRY TO 'PULSE'
	TAD	CALINT		/ LOAD X10 WITH RETURN ADDRESS
	DAC*	(X10
	JMP*	.NEXT		/ PROCEED AS IF NORMAL WATRAN
	.ENDC
/
	.EJECT
/  OTABLE FOR WATRAN VERSION
/
	.IFUND	F4
T	0; 0; 0
	.ASCII	'PULSE'
DFCN
L1	1
L401	401
L32767	77777
DARGS	.
	3*MM+L.FCN
	3*MM+L.32K
	3*MM+L.ERR
	3*MM+L.IVEC
	3*MM+L.1
	3*MM+L.401
	6*MM
L.FCN	-1+DFCN
L.32K	-1+L32767
L.ERR	-1+REPEAT
L.IVEC	-1+FILE1-1
L.1	-1+L1
L.401	-1+L401
/
	.IFDEF	FSYNC
ARGS	.
	3*MM+L.5208
	3*MM+L.IC		/ ARGUMENTS FOR 'CALL FSYNC'
	6*MM
/
L.5208	-1+L5208
L.IC	-1+IC
	.ENDC
	.ENDC
	.IFDEF	FSYNC
	.DEC
L5208	5208			/ NUMBER FOR 41.664 MSEC = 1/24 SEC
	.OCT
	.ENDC
/
	.EJECT
/     THIS SECTION OF ONCE-ONLY CODE RESIDES IN THE I/O BUFFERS.  IT
/  IS USED TO ALLOCATE A DIRECT-ACCESS DATA SET FOR USE IN THE 'REPLAY'
/  SECTION.  THE DATA SET HAS THE NAME 'PULSE RPL' AND WILL HAVE NO MORE
/  THAN 777 BLOCKS (IT MAY HAVE FEWER).  THE FILE WILL NORMALLY BE
/  DELETED AT THE TERMINATION OF THE CURRENT TASK, BUT MAY BE PRESERVED
/  BY SPECIFYING FCN=4 ON THE VERY FIRST CALL TO 'PULSE'.
/     THE MECHANISM FOR DELETING THE FILE IS BY ENABLING, THEN
/  REQUESTING A HIGH PRIORITY TASK (DLERPL) TO BE RUN IN THE 'GRAFIX'
/  PARTITION.  TO PRESERVE THE FILE, 'DLERPL' IS DISABLED BEFORE
/  IT IS REQUESTED.
/
DKINIT	CAL	HINF		/ FIND OUT ABOUT THE DEVICE ON LUN 'DK'
	JMS	WTFOR
	AND	(77		/ KEEP DEVICE CODE
	SAD	(2		/ RF?
	SKP
	SAD	(3		/ OR RP?
	SKP
	SAD	(24		/ OR EVEN RK?
	SKP
	JMP	NOTDK		/ REPLAY DEVICE IS NOT DISK!!
	DAC	GET+4		/ PUT DISK TYPE IN 'GET'
	DAC	PUT+4		/ AND 'PUT' CAL PARAMETER BLOCKS.
	CAL	RENAME		/ FIND OUT IF THERE IS A REPLAY FILE LEFT
	CAL	WAITFR		/ FROM A PREVIOUS RUN.
	LAC	EVDK
	SPA
	JMP	NOPREV		/ NEGATIVE EV.  ASSUME NO PREVIOUS FILE.
	CAL	CLOSE		/ 'RENAME' REQUIRES A 'CLOSE'
	CAL	WAITFR
	CAL	CREATE		/ THIS IS NECESSARY TO FIND OUT
	CAL	WAITFR		/ HOW MANY BLOCKS IN PREVIOUS REPLAY FILE.
	JMP	VAL.EV
/
	.EJECT
NOPREV	DZM	SCHBLK		/ INDICATE NO BLOCKS TO REPLAY.
CREAT.	CAL	CREATE		/ CREATE A DIRECT-ACCESS FILE
	CAL	WAITFR
	LAC	EVDK		/ SEE IF WE GOT ONE OR NOT.
	SAD	LM15
	JMP	CR2BIG
	LAC	CR.TRY		/ CREATION WAS SUCCESSFUL.
	SAD	CR.MAX		/ IF THE TRIAL REQUEST IS EQUAL TO THE MAXIMUM,
	JMP	VAL.EV		/ WE PROBABLY GOT IT ON THE FIRST TRY.
	SAD	CR.MIN		/ WHEN TRY.EQ.MIN, WE ARE AS CLOSE AS POSSIBLE
	JMP	VAL.EV
	DAC	CR.MIN		/ OTHERWISE, ANOTHER ITERATION IS INDICATED.
	CAL	DELETE		/ SET MIN=TRY, DELETE THE FILE JUST CREATED,
	JMS	WTFOR		/ AND TRY AGAIN
	JMP	CR.NXT
/
CR2BIG	LAC	CR.TRY		/ CREATION WAS UNSUCCESSFUL (REQUEST TOO BIG)
	DAC	CR.MAX		/ DECREASE 'MAX' FOR NEXT ITERATION.
	SAD	CR.MIN		/ IF WE HAVE WORKED DOWN TO THE MINIMUM,
	JMP	CR.ERR		/ ANNOUNCE FATAL ERROR (EVDK=-15)
/
CR.NXT	LAC	CR.MIN		/ GENERATE A NEW TRIAL VALUE:
	TAD	CR.MAX
	CLL!RAR			/ TRY = (MAX+MIN)/2
	DAC	CR.TRY
	JMP	CREAT.
/
	.EJECT
VAL.EV	LAC	EVDK
	SMA!TCA
	JMP	CRSIZE		/ WE ARE VALIDATING THE EVENT VARIABLE
	AND	L770
	SAD	L60		/ IS IT A DIRECT-ACCESS ERROR?
	JMP	CRSIZE		/ YES.  PROCEED NORMALLY.
/
CR.ERR	LAC	EVDK
	JMS*	.IOERR		/ ANNOUNCE TERMINAL I/O ERROR
/
CRSIZE	LAW	-1		/ ACCOUNT FOR 1-ORIGIN INDEXING IN SIZE.
	TAD	CR.TRY
	TCA
	DAC	MBLKS		/ NEGATIVE OF NUMBER OF USEABLE BLOCKS
	IAC
	SMA
	JMP	NOROOM		/ WE NEED AT LEAST 3 BLOCKS
	LAC*	FCN
	SAD	L4		/ IF (FCN .EQ. 4) DISABLE 'DLERPL'
	SKP
	INC	DISEN		/ CHANGE 'DISABLE' TO 'ENABLE'
	CAL	DISEN		/ EXECUTE 'DISABLE' OR 'ENABLE'
	CAL	REQDLE		/ REQUEST DELETION OF REPLAY FILE
	LAC	CRTABLE+7
	AND	L7HT
	DAC	UNIT		/ SAVE UNIT NUMBER OF REPLAY DISK
	LAC	CRTABLE+10	/ GET DISK ADDRESS
	LMQ
	LAC	CRTABLE+7	/ GET PLATTER ADDRESS
	AND	L77777		/ STRIP OFF UNIT NUMBER
	LRSS	10		/ CONVERT TO BLOCK NUMBER
	LACQ
	DAC	BASEBK		/ STARTING BLOCK OF REPLAY AREA
	LAW	-2
	TAD	CR.TRY		/ LEAVE A FREE BLOCK FOR 'LAST BLOCK' MARKER
	DAC	LASTBK		/ LAST USEABLE BLOCK OF REPLAY AREA
/
	.EJECT
	LAC*	FCN		/ NOW CHECK TO SEE IF WE SHOULD RETURN A
	SAD	L4		/ 'SIZE OF REPLAY FILE' VALUE TO CALLING PROGRAM
	SKP
	SAD	L5
	SKP
	JMP	PLUG
	LAC	LASTBK		/ SIZE IS RETURNED ONLY FOR FCN=3 OR FCN=4
	IAC
	DAC*	FRMCNT
/
PLUG	LAC	LNOP		/ INSERT PLUG TO DISABLE THE ONCE-ONLY CODE
	DAC	.SETUP
	JMP	.SETUP
/
NOTDK	CAL	WRNODK		/ WRITE 'REPLAY DEVICE IS NOT DISK!!'
	CAL	WAITFR		/ ON MCR TERMINAL
	CAL	L10		/ THEN EXIT
/
NOROOM	LAW	-15
	JMP	CR.ERR		/ ANNOUNCE ERROR 15 (DISK FULL)
/
	.EJECT
CR.MAX	777			/ MAXIMUM PERMISSIBLE VALUE
CR.MIN	  3			/ MINIMUM POSSIBLE FOR REPLAY
LNOP	NOP
XRMASK	070000
LM15	-15
L4	4
L5	5
L10	10
L60	60
L770	770
L77777	077777
L7HT	700000
/
HINF	3600;	EVDK;	DK
RENAME	3700;	EVDK;	DK; .SIXBT 'PULSE@RPL'
CLOSE	3400;	EVDK;	DK; .SIXBT 'PULSE@RPL'
CREATE	1600;	EVDK;	DK;	CRTABLE
CRTABLE	.SIXBT	'PULSE@RPL' ;CR.TRY 777; 4; 5; 6; 7; 10
DELETE	3500;	EVDK;	DK; .SIXBT 'PULSE@RPL'
DISEN	21; 0;	.SIXBT	'DLERPL'	/ CHANGED TO 'ENABLE 22' AS REQUIRED
REQDLE	01; 0;	.SIXBT	'DLERPL' ; 10	/ REQUEST 'DLERPL' AT PRIORITY 10
WRNODK	2700;	EVDK;	MCR; 2; NODK
NODK	NDK-.*400+2; 0
	.ASCII	'REPLAY DEVICE IS NOT DISK!!  TASK ABORTED.'<15> ;NDK=.
/
	.EJECT
	.LOC	DKINIT+1
/
FILE2	.BLOCK	400
FILE1	.BLOCK	400
LSTFRAM	204000			/ THIS IS A STATUS WORD WRITTEN TO DISK
	.END
