.TITLE EXECCL
.IDENT /V1.2/
.NLIST	BEX

;--------------------------------------------------------------
; EXECCL  VERSION 1.2  14-Jul-87
;
;
;	Barry N. Shaklan, M.D.
;	3336 East Equestrian Trail
;	Phoenix, Arizona 85044
;	70265,1140
;
; ____________________________________________________________________
; |    EXECCL is soley derived from and dependent on the program flow |
; |    logic and coding of EXEC.MAC Versions 7.7 and 8.0 written by:  |	
; |	  Chuck Sadoian                                               |
; |	  821 Newton Drive                                            |
; |	  Dinuba, Calif 93618                                         |
; |	  209-591-2631 (work)                                         |
; |	  209-591-6849 (home)                                         |
; +-------------------------------------------------------------------+     
; This program is based upon the program TSTE, submitted
; to DECUS by T.L. Star and L.T. Nieh, 31-Oct-78
;
;
;		EXECCL FEATURES:
;			* CL Handler supported for TSX+
;			* 2400 Baud Rate Supported for both the
;				MO handler in RT-11 or TSX+
;				and the CL Handler under TSX+
;			* User selectable Default Baud Rate
;			* User Configuration area allows selection of
;				of handlers, login codes, and other parameters
;			* Supports Hayes compatible modems or DEC DF224
;			* Auto dial and logon for Compuserve on Compuserve 
;				node,Telenet, or Tymnet
;			* Auto dial and logon for Knowledge Index (Dialog), 
;				the SOURCE, and DEC order line
;			* Executive protocol Filter (SIFLG) which allows
;				use of the SI and SO characters when the
;				protocol mode is not wanted.  Allows graphic
;				dialogue with the DEC order line and also 
;				prevents terminal from going into the 
;				graphic mode when using Compuserve protocols.
;
; CORRECTION HISTORY
; --------------------
;  VERSION 1.2 14-JUL-87  BNS
;	- Improved Receive File Full Procedures
;	- Add CTRL-Q transmit capability evens when SET TT Page is in effect
;	- Corrected Minor text errors
;	- Updated EXECCL. TXT to correspond to changes
;
;  VERSION 1.1  28-JUNE-87   BNS
;	- In PHONE: module, send a CTRLB to DEC Modem after abort to
;		reset modem for next dial
;	- In PHONE module - Change redial testing from ONLINE variable
;		to a .SPFUN that actually checks for carrier.  
;	- Selection of CLUNIT now correctly selects and attaches the proper
;		CL unit.
;	- .FETCH Removed from code specific to TSX+ 
; ---------------------------------------------------------------
;  Assembly Instruction:
;
;	Please see file EXECCL.TXT for full assembly and operating
;	instructions.
;
;=================================================================
;  USER CONFIGURATION AREA
;=================================================================
;
;  Under TSX+ do you wish to use the MO handler or the CL Handler?
;	The MO handler will be assumed under RT-11. Future
;	version will support XL under RT-11.  
;
TSXHAN	= 1		;0=MO handler, 1=CL handler
;
;  Under TSX+, what line is your modem attached to?  (The SHOW TERMINAL
;  Command will give you this information.)  Put the value below.
;
MODTER	= 3	;This is the line number that the modem is at.
;
;  Under TSX+ you can TSGEN up to 16 CL units and either identify them
;  specifically to a device or have extra CL units available (CLXTRA). Here
;  we need to know which Extra CL unit you want to attach to the modem line.
;  If you set up 3 Cl units then they will be called CL0, CL1, CL2. Select
;  the CL unit number (0,1,2,etc) you would like to connect to the modem
;  line. 
;
CLUNIT	= 0		;Use Octal Number 0 thru 7 or 10 thru 17
;  
;  What character do you wish to use as your command character?  In most cases
;  the LF key will suffice but for some terminals (i.e. VT240,etc) this key
;  is not present.
;
CMDKEY	= 140		;Use the octal equivalent of the key you wish to use.
;
;  What BAUD RATE do you want the program to utilize at startup?
;
NEWSPD	= 3		;0=300, 1=600, 2=1200, 3=2400
;
;  What Type of Modem do you have?
;	(Use the modem in abbreviated RESPONSE mode )
;
MODTYP	= 0			; 1= Hays Compatible, 0= DEC 224 Compatible 
;
;   Put the Clear Screen code for your terminal here:
;
CLS:	.ASCIZ	<33><133><110><33><133><112>
;==================================================================
;
; AUTO LOGON INFORMATION
;
;   Fill in all phone numbers, ID numbers and passwords as indicated below:
;	Use the Dialing Codes along with the phone numbers
;	(i.e. ATDT2569493 etc. for Hayes Modem)
;
;-------------------------------------------------------------------------
;Login Sequence to COMPUSERVE via COMPUSERVE NODE (2400 BAUD)
;
MSGLG1:	.ASCIZ	/ 1 - COMPUSERVE via COMPUSERVE Node/  ;Net you are calling
;
CISLOG:	.ASCIZ	/T2569493!/		;PHONE NUMBER + required dialing codes
	.ASCIZ	/xxxxx,xxx/		;ID number
	.ASCIZ	/xxxxxxxxxx/		;Password 
	.EVEN
;
;--------------------------------------------------------------------------
;Login Sequence to KNOWLEDGE INDEX via TELENET (2400)
;
MSGLG2:	.ASCIZ	/ 2 - KNOWLEDGE INDEX  via TELENET/	;Net you are calling
;
KILOG:	.ASCIZ	/T2566955!/		;Phone number + required dialing codes
	.ASCIZ	/D1/			;Terminal Identifier
	.ASCIZ	/XXXXXXXXX/		;TELENET Service Code for KI
	.ASCIZ	/XXXXXX/		;ID Number
	.ASCIZ	/XXXXXXXX/		;Password
	.EVEN
;
;------------------------------------------------------------------------
;Login Sequence to COMPUSERVE via TELENET (2400)
;
MSGLG3:	.ASCIZ	/ 3 - COMPUSERVE via TELENET/	;Net you are calling
;
TNTLOG:	.ASCIZ	/T2566955!/		;Phone number + required dialing codes
	.ASCIZ	/D1/			;Terminal Identifier
	.ASCIZ	/C XXX XXX/		;TELENET Service Code for Compuserve
	.ASCIZ	/XXXXX,XXXX/		;ID number
	.ASCIZ	/XXXXXX/		;Password
	.EVEN
;
;-----------------------------------------------------------------------
;Login Sequence to the Source VIA TELENET
;
MSGLG4:	.ASCIZ	/ 4 - SOURCE via TELENET/	;Net you are calling
;
SOURCE:	.ASCIZ	/T2566955!/		;Phone Number + required dialing codes
	.ASCIZ	/D1/			;Terminal identifier
	.ASCIZ	/C XXX XX/		;TELENET Service code for the SOURCE
	.ASCIZ	/ID XXXXXX/		;Id number
	.ASCIZ	/XXXXXXX/		;Password 
	.even
;
;------------------
;Login Sequence for DEC DEMO BUYING LINE
;
MSGLG5:	.ASCIZ	/ 5 - DIGITAL EQUIPMENT ORDER LINE  - dial sequence only / 
;
DECLOG:	.ASCIZ	/T18003323366!/	;PHONE NUMBER GOES HERE
;
;  (Logon sequence pending future update of this program.  Command key
;	+ 5 will dial number and then login will be initiated by sending
;	a double carriage return. The SIFLG will be automatically set so
;	that the graphics on the DEC line will work properly.)
	.EVEN
;
;----------------------------------------------
;Login Sequence for Dialing COMPUSERVE via TYMNET (2400)
;
MSGLG6:	.ASCIZ	/ 6 - COMPUSERVE via TYMNET/	;Net you are calling
;
TYMLOG:	.ASCIZ	/T2580554!/		;Phone number + required dialing codes
	.ASCIZ	/A/<200>		;Terminal Identifier
	.ASCIZ	/CPS/			;Compuserve Code
	.ASCIZ	/XXXXX,XXXX/		;ID number
	.ASCIZ	/XXXXXXX/		;Password
	.EVEN
;
;=============================================================
;End of User configuration Area
;=============================================================
;
; CONDITIONALS HERE FOR CMDKEY
;
.IF	GT	CMDKEY-40

.IF	LT	CMDKEY-177
	SHOKEY	= CMDKEY
	SHOKE2	= 1
	SHOKE3	= 1
.IFF
	SHOKEY	= '?
	SHOKE2	= '?
	SHOKE3	= '?
.ENDC
.IFF
.IF	EQ CMDKEY-12
	SHOKEY 	= 'L
	SHOKE2	= 'F
	SHOKE3	= 1
.IFF	
.IF	EQ CMDKEY-33
	SHOKEY	= 'E
	SHOKE2	= 'S
	SHOKE3	= 'C	
.IFF	
	SHOKEY	= '?
	SHOKE2	= '?
	SHOKE3	= '?
	
.ENDC
.ENDC
.ENDC
;-----------------------------------------------------------------------
;
;The following are used for CSEXEC transfer

SI	= 17	;Shift into protocol
SO	= 16	;Shift out of protocol
NAK	= 25	;Abort/end transfer
DLE	= 20	;Transparency flag
CTRLB	= 2	;Control B
CTRLC	= 3	;Control C
SOH	= 1	;Start of text
ETX	= CTRLC	;End of text
EOT	= 4	;End of transmission
ESC	= 33	;Escape character

;CSEXEC Status word flags

TFTYPE	= 1	;0=ASCII transfer, 1=Binary Transfer
TRNSFR	= 2	;1=Data transfer in progress
ESCFLG	= 4	;1=Escape sequence in progress
EOTFLG	= 10	;1=EOT received
MSKFLG	= 20	;0=Ok to mask, 1=do not mask
EXEFLG	= 40	;1=Executive mode enabled

;	Console terminal addresses/vector
;	    (not used for TSX-plus)
KVEC	= 60	;Keyboard vector
KSTAT	= 177560;Keyboard status register
KBUF	= 177562;Keyboard buffer

;	Misc definitions, I/O channel assignments
;
CTRLS	= 23	;Control S (DC3 - XOFF)
CTRLQ	= 21	;Control Q (DC1 - XON )
CTRLY	= 31	;Control Y
CTRLE	= 5
DEL	= 177	;Delete
CR	= 15	;Carriage return
BS	= 10	;Backspace
LF	= 12	;Line feed
BELL	= 7	;Bell character
SPACE	= 40	;Space
RMON	= 54	;Resident monitor address
ERRWD	= 52	;Error word
JSW	= 44	;Job status word
OUTCHN	= 2	;Transmit channel no.
INCHN	= 3	;Receive channel no.
LPCHN	= 4	;Line printer channel
CSCHAN	= 5	;CSEXEC channel
HDCHAN	= 6 	;Modem channel
;	Define the size of the modem ring buffer

BUFSIZ	= 4096.	;Define 4K ring buffer
KBFSIZ	= 120.	;Define 120 character keyboard input buffer
;
;
.IF NE TSXHAN
;
;  RDO$N AND RD0$FF STATUS WORDS for CL HANDLER
;
FO$RM	= 1	; Set FORM or NOFORM
TA$B	= 2	; Set TAB or NOTAB
L$C	= 4	; Set LC or NOLC
LF$OUT	= 10	; Set LFOUT or NOLFOUT
LF$IN	= 20	; Set LFIN or NOLFIN
FO$RM0	= 40	; Set FORMO or NOFORMO
BIN$OUT	= 100	; Set BINOUT or NOBINOUT
BIN$IN	= 200	; Set BININ or NOBININ
C$R	= 400	; Set CR or NOCR
CT$RL	= 1000	; Set CTRL or NOCTRL
D$TR	= 2000	; Turn on DTR or Turn off DTR
ET$BIT	= 4000	; Set EIGHTBIT or NOEIGHTBIG
;
;   BR$K Status Word
;
BR$ON	= 1	;Turn break ON
BR$OFF	= 0	;Turn break OFF
;
;
.ENDC

;   Baud rates 
;
B$LOW	= 5.		;300  baud
B$MED	= 6.		;600  baud
B$FST	= 7.		;1200 baud
V$FST	= 10.		;2400 BAUD
;*****************************************************
	.MCALL .REGDEF,.PRINT,.EXIT,.CSISPC
	.MCALL .ENTER,.LOOKUP,.FETCH,.READW
	.MCALL .TTYOUT,.WAIT,.WRITW,.CLOSE
	.MCALL .PURGE,.SERR,.TTINR,.SPFUN,.TWAIT


	.REGDEF
