	.title	k11con	terminal emu
	.ident	/8.0.01/
	.psect
	.enabl	gbl


;
;	WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;
;	This is HISTORICAL only
;
;
;
;
;	Brian Nelson  29-Dec-83  16:00:09  initial version
;	Brian Nelson  23-Jan-84  16:19:49  RSX mods
;	Brian Nelson  16-Apr-84  08:01:57  Merge Bob Denny's changes for RSX
;	John Pieper   840607		Fix  TC.DLU  for autocall modems (RSX)
;	John Pieper   840614		Attach lun.ti (even though slaved!)
;	Brian nelson  840616		Don't change TC.DLU, does not work for
;					my system at any rate.
;	10-Feb-86  11:46:29 BDN	Removed RSTS and RT code, mods from S. Heflin



	.include	/IN:K11MAC.MAC/
	.iif ndf	,k11inc	,.error	; missing INCLUDE for K11MAC.MAC


	.psect	$code

	.sbttl	connect code for kermit
	.enabl	gbl
	.enabl	lsb



poscon::
doconn::tstb	ttname			; insure that a device name is set
	bne	1$			; ok
	message	<You must first define an output port:>,cr	;jfp 840607
	message	<Use the SET LINE command for this.>,cr
	return

	
1$:	message	<Connecting to line >	; Print the line and speed out
	print	#ttname			; the link name
	calls	ttspee	,<#ttname>	; get the speed now
	tst	r0			; not if we can't get it
	ble	5$			; yes, do not print 0 or -1 baud
	message	< at >			; and the speed
	sub	#10	,sp		; try to format the response a little
	mov	sp	,r1		; allocate a buffer and point to it
	deccvt	r0,r1,#4		; convert to decimal, 4 wide
	print	r1	,#4		; print it
	add	#10	,sp		; pop the buffer
	message	< baud>,cr		; and finish off the message
5$:	message	< Type CTRL >
	clr	-(sp)			; allocate a text buffer
	bisb	conesc	,(sp)		; get it
	add	#100	,(sp)		; convert it back to printable
	mov	sp	,r0		; point to it now
	print	r0	,#1		; at last
	tst	(sp)+			; pop the buffer
	message	< and then C to return to command level>,cr

	call	dorsx
	br	100$

100$:	return

	.dsabl	lsb

	global	<conesc	,getsys	,ttcons	,ttname	,lun.co	,lun.ti>




	.sbttl	RSX Connect code - Rev. Notes

;
; This is the terminal emulator for Kermit-11 on native RSX.  It was
; rewritten because the original version developed on the RSTS emulator
; was unsuitable for native RSX.  It wouldn't work reliably at baud
; rates over 1200 on a moderately busy system.
;
;
; Bob Denny	10-Mar-84
;
;	NOTE:	vt125's are a problem as they don't send xon when you type one
;
; John Pieper	840607		fix for connecting to an autocall modem
;	Note:  Autocall modems are a pain under RSX.
;	If the  TTnn:  is set  /remote ,
;	  the Terminal Handler will NOT let you talk to it until it senses
;	  DSR .  This logic is based on the assumption that a remote line
;	  will be used only for incoming calls.
;	If the  TTnn:  is set  /noremote ,
;	  then you can talk to it, but the Terminal Handler will drop  DTR .
;	  Thus, unless your modem has a local  DTR  override, it thinks
;	  that you are not connected to it.
;	Solution:  RSX-11m V4.1  allows  TC.DLU = 2
;	  which holds  DTR  but allows you to talk without having  DSR .
;	Note -- this mechanism is NOT available from  MCR  level.
;	  Further,  TC.DLU  must be reset to 1 when KERMIT is done or else
;	  the system will not recognize the  TT  as really being remote --
;	  things such as  .IFF <LOCAL>  in an indirect command file will fail.
;
;  John Pieper	840614	Slave Terminal Fix!
;	Due to a change in the Terminal Handler, a slaved terminal must also
;	  be attached or else unsolicited input will NOT be kept in the
;	  typeahead buffer.  (See Software Dispatch Dec. 1983).
;	  Terminal Emulation sure works better with this fix !!

	.sbttl	RSX Connect code - Definitions
