/ 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
/
/ START ADDRESS 16000;  JSW 7403
/
/ THIS PROGRAM PERFORMS COPY, READ, AND COMPARE OPERATIONS ON
/ RX FLOPPY DISKS ON A TRACK BY TRACK BASIS.  THE COMMAND FORMAT
/ IS:   DEV:<DEV:/OPTION   WHERE OPTIONS ARE P, N, M, R, OR V.
/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
/ IF NO OPTIONS ARE EXPLICITYLY DECLARED, COPY AND MATCH ARE ASSUMED.
/ IF THE R OPTION IS THE ONLY DISK ACCESSING OPTION SELECTED, THE
/ FOLLOWING FORMATS WORK: DEV:/R  DEV:</R   <DEV:/R.
/ 

MAGIC=7623		/LOCATION IN RX SYSTEM HANDLER WITH A 7004 IF
			/UNIT 0 OR A 7024 IF UNIT 1.  THIS IS ONLY
			/ACCESSED IF THE USER USES SYS: IN THE COMMAND
			/STRING AND SYS: IS KNOWN TO BE AN RX!!
OPT1=7643		/1ST COMMAND DECODER OPTION WORD
OPT2=7644		/2ND COMMAND DECODER OPTION WORD
BUFF=2000		/INPUT BUFFER FOR TTY MSGS
DEVTYP=25		/DEVICE CODE FOR FLOPPY DISKS
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
MMATCH=3777		/CMA OF MATCH OPTION MASK
MCOPY=6777		/CMA OF COPY OPTION MASK
MATCH=4000		/MATCH OPTION MASK
READ=0100		/READ OPTION MASK
VERSION=0004		/VERSION OPTION MASK
PAUS=0400		/PAUSE OPTION MASK

/	RXCOPY  READ-WRITE SUBROUTINE
/
	*6420