;*****************************************************
START:	.SERR				;Let program handle fatal errors
	MOV	#TSX,R0			;Test for TSX
	EMT	375
	BCS	SETUP			;Branch if RT-11
	COM	TSXFLG			;Else set TSX flag
	MOV	#LOCK,R0		;Lock program in low memory
	EMT	375			;For TSX+ only
	BCC	2$			;Error detected?
	.PRINT	#MSG18			;Yes, print message & exit
	.EXIT
2$:	.PRINT	#KBSET			;Make TSX+ pass all control characters
SETUP:	BIS	#50100,@#JSW		;Put keyboard single character mode
	MOV	#LIMIT,FREE		;Start of free area
	MOV	#BUFSIZ,SPFBUF		;Store size of ring buffer
	CLR	BCOUNT			;Clear active character count
	MOV	#BUFSIZ,CNT		;Initialize char count
	MOV	#BUFA,ADDR2		;Process adr pointer
	MOV	#BUFSIZ,CNT2		;Process char count
	TST	TSXFLG			;RT-11?
	BNE	SETMO			;No, skip this
	MOV	#BUFE,KADDR		;Keyboard buffer adr pntr
	MOV	#KBFSIZ,KCNT		;Keyboard buffer char count
	CLR	KCOUNT			;Keyboard active char count
	MOV	#BUFE,KADDR2		;Keyboard process adr pntr
	MOV	#KBFSIZ,KCNT2		;Keyboard process char count
	MOV	@#KVEC,SAVE1		;Save address of rt-11 keyboard
	MOV	#TTYINT,@#KVEC		;Put in our address
	BIS	#100,@#KSTAT		;Enable keyboard interrupts
SETMO:	
.IF  NE TSXHAN
	TST	TSXFLG			;TSX+?
	BEQ	2$			;No, skip this CL code
	MOV	#MODTER,TSXLIN		;Select Terminal line
	MOV	#CLASIG,R0		;Assign CLn to Modem line
	EMT	375
.ENDC
2$:	MOV	FREE,R1			;Get free area
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ??	
	BEQ	4$			;No, forget the CL handler
	BR	6$			;SKIP FETCH
.ENDC
4$:	.FETCH	R1,#MOSP		;Get MO modem handler
	BCC	6$			;Branch if no error
	.PRINT	#MSG1			;Else we have a .FETCH error
	JMP	FATAL			;Terminate program
6$:	MOV	R0,FREE			;Update free area
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ?
	BEQ	8$			;Branch if not TSX+
	.LOOKUP	#CLAREA,#HDCHAN,#CLSP	;Lookup the CL handler
	BCC	10$			;Branch if no error
	.PRINT	#MSG13			;otherwise, tell us
	JMP	FATAL			;and terminate program
.ENDC
8$:	.LOOKUP	#MOAREA,#HDCHAN,#MOSP	;Lookup the modem handler
	BCC	10$			;Skip if no error
	.PRINT	#MSG13			;Else inform user of error
	JMP	FATAL			;and abort program
10$:	MOV	#SPFTBL,R1		;Get address of FUNCTION table
12$:	CMP	(R1),#-1		;End of table?
	BEQ	18$			;Yes, continue with program
.IF NE TSXHAN
	TST	TSXFLG			;Is this TSX+
	BEQ	14$			;No, so skip
	MOV	2(R1),@(R1)+		;Move code to label
	BR	16$
.ENDC
14$:	MOV	4(R1),@(R1)+		;Move value to label
16$:	CMP	(R1)+,(R1)+		;Go to next table entry
	BR	12$			;Loop thru table
18$:	TST	TSXFLG			;TSX+ or RT-11?
	BEQ	24$			;Skip, RT-11 doesn't check
	.SPFUN	#HDFUN,#HDCHAN,TST$CA,#SPFBUF	; Carrier detected?
	BCC 	20$			;Spfun error ?
	.PRINT	#MSG14			;Yes, print message
	JMP	EXIT1			;Exit
20$:					;No error
.IF NE TSXHAN
	BIT 	#2,SPFBUF		;Test bit 1 for carrier
	BEQ	24$			;No carrier, continue
	BR	22$			;Carrier present, modem busy msg
.ENDC
	BIT	#1,SPFLG		;Carrier detected?
	BEQ	24$			;No, ok to use modem channel
22$:	.PRINT	#MSG11			;Else tell user modem is busy
	JMP	EXIT1			;and end program
24$: 	.PRINT	#CLS			;Clear screen
	.PRINT 	#MSGA			;Sign on
.IF NE TSXHAN
	TST	TSXFLG			;TSX+??	
	BEQ	30$			;No, skip CL code
26$:	MOV	#D$TR,RSET		
	.SPFUN	#HDFUN,#HDCHAN,RD$ON,#RSET	;Turn on DTR
					;Set modem to special mode
	BCC	28$			;Branch if no error
	.PRINT	#MSG14			;Tell user the function failed
	JMP	EXIT1			;And abort the program
28$:	MOV	#<LF$OUT!BIN$IN>,RSET	;Set NOLFOUT and NOBININ
	.SPFUN	#HDFUN,#HDCHAN,RDO$FF,#RSET
	BCC	34$			;Branch and continue
	BR	32$			;Branch and exit
.ENDC
30$:	.SPFUN	#HDFUN,#HDCHAN,RD$ON,#SPFBUF
					;Set modem to special mode
	BCC	34$			;Branch if no error
32$:	.PRINT	#MSG14			;Tell user the function failed
	JMP	EXIT1			;And abort the program
34$:	JSR	PC,GOBAUD		;Set initial baud rate
36$:	CLR	DUPFLG			;Make sure we are in Full duplex
	CLR	CMDFLG			;Clear command flag
	CLR	CSSTAT			;Clear CSEXEC status word
	CLR	PSFLG			;Clear pause flag
	MOV	#1500.,SLPCNT		;Load counter
.IF EQ MODTYP				;Is this a DEC 224 modem
SETMOd:	MOVB	#CTRLB,R0		;Bring to Ready condition with CTRLB
	JSR	PC,SEND
	.twait	#twarea,#time		;Need delay to properly clear buffer
CLRBUF:	JSR	PC,TTYIN		;Read keyboard buffer
	bcs	ready			;Buffer empty so go to READY
	CMPB	R0,#'r			;'READY' signal from modem ?
	BNE	CLRBUF			;No, so go read buffer again
.ENDC
;*****************************************************
;MAIN PROGRAM LOOP
READY:	JSR	PC,PRINT		;Check print buffer
	BIT	#ESCFLG,CSSTAT		;Escape sequence in progress (CSEXEC)?
	BEQ	2$			;No, continue
	JSR	PC,CSEXEC		;Else go do protocol
	CLR	CSSTAT			;Clear executive mode
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ??
	BEQ	2$			;No, so skip this
	MOV	#BIN$IN,RSET		;Put us in NOBININ mode
	.SPFUN	#HDFUN,#HDCHAN,RDO$FF,#RSET	;for the CL handler
	BCC	2$			;Error?
	.PRINT	#MSG14			;Tell us
	JMP	EXIT1			;and abort the program
.ENDC
2$:	JSR	PC,TTYIN		;Keyboard input ?
	BCC	6$			;Yes
	TST	SLPCNT			;Should we put program to sleep?
	BEQ	4$			;Yes, so go to timer
	DEC	SLPCNT			;No, so Decrement sleep counter
	BR	READY			;and start again
4$:	.TWAIT	#TWAREA,#TIME		;Wait for a time
	BR	READY			;and start again
6$:	JSR	PC,CKMND		;Check for EXEC commands
	BR	READY			;And then do it again
;*****************************************************
;Check for EXEC commands
CKMND:	TST	CMDFLG			;Command sequence in progress?
	BEQ	8$			;No, try to send character
	CLR	CMDFLG			;Else process command sequence
	JSR	PC,LCCVT		;Make sure commands are UC
	MOV	#DSPTBL,R1		;Get address of dispatch table
2$:	CMP	(R1),#-1		;End of table?
	BEQ	4$			;Yes, invalid command
	CMP	R0,(R1)+		;Character in command table?
	BNE	6$			;No, try next one
	MOV	2(R1),BGNLOG		;Yes, so save logon module name
	MOV	4(R1),TELNO		;Yes, so save phone number
	MOV	6(R1),R2		;Yes, so save next destination
	JSR	PC,@(R1)		;Go do it
4$:	RTS	PC			;Return
6$:	CMP	(R1)+,(R1)+		;To next table entry
	CMP	(R1)+,(R1)+		
	BR	2$			;Loop through table
8$:	CMPB	R0,#DEL			;Delete character?
	BNE	10$			;No, skip
	TST	DELFLG			;Convert the delete?
	BEQ	10$			;No, leave it alone
	MOV	#BS,R0			;Else convert it to a backspace
	BR	12$
10$:	CMPB	R0,#CMDKEY		;Command character ??
	BNE	12$			;No, send everything else
	COM	CMDFLG			;Set command flag
	RTS	PC			;and return
12$:	JSR	PC,SEND			;Send everything else
	RTS	PC			;and start again
;*****************************************************
;Process CSEXEC escape sequences here
CSEXEC:	BIC	#ESCFLG!TRNSFR,CSSTAT	;Clear escape & transfer bits
	CLR	ERRFLG			;Clear error flag
	JSR	PC,HOSTIN		;Get character from host
	BCS	4$			;Abort?
	CMPB	R0,#'I			;Send ID string?
	BNE	2$			;
	JMP	SNDID			;Send ID string to host
2$:	CMPB	R0,#'A			;Initialize for data transmission?
	BNE	4$
	JMP	MNTRAN			;Go to transfer routine
4$:	JMP	ABORT			;Else abort the sequence
;*****************************************************
;Initialize for CSEXEC data transfer
MNTRAN:	.PRINT	#MSGO			;Tell user we are initializing
	MOV	#'0,RECNBR		;Init record number
	JSR	PC,GET1			;Get a command line
	BCS	6$			;Abort?
	CMPB	1(R3),#'A		;ASCII transfer?
	BEQ	2$			;Yes, continue
	BIS	#TFTYPE,CSSTAT		;Else set Binary transfer
2$:	CMPB	(R3),#'U		;Upload?
	BNE	4$			;no
	JMP	UPLOAD			;Else go do upload
4$:	CMPB	(R3),#'D		;Download?
	BNE	6$			;No, abort
	JMP	DNLOAD			;Else go do download
6$:	JMP	ABORT			;Abort
;*****************************************************
;Routine to parse filespec
PARSE:	BIS	#TRNSFR,CSSTAT		;We are transferring now
	MOV	#CSBUFF,R3		;Point to buffer
	TST	(R3)+			;Point to filespec
	MOV	#FBUFF,R1		;Point to CSI buffer
2$:	CMPB	(R3),#CR		;End of filespec?
	BEQ	4$
	MOVB	(R3)+,(R1)+		;Move byte into buffer
	BR	2$
4$:	MOVB	#'=,(R1)+		;Finish filespec
	CLRB	(R1)
	MOV	#FBUFF,R1		;Reset to start of buffer
	MOV	SP,R2			;Save stack
	.CSISPC	#OUTSP,#DEXT,R1		;Process filename
	MOV	R2,SP			;Restore stack
	BCC	8$			;Error?
	.PRINT	#MSG9			;Yes, tell user
6$:	SEC				;Set abort flag
	RTS	PC			;and return
8$:	MOV	FREE,R0			;Get current free area
	.FETCH	R0,#OUTSP		;Load handler
	BCC	10$			;Error?
	.PRINT	#MSG1			;Yes, fetch error
	BR	6$			;Abort transfer
10$:	MOV	R0,FREE			;Update free area
	.PURGE	#CSCHAN			;Clear channel first
	TST	TSXFLG			;TSX?
	BNE	12$			;Skip if TSX
	MOV	@#RMON,R0		;Force directory read
	CLR	256(R0)			;So we can interchange disks
12$:	CLC				;Clear abort flag
	RTS	PC			;and return
;*****************************************************
;Routine to handle downloading
DNLOAD:	.PRINT	#MSGL			;Download message
	JSR	PC,PARSE		;Parse filespec
	BCC	2$			;Error?
	JMP	ABORT			;Yes, abort it
2$:	.LOOKUP	#CSAREA,#CSCHAN,#OUTSP	;See if file exists
	BCS	6$			;No, you can open it ok
	.PRINT	#MSGQ			;Else ask user what to do
	.PURGE	#CSCHAN			;Purge channel first