;

	ef.rem	= 14.			; Remote event flag
	em.rem	= 020000		; Remote event flag mask
	ef.loc	= 15.			; Local event flag
	em.loc	= 040000		; Local event flag mask

;
; LOCAL IMPURE DATA
;
	.psect	$idata	rw,d,lcl,rel,con
;
; Characteristics buffers
;
;	Note: TC.SLV must be second in the list   BDN 18-Apr-84  10:47:18
;
savti: .byte TC.FDX,0,TC.SLV,0,TC.BIN,0	; Original setting for remote   /45/
savdlu:	.byte TC.DLU,0,TC.ABD,0		; original TC.DLU & TC.ABD	/45/
savspd:	.byte TC.RSP,0,TC.XSP,0		; original speed		/45/
	.byte TC.PTH,0			; orig. pasthru mode		/45/
stilen  = . - savti			; - save length		        /45/

savco:	.byte TC.FDX,0			; Original setting for local /45/
	.byte TC.SLV,0,TC.BIN,0		; Slave and binary mode		/45/
	.byte TC.8BC,0,TC.NEC,0		; Eight bit code and NOECHO	/45/
	.byte TC.PTH,0			; orig. pasthru mode		/45/
scolen  = . - savco			; - restore length	        /45/

fdxchr:.byte TC.FDX,1			; Change to FDX if required     /45/
	.byte TC.SLV,1			; Slave 			/45/
	.byte TC.8BC,1,TC.NEC,1		; Eight bit code and NOECHO	/45/
	.byte TC.BIN,0			; No binary (not for pro/350)   /46/
	.byte TC.PTH,1			; pasthru mode			/45/
ftisiz  = .-fdxchr			; - fdx set length for remote   /45/
ftilen:	.word	ftisiz			; /45/ Fix for PRO/350 (no tc.pth)

rtab:	.byte	TC.TBF,0		; #chars in remote typeahead
ltab:	.byte	TC.TBF,0		; #chars in local typeahead

	.mcall	qio$	qiow$
;
; Oft' used QIO DPB's
;
remread:
	qio$	<io.rne!tf.ral>,lun.ti,ef.rem,,remios,,<rembf,1>
locread:
	qio$	<io.rne!tf.ral>,lun.co,ef.loc,,locios,,<locbf,1>
remwrite:
	qiow$	io.wal,lun.ti,ef.loc,,,,<locbf,1>
locwrite:
	qiow$	io.wal,lun.co,ef.rem,,,,<rembf>
locech:
	qiow$	io.wal,lun.co,ef.rem,,,,<locbf,1>
remtest:
	qiow$	sf.gmc,lun.ti,ef.rem,,remios,,<rtab,2>
remtab:
	qiow$	<io.rne!tf.ral>,lun.ti,ef.rem,,remios,,<rembf+1>

;
; Other stuff
;
efbuf:	.blkw	4				; Event flags buffer
rembf:	.blkb	256.				; Remote data buffer
locbf:	.blkb	4.				; Local data buffer
eseen:	.word	0				; 1 = escape seen
locios:	.word	0,0
remios:	.word	0,0

	.psect	$code



;	.sbttl	RSX Connect Code -- Setup


	.mcall	qio$	qiow$	qiow$s	dir$	wtlo$s
	.mcall	alun$s	dscp$s	encp$s	exit$s	rdaf$s	srex$s

	.sbttl	Connect code for RSX kermit 
;
; 	D O C O N N  -  Connect for native RSX
;
; Assumes that the remote device has been attached via the
; SET LINE command and its "asslun()" routine.

	.enabl	lsb



