	.TITLE	WITS
/
/   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 MAKES CHANGES TO THE TTY STATUS WORD FOR	/(002)
/  THE TTY WHICH COMMUNICATES WITH THE OTHER COMPUTER SYSTEM.	/(002)
/  THIS IS TO INHIBIT THE ECHOING OF CHARACTERS SENT BY THE	/(002)
/  OTHER SYSTEM, AS THIS MAY CONFUSE IT.			/(002)
/
/  DEFAULT ASSEMBLY PRODUCES A PROGRAM FOR MULTIACCESS.		/(002)
/  TO ASSEMBLE FOR XVM/RSX V1A, THE SYMBOL			/(002)
/
V1A=0	/ MUST BE DEFINED.					/(002)
/
/  FINALLY, THIS IS AN EXEC MODE TASK, SINCE IT MODIFIES THE	/(002)
/  TELETYPE HANDLER.						/(002)
/
.INH=705522							/(002)
.ENB=705521							/(002)
BUFSIZE=70		/ SIZE OF 'SAVE' ASCIIL 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)
/
	.IFDEF	V1A						/(002)
TTB.PR=200000		/ STATUS WORD 'DEVICE HAS PRINTER'	/(002)
	.ENDC							/(002)
	.IFUND	V1A	/ MULTIACCESS CASE			/(002)
TTB.PR=020000							/(002)
	.ENDC							/(002)
/
	.EJECT							/(004)
	.DEC
MCR=3		/ TO ANNOUNCE ERROR MESSAGES
TT=35		/ KEYBOARD TERMINAL (TT4, NORMALLY)
BD=33		/ TT3, COMMUNICATES WITH 360/75
DK=37		/ NORMALLY PUNCH, BUT COULD BE DISK		/(006)
	.OCT
IDX=ISZ
/
	.GLOBL	.IOERR
	.GLOBL	PACK,UNPACK,FILENM				/(003)
/
WITS	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
	DAC	CLFLAG		/ SET 'FILE NOT OPEN' FLAG	/(005)
	CAL	WHELLO		/ ANNOUNCE OURSELVES		/(001)
	JMS	WTFOR						/(001)
	LAC*	(TTWD0P		/ GET POINTER TO STATUS TABLE	/(002)
	TAD	UNIT		/ ADJUST FOR CURRENT UNIT	/(002)
	DAC	TTSTAT		/ SAVE AS POINTER FOR THIS RUN	/(002)
/
	.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)
	JMS	ENABLE		/ ENABLE PRINTER ON 'BD'	/(003)
	CAL	WRBD		/ SEND LINE TO 360
	JMS	WTFOR
	JMS	DISABLE		/ DISABLE PRINTER ON 'BD'	/(003)
	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	JMS	ENABLE		/ ENABLE TTY TO IBM 360		/(003)
	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)
	CAL	CLOSDK		/ CLOSE THE DISK FILE		/(003)
	LAW	-1		/ RESET 'FILE NOT OPEN' FLAG	/(006)
	DAC	CLFLAG					/(006)
	LAC	JBDL		/ TURN OFF THE 'SAVE' SECTION	/(003)
	DAC	JSV						/(005)
	JMS	WTFOR		/ WAIT FOR 'CLOSE'		/(003)
	JMP	TTLOOP						/(003)