4$:	JSR	PC,TTYIN		;Get input
	BCS	4$
	JSR	PC,LCCVT		;Upper case only
	.TTYOUT				;Echo the response
	JSR	PC,CRLF			;CR/LF for formatting
	CMPB	R0,#'S			;Supercede?
	BEQ	6$			;Yes
	JMP	ABORT			;Else abort transfer
6$:	MOV	OUTSP+8.,R1		;Get filesize (if any)
	.ENTER	#CSAREA,#CSCHAN,#OUTSP,R1
					;Open the file
	BCC	10$			;Error?
8$:	.PRINT	#MSG2			;File open error
	.PURGE	#CSCHAN			;Dump channel
	JMP	ABORT			;and abort transfer
10$:	TST	R0			;No room for file [TSX only]
	BEQ	8$			;Yes, open error
	MOV	R0,CSMAX		;Save size of file
	MOV	#BUFC,CSPNT		;Set up buffer pointer
	MOV	#512.,CSCHR		;Character count
	CLR	CSBLK			;Block count
DOWN1:	
2$:	JSR	PC,GETBLK		;Get a checksummed block of data
	BCC	4$
	INC	ERRFLG			;Set error flag
	BR	12$			;And attempt to close file
4$:	BIT	#EOTFLG,CSSTAT		;End of transmission?
	BNE	12$			;Yes, wrap it up
	MOVB	(R3)+,@CSPNT		;Move character into buffer
	INC	CSPNT			;Increment pointer
	DEC	CSCHR			;Block full?
	BNE	10$			;No, continue
	.WRITW	#CSAREA,#CSCHAN,#BUFC,#256.,CSBLK
	BCC	6$			;Error?
	.PRINT	#MSG5			;Write error
	.PURGE	#CSCHAN			;Dump channel
	JMP	ABORT
6$:	INC	CSBLK			;Next block
	CMP	CSBLK,CSMAX		;Is this the last block?
	BLT	8$			;No
	INC	ERRFLG			;Set error flag
	.PRINT	#MSGR			;Tell user
	BR	16$
8$:	MOV	#512.,CSCHR		;Reset pointers
	MOV	#BUFC,CSPNT
10$:	DEC	MSGLEN			;Message finished?
	BNE	4$			;No, back for more
	BR	DOWN1			;Else get another line
12$:	CMP	CSPNT,#BUFC		;Starting new block?
	BEQ	16$			;Yes, no need to pad
14$:	CLRB	@CSPNT			;Pad buffer with nulls
	INC	CSPNT
	DEC	CSCHR
	BNE	14$
	.WRITW	#CSAREA,#CSCHAN,#BUFC,#256.,CSBLK
	BCC	16$
	.PRINT	#MSG5			;Error?
16$:	.CLOSE	#CSCHAN			;Close it
	TST	ERRFLG			;Check if error in progress
	BEQ	18$			;No error, continue
	JMP	ABORT			;Else abort transmission
18$:	MOVB	#'.,R0			;Tell host we got it
	JSR	PC,SEND
	CLR	CSSTAT			;Clear protocol mode
20$:	.print	#MSGS			;Closing message
	RTS	PC
;*****************************************************
;Routine to handle uploading
UPLOAD:	.PRINT	#MSGM			;Beginning upload message
	JSR	PC,PARSE		;Parse filespec
	BCC	2$			;Error?
	JMP	ABORT			;Yes, abort this
2$:	.LOOKUP	#CSAREA,#CSCHAN,#OUTSP	;Open file
	BCC	4$			;File exists?
	.PRINT	#MSG10			;File not found message
	JMP	ABORT			;No, abort transfer
4$:	BIC	#MSKFLG,CSSTAT		;Allow normal masking
	CLR	UPBLK			;Block number to read
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ??
	BEQ	6$
	MOV	#BIN$OUT,RSET	
	.SPFUN	#HDFUN,#HDCHAN,RD$ON,#RSET	;set BINOUT for CL handler
	BCC	6$
	.PRINT	#MSG14
	JMP	EXIT1			;and abort the program
.ENDC
6$:	MOVB	#'.,R0			;Tell host we are ready

	JSR	PC,SEND
	JSR	PC,HOSTIN		;Get character from host
	BCS	10$			;Abort?
	CMPB	R0,#'.			;Right prompt?
	BNE	10$			;No, abort this
8$:	.READW	#CSAREA,#CSCHAN,#BUFC,#256.,UPBLK
					;Read a block
	BCC	12$			;error or EOF?
	TSTB	@#ERRWD			;EOF?
	BEQ	18$			;Yes, transfer finished
10$:	.CLOSE	#CSCHAN			;Else read error, close chan
	JMP	ABORT
12$:	MOV	#CSBUFF,R3		;Point to start of CS buffer
	MOV	#BUFC,R2		;Get address of input file buffer
	CLR	MSGLEN			;Init message length
14$:	MOVB	(R2)+,(R3)+		;Put data in buffer
	INC	MSGLEN			;bump counter
	CMP	MSGLEN,#256.		;Buffer full?
	BNE	14$			;No, back for more
	JSR	PC,SNDBLK		;Send a checksummed line
	BCS	10$
	MOV	#CSBUFF,R3		;Point to start of CS buffer
	CLR	MSGLEN			;Init message length
16$:	MOVB	(R2)+,(R3)+		;put second half of block in
	INC	MSGLEN
	CMP	MSGLEN,#256.		;Buffer full?
	BNE	16$			;No, back for more
	JSR	PC,SNDBLK		;send a checksummed line
	BCS	10$
	INC	UPBLK			;next block
	BR	8$			;back for another block
18$:	.CLOSE	#CSCHAN			;close input channel
	BIS	#MSKFLG,CSSTAT		;Clear mask
	MOV	#1,MSGLEN		;Message length
	MOV	#EOT,@#CSBUFF		;send EOT
	JSR	PC,SNDBLK		;send checksummed line
	BCS	10$
	CLR	CSSTAT			;Clear protocol mode
20$:	.PRINT	#MSGT
	RTS	PC
;*****************************************************
;Send a checksummed block to remote
SNDBLK:	TST	MSGLEN			;No message?
	BEQ	20$
	INC	RECNBR			;bump record number
	CMPB	RECNBR,#'9		;Roll over?
	BLOS	2$			;No
	MOVB	#'0,RECNBR		;Else reset record number
2$:	MOV	#CSBUFF,R3		;Point to buffer
	MOV	MSGLEN,R1		;Message length
	CLR	CKSUM			;Clear checksum
	MOVB	#SOH,R0			;Start the message
	JSR	PC,SEND
	MOVB	RECNBR,R0		;send record number
	JSR	PC,SEND
	JSR	PC,UPDATE		;update checksum
4$:	MOVB	(R3)+,R0		;Get data byte
	JSR	PC,UPDATE		;Update checksum
	TSTB	R0			;Is this character a null?
	BEQ	6$			;Yes, don't display it
	BIT	#TFTYPE,CSSTAT		;ASCII transfer?
	BNE	6$			;No, binary, don't display
	.TTYOUT				;Else display is ASCII
6$:	BIT	#MSKFLG,CSSTAT		;Ok to mask?
	BNE	12$			;No, if flag set
	TSTB	R0			;Null byte?
	BEQ	12$			;Yes, don't mask it
	CMPB	R0,#4			;ASCII 1-4?
	BHI	10$			;no
8$:	BISB	#100,R0			;Else mask it
	MOVB	R0,R4			;Save character
	MOVB	#DLE,R0
	JSR	PC,SEND			;Send mask
	MOVB	R4,R0			;Restore character
10$:	CMPB	R0,#17			;Mask ASCII 17-25
	BLO	12$
	CMPB	R0,#25
	BLOS	8$
12$:	JSR	PC,SEND			;Send character
	DEC	R1			;Decrement counter
	BNE	4$			;Message finished
	MOVB	#ETX,R0			;Send End of text
	JSR	PC,SEND
	CMPB	CKSUM,#40		;Cksum <40?
	BHIS	14$			;nope
	MOVB	#DLE,R0			;send it masked
	JSR	PC,SEND
	BISB	#100,CKSUM		;Mask it
14$:	MOVB	CKSUM,R0		;send it
	JSR	PC,SEND
16$:	JSR	PC,HOSTIN		;Get host's reply
	BCS	22$			;Abort?
	BIT	#TFTYPE,CSSTAT		;Binary transfer?
	BEQ	18$			;No, no need to display reply
	.TTYOUT				;Else display the reply
18$:	CMPB	R0,#'.			;Transmission ok?
	BEQ	20$			;Yes, return
	CMPB	R0,#'/			;Invalid transmission?
	BNE	16$			;No, try to get another reply
	.PRINT	#MSGP			;Tell user we are re-sending
	BR	2$
20$:	TST	(PC)+			;clear abort flag
22$:	SEC				;Set abort flag
	RTS	PC
;*****************************************************
;Routine to receive a checksummed block from remote
GETBLK:	MOVB	#'.,R0			;Prompt remote for next record
	JSR	PC,SEND
	BIT	#TFTYPE,CSSTAT		;Binary transfer?
	BEQ	GET1			;No, don't display prompt
	.TTYOUT				;Else display it (Binary)
GET1:	INC	RECNBR			;bump record number
	CMPB	RECNBR,#'9		;Roll over?
	BLOS	2$			;No
	MOVB	#'0,RECNBR		;Else reset record number
2$:	MOV	#CSBUFF,R3		;Get start of buffer
	JSR	PC,HOSTIN		;Get a character from remote
	BCC	6$			;Abort?
4$:	RTS	PC			;Yes, return
6$:	CMPB	R0,#SOH			;Start of heading?
	BEQ	8$			;Yes, start receiving the record
	CMPB	R0,#ETX			;ETX by itself is questionable
	BNE	2$
	MOVB	#'/,R0			;Send a logical nak
	JSR	PC,SEND
	BR	2$
8$:	CLR	CKSUM			;Clear checksum
	BIC	#EOTFLG,CSSTAT		;Clear EOT bit
	CLR	MSGLEN			;and message length
10$:	JSR	PC,HOSTIN		;Get sender's record number
	BCS	4$
	MOVB	R0,RECHST		;Save host record number
	BR	24$			;and update checksum
12$:	JSR	PC,HOSTIN		;Get a character
	BCS	4$
	CMPB	R0,#NAK			;A nak?
	BNE	14$
	SEC				;Set for abort
	RTS 	PC
14$:	CMPB	R0,#ETX			;End of text?
	BEQ	26$
	CMPB	R0,#EOT			;End of transmission?
	BNE	16$
	BIS	#EOTFLG,CSSTAT		;set end of transmission flag
16$:	CMPB	R0,#DLE			;Masked character comming?
	BNE	20$			;No
18$:	JSR	PC,HOSTIN		;Else get next character
	BCS	4$
	BICB	#340,R0			;Make control character
20$:	BIT	#TRNSFR,CSSTAT		;Transfer in progress?
	BEQ	22$			;No, don't display this
	BIT	#TFTYPE,CSSTAT		;Binary transfer?
	BNE	22$			;Yes, don't display this
	TSTB	R0			;Null byte?
	BEQ	22$			;Then don't display it
	.TTYOUT				;Display byte
22$:	MOVB	R0,(R3)+		;Move character into buffer
	INC	MSGLEN			;Bump message length
24$:	JSR	PC,UPDATE		;Update checksum
	BR	12$			;And back for more
26$:	JSR	PC,HOSTIN		;Get checksum
	BCS	4$
	CMPB	R0,#DLE			;Masked?
	BNE	30$
28$:	JSR	PC,HOSTIN		;Get masked character
	BCS	4$
	BICB	#340,R0			;Unmask character
30$:	CMPB	CKSUM,R0		;Checksum match?
	BEQ	34$			;Yes, continue
32$:	.PRINT	#MSGP			;No, tell user
	MOVB	#'/,R0			;and request retransmission
	JSR	PC,SEND
	BR	2$			;and start over
34$:	CMPB	RECNBR,RECHST		;Record numbers match?
	BEQ	36$			;Yes
	BHI	4$			;Abort if greater than expected
	MOVB	#'.,R0			;Else it must be a duplicate record
	JSR	PC,SEND			;Accept it, and try again
	BIT	#TFTYPE,CSSTAT		;Binary transfer?
	BEQ	2$			;No, don't display it
	.TTYOUT				;Else display it
	BR	2$
36$:	MOV	#CSBUFF,R3		;Point to start of buffer
	RTS	PC
