/ RXCOPY FOR OS/8 V3D AND OS/78 V1A
/
/ THIS SOFTWARE IS FURNISHED UNDER A LICENSE FOR USE ONLY ON A
/ SINGLE COMPUTER SYSTEM AND MAY BE COPIED ONLY WITH THE INCLUSION
/ OF THE ABOVE SOPYRIGHT NOTICE.  THIS SOFTWARE, OR ANY THEREOF,
/ MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
/ PERSON EXCEPT FOR USE ON SUCH SYSTEM AND TO ONE WHO AGREES TO
/ THESE LICENSE TERMS. TITLE TO AND OWNERSHIP OF THE SOFTWARE
/ SHALL AT ALL TIMES REMAIN IN DEC.
/
/ THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT
/ NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL
/ EQUIPMENT CORPORATION.
/
/ DEC ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS
/ SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DEC.
/

/
/ VERSION V4A	M.H.	MAY 20, 1977
/		S.R.	MAY 20, 1977
/ VERSION V4B	S.R.	AUG 24, 1978
/
/ START ADDRESS 16000;  JSW 7003
/
/ THIS PROGRAM PERFORMS COPY, READ, AND COMPARE OPERATIONS ON
/ RX FLOPPY DISKS ON A TRACK BY TRACK BASIS.
/
/  THE COMMAND OPTIONS ARE:
/
/P	PAUSE BEFORE AND AFTER ACCESSING DISK
/M	MATCH WITH NO IMPLIED COPY
/N	COPY WITH NO IMPLIED MATCH
/R	READ OUTPUT DEVICE WITH NO IMPLIED MATCH OR COPY
/V	PRINT VERSION NUMBER
/C	(NOT DOCUMENTED) COPY
/S	FORMAT (ONLY) OUTPUT DEVICE TO SINGLE DENSITY
/D	FORMAT (ONLY) OUTPUT DEVICE TO DOUBLE DENSITY
/ IF NO OPTIONS ARE EXPLICITLY DECLARED, COPY AND MATCH ARE ASSUMED.
/
/  THERE ARE TWO COMMAND FORMATS:
/
/   DEV:<DEV:/OPTION   WHERE OPTIONS ARE  C, P, N, M, OR V.
/   DEV:/R     DEV:</R   <DEV:/R  THREE FORMATS FOR  R, S, D, OR V.
/ 
/
/  WARNING!!
/
/  THIS PROGRAM HAS TWO PATHOGENIC CONNECTIONS WITH THE STANDARD
/  RX HANDLERS
/
/  IT IS ASSUMED THAT THE RX SYSTEM HANDLER HAS AT LOCATION 7623
/  A WORD THAT CONTAINS THE 20 BIT IF BOOTED TO UNIT #1
/
/  IT IS ASSUMED THAT THE RX NON-SYSTEM HANDLER HAS ENTRY POINTS
/  CORRESPONDING TO UNIT NUMBERS AS FOLLOWS:
/
/		UNIT		LAST DIGIT OF ENTRY POINT
/
/		0		0
/		1		4
/		2		1
/		3		5
/
/  WHERE UNITS 2 AND 3 ARE A SECOND PAIR OF FLOPPIES ON A VT78 ONLY!
/
/

MAGIC=7623		/WORD IN RX SYSTEM HANDLER HAS 20 IF BOOTED ONTO
/			/UNIT #1 (RIGHT-HAND ONE)
OPT1=7643		/1ST COMMAND DECODER OPTION WORD
OPT2=7644		/2ND COMMAND DECODER OPTION WORD
OPT3=7645		/3RD COMMAND DECODER OPTION WORD
BUFF=2000		/INPUT BUFFER FOR TTY MSGS
TYP1=25			/DEVICE CODE FOR RX01
TYP2=32			/DEVICE CODE FOR MULTI-RX HANDLER WAS 27 (TAKEN BY TA8E)
BSIZE=6400		/BUFFER SIZE IN OCTAL WORDS
BSTART=20		/BUFFER START
BHALF=BSIZE%2		/HALF OF BSIZE
USR=200			/ENTRY POINT OF USR
NOMAT=2000		/NO MATCH OPTION MASK
COPY=1000		/COPY OPTION MASK
MATCH=4000		/MATCH OPTION MASK; NOTE SOME CODE !KNOWS! THIS IS 4000
READ=0100		/READ OPTION MASK
VERSION=0004		/VERSION OPTION MASK
PAUS=0400		/PAUSE OPTION MASK
SINGLE=40		/SINGLE DENSITY FORMAT ONLY
DOUBLE=200		/DOUBLE DENSITY FORMAT ONLY
OLDOUB=400		/ORIGINAL POSITION OF DOUBLE BIT
CHANGE=1		/IN OPTION WORD, 1 MEANS MUST FORMAT OUTPUT MEDIA
/
/  CORE LAYOUT
/
/  FIELD 0
/
/  RX BUFFER	0020-6417
/  ERROR MSGS	6420-7177
/  TTY HANDLER	7200-7577
/  SYSTEM	7600-7777
/
/  FIELD 1
/
/  RX BUFFER	0020-6417
/  INIT CODE	5000-6417
/  PROGRAM	6420-7577
/  SYSTEM	7600-7777
/
/  FIELD 2&3 (OPTIONAL)
/
/  RX BUFFER	0020-6417
/
/  EXECUTION ORDER
/
/  INIT CODE STARTS AT 6000, THEN TO 5000, 5200, 5400, 7110
/
/  MAIN LOOP IS AT 6420
/  SERVICE SUBROUINES OCCUPY MOST OF REST OF THE FIELD
/
/
/  FLOPPY IOT'S
/
SDN=6755
LCD=6751
STR=6753
XDR=6752
SER=6754
FLINIT=6757
/
AC7776=CLL CLA CMA RAL		/SET AC TO -2
AC7775=CLL CLA CMA RTL		/SET AC TO -3
AC0002=CLL CLA CML RTL		/SET AC TO 2
AC4000=CLL CLA CML RAR		/SET AC TO 4000
/
/
/  THE OPTION WORDS FROM THE COMMAND DECODER ARE COMBINED INTO ONE WORD
/  HERE CALLED 'OPTION'. THE BITS IN OPTION ARE M,N,C,P,D,R,S,0,0,V,0,0.
/  NOTE THAT ONLY THE 'D' BIT HAS BEEN REPOSITIONED.
/
/  WARNING! THE MEANING OF THE M AND C BITS ON INPUT IS DIFFERENT THAN THAT
/  WHILE THE PROGRAM IS ACTUALLY RUNNING. ON INPUT C IS COPY AND MATCH.
/  ON INPUT M IS MATCH WITHOUT COPY. WHILE THE PROGRAM IS RUNNING, M
/  IS MATCH (INDEPENDENT OF COPY), AND C IS COPY (INDEPENDENT OF MATCH).
/
/  SUMMARY OF CONFIGURATION DEPENDENT VARIABLES
/
/	ISVT78		1 IF A VT78, 0 IF NOT
/	ISBIG		1 IF GREATER THAN 12K, 0 IF NOT
/	ISDOUB		0 IF SINGLE DENSITY TRANSFER, 1 IF DOUBLE
/
/
/  SUMMARY OF DERIVED VARIABLES  (DO NOT APPEAR AS SUCH IN PROGRAM)
/
/	HLFTRK		(NOT ISBIG).AND.ISDOUB=1.AND.MATCH OPTION
/	SHORT		ISDOUB=0.IOR.HLFTRK
/	SLOW		ISVT78.AND.ISDOUB=1
/
/  I/O CONTROLL INFORMATION IS PLACED IN THE VARIABLES RIFN, ROFN
/
/	RIFN		4000  IF RX02 OR RX03 HARDWARE
/			0400  IF A DOUBLE DENSITY TRANSFER IS TAKING PLACE
/			0020  IF UNITS 1 OR 3
/			0002  ALWAYS SET, INDICATES READ FUNCTION
/			0001  IF UNITS 2 OR 3, SECOND PAIR ON VT78
/
/	ROFN		WHICH IS THE SAME WORD FOR OUTPUT, GETS BITS IN
/			THE SAME FORMAT
/
/  THE ABOVE VARIABLES RESULT IN THE SETTING OF THE FOLLOWING COUNTS
/    WHICH ARE PLACED HERE AND THERE IN CONVENIENT PAGES
/
/	COUNT1		-20 IF ISDOUB=1, -10 IF NOT
/	COUNT2		-100 IF ISDOUB=1, -40 IF NOT
/	COUNT3		-400 IF ISDOUB=1, -200 IF NOT
/	COUNT4		-2 IF DOUBLE HEADED, -1 IF NOT
/	COUNT5		-2 IF HLFTRK, -1 IF NOT; 
/	COUNT6		10 IF SHORT, 20 IF NOT
/	COUNT7		-1 IF SHORT, -2 IF NOT
/	COUNT8		3 IF SLOW, 2 IF NOT
/	COUNT9		SKP IF SLOW, IAC IF NOT
/
/
	FIELD	1
	*5000
