/RL0: RL01 DRIVE 0 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 DRIVE 0 NON-SYSTEM HANDLER

	VERSION="A&77

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

/EDIT HISTORY:
/13-OCT-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:
/WORD	CONTENTS
/0	ID (IDENTIFICATION CODE)
/1	BAD BLOCKS FOR DEVICE A (ASCENDING ORDER)
/...	...
/20	0 (TERMINATOR FOR LIST A)
/21	BAD BLOCKS FOR DEVICE B (ASCENDING ORDER)
/...	...
/40	0 (TERMINATOR FOR LIST B)

/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
	-2		/- 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 RL (TYPE 26) DIRECTORY DEVICE
/5	OFFSET TO ENTRY POINT, 2-PAGE INDICATOR
/6	0 (UNUSED WORD)
/7	0 TO REPRESENT NON-SYSTEM DEVICE

	DRIVE=0

DEVICE RL0;DEVICE RL0A;4260;RLA&177+4000;0;0
DEVICE RL0;DEVICE RL0B;4260;RLB&177+4000;0;0
/HANDLER CODE
	*200		/FIRST PAGE

/DATA

A17,	17
A47,	47
A175,	175
A200,	200
A377,	377
A7751,	7751
BASE,	TAD BBL+1
ABLOCK,	BLOCK-MAIN
AMA,	MA-MAIN		/RELATIVE ADDR OF MA
ASECT,	SECTOR-MAIN
ATRACK,	TRACK-MAIN
AERROR,	ERROR-MAIN

/SET UP ARGUMENTS BY CALLING 2ND PAGE SUBROUTINE
SET,	TAD OFFSET	/INITIALIZE MAPPING (BELOW)
	BSW
	CLL RTL		/(0 OR 20: DEVICE A OR B)
	TAD BASE
	DCA MAP
	TAD RLB		/ADDR OF ARGS
	JMS I GO	/SETUP (AC NON-ZERO)
/MAP NEXT BLOCK AROUND ANY BAD BLOCKS BELOW IT
MAP,	TAD		/INITIALIZED ABOVE
	SNA		/0 TERMINATES LIST
	JMP MAPPED
	STL CIA		/13-BIT NEGATE
	TAD I ABLOCK	/COMPARE WITH BLOCK
	SZL CLA
	JMP MAPPED	/BAD BLOCK IS ABOVE CURRENT BLOCK
	ISZ MAP		/TRY NEXT BAD BLOCK ALSO
NEXT,	ISZ I ABLOCK	/INCREMENT CURRENT BLOCK NUMBER,
			/EITHER DURING
			/BAD BLOCK MAPPING OR AFTER SUCCESSFUL TRANSFER
			/OF TWO SECTORS (PAGES) WITH MORE TO GO
	JMP MAP		/CONTINUE MAPPING
	JMP I AERROR	/ERROR ON BLOCK OVERFLOW
	ZBLOCK 240+DRIVE-.	/UNUSED

/ENTRY POINT FOR DEVICE B

RLB,	VERSION
	AC0004		/TRACK OFFSET WILL BE 400
	JMP START	/SKIP AROUND RLA ENTRY POINT
OFFSET,	0		/TRACK OFFSET FOR DEVICE (0 OR 400)

/ENTRY POINT FOR DEVICE A

RLA,	VERSION
A7600,	7600		/=CLA
	TAD RLA		/TRANSFER CALLING ADDR
	DCA RLB
START,	BSW		/SET OFFSET TO 0 IF DEV A, 400 IF DEV B
	DCA OFFSET
	TAD A7600	/RETURN TO KEYBOARD MONITOR
	KRS		/IF CTRL,C TYPED
	TAD A175	/-CTRL,C
	SNA CLA
	KSF
ONCE,	JMP ONLY	/THIS INSTRUCTION IS DONE ONCE ONLY. IT IS
			/THEN CHANGED TO "JMP SET" AFTER HANDLER RELOCATION
			/IS DONE AND THE BAD BLOCK LIST IS READ IN.
ACDIF,	CIF CDF 00
	JMP I A7600	/CALL KB MONITOR
/THIS LOC IS SET TO ADDR OF NEXT PAGE BY ONCE-ONLY CODE
GO,	0		/ADDR OF MAIN
/-----BOUNDARY OF BAD BLOCK LIST-----
BBL,
/ONCE-ONLY CODE, REPLACED BY BAD BLOCK LIST
/READ IN BAD BLOCK LIST (BBL)
/SAVE CALLING DATA FIELD
	RDF
	TAD OOCDF
	DCA BACK
OOCDF,	CDF 00		/SET TO CURRENT FIELD
/REPLACE ONCE-ONLY JUMP INSTRUCTION
	TAD JMPSET
	DCA ONCE
