	.title	k11cmd	command level for kermit-11
	.ident	/8.0.01/


	baselev	==	2		; baseline level
	edit	==	39.		; edit (independent of base_level)
	release	==	'T&137		; T for test, V for release

	.save
	.psect	ident	,ro,d,gbl,rel,con
lasted::.asciz	/  Last edit: 06-Dec-85 /
	.even
ident::	.word	baselev,edit,release
	.restore
	

;	Brian Nelson  01-Dec-83  13:19:14
;
;	Change Software, Toledo, Ohio
;	University of Toledo, Toledo, Ohio
;
;	Copyright (C) 1983   Change Software, Inc.
;
;
;	edits:
;
;	01 08-Jan-84  K11CMD	BDN	fix SET PARITY
;	01 08-Jan-84  K11PAK	BDN	Change  timeout to  MYTIME from MAXTIME
;					if remote's SINIT packet had a value of
;					zero for the timeout (CMS kermit?)
;	01 08-Jan-84  K11CMD	BDN	Added  call to XINIT for initialization
;					based on the operating system.
;	01 08-Jan-84  K11PAK	BDN	Fix .asicz for ERROR: SPACK
;	02 11-Jan-84  K11RMS	BDN	Added RMS rename
;	02 11-Jan-84  K11CMD	BDN	Added RENAME command
;	02 12-Jan-84  K11PAK	BDN	Fix checking for X , Z in ACK for Sdata
;	02 13-Jan-84  K11CMD	BDN	Added TAKE and @ commands
;	02 13-Jan-84  K11CMD	BDN	Added showing speed for SHOW LINE
;	02 13-Jan-84  K11M41	BDN	More rsxm/m+ code added
;	02 13-Jan-84  K11CMD	BDN	Moved C$HELP to module K11HLP
;	02 16-Jan-84  K11CMD	BDN	Add Set Block-Check-Type and SHOW BLOCK
;	02 16-Jan-84  K11PAK	BDN	Redo  checksum processing to accomadate
;					12 bit and CRC types.
;	02 16-Jan-84  K11CMD	BDN	Allow  underscore and digits in command
;					names.
;	02 17-Jan-84  K11PAK	BDN	Allow 12 bit and CRC-CCITT Checksums
;					The user should always set the checksum
;					type for both KERMITS.
;	02 17-Jan-84  K11CMD	BDN	Allow open for KERMIT.INI
;	02 17-Jan-84  K11CMD	BDN	Added  commands  NOTE and  COMMENT  for
;					echoing text from indirect files.
;	02 18-Jan-84  K11CMD	BDN	Added  REMOTE,  SPACE and  REMOTE SPACE
;					commands.  Support  added to K11E80 and
;					K11SER for generic U command.
;	03 20-Jan-84  K11M41	BDN	Test and fix TTSPEED, SETSPD and BINREA
;					for RSX11M/M+
;	03 22-Jan-84  K11M41	BDN	Fixed  BINREAD(lun,tmo)  to work with a
;					passed timout of '-1' to effect a  read
;					without wait (no stalling if no data).
;	03 23-Jan-84  K11E80	BDN	Rewrote NOECHO(line)  and ECHO(line) to
;					set noecho when the remote  link is set
;					via SET LIN  and open in K11CON.  Added
;					calls in K11CMD and K11CON to NOECHO.
;	03 23-Jan-84  K11M41	BDN	Modified CANTYP(lun) to force LUN 5  if
;					a value of zero (0) is passed for a lun
;					to  make it  compatible  with  the RSTS
;					version of CANTYP.
;	03 23-Jan-84  K11SER	BDN	Finished  prototype version of extended
;					replies and added the  remote DIRECTORY
;					command (generic D) to test it for RSTS
;	03 25-Jan-84  K11HLP	BDN	Finished subtopics for HELP command
;	03 25-Jan-84  K11CMD	BDN	Added SET RECORD-FORMAT STREAM and
;					and   SET RECORD-FORMAT VARIABLE
;	03 25-jan-84  K11RMS	BDN	Added support for stream ascii
;
; Version 2
;
;
; I decided that I would like to have the normal TED timestamp on the edit.
;
;
; 04 27-Jan-84  18:30:07  K11PAK  BDN	Redo support for extended server replies
; 04 27-Jan-84  18:45:08  K11SER  BDN	Redo support for remote commands
; 04 27-Jan-84  18:55:44  K11PAK  BDN	If datafield.len < 0 then reset checksum
;					type to type '1' in RPACK$
; 04 27-Jan-84  20:02:34  K11HLP  BDN	Fix keyword match to  match @ position 1
; 04 27-Jan-84  21:33:21  K11CMD  BDN	Added REM ERASE,  also add synonyms  for
;					SET LOGFILE as LOG_FILE and LOG-FILE.
; 05 30-Jan-84  12:01:41  K11CMD  BDN	Add ERASE, DELETE
; 05 30-Jan-84  13:44:28  K11RMS  BDN	Added  RMS $ERASE  code and disk logging
;					of files deleted.
; 05 30-Jan-84  16:38:01  K11SER  BDN	Consolidated remote  server command pac-
;					ket sending and creation.
; 05 30-Jan-84  20:10:28  K11HLP  BDN	Found out  that K11HLP  needs temp privs
;					to get at the help file (K11HLP.HLP). If
;					the sys  manager installs  the  optional
;					patch to FIP for UU.LOK then a <234>  is
;					needed.
; 05 31-Jan-84  08:41:03  K11CMD  BDN	Moved SHOW command to  K11SHO.MAC,  also
;					moved $NAME and COMMAND macros to K11CDF
; 05 31-Jan-84  09:36:56  K11RMS  BDN	Fixed  help file access  problem at  the
;					source, ie, insure FB$GET is set only if
;					the file is opened for reading.
; 06 01-Feb-84  10:21:19  K11CMD  BDN	Moved type and rename commands to K11SHO
;					to space space in the root.
; 06 01-Feb-84  10:22:17  K11SER  BDN	Insure KERMIT.TMP has the default device
;					string inserted in it for create.
; 06 01-Feb-84  10:36:27  K11CMD  BDN	Add  'REMOTE TYPE' and added 'DISK to be
;					same as 'SPACE'
; 06 01-Feb-84  10:37:49  K11SER  BDN	Support remote type in server
; 06 01-Feb-84  13:06:36  K1180S  BDN	New module, do a partial SYSTAT for RSTS
; 06 01-Feb-84  13:07:10  K11SER  BDN	Add support for remote WHO command
; 06 01-Feb-84  13:07:26  K11CMD  BDN	Local and remote WHO commands.
; 06 01-Feb-84  14:25:46  K11RMS  BDN	Insure FB$FID in the FOP is cleared  for
;					the $ERASE call.
; 06 02-Feb-84  17:24:19  K11E80  BDN	Fix  CANTYP and  change parameter  list.
;					Mods required to K11SER, K11PAK,  K11CMD
;					and K11M41.
; 06 03-Feb-84  10:06:23  K11RMS  BDN	Rewrote  the default  directory to  work
;					the way  it should by using  $PARSE  and
;					the DNS and DNA fields in the FAB.  Also
;					added FPARSE to return an expanded name.
;					Changes to K11CMD, K11SER and K11PAK.
; 06 04-Feb-84  11:53:32  K11CPY  BDN  	New module, do file copies using RMS i/o
;					This could be dependent on new  versions
;					of  RMS11 as I access  the IFABS to copy
;					the correct file attributes,
; 06 04-Feb-84  11:54:59  K11SER  BDN	Added remote copy and rename support.
; 06 04-Feb-84  11:55:22  K11CMD  BDN	Added local copy and remote copy, rename
; 06 06-Feb-84  10:34:04  K11PAK  BDN	Added SETTMO to decide what receive time
;					out to use based on server timeout,  the
;					other  kermit's desired  timeout and any
;					timeout set via SET TIMEOUT value.
; 07 08-Feb-84  15:19:58  K11SER  BDN	Force mode to be remote if we are to run
;					as a server. Not really needed, but what
;					about doing a SET LINE and then SERVER ?
; 07 09-Feb-84  09:20:34  K11E80  BDN	Try to anticipate the DHV11 q bus inter-
;					face for  showing and setting speed.  No
;					changes needed to K11M41 for rsx.
; 08 09-Feb-84  21:33:55  K11RSX.ODL	Overlayed CSI1, CSI2 and PARSE which are
;					used to get the simple filename.ext from
;					the RMS11 expanded name string.
; 09 10-Feb-84  12:25:17  K11M41  BDN	Add HANGUP via IO.HNG qio, added code to
;					spawn  MCR SET /SPEED=TTnn:xxxx:xxxx  if
;					the SF.SMC  call to  change speed  fails
;					with  an IE.PRI error,  also changed the
;					cli for SPWN$S to CLI... from MCR...
;					Also use MCR spawn for disabling echo.
; 10 17-Feb-84  15:07:14  K11PAK  BDN	Mods for  doing ^X and ^Z  things.  Also
;					affected K11M41 and K11E80.
; 10 17-Feb-84  15:08:05  K11CMD  BDN	Did some trial  stuff on talking  to IBM
;					mainframes,  but  the CMS  Kermit  makes
;					things difficult as it can't time out.
;					Added Set Handshake and show for it. Not
;					yet done with handshake garbage.
;
; The following mods were done by:
;	Bob Denny
;	Alisa Systems, Inc.
;	Pasadena, Ca
;
; 10 03-Mar-84  20:34:18  K11RSX.ODL	Remove FCS parsing factor
; 10 03-Mar-84  20:41:10  K11DAP.ODL	Add new odl for Decnet (DAP) remote file
;					support for RSX11M.
; 10 03-Mar-84  20:44:35  DAP11S.ODL	Created this for sequential-only DAP
;					support RMS. General purpose, though.
; 10 04-Mar-84  01:10:03  K11M41	Remove FCS style filename parsing and
;					allow DAp remote file specifications.
; 10 04-Mar-84  02:55:47  K11RMS	Many small changes to allow DECNET (DAP)
;					remote file access. See comments in
;					K11RMS.MAC
; 10 05-Mar-84  15:47:30  K11CPY	Remove defaulting to SY: so Decnet  will
;					work  with systems that don't understand
;					SY:
; 10 07-mar-84	14:47:00  K11CPY	Close input file if $create failed.
;
; 10 xx-Mar-84  xx:xx:xx  K11M41	Bob also rewrote much of the RSX i/o
;					support and wrote the connect code for
;					RSX using asynch qios.
;
; The following mods were done by:
;	Brian Nelson
;	Change Software, Inc.
;	Toledo, Ohio
;
; 11 02-Mar-84  11:27:22  K11CMD  BDN	Modified init stuff to look for the init
;					file KERMIT.INI in SY: then if not there
;					to try  LB:[1,2], SY:[1,2] and KERMIT:
;
; 11 05-Mar-84  10:22:48		Sent version 2.11 to  Columbia and  DEC.
;					Did NOT include Bob Denny's RSX mods.
;
; 12 06-Mar-84  16:05:42  K11CMD  BDN	Mods to override auotmatic use of  local
;					terminal name if we're running in server
;					mode and the user did a SET LINE TTnn:
; 12 07-Mar-84  12:28:16  K11TRA  BDN	Added routine to 'brute force' a file to
;					a remote line. Needed it to get the  new
;					(and not yet done) RT11 version onto the
;					RT11 system being used for testing which
;					is, would you believe, a real PDT150.
; 12 08-Mar-84  11:56:14  K11CMD  BDN	Move  'remlst' and 'cmdlst' into  K11COM
;					which is overlayed in the ERROR segment.
;					Added calls to LOACMD and LOAREM to  get
;					the overlay with K11COM resident and  to
;					return a pointer to the command list. It
;					saves about 3000 (8) bytes in task size.
;					Note that  this does  not sit  well with
;					what $AUTO likes to do.
;					If it causes a problem, put K11COM  back
;					into the root.
;					Also had to make all RM$xxx epts in  the
;					module K11CMD global.
; 12 08-Mar-84  12:33:59  K11CMD  BDN	Added default of '.CMD' for TAKE
; 12 14-Mar-84  10:45:39  K11CON  BDN   Added  'BIC #^C177,R1'  in front of both
;					of the  'CMPB R1,CONESC'  to fix problem
;					using Kermit's connect command from  the
;					console (TT00: or KB0:)
; 12 14-Mar-84  10:49:37  K11E80  BDN	Don't  set 8BIT mode for the cpu console
;					if we are  running Kermit  from it  as a
;					local Kermit dialing out (RSTS/E only).
; 12 14-Mar-84  16:58:12  K11RMS  BDN	Skip the $SEARCH if there is no wildcard
;					context.  This gets around problems with
;					RSTS sites that modify the exec to alter
;					the way the exec does directory lookup.
;					This option is only executed if the  lo-
;					cation FU$DIR is <> 0 (see K11RMS.MAC)
;
; 12 17-Mar-84  13:23:45  K11RMS  BDN	Add in Bob Denny's mods for RSX i/o  and
;			  K11CON	doing RMS DAP access correctly.
;			  K11M41
;			  K11CPY
;
; 12 19-Mar-84  14:15:40  K11CMD  BDN	Add check for device name on CONNECT cmd
;			  K11RMS	Add routine to get MCR/CCL command line.
; 12 19-Mar-84  16:52:51  K11RMS  BDN	Put  back SY:  defaulting for RSTS only.
;			  K11CPY	Done if  TST FU$DEF  is <> 0.  FU$DEF is
;					defined in K11E80 to be .word 177777. In
;					K11M41 it is .word 0.
; 12 20-Mar-84  19:55:15  K11CVT  BDN   A new module.  Do  executive independent
;					parsing of file specs to return only the
;					filename.filetype.  This will help those
;					users who  need DAP support.  It's  also
;					overlayed into the ERRDVR region.
; 12 20-Mar-84  19:57:16  K11E80  BDN	Conditional'ed out  NAMCVT,  which I re-
;			  K11M41	wrote and put into K11CVT.MAC.
; 12 20-Mar-84  20:03:16  K11CON  BDN	Added  directive SREX$S  for RSX connect
;					to reset the  TT: lines to  their former
;					states in case of an ABORT.
; 12 20-Mar-84  20:04:15  K11M41  BDN	Added control C ast recognition for RSX.
; 12 20-Mar-84  20:06:06  K11E80  BDN	Modified control C ast support so it can
;					be compatible  with the  newly added RSX
;					control C ast processing.
; 12 23-Mar-84  08:47:08  K11LCL  BDN	Rewrote so commands  can be disabled via
;					ONLPAT for RSTS/E.
; 13 30-Mar-84  10:31:46  K11PAK  BDN	Added software parity generation.  Would
;					be mainly used when connecting out to  a
;					remote system that requires parity.
; 13 30-Mar-84  10:32:44  K11LCL  BDN	Modified protection for commands.
; 13 30-Mar-84  10:33:03  K11E80  BDN	Rewrote DIRECTORY code, disable non-priv
;					users from looking at other accounts. Is
;					patchable via ONLPAT, see K11INS.DOC.
; 13 30-Mar-84  10:34:02  K11PAK  BDN	Fix extended server replies to work when
;					the checksum is type 2 (12bit arith sum)
;					or type 3 (16 bit CRC).
; 13 30-Mar-84  10:40:35  K11MAC  BDN	Defined a macro  for XOR which  does not
;					require 'XOR reg,dst' format.  It uses 4
;					instructions  and will  be needed anyway
;					for the RT11 version.
; 13 30-Mar-84  10:45:08  K11E80  BDN	Removed  hardware parity set code  since
;			  K11M41	we will generate our own if need be.
; 13 02-Apr-84  11:14:12  K11STT  BDN	Added SET DUPLEX HALF, SET DUPLEX FULL
; 13 02-Apr-84  11:14:36  K11CON  BDN	Added support for half duplex link. Also
;					added global 'duplex' to K11DAT.MAC
; 13 02-Apr-84  17:14:29  K11E80  BDN	Insure that no single  private delimiter
;					is set for  the terminal, ala the ttyset
;					command SET DELIMITER "ch".  If  set, an
;					unusual exec bug seems to creep  in when
;					a .sleep is executed ????
; 13 03-Apr-84  16:22:01  K11E80  BDN	Added TTXON to cancel xoffed line state.
; 13 03-Apr-84  17:11:35  K11M41  BDN	Added TTXON to cancel xoffed line state.
; 13 04-Apr-84  09:36:06  K11STT  BDN	Changes to SET BLOCK
; 13 04-Apr-84  10:13:32  K11PAK  BDN	Debug logging mods. Added calls to TTXON
;					to fix xoff'ed line.  Also added routine
;					SINFO to handle init for expected server
;					reply.
; 13 04-Apr-84  18:37:58  K11CON  BDN	Have X command cancel link being xoff'ed
;					by the remote as well as send the remote
;					an xon.
; 13 04-Apr-84  18:39:38  K11SER  BDN	Calls to SINFO if we expect an  extended
;					reply from a remote server, required  if
;					block checks are type 2 or 3.
; 13 04-Apr-84  18:43:33  K11RMS  BDN	Added ept's FOPEN and  FCREATE to  allow
;					use of multiple  block buffering for seq
;					files. Desired for use by HELP command.
; 14 12-Apr-84  17:07:51  K11CON  BDN	Print speed and escape seq for CONNECT.
; 14 18-Apr-84  10:40:01  K11PAK  BDN	Mods for defered file creates to handle
;					attribute packets
; 14 18-Apr-84  10:41:34  K11RMS  BDN	Added 'inited' flag for lun being active
; 15 01-May-84  11:41:49  K11ATR  BDN	Added support for attribute packets.
;					Allow auto determination of binary mode.
;					Support for getting  the IFAB data  will
;					only work between like Kermits.
;					Added SET ATTRIBUTES OFF command to dis-
;					able  any attribute  sending even if the
;					other Kermit's CAPAS field indicates the
;					support of it (ie,  handle  incompatible
;					protocal versions or bugs)
; 15 02-May-84  11:03:57  K11RMS  BDN	Found  out that either INIDM from SYSLIB
;					or the GSA code from the RMS v2 kit will
;					fail if th e task size is exactly on a 1
;					KW boundary. In this case the high limit
;					was 113777,  causing $INIDM  to crash at
;					startup.
; 15 03-May-84  10:25:46  K11M41  BDN	Fixed the faking of BREAK for RSX.  Pass
;			  K11CON	a LUN to use for the set speed QIO.
; 15 03-May-84  10:29:22  K11E80  BDN	Added UU.SPL stuff for the PRINT command
;			  K11M41	Dummy support for it on RSX since PRINT$
;					macro needs FCS, not RMS, support.  Will
;					check RMS out or else SPAWN a PRINT cmd.
; 15 04-May-84  13:56:21  K11M41  BDN	Fixed read  timeouts in RBD's version of
;					BINREA.  Also hooked BINREA into CANTYP.
; 15 06-May-84  11:33:38  K11RMS  BDN	Increased record buffersize to 160
; 15 06-May-84  11:33:56  K11PAK  BDN	Moved  the  ACK for the EOF packet to be
;					send AFTER the output file is closed. An
;					occasional RSX problem in that the BREAK
;					packet was lost  due to timing  required
;					this mod,  though  if the line is set up
;					properly this would not be a problem.
; 15 08-May-84  11:15:35  K11PAK  BDN	Insure R0 cleared in BUFEMP in case  the
;					the data packet was null.
; 16 14-May-84  09:38:50  K11CON  BDN	Check for errors from the qio's for RSX.
;					In particular, catch the IE.DNR in  case
;					the carrier drops.
; 16 18-May-84  10:29:02  K11SER  BDN	The code for response to an  'R'  packet
;					was sending the RMS error text after the
;					routine GETNXT already sent error packet
; 16 21-May-84  17:01:56  K11PAK  BDN	Don't retry until MAXTRY the SINFO ('I')
;					packet since older Kermit's will not  be
;					able to understand 'I' packets. The  old
;					Kermits will ALWAYS send NAKS for SINFO.
; 16 25-May-84  12:18:08  K11DEB  BDN	Added 'DISPLAY globalsym' command.  This
;					prints out values of variables in module
;					K11DAT.MAC for debugging purposes.
; 16 25-May-84  15:39:26  K11STT  BDN	Moved command definitions for the  'SET'
;					command to K11COM.MAC to save space.
; 16 25-May-84  15:40:35  K11PAK  BDN	Problem with VMSKERIT not liking 10 char
;					acks for 'S' packets, changed ACK packet
;					size to 11 for the time being until  the
;					problem can be isolated.
; 16 28-May-84  09:08:47          	Version 3.0.051 of VMS Kermit  fixed the
;					above problem of ACK length.
; 16 28-May-84  09:09:40  K11RTT  BDN	Kermit-11 now runs under the FB moniter
;					for Rt11 version 5 with MT support.
; 16 28-May-84  09:10:19  K11CMD  BDN	Fix call to TTYRST for Kermit-11/RT
; 16 28-May-84  15:55:08  K11PAK  BDN	Insure that 'BUFEMP' does not try to CTL
;					characters that could not have been set.
;					Defensive response to the CPM Kermit 3.9
;					which ALWAYS sends ampersands  over with
;					the CTL quote, '#'.  Note: 20KERMIT does
;					this also.  Fix should be in CPM Kermit,,
;					but it's simple to fix at this end.
; 17 10-Jun-84  16:44:50  K11RTT  BDN	Reduce tt read overhead for RT11 version
;			  K11RT4  BDN	Dummy out K11LCL for RT11 to save space.
;			  K11RT4  BDN   Timing bug in file open routine (?)
;			  K11RT4	Fix overlay error  (K11ATR with K11SUB).
; 17 11-Jun-84  11:21:51  K11CVT  BDN	Add  code to decide if  a file is binary
;					based on the filetype (ala .SAV, .BAC..)
; 17 19-Jun-84  18:08:56  misc	  BDN	Add xon/xoff support to RT11 connect be-
;					cause the MT service for RT has  far too
;					much  overhead  for speeds  greater than
;					300 baud.
;					Add wildcard support for RT11 version.
;					Add IO.ATT for slaved terminal re M+ 2.1
;					and RSX v4.1 kits (curse you, K. Olsen).
;					The 'new'  versions of  M+ and M disable
;					typeahead  for  slaved lines  unless the
;					device is attached (?). Rather odd (?)
; 17 21-Jun-84  15:19:46  K11STT  BDN	If set line kb: or set line ti: then  we
;			  K11M41	should reset back to remote mode.
;			  K11E80
; 17 21-Jun-84  16:22:12  K11CMD  BDN	Fix open for takefile (missing type arg)
; 17 21-Jun-84  19:33:48  K11RT4  BDN	Final RT11 code modifications.
; 17 22-Jun-84  09:31:19  K11RMS  BDN	Don't set fb$wri in the FAC field when a
;					file is readonly for binary file reads.
; 17 22-Jun-84  11:20:29  K11M41  BDN	Add SREX$S  call in TTYINI so an aborted
;					server can fix the line back up.
;
; 17 22-Jun-84  12:33:15  !!! finally ship new version out to Columbia !!!
;
;
; 18 26-Jun-84  09:06:03  K11LCL  BDN	Optionally slow transfer rate down for
;					user's based on the uic and speed
; 18 03-Jul-84  10:16:03  K11INI  BDN	Moved INIT and KERINI from K11CMD.MAC to
;					module (K11INI).  Also moved SPAR, RPAR,
;					DSKDMP and FILLOG from K11PAK to here to
;					save space in the root for RT11 version.
; 18 06-Jul-84  12:45:27  K11RT4  BDN	Finally found out that I had gotten  the
;					arguments for .DSTAT swapped, which will
;					explain why the RT11 file opens and cre-
;					ates were being so flakey.
; 18 06-Jul-84  13:29:21  K11RTT  BDN	Add loop to eat any buffered server NAKS
;					in TTYINI().
;
;
; 18 06-Jul-84  15:20:34		Update sent  to Frank Da Cruz  for fubar
;					RT11 code with .FETCH and .DSTAT
;
;
; 19 11-Jul-84  17:49:26  K11ATR  BDN	Fix RMS problem with attributes for RSTS
;					non attributed binary files.
; 19 11-Jul-84  17:59:20  K11STT  BDN	Add SERVER DETACH command to allow  ser-
;			  K11M41	ver to detach from KB: (or TI:).  In the
;			  K11E80	the case of RSTS/E, spawn new job to log
;			  K11RT4	the caller back in.
; 19 15-Jul-84  17:14:10  K11E80  BDN	Add checks to be sure that the SET  LINE
;					devicename was a real device for  RSTS/E
;					and not some file name like SET LIN 1.
; 20 19-Jul-84  10:26:57  K11RTU  BDN	Add support for RENAME and DELETE for RT
;					version 5.
; 21 19-Jul-84  15:35:00  K11PAK  BDN	Added 8 bit prefixing
; 21 23-Jul-84  12:31:47  K11RT4  BDN	Insure that we are NOT running under the
;					SJ monitor.
; 21 23-Jul-84  12:32:11  K11SER  BDN	Stuff the default device into the server
;					extended reply temp filename (needed for
;					RT11 Kermit).
; 21 23-Jul-84  12:47:03  K11DEF  BDN	New module, an '.include' file to define
;					all the packet types.
; 21 24-Jul-84  11:35:15  K11RTD  BDN	Extended directory lookup for RT11 to
;					allow '%' in the filename or type.
; 21 30-Jul-84  11:17:24  K11PAK  BDN	More work for IBM mode
; 21 30-Jul-84  16:07:44  K11CVT  BDN	Add .EXE and .RTS to binary file list.
; 21 30-Jul-84  16:08:17  K11M41  BDN	Fix TTPARS to return device name so we
;					can use DECNET/M HTnn: device names.
; 21 30-Jul-84  16:11:01  K11COM  BDN	Added commands TIME and DATE
; 21 30-Jul-84  16:11:36  K11M41  BDN	Added date and time ascii conversion.
; 22 03-Aug-84  10:28:23  K11M41  BDN	Hook for single character reads if any
;					handshaking character is set.
; 22 03-Aug-84  10:28:54  K11PAK  BDN	Finish code for talking to half duplex
;			  K11COM	IBM 370 compatible systems.  Added SET
;			  K11STT	IBM ON/OFF, SET LOCAL ON/OFF.  SET LOC
;					is equivalent to SET DUPLEX FULL/HALF.
; 22 08-Aug-84  15:50:33  K11RTD  BDN	Change the check for RT11 volume valid
;					from home block offset 730 to 760.
; 22 10-Aug-84  13:20:31  K11RT4  BDN	Moved ERROR text and error lookup code
;			  K11RTU	to K11RTE.MAC, also moved RT11 COPY to
;					K11RTU overlay.
; 22 14-Aug-84  10:21:51  K11ATR  BDN	Add attribute packet type 41 (8) so we
;			  K11RMS	send  the recieving Kermit the size of
;			  K11RT4	the file. Needed for RT11 Kermit since
;					RT11 needs to preallocate files. Could
;					not create file larger than 243 blocks
;					on the PDT150 until this was put in.
; 22 14-Aug-84  10:24:23  K11RTU  BDN	Added code for ASCTIM for RT11 Kermit.
; 22 15-Aug-84  09:15:32  K11M41  BDN	Slave the connect line at SET LINE  in
;					routine ASSDEV (restored @ exit). Also
;					add RPOI$S call to  ...BYE for generic
;					logout from server.
; 22 20-Aug-84  14:51:05  K11M41  BDN	Mods for P/OS
; 23 14-Oct-84  15:20:13  K11SEN  BDN	Creation, split receive and send state
;			  K11REC	out from K11PAK to save space for  the
;					PRO/RT11 version of Kermit.
; 23 14-Oct-84  16:01:22  K11PRT  BDN	New  module for XC port communications
;					with PRO/RT11 version 5.1
; 23 15-Oct-84  13:39:05  K11CMD  BDN	Moved C$SET back in
; 23 15-Oct-84  13:39:22  K11ST0  BDN	Creation, split K11STT in half for RT11
; 23 15-Oct-84  13:39:22  K11ST1  BDN	Creation, split K11STT in half for RT11
; 23 15-Oct-84  13:52:09  K11RT?  BDN	Fixed all the .FETCH stuff
; 23 16-Oct-84  15:32:31  K11CM1  BDN	Removed  number of commands from K11CMD
;					to save space for PRO/RT11 version.
; 23 21-Oct-84  16:36:51  K11CVT  BDN	Added new filetypes for binary mode.
; 23 21-Oct-84  16:37:16  K11REC  BDN	Added error logging and got all state
;					switches parameterized.
; 23 21-Oct-84  16:38:36  K11CMD  BDN	Moved printing of banner.
; 23 21-Oct-84  16:37:57  K11???  BDN	Got sick of working on PRO/RT11.
; 23 25-Oct-84  16:44:52  K11PAK  BDN	Repeat count prefixing added.
; 23 25-Oct-84  16:45:11  K11ST1  BDN	SET REPEAT ON/OFF
; 23 25-Oct-84  16:45:36  K11PRT  BDN	Real break sending for the PRO/RT11
; 23 25-Oct-84  16:46:01  K11CON  BDN	Removed break sending code to specific
;					executive support modules.
; 23 25-Oct-84  16:47:20  K11XXX  BDN	This is getting to be a drag having to
;					generate six different versions of the
;					Kermit-11 each time I change something.
; 24 09-Nov-84  15:32:36  K11RT?  BDN	Virtual overlays for XM, K11DSP to call
;					the  correct terminal i/o overlay based
;					on the exec and line type (ie, TSX+ and
;					XC/XL). We can now  AVOID  generating a
;					differnt save image for each config.
; 24 09-Nov-84  15:35:05  K11DSP  BDN	Creation.
; 24 09-Nov-84  15:35:17  K11TSX  BDN	Creation from NED RHODE'S modifications
;					to K11RTT for TSX+.  Note that this one
;					I can never test as I do not use TSX.
; 24 26-Nov-84  11:46:53  K11E80  BDN	Fix a UU.TRM call for RSTS T9.0-07.
; 25 16-Jan-85  13:20:45  K11E80  BDN	Mods for much faster packet reading.
; 					Sped file get up by about 35% for RSTS
; 25 17-Jan-85  10:51:58  K11SEN  BDN	Added abort (^E,^X & ^Z) for SENDing.
; 25 17-Jan-85  10:52:38  K11DSP  BDN	Clear PROFLG in ASSDEV if SET LINE is
;					done and device is not X?: for RT11.
; 25 17-Jan-85  10:53:17  K11CON  BDN	Added SET CONSOLE 7, SET CONSOLE 8 to
;			  K11ST1  BDN	force P/OS Kermit11 to junk bit 7 when
;					in terminal mode, thus avoiding DEC's
;					multinational character set.
; 25 17-Jan-85  10:56:03  K11HLP.HLP	More explanation about BINARY files as
;					there seems to be a lot of confusion
;					about binary file transfer.
; 25 28-Jan-85	15:30:01  K11SER.MAC	Get rid of imbedded crlfs in the short
;					server reply string.
; 25 29-Jan-85	09:40:22  K11SEN.MAC	Fix things up for ^e,^x and ^z inter-
;			  K11REC.MAC	upts on getting and sending files.
; 26 20-Feb-85  15:13:05  K11E80.MAC	Changed default record format from
;					FILES-11 variable to STREAM ASCII.
; 26 28-Feb-85  14:00:30  K11RT4.MAC	Fixes for TSX+
;			  K11DSP.MAC
;			  K11TSX.MAC
; 26 28-Feb-85  14:01:08  K11RMS.MAC	Change % to ? in wildcards for RSTS/E
;			  K11SER.MAC	server to kludge around the problem
;					that some Kermits mangle ? in cmdline
; 27 19-Mar-85  15:59:06  K11SEN.MAC	Fix losing attribute packets in case
;					we timed out or were naked.
; 27 XX-Apr-85		  K11M41.MAC	Fix ASSDEV: for stack problem
; 28 20-Apr-85  09:22:01  K11ST1.MAC	Added SET BINARY-TYPE .filetype for
;			  K11CVT.MAC	overriding the built-in binary file
;					type list.
; 28 22-Apr-85	10:34:56  K11RT4.MAC	Kludge if RT system does not have a
;			  K11RTT.MAC	clock.
; 28 01-May-85  16:00:01  K11ST1.MAC	Ignore TYPE in SET FILE [TYPE] arg
; 28 07-May-85  17:40:06  K11TSX.MAC	Final mods by Ned Rhodes for TSX+
;			  K11PRT.MAC
; 28 09-May-85  07:40:41  K11RTD.MAC	Add support for server REM DIR command
;					for RT and TSX+.
; 29 14-MAY-85  10:26:33  K11INI.MAC	Fix bug for setting 8bit prefixing.
;					Quite noticable on PRO/RT version.
; 29 17-May-85  05:08:47  K11ST1.MAC	Add SET FIL [NO]SUPERCEDE to protect
;			  K11REC.MAC	files that already exists.
; 29 18-May-85  14:17:39  K11SER.MAC	Update packet types to symbolic names
; 30 01-Jun-85  11:01:45  K11DAT.MAC	Added 'BLIP::' for packet logging ala
;					SET UPDATE n. A SET UPD 0 will disable
;					all packet counts to the terminal.
; 30 01-Jun-85  11:02:28  K11ST1.MAC	Added LOGFILE filename.type so we can
;					be more compatible (calls SET LOGFILE)
; 30 01-Jun-85  11:03:30  K11INI.MAC	Mods for SET UPDATE, also set do a SET
;					TER VT100 for PRO/3xx systems.
; 30 01-Jun-85  11:04:31  K11M41.MAC	Add 19.2 and 38.4 speeds into SET SPEED
; 30 04-Jun-85  11:23:52  K11ST0.MAC	Added SET RSX TC.DLU value to alter
;			  K11M41.MAC	the tc.dlu setting for connecting to a
;			  K11DAT.MAC	modem. By default, Kermit will never try
;			  K11CON.MAC	to change it, however, a value of 1 or 2
;			  K11COM.MAC	will force a change if not already set.
; 30 04-Jun-85  11:26:04  K11M41.MAC	Added SET RSX CHARIO and SET RSX LINEIO.
;			  K11ST0.MAC	The former will force packet reads to do
;					a SF.GMC for the typeahead count, then
;					read that many under IO.RAL, as is done
;					for P/OS. The latter will (default) do
;					reads by line for M and M+.
; 31 17-Jun-85  14:23:14  K11CON.MAC	Wait 6 seconds if changing TC.DLU
; 31 17-Jun-85  14:53:34  K11CMD.MAC	Add call to RSTSRV to restore line chars
;					if control C abort under SERVER & RSX.
; 31 17-Jun-85  15:29:36  K11RT4.MAC	Added .HRESET if device was X?: at exit.
; 31 20-Jun-85  18:42:27  K11SHO.MAC	Updated SHOW command
; 31 20-Jun-85  18:42:39  K11SEN.MAC	Updated SDATA to not abort on 'unknown'
;					packet type.
;
; New tape to Columbia	  V2.31
;
;
; 32 02-Jul-85  13:02:04  K11PAK.MAC	Insert current prompt into error text
;					sent to other system.
; 32 02-Jul-85  13:10:31  K11CON.MAC	Set remote line to binary mode for RSTS
;					version 9 for the CONNECT command, (see
;					TTDVR, it changes C1 ( > 200 (8)) chars
;					to escape sequences, neat, huh?).
; 32 02-Jul-85  13:14:22  K11INI.MAC	Set pro/350 to 7 bit to avoid multinat
;					char sets, use SET CONS 8 to override.
; 32 02-Jul-85  13:44:50  K11CMD.MAC	Added support for CWD and REM CWD.
;			  K11SER.MAC	Support for GN$CONNECT (rem cwd)
;			  K11COM.MAC	Added CWD and REM CWD to command lists
; 32 02-Jul-85  22:29:34  K11HLP.RNO	Add Doc for modems.
;
; 33 16-Jul-85  20:57:50  K11RXX.MAC	Added new connect code, for now invoked
;			  K11ST0.MAC	via SET RSX CONNECT ALTERNATE, default
;			  K11CON.MAC	is SET RSX CONNECT DEFAULT. If it works
;					out ok, will change new code to default
;					as it appears to do the connect i/o
;					better due to it's own internal xon/xof
;					and double buffering.
; 33 16-Jul-85  21:10:47  K11M41.MAC	Do a MCR SET/NORPA=TTn:, needed if the
;					line was set to /RPA as /RPA tells the
;					TTDRV to pass XON and XOFF thru.
; 33 16-Jul-85  21:12:01  K11HLP.RNo	Update HELP for SET RSX.
; 34 29-Jul-85  14:22:28		Mod REM CWD to accept password if
;					present, no prompts though.
; 35 01-Aug-85  14:15:10  K11CVT.MAC	Fix filenames with fubar characters
;			  K11REC.MAC	to be legit (insert 'x' into name),
;					as in GET abcde_f.dat --> abcdexf.dat
; 35 01-Sep-85	14:30:22  K11PAK.MAC	Modified insertion of prompt into error
; 35 01-Sep-85  14:45:33  K11SEN.MAC	Added messages for retry aborts.
; 36 10-Sep-85  13:38:31  K11ST0.MAC	Added SET RT11 command, currently as
;			  K11RTD.MAC	SET RT11 [NO]VOLUME_VERIFY, to skip
;			  K11DAT.MAC	checking systype at offset 760 in the
;			  K11RT4.MAC	directory header for disks. Also added
;			  K11COM.MAC	SET RT11 [NO]FLOW_CONTROL, same as the
;					old SET RTFLOW [ON][OFF]
; 36 13-Sep-85	12:30:12  K11ST1.MAC	Added SET REC START-OF-PACKET, also
;			  K11PAK.MAC	SET SEN STA . Also added
;					SET START-OF-PACKET which forces both
;					SOP's to same value.
; 36 17-Sep-85  10:54:11  K11ST0.MAC	Added SET RT11 CREATE_SIZE value to
;					for allocation for small disks on file
;					creates, sometimes needed for Kermit-11
;					to non Kermit-11 transfers.
; 36 17-Sep-85  10:55:06  K11REC.MAC	Allow SEN filename destination_filename
;			  K11SEN.MAC	and   GET filename destination_filename
;			  K11CMD.MAC	Disabled for SEND if wilcarded filename
; 36 24-Sep-85  12:29:53  K11E80.MAC	Added REMOTE LOGIN and support for it
;			  K11SER.MAC	in the server. The server support makes
;			  K11COM.MAC	sense only for RSTS/E V9.x since RSTS
;			  K11CMD.MAC	is the only PDP exec supporting logins
;					via executive directives. REM LOGIN was
;					a request by Dale Handy for a specific
;					application.
; 36 10-Oct-85  14:51:33  K11PAK.MAC	Fix call from M$RETRY to ERROR()
; 36 10-Oct-85  14:53:55  K11CON.MAC	Save and reset speed if change TC.DLU
; 36 13-Oct-85  15:27:45  K11SEN.MAC	Fix up control C aborts. Add new state
;			  K11REC.MAC	called STA.CCABORT for processng ctl C
;			  K11M41.MAC	aborts. Added IO.KIL in ctrl C ast
;			  K11E80.MAC	code for RSX and P/OS to stop current
;					i/o operation. Can't do this on RSTS.
; 37 19-Oct-85  17:00:01  K11ST0.MAC	Added SET MODEM command
; 37 19-Oct-85  17:17:49  K11DIA.MAC	Add DIAL command
; 37 28-Oct-85  13:37:44  K11CON.MAC	Added code re Steve Heflin to (1) do
;					a MRKT$S iif 'TC.DLU' does a zero to
;					non-zero transition,  and (2)  alter
;					function code for REMWRITE QIO if the
;					TC.DLU == 2 to IO.WBT!TF.WAL,  a must
;					do for M+ V3  and MicroRsx V3.  Would
;					assume not  needed for packet sending
;					as currently packet sending is block-
;					ing (ie, its half duplex).
; 37 28-Oct-85  17:40:52  K11M41.MAC	Stuff *.*;* into DEFDIR in DODIR: iif
;					the first byte of DEFDIR is \0 (null)
; 37 29-Oct-85  17:01:53  K11M41.MAC	Add code for IO.BRK on P/OS.
; 37 01-Nov-85  10:51:33  K11INI.MAC	Get defensive in RPAR so we can catch
;					short SINIT packets better and fix(?)
;					them. Needed for FIDO Kermit.
; 37 04-Nov-85  13:23:52  K11REC.MAC	Insure call to FPARSE for case where
;					user says GET remote_name local_name
; 37 04-Nov-85  15:25:08  K11PRT.MAC	Various mods for CL: handler for TSX+
;			  K11RT4.MAC	to allow the use of 8BIT mode on the
;			  K11TSX.MAC	handler, also avoid dropping DTR when
;			  K11RTT.MAC	we close CL line. Dummy EPT's stuffed
;			  K11DSP.MAC	in K11TSX and K11RTT for reset @ exit
;					code.
; 37 04-Nov-85  17:23:30  K11PRT.MAC	Put back  in the kludges for the lack
;			  K11RTT.MAC	of a clock, which somehow got lost in
;					subspace somewhere (RT11 specific).
; 37 05-Nov-85  10:19:47  K11PRT.MAC	Added .TWAIT for 1/3 second in TTYFIN
;					to avoid turning the XC/XL driver off
;					before all I/O has been sent to host.
; 38 06-Nov-85  15:13:59  K11PAK.MAC	Moved GETCR0 to call actual next_char
;					routine via CALL @GETROUTINE so we can
;					support the use of alternate routines.
;					This allows extended server responses
;					to use memory or whatever instead of
;					temporary files.
; 38 06-Nov-85  15:17:36  K11RMS.MAC	Change EPT name GETCR0 to FGETCR0
; 38 06-Nov-85  15:17:36  K11RT4.MAC	Change EPT name GETCR0 to FGETCR0
; 38 06-Nov-85  16:20:33  K11SER.MAC	Change REM HELP to use asciz sender
;					instead of dumping to file and sending
;					the file for the extended response.
;
; 38 07-Nov-85  15:13:06  K11M41.MAC	Rewrite handling for REMOTE DIR server
;			  K11E80.MAC	processing so that we do not fill up
;			  K11RTD.MAC	a file with the directory listing and
;			  K11SER.MAC	then send the file. Instead stuff
;					GETROUTINE: with &SDODIR.
; 38 09-Nov-85  12:35:05  K11M41.MAC	Alter XBINREAD to use MRKT$S for the
;					read timeout and do an IO.KIL if it
;					fails then convert IE.ABO to IS.TMO
; 39 14-Nov-85  10:17:15  K11RT4.MAC	Check for XC, XL and MT service.  If
;					not present, warn and fake using TSX
;					TT: code.
; 39 14-Nov-85  10:17:53  K11TSX.MAC	TSXFLG=1 for TSX+, -1 for RT11 without
;					XC,XL or MT service. Thus, RT11 kermit
;					can run using console only systems.
; 39 16-Nov-85  12:13:26  K11CON.MAC	Intercept ESC Z and return a terminal
;					id that all exec's understand on P/OS.
;					Also, intercept all escape sequences
;					from P/OS keyboard and map some of the
;					upper row F keys to something usefull,
;					like ESC (F11)-> \033, INT (F6)>-> \03
;					and so on. Both features added at the
;					request of B. Eiben, DEC LDP, formerly
;					DEC LCG (eiben@dec-marlboro.arpa)
; 39 30-Nov-85  12:35:20  K11E80.MAC	Minor mods for RSTS/E v9.x, get term
;					type and set buffer count for input.
; 39 30-Nov-85  12:35:44  K11INI.MAC	Send ESC > to force ansi mode if a
;					VT100.
; 39 03-Dec-85  13:00:14  K11TSX.MAC	More mods to use CONSOLE port on RT11
;			  K11DSP.MAC	Also, SET LIN TT: will override the
;					use of XL or MT service.
; 39 04-Dec-85  17:58:37  K11DIA.MAC	Modem type data structure mods, see
;					K11DIA.MAC for more info.
; 39 06-Dec-85  11:57:58  K11DIA.MAC	Support for calling external routine
;			  K11M41.MAC	to dial (ala PRO/TMS). Added in mods
;					from Steve Covey for PRO/TMS dialing
;					out, mods for dialing in not done.

	.sbttl	define macros and things we want for KERMIT-11

	.include	/IN:K11MAC.MAC/
	.include	/IN:K11CDF.MAC/
	.iif ndf, k11inc, .error ; INCLUDE for IN:K11MAC.MAC failed

	.psect	$code

	cc$max	==	2

	.enabl	gbl







	.sbttl	the main program
	code