/
/  READ-WRITE SUBROUTINE TO HANDLE FLOPPY DISK IN 8-BIT MODE
/  ROUTINE LIVES IN FIELD 0 TO BE CALLED FROM FIELD 10
/
/  CALLING SEQUENCE
/
/	CIF 0		/ASSUMED CDF 10, CALLED FROM FIELD 10
/	TAD	TRACK	/TRACK # INTO AC
/	JMS I	(RW
/	BITS		/4000 IF FIELD 10 BUFFER, 2 IF READ, 20 IF UNIT 1
/	OK RETURN	/CDF AND CIF TO 10
/	ERROR		/SECTOR # IN AC
/
/  READS OR WRITES A TRACK AT A TIME. TWO BUFFERS LIVE IN 20-6417
/  EACH OF FIELD 0 AND 10
/
/ USES AUTO-INCREMENT REGISTER 10 OF FIELD 0
X10=10
/
/  AN ALTERNATE ENTRY OF CONTIN (JMP NOT JMS) CAUSES THE
/  SUBROUTINE TO CONTINUE WORKING ON THE SAME TRACK ON WHICH THE
/  ERROR OCCURRED.
/
/  THREE RETRIES ARE DONE ON A SECTOR BEFORE AN ERROR IS DECLARED.
/
SDN=6755
LCD=6751
STR=6753
XDR=6752
SER=6754
FLINIT=6757
/
/
/  USE PART OF PAGE AT 6400 TO SPREAD OUT WRITE LOOP
/  FOR A LITTLE EXTRA SAFETY ON MAKING INTERLEAVE TIMING
/
WRIT1,	TAD	(-10	/8 TIMES THRU 16 BYTE > 128
	DCA	WRTCNT
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
/
	PAGE
/
/
/  READ-WRITE ENTRY POINT
/
/
RW,	0
	DCA	TRCKNO	/ARRIVES WITH TRACK # IN AC
	TAD I	RW	/DATA FIELD 10, FETCH CONTROL BITS
	TAD	L7100	/FLOPPY CONTROLLER IGNORES TOP 4 BITS; 100
/			/BIT IS 8 BIT MODE; CONTROL FOR UNIT, R/W, IN PLACE
	DCA	FN	/BUFFER BIT (COMPLEMENTED) ALSO STORED IN FN
	TAD	(17	/SET UP AUTO-INCR REG.
	DCA	X10
	TAD	(-32	/26 DECIMAL SECTORS PER TRACK
	DCA	SECTOR
	ISZ	RW	/POINT TO OK EXIT
	TAD	FN	/IF FIELD ZERO BUFFER, NEED TO CDF
	SPA		/SKIP ON FIELD 10 BUFFER, ALREADY SET!
	CDF 0
	RTR		/READ/WRITE BIT TO LINK
	SZL CLA		/SKIP IF WRITE
	JMP	READLP	/GO TO READ
/
/  WRITE LOOP
/
WRITLP,	CLL CLA CMA RTL	/LITERAL -3 FOR RETRY COUNT
	DCA	RETRY
WRTRY,	TAD	FN	/RETRY ERROR HERE THREE TIMES
	JMS	LDCMD
	JMP	WRIT1	/OTHER PAGE TO MOVE DATA TO SILO
WRIT2,	JMS	DOIO	/RETURN FROM OTHER PAGE TO ACCESS I/O
	ISZ	SECTOR
	JMP	WRITLP
XT1,	CDF CIF 10
	JMP I	RW
/
/  READ LOOP
/
READLP,	CLL CLA CMA RTL	/LITERAL -3 FOR RETRY COUNT
	DCA	RETRY
RDTRY,	JMS	DOIO	/COME HERE TO RETRY I/O
	TAD	FN
	JMS	LDCMD
	TAD	(-40	/32 PASSES THRU 4 BYTES MOVED
	DCA	FLEA
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	FLEA
	JMP	ST5
	ISZ	SECTOR
	JMP	READLP
	JMP	XT1
/
/  DO READ OR WRITE I/O FUNCTION
/
DOIO,	0
	TAD	FN	/SILO FUNCTION, CONVERTED TO READ-WRITE
	TAD	L7004	/BY LITERAL 4 (TOP FOUR BITS IRREL)
	JMS	LDCMD
	JMS	GETSEC	/FETCH SECTOR TO AC
	STR
	JMP	.-1
	XDR
	CLA
	TAD	TRCKNO
	STR
	JMP	.-1
	XDR
	CLA
	TAD	L7530	/UNIT 1, 8-BIT NO-OP (TOP 4 BITS IGNORED)
	JMS	LDCMD
	JMP I	DOIO
/
/  LOAD COMMAND REGISTER
/
FLEA=.
LDCMD,	0
	SDN		/SKIP ON DONE
	JMP	.-1
	LCD		/LOAD COMMAND
	SER		/SKIP ON ERROR
	JMP I	LDCMD
	ISZ	RETRY	/TRIED THREE TIMES YET
	JMP	KEEPON	/NO, KEEP ON TRYING
	JMS	GETSEC	/RETURN SECTOR IN AC
	ISZ	RW	/ON ERROR, RETURN ONE FURTHER DOWN
	JMP	XT1	/EXIT TO CALLER WITH SECTOR # IN AC
/
/  ENTRY TO CONTINUE AFTER ERROR
/
CONTIN,	STA		/BACK UP EXIT TO GOOD EXIT
	TAD	RW
	DCA	RW
	TAD	FN	/SET DATA FIELD TO 0 IF NECESSARY
	SPA CLA		/ALREADY CDF TO 10, SKIP IF OK
	CDF 0		/NO, SO SET TO 0
	JMP I	LDCMD	/PRETEND OPERATION OK, SO RETURN THRU LDCMD!
/
KEEPON,	FLINIT		/DO A RECAL TO SHAKE IT UP
	TAD	FN	/RETRYING READ OR WRITE
	RTR		/R/W BIT TO LINK
	SZL CLA		/SKIP ON WRITE
	JMP	RDTRY	/RETRY A READ
	TAD	(-200	/BACK UP AUTO INCR TO REFILL SILO FOR WRITE
	TAD	X10	/SINCE THE FLINIT CLEARED SILO
	DCA	X10
	JMP	WRTRY	/SO GO RETRY WRITE
/
/  CONVERT COUNT TO SECTOR
/
GETSEC,	0
	TAD	SECTOR	/CONVERT -32 TO -1 TO INTERLEAVED SECTOR
	TAD	(15
L7100,	CLL		/100 BIT SETS 8-BIT MODE, AS LITERAL
L7530,	SPA SZL		/SZL JUST TO MAKE CORRECT LITERAL, NO-OP WAIT
	TAD	(15
	CML RAL
	IAC
	JMP I	GETSEC
L7004,	7004
/
/
/
TRCKNO,	0		/TRACK NUMBER, INVARIANT THRU CALL
SECTOR,	0		/COUNTS -32 UP TO 0; 26 DECIMAL SECTORS PER TRACK
FN,	0		/FUNCTION BITS: ALWAYS 100 FOR 8BIT MODE
/			/20 IF UNIT 1
/			/2 IF READ OPERATION (2 IS SILO FETCH; 0 SILO FILL)
/			/MINUS WORD IF BUFFER IN FIELD 0, PLUS IF FIELD 10
/			/CONTROLLER IGNORES TOP 4 BITS OF WORD
RETRY,	0		/RETRY COUNTER -3 TO 0
	FIELD	1
	*6000
/
/ ***** BEGIN ONCE ONLY CODE *****
/
/
/ ENTER HERE AND GET USER INPUTS
/
START,	CLA!SKP			/NORMAL ENTRY (MUST CALL DECODER)
CHAIN,	JMP	NODEC		/CHAIN ENTRY
	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			/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
	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
				/YES --
/
LOC3A,	JMS I	(USR		/LOAD RXA0 AND RXA1 SO UNIT NUMBERS CAN
	1			/BE FOUND.
	DEVICE	RXA0
RX0EP,	200
	NOP
	JMS I	(USR
	1
	DEVICE	RXA1
RX1EP,	200
	NOP
	JMP	LOC3		/GO TO NEXT PAGE
/
OUTDEV,	0			/OUTPUT DEVICE NUMBER
INDEV,	0			/INPUT DEVICE NUMBER
TMP1,	0			/TEMP STORE
TMP2,	0			/TEMP STORE
/
ERR2,	TAD	(MSG2		/ILLEGAL SPECIFICATION
PERR,	JMS	TYPE		/PRINT ERROR MESSAGE
	JMP	EXIT		/LEAVE
/
ERRUSR,	JMS I	(USR		/PRINT USER ERROR
	7
	2
	JMP	EXIT
/
/ SUBROUTINE UNIT -- FIND OUT WHAT THE UNIT NUMBER IS
/			ON ENTRY AC HAS DEVICE NUMBER
/			ON EXIT AC HAS 0 IFF UNIT 0 OR 0020 IFF UNIT 1
/
UNIT,	0
	DCA	TMP1		/SAVE DEVICE NUMBER
	CLA!CMA
	TAD	TMP1		/IS DEVICE SYS:?(I.E. IS DEV NUM=1?)
	SZA!CLA
	JMP	UNITNS		/NO
UNITSY,	CDF	0		/YES -- FIND OUT WHICH UNIT IS SYS:
	TAD I	(MAGIC		/GUT HOOK RX SYSTEM HANDLER********
	CDF	10
	AND	(0020		/IF AC IS 0 ITS UNIT 0
	JMP I	UNIT
UNITNS,	TAD	TMP1		/GET INFO ON DEVICE NUMBER
	JMS I	(USR
	12
UNITIN,	0
	JMP	ERR3		/SAY DEVICE IS NOT RX IF ERROR HERE
	TAD	UNITIN		/IS DEV SYS: IN DISGUISE?
	RAL
	SZL!CLA
	JMP	UNITSY		/YES -- GO DIG OUT THE UNIT NUM.
	TAD	UNITIN		/NO -- DOES EP MATCH RXA0'S
	CMA!IAC
	TAD	RX0EP
	SNA!CLA
	JMP I	UNIT		/YES
	TAD	UNITIN		/NO -- CHECK RXA1
	CMA!IAC
	TAD	RX1EP
	SZA!CLA
	JMP	ERR3		/NO -- ERROR
	TAD	(20		/YES
	JMP I	UNIT

/
	PAGE
/

/
/ CHECK THAT REQ'D DEVICES WERE SPECIFIED FOR OPTIONS SELECTED
/
LOC3,	JMS	OUTD		/CHECK THAT OUTPUT DEVICE  WAS GIVEN
	TAD I	(OPT2		/IF COPY OR MATCH, CHECK FOR INPUT DEV
	AND	(NOMAT!MATCH
	SZA!CLA
	JMS	IND
	TAD I	(OPT2		/IF NOT READ OPTION, CHECK FOR INPUT DEV
	AND	(READ
	SNA!CLA
	JMS	IND
/
/ PRINT VERSION IF SELECTED
/
VERS,	JMS	CTRLC		/CHECK FOR CONTROL C
	TAD I	(OPT2		/SHOULD VERSION NUMBER BE PRINTED?
	AND	(VERSION
	SNA!CLA
	JMP	TRANS		/NO -- GO CHECK THAT DEVS ARE RXS
	TAD	(VERBUF		/YES -- PRINT MESSAGE
	JMS	TYPE
/
/ PREPARE FOR DATA TRANSFER
/
TRANS,	TAD I	(OPT2		/SET C SWITCH IF COPY REQ'D
	AND	(MATCH!READ
	SNA!CLA
	JMP	TRANSB
	TAD I	(OPT2
	AND	(NOMAT
	SNA!CLA
	JMP	TRANSA		/DON'T SET C SWITCH
TRANSB,	TAD I	(OPT1		/SET IT
	AND	(MCOPY
	TAD	(COPY
	DCA I	(OPT1
TRANSA,	TAD I	(OPT2		/SET M SWITCH IF MATCH REQ'D
	AND	(NOMAT!READ
	SZA!CLA
	JMP	TRANS1
	TAD I	(OPT2
	AND	(MMATCH
	TAD	(MATCH
	DCA I	(OPT2
TRANS1,	TAD	OUTDEV		/NO -- CHECK THAT OUTPUT DEV IS RX
	TAD	(7757		/PREPARE TO GET DEV TYPE FROM TABLE
	DCA	TMP3
	TAD I	TMP3
	AND	(0770
	RTR!CLL
	RAR
	TAD	(-DEVTYP	/WAS DEVICE AN RX?
	SZA!CLA			/DOES IT MATCH?
	JMP	ERR3		/NO -- OUTDEV IS NOT AN RX!!
	TAD	OUTDEV		/SETUP UNIT NUMBERS
	JMS	UNIT		/FOR OUPUT DEVICE
	DCA	WO1
	TAD	WO1
	TAD	(4002
	DCA	RO1
/
OUTOK,	TAD I	(OPT1		/IF MATCH OR COPY GET INFO ON INDEV
	AND	(COPY
	SZA!CLA
	JMP	OUTOK1
	TAD I	(OPT2
	AND	(MATCH
	SNA!CLA			/WAS MATCH OR COPY SELECTED?
	JMP	DORDY		/NO -- OK
OUTOK1,	TAD	INDEV		/MAKE SURE INPUT DEVICE IS AN RX
	TAD	(7757		/PREPARE TO ACCESS TABLE
	DCA	TMP3
	TAD I	TMP3
	AND	(0770
	RTR!CLL
	RAR
	TAD	(-DEVTYP
	SZA!CLA			/DOES IT MATCH?
	JMP	ERR3		/NO -- ERROR
	TAD	INDEV		/SETUP UNIT NUMBERS
	JMS	UNIT		/FOR INPUT DEVICE
	TAD	(2
	DCA	RI1
DORDY,	JMS	QUEST		/PAUSE IF SPECIFIED
	MSG12
	JMP	DO		/PROCESS DISKS

/
/ SUBROUTINE IND -- RETURN IF INPUT DEVICE NUMBER IS NON-ZERO
/
IND,	0
	TAD	INDEV		/IF INPUT DEV WAS SPEC'D RETURN
	SNA!CLA			/IF NOT DECLARE ERROR
	JMP	ERR5
	JMP I	IND
/
/ SUBROUTINE OUTD -- RETURN IF OUTPUT DEVICE NUMBER IS NON-ZERO
/
OUTD,	0
	CLA
	TAD	OUTDEV		/IF OUTPUT DEV WAS SPEC'D RETURN
	SNA!CLA			/IF NOT DECLARE ERROR
	JMP	ERR6
	JMP I	OUTD
/
TMP3,	0			/TEMP STORE
TMP4,	0			/TEMP STORE
/
ERR3,	TAD	(MSG3
	JMP	PERR
ERR5,	TAD	(MSG5
	JMP	PERR
ERR6,	TAD	(MSG6
	JMP	PERR

/
	PAGE
/

DO,	JMS I	(USR		/UNLOCK USR FROM CORE
	11
	TAD	(-115		/INIT COUNTER TO -77 DECIMAL
	DCA	CNT
	DCA	TRACK		/INIT TRACK NUMBER TO 0
	JMP	DO1
/
/ ****** END OF ONCE ONLY CODE ******
/
	*6420
/
/ WAS COPY SELECTED?
/
DO1,	TAD I	(OPT1		/SHOULD WE COPY?
	AND	(COPY
	SNA!CLA
	JMP	DO2		/NO
	JMS	RI		/YES -- READ INPUT DEVICE INTO FIELD 0
	JMS	WO		/WRITE OUTPUT DEVICE FROM FIELD 0
/
/ WAS READ SELECTED?
/
DO2,	TAD I	(OPT2		/SHOULD WE READ?
	AND	(READ
	SNA!CLA
	JMP	DO3		/NO -- CHECK MATCH
	IAC			/YES -- READ OUTPUT DEVICE INTO FIELD 1
	JMS	RO
/
/ WAS MATCH SELECTED?
/
DO3,	TAD I	(OPT2		/SHOULD WE MATCH?
	AND	(MATCH
	SNA!CLA
	JMP	DO5		/NO
	TAD I	(OPT1		/YES -- WAS THERE A COPY?
	AND	(COPY
	SNA!CLA
	JMS	RI		/NO -- READ INPUT DEVICE INTO FILED 0
	TAD I	(OPT2		/YES -- WAS THERE A READ?
	AND	(READ
	SZA!CLA
	JMP	DO4		/YES
	IAC			/NO -- READ OUTDEV TO FIELD 1
	JMS	RO
/
/ COMPARE BUFFERS
/
DO4,	TAD	(BSTART
	DCA	PTR		/INIT BUFFER POINTER
	TAD	(-BSIZE		/SETUP WD IN BUFFER COUNTER
	DCA	WDCNT
DO4A,	TAD I	PTR		/GET A WD FROM FIELD 1
	DCA	TMP5		/SAVE
	CDF	0		/GET A WD FROM FIELD 0
	TAD I	PTR
	CDF	10
	CMA!IAC			/NEGATE
	TAD	TMP5		/DID WDS MATCH?
	SZA!CLA			/SKIP IF SO
	JMS	ERR7		/NO -- ERROR (BUT NOT FATAL)
	ISZ	PTR		/YES -- INCREMENT POINTER
	ISZ	WDCNT		/DONE WITH BUFFER?
	JMP	DO4A		/NO -- PROCEED
				/YES --
/
/ TEST FOR END OF DISK
/
DO5,	ISZ	TRACK		/INCREMENT TRACK
	ISZ	CNT		/DONE?
	JMP	DO1		/NO
	JMP	EXITOK		/YES
TMP5,	0			/TEMP STORE
CNT,	0			/ISZ COUNTER OF TRACKS
TRACK,	0			/TRACK NUMBER
PTR,	0			/WORD IN BUFFER POINTER
WDCNT,	0			/BUFFER WORD COUNTER
/
/ SUBROUTINE QUEST -- PRINT MSG AND ASK QUESTION
/			ASK IT ONLY IF /P WAS SPECIFIED
/			JMS+1 HAS MSG TO ASK
/			RETURN ONLY WHEN ANSWER IS YES
/
QUEST,	0
	TAD I	(OPT2		/WAS /P SPECIFIED?
	AND	(PAUS
	SNA!CLA
	JMP	Q2		/NO -- RETURN
Q1,	TAD I	QUEST		/YES -- GET MESG ADDR
	JMS	TYPE		/PRINT IT
	TAD	(BUFF		/SELECT INPUT BUFFER
	JMS	RDANS		/READ ANSWER
	TAD I	(BUFF		/WAS IT "Y"?
	AND	(77
	TAD	(-31
	SZA!CLA
	JMP	Q1		/NO -- ASK AGAIN
Q2,	ISZ	QUEST		/YES -- RETURN AT JMS+2
	JMP I	QUEST
/
/ SUBROUTINE CTRLC -- CHECK FOR CONTROL C
/
CTRLC,	0
	KRS
	AND	(177
	TAD	(-3
	SNA!CLA
	KSF
	JMP I	CTRLC
	JMP	EXIT
/
/ EXIT PROGRAM
/
EXITOK,	JMS	QUEST
	MSG11
EXIT,	CIF!CDF	0
	JMP I	(7605

/
	PAGE
/

/
/ SUBROUTINE RI -- READ FROM INPUT DEVICE
/
RI,	0			/READ FROM INPUT DEVICE
	JMS	CTRLC		/CHECK FOR CONTROL C
	TAD	TRACK		/GET TRACK NUMBER INTO AC
	CIF	0		/PREPARE TO ENTRY DRIVER
	JMS I	(RW		/CALL DRIVER
RI1,	0			/FUNCTION WORD
	JMP I	RI		/EXIT -- SUCCESSFUL
	JMS	ERR8		/ERROR
	JMS	CTRLC		/CHECK FOR CONTROL C
	CIF	0
	JMP I	(CONTIN		/PROCEED
/
/ SUBROUTINE RO -- READ FROM OUTPUT DEVICE
/
RO,	0			/READ FROM OUTDEV
	JMS	CTRLC		/CHECK FOR CONTROL C
	TAD	TRACK
	CIF	0
	JMS I	(RW
RO1,	0
	JMP I	RO
	JMS	ERR9
	JMS	CTRLC
	CIF	0
	JMP I	(CONTIN

/
/ SUBROUTINE WO -- WRITE OUTPUT DEVICE
/
WO,	0			/WRITE TO OUTPUT DEVICE
	JMS	CTRLC
	TAD	TRACK
	CIF	0
	JMS I	(RW
WO1,	0
	JMP I	WO
	JMS	ERR10
	JMS	CTRLC
	CIF	0
	JMP I	(CONTIN
/
/ MISC ERROR ROUTINES
/
ERR7,	0
	TAD	(-BSTART	/SUBTRACK BUFFER START
	TAD	PTR		/FROM WORD IN BUFFER POINTER
	TAD	(-BHALF		/THEN SUBTRACT 1/2 OF BUFFER SIZE
	SPA			/SKIP IF PTR IN 2ND HALF
	JMP	ERR7A		/PTR IN 1ST HALF
	AND	(7600		/DIVIDE BY 64 DECIMAL AND ADD 2
	CLL!RTR
	RTR
	RTR
	IAC
	JMP	ERR7W
ERR7A,	TAD	(BHALF		/MAKE POSITIVE
	AND	(7600		/DIVIDE BY 64 AND ADD 1
	CLL!RTR
	RTR
	RTR
ERR7W,	IAC
	DCA	ERRTMP		/SAVE SECTOR NUMBER
	TAD	TRACK		/WAS THERE ANOTHER MISMATCH ON THIS SECTOR?
	TAD	ERR7TR
	SZA!CLA
	JMP	ERR7P		/NO
	TAD	ERRTMP		/MAYBE
	TAD	ERR7SC
	SNA!CLA
	JMP I	ERR7		/YES
ERR7P,	TAD	(MSG7
	JMS	TYPE
	TAD	ERRTMP
	JMS	ADPRNT
	TAD	TRACK		/SAVE TRACK AND SECTOR
	CMA!IAC			/AS 2'S COMP FOR FUTURE COMPARISION
	DCA	ERR7TR
	TAD	ERRTMP
	CMA!IAC
	DCA	ERR7SC
	JMP I	ERR7
ERR7TR,	400
ERR7SC,	400
ERR8,	0
	DCA	ERRTMP
	TAD	(MSG8
	JMS	TYPE
	TAD	ERRTMP
	JMS	ADPRNT
	JMP I	ERR8
ERR9,	0
	DCA	ERRTMP
	TAD	(MSG9
	JMS	TYPE
	TAD	ERRTMP
	JMS	ADPRNT
	JMP I	ERR9
ERR10,	0
	DCA	ERRTMP
	TAD	(MSG10
	JMS	TYPE
	TAD	ERRTMP
	JMS	ADPRNT
	JMP I	ERR10
/
ERRTMP,	0
/

/
/ SUBROUTINE TYPE -- PRINT MESSAGE
/			ON ENTRY AC HAS MESSAGE ADDRESS
/
TYPE,	0
	DCA	TYPAD		/SAVE ADDR
	CIF	0
	JMS I	TTYENT
	4110
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
/

/
	PAGE
/
/
/ SUBROUTINE APRNT -- PRINT TRACK AND SECTOR
/			ENTER WITH SECTOR IN AC
/
ADPRNT,	0
	JMS	SETIN
	MSG13B-1
	TAD I	TRACKN
	JMS	SETIN
	MSG13A-1
	TAD	MSG
	JMS I	TYPEIT
	JMP I	ADPRNT
TYPEIT,	TYPE
TRACKN,	TRACK
MSG,	MSG13

/
/ 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	10		/ENTER INTO AUTOINC POINTER
	ISZ	SETIN		/BUMP RETURN ADDR
SETINB,	TAD	SETIN1		/GET NUMBER
	TAD	M12		/SUBTRACT 10 DECIMAL
	SMA			/DONE DIVIDING?
	JMP	SETINA		/NO
	CLA			/YES
	TAD	SETCNT		/GET 10'S
	TAD	P260		/MAKE IT ASCII
	DCA I	10		/STORE IN MESSAGE
	TAD	SETIN1		/GET REMAINDER
	TAD	P260		/MAKE IT ASCII
	DCA I	10		/STORE IN MESSAGE
	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
M12,	-12			/MINUS 10 DECIMAL
P7,	7			/LITERAL
P260,	260			/LITERAL

/ 
/ ERROR MESSAGES
/
VERBUF,	"R; "X; "C; "O; "P; "Y; 240; "V; "4; "A; 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; "T; "R; "A; "C; "K; 240
MSG13A,	0
	0
	",; "S; "E; "C; "T; "O; "R; 240
MSG13B,	0
	0
	215; 212; 232
$