;*****************************************************
;Routine to update checksum
UPDATE:	MOVB	CKSUM,R4		;Get checksum
	ASLB	R4			;Rotate 1 bit left
	ADC	R4			;Add carry (if any)
	MOVB	R4,R4			;Sign extend it
	ADD	R0,R4			;Add new checksum
	ADC	R4			;Add carry (if any)
	MOVB	R4,CKSUM		;save new checksum
	RTS	PC
;*****************************************************
;Send ID string to host
SNDID:	.PRINT	#MSGK			;Tell user we are sending ID
	MOV	#SYSID,R1		;Get address of ID string
	JSR	PC,SNDLIN		;Send it
	RTS	PC
;*****************************************************
;Routine to get character from Remote
HOSTIN:	JSR	PC,SCAN			;Check keyboard for abort
	BCC	2$			;Abort this?
	RTS	PC			;Yes
2$:	JSR	PC,REMOTE		;Check remote input
	BCS	HOSTIN			;Loop if nothing
4$:	CMPB	R0,#NAK			;Abort this?
	BEQ	6$			;Branch if yes
	TST	(PC)+			;Clear abort flag
6$:	SEC				;Set abort flag
	RTS	PC			;and return
;*****************************************************
;Abort CSEXEC mode here
ABORT:	.PRINT	#MSGN			;Inform user
	CLR	CSSTAT			;Clear status word
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ??
	BEQ	2$			;no so skip
	MOV	#BIN$IN,RSET	
	.SPFUN	#HDFUN,#HDCHAN,RDO$FF,#RSET	;SET NOBININ for CL handler
	BCC	2$
	.PRINT	#MSG14
	JMP	EXIT1			;and abort the program
.ENDC
2$:	MOVB	#NAK,R0			;Send a nak to host
	JSR	PC,SEND			;to kill transfer
	RTS	PC			;and return to terminal mode
;*****************************************************
;Scan keyboard for abort character
SCAN:	JSR	PC,TTYIN		;Check keyboard
	BCS	2$			;Nothing entered
	CMPB	R0,#CTRLC		;Was character a CTRL-C?
	BEQ	4$			;Yes, abort this
	JSR	PC,SEND			;Else send character
2$:	TST	(PC)+			;Clear carry flag
4$:	SEC				;Set abort flag for abort
	RTS	PC			;Return
;*****************************************************
;TRANSMIT FILE TO THE REMOTE COMPUTER
TRANS:	.PURGE	#OUTCHN			;Make sure channel is free
	.PRINT	#MSG8A			;Ask for filespec
	JSR	PC,FILSPC		;Get filespec
	BCS	RETRN			;Abort if error
	MOV	FREE,R1			;Fetch handler
	.FETCH	R1,#OUTSP
	BCC	2$			;Error?
	.PRINT	#MSG1			;Yes, inform user
	RTS	PC			;And return
2$:	MOV	R0,FREE			;Update free memory
	TST	TSXFLG			;TSX?
	BNE	4$			;Skip if TSX
	MOV	@#RMON,R0		;Get RMON location
	CLR	256(R0)			;Force directory read
4$:	.LOOKUP	#TAREA,#OUTCHN,#OUTSP	;Open transmit file
	BCC	6$			;Error?
	.PRINT	#MSG10			;Yes, file not found
	RTS	PC			;And return
6$:	.PRINT	#MSGD
	CLR	R2			;Block no.
8$:	.READW	#TAREA,#OUTCHN,#BUFC,#256.,R2;Read a block
	BCS	26$			;Read error or eof ?
	MOV	#512.,R4		;No, char count
	MOV	#BUFC,R5		;Point to buffer
10$:	MOVB	(R5)+,R0		;Get char
	TSTB	R0			;Null ?
	BEQ	24$			;Yes, skip
	TST	PSFLG			;Ok to send to remote?
	BEQ	12$			;Yes
	JSR	PC,PAUSE		;Else wait for remote to clear
12$:	JSR	PC,SEND			;Send character
;	BR	16$			;Patch to defeat throttling....
;
;  Routine below will allow handshaking with Compuserve
;  when uploading messages if required
;

;	CMPB	R0,#CR			;Carriage return sent?
;	BNE	16$
;14$:	JSR	PC,PRINT		;Check remote for a CTRLE
;	CMPB	R0,#CTRLE		;CTRLE received?
;	BEQ	16$			;Yes, resume sending
;	JSR	PC,TTYIN		;else scan for abort while waiting
;	CMPB	R0,#CTRLY		;CTRL-Y seen?
;	BEQ	22$			;Yes, abort the transmission
;	BR	14$			;else go back and wait for a CTRLE
;
16$:	JSR	PC,PRINT 		;Check print and remote 1st
	JSR	PC,TTYIN		;Check keyboard
	BCS	24$			;Continue if nothing 
	CMPB	R0,#SPACE		;A space?
	BNE	20$			;No, go on
18$:	JSR	PC,PRINT		;Check print
	JSR	PC,TTYIN		;Else wait for a character
	BCS	18$
20$:	CMPB	R0,#CTRLY		;Cntrl-Y?
	BNE	24$			;No go on
22$:	.PURGE	#OUTCHN			;Dump channel
	.PRINT	#MSGH			;Print message
	RTS	PC
24$:	DEC	R4			;Dec char count
	BNE	10$			;Block done ?
	INC	R2			;Yes, next block
	BR	8$			;Again
26$:	TSTB	@#ERRWD			;EOF ?
	BEQ	28$			;Yes, done
	.PRINT	#MSG3			;No, read error
28$:	.CLOSE	#OUTCHN			;Close file
	JSR	PC,PRINT		;Check print
	.PRINT	#MSGC			;File transmitted
RETRN:	RTS	PC
;*****************************************************
;OPEN RECEIVER FILE
OPEN:	.WAIT	#INCHN			;Channel active ?
	BCS	2$			;No, channel available
	.PRINT	#OPNERR			;File already open, skip
	RTS	PC
2$:	.PURGE	#INCHN			;Make sure channel is clear
	.PRINT	#MSG8			;Ask user for file name
	JSR	PC,FILSPC		;Get file name
	BCC	4$			;Skip if no error
	RTS	PC			;Else abort
4$:	MOV	FREE,R1
	.FETCH	R1,#OUTSP		;Get handler
	BCC	6$			;Error?
	.PRINT	#MSG1			;Fetch error
	RTS	PC			;Return
6$:	MOV	R0,FREE			;Update free area
	TST	TSXFLG			;TSX?
	BNE	8$			;Skip if TSX
	MOV	@#RMON,R0		;Get RMON address
	CLR	256(R0)			;Force directory read
8$:	.LOOKUP	#RAREA,#INCHN,#OUTSP	;File exists?
	BCS	12$			;No, create it
	.PRINT	#MSGI			;Ask user for permission
	.PURGE	#INCHN			;Clear I/O channel first
10$:	JSR	PC,TTYIN		;Keyboard
	BCS	10$
	JSR	PC,LCCVT		;Make sure only UC
	.TTYOUT				;Echo the character
	JSR	PC,CRLF			;Send CR/LF for formatting
	CMPB	R0,#'S			;Supercede?
	BEQ	12$			;Yes
	CMPB	R0,#'R			;Re-enter filespec?
	BEQ	2$			;Yes
	.PRINT	#MSGJ			;Else file is not superceded
	RTS	PC
12$:	MOV	OUTSP+8.,R1		;Get size of file (if any)
	.ENTER	#RAREA,#INCHN,#OUTSP,R1	;Open receiver file
	BCC	16$			;Error ?
14$:	.PRINT	#MSG2			;Yes, open error
	.PURGE	#INCHN			;Dump channel
	RTS	PC			;And return
16$:	TST	R0			;No room for file [TSX only]?
	BEQ	14$			;File error
	MOV	#BUFB,INPNT		;Buffer pointer
	CLR	INBLK			;Block count
	MOV	#512.,INCHR		;Character count
	MOV	R0,MAXBLK		;Save filesize just in case
	.PRINT	#MSGE			;File open message
	CLR	TGFLG			;Clear toggle flag
	INC	RXFLG			;Set Receiver flag
	RTS	PC
;*****************************************************
FCLOSE:
.IF NE TSXHAN				;Is CL handler installed
	TST	TSXFLG			;and is this TSX+
	BNE	2$			;Yes, so skip CTRLS
.ENDC
	MOV	#CTRLS,R0		;Shut off remote
	JSR	PC,SEND			;Send cntrl-s
2$:	.PRINT	#MSG12			;Tell that file is full
	DEC	INBLK			;Restore last block
	.CLOSE	#INCHN			;Close the file
	.PRINT	#MSGB			;Tell user it is closed
	CLR	RXFLG			;Clear receiver flag
	CLR	TGFLG			;Clear toggle flag
	.PRINT	#MSG12A			;Ask if you want a new file
4$:	JSR	PC,TTYIN		;Get user response
	BCS	4$
	JSR	PC,CRLF			;Send a CR/LF
	JSR	PC,LCCVT		;Make it upper case
	CMPB	R0,#'Y			;Confirm desire to open new file.
	BEQ	6$			;Yes
	BR	8$			;Continue without opening file
6$:	JSR	PC,OPEN			;Open a new file
8$:
.IF NE TSXHAN				;Is CL handler selected
	TST	TSXFLG			;and is this TSX+
	BNE	10$			;Yes, so skip CTRLQ sequence
.ENDC
	MOV	#CTRLQ,R0		;
	JSR	PC,SEND			;Tell NET to start xmiting again
10$:	RTS	PC			;In any case let's continue on
;*****************************************************
CLOSE:	TST	RXFLG			;Channel active ?
	BNE	2$			;Yes, can close
	.PRINT	#CLSERR			;No, already closed
	BR	6$
2$:	CLRB	@INPNT			;Pad buffer with nulls
	INC	INPNT
	DEC	INCHR
	BNE	2$
	MOV	#BUFB,R1		;Write last block
	MOV	INBLK,R3
	.WRITW	#RAREA,#INCHN,R1,#256.,R3
	BCC	4$			;Error ?
	.PRINT	#MSG5
4$:	.CLOSE	#INCHN			;Close file
	.PRINT	#MSGB			;File closed
	CLR	RXFLG			;Clear receiver flag
6$:	RTS	PC
;*****************************************************
BREAK:	
.IF NE TSXHAN
	TST	TSXFLG			;RT-11
	BNE	2$			;No, skip this
.ENDC
	.SPFUN	#HDFUN,#HDCHAN,BR$K	;Send a break
	BCC	8$			;Branch if no error
	BR	6$
.IF NE TSXHAN

2$:	.SPFUN	#HDFUN,#HDCHAN,BR$K,#0,#BR$ON	;Turn break on
	BCC	4$			;Branch if no error
	BR	6$
4$:	.TWAIT	#TWAREA,#TIME
	.SPFUN	#HDFUN,#HDCHAN,BR$K,#0,#BR$OFF		;TURN BREAK OFF
	BCC	8$			;BRANCH IF NO ERROR
.ENDC

6$:	.PRINT	#MSG14			;Tell user we failed
	JMP	EXIT1			;and abort program
8$:	RTS	PC
;*****************************************************
;TRANSMIT A CHARACTER TO REMOTE
SEND:	MOVB	R0,CHRSAV		;Save character to be output
2$:	.SPFUN	#HDFUN,#HDCHAN,WRT$Q,#WRTFLG,#1,,#0 ;Is Modem busy?
	BCC	4$			;No error,so skip
	.PRINT #MSG14			;Else, error message
	JMP	EXIT1			;and exit
4$:	
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ??
	BEQ	6$			;No, skip next step
	BICB	#5,WRTFLG		;leave only XOFF from remote to check
.ENDC
6$:	TSTB	WRTFLG			;Busy?
	BEQ	12$			;No so continue
	JSR	PC,PRINT		;yes, so check print and keyboard
	JSR	PC,TTYIN
	BCS	2$			;nothing so try again
	CMPB	R0,#CTRLC		;Control-C  ???
	BEQ	10$			;
8$:	Br	2$			;Try again
10$:	jmp	hangup			;CTRLC intercepted- try hangup
12$:	MOVB	CHRSAV,R0		;Restore character
	BIT	#EXEFLG,CSSTAT		;Executive mode?
	BNE	16$			;Yes, transfer byte untouched
	JSR	PC,LCOPT		;Check if LC ok
	MOVB	R0,CHRSAV		;Change our saved copy
	CMPB	R0,#LF			;Is character a line feed?
	BNE	14$			;No, continue
	TST	LFFLG			;Ok to send LF's?
	BNE	20$			;No, ignore the character