/
/  ADDITIONAL ONCE-ONLY CODE
/
/
/
/  PRINT VERSION NUMBER EVEN IF SOME ERRORS
/
LOC3,	TAD	OPT2	/PRINT VERSION FIRST EVEN IF AN ERROR
	AND	(VERSION
	SNA CLA		/SKIP IF PRINTOUT NEEDED
	JMP	VALID	/NO, CONTINUE CHECKING
	TAD	(VERBUF	/ADDRESS OF MESSAGE IN FIELD 0
	JMS	TYPE
/
/
/
/  VARIOUS CHECKING FOR ILLEGAL SWITCHES
/
VALID,	TAD	(-COPY-OLDOUB-1  /IS SWITCH OTHER THAN COPY OR DOUBLE?
	AND	OPT1	/IN THE FIRST COMMAND DECODER OPTION WORD
	SZA CLA		/SKIP IF OK
	JMP	ERR17
	TAD	(-MATCH-NOMAT-PAUS-READ-SINGLE-VERSIO-1
	AND	OPT2	/CHECKING FOR OTHER THAN M,N,P,R,S,V
	SZA CLA
	JMP	ERR17
	TAD	OPT3	/THIS WORD SHOULD BE 0, I.E. NO SWITCHES AT ALL
	SZA CLA		/SKIP IF OK
	JMP	ERR17
	TAD	OPT1	/DOUBLE, IF PRESENT, MUST CHANGE POSITION
	AND	(OLDOUB	/CHECK IT IN OLD POSITION
	SZA CLA		/SKIP IF NOT THERE
	TAD	(DOUBLE-OLDOUB	/MOVE TO NEW POSITION
NOFORM,	TAD	OPT1	/JOIN ALL SWITCHES INTO ONE WORD
	TAD	OPT2	/COMBINING WORDS
	DCA	OPTION	/HOLD ALL TOGETHER FOR SIMPPLICITY
	TAD	(BITTAB	/LOAD UP TO TEST COMBINATIONS
	DCA	TMP5
	TAD	OPTION
	DCA	TMP6
VALLOO,	TAD	TMP6
	CLL RAL		/NEXT OPTION BIIT TO LINK
	DCA	TMP6
	TAD I	TMP5	/NEXT MASK
	SNA		/SKIP IF MORE TO DO
	JMP	CROSS	/CROSS TALK CHECKED OUT
	ISZ	TMP5	/BUMP POINTER
	AND	TMP6	/CHECK ILLEGAL POSSIBILITIES
	SNL		/SKIP ONLY IF MASTER BIT IS ON
	CLA		/GO OUT VIA JMP VALLOO
	SNA CLA		/SKIP IF MASTER AND SOME OTHER MATCH, ILLEGAL
	JMP	VALLOO
ERR17,	TAD	(MSG17-MSG6	/SWITCHES ERROR MSG
ERR6,	TAD	(MSG6-MSG5
ERR5,	TAD	(MSG5-MSG3
ERR3,	TAD	(MSG3
	JMP	PERR	/GO PRINT ERROR
/
CROSS,	TAD	(SINGLE+DOUBLE+MATCH+READ	/ANY SPECIFIED FUNCTION
	AND	OPTION
	SZA CLA		/SKIP IF NO
	JMP	CROSS1	/A FUNCTION THERE, DON'T SET C
	TAD	OPTION
	AND	(-COPY-1
	TAD	(COPY
	DCA	OPTION
CROSS1,	TAD	(SINGLE+DOUBLE+NOMAT+READ
	AND	OPTION	/SET M IF REQUIRED
	SZA CLA		/SKIP IF NECESSARY
	JMP	CROSS3	/NO
	TAD	OPTION
	RAL		/KNOW! THAT MATCH=4000
	CLL CML RAR
	DCA	OPTION
/
/  NOW OUTPUT DEVICE
/
CROSS3,	TAD	OUTDEV
	SNA
	JMP	ERR6	/DEVICE NOT THERE AT ALL!
	JMS	CHCKRX	/IS IT REALLY AN RX? RETURN UNIT NUMBER;+2 FOR READ
	DCA	ROFN	/BUILD REST OF IT IN LATER
/
/  NOW INPUT DEVICE (IF ANY)
/
CROSS2,	TAD	(READ+SINGLE+DOUBLE
	AND	OPTION	/AN INPUT DEVICE NEEDED
	SZA CLA		/SKIP IF NECESSARY
	JMP	REAFOR	/READ OR FORMAT
	TAD	INDEV
	SNA
	JMP	ERR5	/DEVICE NOT PRESENT AT ALL, ERROR
	JMS	CHCKRX	/IS IT REALLY AN RX? RETURN READ CODE +UNIT #
	DCA	RIFN
	TAD	RIFN	/CHECK IF UNIT NUMBERS THE SAME
	CIA		/WHICH IS AN ERROR
	TAD	ROFN
	SNA CLA		/SKIP IF DIFFERENT
	JMP	ERR2
	JMP	IICNT
/
REAFOR,	TAD	INDEV	/FOR READ AND FORMAT INPUT DEVICE IS ILLEGAL
	SZA CLA		/SKIP IF NOT PRESENT
	JMP	ERR2	/SPECIFICATION ERROR ON EXTRA DEVICE
	JMP	IICNT	/OK, CONTINUE INITIALIZATION
/
/
TMP5,	0		/WORK LOCATIONS
TMP6,	0
/
	PAGE
/
/
/  ESTABLISH FUNDAMENTAL CONFIGURATION VARIABLES
/
IICNT,	JMS I	(USR	/UNLOCK USR
	11
	TAD	OPTION	/IF SLASH-P, MUST GET CORRECT FLOPPY ON!
	AND	(PAUS
	SNA CLA		/SKIP IF SLASH-P
	JMP	IICNT2	/NO, JUST KEEP GOING
SYSOFF,	JMS	QUEST	/ASK REMOUNT QUESTION
	MSG12		/ADDR OF MESSAGE
	JMP	SYSOFF	/"N" ASK AGAIN
/			/"Y" CONTINUE TO INITIALIZE
IICNT2,	CDF	70	/TEST FOR A VT78
	RDF
	CDF	10	/BACK TO US
	TAD	(7750	/VT78 RETURNS 30 FROM 70 !
	SNA CLA
	IAC
	DCA	ISVT78	/
	CDF	0	/FETCH CORE SIZE WORD
	TAD I	(7777
	CDF	10	/INDIRECTS HERE
	AND	(70
	TAD	(7750	/MAKING + IF 16 OR MORE K OF CORE
	SMA CLA		/SKIP IF NOT 16K
	IAC		/16K
	DCA	ISBIG	/SAVE THAT INFO
	TAD	ROFN	/GET DEVICE STATUS TYPE FOR OUTPUT DEVICE
	JMS	DEVSTT	/RETURN CODE IN .+1, UPDATED ROFN WORD IN AC
MEDOU,	-1		/RETURN 0-3;SINGLE;SINGLE ON DOUB;DOUB;QUAD
	DCA	ROFN
	TAD	MEDOU	/DEFAULT FOR MEDIN, IF NO INPUT MEDIA AT ALL
	DCA	MEDIN
	TAD	INDEV	/IS AN INPUT DEVICE?
	SNA CLA		/SKIP IF YES
	JMP	ONLY1	/SPECIAL PROCESSING FOR ONE DEVICE CASES
	TAD	RIFN	/GETTING UNIT NUMBER
	JMS	DEVSTT	/CHECK FOR READY, RETURN TYPE CODE
MEDIN,	-1		/RETURN 0-3, SAME AS MEDOU
	DCA	RIFN	/FULL I/O SKELETON
	TAD	MEDIN	/CONVENIENCE, MAKE INPUT OUTER LEVEL INDEX
	RTL
	TAD	MEDOU	/INNER LEVEL INDEX
	TAD	(ACTAB	/TABLE FOR WHICH ACTION TO TAKE
	DCA	TMP7
	TAD I	TMP7	/AN EXTRA INDIRECT NEEDED
	DCA	TMP7
	JMP I	TMP7	/GO TO CORRECT ACTION
/
/  DEVSTT
/
/  CALL WITH 2 (READ CODE) + UNIT NUMBER IN AC: PARTIAL RIFN/ROFN WORD
/
/  IF DRIVE NOT READY, ERROR OUT DIRECTLY
/
/  RETURN WITH DEVICE TYPE IN CALL +1
/
/	0		RX01 DRIVE
/	1		RX02 DRIVE WITH RX01 FLOPPY
/	2		DOUBLE DENSITY DRIVE AND MEDIA; EITHER BOTH NOT
/			BOTH MAY BE DOUBLE SIDED, BUT THAT IS IGNORED!!
/	3		RX03 DRIVE AND RX03 FLOPPY
/
/  RETURN WITH FULL RIFN/ROFN CODE IN AC
/
DEVSTT,	0
	DCA	TMP7	/SAVE CALLING CODE
	TAD	TMP7	/BUT CHECK OUT WHICH DRIVE PAIR
	JMS	SELECT	/SELECT PAIR, IF NECESSARY; AC HAS BEEN ANDED WITH 7776
	TAD	(410	/DO DOUBLE DENSITY 12 BIT READ STATUS
	SDN		/WAITING ON DONE
	JMP	.-1
	LCD		
	SDN		/WAIT AGAIN ON DONE
	JMP	.-1
	XDR		/GET STATUS
	AND	(232	/KEEPING READY, DENSITY ERROR, DOUBLE, QUAD
	DCA	TMP8	/SAVE WHILE WE CLEAR UP DEVICE
	TAD	(416	/DUMMY READ ERROR STATUS TO SET DONE AGAIN
	LCD
	SER		/CLEAR POOSSIBLE ERROR FLAG
L7600,	7600		/IT MAY SKIP!
	TAD	TMP8	/GET BACK STATUS
	TAD	L7600	/CHECK FOR READY
	SPA
	JMP	STERR	/NOT READY, PRINT ERROR
	CLL RTR		/PUT QUAD BIT TO LINK
	SZL		/SKIP ON NOT QUAD
	CLL CML CLA CMA	/ALL BITS TO 1 !! FALLS THRU TO EXIT WITH 3
	RTR		/PUT DOUBLE BIT TO LINK
	SNL		/SKIP ON DOUBLE
	JMP	REJOIN	/JOIN WITH OTHER CASES, AC NOW 0
	CMA		/MAKING SINGLE -2, DOUBLE -1, QUAD 0
	TAD	(3	/MAKING SINGLE 1, DOUBLE 2, QUAD 3
REJOIN,	DCA I	DEVSTT	/RETURN 0-3 TYPE IN CALL+1
	TAD I	DEVSTT	/GET CODE BACK
	TAD	(FNTAB	/TURN CODE INTO FUNCTION BITS
	DCA	TMP8
	TAD I	TMP8	/4000 FOR DOUBLE DRIVE, 400 FOR DOUBLE TRANSFER
	TAD	TMP7	/ORIGINAL CALLING BITS
	ISZ	DEVSTT	/HOP OVER RETURNED ARGUMENT
	JMP I	DEVSTT	/EXIT WITH CODE IN AC
/
/
STERR,	CLA			/AC JUNK COMING IN
	TAD	(MSG18-MSG19	/PRINT MESSAGE 18
ERR19,	TAD	(MSG19-MSG15	/PRINT MESSAGE 19
ERR15,	TAD	(MSG15		/PRINT MESSAGE 15
	JMP	PERR
/
TMP7,	0
TMP8,	0

/
	PAGE
/
/  SPECIAL CODE FOR ONE DEVICE CASES; READ, SINGLE, DOUBLE
/
ONLY1,
	TAD	OPTION	/SEPARATE OUT READ
	AND	(SINGLE+DOUBLE
	SNA		/SKIP IF NOT READ (CAN ONLY BE ONE OF THREE BITS!)
	JMP	READIT	/READ CASE, FALL INTO OTHER CODE
	RAL		/WATCH OUT! GOING TO SPLICE PROPER DENSITY BIT
	JMP	TOUGH	/INTO ROFN FOR LATER FORMAT
/
/  ENTER FROM DISPATCHER, AUTO-FORMAT, AND OK
/
CISZ,	ISZ	OPTION	/SET CHANGE DENSITY BIT IN OPTION WORD
SAME,
/
/  SET UP COUNT VARIABLES
/
IICNT4,	TAD	RIFN	/PUT TRANSFER DENSITY BIT FROM INPUT INTO OUTPUT
TOUGH,	AND	(400	/KEEPING THAT BIT; FORMAT ONLY CASE JOINS HERE
	DCA	ISDOUB	/TERMPORARY USE OF LATER VARIABLE
	TAD	ROFN	/OUTPUT CONTROL
	AND	(7377	/KEEPING OTHER BITS
	TAD	ISDOUB
	DCA	ROFN	/REPLACING MODIFIED OUTPUT WORD
READIT,	AC7776		/TAKE OFF READ BIT FOR OUTPUT WRITE FUNCTION
	TAD	ROFN
	DCA	WOFN
	AC7776		/
	TAD	MEDIN	/MAKE A TEMPORARY VARIABLE ISDOUB
	SMA CLA		/SKIP IF SINGLE
	IAC
	DCA	ISDOUB	/WHICH IS 1 IF DOUBLE DENSITY MEDIA
	TAD	ISDOUB	/SIGNLE OR DOUBLE
	SZA CLA		/SKIP IF SINGLE
	TAD	(-10	/DOUBLE, MAKE -20
	TAD	(-10	/SINGLE, MAKE -10
	DCA	COUNT1
	TAD	COUNT1	/NOW MULTIPLY BY FOUR
	CLL RAL
	CLL RAL
	DCA	COUNT2
	TAD	COUNT2	/NOW AGAIN BY FOUR
	CLL RAL
	CLL RAL
	DCA	COUNT3
	AC7775
	TAD	MEDIN	/CHECK FOR QUAD SIZED
	SMA CLA		/SKIP IF NOOT
	IAC
	CMA		/MAKE A -2 IF YES, -1 IF NO
	DCA	COUNT4
	TAD	ISBIG	/MAKE VARIABLE HLFTRK
	SNA CLA		/MISSES COLLECT IN SZA CHAIN
	TAD	OPTION
	SPA CLA		/!!KNOWS!! THAT MATCH BIT IS AC0
	TAD	ISDOUB
	SZA CLA
	IAC		/HALF TRACK; SMALL MACHINE, MATCH OPTION, DOUBLE DENSITY
	CMA
	DCA	COUNT5	/-2 IF HALF-TRACK, OTHERWISE -1
	TAD	COUNT5	/FIND OUT IF ONE OR TWO FIELDS PER SWOOP
	AND	ISDOUB	/LEAVING 1 IN AC IF TWO FIELDS
	CMA		/SO MAKE ANOTHER -2,-1 COUNTER
	DCA	COUNT7
	TAD	COUNT7	/NOW MULTIPLY IT BY -10 OCTAL TO MAKE FIELD SPAN
	CIA
	CLL RAL
	RTL
	DCA	COUNT6
	TAD	ISVT78	/NOW CONSTRUCT INTERLEAVE, TWO OR THREE
	AND	ISDOUB	/THREE IF DOUBLE DENSITY ON A VT78
	TAD	(2
	DCA	COUNT8
	AC7775		/REST OF JOB, MAKE SKP OR IAC
	TAD	COUNT8
	SZA CLA		/SKIP IF IT WAS THREE INTERLEAVE
	TAD	(IAC-SKP /TWO INTERLEAVE, WANTS AN IAC
	TAD	(SKP	/THREE INTERLEAVE, WANTS A SKIP
	DCA	COUNT9
	TAD	OPTION	/INITIALIZE ROFLD
	AND	(READ	/IS IT ONLY A READ
	SNA CLA		/SKIP IF YES, CDF 0
	TAD	COUNT6	/MATCH, INIT AT CDF SPAN
	TAD	(CDF 0
	DCA	ROFLD
	TAD	OPTION	/NEED TO REFORMAT OUTPUT DRIVE?
	AND	(CHANGE+SINGLE+DOUBLE
	SNA CLA		/SKIP IF YES
	JMP	DO00	/NO, GO DO OPERATION
	JMP	REFORM	/GO TO REFORMATTER
/
/
ISVT78,	0		/1 IF A VT78, OTHERWISE 0
ISBIG,	0		/1 IF IT HAS 16K OF CORE, 0 IF LESS
ISDOUB,	0		/1 IF TRANSFER DOUBLE DENSITY
/
	FIELD	1
	*6000
/
/
/  EQUATES FOR AUTO-INCR REG'S, SO THEY SHOW UP IN CREF
/
X10=10
X11=11
X17=17
/
/ ***** BEGIN ONCE ONLY CODE *****
/
/
/ ENTER HERE AND GET USER INPUTS
/
START,	CLA!SKP			/NORMAL ENTRY (MUST CALL DECODER)
CHAIN,	JMP	NODEC		/CHAIN ENTRY
	CDF	10
	JMS I	(USR		/CALL IT
	5
	5200			/DEFAULT INPUT EXT.(SPECIAL MODE)
	0			/PRESERVE TENTATIVE FILES
/
/ LOAD CONSOLE TTY HANDLER
/
NODEC,	JMS I	(USR		/LOAD THE KL8E HANDLER
	1
	DEVICE	TTY
TTYEP,	7201
	JMP	ERRUSR		/PRINT USER ERROR
	TAD	TTYEP		/MOVE ENTRY POINT FROM THIS PAGE
	DCA	TTYENT
/
/ LOAD OUTPUT DEVICE IF SPECIFIED
/
	JMS	CTRLC		/CHECK FOR CONTROL C TYPE-IN
	TAD I	(7600		/GET OUTPUT DEV
	AND	(17
	DCA	OUTDEV
	TAD I	(7605		/GET INPUT DEVICE
	AND	(17
	DCA	INDEV
	TAD	OUTDEV		/IF NO OUTPUT DEVICE
	SZA CLA			/IS NAMED MOVE INPUT
	JMP	LOC10		/TO OUTPUT DEVICE
	TAD	INDEV		/MOVE IT!
	DCA	OUTDEV
	DCA	INDEV		/ZERO INPUT DEVICE
/
/ VALIDATE OUTPUT DEVICES AND FILES
/
LOC10,	JMS	CTRLC		/CHECK FOR CONTROL C
	TAD	(7601		/MAKE SURE THAT THERE ARE NO OUTPUT FILES
	DCA	TMP1		/OR OTHER OUTPUT DEVICES
	TAD	(-4
	DCA	TMP2
LOC1,	TAD I	TMP1		/GET DECODER ENTRY 
	SZA!CLA			/IS IT ZERO?
	JMP	ERR2		/NO -- ERROR
	ISZ	TMP1		/INCREMENT POINTER
	ISZ	TMP2		/YES -- DONE WITH OUTPUT ENTRIES?
	JMP	LOC1		/NO -- PROCEED
				/YES --
/
	JMS	CTRLC		/CHECK FOR CONTROL C
	TAD I	(7605		/WAS THERE ANY INPUT SPECIFICATION?
	SNA CLA
	JMP	LOC3A		/NO
	TAD	(7606		/YES -- MAKE SURE THAT THERE ARE NO INPUT FILES
	DCA	TMP1		/OR OTHER INPUT DEVICES
	TAD	(-5
	DCA	TMP2
LOC2,	TAD I	TMP1		/GET DECODER ENTRY
	SZA!CLA			/IS IT ZERO?
	JMP	ERR2		/NO -- ERROR
	ISZ	TMP1		/INCREMENT POINTER
	ISZ	TMP2		/YES -- DONE WITH INPUT ENTRIES?
	JMP	LOC2		/NO -- PROCEED
LOC3A,	JMP	LOC3		/YES -- CONTINUE ON NEXT PAGE
/
OUTDEV,	0			/OUTPUT DEVICE NUMBER
INDEV,	0			/INPUT DEVICE NUMBER
TMP0,	0
TMP1,	0			/TEMP STORE
TMP2,	0			/TEMP STORE
/
ERR2,	TAD	(MSG2		/ILLEGAL SPECIFICATION
PERR,	JMS	TYPE		/PRINT ERROR MESSAGE
	JMP	GOEXIT		/LEAVE
/
ERRUSR,	JMS I	(USR		/PRINT USER ERROR
	7
	2
	JMP	GOEXIT
/
/
/  CHCKRX
/
/  CALL WITH DEVICE # IN AC, RETURN IF REALLY AN RX
/  RETURN WITH UNIT NUMBER IN AC; 20 IF RIGHT HAND DRIVE (#1)
/  PLUS 1 IF A SECOND PAIR ON A VT78
/  PLUS ALWAYS HAVING A 2 ADDED IN FOR A READ FUNCTION
/
OLDRX=TYP1^10
NEWRX=TYP2^10		/TYPE CODES FOR RX HANDLERS
/
/
/
CHCKRX,	0
	DCA	TMP0	/SAVE DEVICE NUMBER
	CLA CMA
	TAD	TMP0	/CHECK IF IT IS SYS
	SZA CLA		/SKIP IF YES
	JMP	NONSYS	/NO, GO TO NON-SYS PROCESSING
CHCKSY,	CDF	0	/FETCH SKELETON WORD FROM SYS
	AC0002		/PUT IN READ BIT (BIT NOT SET IN MAGIC)
	TAD I	(MAGIC
	CDF	10
	JMP	CHCKJ	/JOIN UP TO MASK AND EXIT
NONSYS,	TAD	(7757	/TABLE BASE
	TAD	TMP0
	DCA	TMP1	/HOLD FOR INDIRECT
	TAD I	TMP1	/GET STORED CODE
	AND	(770	/KEEP TYPE BITS
	TAD	(-NEWRX	/IS IT A NEW ONE
	SZA		/SKIP IF YES, BOUNCE DOWN SZA'S
	TAD	(-OLDRX+NEWRX /SO SEE IF OLD ONE
	SZA		/SKIP IF GOT A MATCH
	JMP	ERR3	/WRONG DEVICE TYPE, ERROR OUT
	TAD	(4001	/RE-ESTABLISH LOAD ADDRESS ARGUMENT
	DCA	LOADAD
	TAD	TMP0	/TRY TO LOAD HANDLER
	JMS I	(USR
	1		/LOAD CODE
LOADAD,	4001		/GETS WRITTEN OVER
	JMP	ERR3	/ERROR OUT
	TAD	LOADAD	/OUCH!! ENTRY POINT FOR UNIT 1+3, HAS A 4 IN IT!!
/			/ENTRY POINT FOR UNIT 2+3 HAS A 1 IN IT
	AND	(5	/KEEP ONLY THE TWO RELEVANT BITS
	TAD	(16	/SHIFT 4 TO 20, PUT IN 2 FOR READ CODE
CHCKJ,	AND	(23	/KEEP 2 FOR READ CODE, 20 AND 1 FOR UNIT SPECIFIERS
	JMP I	CHCKRX	/OK, RETURN
/
	PAGE
/

/
/
	*6400
/
/  PUT TABLES HERE TO FIT
/  BITTAB
/
/  TABLE FOR DETERMINING ILLEGAL CALLING OPTIONS
/
BITTAB,	6700		/WITH M; N,C,D,R,S  ILLEGAL
	5600		/WITH N; C,D,R,S  ILLEGAL
	3400		/WITH C; D,R,S  ILLEGAL
	0001		/WITH P; ALL ARE LEGAL
	6000		/WITH D; R,S ILLEGAL
	4000		/WITH R; S ILLEGAL
	0		/LOOP STOPPER; ALL LEGAL WITH V, FALLS OUT OK
/
/  ACTAB
/
/  TABLE OF ACTION FOR 16 COMBINATIONS OF INPUT AND OUTPUT TYPES
/
ACTAB,	SAME		/IN TYPE 0, OUT TYPE 0
	SAME		/0,1
	CISZ		/0,2
	CISZ		/0,3
	SAME		/1,0
	SAME		/1,1
	CISZ		/1,2
	CISZ		/1,3
	ERR15		/2,0
	CISZ		/2,1
	SAME		/2,2
	SAME		/2,3  ?????
	ERR15		/3,0
	ERR15		/3,1
	ERR15		/3,2
	SAME		/3,3
/
/
FNTAB,	0		/FUNCTION BITS BY TYPE CODE 0-3
	4000		/SINGLE MEDIA BUT 4000 DOUBLE DRIVE
	4400		/DOUBLE ON DOUBLE
	4400		/QUAD ON QUAD, LOOP HANDLES WHICH HEAD
/
/
DO00,	TAD	(-115	/TRACK LOOP CONTROL COUNT
	DCA	TRACK
/
/ ****** END OF ONCE ONLY CODE ******
	IFNZRO	.-6420&4000	<*6420>	/FORCE BEYOND BUFFER
/
/  ##  MAIN LOOP  ##
/
DO0,	TAD	COUNT4		/SET UP HEAD CONTROLLER
	DCA	HEADER
DO1,	TAD	COUNT5		/SET UP HALF-TRACK CONTROLLER
	DCA	HFTRCK
/
/ WAS COPY SELECTED?
/
DO2,	TAD	HEADER		/PLACE HEADER INFO TO COMMAND WORD
	CMA CLL RTR
	RTR			/0 IF FIRST, 1000 IF SECOND
	TAD	(100		/ALSO NEED EIGHT-BIT BIT
	DCA	LOOPFN		/FUNCTION FOR THIS LOOP
	TAD	OPTION		/SHOULD WE COPY?
	AND	(COPY
	SNA!CLA
	JMP	DO3		/NO
	JMS	RI		/YES -- READ INPUT DEVICE INTO FIELD 0
	JMS	WO		/WRITE OUTPUT DEVICE FROM FIELD 0
/
/ WAS READ SELECTED?
/
DO3,	TAD	OPTION		/SHOULD WE READ?
	AND	(READ
	SZA CLA			/SKIP IF NOT NEEDED
	JMS	RO
/
/ WAS MATCH SELECTED?
/
DO4,	AC4000		/ADD PUTS MATCH BIT TO LINK
	TAD	OPTION
	AND	(COPY	/MATCH IN LINK, COPY IN AC
	SNL		/SKIP IF A MATCH
	JMP	DO6	/NO MATCH, READY FOR LOOP CONTROL
	SNA CLA		/HAS A COPY ALREADY BEEN DONE; IF SO DON'T READ TWICE
	JMS	RI	/READ FROM INPUT DEVICE
	JMS	RO	/READ FROM OUTPUT DEVICE
/
/ COMPARE BUFFERS
/
DO5,	JMS	COMP		/CALL ACTION TO DO COMPARE
/
/  LOOP CONTROLLERS
/
DO6,	CLA			/MAY HIT WITH JUNK IN AC
	ISZ	HFTRCK		/GO AGAIN FOR OTHER HALF TRACK?
	JMP	DO2		/YES
	ISZ	HEADER		/NEED TO GO TO OTHER HEAD?
	JMP	DO1		/OTHER HEAD, LOOP AGAIN
	ISZ	TRACK		/INCREMENT TRACK, CHECK DONE
	JMP	DO0		/NO
EXITOK,	TAD	OPTION		/DOES HE NEED TO REMOUNT SYS?
	AND	(PAUS
	SNA CLA			/SKIP IF YES
	JMP	GOEXIT		/NO, BACK TO SYSTEM
SYSON,	JMS	QUEST		/ASK HIM
	MSG11			/ADDR OF MESSAGE
	JMS	SYSON		/"N" ANSWER, ASK AGAIN
/				/"Y" ANSWER, GO EXIT
GOEXIT,	JMS	SELECT		/FORCE BACK TO FIRST PAIR
	CDF CIF 0		/FIELDS FOR EXEC
	JMP I	(7605
/
/  ##  END OF MAIN LOOP  ##
/
OPTION,	0			/OPTION BITS TOGETHER IN ONE WORD
COUNT4,	0			/-1 IF ONE HEAD, -2 IF TWO
COUNT5,	0			/-2 IF TRACK MUST BE DONE IN TWO PASSES
/				/OTHERWISE -1
HFTRCK,	0			/CONTROLS LOOP PASSES PER TRACK,FILL FROM COUNT5
HEADER,	0			/FILL FROM COUNT4, CONTROLS HEAD
LOOPFN,	0			/EIGHT-BIT MODE + WHICH HEAD TO USE
/
/ SUBROUTINE QUEST -- PRINT MSG AND ASK QUESTION
/
/			JMS	QUEST
/			ADDR OF MESSAGE
/			"N" RETURN
/			"Y" RETURN
/
QUEST,	0
Q1,	TAD I	QUEST		/GET ADDR OF MESSAGE
	JMS	TYPE		/PRINT IT
	TAD	(BUFF		/SELECT INPUT BUFFER
	JMS	RDANS		/READ ANSWER
	TAD I	(BUFF		/WHAT WAS IT?
	AND	(177
	TAD	(-116		/WAS IT A "N"
	SNA
	JMP	Q3		/GO TO "N" EXIT
	TAD	(-131+116	/WAS IT A "Y"
	SZA!CLA
	JMP	Q1		/NO -- ASK AGAIN
Q2,	ISZ	QUEST		/"Y" RETURN AT JMS+3
Q3,	ISZ	QUEST		/"N" RETURN AT JMS+2
	JMP I	QUEST
/
/ SUBROUTINE CTRLC -- CHECK FOR CONTROL C
/
CTRLC,	0
	KSF		/SKIP IF A CHARACTER HAS BEEN TYPED
	JMP I	CTRLC	/NO
	KRS
	AND	(177
	TAD	(-3
	SNA!CLA
	JMP	GOEXIT	/IS A CONTROL C, EXIT
	JMP I	CTRLC
/

/
	PAGE
/

/
/ SUBROUTINE RI -- READ FROM INPUT DEVICE
/
RI,	0			/READ FROM INPUT DEVICE
	TAD	RISEC		/SET UP OUR SECTOR
	DCA	SECTOR
	TAD	RIFN		/AND OUR FUNCTION (UNIT, READ, ETC.)
	TAD	LOOPFN		/AND LOOP CONTROLLER FUNCTION
/				/DENSITY, HEAD, AND 8BIT MODE
	DCA	FN
	TAD	RIFLD		/SET UP OUR FIELD
	JMS	BUMPER		/GO DO IT
	MSG8			/ERROR MESSAGE ADDRESS
	TAD	SECTOR		/GET OUR SECTOR BACK
	DCA	RISEC
	JMP I	RI		/BACK TO MAIN LOOP
/
RISEC,	-32			/START AT SECTOR 1 (OFFSET BY 33)
RIFLD,	CDF	0		/START AT FIELD 0
RIFN,	0			/4000 IF DOUBLE DENSITY DRIVE, 20 IF ODD # UNIT
/				/2 ALWAYS FOR READ, 1 IF SECOND PAIR ON VT78
/				/400 IF DOUBLE DENSITY TRANSFER
/
/ SUBROUTINE RO -- READ FROM OUTPUT DEVICE
/
RO,	0			/READ FROM OUTDEV
	TAD	ROSEC		/SET UP OUR SECTOR
	DCA	SECTOR
	TAD	ROFN		/SET UP OUR FUNCTION
	TAD	LOOPFN
	DCA	FN
	TAD 	ROFLD		/SET UP OUR FIELD
	JMS	BUMPER		/GO DO IT
	MSG9
	TAD	SECTOR		/GET BACK OUR SECTOR
	DCA	ROSEC
	JMP I	RO		/BACK TO MAIN
/
ROSEC,	-32			/START AT SECTOR 1
ROFLD,	CDF	0		/SET AT INIT TIME
ROFN,	0			/SET AT INIT TIME, SAME FORMAT AS RIFN

/
/ SUBROUTINE WO -- WRITE OUTPUT DEVICE
/
WO,	0			/WRITE TO OUTPUT DEVICE
	TAD	WOSEC		/SET UP OUR SECTOR
	DCA	SECTOR
	TAD	WOFN		/SET UP OUR FUNCTION
	TAD	LOOPFN
	DCA	FN
	TAD	WOFLD		/SET UP OUR FIELD
	JMS	BUMPER		/GO DO IT
	MSG10
	TAD	SECTOR		/GET BACK OUR SECTOR
	DCA	WOSEC
	JMP I	WO		/BACK TO MAIN LINE
/
WOFLD,	CDF	0		/FIELD TO START OUR WRITE
WOSEC,	-32			/OUR SECTOR, START AT 1
WOFN,	0			/SET FUNCTION AT INIT TIME
/				/SAME FORMAT AS ROFN, BUT NO READ BIT

/
/
/ SUBROUTINE COMP -- COMPARE BUFFERS
/
COMP,	0
	TAD	COMSEC		/OUR SECTOR
	DCA	SECTOR
	DCA	FN		/0 IS COMPARE FUNCTION
	TAD	COMFLD		/SET OUR FIELD
	JMS	BUMPER		/DO IT
	MSG7
	TAD	SECTOR		/SAVE OUR SECTOR
	DCA	COMSEC
	JMP I	COMP
/
COMSEC,	-32			/START AT 1
COMFLD,	CDF	0		/
/
/
/  BUMPER
/
/  ROUTINE TO HANDLER SECTORING, CORE POINTER, AND FIELDS
/
/  CALLED BY RI, RO, WO, COMP;
/  STARTING FIELD IN AC,  ERROR MSG ADDR IN CALL+1
/  BUMPER IN TURN CALLS ACTION
/
BUMPER,	0
	DCA	BUMFLD		/PLACE CDF SO SETS WHEN CALL ACTION
	JMS	CTRLC		/CHECK A CONTROL C
	TAD	FN		/NEED TO SELECT
	JMS	SELECT		/DO IF NECESSARY, AC.AND.7776
	DCA	FN		/REPLACE FUNCTION, SELECT ONCE PER BUMPER CALL
	TAD	COUNT7		/HOW MANY FIELDS TO INCREMENT THRU
	DCA	BUMCNT
B0,	TAD	(BSTART-1	/SET AUTO INCREMENT REG'S
	DCA	X10
	TAD	X10
	DCA	X11
	TAD	BUMFLD		/SET FIELD INTO ACTION
	DCA	BFIELD
BUMFLD,	0			/CDF PLACED HERE BY CALLER
	JMS	ACTION		/CALL ACTION ROUTIN
	JMS	OOPS		/ERROR, PRINTOUT SOMTHING
	TAD	SECTOR		/MOVE TO NEXT SECTOR
	TAD	COUNT8		/ADD IN INTERLEAVE
	SPA			/SKIP IF SPECIAL COMPUTING NEEDED
	JMP	B2		/NO SPECIAL NEEDED, REPLACE SECTOR
COUNT9,	0			/IAC OR SKP PLACED HERE !!
	AND	(1		/FOR 2 INTERLEAVE, SWAP 0 AND 1
	TAD	(-32		/WRAP BACK TO MINUS
B2,	DCA	SECTOR
	TAD	X10		/CHECK IF DONE WITH BUFFER
	TAD	(-BSTART-BSIZE+1 /DONE IF POINTING TO LAST LOC
	SZA CLA			/SKIP IF DONE
	JMP	BUMFLD		/NO, DO NEXT SECTOR
	TAD	(10		/INCREMENT FIELD
	TAD	BUMFLD
	DCA	BUMFLD
	ISZ	BUMCNT		/DONE WITH ALL FIELDS
	JMP	B0		/NO, DO NEXT ONE
	ISZ	BUMPER		/SKIP OVER ERROR POINTER
	JMP I	BUMPER
/
COUNT7,	0			/MINUS NUMBER OF FIELDS PER PASS
COUNT8,	0			/INTERLEAVE 2 OR 3 SET AT INIT TIME
BUMCNT,	0			/LOOP CONTROL FOR FIELDS, FILL FROM COUNT7
/
/  CONSTRUCT ERROR MESSAGE
/
OOPS,	0
	TAD I	BUMPER		/GET ADDR OF MESSAGE
	JMS	TYPE		/PRINT TYPE OF FAILURE
	JMS	ADPRNT		/PRINT (HEAD), TRACK, SECTOR
	JMP I	OOPS
/
	PAGE

/
/ SUBROUTINE TYPE -- PRINT MESSAGE
/			ON ENTRY AC HAS MESSAGE ADDRESS
/
TYPE,	0
	DCA	TYPAD		/SAVE ADDR
	CIF	0
	JMS I	TTYENT
	4100
TYPAD,	0
	0
	NOP
	JMP I	TYPE
/
/ SUBROUTINE RDANS -- READ ANSWER FROM TTY
/			ON ENTRY AC HAS BUFFER ADDR
/
RDANS,	0
	DCA	RDAD		/SAVE ADDR
	CIF	0
	JMS I	TTYENT
	0110
RDAD,	0
	0
	NOP
	JMP I	RDANS
/
TTYENT,	0			/ENTRY POINT TO TTY HANDLER
/
/
/ SUBROUTINE APRNT -- PRINT TRACK AND SECTOR
/			ENTER WITH SECTOR IN AC
/
ADPRNT,	0
	TAD	LOOPFN		/WHICH HEAD
	CLL RTL
	RAL			/HEAD BIT TO AC11
	CLA RAL			/BUT CLEARING OUT OTHER BITS
	JMS	SETIN		/PUT TO MESSAGE
	MSG13A-1
	TAD	TRACK		/TRACK KEPT IN COMPLEMENT FORM
	CMA
	JMS	SETIN
	MSG13B-1
	TAD	SECTOR		/SECTOR KEPT AS SECTOR-33
	TAD	(33
	JMS	SETIN
	MSG13C-1
	TAD	COUNT4		/IS QUAD OPERATION
	IAC			/COUNT4 COMES -2 FOR QUAD, -1 NOT
	SNA CLA			/SKIP IF YES
	TAD	(10		/NO, DON'T TALK ABOUT HEADS
	TAD	(MSG13		/ADDR FOR PRINTOUT
	JMS	TYPE
	JMP I	ADPRNT

/
/ SUBROUTINE SETIN -- ENTER NUMBER INTO A MESSAGE
/
/	ON ENTRY AC HAS NUMBER AND JMS+1 HAS POINTER TO MESSAGE
/	HOLE MINUS 1. (2 DECIMAL DIGIT NUMBERS ARE ASSUMED)
/
SETIN,	0
	DCA	SETIN1		/SAVE NUMBER
	DCA	SETCNT		/ZERO 10'S COUNTER
	TAD I	SETIN		/GET MSG ADDR
	DCA	X17		/ENTER INTO AUTOINC POINTER
	ISZ	SETIN		/BUMP RETURN ADDR
SETINB,	TAD	SETIN1		/GET NUMBER
	TAD	(-12		/SUBTRACT 10 DECIMAL
	SMA			/DONE DIVIDING?
	JMP	SETINA		/NO
	CLA			/YES
	TAD	SETCNT		/GET 10'S
	SNA			/SKIP IF A LEADING DIGIT
	TAD	(-20		/MAKE LEADING 0 A LEADING BLANK
	TAD	(260		/MAKE IT ASCII
	CDF	0		/ERROR MESSAGES IN FIELD 0!
	DCA I	X17		/STORE IN MESSAGE
	TAD	SETIN1		/GET REMAINDER
	TAD	(260		/MAKE IT ASCII
	DCA I	X17		/STORE IN MESSAGE
	CDF	10		/POINT CDF BACK HERE
	JMP I	SETIN
SETINA,	DCA	SETIN1		/SAVE RESULT
	ISZ	SETCNT		/INCREMENT 10'S COUNT
	JMP	SETINB		/CONTINUE
/
SETIN1,	0			/NUMBER STORAGE
SETCNT,	0			/10'S COUNTER
/
/  REFORMAT
/
/  BELONGING HERE ONLY FOR REASONS OF FIT
/
/
REFORM,	TAD	ROFN	/OK, WHAT OUTPUT DENSITY DO WE HAVE
	SMA CLA		/SKIP IF DRIVE IS CAPABLE OF A REFORMAT
	JMP	ERR15	/GO PRINT ILLEGAL TYPE
	TAD	ROFN	/GET FUNCTION BACK
	JMS	SELECT	/ALSO MUST CHECK WHICH PAIR; AC=AC.AND.7776
	TAD	(4006	/TURN OFF TOP BIT, MAKE 2 READ INTO 10 REFORMAT
	SDN		/CONTROLLER READY
	JMP	.-1
	LCD
	STR		/WAIT FOR READY TO TAKE CODE
	JMP	.-1
	TAD	(111	/SAFETY CODE
	XDR		/PLACE TO DRIVE
	CLA
	SDN		/WAIT FOR OVERALL DONE
	JMP	.-1	/WIGGLE AC TO SHOW LIFE ??
	AC7776		/SET AC TO STRIP WHICH PAIR BIT
	SER		/SKIP IF AN ERROR DURING FORMAT
	CLL		/CLEAR LINK TO SHOW NO ERROR
	AND	ROFN	/SET DONE FLAG
	TAD	(4014	/BY A DUMMY READ ERROR STATUS, FLIPS LINK!
	LCD
	SNL		/SKIP IF REFORMAT HAD NO ERROR
	JMP	ERR19	/ERROR DURING REFORMAT, FATAL
	TAD	OPTION	/WAS IT A REFORMAT ONLY?
	AND	(SINGLE+DOUBLE
	SNA CLA		/SKIP IF YES
	JMP	DO00	/NO, GO DO OTHER STUFF
	JMS	QUEST	/ASK IF ANOTHER FORMAT OPERATION WANTED
	MSG16
	JMP	EXITOK	/"N" RETURN
	JMP	REFORM	/"Y" RETURN
/
	PAGE
/
/
/  ACTION ROUTINE ENTRY POINT
/
/  WATCH IT! WE CALLED WITH CDF POINTING TO BUFFER
/  ALSO CDF IS PLACED IN BFIELD,
/  SO WE CAN DO NO INDIRECTS EXCEPT THRU AUTO INCR TO BUFFER !!
/
/  RETURN WITH SKIP IF OK, DIRECT RETURN WITH ERROR
/
/  RESTORES DF TO 10 ON EITHER EXIT
/
/  DO A SECTOR AT A TIME FOR A SINGLE FUNCTION
/
ACTION,	0
	AC7775		/-3 ERROR RETRY COUNT
	DCA	RETRY
	TAD	FN	/SORT FUNCTIONS
	SNA
	JMP	COMPAR	/GO DO COMPAR
	RTR		/READ/WRITE BIT TO LINK
	SZL CLA		/SKIP IF WRITE
	JMP	READLP	/GO TO READ
/
/  WRITE LOOP
/
WRITLP,	TAD	FN	/SET UP SILO OPERATION
	JMS	LDCMD
	JMP	WRIT1	/OTHER PAGE TO MOVE DATA TO SILO
WRIT2,	JMS	DOIO	/RETURN FROM OTHER PAGE TO ACCESS I/O
	JMP	REFILL	/COMMON EXIT
/
/  READ LOOP
/
READLP,	JMS	DOIO	/COME HERE TO RETRY I/O
	TAD	FN
	JMS	LDCMD
	TAD	COUNT2	/RX01, 32 PASSES THRU 4 BYTES MOVED
	DCA	RDCNT	/RX02, 64 PASSES THRU
ST5,	STR
	JMP	.-1
	XDR
	DCA I	X10
	STR
	JMP	.-1
	XDR
	DCA I	X10
	STR
	JMP	.-1
	XDR
	DCA I	X10
	STR
	JMP	.-1
	XDR
	DCA I	X10
	ISZ	RDCNT
	JMP	ST5
REFILL,	ISZ	ACTION	/OK EXIT, ALSO A LITERAL
ACTEND,	CDF	10	/DATA FIELD NORMAL AGAIN
	JMP I	ACTION
/
/  COMPAR
/
/  COMPARE THE TWO BUFFERS
/
COMPAR,	TAD	REFILL	/RESTORE ERROR FLAG TO 'OK'
	DCA	ZOT
	TAD	BFIELD	/CREATE OTHER FIELD POINTER
	TAD	COUNT6
	DCA	CFIELD
	TAD	COUNT3	/SET UP LOOP CONTROL
	DCA	COMCNT
BFIELD,	0		/CDF PLACED HERE
	TAD I	X10	/COMPARE
	CIA
CFIELD,	0		/CDF PLACED HERE
	TAD I	X11
	SZA CLA		/SKIP IF OK
	DCA	ZOT	/NOT OK, MAKE NON-SKIP RETURN!!!!
	ISZ	COMCNT	/THRU?
	JMP	BFIELD	/NO
ZOT,	0		/ISZ ACTION PLACED HERE
	JMP	ACTEND	/RESTORE FIELD, GO BACK
/
/
/  DO I/O FUNCTION FOR READ OR WRITE
/
DOIO,	0
	TAD	FN	/SILO FUNCTION, CONVERTED TO READ-WRITE
	TAD	(4	/CONVERT SILO OPERATION TO I/O OPERATION
	JMS	LDCMD
	TAD	SECTOR	/REQUESTED SECTOR TO HARDWARE
	TAD	(33	/STORED AS -32 TO -1
	STR
	JMP	.-1
	XDR
	CLA
	TAD	TRACK
	CMA		/COMPLEMENT TO PLUS NUMBER
	STR
	JMP	.-1
	XDR
	CLL CLA CMA RTL	/AC=-3 TO KILL READ-WRITE BIT
	AND	FN	/I/O SKELETON WITHOUT READ-WRITE BIT
	TAD	(16	/LOAD ERROR STATUS IS GOOD NO-OP
	JMS	LDCMD
	JMP I	DOIO
/
/  LOAD COMMAND REGISTER
/
RDCNT=.
LDCMD,	0
	DCA	CMDTMP	/SAVE THE COMMAND
	TAD	CMDTMP
	AND	(376	/DOUBLE, KEEP ONLY 8 BITS, SINGLE NEVER HAD THEM
	SDN		/SKIP ON DONE
	JMP	.-1
	LCD		/PUT THE COMMAND
	TAD	CMDTMP	/CHECKING TOP BIT FOR DOUBLE DRIVE
	SMA
	JMP	CDCK	/SINGLE, JUST GO CHECK ERROR
	RTL
	RTL
	RAL
	AND	(7	/TOP FOUR BITS NOW SENT
	STR
	JMP	.-1
	XDR
CDCK,	CLA
	SER		/SKIP ON ERROR
	JMP I	LDCMD
	ISZ	RETRY	/TRIED THREE TIMES YET
	JMP	KEEPON	/NO, KEEP ON TRYING
	TAD	FN	/DID WE ERROR OUT OF READ OR WRITE
	RTR		/READ-WRITE BIT TO LINK
	SNL CLA		/SKIP IF READ
	JMP	ACTEND	/WRITE IS ALL SET, GO TO ERROR RETURN
	TAD	COUNT3	/READ MUST ADD APPROPRIATE AMOUNT TO X10
	CIA		/SO LOOP CONTROL IN BUMPER WORKS RIGHT!
	TAD	X10	/
	DCA	X10
	JMP	ACTEND	/SET CDF BACK, AND ERROR EXIT
/
/  ENTRY TO CONTINUE AFTER ERROR
/
/
KEEPON,	TAD	FN	/RETRYING READ OR WRITE
	RTR		/R/W BIT TO LINK
	SZL CLA		/SKIP ON WRITE
	JMP	READLP	/RETRY A READ
	JMP	WRIT2	/SO GO RETRY WRITE
/
COUNT2,	0		/MINUS NUMBER OF READ PASSES PER SECTOR
COUNT3,	0		/MINUS NUMBER OF BYTES (WORDS AS WELL) PER SECTOR
COUNT6,	0		/DELTA FIELDS FOR COMPARE
TRACK,	0		/TRACK NUMBER IN COMPLEMENT FORM FOR ISZ
SECTOR,	0		/SECTOR TO DO, SET BY INTERLEAVE ROUTINE
FN,	0		/FUNCTION BITS: ALWAYS 100 FOR 8BIT MODE
/			/+4000 FOR DOUBLE DRIVE, +1 FOR SECOND PAIR
/			/NOTE, THE 1 IS STRIPPED PRIOR TO CALL TO ACTION
RETRY,	0		/RETRY COUNTER -3 TO 0
CMDTMP,
COMCNT,	0		/TEMPORARY FOR COMPARE OR I/O
/
	PAGE
/
/  PART OF ACTION ROUTINE
/
/  FILL SILO FOR WRITE
/
/  SPREAD OUT TO SPEED UP
/
/
/
WRIT1,	TAD	COUNT1	/FOR RX01, 8 TIMES THRU 16 BYTE GIVES 128
	DCA	WRTCNT	/FOR RX02, 16 TIMES THRU FOR 256
ST4,	TAD I	X10	/FETCH A BYTE
	STR		/SKIP IF READY TO TRANSFER
	JMP	.-1	/NO (SHOULDN'T HIT THIS ON VT78)
	XDR		/MOVE BYTE TO SILO
	CLA		/CLEAR THE MUMBLE AC
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	TAD I	X10
	STR
	JMP	.-1
	XDR
	CLA
	ISZ	WRTCNT	/THRU WITH SILO?
	JMP	ST4	/NO
	JMP	WRIT2	/REST OF LOOP ON OTHER PAGE
/
WRTCNT,	0		/CONTROL COUNT FOR FILL SILO LOOP
COUNT1,	0		/FILLED AT INIT TIME, WRITE PASSES PER SECTOR!
/
/
/  SELECT SUBROUTINE
/
/  CALL WITH AC11=0 TO SELECT FIRST PAIR, AC11=1 TO SELECT SECOND
/
/  RETURN AC.AND.7776
/
/  IF SELECT REQUESTED IS SAME AS LAST SELECT, NO ACTION TAKEN
/
SELECT,	0
	DCA	WRTCNT	/CONVENIENT TEMPORARY TO SAVE ARGUMENT
	TAD	WRTCNT
	TAD	LSTSEL	/IS IT SAME AS LAST TIME
	RAR		/TEST BIT TO LINK
	SNL CLA		/SKIP IF DIFFERENT
	JMP	NOSEL	/NO SELECT NEEDED
	ISZ	LSTSEL	/CHANGE TO OTHER TYPE
	NOP		/MAY INDEED SKIP
	CLA IAC
	AND	LSTSEL	/SELECT NEW TYPE
	6750		/SELECT IOT
	SER		/MUST CLEAR ERROR FLAG, MAY RANDOMLY SET
	NOP
	SDN		/SAME FOR DONE
	NOP
	STR		/AND TRANSFER
	NOP
	CLA
	TAD	(16	/DUMMY READ ERROR STATUS TO SET DONE FLAG!!
	LCD
NOSEL,	AC7776		/RETURN ARGUMENT WITH LOW BIT CLEARED
	AND	WRTCNT
	JMP I	SELECT
LSTSEL,	0		/START OFF ON FIRST PAIR
/
	PAGE

        FIELD   0
        *6420
/
/  PUT ERROR MESSAGES IN FIELD 0 RIGHT AFTER BUFFER
/
/ 
/ ERROR MESSAGES
/
VERBUF, "R; "X; "C; "O; "P; "Y; 240; "V; "4; "B; 240; 215; 212; 232
MSG2,   "I; "L; "L; "E; "G; "A; "L; 240; "S; "P; "E; "C; "I; "F; "I
        "C; "A; "T; "I; "O; "N; 215; 212; 232
MSG3,   "D; "E; "V; "I; "C; "E; 240; "I; "S; 240; "N; "O; "T; 240
        "R; "X; 215; 212; 232
MSG5,   "N; "O; 240; "I; "N; "P; "U; "T; 240; "D; "E; "V; "I; "C;
        "E; 215; 212; 232
MSG6,   "N; "O; 240; "O; "U; "T; "P; "U; "T; 240
        "D; "E; "V; "I; "C; "E; 215; 212; 232
MSG7,   "C; "O; "M; "P; "A; "R; "E; 240
        "E; "R; "R; "O; "R; 232
MSG8,   "I; "N; "P; "U; "T; 240; "D; "E; "V; "I; "C; "E; 240
        "R; "E; "A; "D; 240; "E; "R; "R; "O; "R; 232
MSG9,   "O; "U; "T; "P; "U; "T; 240; "D; "E; "V; "I; "C; "E; 240
        "R; "E; "A; "D; 240; "E; "R; "R; "O; "R; 232
MSG10,  "O; "U; "T; "P; "U; "T; 240; "D; "E; "V; "I; "C; "E; 240
        "W; "R; "I; "T; "E; 240; "E; "R; "R; "O; "R; 232
MSG11,  "I; "S; 240; "M; "O; "N; "I; "T; "O; "R; 240
        "R; "E; "M; "O; "U; "N; "T; "E; "D
        "?; 232
MSG12,  "R; "E; "A; "D; "Y; "?; 232
MSG13,  240; "H; "E; "A; "D; 
MSG13A, 0
        0
        ",
        240; "T; "R; "A; "C; "K; 240
MSG13B, 0
        0
        ",
        240; "S; "E; "C; "T; "O; "R; 240
MSG13C, 0
        0
        215; 212; 232
MSG15,  "I; "L; "L; "E; "G; "A; "L; 240; "F; "L; "O; "P; "P; "Y; 
        240; "T; "Y; "P; "E;
        215; 212; 232
MSG16,  "F; "O; "R; "M; "A; "T; 240; "A; "N; "O; "T; "H; "E; "R;
        240; "F; "L; "O; "P; "P; "Y; "?; 232
MSG17,  "I; "L; "L; "E; "G; "A; "L; 240; "S; "W; "I; "T; "C; "H;
        "(; "E; "S; "); 215; 212; 232
MSG18,  "F; "L; "O; "P; "P; "Y; 240; "N; "O; "T; 240; "R; "E; "A; "D; "Y;
        215; 212; 232
MSG19,  "E; "R; "R; "O; "R; 240; "D; "U; "R; "I; "N; "G; 240;
        "F; "O; "R; "M; "A; "T; 215; 212; 232
$
