/	INITIAL PROGRAM LOADER

/	LAST EDIT:	06-OCT-1991	05:00:00	CJL

/	MAY BE ASSEMBLED WITH '/F' SWITCH SET.

/	THIS PROGRAM IS USED TO  LOAD  BINARY  PROGRAMS  IN  .IPL FORMAT DIRECTLY.  AN
/	ERROR-FREE PATH IS ASSUMED BETWEEN THE PDP-8 (OR DECMATE) AND THE DATA SERVER.
/	SUCH A CONNECTION COULD BE ESTABLISHED BETWEEN THE PDP-8 AND A NEARBY PC USING
/	A SHORT RS-232 CABLE WITH NULL MODEM.  THIS UTILITY IS WRITTEN FOR THE EXPRESS
/	PURPOSE OF LOADING KERMIT-12 ON PDP-8 SYSTEMS WITHOUT IT.   ONCE KERMIT-12 HAS
/	BEEN LOADED, ITS USE SUPERSEDES THIS PROGRAM ENTIRELY.

/	THERE IS NO FLOW-CONTROL PROTOCOL PER SE BETWEEN  SYSTEMS,  SINCE  THE UTILITY
/	STORES  DATA  DIRECTLY  INTO  PDP-8  MEMORY  AND  THEREFORE  DOESN'T   REQUIRE
/	SYNCHRONIZATION DELAYS.    INITIAL  SYNCHRONIZATION  CAN  BE  ACCOMPLISHED  BY
/	SENDING A SINGLE  CHARACTER FROM THE PDP-8 TO THE SERVER SIDE WHICH STARTS THE
/	TRANSMISSION.  ALTERNATIVELY THE  PDP-8 PROGRAM CAN BE STARTED FIRST, THEN THE
/	SERVER CAN SEND DATA DIRECTLY TO THE PDP-8;  THIS ASSUMES THE ABILITY TO START
/	THE SERVER TRANSMISSION FROM THE SERVER'S END.

/	THIS  PROGRAM  IS  FOR  ANY MODEL PDP-8 WITH A  KL-STYLE  REMOTE  LINE  SERIAL
/	INTERFACE  OR  EQUIVALENT.   DEFAULT PARAMETER VALUES ARE CONSISTENT WITH  THE
/	DISTRIBUTION SETTINGS FOR KERMIT-12 ITSELF AND ARE EASILY CHANGED.  IT  CAN BE
/	MODIFIED FOR USE ON VARIOUS DECMATE MODELS, BUT WILL BECOME SOMEWHAT LARGER IN
/	THE  PROCESS  DUE  TO  THE  MUCH  GREATER  COMPLEXITY  OF  THE VARIOUS DECMATE
/	COMMUNICATIONS INTERFACES UNLESS THE COMPATIBLE PRINTER PORT IS CHOSEN (DEVICE
/	32/33).

/	THIS PROGRAM SHOULD ONLY BE USED  IF  NO  OTHER  METHOD  IS  AVAILABLE  AS THE
/	ASSUMPTION OF AN ERROR-FREE CONNECTION IS UNRELIABLE.  DISTRIBUTION PATHS SUCH
/	AS INTERNET FTP OR CONTACTING THE AUTHOR CAN  YIELD  COMPLETE  COPIES  OF  THE
/	PROGRAM DISTRIBUTION ON APPROPRIATE MEDIA WHERE APPLICABLE.
/	USAGE:

/	THIS PROGRAM IS  RESTRICTED  TO  A  SINGLE-FIELD  LOAD  ONLY.  SEVERAL VARIANT
/	VERSIONS MUST BE CREATED  TO  COMPLETELY LOAD KERMIT-12.  (AS OF THIS WRITING,
/	ONLY A FIELD ZERO AND  FIELD  ONE VERSION NEED BE CREATED.  HOWEVER, KERMIT-12
/	MAY BECOME LARGER!).  THE EXAMPLE GIVEN BELOW ILLUSTRATES USAGE FOR FIELD ONE.
/	REPEATING THE PROCESS WITH THE INTENDED CONTENTS  OF  ALL  OTHER  FIELDS  WILL
/	(EVENTUALLY) YIELD AN ENTIRE COPY OF KERMIT-12:

/	.R IPL1 (OR RUN DEV IPL1)

/	[PRESS AN APPROPRIATE KEY (SUCH AS CR) TO START WAITING FOR THE TRANSFER]

/	[THE DATA IS TRANSFERRED FROM THE OTHER SYSTEM AT THIS TIME AND THE PROGRAM
/	EXITS AUTOMATICALLY TO THE KEYBOARD MONITOR.]

/	.SAVE DEV FIELD1.SV 10000-17577=0

/	CHANGING  ALL  OF THE ONES IN  THE  ABOVE  EXAMPLE  TO  ZERO  WILL  YIELD  THE
/	FIELD-ZERO LOAD FILE FIELD0.SV AS WELL.   DEV  IS  ANY  CONVENIENT OS/8 DEVICE
/	SUCH AS SYS OR DSK.  (IT ISN'T  CRITICAL SINCE THESE FILES CAN BE DELETED ONCE
/	KERMIT-12 IS CREATED.) ONCE ALL PORTIONS OF KERMIT-12 HAVE  BEEN OBTAINED, THE
/	FOLLOWING COMMANDS WILL COMBINE THEM INTO THE STANDARD RELEASE FILE K12MIT.SV:

/	.LOAD DEV:FIELD1.SV/I,FIELD0.SV/I$	LOAD IMAGE  FILES FIELD1.SV, FIELD0.SV
/						WITH  /I SWITCH SET.  (FUTURE VERSIONS
/						MAY REQUIRE LENGTHENING THE COMMAND TO
/						ADD  MORE  FILES  SUCH  AS  FIELD2.SV,
/						FIELD3.SV,  ETC.)  $  INDICATES  USING
/						<ESC> TO TERMINATE LINE.

/	.SAVE DEV K12MIT=1			SAVE  COMPLETED  FILE ON ANY AVAILABLE
/						DEVICE DEV (PREFERABLY SYS).

/	CREATING THE VARIANT VERSIONS.

/	ONLY  ONE PARAMETER NEED BE CHANGED TO PRODUCE THE VARIOUS VERSIONS  REQUIRED.
/	SETTING  DFIELD=0  CREATES  A  VERSION  USED  TO  OBTAIN  THE FIELD-ZERO DATA.
/	SETTING DFIELD=1  CREATES  THE  FIELD-ONE  VERSION.    LEGAL VALUES FOR DFIELD
/	EXTEND UP TO  SEVEN.    THE  DEFAULT  VALUE IS ZERO.  NOTE THAT THE FIELD-ZERO
/	VERSION LOADS INTO FIELD  ONE  WHILE  ALL OTHER VERSIONS LOAD INTO FIELD ZERO.
/	THIS IS NECESSARY TO ALLOW  UNRESTRICTED  FILE  LOADING  WITHIN  THE  SELECTED
/	FIELD.   (OS/8 ITSELF GENERALLY BARS LOADING INTO 7600-7777 OF ANY FIELD, THUS
/	LOADING IS ACTUALLY RESTRICTED TO 0000-7577 OF THE SELECTED FIELD.)
/	OTHER ASSEMBLY PARAMETERS.

/	SETTING REC= 	XX			SETS THE REMOTE RECEIVE DEVICE CODE TO
/						XX (DEFAULT VALUE IS 40).

/	SETTING SEN=	XY			SETS THE REMOTE  TRANSMIT  DEVICE CODE
/						TO XY (DEFAULT VALUE IS 41).

/	SETTING BRATE=	NN			SETS THE  BAUD  RATE (FOR SYSTEMS THAT
/						SUPPORT  THIS  FEATURE  SUCH  AS   THE
/						VT-78) FROM A TABLE OF VALUES  (00-17)
/						AS FOLLOWS:

/						NN (OCTAL)	BAUD RATE