kermit::calls	setcc	,<#cctrap>	; enable control C trapping ?
	message
	call	sho$ve			; print version and edit number
	call	drpprv			; drop temp privs (for RSTS)
	clr	cccnt			; clear control C count
	mov	#stack	,sp		; initialize a large stack
	call	kerini			; try to open SY:KERMIT.INI
	call	binini			;

10$:	calls	setcc	,<#cctrap>	; command loop reading
	call	drpprv			; insure no privs are up now
	mov	#argbuf	,argpnt		; insure arg pointer is reset
	call	fixchk			; restore setted crc type
	clr	cccnt			; no control C's
	call	getcmd			; read and parse the command
	tst	r0			; but did it work out ?
	blt	70$			; no
	jsr	pc	,@cmdadr	; dispatch to the command
	br	90$			; and drop to bottom of the loop

70$:	cmp	r0	,#cmd$ex	; control Z typed
	bne	80$			; no
	jmp	c$exit			; yes, exit normally

80$:	cmp	r0	,#cmd$ba	; invalid command ?
	bne	85$			; no
	print	#200$			; yes, print out an error message
	br	90$			; and go back for more

85$:	cmp	r0	,#cmd$un	; /39/ not unique?
	bne	90$			; /39/ no
	print	#210$			; /39/ yes