14$:	TST	DUPFLG			;Half duplex?
	BEQ	16$			;No, must be full duplex
	.TTYOUT				;Else display character
16$:	
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ??
	BEQ	18$			;No so skip to WRITW
	.SPFUN	#HDFUN,#HDCHAN,BYT$SN,#CHRSAV,#1	;Send a BYTE
	BCC	20$			;Error?
	.PRINT	#MSG15			;Yes, so tell us
	JMP	HANGUP			;and hangup
.ENDC
18$:	.WRITW	#MAREA,#HDCHAN,#CHRSAV,#1
					;Send character
	BCC	20$			;Branch if no error
	.PRINT	#MSG15			;Tell user we have write error
	JMP	HANGUP			;and abort the program
20$:	MOVB	CHRSAV,R0		;Restore character to R0
	RTS	PC
;*****************************************************
;PAUSE ROUTINE
PAUSE:	MOV	R0,-(SP)		;Save R0
2$:	TST	PSFLG			;Ok to resume sending?
	BEQ	6$			;Yes
	JSR	PC,PRINT		;Check remote echo
	JSR	PC,TTYIN		;Keyboard input
	BCS	2$			;No, skip
	BICB	#200,R0			;Strip parity
	CMPB	R0,#CTRLC		;Control-C ??
	BNE	4$			
	.PRINT	#MSG25			;yes, so tell us
	JMP	HANGUP			;and hangup
4$:	CMPB	R0,#CTRLQ		;Control Q?
	BNE	2$			;No, wait some more
6$:	CLR	PSFLG			;yes, so clear flag
	MOV	(SP)+,R0		;Restore R0
	RTS	PC
;*****************************************************
;PRINT REMOTE INPUTS AND TRANSMISSION ECHOS
PRINT:	JSR	PC,REMOTE		;Character to print?
	BCC	2$			;Yes, process
	RTS	PC			;Else return
2$:	MOV	#1500.,SLPCNT		;First reset sleep counter
	BICB	#200,R0			;Strip parity
	JSR	PC,LCOPT		;Check if LC ok
	BIT	#EXEFLG,CSSTAT		;protocol mode enabled?
	BEQ	PRINT1			;no, skip this
4$:	CMPB	R0,#ESC			;escape sequence starting?
	BNE	PRINT1			;No, continue processing
	BIS	#ESCFLG,CSSTAT		;Set escape sequence flag
	RTS	PC			;and return
PRINT1:	MOVB	R0,SAVCHR		;Save character
	TST	SIFLG			;Have we blocked Executive mode
	BNE	2$			;Yes, so allow ^N to go to terminal
	CMPB	R0,#SO			;No, so if this is a ^N
	BEQ	4$			;Skip the output to terminal
2$:	.TTYOUT				;Print it
4$:	TST	RXFLG			;Receiver file active ?
	BEQ	14$			;No, skip
	CMPB	R0,#DEL			;Delete ?
	BEQ	14$			;Yes, skip
	CMPB	R0,#LF			;Line feed?
	BNE	8$			;No, skip
	TST	TGFLG			;Is file toggle on or off?
	BEQ	6$			;Toggle on
	MOVB	#'*,R0			;Tell user filesave is off
	.TTYOUT
	BR	14$
6$:	MOV	#':,R0			;Filesave is on
	.TTYOUT
8$:	TST	TGFLG			;Filesave on?
	BNE	14$			;No, skip this
	MOVB	SAVCHR,@INPNT		;Move char to in buffer
	INC	INPNT			;Advance pointer
	DEC	INCHR			;Block full?
	BNE	14$			;No, skip
	MOV	#BUFB,R1		;Yes, write a block
	MOV	INBLK,R3
	.WRITW	#RAREA,#INCHN,R1,#256.,R3
	BCC	10$			;Error?
	JMP	RXFATL			;Yes, fatal error
10$:	INC	INBLK			;Reset pointers
	CMP	INBLK,MAXBLK		;Is this the last block?
	BLT	12$			;No keep going
	JSR	PC,FCLOSE		;Yes, force file closed
	BR	14$
12$:	MOV	#512.,INCHR
	MOV	#BUFB,INPNT
14$:	TST	LPFLG			;Line printer active?
	BEQ	18$			;No, skip
	MOVB	savchr,@LPPNT		;Move char into buffer
	INC	LPPNT			;Bump pointer
	DEC	LPCHR			;Block full?
	BNE	18$			;No, skip
	MOV	#BUFD,R1		;Yes, write a block
	MOV	LPBLK,R3
	.WRITW	#LPAREA,#LPCHN,R1,#256.,R3
	BCC	16$			;Error?
	JMP	LPFATL			;Yes, fatal error
16$:	INC	LPBLK
	MOV	#512.,LPCHR		;Reset pointers
	MOV	#BUFD,LPPNT
18$:	RTS	PC			;Return
;*****************************************************
;PRINTER ENABLE
LPOPN:	.WAIT	#LPCHN			;Channel active?
	BCS	2$			;No, channel available
	.PRINT	#MSG6			;Already open, skip
	BR	8$
2$:	MOV	FREE,R1
	.FETCH	R1,#LPNAME		;Get LP handler
	BCC	4$
	.PRINT	#MSG1			;Error, tell user
	RTS	PC			;And exit
4$:	MOV	R0,FREE			;Update free area
	.ENTER	#LPAREA,#LPCHN,#LPNAME	;Open line printer channel
	BCC	6$			;Error?
	.PRINT	#MSG2
	BR	8$
6$:	MOV	#BUFD,LPPNT		;Buffer pointer
	CLR	LPBLK			;Block count
	MOV	#512.,LPCHR		;Character count
	INC	LPFLG
	.PRINT	#MSGF			;Tell user printer is now on
8$:	RTS	PC
;*****************************************************
;CLOSE LINE PRINTER CHANNEL
LPCLS:	TST	LPFLG			;LP active?
	BNE	2$			;Yes, can close
	.PRINT	#MSG7			;No, not active
	BR	6$
2$:	CLRB	@LPPNT			;Pad with nulls
	INC	LPPNT
	DEC	LPCHR
	BNE	2$
	MOV	#BUFD,R1		;Write last block
	MOV	LPBLK,R3
	.WRITW	#LPAREA,#LPCHN,R1,#256.,R3
	BCC	4$
	.PRINT	#MSG5
4$:	.CLOSE	#LPCHN
	.PRINT	#MSGG			;Print message
	CLR	LPFLG
6$:	RTS	PC
;*****************************************************
;ROUTINE TO GET FILESPEC
FILSPC:	MOV	#FBUFF,R4		;Set up buffer
2$:	JSR	PC,TTYIN		;Get keyboard input
	BCS	2$
	CMPB	R0,#DEL			;Delete character?
	BNE	4$
	CMPB	R4,#FBUFF		;No characters to delete?
	BEQ	2$
	DEC	R4			;Else back up buffer
	MOV	#BS,R0			;Backspace cursor
	.TTYOUT
	MOV	#40,R0			;and delete character
	.TTYOUT
	MOV	#BS,R0
	.TTYOUT
	BR	2$
4$:	CMPB	R0,#LF			;A line feed?
	BEQ	2$			;Ignore it
	CMPB	#BS,R0			;Backspace?
	BEQ	2$			;Ignore backspaces
	.TTYOUT				;Else echo it
	CMPB	R0,#CR			;A CR?
	BEQ	6$			;Yes, finish
	CMP	R4,#FBUFF+80.		;End of buffer?
	BHI	2$			;Yes, wait for lf
	MOVB	R0,(R4)+		;Else store character
	BR	2$
6$:	JSR	PC,CRLF			;Send CR/LF for formatting
	CMPB	R4,#FBUFF		;Nothing entered?
	BEQ	8$			;Yes, error
	MOVB	#'=,(R4)+		;Finish filespec for CSI
	CLRB	(R4)			;
	MOV	#FBUFF,R4		;Reset buffer address
	MOV	SP,R5			;Save stack pointer
	.CSISPC	#OUTSP,#DEXT,R4		;CSI in special mode
	MOV	R5,SP			;Restore stack
	BCC	10$			;Branch if no error
8$:	.PRINT	#MSG9			;Yes, inform user
	BR	12$
10$:	TST	(PC)+			;Clear error flag
12$:	SEC				;Set error flag
	RTS	PC			;Return
;*****************************************************
PHONE:	.SPFUN	#HDFUN,#HDCHAN,TST$CA,#SPFBUF
					;Test to see if modem is in use
.IF NE TSXHAN
	TST	TSXFLG			;TSX+?
	BEQ	1$			;no, so skip code
	BIT	#2,SPFBUF		;test for carry bit
	BEQ	3$			;Not set, so try again
	BR	2$			;Carry bit SET so go on
.ENDC
1$:	BIT	#1,SPFLG		;Is carrier off or on?
	BEQ	3$			;OFF, TRY AGAIN	
2$:	.PRINT	#MSG24			;Yes, so tell us
	RTS	PC			;and start over
3$:	CLR	SIFLG			;In case last call was to DEC
	.PRINT	#MSG20			;Tell us we are dialing
	.PRINT	R2			; and to where
	MOV	TELNO,R1		;Send telephone number
	JSR	PC,SNDLIN		;to the remote
4$:	JSR	PC,GTCHAR		;and start looking for response
	BCS	14$			;Abort is error flag
.IF	EQ	MODTYP			; If DEC modem
	CMPB	R0,#'a			;look for 'answer' signal
	BEQ	8$			;and continue on
	CMPB	R0,#'d			; or 'disconnect' signal
	BEQ	14$			
	CMPB	R0,#'b			; or 'busy' signal
	BEQ	10$
	CMPB	R0,#'n			; or 'no answer'
	BEQ	12$
.IFF					;If Hayes Compatible
	CMPB	R0,#'1			;look for answer code
	BEQ	8$			;and continue
	CMPB	R0,#'3			;disconnect code
	BEQ	14$			;and hangup
.ENDC
	.SPFUN	#HDFUN,#HDCHAN,TST$CA,#SPFBUF
					;Test to see if modem is in use
.IF NE TSXHAN
	TST	TSXFLG			;TSX+?   
	BEQ	6$			;no, so skip code
	BIT	#2,SPFBUF		;test for carry bit
	BEQ	4$			;Not set, so try again
	BR	8$			;Carry bit SET so go on
.ENDC
6$:	BIT	#1,SPFLG		;Is carrier off or on?
	BEQ	4$			;OFF, TRY AGAIN
8$:	.TTYOUT
	.PRINT	#MSG22			;Tell us we are connected
	JSR	PC,@BGNLOG		;and start selected Log-on routine
	BR	16$			;then return
10$:	.PRINT	#MSG23			;"BUSY"
	BR	14$
12$:	.PRINT	#MSG21			;"NO ANSWER"
14$:	.PRINT	#MSG19			;let us know
.IF EQ MODTYP							     
	MOVB	#2,R0			;RESET DEC MODEM WITH CTRL-B 
	JSR	PC,SEND						     
.ENDC								     
16$:	RTS	PC			;and return 
;------------------------------------
; Log on sequence for Compuserve Node
LOGIN1:	.TWAIT	#TWAREA,#TIME1		;Wait for net to allow input
2$:	CLR	BCOUNT			;Clear input character count
	MOVB	#CTRLC,R0
	JSR	PC,SEND			;Send CTRL C to wake up net
	JSR	PC,GTCHAR		;Look for response
	BCS	10$			;is this a CTRL-c ABORT
	TST 	CHRFLG			;or no response so try again
	BNE	2$		
	.TTYOUT				;Echo the character
	JSR	PC,LCCVT		;Convert to UC
	CMPB	R0,#'D			;Look for "D" in "User ID"
	BEQ	6$
4$:	JSR	PC,GTCHAR		;Get next character
	BCS	10$			;Abort if CTRL C was input
	TST	CHRFLG			;else, check for input
	BNE	4$			;no, so try again
	.TTYOUT				;else print the character
	CMPB	R0,#'D			;'D' in User ID ?
	BNE	4$			;No, must be error
6$:	JSR	PC,GTCHAR		;Get next character
	BCS	10$			;Is it a CTRL C.. then abort
	tst	CHRFLG			;or is there another character
	BNE	6$			;no so look again
	.TTYOUT				;then print the character
	CMPB	R0,#':			;If not a colon, it
	BNE	2$			;Must be an error try again
	JSR	PC,SNDLIN		;send next part of string