LOOP,	TAD LIST	/RELOCATE CROSS-PAGE REFERENCES;
			/SCAN "LIST" FOR RELATIVE LOCATIONS
			/OF VALUES TO BE RELOCATED
	SNA		/0 ACTS AS TERMINATOR
	JMP OUT
	TAD GO		/RELOCATE RELATIVE ADDRESS
	DCA ONLY	/"ONLY" IS NOW TEMP STORAGE
	ISZ LOOP	/NEXT VALUE
	TAD GO
	TAD I ONLY	/RELOCATE THE CONTENTS
	DCA I ONLY
	JMP LOOP	/CONTINUE UNTIL DONE

/LIST OF RELATIVE ADDRESSES OF RELATIVE VALUES

LIST,	BARG-MAIN
	ABLOCK-MAIN
	BBBL-MAIN
	AMA-MAIN
	ASECT-MAIN
	ATRACK-MAIN
	MA-MAIN
	AERROR-MAIN
	0		/TERMINATOR

	ZBLOCK	BBL+40-.	/UNUSED (IN BBL BUFFER)

/ONCE-ONLY CODE CONTINUES
OUT,	JMS I GO	/READ BAD BLOCK LIST
/-----BOUNDARY OF BAD BLOCK LIST-----
OK,	CLA		/ERROR RETURN (IGNORE)
BACK,	CDF		/RESTORE CALLING FIELD
JMPSET,	JMP SET		/SETUP FOR TRANSFER

/END OF ONCE-ONLY CODE
/SETUP ARGS FOR CALL TO 2ND PAGE SUBROUTINE
/CALCULATE TRACK AND SECTOR FROM BLOCK
MAPPED,	TAD I ABLOCK
	RTR
	RTR
	AND A377
	TAD OFFSET	/DEVICE OFFSET (0 OR 400)
	DCA I ATRACK
	TAD I ABLOCK	/CALCULATE SECTOR FROM BLOCK
	AND A17		/SECTOR CODE
	CLL RTL
	TAD A7751
	SPA
	TAD A47
	BSW
	DCA I ASECT
/TRANSFER 1ST PAGE OF BLOCK
	JMS I GO
	TAD A200	/INCREMENT MA
	TAD I AMA
	DCA I AMA
/INCREMENT SECTOR
	TAD A200
	TAD I ASECT
	DCA I ASECT
/TRANSFER 2ND PAGE OF BLOCK
	JMS I GO
	TAD A200	/INCREMENT MA
	TAD I AMA
	DCA I AMA
/CONTINUE WITH NEXT BLOCK
	JMP NEXT

/ONCE-ONLY CODE AT END OF PAGE
	ZBLOCK 377-.	/UNUSED
ONLY,	JMS GO		/EXECUTED ONCE ONLY; STORES ADDR OF
			/2ND PAGE IN LOC "GO"
	*400
/2ND PAGE OF HANDLER

/SUBROUTINE TO SETUP AND TRANSFER
/AC=0 FOR TRANSFER ELSE SETUP
MAIN,	0
	SNA
	JMP TRANS
/GET HANDLER ARGUMENTS
SETUP,	DCA BARG	/ADDR OF HANDLER ARGS
	AC2000		/SET "OLDTRK" TO INVALID TRACK
	DCA OLDTRK	/TO FORCE READING NEXT HEADER.
	TAD B7600	/SET FOR FULL PAGE TRANSFERS
	DCA WC		/(WAS SMALLER FOR BBL READ)
	TAD I BARG	/NOW GET HANDLER ARGUMENTS
			/FUNCTION WORD
/NOTE: THE FOLLOWING INSTRUCTION IS USED AS A CONSTANT
B377,	AND B4070	/CONVERT TO RLCB FORMAT
	SPA
	TAD B3777
	TAD BRLRD
	DCA FNC
	TAD I BARG	/FUNCTION WORD
	RAL		/CONVERT TO PAGE COUNT IN BITS [7600]
	AND B7600
	DCA PAGES
	ISZ BARG
	TAD I BARG	/MA
	DCA MA
	ISZ BARG
	TAD I BARG	/BLOCK
	DCA BLOCK
	ISZ BARG
/SAVE CALLING FIELD FOR RETURN
	RDF
	TAD BCDIF
	DCA BRTN
/RESET DATA FIELD AND RETURN FROM SETUP WITH AC=BLOCK
BCDIF,	CIF CDF 00
/GET DEVICE OFFSET FROM 1ST PAGE
	TAD I BBBL	/CHECK FOR BBL VALIDITY -
	TAD CHECK	/1ST LOC OF BBL CONTAINS AN
	SZA CLA		/IDENTIFICATION CODE ("ID")
	JMP ERROR	/TAKE ERROR RETURN FROM HANDLER
			/IF BBL IS INVALID.
	JMP I MAIN
/TRANSFER ONE OR MORE PAGES TO/FROM DISK
/GET INTERPAGE ARGUMENTS
/RESET RETRY COUNT FOR 2 RETRIES ON I/O ERRORS
TRANS,	AC7775		/AC=-3
	DCA ERRCNT
/CALCULATE CYLINDER AND SURFACE FROM TRACK
	TAD TRACK
	CLL RAR
	DCA CYL
	RTR
	DCA SURF
/COMPARE WITH OLD (PREVIOUS) TRACK; IF SAME, DO TRANSFER
	JMS TRKCMP
