	.TITLE	TSW
/
/  28 MAR 77 - PAUL HENDERSON
/
	.DEC
PP=7
CD=12		/ BATCH DEVICE
TT=13
	.OCT
IDX=ISZ
/
	.GLOBL	PACK,UNPACK
/
TSW	CAL	HINFPP		/ FIND OUT ABOUT OUTPUT DEVICE
	JMS	WTFOR
	EVPP
	AND	(77
	SAD	(10		/ MAKE SURE IT IS A PUNCH
	SKP
	JMP	NOPUN
	CAL	READCD		/ READ FIRST LINE OF INPUT
/
WAITCD	JMS	WTFOR		/ WAIT FOR LINE TO BE READ
	EVCD
	LAC	LINE
	AND	(7
	SAD	(2
	SKP
	JMP	DONE		/ END OF FILE IF NOT ASCII MODE
	LAC	(LINE+2
	DAC	UNPCK+1
	LAC	(IMAGE
	DAC	UNPCK+2		/ POINTERS FOR PACK & UNPACK
	DAC	PCK+1
UNPCK	JMS*	UNPACK
	0; 0
	SMA
	JMP	UNPCK
	CAL	READCD		/ READ NEXT LINE AS SOON AS BUFFER IS FREE
	.DEC
	LAW	-70
	PAL
	CLX
/
TLOOP	LAC	IMAGE+71,X	/ SEARCH BACKWARDS FOR NON-SPACE,
	.OCT			/ BEGINNING IN COLUMN 71 (DELETE SEQUENCE #'S)
	SAD	(40		/ SPACE?
	SKP
	SKP			/ NOT A SPACE.  FINISH OFF LINE
	AXS	-1
	SKP
	JMP	TLOOP		/ SPACE; MORE TO CHECK.
/
	LAW	15
	.DEC
	DAC	IMAGE+72,X	/ APPEND CARRIAGE RETURN IN PROPER PLACE
	.OCT
	LAC	(OLINE+2
	DAC	PCK+2
	JMS	WTFOR		/ WAIT FOR PUNCH
	EVPP
PCK	JMS*	PACK
	0; 0
	SMA
	JMP	PCK
	LAC	(OLINE
	TCA
	TAD	PCK+2
	ALSS	10
	XOR	(2		/ GENERATE PROPER HEADER WORD
	DAC	OLINE
	CAL	WRPP		/ PUNCH OUT MODIFIED LINE
	JMP	WAITCD
/
/  PROGRAM COMES HERE WHEN END OF INPUT FILE IS DETECTED.
/
DONE	JMS	WTFOR		/ WAIT FOR LAST PUNCH BUFFER
	EVPP
	CAL	CLOSE		/ CLOSE PUNCH TO GIVE SOME BLANK LEADER
	JMS	WTFOR
	EVPP
	CAL	(10		/ EXIT WHEN JOB HAS FINISHED
/
	.EJECT
/  SUBROUTINE TO WAIT FOR SPECIFIED EVENT VARIABLE, AND ISSUE ERROR
/  MESSAGE WHEN APPROPRIATE.
/
WTFOR	XX
	LAC*	WTFOR
	IDX	WTFOR		/ STEP PAST ARGUMENT
	DAC	WAITFR+1	/ INSERT ADDRESS INTO CPB
	CAL	WAITFR
	LAC*	WAITFR+1	/ GET EVENT VARIABLE
	SMA
	JMP*	WTFOR		/ GOOD EV.  RETURN.
/
IOERR	TCA			/ MAKE BAD EV POSITIVE
	CLQ!LRSS 11		/ SHIFT BAD EV TO UPPER HALF OF MQ
	LAC	(6		/ OCTAL TO ASCII CONVERSION
	LLSS	3		/ SHIFT IN FIRST DIGIT
	ALSS	4
	XOR	(6		/ CONVERSION FOR SECOND DIGIT
	LLSS	3
	ALSS	4
	XOR	(6		/ CONVERSION FOR 3RD DIGIT
	DAC	ERRB		/ PUT IN LINE BUFFER
	LACQ
	XOR	CR		/ APPEND CARRIAGE RETURN
	DAC	ERRB+1
	CAL	WRERR
EXIT	CAL	WTFRTT
	CAL	(10		/ EXIT AFTER ERROR ANNOUNCEMENT
/
/  COME HERE WHEN OUTPUT DEVICE IS NOT PUNCH TO ISSUE TERMINAL ERROR.
/
NOPUN	CAL	WRNOPP
	JMP	EXIT
/
	.EJECT
/  CPB'S, VARIABLES, AND LINE BUFFERS
/
HINFPP	3600;	EVPP;	PP
READCD	2600;	EVCD;	CD; 2; LINE; 120
WRPP	2700;	EVPP;	PP; 2; OLINE
WAITFR	20;	0
WTFRTT	20;	EVTT
CLOSE	3400;	EVPP;	PP
WRERR	2700;	EVTT;	TT; 2; ERRL
WRNOPP	2700;	EVTT;	TT; 2; NOPP
EVCD;EVPP 1
LINE	.BLOCK	42
	.ASCII	<0><0><0><0><15> ;CR=.-1
IMAGE	.BLOCK	125
OLINE	.BLOCK	40
/
NOPP	NP-.*400+2; 0; .ASCII 'OUTPUT DEVICE NOT PAPER PUNCH'<15> ;NP=.
ERRL	EL-.*400+2;EVTT; .ASCII '*** TSW I/O ERROR '
ERRB	.BLOCK	2;EL=.
	.END	TSW