8$:	JSR	PC,GTCHAR		;Check response
	BCS	10$			;Abort if flag set
	TST	CHRFLG
	BNE	8$
	.TTYOUT				;Display it
	CMPB	R0,#':			;Prompt character?
	BNE	8$			;No, check again
	JSR	PC,SNDLIN		;Send last part of message
	.PRINT	#ALERT			;Tell operator we are on
	RTS	PC
10$:	.PRINT	#MSG19			;Login Aborted
	RTS	PC			;And return
;*****************************************************
; Log on Knowledge Index via Telenet
LOGIN2:	.TWAIT	#TWAREA,#TIME1		;wait for Telenet to accept input
2$:	MOVB	#'@,R0			;2400 baud requires '@'<CR> to
	JSR	PC,SEND			;wake up the net
	.TWAIT	#TWAREA,#TIME2		;give it time to digest input
	MOVB	#CR,R0			;send the CR
	JSR	PC,SEND
	.TWAIT	#TWAREA,#TIME2		;needs more digestion time
	JSR	PC,GTCHAR		;then look for response
	BCS	14$			;and we are rolling.....
	TST 	CHRFLG			;with same logic as in Login1 above
	bne	2$		
	.TTYOUT
4$:	JSR	PC,GTCHAR
	BCS	14$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#'=
	BNE	4$
	JSR	PC,SNDLIN
6$:	JSR	PC,GTCHAR
	BCS	14$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#'@
	BNE	6$
	JSR	PC,SNDLIN
8$:	JSR	PC,GTCHAR
	BCS	14$
	.TTYOUT
	CMPB	R0,#'?
	BNE	8$
	JSR	PC,SNDLIN
10$:	JSR	PC,GTCHAR
	BCS	14$
	.TTYOUT
	CMPB	R0,#'?
	BNE	10$
12$:	JSR	PC,SNDLIN
	.PRINT	#ALERT
	RTS	PC
14$:	.PRINT	#MSG19
	RTS	PC
;*****************************************************
; Log on to Compuserve via Telenet
LOGIN3:	.TWAIT	#TWAREA,#TIME1
2$:	MOVB	#'@,R0
	JSR	PC,SEND
	.TWAIT	#TWAREA,#TIME2
	MOVB	#CR,R0
	JSR	PC,SEND
	.TWAIT	#TWAREA,#TIME2
	JSR	PC,GTCHAR
	BCS	14$
	TST 	CHRFLG
	BNE	2$		
	.TTYOUT
4$:	JSR	PC,GTCHAR
	BCS	14$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#'=
	BNE	4$
	JSR	PC,SNDLIN
6$:	JSR	PC,GTCHAR
	BCS	14$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#'@
	BNE	6$
	JSR	PC,SNDLIN
8$:	JSR	PC,GTCHAR
	BCS	14$
	.TTYOUT
	CMPB	R0,#':
	BNE	8$
	JSR	PC,SNDLIN
10$:	JSR	PC,GTCHAR
	BCS	14$
	.TTYOUT
	CMPB	R0,#':
	BNE	10$
12$:	JSR	PC,SNDLIN
	.PRINT	#ALERT
	RTS	PC
14$:	.PRINT	#MSG19
	RTS	PC
;*****************************************************
; Log on to the Source via Telenet
LOGIN4:	.TWAIT	#TWAREA,#TIME1
10$:	MOVB	#'@,R0
	JSR	PC,SEND
	.TWAIT	#TWAREA,#TIME2
	MOVB	#CR,R0
	JSR	PC,SEND
	.TWAIT	#TWAREA,#TIME2
	JSR	PC,GTCHAR
	BCS	24$
	tST 	CHRFLG
	bne	10$
	.TTYOUT
14$:	JSR	PC,GTCHAR
	BCS	24$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#'=
	BNE	14$
	JSR	PC,SNDLIN
16$:	JSR	PC,GTCHAR
	BCS	24$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#'@
	BNE	16$
	JSR	PC,SNDLIN
18$:	JSR	PC,GTCHAR
	BCS	24$
	.TTYOUT
	CMPB	R0,#'>
	BNE	18$
	JSR	PC,SNDLIN
20$:	JSR	PC,GTCHAR
	BCS	24$
	.TTYOUT
	CMPB	R0,#'?
	BNE	20$
22$:	JSR	PC,SNDLIN
	.PRINT	#ALERT
	RTS	PC
24$:	.PRINT	#MSG19
	RTS	PC
;******************************************************
; Log on to the DEC Order Line
LOGIN5:	INC	SIFLG
	.PRINT	#DECMSG
	RTS	PC
;*****************************************************
; log on to Compuserve via Tymnet
LOGIN6:
10$:	.TWAIT	#TWAREA,#TIME3
	MOVB	#'A,R0
	JSR	PC,SEND
	JSR	PC,GTCHAR
	BCS	18$
	TST	CHRFLG
	BNE	10$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#'N
	BEQ	14$
12$:	JSR	PC,GTCHAR
	BCS	18$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#'N
	BNE	12$
13$:	JSR	PC,GTCHAR
	BCS	18$
	.TTYOUT
	JSR	PC,LCCVT
	CMPB	R0,#':
	BNE	12$
	JSR	PC,SNDLIN
14$:	JSR	PC,GTCHAR
	BCS	18$
	.TTYOUT
	CMPB	R0,#'W
	BNE	14$
15$:	JSR	PC,GTCHAR
	BCS	18$
	.TTYOUT
	CMPB	R0,#':
	BNE	15$
	JSR	PC,SNDLIN
16$:	JSR	PC,GTCHAR
	BCS	18$
	.TTYOUT
	CMPB	R0,#':
	BNE	16$
	JSR	PC,SNDLIN
	.PRINT	#ALERT
	RTS	PC
18$:	.PRINT	#MSG19
	RTS	PC
;**********************************************************
;Routine to get a character and check for CNTRL-C abort
GTCHAR:	JSR	PC,TTYIN		;Check keyboard first
	BCS	2$			;Character NOT available
	CMPB	R0,#CTRLC		;A CNTRL-C?
	BEQ	8$			;Yes, set abort flag
2$:	CLR	CHRFLG			;Clear the Character flag
	JSR	PC,REMOTE		;Anything from remote?
	BCS	4$
	BICB	#200,R0			;Clear parity
	BR	6$
4$:	INC 	CHRFLG			;No char-- set flag
6$:	TST	(PC)+			;Else clear carry
8$:	SEC				;Set carry flag (abort)
	RTS	PC			;And return
;*****************************************************
;GET A KEYBOARD CHARACTER
TTYIN:	TST	TSXFLG			;Check for TSX system
	BNE	6$			;Skip if TSX
	TST	KCOUNT			;Check input ring buffer
	BNE	2$			;Yes, go get it
	SEC				;else,Set carry flag
	RTS	PC			;And return
2$:	MOV	#1500.,SLPCNT		;First reset sleep counter
	MOVB	@KADDR2,R0		;Get the character
	INC	KADDR2			;Advance character adr pntr
	DEC	KCOUNT			;Dec active character count
	DEC	KCNT2			;Dec proc character count
	BNE	8$			;End of buffer?
	MOV	#BUFE,KADDR2		;Yes, reset pointers
	MOV	#KBFSIZ,KCNT2		;
4$:	BR	8$
6$:	.TTINR				;Get a character for TSX+
	BCS	8$			;Return with carry set if nothing
	MOV	#1500.,SLPCNT		;Else reset sleep counter
8$:	RTS	PC
;*****************************************************
;Routine to send a line to the remote
SNDLIN:	TSTB	(R1)			;End of message?
	BEQ	2$			;Yes, terminate
	MOVB	(R1)+,R0
	JSR	PC,SEND			;Send the message
	BR	SNDLIN
2$:	TSTB	(R1)+			;bump R1
	MOVB	#CR,R0			;Send a CR
	JSR	PC,SEND
	RTS	PC
;*****************************************************
;Routine to get a character from remote
REMOTE: 
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ??
	BNE	1$			;yes, continue
	JMP	REMOT1			;or else, skip all
1$:	TST	BCOUNT			;Any residual char in buffer?
	BNE	6$			;Yes, then process
	MOV	#BUFA,ADDR2		;No, reset pointers
	MOV	#BUFSIZ,CNT2		;reset counter
	.SPFUN	#HDFUN,#HDCHAN,BYT$IN,#INRING	;Bytes in in-bufferf??
	BCC	2$			;Error??
	.PRINT	#MSG14			;yes, so tell us
	JMP	EXIT1			;and abort the program
2$:	TST	INRING			;Anything in ring buffer?
	BEQ	14$			;No, return with carry set
	.SPFUN	#HDFUN,#HDCHAN,BYT$RE,#bufa,inring
					;yes, move characters to BUFA
	BCC	4$
	.PRINT	#MSG14
	JMP	EXIT1			;and abort the program
4$:	MOV	INRING,BCOUNT		;active character count to BCOUNT
6$:	MOVB	@ADDR2,R0		;mov character to r0
	MOVB	R0,STOCHR		;and store it in TEMP
	INC	ADDR2			;Advance proc adr pointer
	DEC	BCOUNT			;Dec active character count
	BICB	#200,R0			;strip parity
	BIT	#EXEFLG,CSSTAT		;protocol mode enabled?
	BNE	12$			;yes, skip checks
	CMPB	R0,#SI			;No, so check for SI
	BNE	8$			;No  SI, so continue on
	TST	SIFLG			;SI present, do we want protocol
	BNE	8$			;no, so skip protocol setup
	BIS	#EXEFLG,CSSTAT		;yes, so set EXEFLG
	CLR	R0			;clear R0 and 
	TST	TSXFLG			;TSX+ ??
	BEQ	14$			;No, so set carry and return
	MOV	#BIN$IN,RSET		;yes, so 
	.SPFUN	#HDFUN,#HDCHAN,RD$ON,#RSET	;set BININ for CL handler
	BCC	14$			;any error?
	.PRINT	#MSG14			;tell us
	JMP	EXIT1			;and abort the program
	br	14$			;set carry and return
8$:	CMPB	R0,#CTRLS		;check for Control-S
	BNE	10$			;No so continue on
	INC	PSFLG			;Yes, so increment Pause Flag
	CLR	R0			;then clear R0
	BR	14$			;and Return with Carry Set
10$:	CMPB	R0,#CTRLQ		;test for Control-Q
	BNE	12$			;no so continue
	CLR	PSFLG			;yes, so clear Pause Flag
	CLR	R0			;clear R0
	BR	14$			;and return with carry set
12$:	MOVB	STOCHR,R0		;move saved character to R0
	TST	(PC)+			;Clear carry and return
14$:	SEC				;Else set carry
	RTS	PC
.ENDC
;------------------------------------------
REMOT1:	TST	BCOUNT			;Anything in ring buffer?
	BEQ	6$			;No, return with carry set
2$:	MOVB	@ADDR2,R0		;Else get character
	INC	ADDR2			;Advance proc adr pointer
	DEC	BCOUNT			;Dec active character count
	DEC	CNT2			;Dec proc character count
	BNE	4$			;End of buffer?
	MOV	#BUFA,ADDR2		;Yes, reset pointers
	MOV	#BUFSIZ,CNT2
4$:	TST	(PC)+			;Clear carry
6$:	SEC				;Else set carry
	RTS	PC
;*****************************************************
;Toggle flags
TOGFIL:	TST	RXFLG			;Is file open now?
	BEQ	2$			;No, skip
TOGGLE=.
	COM	(R2)			;Toggle the flag
2$:	RTS	PC			;And return
;*****************************************************
HELP:	.PRINT	#HLPMSG			;Print the help message
	.PRINT	#MSGLG1
	.PRINT	#MSGLG2
	.PRINT	#MSGLG3
	.PRINT	#MSGLG4
	.PRINT	#MSGLG5
	.PRINT	#MSGLG6
	RTS	PC			;and return
;*****************************************************
;Lower case/upper case conversion
LCOPT:	TST	LCFLG			;Option enabled?
	BEQ	LCRET			;No, leave alone
LCCVT:	CMPB	R0,#140			;Check to see if these are LC
	BLOS	LCRET
	CMPB	R0,#173			
	BHIS	LCRET
	SUB	#40,R0			;Convert LC to UC
LCRET:	RTS	PC			;and return
;*****************************************************
;Routine to send CR/LF to console terminal
CRLF:	MOV	R0,-(SP)		;Save register 0
	MOVB	#CR,R0			;Send CR
	.TTYOUT
	MOVB	#LF,R0			;Send LF
	.TTYOUT
	MOV	(SP)+,R0		;Restore register 0
	RTS	PC
