	.TITLE	DCSIM
/
/  16 JUN 77 (004; PDH) CHANGE ORDER IN 'FETCH' TO 'DIRD; DCJOG'
/			CHANGE START-UP PROCEDURE
/  16 JUN 77 (003; PDH) CHANGE TO 'TIME' INTERVALS
/  15 JUN 77 (002; PDH) CHANGE TO 2 SECOND INTERVALS
/  15 JUN 77 - PAUL HENDERSON
/
/  PROGRAM TO SIMULATE THE ACTION OF AN EXTERNAL DEVICE CONNECTED TO THE
/  UOW DATA CHANNEL DEVICE.  THE FORM OF THE SIMULATION WILL BE DEPENDENT
/  ON THE TIME OF DAY.  ON ODD SECONDS, THE DEVICE HANDLER WRITES TO THE
/  DEVICE, AND THE DEVICE SIMULATOR STORES DATA, WHICH WILL BE RETURNED
/  ON THE NEXT EVEN SECOND.
/  ON EVEN SECONDS, THE DEVICE HANDLER READS THE DATA SUPPLIED BY THE SIMULATOR.
/
/  PROGRAM DOES THE FOLLOWING:
/
/	1. DO FOREVER
/	2.   MARK TIME FOR 1 SECOND
/	3.   ISSUE 'DATE' TO FIND OUT WHICH SECOND
/	4.   CASE 1: ODD SECOND - RECEIVE AND STORE DATA
/	5.   CASE 2: EVEN SECOND - RETURN STORED DATA
/	6. ENDO
/
DIRD=702712	/ DIAGNOSTIC READ (DOES IT REALLY WORK?)
DIWT=702704	/ DIAGNOSTIC WRITE
DCJOG=702504	/ SIMULATE EXTERNAL DEVICE
/
TIME=10		/ TIME INTERVAL IS 8 SECONDS
/
DCSIM	CAL	MARK
	CAL	WAITFR
	CAL	DATE
	LAC	SECOND
	AND	(TIME*2-1
	SAD	(TIME
	JMP	DCSIM		/ NEVER BEGIN ON A 'TIME' INTERVAL
/
DCS2	CAL	MARK1T		/ WAIT FOR 1 CLOCK TICK
	CAL	WAITFR
	CAL	DATE		/ THEN SEE IF WE ARE AT THE
	LAC	SECOND		/ BEGINNING OF AN INTERVAL
	AND	(TIME*2-1
	SAD	(TIME
	JMP	DCM		/ BEGIN WHEN TIME IS RIPE
	JMP	DCS2
/
DCLOOP	CAL	WAITFR
DCM	CAL	MARK
	CAL	DATE
	LAC	SECOND
	AND	(TIME
	SNA
	JMP	RETURN
/
/  ON ODD SECONDS, THIS SIMULATOR RECEIVES DATA FROM THE SYSTEM
/  AND STORES IT IN THE INTERNAL BUFFER
/
FETCH	LAC	(200		/ 128 WORDS IN A BLOCK
	PAL
	CLX
F.LOOP	DCJOG			/ KICK SYSTEM FOR NEXT DATA
	JMS	DELAY		/ ALLOW HARDWARE TO MOVE DATA BEFORE WE
	DIRD			/ READ DATA CHANNEL REGISTER AND
	DAC	BUF,X		/ STORE IT.
	AXS	1
	JMP	F.LOOP
	SNAP	101,0,BUF,SECOND
	JMP	DCLOOP
/
/  ON EVEN SECONDS, THIS SIMULATOR PICKS UP DATA FROM THE INTERNAL BUFFER
/  AND RETURNS IT TO THE SYSTEM.
/
RETURN	LAC	(200
	PAL
	CLX
R.LOOP	JMS	DELAY		/ ALLOW SYSTEM TO SETTLE AND/OR MOVE DATA
	LAC	BUF,X		/ GET STORED DATA
	DIWT			/ LOAD DATA CHANNEL REGISTER
	DCJOG			/ THEN KICK THE SYSTEM
	AXS	1
	JMP	R.LOOP
	JMP	DCLOOP
/
/  SUBROUTINE TO DELAY SO THAT THE DATA CHANNEL IS DRIVEN FASTER THAN THE
/  HARDWARE CAN RESPOND.  IT IS ANTICIPATED THAT THE DELAY WILL BE SUCH
/  THAT THERE WILL BE ABOUT 100 USEC BETWEEN EACH 'DCJOG'.
/
DELAY	XX
	LAW	-34		/ 28*3 + 5 + 13 = 102 (>100)
	DAC	COUNT
	ISZ	COUNT
	JMP	.-1
	JMP*	DELAY
/
COUNT;EV
BUF	.BLOCK	200
/
MARK	13;	EV; TIME; 2	/ 'TIME' SECONDS
MARK1T	13;	EV; 1; 1	/ 1 TICK
WAITFR	20;	EV
DATE	24;	0;	.BLOCK 5
SECOND
	.END	DCSIM