dorsx:	clr	eseen			; must do this for next connect cmd
	call	getprv			; get privs for connect mode
	calls	ttpars	,<#ttname>	; Get remote unit number
	srex$s	#rsxabo			; abort perhaps
	alun$s	#lun.ti,r1,r0		; Assign it
	alun$s	#lun.co,#"TI,#0		; Assign our local terminal
	tst	proflg
	bne	4$			; yes, don't try to attach xk0:
	qiow$s	#io.att,#lun.ti,#ef.rem	; and now Attach it. (jfp 840614)
4$:
	;
	; Save local and remote's /{NO}FULLDUPLEX settings, and
	; set them to /FULLDUPLEX.  Then DISABLE CHECKPOINTING
	; so asynchronous buffered I/O is disabled and true full
	; duplex communication can take place.
	; BDN 18-Apr-84  10:41:51  Also force slave mode
	;
	; save current characteristics					  /45/
	qiow$s	#sf.gmc,#lun.ti,#ef.rem,,,,<#savti,#stilen>;		  /45/
	qiow$s	#sf.gmc,#lun.co,#ef.loc,,,,<#savco,#scolen> ;		  /45/
	;
	; now set characteristics for connect mode			  /45/
	tst	proflg						;	  /46/
	beq	6$						;	  /46/
	mov	#ftisiz-4,ftilen				;	  /46/
6$:	qiow$s	#sf.smc,#lun.ti,#ef.rem,,#remios,,<#fdxchr,ftilen> ;	  /45/
	qiow$s	#sf.smc,#lun.co,#ef.loc,,#remios,,<#fdxchr,ftilen> ;	  /45/

	; If  lun.ti  is currently /noremote (hard wire connection), leave it.
	; Notify user to make sure correct  TT number.

	tst	proflg
	beq	9$
	qiow$s	#IO.DEL,#LUN.CO
	qiow$s	#IO.ATA,#LUN.CO,,,,,<,#0,#conast>
	jmp	10$
9$:	tstb	savdlu+1			; currently /remote ?
	bne	10$				;  Yes			 /45/
	message	<Note:  This is NOT a Remote line.>,cr
10$:	dscp$s					; **DISABLE CHECKPOINTING**



	.sbttl	RSX Connect code - Remote Input
	;
	; Prime incoming and outgoing streams
	;
	dir$	#remread
	dir$	#locread

	;
	; Main loop - Handle incoming and outgoing streams
	; until escape character is detected on outgoing (local KB)
	;
20$:	wtlo$s	0,#<em.loc!em.rem>		; Wait for a character on either
	rdaf$s	#efbuf				; Read the event flags

	movb	remios	,r5			; get the status of the read
	call	iocheck				; /46/ Move this up please
	bcc	21$				; /46/ It's ok
	jmp	100$				; /46/ It's not, we will die
	;
	; Handle character(s) on incoming stream
	;
21$:	bit	#em.rem,efbuf+0			; Anything coming in?
	beq	40$				; (no)

	dir$	#remtest			; More in typeahead?
	clr	r0				; m+ may have a lot ready to get
	bisb	rtab+1,r0			; r0 = # in typeahead
	beq	30$				; (no)
	tst	proflg				; /44/ Pro/350 ?
	beq	25$				; /44/ No
	cmp	r0	,#40			; /44/ Yes, drop size of read?
	blos	25$				; /44/ No
	mov	#40	,r0			; /44/ Yes
25$:	mov	r0,remtab+q.iopl+2		; Set # to read to drain
	dir$	#remtab				; Read 'em in

30$:	inc	r0				; r0 = total # chars to show
	clrb	rembf(r0)			; /39/ asciz
	tst	con8bit				; should we pass 8 bits?
	bne	32$				; yes
	mov	r0	,-(sp)			; no, clear out the high bit
	mov	#rembf	,r1			; for the entire buffer
31$:	bicb	#200	,(r1)+			; simple to do
	sob	r0	,31$			; next please
	mov	(sp)+	,r0			; restore the byte count now

32$:	mov	r0,locwrite+q.iopl+2		; Write out this many
	mov	locwrite+q.iopl+0,r2		; now dump junk to logging file
