	.TITLE	WITS
/
/  28 FEB 78 (007; PDH)	MODIFY FOR USE WITH MODIFIED TTY HANDLER NOW
/			AVAILABLE IN MULTIACCESS.  THIS EDIT ALSO REMOVES
/			ALL CONDITIONALS FOR XVM/RSX V1A, MEANING THAT
/			FROM THIS EDIT, 'WITS' WILL BE AVAILABLE ONLY
/			AS A TDV FUNCTION TASK WITH MULTIACCESS.
/   8 NOV 77 (006; PDH) IGNORE NULLS AND DELETES; FIX ERROR IN CLOSE
/   4 NOV 77 (005; PDH) DON'T CLOSE UNOPENED FILE
/   4 NOV 77 (004; PDH) TIDY UP LISTING; FIX BUG NEAR 'GET2'
/   4 NOV 77 (003; PDH) ADD FILE RETRIEVAL CAPABILITY
/   3 NOV 77 (002; PDH) TRY TO PLAY SOME GAMES WITH THE SYSTEM
/   2 NOV 77 (001; PDH) ADD 'HELLO' MESSAGE
/   1 NOV 77 - PAUL HENDERSON
/
/  CREATE A PROGRAM WHICH WILL COMMUNICATE WITH THE IBM 360/75, USING
/  THE PDP-15 AS A BUFFERED TERMINAL.  THIS IS BASED, IN PART, ON A
/  PREVIOUS PROGRAM OF THE SAME NAME.
/     THIS PROGRAM INSPECTS THE TTY STATUS WORD TO ENSURE THAT	/(007)
/  THE DEVICE WHICH COMMUNICATES WITH THE OTHER COMPUTER SYSTEM	/(007)
/  IS A FULL DUPLEX TERMINAL WITH LOCAL COPY.  THIS CONDITION	/(007)
/  IS NECESSARY TO PREVENT MASS CONFUSION BY THE CC70.  THE	/(007)
/  FULL DUPLEX STATUS BIT IS SET EXTERNALLY (IDEALLY BY THE	/(007)
/  MCR 'DTC' TASK), SO THIS TASK RUNS IN USER MODE AS A TDV	/(007)
/  FUNCTION TASK						/(007)
/
BUFSIZE=70		/ SIZE OF 'SAVE' ASCII LINE BUFFER	/(003)
WRKSIZE=BUFSIZE-2/2*5	/ SIZE OF IMAGE BUFFER FOR 'SAVE'	/(003)
X10=10								/(003)
TTWD0P=202		/POINTER TO TTY STATUS WORD TABLE	/(002)
/
TTB.PR=020000		/ STATUS WORD 'DEVICE HAS PRINTER'	/(002)
TTB.LC=10		/ FULL DUPLEX TERMINAL HAS LOCAL COPY	/(007)
			/  (DO NOT ECHO KEYBOARD INPUT)		/(007)
/
	.EJECT							/(004)
	.DEC
MCR=3		/ TO ANNOUNCE ERROR MESSAGES
TT=4		/ KEYBOARD TERMINAL (TT4, NORMALLY)		/(007)
BD=23		/ TT3, COMMUNICATES WITH 360/75			/(007)
DK=7		/ NORMALLY PUNCH, BUT COULD BE DISK		/(007)
	.OCT
IDX=ISZ
/
	.GLOBL	.IOERR
	.GLOBL	PACK,UNPACK,FILENM				/(003)