/						00		50
/						01		75
/						02		110
/						03		134.5
/						04		150
/						05		300
/						06		600
/						07		1200
/						10		1800
/						11		2000
/						12		2400
/						13		3600
/						14		4800
/						15		7200
/						16		9600
/						17		19200

/						(THE  DEFAULT  VALUE  IS  07  FOR 1200
/						BAUD COMMUNICATIONS.)
/	ASSEMBLY INSTRUCTIONS FOR ANY VARIANT VERSION.

/	ASSUMING A  CUSTOMIZED  FILE  SETUP  FOR  LOADING  FIELD  ZERO  DATA IS CALLED
/	IPL0.PA, THE FOLLOWING COMMANDS WILL CREATE IPL0.SV:

/	.PAL IPL0<IPL0/E/F			ASSEMBLE VARIANT FOR FIELD ZERO
/	.LOAD IPL0				LOAD THE BINARY
/	.SAVE DEV IPL0 ;10200=0			SAVE THE IMAGE ON ANY DEV (SUCH AS
/						SYS).

/	NOTE THE NON-STANDARD STARTING ADDRESS FOR THE FIELD ZERO VERSION (10200).

/	ASSUMING A CUSTOMIZED FILE SETUP FOR LOADING FIELD ONE DATA IS CALLED IPL1.PA,
/	THE FOLLOWING COMMANDS WILL CREATE IPL1.SV:

/	.PAL IPL1<IPL1/E/F			ASSEMBLE VARIANT FOR FIELD ONE
/	.LOAD IPL1				LOAD THE BINARY
/	.SAVE DEV IPL1=0			SAVE  THE  IMAGE  ON  ANY DEV (SUCH AS
/						SYS).

/	IF NECESSARY FOR  FIELD TWO AND FOLLOWING, ADDITIONAL VERSIONS CAN BE CREATED.
/	THE SAVE COMMAND WILL BE THE SAME AS FOR IPL1.
/	EQUATED SYSMBOLS.

/	LOADING FIELD DEFINED HERE.  REMOVE THE / FROM THE APPROPRIATE LINE.

/	DFIELD=	0			/LOAD FIELD ZERO DATA
/	DFIELD=	1			/LOAD FIELD ONE DATA

	IFNDEF	DFIELD	<DFIELD=0>	/DEFINE LOADING FIELD ZERO BY DEFAULT

/	REMOTE LINE RECEIVE DEVICE  CODE  DEFINED  HERE.  REMOVE THE / AND FILL IN THE
/	APPROPRIATE VALUE.

/	REC=	40			/REMOTE RECEIVE DEVICE CODE

	IFNDEF	REC	<REC=	40>	/DEFAULT RECEIVE DEVICE CODE IS 40

/	REMOTE LINE TRANSMIT DEVICE CODE  DEFINED  HERE.  REMOVE THE / AND FILL IN THE
/	APPROPRIATE VALUE.

/	SEN=	41			/REMOTE TRANSMIT DEVICE CODE

	IFNDEF	SEN	<SEN=	41>	/DEFAULT TRANSMIT DEVICE CODE IS 41

/	BAUD RATE CONTROL VALUE DEFINED HERE FOR VT-78, ETC.  REMOVE THE / AND FILL IN
/	THE APPROPRIATE VALUE.

/	BRATE=	7			/BAUD RATE CONTROL VALUE

	IFNDEF	BRATE	<BRATE=	7>	/DEFAULT IS VALUE FOR 1200 BAUD

/	REMOTE LINE IOT DEFINITIONS.

/	RECEIVE DEFINITIONS.

/	RKCCIOT=REC^10+6002		/CLEAR REMOTE INPUT FLAG, AC
	RKRBIOT=REC^10+6006		/READ REMOTE, CLEAR FLAG
	RKSFIOT=REC^10+6001		/SKIP ON REMOTE INPUT FLAG

/	TRANSMIT DEFINITIONS.

	RSBIOT=	SEN^10+6003		/SET BAUD RATE FROM AC[8-11]
	RTLSIOT=SEN^10+6006		/TRANSMIT CHARACTER, CLEAR FLAG