/IF REQUESTED TRACK IS DIFFERENT, SEEK TO TRACK
/RESET DRIVE (FUNCTION=1)
RETRY,	RLDC		/CLEAR CONTROLLER, AC
/SEEK (FUNCTION=3) WHEN CALLED FROM BELOW
SEEK,	IAC		/AC=(1 OR 3)
	JMS IO		/RESET DRIVE OR SEEK
/READ NEXT HEADER TO FIND OUT ACTUAL CURRENT TRACK
	TAD HEADER
	JMS IO		/READ NEXT HEADER
	RRSI		/GET HEADER BYTE #1
	BSW
	AND B3
	DCA OLDTRK	/SAVE 2 LSB
	RRSI		/GET HEADER BYTE #2
	AND B377	/HARDWARE SHOULD DO THIS
	CLL RTL
	TAD OLDTRK	/ADD IN MSB
	DCA OLDTRK
/COMPARE WITH OLD (PREVIOUS) TRACK; IF SAME, DO TRANSFER
	JMS TRKCMP
/IF REQUESTED TRACK IS DIFFERENT, SEEK TO TRACK
/CALCULATE DIFFERENCE WORD FOR SEEK FROM TRACK DIFFERENCE
	SPA		/IF POSITIVE, LINK WILL BE SET
	CLL CIA		/IF NEGATIVE, CLEAR LINK
	RAR		/DELETE SURFACE, INCLUDE DIRECTION
	TAD SURF	/ADD SURFACE
	RLCA		/LOAD DIFFERENCE WORD
	AC0002		/PREPARE FOR SEEK
/LOOP BACK AND PERFORM SEEK; THIS ENSURES THAT THE TRACK
/REACHED IS THE CORRECT ONE IN SPITE OF POSSIBLE RL01
/SEEK UNRELIABILITY
	JMP SEEK
/SUBROUTINE TO COMPARE REQUESTED TRACK WITH OLD (REMEMBERED)
/TRACK; IF SAME, DO TRANSFER. IF DIFFERENT, RETURN WITH AC=
/REQUESTED-OLD, AND LINK=1
TRKCMP,	0
	TAD OLDTRK	/CALCULATE DIFFERENCE
	CIA
	TAD TRACK
	STL		/LINK MUST BE SET WHEN
			/DIFFERENCE IS POSITIVE.
	SZA
	JMP I TRKCMP	/DIFFERENT; RETURN
/ON TRACK: DO TRANSFER
/LOAD ALL REGISTERS
	TAD SECTOR
	RLSA
	TAD WC
	RLWC
	TAD SURF
	TAD CYL
	RLCA
	TAD MA
	RLMA
/DO THE READ OR WRITE
	TAD FNC
	JMS IO
/COUNT REQUESTED NUMBER OF PAGES
	TAD B7600
	TAD PAGES
	SNA
	JMP DONE
	DCA PAGES
	JMP I MAIN	/RETURN FOR MORE
/SUBROUTINE TO DO THE ACTUAL I/O
IO,	0		/AC=MODE,FIELD,FUNCTION
	TAD BDRIVE
	RLCB		/DO THE OPERATION
	RLSD		/WAIT UNTIL DONE
	JMP .-1
	RLSE		/TEST FOR I/O ERROR(S)
	JMP I IO	/NONE; RETURN
/IF ERROR, RETRY TWICE
	ISZ ERRCNT	/MORE RETRIES LEFT?
	JMP RETRY	/YES
/AFTER THREE TRIES, TAKE HANDLER ERROR RETURN
/WITH AC=4000
ERROR,	AC4000
	SKP
/NORMAL RETURN FROM HANDLER
DONE,	ISZ BARG	/SKIP ERROR RETURN
BRTN,	CIF CDF 00	/RETURN TO CALLING FIELD
			/BBL READ: NOP (FIELD 0)
	JMP I BARG	/RETURN TO CALLING PROGRAM
/DATA
BLOCK,	0
TRACK,	0		/BBL READ: TRACK 0
WC,	-41		/BBL READ: -BBL LENGTH
SECTOR,	1400		/BBL READ: SECTOR 14
CYL,	0
SURF,	0
ERRCNT,	0		/COUNT OF RETRIES
OLDTRK,	2000		/FORCE INITIAL SEEK
PAGES,	200		/BBL READ: ONE PAGE
FNC,	RLRD		/BBL READ: READ FUNCTION

/RELOCATED RELATIVE ADDRESSES
BARG,	OK-MAIN		/BBL READ: RETURN FROM READ
			/ADDRESS OF HANDLER ARGUMENTS
MA,	BBL-MAIN	/BBL READ: ADDR OF BBL
BBBL,	BBL-MAIN

B3,	3
B3777,	3777
B7600,	7600
BRLRD,	RLRD
HEADER,	BYTE RLRH
BDRIVE,	DRIVE^100	/DRIVE BITS FOR RLCB
CHECK,	-ID

/THIS CONSTANT MUST BE AT END OF PAGE
	ZBLOCK 577-.
B4070,	4070
$