/
WITS	CAL	XFRCMD		/ NECESSARY FOR TDV FUNCTION	/(007)
	CAL	WAITFR		/ NO ERROR CHECKING		/(007)
	CAL	HINFT		/ VALIDATE BOTH 'TT' & 'BD' DEVICES
	JMS	CK4TTY
	CAL	WRCRLF		/ START TTY AT LEFT MARGIN	/(003)
	CAL	HINFB
	JMS	CK4TTY
	LAC	EV						/(002)
	LRSS	6		/ EXTRACT UNIT NUMBER		/(002)
	AND	(77						/(002)
	DAC	UNIT						/(002)
	CAL	ATTACH		/ MAKE SURE WE 'OWN' THE BD	/(003)
	JMS	WTFOR						/(003)
	LAC	(IMAGE
	DAC	IBUFP		/ INITIALIZE BUFFER POINTER
	AAC	2
	DAC	CBUFP
	LAW	-1
	DAC	S.FLAG		/ SET 'SHOW' FLAG FOR 1ST CHARACTER
	DAC	CLFLAG		/ SET 'FILE NOT OPEN' FLAG	/(005)
	LAC	(TTWD0P						/(007)
	JMS	LOOKUP		/ GET POINTER TO STATUS TABLE	/(007)
	TAD	UNIT		/ ADD OFFSET FOR TTY UNIT NO.	/(007)
	JMS	LOOKUP		/ GET STATUS TABLE ENTRY	/(007)
	AND	(TTB.LC		/ VERIFY THAT 'BD' 		/(007)
	SZA							/(007)
	JMP	BDOK		/ HAS LOCAL COPY		/(007)
	CAL	WNO.LC		/ 'BD' DEVICE DOES NOT INDICATE	/(007)
	JMS	WTFOR		/ LOCAL COPY			/(007)
	CAL	(10		/ THIS IS A DISASTER!!		/(007)
/
BDOK	CAL	WHELLO		/ ANNOUNCE OURSELVES		/(007)
	JMS	WTFOR						/(001)
	.EJECT							/(004)
TTLOOP	DZM	TTLINE+2	/ START WITH VIRGIN LINE	/(003)
	CAL	RDTT		/ READ LINE FROM USER
	JMS	WTFOR
	LAW	777760
	AND	TTLINE+2	/ SEE IF WE HAVE A		/(003)
	SAD	DOTDOT		/ LOCAL COMMAND			/(003)
	JMP	COMAND		/ LOOKS LIKE IT!		/(003)
	CAL	WRBD		/ SEND LINE TO 360
	JMS	WTFOR
	CAL	READBD		/ WHEN KEYBOARD INPUT IS FINISHED,
				/ BEGIN EXPECTING INPUT FROM 360.
/
BDLOOP	JMS	RDBD
	SAD	(23
	JMP	DC3		/ 'UNLOCK' THE KEYBOARD
	JMS	SHOW
JSV	JMP	BDLOOP		/ CHANGED TO 'JMS SAVE' FOR	/(003)
JBDL	JMP	BDLOOP		/ DURATION OF '..GET' COMMAND	/(003)
/
DC3	CLA
	JMS	SHOW
	JMS	SHOW		/ MAKE SURE LAST CHARACTER IS DISPLAYED
	JMP	TTLOOP
/
	.EJECT							/(004)
/
/  A LOCAL COMMAND HAS BEEN DISCOVERED.  SORT IT OUT AND TAKE	/(003)
/  APPROPRIATE ACTION.					/(003)
/
COMAND	LAC	TTLINE+2	/ BEGIN THE VALIDATION		/(003)
	SAD	..GET						/(003)
	SKP							/(003)
	JMP	CKGCL						/(003)
	LAC	TTLINE+3					/(003)
	SAD	..GET+1						/(003)
	JMP	GET		/ LOCAL COMMAND IS '..GET'	/(003)
/
CKGCL	LAC	TTLINE+2					/(003)
	SAD	..GCL						/(003)
	SKP							/(003)
	JMP	CKEXIT						/(003)
	LAC	TTLINE+3					/(003)
	SAD	..GCL+1						/(003)
	JMP	GCLOSE		/ LOCAL COMMAND IS '..GCL'	/(003)
/
CKEXIT	LAC	TTLINE+2					/(003)
	SAD	..EXI						/(003)
	SKP							/(003)
	JMP	INVALC						/(003)
	LAC	TTLINE+3					/(003)
	SAD	..EXI+1						/(003)
	JMP	EXIT		/ LOCAL COMMAND IS '..EXI'	/(003)
/
INVALC	CAL	WRINVC		/ '*** INVALID LOCAL COMMAND'	/(003)
	JMS	WTFOR						/(003)
	JMP	TTLOOP		/ RETURN TO MAIN LOOP		/(003)
/
	.EJECT							/(004)
/  '..EXI(T)' LOCAL COMMAND EXITS THE TASK			/(003)
/
EXIT	ISZ	CLFLAG		/ SKIPS IF FILE NOT OPEN	/(005)
	CAL	CLOSDK		/ CLOSE POSSIBLY OPEN DISK FILE	/(003)
	JMS	WTFOR						/(003)
	CAL	(10		/ THEN EXIT			/(003)
/
/  '..GET' LOCAL COMMAND PUTS ALL CHARACTERS RECEIVED FROM	/(003)
/  IBM 360 INTO SPECIFIED DISK FILE (OR DIRECTLY ON PUNCH)	/(003)
/
GET	LAC	(TTLINE+2					/(003)
	DAC	G.UNP+1		/ POINTERS FOR UNPACK		/(003)
	LAC	(WORK
	DAC	G.UNP+2
	DAC*	(X10
	DAC	SVPNT		/ POINTER TO IMAGE WORK BUFFER	/(003)
G.UNP	JMS*	UNPACK						/(003)
	0; 0							/(003)
	SMA							/(003)
	JMP	G.UNP						/(003)
/
GET1	LAC*	X10		/ FLUSH COMMAND TO FIRST SPACE	/(003)
	SAD	(40						/(003)
	JMP	GET2						/(003)
	SAD	(15		/ MAY NOT HAVE SPECIFIED NAME	/(003)
	SKP
	SAD	(175						/(003)
	SKP							/(003)
	JMP	GET1						/(003)
	LAC	DFNAME						/(003)
	DAC	ENTER+3						/(003)
	DZM	DFNAME+4	/ ESTABLISH DEFAULT NAME	/(003)
	JMP	GETSRC						/(003)
/
	.EJECT							/(004)
GET2	LAC*	X10		/ NOW FLUSH THE SPACES		/(003)
	SAD	(40						/(003)
	JMP	GET2						/(003)
	LAC*	(X10		/ GET ADDRESS OF FILE NAME	/(003)
	DAC	G.PCK+1		/ PUT IT WHERE 'PACK' EXPECTS	/(003)
	LAC	(TTLINE		/ PACK FILE NAME BACK UP IN	/(004)
	DAC	G.PCK+2		/ THE LINE BUFFER		/(004)
G.PCK	JMS*	PACK						/(004)
	0; 0							/(004)
	SMA							/(004)
	JMP	G.PCK						/(004)
	JMS*	FILENM						/(003)
	TTLINE;	ENTER+3						/(004)
	LAC	ENTER+5						/(003)
	SNA							/(003)
GETSRC	LAC	SRC		/ DEFAULT EXTENSION IS 'SRC'	/(003)
	DAC	ENTER+5						/(003)
	CAL	ENTER		/ OPEN OUTPUT FILE		/(003)
	LAC	(WRBUF		/ INITIALIZE BUFFER POINTER	/(003)
	DAC	WRBUFP						/(003)
	LAC	(JMS SAVE	/ ENABLE 'SAVE'			/(003)
	DAC	JSV						/(003)
	JMS	WTFOR		/ VALIDATE EV			/(003)
	DZM	CLFLAG		/ INDICATE FILE NOW OPEN	/(005)
	JMP	TTLOOP						/(003)
/
	.EJECT							/(004)
/  SUBROUTINE TO SAVE CHARACTERS FROM IBM 360 IN FILE (OR ON PP)/(003)
/
SAVE	XX							/(003)
	DAC*	SVPNT		/ STORE CHARACTER IN WORK BUFFER/(003)
	IDX	SVPNT						/(003)
	SAD	(15		/ END OF LINE?			/(003)
	SKP							/(003)
	JMP*	SAVE		/ NOT YET.  RETURN		/(003)
/
	LAC	(WORK						/(003)
	DAC	S.PCK+1		/ INITIALIZE POINTERS FOR 'PACK'/(003)
	DAC	SVPNT		/ AND FOR NEXT BUFFER		/(003)
	LAC	WRBUFP		/ GET LINE BUFFER POINTER	/(003)
	DAC	S.WRITE+4	/ SET UP CPB			/(003)
	AAC	2		/ STEP PAST HEADERS		/(003)
	DAC	S.PCK+2						/(003)
S.PCK	JMS*	PACK		/ PACK UP THE LINE		/(003)
	0; 0							/(003)
	SMA							/(003)
	JMP	S.PCK						/(003)
	LAC	WRBUFP						/(003)
	TCA							/(003)
	TAD	S.PCK+2		/ CALCULATE LINE LENGTH		/(003)
	ALSS	10		/ CONVERT TO WORD PAIRS		/(003)
	AAC	2		/ INDICATE ASCII MODE		/(003)
	DAC*	WRBUFP		/ INSERT IN HEADER LOCATION	/(003)
	CAL	S.WRITE		/ OUTPUT THE LINE		/(003)
	LAC	WRBUFP						/(003)
	AAC	BUFSIZE		/ MOVE TO NEXT BUFFER		/(003)
	SAD	(EWRBF		/ END OF BUFFER BLOCK?		/(003)
	LAC	(WRBUF		/ YES.  RESET TO BEGINNING AGAIN/(003)
	DAC	WRBUFP						/(003)
	JMP*	SAVE						/(003)
/
	.EJECT							/(004)
/  '..GCL(OSE)' CLOSES THE 'SAVE' FILE				/(003)
/
GCLOSE	ISZ	CLFLAG		/ DON'T CLOSE UNOPENED FILE	/(005)
	.TITLE	.SIXPK
/
/  23 JUN 78 - PAUL HENDERSON
/
/  THIS ROUTINE CONSTRUCTS A .SIXBT FILE NAME AND EXTENSION AS
/  CHARACTERS ARE SUPPLIED, ONE CHARACTER PER CALL.  THE CONVENTION
/  USED IS THAT CHARACTERS ARE PACKED, THREE PER WORD, IN THE
/  FILE NAME AND EXTENSION.  ALL NON-SPACE CHARACTERS AFTER A
/  SPACE GO IN THE EXTENSION, EVEN IF THE FILE NAME IS NOT
/  COMPLETELY FILLED, OR IF THERE HAVE BEEN MORE THAN SIX
/  CHARACTERS.  ALL CHARACTERS AFTER THE NINTH (IF NO SPACE)
/  OR AFTER THE THIRD EXTENSION CHARACTER ARE IGNORED, AS ARE
/  ALL CHARACTERS INCLUDING AND AFTER A LINE TERMINATOR.
/     THE ROUTINE MUST BE INITIALIZED BY A CALL TO 'SIX.IN',
/  WHICH ALSO ZEROS THE 3-WORD FILE NAME BUFFER.
/
/  CALLING SEQUENCES:
/
/ 1) TO INITIALIZE -
/
/	LAC	(ADDRESS OF 3-WORD FILE NAME BUFFER
/	JMS*	SIX.IN
/	(RETURN)
/
/ 2) TO PACK CHARACTERS -
/
/	LAC	CHARACTER
/	JMS*	.SIXPK
/	(RETURN)
/
X10=10
SET=ISZ			/ SET A FLAG NON-ZERO
	.GLOBL	SIX.IN
/
SIX.IN	XX
	DAC	KPNT		/ KEEP ORIGINAL POINTER
	DAC	WPNT		/ WORKING POINTER GETS ALTERED
	DAC*	(X10
	DZM*	WPNT
	DZM*	X10		/ ZERO THE 3-WORD BLOCK
	DZM*	X10
	LAC	(FIRSTC
	DAC	SWING		/ SET UP THE BRANCH ADDRESSES
	LAC	(FNAME2
	DAC	SELECT
	DZM	TERMIN		/ CLEAR 'LINE TERMINATOR FOUND'
	JMP*	SIX.IN
/
KPNT;WPNT;TERMIN 1
	.EJECT
	.GLOBL	.SIXPK
/
.SIXPK	XX
	AND	(177		/ ENSURE WE HAVE ONLY 7 BITS
	SAD	(15		/ IF (CARRIAGE RETURN
	SKP
	SAD	(175		/ 	OR ALT MODE)
	JMP	CRALT		/    IGNORE ALL CHARACTERS UNTIL
				/    AFTER NEXT 'SIX.IN';
	SAD	(40		/ ELSEIF (SPACE)
	JMP	EXT		/    CHARACTERS GO IN EXTENSION
	AAC	-140
	SMA			/ IF (LOWER CASE)
	AAC	-40		/    CONVERT TO UPPER CASE
	AAC	140
	AND	(77		/ CHOP TO 6 BITS
	JMP*	SWING		/ THEN PROCESS CHARACTERS IN TURN
/\
SWING	OVRFLOW			/ IGNORE CHARACTERS UNLESS SET UP
	JMP*	.SIXPK
/
CRALT	SET	TERMIN		/ SET 'LINE TERMINATOR FOUND' FLAG
	JMP	OVRFLOW		/ THEN IGNORE CHARACTERS
/
NXT	JMS	SWING		/ ESTABLISH CORRECT BRANCH ADDRESS
/
FIRSTC	ALSS	14
	DAC*	WPNT		/ STORE FIRST CHARACTER
	JMS	SWING
/
	ALSS	6
	XOR*	WPNT		/ INCLUDE WITH 1ST CHAR
	DAC*	WPNT		/ AND STORE FIRST 2 CHARACTERS
	JMS	SWING
/
	XOR*	WPNT
	DAC*	WPNT		/ WORD NOW FULL.
	JMP*	SELECT		/ SELECT NEXT STAGE IN PROCESSING
/
	.EJECT
SELECT	OVRFLOW			/ IGNORE IF NOT SET UP
	JMP	NXT		/ SET UP WORD PACKER FOR
				/ ANOTHER 3 CHARACTERS
FNAME2	LAC	KPNT
	IAC			/ POINT TO SECOND WORD OF BLOCK
	DAC	WPNT
	JMS	SELECT
/
EXT	LAC	TERMIN		/ MUST CHECK BECAUSE A SPACE AFTER
	SZA			/ A LINE TERMINATOR COULD WREAK HAVOC
	JMP	OVRFLOW
	LAC	KPNT
	AAC	2
	DAC	WPNT		/ SELECT 3RD WORD (EXTENSION)
	JMS	SELECT
/
OVRFLOW	JMS	SWING		/ RETURN WITHOUT PROCESSING
	JMP	OVRFLOW		/ OVERFLOW CHARACTERS
	.END