;-/41/	call	mapid				; /39/ pro and identify esc seq
;-/41/	bcs	35$				; /39/ yes, mapid responded
	dir$	#locwrite			; /39/ normal writes
35$:	movb	(r2)+	,r1			; a character at a time
	call	dumplo				; simple to do
	sob	r0	,35$			; next please
	dir$	#remread			; Re-issue read


	.sbttl	RSX Connect code - Local Input



	; Handle characters on outgoing (Local input) stream
	;  do this without fast-drain (yet)


40$:	mov	#cvtbuf	,cvtadr		; /39/ for converting pro/350 codes
	clrb	cvtbuf			; /39/ nothing is there for now
	clrb	cvtbuf+1		; /39/ ... nothing is there for now
	bit	#em.loc,efbuf+0		; Anything typed locally?
	beq	90$			; (no, loop back)

	clr	r1			; /39/ pass 8bit ctls for pro/350
	bisb	locbf	,r1		; r1 = just typed character
	call	proesc			; /39/ is this a pro/350 ESC or BS?
	bcs	45$			; /39/ no
	movb	@cvtadr	,locbf		; /39/ and setup send for first char
	movb	@cvtadr	,r1		; /39/ ditto
	beq	80$			; /39/ nothing to do
	inc	cvtadr			; /39/ point to the next character
45$:	bic	#^C177	,r1		; drop bit 7 if mark set (BDN)
	cmpb	r1	,conesc		; Console escape?
	bne	50$			; (no)
	tst	eseen			; Already seen one escape?
	bne	60$			; (yes, send this one)
	inc	eseen			; Yes, note it for now
	br	70$			; And go read again

50$:	tst	eseen			; Character following conesc?
	beq	60$			; (no, send it)
	call	concmd			; Yup, process it
	clr	eseen			; clear the flag
	tst	r0			; Exit CONNECT mode?
	bgt	100$			; (yes, clean up etc.)
	blt	70$			; no, but it was a command

60$:	clr	eseen			; clear the flag
	setpar	locbf	,locbf		; set correctr outgoing parity
	dir$	#remwrite		; Transmit character to remote
	tst	duplex			; ibm type things today?
	beq	70$			; no
	dir$	#locech			; need half duplex duplex ?
70$:	movb	@cvtadr	,locbf		; /39/ anymore conversion chars to
	beq	80$			; /39/ to transfer over?
	inc	cvtadr			; /39/ no, get the next one please
	br	60$			; /39/ next please
80$:	dir$	#locread		; Re-issue local read
	mov	#cvtbuf	,cvtadr		; /39/ reset conversion address
	clrb	@cvtadr			; /39/ insure .asciz
90$:	jmp	20$			; Loop back




	.sbttl	RSX Connect code - Clean Up and Exit

;
; Exit CONNECT mode
;
100$:	call	rsxrst			; restore terminal settings
	encp$s				;**ENABLE CHECKP**
	call	setcc
	call	drpprv			; drop privs
	return

	

rsxabo:	call	rsxrst			; called via requested exit
	srex$s				; disable further exits
	exit$s				; bye


rsxrst:	srex$s					; /45/ Don't keep reentering
	qiow$s	#io.kil,#lun.ti,#ef.rem		; Kill incoming I/O
	qiow$s	#io.kil,#lun.co,#ef.loc		; Kill incoming I/O
						; Restore line attributes   /45/
	qiow$s	#sf.smc,#lun.ti,#ef.rem,,,,<#savti,#stilen>	; remote    /45/
	qiow$s	#sf.smc,#lun.co,#ef.loc,,,,<#savco,#scolen>	; local     /45/
	qiow$s	#io.det,#lun.ti,#ef.rem		; De-Attach remote line
	return



	.sbttl 	map pro/350 codes to vt100 codes
	.dsabl	lsb