/
CK4TTY	XX
	JMS	WTFOR
	AND	(77		/ SELECT DEVICE CODE
	SAD	(1		/ DEVICE MUST BE TTY
	JMP*	CK4TTY
	CAL	WRNOTT		/ OTHERWISE COMPLAIN
	CAL	WAITFR
	CAL	(10		/ AND QUIT
/
/  SUBROUTINE TO ENABLE THE PRINTER ON THE TELETYPE ASSOCIATED	/(003)
/  WITH THE IBM 360.						/(003)
/
ENABLE	XX							/(003)
	.INH			/ MUST NOT BE INTERRUPTED HERE	/(002)
	LAC*	TTSTAT		/ GET STATUS WORD		/(002)
	AND	(TTB.PR\777777	/ CLEAR BIT, IF SET		/(002)
	XOR	(TTB.PR		/ THEN SET BIT SO WE CAN SEND	/(002)
	DAC*	TTSTAT						/(002)
	.ENB							/(002)
	JMP*	ENABLE						/(003)
/
/  SUBROUTINE TO DISABLE THE TELETYPE PRINTER SO THAT THE	/(003)
/  IBM 360 DOES NOT GET CONFUSED BY THE ECHOING CHARACTERS.	/(003)
/
DISABLE	XX							/(003)
	.INH							/(002)
	LAC*	TTSTAT		/ NOW CLEAR BIT FOR RECEIVING	/(002)
	AND	(TTB.PR\777777					/(002)
	DAC*	TTSTAT						/(002)
	.ENB							/(002)
	JMP*	DISABLE						/(003)
/
	.EJECT							/(004)
SHOW	XX
	DAC	CHAR		/ SAVE CHARACTER		/(003)
	ISZ	S.FLAG		/ 1ST OR 2ND CHARACTER?
	JMP	SECOND
	DAC*	CBUFP		/ FIRST CHARACTER.  STORE IN BUFFER
	IDX	CBUFP
	JMP*	SHOW		/ LEAVE WITH CHARACTER STILL IN AC
/
SECOND	DAC*	CBUFP
	LAC	(2003
	DAC*	IBUFP		/ PUT HEADER IN LINE BUFFER
	LAC	IBUFP
	DAC	WRIMG+4		/ PUT ADDRESS IN CPB
	AAC	4
	SAD	(EBUF		/ END OF IMAGE BUFFERS?
	LAC	(IMAGE		/ YES.  RESTART AT BEGINNING AGAIN.
	DAC	IBUFP
	AAC	2
	DAC	CBUFP
	CAL	WRIMG		/ THEN SHOW THE TWO CHARACTERS
	LAW	-1
	DAC	S.FLAG		/ RESET BRANCHING FLAG.
	LAC	CHAR		/ RETRIEVE CHARACTER FOR EXIT	/(003)
	JMP*	SHOW
/
RDBD	XX
RDAGN	LAC	EV						/(006)
	SPA
	JMS*	.IOERR		/ VALIDATE EVENT VARIABLE
	SZA
	JMP	OK
	CAL	MARK1T		/ EV NOT SET.  DELAY 1 TICK
	CAL	WT4MK
	JMP	RDBD+1		/ CHECK AGAIN
/
OK	LAC	BDLINE+2
	AND	(177		/ IN CASE WE GET 8-BIT CHARACTER/(006)
	DAC	CHAR		/ SAVE CHARACTER JUST RECEIVED
	SAD	(23
	SKP
	CAL	READBD		/ IF NOT 'DC3', READ ANOTHER CHARACTER
	LAC	CHAR		/ RETRIEVE CHARACTER LOST DURING 'CAL'
	SAD	(177		/ DELETE?			/(006)
	JMP	RDAGN						/(006)
	SNA							/(006)
	JMP	RDAGN		/ IGNORE DELETES AND NULLS	/(006)
	JMP*	RDBD		/ LEAVE WITH CHARACTER IN AC
/
	.EJECT							/(004)
WTFOR	XX
	LAC	EV		/ PERFORM QUICK CHECK
	SNA
	CAL	WAITFR		/ WAIT ONLY WHEN NECESSARY
	LAC	EV
	SMA							/(003)
	JMP*	WTFOR						/(003)
	SAD	(-6		/ IGNORE UNIMPLEMENTED FUNCTIONS /(005)
	JMP*	WTFOR						/(005)
	JMS	ENABLE		/ ENABLE 'BD' BEFORE DEPARTURE	/(003)
	LAC	EV		/ RETRIEVE EVENT VARIABLE	/(004)
	JMS*	.IOERR		/ COMPLAIN ON BAD EVENT VARIABLE
/
HINFT	3600;	EV;	TT
HINFB	3600;	EV;	BD
RDTT	2600;	EV;	TT; 2; TTLINE; 42
WRBD	2700;	EV;	BD; 2; TTLINE
READBD	2600;	EV;	BD; 3; BDLINE; 3
WRARO	2700;	EVPP;	PP;  2; ARROW	/ CHANGE TO MODE 2	/(015)
WRATSN	2700;	0;	PP;  2; ATSIGN
CLOSPP	3400;	EVPP;	PP
ATTLP	2400;	EVLP;	LP
WRILLC	2700;	0;	TTO; 2; ILLCHR
WRBL	2700;	0;	TTO; 2; BLINE
WRBAD	2700;	EVTTO;	TTO; 3; IMAGE-1
WROLINE	2700;	EVPP;	PP;  2; OLINE
WRLIST	2700;	EVLP;	LP;  2; OLINE
WRLPFF	2700;	EVLP;	LP;  2; FF
WRXTRA	2700;	0;	PP;  2; EXTRA
	.END	ROMSIM