90$:	br	10$			; back to the command loop


200$:	.asciz	/Unrecognized command/<cr><lf>
210$:	.asciz	/%Command not unique, try longer spelling/<cr><lf>
	.even

	global	<argbuf,argpnt,binini,drpprv,fixchk,stack>

	.sbttl	commands
	.enabl	lsb

c$rec::	$name	<REC>
	call	opentt			; initialize the link line
	mov	pauset	,oldpau		; save old pause settings
	call	throtl			; perhaps thottle the line speed
	tst	outopn			; is an output file already open?
	beq	10$			; no
	calls	close	,<#lun.ou>	; yes, close it up please
10$:	calls	recsw	,<#'R>		; get the file
	tst	r0			; did it work
	bne	20$			; no
	calls	printm	,<#1,#200$>	; yes, say so if we are local
	br	100$			; bye
20$:	calls	printm	,<#1,#210$>	; it failed, say so iff local
100$:	call	clostt			; release the terminal
	mov	oldpau	,pauset		; restore old pause setting
	message
	return

	.enabl	lc
200$:	.asciz	/Receive complete/<cr><lf>
210$:	.asciz	/Receive failed/<cr><lf>
	.even
	.dsabl	lsb


	global	<oldpau	,pauset	,throtl>


	.sbttl	send a file to pc
	.enabl	lsb
	.enabl	lc


