/RLC: RL01 DEVICE C NON-SYSTEM HANDLER
/
/
/
/
/
/
/
/
/
/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.
/
/
/
/
/
/
/
/
/
/
/RL01 DEVICE C NON-SYSTEM HANDLER


	VERSION="A&77

/NOTES:
/1. PRE-OMNIBUS COMPUTERS NOT SUPPORTED.

/EDIT HISTORY:
/9-NOV-77 DAVID SPECTOR: CREATION

/INSTRUCTIONS THAT GENERATE CONSTANTS

AC0001=CLA IAC
AC0002=CLA CLL CML RTL
AC0003=CLA CLL CML IAC RAL	/*
AC0004=CLA CLL IAC RTL		/*
AC0006=CLA CLL CML IAC RTL	/*
AC0100=CLA IAC BSW		/*
AC2000=CLA CLL CML RTR
AC3777=CLA CLL CMA RAR
AC4000=CLA CLL CML RAR
AC5777=CLA CLL CMA RTR
AC6000=CLA CLL CML IAC RTR	/*
AC7775=CLA CLL CMA RTL
AC7776=CLA CLL CMA RAL

/* USE ONLY ON VT-78 AND PDP-8E,F,M,A

/ID CODE AT START OF BAD BLOCK LIST (BBL)
	ID=123

/BAD BLOCK LIST FORMAT:
/(TRACK 0 SECTOR 16)
/WORD	CONTENTS
/0	ID (IDENTIFICATION CODE)
/1	BAD BLOCK NUMBERS (ASCENDING ORDER)
/...	...
/20	0 (LIST TERMINATOR)
/RL01 DEFINITIONS

RLIOT=6600
RLDC=RLIOT 0	/CLEAR DEVICE
RLSD=RLIOT 1	/SKIP IF DONE
RLMA=RLIOT 2	/LOAD MEM ADDR
RLCA=RLIOT 3	/LOAD REGISTER "A"
RLCB=RLIOT 4	/LOAD REG "B" AND EXECUTE
RLSA=RLIOT 5	/LOAD SECTOR ADDR
		/RLIOT 6 UNUSED
RLWC=RLIOT 7	/LOAD WORD COUNT
RRER=RLIOT 10	/READ ERROR REG
RRWC=RLIOT 11	/READ WORD COUNT
RRCA=RLIOT 12	/READ REG "A"
RRCB=RLIOT 13	/READ REG "B"
RRSA=RLIOT 14	/READ SECTOR ADDR
RRSI=RLIOT 15	/READ SILO BYTE
		/RLIOT 16 UNUSED
RLSE=RLIOT 17	/SKIP IF ERROR
/RLCB FUNCTION BITS:
	RLMT=0	/MAINTENANCE MODE
	RLRE=1	/RESET DRIVE ERRORS
	RLST=2	/READ STATUS REGS INTO SILO
	RLSK=3	/SEEK
	RLRH=4	/READ HEADER
	RLWR=5	/WRITE
	RLRD=6	/READ
	RLRN=7	/READ WITH NO HEADER CHECK
/BIT DEFINITIONS IN REGISTERS:
BYTE=1000	/BYTE TRANSFER MODE
/HEADER BLOCK FOR USE BY "BUILD"

	*0
	-4		/- NR DEVICES PER HANDLER

/FORMAT OF ENTRIES IN HEADER BLOCK:
/WORD	DESCRIPTION
/0	GROUP NAME (4 CHAR)
/2	DEVICE NAME (4 CHAR)
/4	DCB WORD FOR AN RL01(C), DIRECTORY DEVICE
/5	OFFSET TO ENTRY POINT, 2-PAGE INDICATOR
/6	0 (UNUSED WORD)
/7	0 TO REPRESENT NON-SYSTEM DEVICE

DEVICE RLC;DEVICE RL0C;4310;RL0C&177+4000;0;0
DEVICE RLC;DEVICE RL1C;4310;RL1C&177+4000;0;0
DEVICE RLC;DEVICE RL2C;4310;RL2C&177+4000;0;0
DEVICE RLC;DEVICE RL3C;4310;RL3C&177+4000;0;0
/HANDLER CODE

	*200		/FIRST PAGE

START,	DCA DRIVE	/SAVE DRIVE NUMBER.
	TAD DRIVE	/FIND ENTRY ADDR IN
	CLL RTL		/ORDER TO TRANSFER
	TAD TADX	/CALLING ADDR TO "ARG".
	DCA .+1
	TAD
	DCA ARG
	TAD I ARG	/GET ARGUMENTS
			/FUNCTION WORD
	AND A4070	/READ-WRITE, FIELD
	SPA
	TAD A3777	/IF WRITE, -1
	TAD ARLRD	/CONVERT FUNCTION TO RL01
			/FUNCTION WORD.
	DCA FNC
	TAD I ARG	/FUNCTION WORD
	RAL
	AND A7600	/PAGES IN BITS [7600];
			/0 MEANS 40.
	DCA PAGES
	ISZ ARG
	TAD I ARG	/MA
	DCA MA
	ISZ ARG
	TAD I ARG	/BLOCK
	DCA BLOCK
	ISZ ARG
	RDF		/SAVE CALLING FIELD
	TAD ACIDF	/FOR RETURN.
	DCA RTN
ACIDF,	CIF CDF 00	/CHANGE TO CURRENT FIELD.
	TAD A7600	/RETURN TO MONITOR IF USER
	KRS		/TYPES CTRL,C.
	TAD A175
	SNA CLA
	KSF
ONCE,	JMP ONLY	/ELSE START ONCE-ONLY CODE
			/AT "ONLY". "ONCE" GETS CHANGED
			/TO "JMP BEGIN" BY ONCE-ONLY CODE.
	JMP I A7600	/CALL MONITOR UPON CTRL,C.

/CONSTANTS

ATRANS,	TRANS-MAIN
ACURTK,	CURTRK-MAIN
CHECK,	-ID
A200,	200
A4070,	4070
/ENTRY POINTS

	IFNZRO 250-.	<ENTRY POINTS START AT OFFSET OF 50>

ARG,			/ADDR OF ARG LIST
RL0C,	VERSION		/DRIVE 0 ENTRY POINT
	CLA
	JMP START
TADX,	TAD ARG		/A CONSTANT
RL1C,	VERSION		/DRIVE 1 ENTRY POINT
	AC0001
	JMP START
A175,	175
RL2C,	VERSION		/DRIVE 2 ENTRY POINT
	AC0002
	JMP START
A3777,	3777
RL3C,	VERSION		/DRIVE 3 ENTRY POINT
	AC0003
	JMP START
GO,	0		/ONCE-ONLY CODE.
			/ADDRESS OF 2ND PAGE STORED HERE.
BBL,	TAD JMPX	/NEXT 21 OCTAL LOCATIONS ARE
			/REPLACED BY THE BAD BLOCK LIST
			/WHEN IT IS READ IN
			/FROM REQUESTED DRIVE.
			/ONCE-ONLY CODE: PREVENT EXE-
			/CUTION MORE THAN ONCE.
	DCA ONCE
LOOP,	TAD LIST	/RELOCATE LOCATIONS CONTAINING
	SNA		/RELATIVE ADDRESSES TO MAKE THEM
JMPX,	JMP BEGIN	/ABSOLUTE. LOCATION LIST IS TERM-
			/INATED BY ZERO.
	TAD GO		/RELOCATE VALUE IN LIST.
	DCA ONLY	/"ONLY" IS NOW TEMP STORAGE.
	ISZ LOOP
	TAD GO		/RELOCATE ADDRESS(VALUE).
	TAD I ONLY
	DCA I ONLY
	JMP LOOP	/CONTINUE UNTIL DONE.
LIST,	ABBL-MAIN	/LIST OF RELATIVE ADDRESSES OF
			/RELOCATABLE ADDRESSES.
	ATRANS-MAIN
	ACURTK-MAIN
	BBLOCK-MAIN
	BSECT-MAIN
	BTRACK-MAIN
	BHALF-MAIN
	BDRIVE-MAIN
	BASE-MAIN
	BERROR-MAIN
	0		/TERMINATOR.
/PERFORM TRANSFER, READING IN BBL IF NECESSARY

BEGIN,	AC2000	
	DCA I ACURTK	/FORCE IGNORANCE OF CURRENT
			/TRACK IN CASE OPERATION IS
			/TO A DIFFERENT DRIVE.
			/(2000 IS AN ILLEGAL TRACK)
	TAD DRIVE	/HAS DRIVE CHANGED FROM LAST CALL?
	CIA
	TAD CURDRV
	SNA CLA
	JMP I ATRANS	/NO, DO TRANSFER.
	TAD DRIVE	/YES, REMEMBER CHANGE AND
	DCA CURDRV	/READ IN BAD BLOCK LIST.
	JMS I GO	/CALL TRANSFER SUBROUTINE
	    0		/TRACK=0
	    16		/SECTOR=16
	    -21		/WC=-LIST LENGTH
ABBL,	    BBL-MAIN	/MA="BBL"
ARLRD,	    RLRD	/FUNCTION=READ INTO FIELD 0
	TAD I ABBL	/IS BBL VALID?
	TAD CHECK	/-ID.
	SNA CLA
	JMP I ATRANS	/YES, DO TRANSFER.
ERROR,	AC4000		/HANDLER ERROR RETURN.
	SKP
DONE,	ISZ ARG		/NORMAL HANDLER RETURN.
RTN,	CIF CDF		/RETURN TO CALLING FIELD.
	JMP I ARG
/SECTOR TRANSFER SUBROUTINE

HALF,	0		/TRANSFER ONE PAGE.
	JMS I GO	/CALL TRANSFER SUBROUTINE
TRACK,	    0		/TRACK
SECTOR,	    0		/SECTOR
A7600,	    7600	/-WORD COUNT
MA,	    0		/MEMORY ADDRESS
FNC,	    0		/FUNCTION WORD
	TAD A200	/INCREMENT MEMORY ADDRESS.
	TAD MA
	DCA MA
	ISZ SECTOR	/INCREMENT SECTOR ADDRESS.
	ISZ SECTOR	/(2:1 INTERLEAVE)
	TAD A7600	/DECREMENT PAGE COUNT.
	TAD PAGES
	SNA
	JMP DONE	/TAKE NORMAL HANDLER RETURN
			/WHEN PAGE COUNT REACHES ZERO.
	DCA PAGES	/ELSE CONTINUE TRANSFER.
	JMP I HALF

/VARIABLES

DRIVE,	0
PAGES,	0
BLOCK,	0

	ZBLOCK 377-.	/UNUSED: "ONLY" MUST BE AT 377!

CURDRV,			/CURRENT DRIVE (INITIALLY INVALID
			/TO FORCE READ-IN OF BAD BLOCK LIST).
ONLY,	JMS GO		/ONCE-ONLY CODE TO PUT ADDRESS
			/OF "MAIN" INTO "GO".
			/REUSED AS CURRENT DRIVE.
	*400		/SECOND PAGE

MAIN,	0		/TRANSFER UP TO ONE PAGE.
	AC7775		/INITIALIZE FOR 3 TRIES.
	DCA ERRCNT
	TAD MAIN	/SAVE ADDRESS OF ARGS.
	DCA MAINSV
	TAD I MAIN	/CALCULATE CYLINDER AND
			/SURFACE FROM TRACK.
			/1ST ARG=TRACK.
	CLL RAR
	DCA CYL
	RTR
	DCA SURF
	JMS TRKCMP	/IF ON TRACK, DO TRANSFER.
RETRY,	TAD MAINSV	/OFF TRACK: SEEK TO TRACK.
	DCA MAIN	/RESTORE ADDRESS OF ARGS.
	RLDC		/CLEAR CONTROLLER REGISTERS.
SEEK,	IAC		/AC=CLEAR DRIVE REGISTERS
			/FUNCTION (AC=SEEK FUNCTION
			/WHEN CALLED FROM BELOW).
	JMS IO		/DO RL01 FUNCTION.
	TAD HEADER
	JMS IO		/READ NEXT HEADER FROM DISK.
	RRSI		/GET HEADER BYTE #1.
	BSW
B377,	AND B3		/THIS INSTRUCTION IS ALSO USED
			/AS A CONSTANT.
	DCA CURTRK	/BITS [3] OF CURRENT TRACK.
	RRSI		/GET HEADER BYTE #2.
	AND B377	/THIS SHOULD BE DONE BY HARDWARE!
	CLL RTL		/BITS [774] OF CURRENT TRACK.
	TAD CURTRK
	DCA CURTRK
	JMS TRKCMP	/IF ON TRACK, DO TRANSFER.
	TAD CURTRK	/OFF TRACK: CONSTRUCT DIFFERENCE
	CLL RAR		/WORD FOR SEEK.
	CIA
	TAD CYL
	SMA
	JMP AROUND
	CIA
	SKP
AROUND,	TAD B4000	/SET DIRECTION BIT IF TO HIGHER
			/CYLINDER ADDRESS.
	TAD SURF
	RLCA		/LOAD DIFFERENCE WORD.
	AC0002		/PREPARE AC FOR SEEK FUNCTION.
	JMP SEEK	/SEEK.
TRKCMP,	0		/IF ON TRACK, DO TRANSFER.
	TAD CURTRK	/COMPARE CURRENT TRACK AND
	CIA		/DESIRED TRACK.
	TAD I MAIN	/1ST ARG=TRACK.
	SZA CLA
	JMP I TRKCMP	/DIFFERENT: SEEK.
	ISZ MAIN	/ON TRACK: DO TRANSFER.
	TAD CYL
	TAD SURF
	RLCA		/LOAD DISK ADDRESS OF TRACK.
	TAD I MAIN	/2ND ARG=SECTOR.
	BSW
	RLSA		/LOAD SECTOR ADDRESS.
	ISZ MAIN
	TAD I MAIN	/3RD ARG=WORD COUNT.
	RLWC		/LOAD WORD COUNT.
	ISZ MAIN
	TAD I MAIN	/4TH ARG=MA.
	RLMA		/LOAD MA.
	ISZ MAIN
	TAD I MAIN	/5TH ARG=FUNCTION.
	JMS IO		/DO RL01 FUNCTION.
	ISZ MAIN
	JMP I MAIN	/RETURN FROM TRANSFER SUBROUTINE.
TRANS,	TAD BASE	/DO TRANSFER.
			/INITIALIZE BAD BLOCK MAPPING.
	DCA MAPPER
MAP,	TAD I MAPPER	/DO BAD BLOCK MAPPING.
			/GET BAD BLOCK IF ANY.
	SNA		/DONE? (0 TERMINATES)
	JMP MAPPED	/YES.
	STL CIA		/NO, 13-BIT NEGATE.
	TAD I BBLOCK	/SUBTRACT FROM CURRENT BLOCK.
	SZL CLA		/IS BAD BLOCK GREATER (UNSIGNED)?
	JMP MAPPED	/YES, MAPPING IS DONE.
	ISZ MAPPER	/NO, MAP AROUND THIS BAD BLOCK
			/AND TRY NEXT.
NEXT,	ISZ I BBLOCK	/WILL NEVER SKIP.
	JMP MAP		/CONTINUE MAPPING UNTIL DONE.
MAPPED,	TAD I BBLOCK	/CALCULATE SECTOR FROM BLOCK.
	AND B3
	CLL RTL
	DCA I BSECT
	TAD I BBLOCK	/TEST BLOCK FOR LEGALITY: LEGAL
	TAD B4010	/BLOCKS ARE 0-3767.
	SZL CLA
	JMP I BERROR
	TAD I BBLOCK	/CALCULATE TRACK FROM BLOCK.
	RTR
	AND B777
	IAC
	DCA I BTRACK
	JMS I BHALF	/TRANSFER 1ST HALF OF BLOCK.
	JMS I BHALF	/TRANSFER 2ND HALF OF BLOCK.
	JMP NEXT	/CONTINUE WITH NEXT BLOCK.
IO,	0		/DO RL01 FUNCTION.
	BSW
	TAD I BDRIVE
	BSW		/PUT DRIVE INTO BITS [300].
	RLCB		/DO RL01 COMMAND.
	RLSD		/WAIT UNTIL DONE.
	JMP .-1
	RLSE		/ANY ERRORS?
	JMP I IO	/NO, RETURN.
	ISZ ERRCNT	/YES, TRY AGAIN?
	JMP RETRY	/YES.
	JMP I BERROR	/TAKE ERROR RETURN WHEN 3
			/TRIES HAVE BEEN DONE.

/DATA
BBLOCK,	BLOCK-MAIN
BSECT,	SECTOR-MAIN
BTRACK,	TRACK-MAIN
BHALF,	HALF-MAIN
BDRIVE,	DRIVE-MAIN
BERROR,	ERROR-MAIN
BASE,	BBL+1-MAIN	/START OF BBL FOR MAPPING.
MAPPER,	0
MAINSV,	0		/SAVED "MAIN" VALUE.
CURTRK,	0
HEADER,	BYTE RLRH
SURF,	0
CYL,	0
ERRCNT,	0
B777,	777
B4000,	4000
B4010,	4010

	ZBLOCK 577-.	/UNUSED.

B3,	3		/THIS CONSTANT MUST BE AT
			/LAST LOC OF 2ND PAGE.

$