;	Following code added edit 2.39 /39/
;
;
;	 The following code, to  (1)  intercept  'DECID'  and  return  a
;	VT100   term   type  instead  of  P/OS's  mess  that  few  execs
;	recognize, and (2) to map some of the upper  row  LK201  Pro/350
;	function  keys  into useable characters were made at the request
;	of   Bernie   Eiben   of   DEC   LDP   (eiben@dec-marlboro.arpa,
;	eiben%lsmvax.dec@decwrl.arpa).  Currently,  the  mapping  is  as
;	follows (as of 18-NOV-1985 14:08)
;
;	F5  (break)    --> send a 'real' break ala IO.BRK for XKdriver
;	F6  (interupt) --> send \03  (control C)
;	F10 (exit)     --> send \032 (control Z)
;	F11 (ESC)      --> send \033 (esc)
;	F12 (BS)       --> send \010 (backspace)
;	
;	Since these settings may intfere with some editor functions keys
;	they can be disabled via the SET TER VT200 command.  The mapping
;	of F11 is notable to TOPS20 users for command completion.  In my
;	opinion, the mods were well worth it, though mapping F10 to \032
;	does present  some difficulties.  A future  version of this code
;	would most likely access a global data structure to map settable
;	codes (with defaults) to specified character sequences.  Ie,  we
;	may end up rewritting PRO/COMM functionality for Kermit-11/POS.


	.save
	.psect	mapdata	,rw,d,lcl,rel,con