c$send::$name	<SEN>
	clr	index			; initialize for directory i/o
	tst	inopn			; is an input file currently open
	beq	5$			; no
	calls	close	,<#lun.in>	; yes, pelase close old file up
5$:	call	opentt			; open and initialize the terminal
	mov	#argbuf	,r1		; address of command line buffer
	tstb	@r1
	bne	10$			; yes
	message	<?Syntax   SEND Filename.type>,cr
	br	100$
10$:	tst	sermode			; are we a server now ?
	bne	15$			; yes, don't delay sending it.
	tst	remote
	beq	15$
	calls	suspend	,<sendly>	; give them a moment to type REC

15$:	mov	#srcnam	,r2		; /36/ destination address
	clrb	asname			; /36/ no SEND f1 [AS] f2
20$:	tstb	@r1			; /36/ and of the line today ?
	beq	40$			; /36/ yes, exit this loop
	cmpb	@r1	,#40		; /36/ if a space they may have typed
	beq	30$			; /36/ SEND file [as] file
	movb	(r1)+	,(r2)+		; /36/ ok so far, copy the name over
	br	20$			; /36/ next please
30$:	inc	r1			; /36/ found a <SPACE> in the cmd line
	cmpb	@r1	,#40		; /36/ assume not trailing control char
	blos	40$			; /36/ no
	clrb	@r2			; /36/ insure source name(s) asciz
	calls	iswild	,<#srcnam>	; /36/ check for wildcarding on the name
	tst	r0			; /36/ if NE, then wildcarded
	bne	40$			; /36/ can't rename outgoing if wildcard
	strcpy	#asname	,r1		; /36/ not wildcard, copy it
