/FLOPPY DISK (RX01,RX71) NON-SYSTEM HANDLER FOR OS/8
/
/
/
/
/
/
/
/
/
/COPYRIGHT  (C)  1977 BY DIGITAL EQUIPMENT CORPORATION
/
/
/
/
/
/
/
/
/
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE WITHOUT NOTICE
/AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
/CORPORATION.  DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/FOR ANY ERRORS THAT MAY APPEAR IN THIS DOCUMENT.
/
/THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FURNISHED TO THE PURCHASER
/UNDER A LICENSE FOR USE ON A SINGLE COMPUTER SYSTEM AND CAN BE COPIED
/(WITH INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR USE IN SUCH
/SYSTEM, EXCEPT AS MAY OTHERWISE BE PROVIDED IN WRITING BY DIGITAL.
/
/DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY FOR THE USE
/OR RELIABILITY OF ITS SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY
/DIGITAL.
/
/
/
/
/
/
/
/
/
/
/FLOPPY DISK (RX01,RX71) NON-SYSTEM HANDLER FOR OS/8

/DEFINITIONS OF RX8/E IOT'S

RXVER=	"E&77

DEVCOD=	750	/DEVICECODE

LCD=	6001+DEVCOD	/LOAD COMMAND REGISTER
XDR=	6002+DEVCOD	/TRANSFER DATA REGISTER
STR=	6003+DEVCOD	/SKIP ON TRANSFER REQUEST FLAG, CLEAR FLAG
SER=	6004+DEVCOD	/SKIP ON ERROR FLAG, CLEAR FLAG
SDN=	6005+DEVCOD	/SKIP ON DONE FLAG, CLEAR FLAG
INTR=	6006+DEVCOD	/INTERRUPT ENABLE/DISABLE
INIT=	6007+DEVCOD	/INITIALIZE CONTROLLER AND RECALIBRATE DRIVES


/NOTES ON THIS HANDLER:

/THIS HANDLER READS AND WRITES THE DISK IN "12-BIT" MODE, IN WHICH
/ONLY 6 BITS OF EVERY 8-BIT BYTE ARE USED. AN RX01 CARTRIDGE
/CONTAINS 494 OS/8 BLOCKS UNDER THIS METHOD

/TO MAXIMIZE SPEED ON THE DEVICE, THE HANDLER READS AND WRITES DATA
/ON A TRACK WITH A TWO-WAY INTERLEAVE - I.E. RECORDS 1-26 ON A TRACK
/ARE WRITTEN IN THE SEQUENCE:
/  1,3,5,7,9,11,13,15,17,19,21,23,25,2,4,6,8,10,12,14,16,18,20,22,24,26

/IN THIS WAY THE HANDLER CAN TRANSFER DATA AT A 5KHZ WORD RATE

/MODIFIED TO ALLOW ADDRESS CALCULATION DURING SECTOR BUFFER
/LOAD-UNLOAD.
	*0		/ORIGIN FOR BUILD

	-2		/TWO ENTRY POINTS
	DEVICE	RX01	/"RX01" IS THE GROUP NAME
	DEVICE	RXA0	/"RXA0" IS THE ENTRY POINT NAME
	4250		/DCB WORD - DEVICE TYPE 25, DIRECTORY DEVICE
	RXA0&177	/ENTRY POINT OFFSET
	0		/THIS WORD ALWAYS SEEMS TO BE 0
	0		/UNUSED FOR NONSYSTEM DEVICE

	DEVICE	RX01	/"RX01" IS THE GROUP NAME
	DEVICE	RXA1	/"RXA1" IS THE ENTRY POINT NAME
	4250		/DCB WORD - DEVICE TYPE 25, DIRECTORY DEVICE
	RXA1&177	/ENTRY POINT OFFSET
	0		/THIS WORD ALWAYS SEEMS TO BE 0
	0		/UNUSED FOR NONSYSTEM DEVICE
	*200		/HANDLER CODE

BUF,	0		/USER BUFFER POINTER
REC,	0		/RX01 RECORD NUMBER BEFORE INTERLEAVING
BC,	0		/BLOCK COUNT OF TRANSFER
FN,	0		/FUNCTION, 0=WRITE, 2=READ
TRANS,	0		/TRANSFER COMMAND

FLPWC=.			/100 COUNTER FOR SILO OK IN LDCMD ENTRY
LDCMD,	0		/WAIT FOR DONE FLAG AND LOAD CMD REG
	DCA	TRANS	/SAVE THE NEW COMMAND REG VALUE
DONELP,	TAD	S7600	/SEE IF THE KEYBOARD BUFFER
	KRS		/CONTAINS A CONTROL/C CHARACTER
	TAD	(-7603	/(WITH OR WITHOUT PARITY)
	CLL		/KEEP LINK CLEAAR
	SNA CLA
	KSF		/WITH THE FLAG UP.
	JMP	NOTCTC	/IF NOT, CONTINUE
SCDIF0,	CDF CIF 0	/IF SO, RETURN TO OS/8
	JMP I	S7600

NOTCTC,	SDN		/WAIT FOR THE DONE FLAG TO COME UP
	JMP	DONELP	/BEFORE YOU LOAD THE COMMAND REGISTER
	TAD	TRANS	/NOW GET THE NEW COMMAND REGISTER CONTENTS
	LCD		/AND LOAD IT.
	SER		/SKIP IF I/O ERROR
	JMP I	LDCMD	/AND RETURN
	CLA CLL CML RAR	/SET AC TO 4000
	JMP	SRET	/TAKE ERROR RETURN


RXA0,	RXVER		/ENTRY POINT FOR UNIT 0
	CLA		/BE PROTECTIVE
	JMP	RXCOMN	/GO TO COMMON CODE
S70,	70		/** MUST BE AT 33 ON THIS PAGE**

	IFNZRO	S70&177-33	<.ERROR>

MQ,			/DIVIDE TEMPORARY
RXA1,	RXVER		/ENTRY POINT FOR UNIT 1
	CLA		/CAREFUL, CAREFUL!
	TAD	RXA1
	DCA	RXA0	/PUT CALLING ADDR IN KNOWN PLACE
	TAD	DIVLP	/GET "20"
RXCOMN,	TAD	DIVRAL	/SET AC TO 20*UNIT+4
	DCA	UNIT	/SAVE UNIT NUMBER
	RDF
	TAD	SCDIF0	/REMEMBER CALLING FIELD FOR RETURN
	DCA	SRET

/  OVERALL COMMENTS:
/
/  LINK REMAINS 0 THROUGH THE MAIN PROCESSING LOOP
/  EXCEPT AS MANIPULATED BY DIVSUB
/
/  OVERALL LOOP CONTROL THROUGH BC IS MILDLY ODD.
/  BC STARTS WITH MINUS COUNT OF THE # OF WORDS TO BE TRANSFERRED.
/  BC IS INCREMENTED 77 TIMES AT THE SILO CODE, AND 1 TIME AFTER
/  THE I/O OPERATION. 
/  A READ OPERATION STARTS AND FINISHES AT THE MIDDLE OF THE LOOP.
/  A WRITE OEPRATION STARTS AT THE TOP, AND FINISHES AT BOTTOM.
/  THUS, A 1 BLOCK READ INCREMENTS 1, 77, 1, 77 AND EXITS FROM MIDDLE.
/  AND, A 1 BLOCK WRITE INCREMENTS 77, 1, 77, 1 AND EXITS FROM BOTTOM.
/
/  DIVISION IS CARRIED OUT IN PARALLEL WITH I/O OPERATION BECAUSE OF
/  TIMING CONSIDERATIONS OF THE VT78.
/
/  THERE IS NO ERROR RETRY, NOT PARTICULARLY CRITICAL FOR A FLOPPY.

	CLL CML CLA RAR	/SET LINK=0, AC=4000
	TAD I	SYS	/TO PUT READ-WRITE BIT TO LINK
S33,	AND	S70	/KEEP BITS FOR CDF
	TAD	SCDF0	/ADDING IN CDF LITERAL
	DCA	BUFCDF	/CDF INSTRUCTION TO USER'S BUFFER
	CML RTL		/FUNCTION CODE, 0=WRITE, 2=READ
	DCA	FN
	TAD I	SYS	/MAKE CONTROL COUNT
	RAL	
	AND	S7600	/MAKE CONTROL COUNT FOR TOTAL
	CIA		/NUMBER OF WORDS
	DCA	BC
	ISZ	SYS
	TAD I	SYS	/FETCH BUFFER ADDRESS
	DCA	BUF
	ISZ	SYS
	TAD I	SYS	/OS8 BLOCK #
	CLL RTL		/TIMES 4 TO BE FLOPPY SECTOR #
	DCA	REC
	ISZ	SYS	/ERROR EXIT FROM I/O CALL
	JMS	DIVSUB	/COMPUTE TRACK/SECTOR FOR FIRST I/O
	TAD	FN	/READ OR WRITE START DIFFERENTLY
	SZA CLA		/SKIP ON WRITE
	JMP	STREAD	/GO TO READ
/
/  WRITE FALLS THRU.......
/
/
/
/ TOP OF MAIN PROCESSING LOOP
/
SETSLO,	TAD	FN	/SET SILO TO LOAD-UNLOAD DEPENDING
	JMS	LDCMD
	TAD	S7700	/SILO CONTROL COUNT 100 OCTAL
	DCA	FLPWC
BUFCDF,	HLT		/CDF TO USER'S BUFFER PLACED HERE
TRLOOP,	TAD I	BUF	/FETCH A WORD IN CASE WRITE
	STR		/WAIT
	JMP	.-1
	XDR		/AC TO SILO; OR; SILO TO AC
	DCA I	BUF	/PLACE A WORD IN CASE READ; WRITE REPLACES SAME.
	ISZ	BUF	/MOVE TO NEXT BUFFER LOCATION (MAY SKIP)
S77,	77		/LITERAL 77, EXECUTES AS A NOP
	ISZ	FLPWC	/DONE WITH 100 OCTAL SILO OPERATION
	JMP	TRLOOP	/NO
	TAD	BC	/INCREMENT BC BY 77 HERE, 1 LATER
	TAD	S77	/CHECKING FOR A READ EXIT
MAGIC,	SNA		/IF BC HAS GONE TO ZERO, NO-OP FOR LDCMD
	JMP	OKEX	/READ EXIT.
	DCA	BC	/REPLACING BC FOR WRITE EXIT CHECK AT LOOP END
/
/  MIDDLE OF MAIN PROCESSING LOOP
/
STREAD,	TAD	FN	/READ STARTS HERE
	TAD	UNIT	/SET UP DO DO READ OR WRITE I/O
	JMS	LDCMD
	TAD	MQ	/LOAD PRECOMPUTED SECTOR INFO
	STR
	JMP	.-1	/IN CASE NOT READY
	XDR
S7700,	7700		/CLEAR AC, CAN'T SKIP (XDR LEAVES AC ALONE)
	TAD	QUO	/TRACK
	STR		/ILLEGAL 7700 ENTRY WILL HANG; THE FUNCTION
	JMP	.-1	/IS NOT SET UP (LDCMD)
	XDR
S7600,	7600
	ISZ	REC	/MOVE TO NEXT FLOPPY SECTOR
	JMS	DIVSUB	/COMPUTE NEXT TRACK AND SECTOR DURING THIS I/O
	TAD	MAGIC	/WAIT FOR I/O TO COMPLETE
	JMS	LDCMD
	ISZ	BC	/CHECK FOR WRITE EXIT
	JMP	SETSLO	/NO, BACK TO TOP
OKEX,	ISZ	SYS	/BUMP TO REGULAR EXIT
SRET,	HLT		/CDF CIF FOR USER'S CALLING FIELD
	JMP I	SYS	/GONE
/
UNIT,	0		/UNIT
SYS=RXA0
/
/
/
/  LITERALS
/
SM15,	-15
SCDF0,	CDF 0
/
/  DIVSUB
/
/  MUST ENTER WITH LINK AND AC 0
/  COMPUTES TRACK IN 'QUO', SECTOR IN 'MQ', FROM # IN 'REC'
/
/  REPEATED SUBTRACTS OF 13 DECIMAL LEAVE THE HIGH N-1 BITS OF
/  QUOTIENT IN QUO, THE LOW BIT OF QUOTIENT IN LINK, AND THE
/  REMAINDER IN AC. THE INTERLEAVE IS ACCOMPLISHED BY SHIFTING
/  LOW QUOTINET BIT INTO LOW REMAINDER BIT.
/
DIVSUB,	0
	DCA	QUO	/INIT QUOTIENT FOR DIVIDE
	TAD	REC	/RECORD # MASSAGED IN AC
DIVLP,	SNL		/LINK USAGE REVERSED FROM RICHIE'S CODE
	ISZ	QUO	/ISZ EVERY OTHER TIME, <=DIVIDE BY 26
	TAD	SM15	/THE -13 DECIMAL
	SMA		/SKIP ON DONE
	JMP	DIVLP	/MORE
DIVRAL,	RAL		/LINK USAGE REVERSED; INTERLEAVE!!
	TAD	S33	/ADD 233 (200 IRREL) MAKING SECTOR
	DCA	MQ
	JMP I	DIVSUB	/LEAVING LINK AND AC 0
QUO,	0		/DIVIDE TEMP
/

	$


