;[SIMTEL20]PS:MODEM.MAC.314, 10-Apr-85 19:42:18, Edit by WANCHO
; Restored net binary mode negotiations to be done only if N option used.
; Made net binary code into subroutines NETBON and NETBOF.
;[SIMTEL20]PS:MODEM.MAC.313,  9-Apr-85 00:40:19, Edit by MRC
; Added conditional code for PANDA MONITR's handling of network binary
;mode negotiations and doubling of FFH's.
;[SIMTEL20]PS:MODEM.MAC.312,  9-Feb-85 09:42:10, Edit by WANCHO
; No longer writes ITS Binary Header
;[SIMTEL20]PS:MODEM.MAC.311,  9-Jan-85 07:35:40, Edit by WANCHO
; Forgot to do SFPTR% to set pointer back if input file was tested for
; ITS mode and wasn't - in IPNFIL.
;[SIMTEL20]PS:MODEM.MAC.310,  7-Jan-85 20:43:45, Edit by WANCHO
; Reorganized file type determination code to allow for ITS Binary
;  Mode files of bytesize 8 (as written by TOPS-20 SQ) as well as 36.
; ITS Binary files are now defaultly written with bytesize 8 instead of 36.
;[SIMTEL20]PS:MODEM.MAC.309, 21-Nov-84 09:33:26, Edit by WANCHO
; Cleared F%ITS and F%B in MSEND and SEND to ignore previous settings
;  by IPNFIL or by user.
;[SIMTEL20]PS:MODEM.MAC.308, 14-Nov-84 21:40:04, Edit by WANCHO
; Added push/pop of 2 in CSUM.  Checksum mode should now work again!
;[SIMTEL20]PS:MODEM.MAC.307, 16-Oct-84 18:04:29, Edit by WANCHO
; Set the remote device speed to 0, per BillW's suggestion, in HALT
; Added code in Help to allow paging of the help display, from Frank DaCruz
;[SIMTEL20]PS:MODEM.MAC.306, 16-Oct-84 06:33:28, Edit by WANCHO
; Fixed logical error in INIWAI - was aborting if not C or CAN
;[SIMTEL20]PS:MODEM.MAC.305, 13-Oct-84 21:52:24, Edit by WANCHO
; HALT now closes and releases the JFN on MODEM-DEVICE: so that a
; superior process, such as DIAL, will work in a v6.n environment.
;[SIMTEL20]PS:NMODEM.MAC.304,13-Oct-84 20:56:34, Edit by WANCHO
; ABORT now calls CLSFIL to avoid the "invalid simultaneous access" problem
; Added OF%THW to OPENF% of TTY or PTY
; Changed 10B4 to 10B5 in same places
;
;[SIMTEL20]PS:MODEM.MAC.303,  5-Oct-84 18:49:06, Edit by WANCHO
;
; Reinstated the GETTIM routine and use its value for the GETSTR t/o.
;
; Moved the checksum calculation in RECEIVE to AFTER receiving the
;  remote checksum to avoid a potential timing problem.
;
;[SIMTEL20]PS:MODEM.MAC.302, 17-Sep-84 00:27:51, Edit by WANCHO
; The following details the changes made in the jump from 249 to 302.
; Most are mainly changes to fully implement the timeout and recovery
; features in MDM730.  Others fix long standing and some somewhat
; obscure bugs.
;
; This list is mostly in the sequential order of the program source:
;
; 1.  Due to the extent of the changes, especially the changes in the
; timeout mechanism, the major version number of the program has been
; upped from 4.0 to 5.0, and the Edit number jumped to the 300 series.

; 2.  This version now contains the MACRO directives SALL and FLBLST
; for cleaner listings, and contains the LINK directives /NOINITAL and
; MODEM/SAVE.  Ignore the %LNKTDS error.  That latter directive means
; the LINK step will automatically do the SAVE for you.