40$:	clrb	@r2			; /36/ insure source name .asciz
	call	getnxt			; get the first filename please
	tst	r0			; did it work ?
	bne	100$			; no. Getnxt will send the error pak
	calls	sendsw	,<#'S>		; now send the file
	tst	r0			; did it work ?
	bne	90$			; no
	calls	printm	,<#1,#200$>	; yes
	br	100$			; bye
90$:	calls	printm	,<#1,#210$>	; no
100$:	call	clostt			; exit
	message
	clrb	asname			; /36/ insure no more alternate names
	return
	
	.dsabl	lsb

	global	<cmdbuf	,filsiz	,index	,inopn	,sermod	,srcnam	,sendly>
	
200$:	.asciz	/Send complete/<cr><lf>
210$:	.asciz	/Send failed/<cr><lf>
	.even



	.sbttl	call the server




c$serv::$name	<SER>			; allow patching this out (why??)
	clr	notatt			; assume attached
	tstb	argbuf			; if nothing for arg, do normal server
	beq	20$			; ok, do normal server thing
	calls	getcm0	,<#argbuf,#serlst>; no, check for server cmd argument
	tst	r0			; did we find a valid one
	bmi	110$			; no
	jsr	pc	,@r1		; yes, process it
	tst	r0			; did this work?
	bne	100$			; no, exit please