;*****************************************************
;CONSOLE INTERRUPT SERVICE ROUTINE
TTYINT:	MOVB	@#KBUF,@KADDR		;Mov char into ring buffer
	BICB	#200,@KADDR		;Get rid of parity
	INC	KCOUNT			;Inc char count
	INC	KADDR			;Advance keyboard address ptr
	DEC	KCNT			;Dec ring buffer char cnt
	BNE	2$			;End of buffer?
	MOV	#BUFE,KADDR		;Yes, reset pointers
	MOV	#KBFSIZ,KCNT
2$:	RTI
;******************************************************
;Receiver file Fatal I/O
RXFATL:	.PURGE	#INCHN			;Dump receiver channel
	.PRINT	#MSG5			;Tell user
	CLR	RXFLG			;Clear RX file flag
	CLR	TGFLG			;Clear toggle
	RTS	PC
;******************************************************
;Line printer fatal I/O
LPFATL:	.PURGE	#LPCHN			;Dump LP channel
	.PRINT	#MSG5			;Tell user
	CLR	LPFLG			;Clear LP flag
	RTS	PC
;******************************************************
;TERMINATE PROGRAM HERE
HANGUP:	.SPFUN	#HDFUN,#HDCHAN,TST$CA,#SPFBUF
					;See if modem carrier is still there
	BCC	2$			;Error?
	.PRINT	#MSG14			;Yes, tell user
	BR	8$			;and attempt to shut down program

2$:	
.IF NE TSXHAN
	TST	TSXFLG			;TSX+ ??
	BEQ	4$			;No, skip this
	BIT	#2,SPFBUF		;Is carrier off or on?
	BEQ	8$			;It's off, proceed with shutdown
	.PRINT	#MSG16			;Else it's on, give user a choice
	BR	6$
.ENDC
4$:	BIT	#1,SPFLG		;Is carrier off or on?
	BEQ	8$			;It's off, proceed with shutdown
	.PRINT	#MSG16			;Else it's on, give user a choice
6$:	JSR	PC,TTYIN		;Get user response
	BCS	6$
	JSR	PC,CRLF			;Send a CR/LF
	JSR	PC,LCCVT		;Make it upper case
	CMPB	R0,#'Y			;Confirm hangup?
	BEQ	8$			;Yes
	JMP	READY			;Else go back to program
8$:
.IF NE TSXHAN
	TST	TSXFLG			;TSX?
	BEQ	10$			;No,so skip this
	CLR	TSXLIN			;SET CL EMT line to '0'
	MOV	#CLASIG,R0		;and disconnect CL from TT line
	EMT	375
	BCC	EXIT1			;Branch if no error
	.PRINT 	#MSG14			;Tell the user we failed
	BR	EXIT1			;and try to close the channel
.ENDC
10$:	.SPFUN	#HDFUN,#HDCHAN,RD$OF	;Turn reader off and drop DTR
	BCC	EXIT1			;Branch if no error
	.PRINT 	#MSG14			;Tell the user we failed
	BR	EXIT1			;and try to close the channel
EXIT:	TST	TSXFLG			;TSX system?
	BEQ	2$			;No, RT-11...this command OK
	.PRINT	#MSG17			;Under TSX+ this command is illegal
	JMP	READY
2$:	.SPFUN	#HDFUN,#HDCHAN,IN$OFF	;Turn off interrupts only
	BCC	EXIT1			;Branch if no error
	.PRINT	#MSG14			;Tell user we failed
	JMP	READY			;and return to main loop
EXIT1:	.CLOSE	#HDCHAN			;Close modem channel
	TST	RXFLG			;Receiver file active?
	BEQ	2$			;No, skip
	JSR	PC,CLOSE		;Else force it closed
2$:	TST	LPFLG			;LP active?
	BEQ	FATAL			;No, skip
	JSR	PC,LPCLS		;Yes, force it closed
FATAL:	TST	TSXFLG			;TSX system?
	BNE	2$			;Yes, skip this
	MOV	SAVE1,@#KVEC		;Restore RT-11 vectors
2$:	.EXIT				;and exit to monitor
;*****************************************************
GOBAUD:	MOVB	#NEWSPD,R0		;BAUD SELECTION TO RO
	ADD	#60,R0			;Convert to Ascii char
	BR	STBAUD			;then process
GTBAUD:	.PRINT	#PROMPT			;Ask user for baud rate
2$:	JSR	PC,TTYIN		;Get response
	BCS	2$
	.TTYOUT				;Echo character
	JSR	PC,CRLF			;Send CR/LF for formatting
STBAUD:	CMPB	R0,#'0			;300 Baud?
	BEQ	SLOW			;Yes, set for 300
	CMPB	R0,#'1			;600 Baud?
	BEQ	MEDIUM			;Yes, set for 600
	CMPB	R0,#'2			;1200 Baud?
	BEQ	FAST			;Yes, set up for 1200
	CMPB	R0,#'3			;2400 BAUD?
	BEQ	VFAST			;YES, SET UP FOR 2400
	MOV	#7,R0			;Error, ring bell
	.TTYOUT
	BR	GTBAUD			;and try again
SLOW:	.PRINT	#MSGB30			;Tell us new baud rate - 300
	MOV	#B$LOW,RATE		;and set it
	BR	SET
MEDIUM:	.PRINT	#MSGB60			;600
	MOV	#B$MED,RATE
	BR	SET
FAST:	.PRINT	#MSGB12			;1200
	MOV	#B$FST,RATE
	BR	SET
VFAST:	.PRINT	#MSGB24			;2400
	MOV	#V$FST,RATE
SET:	
.IF NE TSXHAN
	TST	TSXFLG			;TSX+  ?
	BEQ	1$			;No,so set up baud code
	BR	2$			;yes, so go direct to Spfun
.ENDC
1$:	SEC				;SET CAR
	ROL	RATE			;Then rotate left 4 time
	ROL	RATE			;which converts the
	ROL	RATE			;baud code to a low byte
	ROL	RATE			;code compatible with MO handler
2$:	.SPFUN	#HDFUN,#HDCHAN,BA$UD,#RATE
					;SET BAUD RATE
	BCC	3$
	.PRINT	#MSG14
	JMP	exit1
3$:	RTS	PC
;*****************************************************
PROCED:
.IF NE TSXHAN
	.SPFUN	#HDFUN,#HDCHAN,CLR$CL	;Send CTRLQ to remote (CL)
.IFF
	MOV	#CTRLQ,R0		;SEND CTRLQ TO REMOTE (MO)
	JSR	PC,SEND
.ENDC
	RTS	PC
;*****************************************************
;Dispatch table for EXEC commands
DSPTBL:	.WORD	'B,STBAUD,0,0,0		;B - Set baud rate
	.WORD	'C,TOGGLE,0,0,LCFLG	;C - Upper/lower case toggle
	.WORD	'D,CLOSE,0,0,0		;D - Close receiver file
	.WORD	'E,TOGGLE,0,0,DUPFLG	;E - Toggle full/half duplex
	.WORD	'G,TOGGLE,0,0,SIFLG	;G - PREVENT PROTOCOL MODE
	.WORD	'H,HELP,0,0,0		;H - Print help message
	.WORD	'K,BREAK,0,0,0		;K - Transmit a break to remote
	.WORD	'L,TOGGLE,0,0,LFFLG	;L - Toggle trans of LF to remote
	.WORD	'O,EXIT,0,0,0		;O - Exit without disconnect
	.WORD	'P,LPOPN,0,0,0		;P - Open line printer channel
	.WORD	'Q,PROCED,0,0,0		;Q - Sends CTRL-Q to remote
	.WORD	'R,OPEN,0,0,0		;R - Open receiver file
	.WORD	'T,TRANS,0,0,0		;T - Transmit a file
	.WORD	'W,TOGFIL,0,0,TGFLG	;W - Toggle receiver file capture
	.WORD	'Z,LPCLS,0,0,0		;Z - Close line printer channel
	.WORD	'1,PHONE,LOGIN1,CISLOG,MSGLG1	;1 - LOGIN TO COMPUSERVE
	.WORD	'2,PHONE,LOGIN2,KILOG,MSGLG2	;2 - LOGIN TO KNOWLEDGE INDEX
	.WORD	'3,PHONE,LOGIN3,TNTLOG,MSGLG3	;3 - LOGIN TO TELNET(CIS)
	.WORD	'4,PHONE,LOGIN4,SOURCE,MSGLG4	;4 - LOGIN TO THE SOURCE
	.WORD	'5,PHONE,LOGIN5,DECLOG,MSGLG5	;5 - LOGIN TO DEC DEMO
	.WORD	'6,PHONE,LOGIN6,TYMLOG,MSGLG6	;6 - LOGIN TO DEC DEMO
	.WORD	ESC,HANGUP,0,0,0	;ESC-Exit and disconnect
	.WORD	DEL,TOGGLE,0,0,DELFLG	;DEL-Delete conversion toggle
	.WORD	CMDKEY,SEND,0,0,0	;Send the Command Key
	.WORD	-1			;End of table
;*****************************************************
; SPECIAL FUNCTION TABLE TO LOAD VALUES DEPENDING ON HANDLER
;----------------------------------------------------------
;             |  NAME, CL, MO		 .SPFUN Code for
;		----- --------
SPFTBL:	.WORD	BA$UD,256,373		;Baud rate
	.WORD	WRT$Q,204,374		;Get Handler Status
	.WORD	RD$ON,250,377		;Turn read on, set DTR,TURN .SPFUN on
	.WORD	RD$OF,205,376		;Turn Read off, drop DTR
	.WORD	BR$K,202,372		;send break to remote
	.WORD	IN$OFF,0,375		;TURN READ OFF, LEAVE DTR ALONE
	.WORD	TST$CA,255,371		;TEST FOR MODEM CARRIER
	.WORD	BYT$IN,261,0		;Test for input characters pending
	.WORD	BYT$RE,203,0		;Get input bytes pending
	.WORD	CLR$CL,201,0		;TRANSMIT XON TO CL DEVICE
	.WORD	BYT$OU,262,0		;Test for output characters pending
	.WORD	BYT$SN,263,0		;Send output bytes pending
	.WORD	RDO$FF,251,0		;Turn off .SPFUN for CL line
	.WORD	RE$SET,265,0		;RESET CL HANDLER
	.WORD	-1			;End of the table
;___________________________________________________________
;	.SPFUN CODE STORAGE AREA
;
BA$UD:	.WORD	0
WRT$Q:	.WORD	0
RD$ON:	.WORD	0
RD$OF:	.WORD	0
BR$K:	.WORD	0
IN$OFF:	.WORD	0
TST$CA:	.WORD	0
BYT$IN:	.WORD	0
CLR$CL:	.WORD	0
BYT$RE:	.WORD	0
BYT$OU:	.WORD	0
BYT$SN:	.WORD	0
RDO$FF:	.WORD	0
RE$SET:	.WORD	0
	.even
;
;---------------------------------------------------------------
TSX:	.BYTE	0,110			;EMT to check if TSX is running
LOCK:	.BYTE	7,140			;TSX+ EMT to lock program in memory
SAVE1:	.BLKW	1			;Area to save RT-11 KB addr
RATE:	.WORD	0			;Baud rate storage

KADDR:	.WORD	0			;Keyboard ring buffer adr ptr
KCOUNT:	.WORD	0			;Keyboard active char count
KCNT:	.WORD	0			;Keyboard ring buffer char count
KADDR2:	.WORD	0			;Keyboard process adr ptr
KCNT2:	.WORD	0			;Keyboard process char count

MOAREA:	.BLKW	3			;EMT area for MO .LOOKUP
MAREA:	.BLKW	5			;EMT area for MO .WRITW
MOSP:	.RAD50	/MO /			;Modem handler device name

CLASIG:	.BYTE	0,155			;EMT To assign CL Unit
	.WORD	CLUNIT			;CL unit Number
TSXLIN:	.WORD	0			;Modem Line Number
CLAREA:	.BLKW	3			;EMT area for CL .Lookup
HDFUN:	.BLKW	6			;EMT AREA FOR .SPFUN

.IF LE CLUNIT-7 			;If CL unit is 0 thru 7	
CU	= 14				;2nd RAD50 Char is L
CLSP:	.RAD50	/C/<CU><36+CLUNIT>	;Modem handler device name
.IFF					;if CL unit is 10 thru 17
CU	= 37				;2nd RAD50 Char is 1
CLSP:	.RAD50	/C/<CU><26+CLUNIT>	;Modem handler device name
.ENDC

