	.TITLE	PDATE
/
/  15 FEB 77 (002; PDH) ADD FETCH OF LUN FROM CALLING PROGRAM
/  14 FEB 77 (001; PDH) CONVERT FROM PROGRAM 'SNAP'
/
/  PROGRAM TO PRINT DATE AND TIME ON USER SPECIFIED LUN.  IT IS ASSUMED
/  THAT OUTPUT IS TO A NON FILE-ORIENTED DEVICE, OR TO AN OPEN FILE.
/
/  CALLING SEQUENCE:	CALL PDATE (LUN)
/
/  OUTPUT FORMAT IS AS FOLLOWS:
/
/	(BLANK LINE)		- -
/	<TAB> DATE TIME		- -	15 FEB 77  14:52:31
/	(BLANK LINE)		- -
/
IDX=ISZ		/ INDEX POINTER, SKIP NEVER EXPECTED
/
	.GLOBL	PDATE,.ARG
/
PDATE	XX
	JMS*	.ARG
	JMP	.+2
LUN	XX
	LAC*	LUN		/ GET CALLER SUPPLIES LUN
	DAC	WRITEL+2	/ INSERT INTO WRITE CPB'S
	DAC	WRITEB+2
/
	.EJECT
/  GET DATE AND TIME FROM SYSTEM
/
GDATE	CAL	DATIME
	LAC	DATIME+3	/ DAY
	JMS	TWOC		/ CONVERT TO TWO ASCII CHARACTERS (PACKED)
	DAC	DD
	LAC	DATIME+2	/ MONTH
	AAC	-1
	RCL
	TAD	(MONTHS		/ POINT TO CORRECT MONTH
	DAC	GETP
	LAC*	GETP
	IDX	GETP
	DAC	MONTH		/ MOVE ASCII MONTH TO HEADER BUFFER
	LAC*	GETP
	DAC	MONTH+1
	LAC	DATIME+4	/ YEAR
	JMS	TWOC
	DAC	YY
	LAC	DATIME+5	/ HOUR
	JMS	TWOC
	DAC	HH
	LAC	DATIME+6	/ MINUTE
	JMS	TWOC
	DAC	MM
	LAC	DATIME+7	/ SECOND
	JMS	TWOC
	DAC	SS
/
	CAL	WRITEB		/ BLANK LINE GOES BEFORE THE DATE
	JMS	WAIT
	CAL	WRITEL		/ OUTPUT DATE AND TIME
	JMS	WAIT
	CAL	WRITEB		/ OUTPUT BLANK LINE
	JMS	WAIT
	JMP*	PDATE
/
	.EJECT
/  SUBROUTINE TO CONVERT 2 OCTAL DIGITS TO DECIMAL IN PACKED ASCII.  THE
/  DIGITS ARE IN AC 12-17 ON ENTRY, AND ARE CONVERTED FIRST TO DECIMAL,
/  THEN TO 7-BIT, LEFT JUSTIFIED ASCII IN THE ACCUMULATOR ON EXIT.
/  THERE IS ALSO AN ENTRY TO CONVERT 3 DIGITS TO ASCII.  THE FIRST 
/  TWO DIGITS ARE CONVERTED AS ABOVE, AND THE NUMERICAL VALUE OF THE
/  THIRD DIGIT IS IN 'CODEID' ON EXIT.
/
THREEC	XX
	DAC	CODEID		/ 3 DIGIT ENTRY.  SAVE VALUE
	LAC	THREEC		/ MOVE RETURN ADDRESS
	DAC	TWOC
	LAW	-3
	JMP	TWOC2		/ JUMP INTO TWO CHARACTER ROUTINE
/
TWOC	XX
	DAC	CODEID		/ STORE DIGITS TO BE CONVERTED
	LAW	-2
TWOC2	DAC	OFFSET		/ NUMBER OF DIGITS CALLED FOR
	LAW	-3
	DAC	DCOUNT		/ ALWAYS CONVERT 3 DIGITS
	LAC	(THREE		/ CONVERTED DIGITS
	DAC	GETP
	LAC	(DECDIG		/ POINTERS FOR THE CONVERSION
	DAC	PUTP
CVRT	LAC*	GETP		/ GET NEXT DIVISOR
	DAC	DIVSR
	LAC	CODEID		/ GET NUMBER TO BE CONVERTED
	CLL
	IDIV
DIVSR	XX
	DAC	CODEID		/ SAVE NEW REMAINDER
	LACQ			/ GET DIVIDEND
	DAC*	PUTP		/ PUT IN BUFFER
	IDX	GETP		/ POINT TO NEXT DIVISOR
	IDX	PUTP		/ POINT TO NEXT PLACE IN 'DECDIG'
	ISZ	DCOUNT		/ FINISHED WITH CONVERSION?
	JMP	CVRT		/ NO.  DO ANOTHER DIGIT
OFFSET	XX			/ 'LAW -2' OR 'LAW -3'
	TAD	PUTP
	DAC	PUTP		/ BACK UP POINTER
	LAC*	PUTP		/ GET 1ST CONVERTED VALUE
	IDX	PUTP
	ALSS	7		/ SHIFT FOR NEXT ASCII CHARACTER
	XOR*	PUTP		/ GET 2ND CONVERTED VALUE
	XOR	(014060		/ INCLUDE THE ASCII CONVERSION
	ALS	4		/ LEFT JUSTIFY THE 2 CHARACTERS
	JMP*	TWOC		/ LEAVE WITH ASCII IN AC
/
	.EJECT
/  SUBROUTINE TO WAIT FOR EVENT VARIABLE TO BE SET.  IF EVENT VARIABLE
/  IS SET NEGATIVE, SHOW IT IN A TERMINAL I/O ERROR ON THE MCR TERMINAL.
/
WAIT	XX
	CAL	WAITF
	LAC	EV		/ CHECK FOR GOOD EVENT VARIABLE
	SMA!TCA
	JMP*	WAIT
	DAC	CODEID		/ SAVE COMPLEMENTED EV
	LRSS	3		/ SHIFT OUT LOW ORDER DIGIT
	CLQ!LRS	6		/ TWO DIGITS NOW IN MQ
	LAC	(6		/ THIS CONVERTS TO ASCII
	LLSS	3		/ FIRST CHARACTER NOW IN IMAGE POSITION
	ALSS	4		/ MAKE ROOM FOR SECOND ASCII CONVERSION
	XOR	(6		/ INSERT THE CONVERSION
	LLSS	7		/ LEFT JUSTIFY THE TWO CHARACTERS
	XOR	(6		/ CONVERSION FOR 3RD DIGIT
	DAC	ERRNUM		/ INSERT IN ERROR BUFFER
	LAC	CODEID
	CLQ!LLS	17		/ PLACE 3RD DIGIT
	DAC	ERRNUM+1
	CAL	WRTERR		/ ANNOUNCE ERROR ON MCR TERMINAL
	CAL	WAITF
	CAL	(10		/ AND EXIT.
/
	.EJECT
DATIME	24;	EV;	.BLOCK 6
WAITF	20;	EV
WRTERR	2700;	EV;	 3; 2; IOERR
WRITEL	2700;	EV;	XX; 2; HEADER
WRITEB	2700;	EV;	XX; 2; BLANK
MONTHS	.ASCII	' JAN '
	.ASCII	' FEB '
	.ASCII	' MAR '
	.ASCII	' APR '
	.ASCII	' MAY '
	.ASCII	' JUN '
	.ASCII	' JUL '
	.ASCII	' AUG '
	.ASCII	' SEP '
	.ASCII	' OCT '
	.ASCII	' NOV '
	.ASCII	' DEC '
BLANK	2002; 0; .ASCII ' '<15>
HEADER	10002; 0
	.ASCII	<11>
DD	.BLOCK	2
MONTH	.BLOCK	2
YY	.ASCII	'YY'<0>'  '
HH	.ASCII	'HH'<0>':'
MM	.ASCII	'MM'<0>':'
SS	.ASCII	'SS'<0><15>
IOERR	7002;EV
	.ASCII	'SNAP I/O ERR -'
ERRNUM	.BLOCK	2
	.ASCII	'  LUN 6'<15>
	.EJECT
GETP;PUTP;DCOUNT
DECDIG; 0			/ IMAGE BUFFER FOR OCTAL-DECIMAL CONVERSION
CODEID				/ THIRD CONVERTED DIGIT LEFT HERE
THREE	144;	12;	1	/ TABLE OF CONVERSION VALUES
	.END