20$:	clr	mcrcmd			; always allow remote FIN command
	tst	notatt			; are we attached today?
	bne	30$			; no
	print	#sertxt			; dump a message out please
30$:	call	opentt			; get the line open please
	direrr	r0			; print any errors out
	calls	cantyp	,<#ttname,#lun.ti>; dump garbage perhaps
	call	server			; and do it
	call	clostt			; we came back ?
	clr	notatt			; assume attached now
100$:	clr	r0
	return				; ok


110$:	message	<Invalid SERVER subcommand>,cr
	return


	.enabl	lsb

sr$det:	tstb	ttdial			; insure a SET LINE command was done
	beq	110$			; no, thats an error please
	message	<Server detaching from TI:>,cr
	call	detach			; detach from the current TI:
	tst	r0			; did this work ok ?
	bne	90$			; no
	mov	sp	,notatt		; no longer attached to ti:
	clr	r0
	br	100$
90$:	direrr	r0			; say why please
100$:	return

110$:	message	<You must use the SET LINE command before detaching the server>
	message
	mov	sp	,r0
	return

	.dsabl	lsb


	$cmglob	=	0

	command	serlst	,DETACH	,3	,sr$det
	command	serlst


	global	<detach	,lun.ti	,notatt	,server>


	.save
	.psect	$pdata

sertxt:

.ascii #Kermit Server running on PDP-11 host. Please type your escape sequence#
.byte  cr,lf
.ascii #to return  to your local machine.  Shut down the server by  typing the#
.byte  cr,lf
.asciz #Kermit BYE command on your local machine.#<cr><lf>

	.even
	.restore




	.sbttl	open and close a link




opentt::tst	linksts			; already open ?
	bne	100$			; yes, ignore it then
	tst	remote			; if remote
	beq	10$			;  then ttname := ourname
	tst	inserv			; but not if we are a server
	beq	5$			; and the line number has been
	tstb	ttname			; set already
	bne	10$			;