; 3.  The timeout counter TIMCNT is now a register (11).
;
; 4.  A new macro TMOSET was added to make setting timeout values
; easy, and all the timeout values are now easily changed variables.
;
; 5.  Subroutines GETACK and GETNAK were added.  Each will wait up to
; 15 seconds for an ACK or up to two minutes for a NAK, respectively.
; These routines replaced those sections of code where a single ACK or
; NAK was gotten with no timeouts, especially in MSEND and elsewhere.
;
; 6.  All GETCHR calls are now preceded by a timeout setting and
; GETCHR clears and resets the timer to that value.  GETCHR returns +1
; if a character is received within the timeout limit, else it returns
; +2.  The timer is cleared in either case.
;
; 7.  MSEND now sends a 75H ("u") if the remote sends a bad checksum
; back on the received filename, and tries again.
;
; 8.  MSND.F clears F%MULT before returning to CMDLP.
;
; 9.  SEND now calls DISINT to disable interrupts if the terminal is
; used as the MODEM-DEVICE.  Because it had failed to do this, the
; checksums returned by the remote for certain filenames always
; failed.  Likewise, spurious received noise would mysteriously cause
; the program to appear to hang because this was not called.
;
; 10. SEND also clears F%MULT just in case...
;
; 11. GETTIM has been flushed in favor of using known reasonable
; timeout values for GETSTR.
;
; 12. A two-minute timeout was added to SFILE's INIWAI loop, waiting
; for a "C", a NAK, or now also a CAN.
;
; 13. SFILE's DOEOF now sends the EOF and waits for an ACK in a loop
; (without a timeout as per MDM730).  This may change.
;
; 14. SFILE's ACKWAIT will keep trying for an ACK, NAK, or CAN in a
; timout loop up to 192 seconds or 192 characters, whichever comes
; first, per MDM730, before aborting.  However, up to 10 NAK retries
; still applies.
;
; 15. TYPFIL does not display the trailing and usually wrong info
; about a wild-card file, just the wildcard name.
;
; 16. RECEIVE clears F%MULT before the test is made to see if the
; request is for a batch mode receive.
;
; 17. ININAK in RECEIVE now tests for and allows first trying CRC mode
; (with up to 6 ten-second timeouts), then CHECKSUM mode, with up to
; 10 sixteen-second timouts waiting for a NAK.  Both checks also look
; for CAN.
;
; 18.  All subsequent calls to GETCHR are with sixteen-second timeouts
; that go to WAITQ1 first, which calls WAITQ to wait for the line to
; clear for at least one second before jumping back to SNDNAK.
;
; 19. GETSTR now has its own 20-second timeout and uses SOUT to
; display to the controlling console if a third line is in use, and
; its +1 return also goes to WAITQ1.
;
; 20. RECEIVE now keeps a separate count of records received in RECNUM
; for possible display to the controlling terminal.  This count
; doesn't rollover at 255...
;
; 21. All combinations of "movei 2,ACK" then "call sndchr" were
; replaced by a "call SNDACK" where SNDACK has the movei and falls
; through to SNDCHR.
;
; 22. ABORT and RCVERR call WAITQ before eventually jumping back to
; CMDLP.
;
; 23. GETFIL revamped to add the equivalent of MDM730's HSNAK routine,
; plus other timeouts and retries ala MDM730.  GETFIL retries
; indefinitely, but HSNAK will quit after three minutes per MDM730.
;
; 24. GFILLP uses register 7 instead of 3 so as not to get stomped on
; by the GETCHR routine.
;
; 25. MULERR has been flushed.
;
; 26. SETTIM and INTER have been replaced by a heavily modified
; version of the SETTIM/TIMINT approach used in MMAILR.  The new
; routine also sets PC%USR for the timeout return address which was
; NOT set by the old version!
;
; 27. The HELP text has been reformatted.  However, it still rolls off
; the screen because page mode has already been defeated at that
; point.  This will probably be changed later.
;
;[SIMTEL20]PS:NMODEM.MAC.249,10-Sep-84 03:54:22, Edit by WANCHO
; Fixed no more files detection on batch receive in GETFIL
;[SIMTEL20]PS:NMODEM.MAC.248,10-Sep-84 00:31:10, Edit by WANCHO
; Don't display block numbers if View (F%V) is set
;[SIMTEL20]PS:NMODEM.MAC.247, 9-Sep-84 18:39:51, Edit by WANCHO
; changed F%ARPA to F%DDN.
; changed ARPANet to DDN.
; corrected various typos.
; changed minimum timeout to 10 seconds instead of 3.
; don't send ^Vs in filenames!
; added code from DIAL to set up slaved port
; fixed nout in SEND also, and made RECEIVE display RECSAV instead of
; LSTREC, which is modulo 255...
;[SIMTEL20]PS:MODEM.MAC.246,  8-Sep-84 21:50:42, Edit by WANCHO
; expanded nout to four places (and backspaces)
;[SRI-KL]PS:MODEM.MAC.244, 21-Apr-84 14:20:42, Edit by BILLW
; add return instruction in DISINT!
;NMODEM.MAC.237,  9-Jan-84 19:54:24, Edit by BILLW
; add multiple send.  Have errors occuring when receiving or
; transmitting a filename clean up after themselves.
;NMODEM.MAC.206,  2-Nov-83 17:59:34, Edit by BILLW
; things to make multiple receive work.  Include ^Z in file name
; checksum, do only CHKSUM type transfers, wait 2 secs bfore FN NAK,
; quote all filename chars with ^V
;  (doesn't matter on chars that don't need it!),
;NMODEM.MAC.201, 19-Oct-83 15:48:21, Edit by BILLW
; multiple file receive added.  Major version set to 4, edit to 200.
;NMODEM.MAC.20, 31-Jul-83 18:05:41, Edit by BILLW
; fixed an obscure bug with FF quoting in ARPA mode. (SNDSTR)
;MODEM.MAC.133, 30-Jun-83 17:36:09, Edit by BILLW
; implement . subcommand for "T" command and subcommand to set speed of
; terminal.  If the speed is set, then it is reset to 0 on "D" command.
; examples:	MODEM>T.300		MODEM>CT115T.9600
; the speed is not altered in XMODEM mode (eg: only valid for "calling"
; another terminal.  This routine is in the wrong place to handle
; autodialers with multiple speeds...
;MODEM.MAC.128, 30-Jun-83 16:22:43, Edit by BILLW
; make TTY mode use multiple forks.  Improve error reporting.
;Modem.mac.124, 29-Apr-83 15:47:39, Edit by BILLW
; remove DDN hacks (new monitors work better?) still available via option
; fix logging macros, add more logging, change numbers to Hex in log file
; fix timing problems in CRC mode. 4 seconds won't even cover xmit time!
; send "C" immediately if we are MASTER device.
;MODEM.MAC.115, 11-Nov-82 17:37:47, Edit by BILLW
; 10 second pause in receive before sending initial NAK/"C"
;MODEM.MAC.112,  8-Nov-82 16:57:17, Edit by BILLW
; fixed bugs in CRC receive.  added debug message if switch to checksum
;MODEM.MAC.107,  7-Nov-82 22:38:01, Edit by BILLW
; added crc16 option on receive.  If a SOH is not received within 4
; seconds, we switch back to checksum mode
;MODEM.MAC.105,  5-Nov-82 16:28:29, Edit by BILLW
; added crc16 option to SEND option.  (converted 8080 code to DEC20ness)
;MODEM.MAC.91, 28-Oct-82 14:46:06, Edit by BILLW
; horrible hacking at RMLAST and GETEOF to prevent extra characters
; (nulls or ^Zs) at the end of a transferred file.
;MODEM.MAC.71, 21-Oct-82 14:20:54, Edit by BILLW
; automatically detect TVTs
;MODEM.MAC.63, 16-Oct-82 21:42:38, Edit by BILLW
; added READY to receive/xmit file message at beginning of transfer
;MODEM.MAC.62, 16-Oct-82 16:45:47, Edit by BILLW
; made timouts for downloading >> timeouts for uploading.  This is
; because it seems to be very dangerous to send text to a micro that
; isn't listening.  In particular, they can be acknowledging an old
; packet, while the current packet is being transmitted.  On the other
; hand, to lose a character due to buffer overflow is quite common
; when uploading at high speeds, so that it is in the best interests of
; throughput to make this timout as short as possible.
;MODEM.MAC.58, 12-Oct-82 19:09:47, Edit by WANCHO
; extended 10-second timeout value to 15 seconds and corrected
; some spelling errors in Help info.
;MODEM.MAC.52,  7-Oct-82 14:04:40, Edit by BILLW
; fixed several bugs in TAC/TIP code (TACs aren't the same
;  as TIPs - they also need WILL TRNBIN)
; support of ITS/LMODEM .COM file format, and automatic detection of same.
;  (sixbit/DSK8/ in word 0, rest just 4 8bit bytes/word) ("I" option)
; DMESG debugging macro writes to MODEM-DEBUG.LOG file
; fixed transmission of extra block for file with even number of blocks
;MODEM.MAC.25, 27-Sep-82 16:51:41, Edit by BILLW
; make it work woth Tip/TAC DDN connections
;  DO TRANSMIT BINARY negotiaition
;  transmit FFs twice
; turn off PAUSE (on) COMMAND mode
; check for incrementing block numbers
; fix bug that typed backspaces even when using .priou for transfer
; leave null instead of ^Z at EOF
; (thanks to Ted Shapin (ADMIN.SHAPIN@isib) for the original fixes to
;  some of these problems, and to Frank Wancho, (FJW@MIT-MC) who
;  explained how to make it work over the DDN)
;MODEM.MAC.158, 19-Jul-82 13:46:23, Edit by BILLW
; re-enable links on exit.
;MODEM.MAC.154,  2-Jul-82 18:09:37, Edit by BILLW
; made time-out time dependent on transmission speed

	title	MODEM	File transfer program for MICROS <-> TOPS-20

ifndef SRIKL,
ifndef SRIAI,

VWHO==	 7
VMAJOR== 5
VMINOR== 0
VEDIT==	 ^d314

;	Written By Bill Westfield for SRI International Networks Group
;	Bugs/suggestions/questions to BillW@SRI-KL


comment	~

	This program is a Tops-20 implementation of the defacto-standard
	MODEM2 File Transfer Protocol as devised by Ward Christensen?.

	The protocol itself is documented in SRI-KL:MODEM2.PROTO

	This program attempts to implement to standard user interface,
	IE you type commands like:

	MODEM  FILE
	to the Twenex EXEC


	Hooks are included to use an autodialer or a TTY line when
	the Tops-20 system is the "Master" console...

	~



	SEARCH	MACSYM,MONSYM
	SALL			;Supress macro expansions

	.DIRECTIVE FLBLST
	.TEXT "/NOINITIAL"
	.TEXT "MODEM/SAVE"

F==	0
P==	17
A==	15
B==	16
CRCC==	12		;16 bit CRC  (x^16+x^12+x^5+1)
CHKSUM= 13
RECNUM= 14
TIMCNT=	11

EOT==	"D"-100
ACK==	"F"-100
NAK==	"U"-100
SOH==	"A"-100
SUB==	"Z"-100
CAN==	"X"-100
BDNM==	"u"
IAC==	377				;DDN TELNET IAC
WILL==	373				; TELNET will 

    Source: geocities.com/westfw