TGFLG:	.WORD	0			;Receiver file toggle
RXFLG:	.WORD	0			;Receiver file status
LPFLG:	.WORD	0			;Line printer file status
LCFLG:	.WORD	0			;Lower case toggle flag
DELFLG:	.WORD	-1			;Delete toggle flag (set on)
DUPFLG:	.WORD	0			;Half/full duplex flag
CHRFLG:	.WORD	0			;GET CHARACTER FLAG
LFFLG:	.WORD	-1			;LF toggle (set on, do not transmit)
WRTFLG:	.WORD	0			;Write status flag
TSXFLG:	.WORD	0			;TSX flag (assume RT-11)
ERRFLG:	.WORD	0			;Error flag
CMDFLG:	.WORD	0			;Command sequence flag

UPBLK:	.WORD	0			;Block number
RECHST:	.WORD	0			;Record number from host
CKSUM:	.WORD	0			;Checksum
RECNBR:	.WORD	0			;Record number
MSGLEN:	.WORD	0			;Message length
CSMAX:	.WORD	0			;Maximum # blocks for download file

LPNAME:	.RAD50	"LP "			;Line printer
LPAREA:	.BLKW	5			;EMT area for LP
LPPNT:	.WORD	0			;Pointer
LPBLK:	.WORD	0			;Block count
LPCHR:	.WORD	0			;Character count

CSAREA:	.BLKW	5			;EMT area for CSEXEC transfers
CSPNT:	.WORD	0			;pointer
CSBLK:	.WORD	0			;Block count
CSCHR:	.WORD	0			;Character count

TAREA:	.BLKW	5			;EMT area for file transmit

TWAREA:	.BLKW	2			;EMT area for timed wait
TIME:	.WORD	0,15.*1.		;Sleep for 1/4 second
TIME1:	.WORD	0,60.*12.		;Sleep 12 seconds
TIME2:	.WORD	0,12.*2.		;Sleep .4 seconds
TIME3:	.WORD	0,30.*1			;sleep .5 seconds
SLPCNT:	.WORD	0			;Sleep counter
RAREA:	.BLKW	5			;EMT area for receiver channel
INPNT:	.WORD	0			;Receive buffer pointer
INBLK:	.WORD	0			;Receive block count
INCHR:	.WORD	0			;Receive char count

STOCHR:	.WORD	0			;Temporary character storage - remote
SAVCHR:	.WORD	0			;Temporary character storage - print
CHRSAV:	.WORD	0			;Temporary character storage - send
MAXBLK:	.WORD	0			;Receiver file size
BGNLOG:	.WORD	0			;Login Routine 
TELNO:	.WORD	0			;Telephone number
DEXT:	.WORD	0			;Default file types for .CSIGEN
	.RAD50	"NET"			;Use .net for default
	.WORD	0,0
;
OUTSP:	.BLKW	39.			;CSI file descriptors
;
MSGA:	.ASCII	<CR><LF>"EXECCL - Version 1.2  14-JUL-87"
	.ASCIZ	<CR><LF>"Use <"<SHOKEY>"> H  for help"<CR><LF>
MSGB:	.ASCIZ	<CR><LF>"EXECCL-I-Receiver file closed"
MSGC:	.ASCIZ	<CR><LF><BELL>"EXECCL-I-File transmitted"
MSGD:	.ASCIZ	<CR><LF>"EXECCL-I-Transmitting file"
MSGE:	.ASCIZ	<CR><LF>"EXECCL-I-Receiver file opened"
MSGF:	.ASCIZ	<CR><LF>"EXECCL-I-Printer on"
MSGG:	.ASCIZ	<CR><LF>"EXECCL-I-Printer off"
MSGH:	.ASCIZ	<CR><LF><BELL>"EXECCL-I-Transmission aborted"
MSGI:	.ASCII	<CR><LF><BELL>"EXECCL-W-File exists - <S>upercede, <R>e-enter, <A>bort:?"
	.BYTE	200
MSGJ:	.ASCIZ	<CR><LF>"EXECCL-I-File not opened"
MSGK:	.ASCIZ	<CR><LF><BELL>"EXECCL-P-Sending CSEXEC System ID to host"
MSGL:	.ASCIZ	<CR><LF>"EXECCL-P-Beginning download"
MSGM:	.ASCIZ	<CR><LF>"EXECCL-P-Beginning upload"
MSGN:	.ASCIZ	<CR><LF><BELL>"EXECCL-P-Aborting transfer"
MSGO:	.ASCIZ	<CR><LF>"EXECCL-P-Initializing file transfer"
MSGP:	.ASCIZ	<CR><LF><BELL>"EXECCL-P-Invalid data block/re-transmitting"
MSGQ:	.ASCII	<CR><LF><BELL>"EXECCL-P-File exists - <S>upercede or <A>bort:"
	.BYTE	200
MSGR:	.ASCIZ	<CR><LF><BELL>"EXECCL-E-Receiver file is full"
MSGS:	.ASCIZ	<CR><LF><BELL>"EXECCL-P-Download Completed"
MSGT:	.ASCIZ	<CR><LF><BELL>"EXECCL-P-Upload Completed"
;
MSG1:	.ASCIZ	<CR><LF><BELL>"EXECCL-E-Fetch error"
MSG2:	.ASCIZ	<CR><LF><BELL>"EXECCL-E-File open error"
MSG3:	.ASCIZ	<CR><LF><BELL>"EXECCL-E-Read error"
MSG5:	.ASCIZ	<CR><LF><BELL>"EXECCL-E-Write error"
MSG6:	.ASCIZ	<CR><LF>"EXECCL-I-Printer already on"
MSG7:	.ASCIZ	<CR><LF>"EXECCL-I-Printer already closed"
MSG8:	.ASCII	<CR><LF>"Enter receiver filespec: "
	.BYTE	200
MSG8A:	.ASCII	<CR><LF>"Enter transmit filespec: "
	.BYTE	200
MSG9:	.ASCIZ	<CR><LF><BELL>"EXECCL-E-Illegal filename"
MSG10:	.ASCIZ	<CR><LF><BELL>"EXECCL-E-File not found"
MSG11:	.ASCIZ	<CR><LF><BELL>"EXECCL-F-Modem line in use, cannot connect"
MSG12:	.ASCIZ	<CR><LF><BELL>"EXECCL-W-Receiver file full"
MSG12A:	.ASCII	<CR><LF><BELL>"Do you want to open another file?"
	.BYTE	200
MSG13:	.ASCIZ	<CR><LF><BELL>"EXECCL-F-Lookup failed on handler"
MSG14:	.ASCIZ	<CR><LF><BELL>"EXECCL-F-Modem special function failed"
MSG15:	.ASCIZ	<CR><LF><BELL>"EXECCL-F-Modem write error"
MSG16:	.ASCII	<CR><LF><BELL>"EXECCL-W-Modem carrier detected - Are you sure you want to hangup? (Y/N): "
	.BYTE	200
MSG17:	.ASCII	<CR><LF><BELL>"EXECCL-E-Illegal command under TSX+"<CR><LF>
	.ASCIZ	"Use <"<SHOKEY><SHOKE2><SHOKE3>"> ESC to disconnect"
MSG18:	.ASCIZ	<CR><LF><BELL>"EXECCL-F-Cannot lock job in memory"
MSG19:	.ASCIZ	<CR><LF><Bell>"EXECCL-W-Login Aborted"<LF><CR>
MSG20:	.ASCII	<CR><LF>"You are DIALING"<200>
MSG21:	.ASCIZ	<CR><CR><BELL>"EXECCL-I-No Answer, try again later"
MSG22:	.asciZ	<cr><Lf><BELL> "EXECCL-I-Carrier Detected - Logon Sequence in progress"
MSG23:	.ASCIZ	<CR><LF><BELL> "EXECCL-I-Line is Busy"
MSG24:	.ASCIZ	<CR><LF>"EXECCL-I- You are already logged on"
MSG25:	.ASCIZ	<CR><LF><BELL>"EXECCL-W-Control-C Intercepted"
PROMPT:	.ASCII	<CR><LF>"0=300  1=600  2=1200  3=2400"<CR><LF><LF>
	.ASCII	"Enter baud code: "<200>
MSGB30:	.ASCIZ	<CR><LF>"EXECCL-I-EXECCL is at 300 Baud"<CR><LF><LF>
MSGB60:	.ASCIZ	<CR><LF>"EXECCL-I-EXECCL is at 600 Baud"<CR><LF><LF>
MSGB12:	.ASCIZ	<CR><LF>"EXECCL-I-EXECCL is at 1200 Baud"<CR><LF><LF>
MSGB24:	.ASCIZ	<CR><LF>"EXECCL-I-EXECCL is at 2400 Baud"<CR><LF><LF>
KBSET:	.BYTE	35,123,35,125,35,104,25,35,104,17,35,104,23,35,104,21
	.BYTE	35,104,22,35,104,3,35,104,15,35,104,32,35,104,12
	.BYTE	200
OPNERR:	.ASCIZ	<CR><LF>"EXECCL-E-Receiver file already open"
CLSERR:	.ASCIZ	<CR><LF>"EXECCL-E-File already closed"
HLPMSG:	.ASCII	<CR><LF>"                 EXECCL Commands"
	.ASCII	<CR><LF><LF>"B - Alter baud rate          L - LF transmission on/off"
	.ASCII	<CR><LF>"C - Case toggle (UC/LC)      O - Exit EXECCL to RT-11"
	.ASCII	<CR><LF>"D - Close receiver file      P - Open printer channel"
	.ASCII	<CR><LF>"E - Toggle Half/Full Duplex  Q - Send CTRL-Q to remote"
	.ASCII	<CR><LF>"G - Toggle SI Flag Off/On    R - Open receiver file"
	.ASCII	<CR><LF>"H - Help; prints this list   T - Transmit file"
	.ASCII	<CR><LF>"K - Send 'BREAK' to remote   W - Toggle receiver file ON/OFF"
	.ASCII	<CR><LF>"DEL-Toggle Delete conversion Z - Close printer channel"
	.ASCII	<CR><LF>"           ESC-Exit EXECCL and hang up"
	.ASCII	<CR><LF><LF>"       Precede all commands with the <"<SHOKEY><SHOKE2><SHOKE3>"> key"<CR><LF>
	.ASCII	<CR><LF>/                   ************************/
	.ASCIZ	<CR><LF>/                   AUTO LOGON SELECTIONS/<CR><LF>
DECMSG:	.ASCII	<CR><LF><LF><BELL>/EXECCL-I-TEMPORARY MESSAGE/
	.ASCII	<CR><LF><LF>/ YOU ARE CONNECTED TO THE DEC LINE  /
	.ASCII	<CR><LF><LF>/                Full logon has not been implemented / 
	.ASCIZ	<CR><LF><LF><BELL>/             PLEASE HIT <CR> TWICE and log on manually!!/
SYSID:	.ASCIZ	"# DEC H11/LSI-11,CC,HC,PA,PL"
ALERT:	.ASCII	<CR><LF><BELL><BELL>"CONNECTED TO NETWORK"<BELL><200>
	.EVEN
;
; Do not change the sequence of the following 9 symbols
;
ADDR2:	.WORD	0			;Process adr ptr
CNT2:	.WORD	0			;Process char count
SPFBUF:	.WORD	0			;Storage of input ring buffer size
BCOUNT:	.WORD	0			;Active char count
CNT:	.WORD	0			;Ring buffer character count
CSSTAT:	.WORD	0			;Executive status word
PSFLG:	.WORD	0			;Pause flag
SPFLG:	.WORD	0			;Special function flag
BUFA:	.BLKB	BUFSIZ			;Modem input ring buffer
;
SIFLG:	.WORD	0			;FORCE PROTOCOL MODE BYPASS
INRING:	.WORD	0			;Input ring buffer count
RSET:	.WORD	0			;Special function storage word
BUFB:	.BLKW	256.			;Receive buffer
BUFC:	.BLKW	256.			;Transmit buffer
BUFD:	.BLKW	256.			;LP buffer
CSBUFF:	.BLKB	256.			;256 byte buffer for CSEXEC
BUFE:	.BLKB	KBFSIZ			;Keyboard input buffer
FBUFF:	.BLKB	80.			;80 character file name buffer
	.EVEN
FREE:	.WORD	0
LIMIT:	.+2				;Limit of program
	.END	START