5$:	calls	gttnam	,<#ttname>	; get the terminal name here
10$:	calls	ttyini	,<#ttname,#lun.ti,#ter$pa>
	tst	r0
	bne	100$
	calls	ttysav	,<#ttname>	; save terminal settings
	calls	ttyset	,<#ttname>	; set some things now
	mov	sp	,linksts	; flag it as being open
100$:	return


clostt::save	<r0>
	calls	ttyfin	,<#ttname,#lun.ti>
	calls	ttyrst	,<#ttname>
	clr	linksts
	unsave	<r0>
	return
	
	global	<linksts,remote	,rwdata	,rwsize	,ttname>
	global	<gttnam	,ttyini	,ttyrst	,ttysav	,ttyset>
	global	<chksiz	,chktyp	,defchk	,mx$try	,maxtry>
	global	<inserv>



	.sbttl	exit kermit-11

c$exit::call	sd$off
10$:	tst	outopn
	beq	20$
	calls	close	,<#lun.ou>
20$:
	jmp	exit

	global	<exit>



c$nop::	return				; a NO-OP command ???






	.sbttl	bye, finish and get



rmtbye::
c$bye::	$name	<BYE>
	call	ckremote		; must not be remote for this
	bcs	100$			; we are remote, abort this
	call	rembye			; tell a server to logout
100$:	return				; back to command loop


rmtfin::
c$fin::	$name	<FIN>
	call	ckremote		; must not be remote for this
	bcs	100$			; we are remote, abort this
	call	remfin			; tell a server to exit
100$:	return				; back to command loop


rmtget::
c$get::	$name	<GET>
	call	ckremote		; must not be remote for this
	bcs	100$			; we are remote, abort this
	clrb	asname			; /36/ assume no names
	call	nextarg			; /36/ if two files present use last one
	tstb	@r1			; /36/ for new name (first file only)
	beq	10$			; /36/ nothing present
	strcpy	#asname	,r1		; /36/ something there, copy it please
	clrb	-(r1)			; /36/ get rid of last arg now
10$:	calls	remget	,<#argbuf>	; tell a server to get a file
	tst	r0			; success ?
	beq	100$			; yes
	calls	printm	,<#1,#gmsg>	; no
100$:	message
	clrb	asname			; /36/ always fix [as file] name to null
	return				; back to command loop

gmsg:	.asciz	/Get from server aborted/<cr><lf>
	.even


rmtspa::$name	<SPA>
	call	remspa			; issue a space ('U') generic command
100$:	return


rmthlp::$name	<HEL>
	call	remhlp			; issue a space ('U') generic command
100$:	return


rmthos::$name	<HOS>
	calls	remhos	,<#argbuf>
	return


rmtdir::$name	<RDI>
	calls	remdir	,<#argbuf>	; issue a dir ('D') generic command
	return


rmttyp::$name	<TYP>
	calls	remtyp	,<#argbuf>	; issue a typ ('T') generic command
	return


rmtwho::$name	<WHO>
	calls	remwho	,<#argbuf>	; issue a who ('W') generic command
	return


rmtdel::$name	<DEL>
	calls	remera	,<#argbuf>	; issue a erase ('E') generic command
	return


rmtcwd::$name	<CWD>			; Change Working Directory
	mov	#argbuf	,r1		; check for optional password
10$:	tstb	@r1			; find eos yet ?
	beq	30$			; yes exit
	cmpb	(r1)+	,#40		; look for a space
	bne	10$			; nothing
20$:	tstb	@r1			; null here ?
	beq	30$			; yes, no password present
	calls	remcwd	,<#argbuf,r1>	; send password over also
	br	100$			; and exit
30$:	calls	remcwd	,<#argbuf,#null>; send the command to the server
100$:	return				; without any password trash


rmtlgi::$name	<LOG>			; Login
	mov	#argbuf	,r1		; check for optional password
10$:	tstb	@r1			; find eos yet ?
	beq	30$			; yes exit
	cmpb	(r1)+	,#40		; look for a space
	bne	10$			; nothing
20$:	tstb	@r1			; null here ?
	beq	30$			; yes, no password present
	clrb	-1(r1)			; insert null over the <space>
	calls	remlgi	,<#argbuf,r1>	; send password over also
	br	100$			; and exit
30$:	calls	remlgi	,<#argbuf,#null>; send the command to the server
100$:	return				; without any password trash


rmtren::$name	<REN>			; do a remote rename please
	call	gettwo			; insure both arguments are here
	tst	r0			; but did that work out ok ?
	bne	100$			; no, just exit then please
	calls	remren	,<#cmdbuf,#argbuf>; send a generic 'r' please
100$:	return				; bye


rmtcop::$name	<COP>			; do a remote Kopy please
	call	gettwo			; insure both arguments are here
	tst	r0			; but did that work out ok ?
	bne	100$			; no, just exit then please
	calls	remcop	,<#cmdbuf,#argbuf>; send a generic 'K' please
100$:	return				; bye



ckremo:	tst	remote			; are we local or remote
	bne	100$			; local, ok
	clc				; ok
	return				; bye
100$:	message	<KERMIT is not running as a LOCAL Kermit>,cr
	sec
	return

	global	<asname	,cmdbuf	,argbuf>
	global	<rembye	,remdir	,remera	,remfin	,remget	,remhlp>
	global	<remspa	,conesc	,remote	,doconn	,ttdial	,ttname>
	global	<remcop	,remren>





	.sbttl	get the next command
	.enabl	lsb

;	R E A D C M D
;
;	input:	@r5	buffer address
;		2(r5)	prompt address
;	output:	r0	error
;		r1	byte count


readcmd:tst	cmdlun			; reading from indirect file
	beq	50$			; no, do a read on the terminal
	calls	getrec	,<@r5,#lun.ta>	; yes, try to read a record
	tst	r0			; did it work ?
	bne	30$			; yes

	tst	tkecho			; should we echo the prompt and
	beq	100$			; the command string read ?
	print	2(r5)			; yes, print the passed prompt
	print	@r5	,r1		; and also echo the command.z
	message				; crlf
	br	100$			; and exit with a success read

30$:	cmp	r0	,#ER$EOF	; hopefully, it's end of file
	beq	40$			; yes
	message	<Read error on TAKE file: >
	direrr	r0			; no, print the RMS error number
40$:	tst	sy.ini			; from kermit.ini ?
	bne	45$			; yes, don't print the message
	message	<Current TAKE file closed>,cr
45$:	calls	close	,<#lun.ta>	; close the file on any errors
	clr	sy.ini			; no longer a kermit.ini
	clr	cmdlun			; and read a command from TI:

50$:	tst	mcrcmd			; did we ever get a mcr command
	beq	60$			; no
	mov	#-1	,r0		; yes, fake end of file then
	br	100$			; bye
60$:	calls	getmcr	,<@r5>		; no mcr command yet, check for it
	mov	r0	,r1		; did we get any characters there?
	clr	r0			; say no errors
	mov	r1	,mcrcmd		; flag if we got a mcr command
	bne	100$			; and set eof next time we get called
	
70$:	print	2(r5)			; print the prompt
	calls	echo	,<#0>		; ensure the local terminal echoes
	calls	kbread	,<@r5>		; read a record from the terminal
100$:	return				; bye


tkecho::.word	-1			; if <> then echo the take file

	global	<cmdlun	,argbuf	,cmdbuf	,er$eof	,lun.ta	,mcrcmd>

	.dsabl	lsb



	.sbttl	the LOCAL command (basically, a NOP)


c$loc::	$name	<LOC>
	call	loacmd
	calls	getcm0	,<#argbuf,r0>
	tst	r0
	bmi	110$
	mov	r0	,r3
	call	loacmd
	calls	getcm1	,<#argbuf,r0,r3>
	tst	r0
	bmi	110$
	jsr	pc	,@r1
110$:	return


	global	<argbuf>



	.sbttl	the REMOTE command
	.enabl	lsb