;	 In the list  specified  in  MAPSEQ,  the  translation  of  P/OS
;	escape  sequences  from  the upper row function keys is normally
;	an ascii character string. The exceptions are (1) if  the  first
;	character  is  a  \0377 then the next character is assumed to be
;	the argument of a connect mode 'escape'  command,  such  as  ^\B
;	for  sending  a  break,  or perhaps a possible mapping of F8 (or
;	F7) (\033[19\0176  and  \033[18\0176)  to  a  ^\C  command.  The
;	mapping  or  a  sequence  to  a NULL tells the mainline emulator
;	code to do nothing (a NOP).  INSEQ is  simply the P/OS generated
;	ecsape sequences.


mapseq:	.word	10$,20$,30$,40$,50$,60$,70$,80$,90$
	.word	100$,110$,120$
	.word	0
10$:	.byte	10,0			; /39/ return for F10
20$:	.byte	33,0			; /39/ return for F11
30$:	.byte	3,0			; /39/ return for F6
40$:	.byte	'Z&37,0			; /39/ return for F10
50$:	.byte	377,'b,0		; /39/ fake ^\b break cmd
60$:	.asciz	<33>/[?1;0c/		; /39/ vt101 response
70$:	.asciz	<33>/[?1;0c/		; /39/ vt101 response
80$:	.asciz	<33>/[?1;0c/		; /39/ vt101 response
90$:	.asciz	<33>/[?1;0c/		; /39/ vt101 response
100$:	.asciz	<33>/[?1;0c/		; /39/ vt101 response
110$:	.asciz	<33>/[?1;0c/		; /39/ vt101 response
120$:	.asciz	<33>/[?1;0c/		; /39/ vt101 response
	.even
inseq:	.word	10$,20$,30$,40$,50$,60$,70$,80$,90$
	.word	100$,110$,120$
	.word	0
10$:	.byte	'2,'4,176,0		; /39/ generated code for BS  (10)
20$:	.byte	'2,'3,176,0		; /39/ generated code for ESC (33)
30$:	.byte	'1,'7,176,0		; /39/ generated code for INT (3)
40$:	.byte	'2,'1,176,0		; /39/ exit key
50$:	.byte	'1,'5,176,0		; /39/ break
60$:	.asciz	/?21;0;0;/		; /39/ part of response to DECID
70$:	.asciz	/?21;1;0;/		; /39/ part of response to DECID
80$:	.asciz	/?21;2;0;/		; /39/ part of response to DECID
90$:	.asciz	/?21;0;0;8;0c/		; /39/ baseline p/os 2.0 system
100$:	.asciz	/?21;1;0;8;0c/		; /39/ baseline p/os 2.0 system
110$:	.asciz	/?21;2;0;8;0c/		; /39/ baseline p/os 2.0 system
120$:	.asciz	/?21;3;0;8;0c/		; /39/ baseline p/os 2.0 system
	.even
inid:	.word	10$,40$			; /39/ host strings to return ID
	.word	0			; /39/ DECID is 'not recommended'
10$:	.byte	33,'Z&137,0		; /39/ but intil 52's are gone...
40$:	.byte	33,'Z&137,15,0		; /39/ just in case
	.even
outid:	.asciz	<33>/[?1;0c/		; /39/ vt101 response
	.even
iosb:	.word	0,0			; /39/ a QIOW$S i/o status block
smallb:	.word	0			; /39/ a QIOW$S buffer
cvtbuf:	.blkb	30			; /39/ copy translated codes to
cvtadr:	.word	cvtbuf			; /39/ a pointer to it
	.even
	.restore

	

	.sbttl	DECID and PRO esc seq conversion code, continued...



	.mcall	mrkt$s	,cmkt$s	,astx$s	,wtse$s

mapid:	save	<r0,r1,r2,r3>		; /39/ save register please
	tst	proflg			; /39/ really on a pro/350?
	beq	100$			; /39/ no
	cmpb	vttype	,#VT100		; /39/ iif we think we are a vt100
	bne	100$			; /39/ no
	cmpb	@r2	,#33		; /39/ ESC ?
	bne	100$			; /39/ no
5$:	strlen	r2			; /39/ is there enough to look for?
	dec	r0			; /39/ well ?
	bne	20$			; /39/ yes, go ahead with checks
	mrkt$s	#20,#12,#1,#200$	; /39/ time the read to be very short
	qiow$s	#IO.RAL!TF.RNE,#LUN.TI,,,#iosb,,<#smallb,#1>
	cmkt$s	#20,#200$		; /39/ kill the timed read
	cmpb	iosb	,#IS.SUC	; /39/ successfull read?
	bne	100$			; /39/ no, exit on error
	inc	locwrite+q.iopl+2	; /39/ fix i/o count up
	movb	smallb	,1(r2)		; /39/ yes, append the character now
	clrb	2(r2)			; /39/ insure asciz
20$:	clr	r3			; /39/ yes	
30$:	tst	inid(r3)		; /39/ done looking ?
	beq	100$			; /39/ yes
	strcmp	r2	,inid(r3)	; /39/ check
	tst	r0			; /39/ found it?
	bne	40$			; /39/ no
	strlen	#outid			; /39/ yes
	qiow$s	#IO.WAL,#LUN.TI,,,,,<#outid,r0>
	br	90$			; /39/ exit
40$:	tst	(r3)+			; /39/ not found, check again
	br	30$			; /39/ next
90$:	sec				; /39/ say we sent a response
	br	110$			; /39/ exit
100$:	clc				; /39/ say we never sent response
110$:	unsave	<r3,r2,r1,r0>		; /39/ exit
	return				; /39/ bye


200$:	qiow$s	#IO.KIL,#LUN.TI		; /39/ abort the qio if timeout
	astx$s				; /39/ exit marktime ast



proesc:	save	<r1,r2,r3,r4>		; /39/ save a register please
	cmpb	vttype	,#VT100		; /39/ not is we really want pro
	bne	90$			; /39/ exit
	mov	#cvtbuf	,r4		; /39/ get address of conversion buf
	clrb	@r4			; /39/ assume failure
	cmpb	r1	,#233		; /39/ escape character typed 8bit?
	beq	10$			; /39/ yes
	cmpb	r1	,#33		; /39/ escape w/o bit 7 set
	bne	90$			; /39/ no, exit with C set
10$:	mrkt$s	#20,#2,#1		; /39/ insure we wait long enough
	wtse$s	#20			; /39/ to get all the data input
	qiow$s	#SF.GMC,#LUN.CO,,,,,<#ltab,#2> ;/ 39/  yes, get typeahead count
	movb	ltab+1	,r2		; /39/ check for typeahead count
	beq	90$			; /39/ nothing to do
	qiow$s	#IO.RAL!TF.RNE,#LUN.CO,,,,,<r4,r2>
	clrb	cvtbuf(r2)		; /39/ insure .asciz
	mov	r4	,r3		; /39/ get address of data read
	cmpb	@r3	,#'[		; /39/ esc [ or CSI ?
	bne	15$			; /39/ must be CSI
	inc	r3			; /39/ must be ESC [
15$:	clr	r2			; /39/ look for a matching esc seq
20$:	tst	inseq(r2)		; /39/ all done
	beq	90$			; /39/ exit with C set
	strcmp	r3	,inseq(r2)	; /39/ did we get a pro/350 esc seq?
	tst	r0			; /39/ ...
	bne	30$			; /39/ no
	mov	mapseq(r2),r3		; /39/ yes, get the translation
	cmpb	@r3	,#377		; /39/ fake emulator command?
	bne	25$			; /39/ no
	inc	eseen			; /39/ say we have a ctrl\
	movb	1(r3)	,(r4)+		; /39/ yes, return 1 char code
	clrb	(r4)+			; /39/ insure .asciz
	br	100$			; /39/ exit success
25$:	strcpy	r4	,r3		; /39/ yes, copy the mapped string
	br	100$			; /39/ and exit
30$:	add	#2	,r2		; /39/ not done, next please
	br	20$			; /39/

90$:	sec				; /39/ failure
	br	110$			; /39/ exit
100$:	clc				; /39/ success
110$:	unsave	<r4,r3,r2,r1>		; /39/ pop regs and exit
	return


conast:	qiow$s	#IO.WAL,#LUN.TI,,,,,<#200$,#1>
	tst	(sp)+
	astx$s

200$:	.byte	3,0



	.sbttl	check for allowable i/ o errors for RSX/ M+ and P/ OS



iocheck:mov	r0	,-(sp)		; insure this is saved
	tstb	r5			; sucessesful read qio ?
	bpl	180$			; yes
	scan	r5	,#200$		; allowable error code ?
	tst	r0			; well
	bne	180$			; yes, let it through
	neg	r5			; make > 0 for direrr macro
	direrr	r5			; simple
	sec				; failure, exit to command level
	br	190$			; bye
180$:	clc				; success, stay in connect code
190$:	mov	(sp)+	,r0		; restore old r0 please
	return

200$:	.byte	IE.BCC	,IE.DAO	,IE.IES	,IE.NOD	,IE.PES	,IE.VER	,IE.ABO ,0
	.even


	global	<conesc	,ttcons	,ttname	,lun.co	,lun.ti>

	.dsabl	lsb




	.sbttl	errchk	check for allowable errors on the link



errchk:	mov	r0	,-(sp)		; save the error code
	cmpb	r0	,#nodata	; check error codes out please
	beq	210$			; that is what we wanted (no data)
	tst	r0			; any other kind of error ?
	beq	210$			; no
	calls	syserr	,<r0,#errtxt>	; yes, get the error text please
	strlen	#errtxt			; ok
	add	#errtxt	,r0		; get the length, point to the end
	movb	#cr	,(r0)+		; and stuff a carriage return and
	movb	#lf	,(r0)+		; a line feed in
	clrb	@r0			; insure .asciz please
	strlen	#errtxt			; the length once again
	calls	binwri	,<#errtxt,r0,#lun.co> ; try to print error on TI
	tst	r0			; did that also fail ?
	beq	210$			; no
	mov	@sp	,r0		; yes
	direrr	r0			; yes, print on default TI: lun
210$:	mov	(sp)+	,r0		; pop saved r0 and exit
	return				; bye

	global	<errtxt	,lun.co	,nodata>




	.sbttl	concmd	terminal emulation escape commands

concmd::save	<r1>
	bicb	#^C177	,r1
	scan	r1,#200$		; look for a match here
	tst	r0			; if no match, return 0
	beq	100$			; ok
	asl	r0			; word offsets
	jsr	pc	,@210$(r0)	; dispatch to the correct routine
	tst	r0			; if not set then set to -1
	bne	100$			; already set
	dec	r0			; set to -1
100$:	unsave	<r1>			; pop r1 and exit
	return


200$:	.byte	'C&137	,'c!40		; drop connection ctrl \ C
	.byte	'I&137	,'i!40		; init the line
	.byte	'Q&137	,'q!40		; quit logging but leave file open
	.byte	'R&137	,'r!40		; resume logging if file is open
	.byte	'X&137	,'X!40		; control Q and then thats all
	.byte	'B&137	,'b!40
	.byte	'?	,177		; help, rub for send break
	.byte	'H&137	,'h!40
	.byte	0
	.even

210$:	.word	con.$			; unknown escape command
	.word	con.c	,con.c		; drop connection
	.word	con.i	,con.i		; get modems attention
	.word	con.q	,con.q		; turn console logging off
	.word	con.r	,con.r		; turn it back on please
	.word	con.x	,con.x		; send XON
	.word	con.br	,con.br		; break
	.word	con.hl	,con.br		; print out commands
	.word	con.hl	,con.hl		; help



con.$:	calls	binwri	,<#200$,#1,#lun.co>	; beep at user
	clr	r0
	return

200$:	.byte	'G&37			; [BEL]
	.even


con.c:	mov	#1	,r0		; set flag to exit connect code
	return				; simple


con.i:	calls	ttydtr	,<#ttname>	; try to force DTR up on the line
	clr	r0
	return


con.q:	bic	#log$co	,trace		; turn off console logging
	clr	r0
	return


con.r:	bit	#log$op	,trace		; if the file is open do it
	beq	100$			; no
	bis	#log$co	,trace		; yes, enable this
100$:	clr	r0
	return


con.x:	calls	binwri	,<#200$,#1,#lun.ti>; insure a control Q goes down
	calls	ttxon	,<#ttname>
	clr	r0
	return

200$:	.byte	'Q&37
	.even

con.br:	qiow$s	#IO.KIL,#LUN.TI			; abort the read qio	   /45/
	calls	senbrk	,<#ttname,#lun.ti>	;
	dir$	#remread			; re-prime the read	   /45/
	clr	r0
	return




con.hl::strlen	#200$
	calls	binwri	,<#200$,r0,#lun.co>
	clr	r0
	return

200$:	.ascii	/B	Try to send a  break to the  remote/<cr><lf>
	.ascii	/C	Connect back to the local Kermit-11/<cr><lf>
	.ascii	/I	Drop  and raise DTR (for RSTS only)/<cr><lf>
	.ascii	/Q	Quit console logging.   See SET LOG/<cr><lf>
	.ascii	/R	Resume console logging. See SET LOG/<cr><lf>
	.ascii	/X	Send XON and cancel any active XONs/<cr><lf>
	.asciz	/RUBOUT	Try to fake a break to the remote/<cr><lf>
	.ascii	/?	Print this message/<cr><lf>
	.byte	0
	.even




	.sbttl	dump i/o to a log file ?


dumplo:	bit	#log$co	,trace		; is this enabled ?
	beq	100$			; no
	bit	#log$op	,trace		; is it open
	beq	100$			; no
	save	<r0,r1>			; yes, save temps please
	mov	r1	,r0		; call simple version
	mov	#lun.lo	,r1		; unit number
	call	putcr0			; thats it folks
	unsave	<r1,r0>
100$:	return



sxon:	tst	conflow
	beq	100$
	calls	binwri	,<#xon,#1,#lun.ti>
100$:	return

sxoff:	tst	conflow
	beq	100$
	calls	binwri	,<#xoff,#1,#lun.ti>
100$:	return


	.save
	.psect	$pdata
xon:	.byte	'Q&37
xoff:	.byte	'S&37
	.even
	.restore



	global	<lun.lo	,putcr0	,trace	,conflow>



	.end