/	RTSFIOT=SEN^10+6001		/SKIP ON TRANSMIT FLAG

/	OTHER DEFINITIONS.

	DATFLD=	DFIELD^10		/LOADING FIELD FOR CDF INSTRUCTIONS
/	THE PROGRAM CODE STARTS HERE.

	IFZERO	DFIELD	<FIELD	1>	/FIELD ZERO VERSION LOADS HERE

	IFNZRO	DFIELD	<FIELD	0>	/ALL OTHER VERSIONS LOAD HERE

	*200				/START AT THE BEGINNING

START,	KCC				/CLEAR KEYBOARD FLAG AND AC
	TAD	INPUT			/GET BAUD RATE CONTROL VALUE
	RSBIOT				/SETUP THE BAUD RATE
/	RKSFIOT				/**** FOR DECMATE PRINTER PORT ONLY ****
	KSF				/WAIT FOR
	JMP	.-1			/KEYBOARD INPUT
	KRB				/GET THE CHARACTER
	RTLSIOT				/OUTPUT TO REMOTE
	TLS				/LET USER SEE IT ALSO
	RKRBIOT				/CLEAR REMOTE INPUT FLAG NOW
	CDF	DATFLD			/SETUP LOADING FIELD
	JMS	INPUT			/TRY TO GET A VALID DATA CHARACTER
	JMP	.-1			/LEADER FOUND, IGNORE IT
	JMP	GOTDATA			/LOAD FIRST DATA CHARACTER THERE

DATLUP,	JMS	INPUT			/TRY TO GET A VALID DATA CHARACTER
	JMP	LOADEND			/TRAILER FOUND, GO FINISH THERE
GOTDATA,CLL RTL;RTL;RTL			/MOVE HALF-WORD UP
	DCA I	LOADPTR			/STORE HIGH-ORDER HALF
	JMS	INPUT			/TRY TO GET A VALID DATA CHARACTER
	JMP	LOADEND			/TRAILER FOUND, GO FINISH THERE
	TAD I	LOADPTR			/COMBINE LATEST WITH PREVIOUS
	DCA I	LOADPTR			/STORE BACK COMPOSITE
	ISZ	LOADPTR			/BUMP TO NEXT
L177,	177				/CONSTANT 0177; HERE JUST IN CASE IT SKIPS
	JMP	DATLUP			/GO BACK FOR MORE

/	COMES HERE WHEN LOADING IS DONE.

LOADEND,CLA!400				/CLEAN UP; ALSO CONSTANT 7600
	CIF CDF 00			/GOING TO MONITOR FIELD
	JMP I	LOADEND/(7600)		/EXIT TO MONITOR

LOADPTR,0000				/LOADING POINTER
INPUT,	BRATE				/INPUT ROUTINE; ALSO HOLDS BAUD RATE VALUE
INPAGN,	RKSFIOT				/ANY REMOTE INPUT?
	JMP	INPAGN			/NO, WAIT FOR IT
	RKRBIOT				/YES, READ IT IN
	AND	L177/(177)		/REMOVE PARITY BIT
	TAD	L7737/(-41)		/COMPARE TO LOWER LIMIT
	SPA				/SKIP IF GREATER THAN THAT
	JMP	INPAGN			/ELSE IGNORE IT
	TAD	L7700/(-100)		/COMPARE TO UPPER LIMIT
	SMA				/SKIP IF IN RANGE
	JMP I	INPUT			/ELSE TAKE IMMEDIATE RETURN ON LEADER/TRAILER
	AND	L77/(77)		/REMOVE JUNK BITS
	ISZ	INPUT			/BUMP RETURN
	JMP I	INPUT			/TAKE SKIP RETURN TO CALLER

L77,	77				/CONSTANT 0077
L7700,	7700				/CONSTANT 7700
L7737,	7737				/CONSTANT 7737

	$				/THAT'S ALL FOLK!