c$rem::	$name	<REM>
	call	ckremo			; insure that we are remote
	bcs	120$			; no, exit then
	call	loarem			; get the command overlay in
	calls	getcm0	,<#argbuf,r0>	; and try it please
	tst	r0			; did we find the remote command
	bmi	110$			; no
	mov	r0	,r3		; save the index (can't use r1)
	call	loarem			; get the overlay resident
	calls	getcm1	,<#argbuf,r0,r3>; get any required args for command
	tst	r0			; now could we get command arguements?
	bmi	120$			; no
	jsr	pc	,@r1		; dispatch on it now please
	return
110$:	message	<Unrecogized REMOTE command>,cr
120$:	return

	.dsabl	lsb

	global	<loarem>


c$cwd::	strcpy	#defdir	,#argbuf	; CWD command, same as SET DEF command
	clr	r0			; no errors
	return				; exit


c$test::calls	sdirini	,<#argbuf>
10$:	call	sdodir
	tst	r0
	bne	20$
	mov	r1	,-(sp)
	mov	sp	,r1
	.print	r1	,#1
	tst	(sp)+
	br	10$
20$:	decout	r0
	.newline
	return

	global	<sdirini,sdodir>

c$home::clrb	defdir
	clr	r0
	return

	.sbttl	get command from the attached terminal

;	G E T C M D
;
;	input:	nothing
;	output:	r0	command index in dispatch table
;		r0	-1 (CMD$BAD) for invalid command
;			-2 (CMD$EX)  for exit
;	side effects:	cmdbuf written into

	cvtarg	=	4 + 10 + 20 + 40 + 200

	.name	=	0
	.minle	=	2
	.cmdad	=	4
	.cmdar	=	6
	.cmdat	=	10

	cmd$un	==	-4
	cmd$ab	==	-3
	cmd$ex	==	-2
	cmd$bad	==	-1

getcmd::clrb	argbuf
10$:	clr	cmdnum
	mov	#cmdbuf	,r4		; point to the command buffer
	calls	readcmd	,<r4,#prompt>	; get from current input stream
	tst	r0			; and exit if it failed for whatever
	bne	120$			; oops
	tst	cccnt			; time to exit on control C ?
	bne	120$			; yep
	calls	cvt$$	,<r4,r1,#cvtarg>; remove junk, convert to upcase
	tst	r0			; anything left ?
	beq	10$			; no, reprompt and try again
	clrb	cmdbuf(r0)		; insure .asciz please
	call	loacmd			; get the command list overlay
	calls	getcm0	,<r4,r0>	; search for the command
	mov	r1	,cmdadr		; store address of routine away
	mov	r0	,cmdnum		; store index of command away
	mov	r0	,r3		; did we actually find a command ?
	bmi	110$			; no
	call	loacmd
	calls	getcm1	,<r4,r0,r3>	; now get the rest of the commandline
	tst	r0			; or prompt for extra. Did it work
	bmi	110$			; no
100$:	mov	cmdnum	,r0
110$:	return

120$:	mov	#cmd$ex	,r0
	return


	global	<loacmd	,prompt>


	.sbttl	getcm1	check for additional input needed

;	G E T C M 1
;
;	input:	@r5	current command buffer
;		2(r5)	command table address
;		4(r5)	index of the current command
;
;	output:	r0	index of current command or < 0 for error
;		argbuf	any additional input or rest of the command line



getcm1:	save	<r1,r2,r3>
	mov	@r5	,r1
	scan	#40	,r1		; look for a space that might delimit
	tst	r0			; the command name from an argument
	beq	30$			; nothing there
	add	r1	,r0		; point to the string after the space
	copyz	r0,#argbuf,#200		; copy the command arg over please
	br	100$			; and exit

30$:	mov	4(r5)	,r3		; get the command index
	mul	#$listl*2,r3		; if no arg given, see if one is needed
	add	2(r5)	,r3		; add in base address of command table
	mov	.cmdar(r3),r3		; get the argument prompt now
	tstb	@r3			; anything there that is required ?
	beq	100$			; no
40$:	.print	r3			; yes, prompt for it and read it now
	calls	kbread	,<#argbuf>	; read a command from the keyboard
	tst	r0			; and exit if it failed for whatever
	bne	90$			; oops
	tst	cccnt
	bne	90$
	calls	cvt$$	,<#argbuf,r1,#cvtarg>; remove junk, convert to upcase
	tst	r0			; anything left ?
	beq	40$			; no, reprompt and try again
	clrb	argbuf(r0)		; insure .asciz
	br	100$


90$:	mov	#cmd$ab	,r0
	br	110$
100$:	mov	4(r5)	,r0
110$:	unsave	<r3,r2,r1>
	return


	global	<argbuf	,cmdadr	,cmdbuf	,cmdnum>



	.sbttl	getcm0	find the command in the table


;	input:	@r5	command buffer
;		2(r5)	first command descriptor block
;	output:	r0	command index
;		r1	dispatch address
;
;	errors:	r0	-1 (CMD$BAD)	unrecognized command
;		r0	-4 (CMD$UN)	not unique
;
;	descriptor block:
;
;		.word	commandname text
;		.word	minimum length
;		.word	address of command itself
;		.word	required argument prompt or a null for nothing
;		.word	type of argument



getcm0::save	<r2,r3,r4>
	clr	-(sp)			; /39/ temp
	mov	@r5	,r1		; the passed command buffer
	strlen	r1			; get the command length
	mov	r0	,r3		; error if nothing is there
	beq	110$			; oops
	clr	r2			; length := 0
10$:	scan	(r1)+	,#cmdch		; is this character ok in name?
	tst	r0			; find it in the list ?
	beq	20$			; no, we have found enough
	inc	r2			; command name len and pointer
	sob	r3	,10$		; next

20$:	tst	r2			; anything useful in cmd line
	ble	110$			; No leading letters ????
	mov	2(r5)	,r4		; the list of edit commands
	clr	r3			; R3 will have the command #

30$:	tst	.name(r4)		; anything left in the command list
	beq	110$			; no
	strlen	.name(r4)		; get the length of the command name
	calls	instr, <.name(r4),r0,@r5,r2> ; the next command?
	cmp	r0	,#1		; /39/ find anything ?
	bne	35$			; /39/ no
	mov	r0	,@sp		; /39/ save it
35$:	cmpb	r2	,.minle(r4)	; check if command length is ok
	blo	40$			; no, not enough for the command
	 dec	r0			; if match = position 1 we have it
	 beq	100$			;  then 'found the command'
40$:	inc	r3			; commandnum := commandnum + 1
	add	#$listl*2,r4		; cmdsaddr   := succ( cmdsaddr)
	br	30$


100$:	mov	r3	,r0		; return command index and exit
	mov	.cmdad(r4),r1		; return the command address also
	br	200$

110$:	mov	#cmd$ba	,r0		; bad command
	dec	@sp			; /39/ command not unique?
	bne	120$			; /39/ no
	mov	#cmd$un	,r0		; /39/ yes, say so
120$:	br	200$

200$:	tst	(sp)+			; /39/ pop it
	unsave	<r4,r3,r2>
	return

cmdch:	.asciz	/0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-@_./
	.even



	.sbttl	cctrap	the control C trap


cctrap::cmp	cccnt	,#cc$max
	bhi	100$
	calls	setcc	,<#cctrap>
	inc	cccnt
	return

100$:	tst	inserv
	beq	110$
	call	rstsrv
110$:	jmp	c$exit

	global	<cccnt	,exit	,inserv	,rstsrv>




;	D I R E R $
;
;	called from DIRERR value    macro

	.enabl	lsb


direr$::mov	r0	,-(sp)		; direrr will select whether or not
	mov	4(sp)	,r0		; to call rms error or FIP (or DIR)
	beq	10$			; error based on whether the error
	calls	syserr	,<r0,#errtxt>	; code is < 0 (implies RMS) or > 0
	print	#errtxt			; which  implies either FIP  (RSTS)
	message				; or a DIRECTIVE error (RSX).  Thus
10$:	mov	(sp)+	,r0		; for RSX all error codes should be
	mov	@sp	,2(sp)		; made > 0 for non RMS errors.
	tst	(sp)+			; error 0 is a no-op.
	return

	.dsabl	lsb

	.sbttl	get/and or read second command argument

;	input:	argbuf	command args
;	output:	cmdbuf	first arg
;		argbuf	second arg
;		r0	error code from read if done, else zero


gettwo::save	<r1,r2>			; save temps please
	mov	#argbuf	,r2		; point to the arguement buffer
	tstb	@r2			; anything there (should be) ?
	beq	100$			; no
	dec	r2
10$:	inc	r2			; next byte
	tstb	@r2			; We have to finish parsing this
	beq	20$			; end of it, prompt for 'To:'
	cmpb	@r2	,#40		; find a space yet ?
	bne	10$			; no
	clrb	(r2)+			; yes, make it .asciz
	copyz	#argbuf	,#cmdbuf	; save the first part of the arg
	br	30$			; got old and new so we are all set

20$:	mov	#argbuf	,r2		; point to the 'to:' part to read
	copyz	r2	,#cmdbuf	; save the from part
	print	#200$			; and read the rest of it
	calls	echo	,<#0>		; ensure terminal can echo
	calls	kbread	,<r2>		; do it
	tst	r0			; did it work ?
	bne	100$			; no
	calls	cvt$$	,<r2,r1,#377>	; yes, remove all junk
	tst	r0			; anything left ?
	beq	20$			; no
	add	r2	,r0		; yes, make it .asciz
	clrb	@r0			; simple

30$:	copyz	r2	,#argbuf	; return arg number two in argbuf
	clr	r0			; no errors please
100$:	unsave	<r2,r1>			; pop temps and exit
	return

200$:	.asciz	/To:   /
	.even



	
nextar::mov	#argbuf	,r1
10$:	tstb	@r1
	beq	100$
	cmpb	(r1)+	,#40
	bne	10$
100$:	return




	.end	kermit
