// BFS.decl -- Special copydisk version of BFS.d
// Copyright Xerox Corporation 1979
// Last modified November 5, 1980  4:23 PM by Boggs

manifest
[
ecUnRecovDiskError = 1101
ecBfsQueue = 1104
]

//----------------------------------------------------------------------------
structure DST:		// Disk Status
//----------------------------------------------------------------------------
[
sector bit 4
done bit 4
seekFail bit
seeking bit
notReady bit
dataLate bit
noTransfer bit
checksumError bit
finalStatus bit 2
]

manifest
[
// disk status bits
done = 7400B
seekFail = 200B
seeking = 100B
notReady = 40B
dataLate = 20B
noTransfer = 10B
checksumError = 4

// final status values
badSector = 3

DSTdoneBits = done
DSTerrorBits = seekFail + notReady + dataLate + checksumError + badSector
DSTgoodStatusMask = DSTerrorBits % DSTdoneBits
DSTgoodStatus = done
DSTfreeStatus = 400B
DSTfakeError = done + dataLate
]

// Header, Label, and Data formats on disk

//----------------------------------------------------------------------------
structure DA:		// Disk Address
//----------------------------------------------------------------------------
[
sector bit 4
cylinder bit 9
head bit 1
disk bit 1
restore bit 1
]

//----------------------------------------------------------------------------
structure DH:		// Disk Header
//----------------------------------------------------------------------------
[
blank word		// must be 0
diskAddress @DA
]
manifest lDH = size DH/16

//----------------------------------------------------------------------------
structure DL:		// Disk Label
//----------------------------------------------------------------------------
[
next word
previous word
blank word
numChars word
pageNumber word
fid word 3 =
   [
   version word
   sn1 word =
      [
      directory bit
      blank bit 15
      ]
   sn2 word
   ]
]
manifest
[
lFID = 3
lDL = size DL/16
]

// Note: the big disks on D0 and Dorado are partitioned into a number
// of simulated Diablo disks.  The partitions are numbered 1 through 7;
// partition 0 refers to the current "default" partition known about
// by the microcode.  A BFSDSK object for a particular partition may
// be constructed by passing the partition number embedded in the
// driveNumber argument of BFSInit or BFSNewDisk.  The partition is
// passed to the microcode embedded in the command block seal.

//----------------------------------------------------------------------------
structure DriveNumber:	// interpretation of BFSDSK.driveNumber cell
//----------------------------------------------------------------------------
[
blank bit 12
partition bit 3
drive bit 1
]

//----------------------------------------------------------------------------
structure DC:		// disk command
//----------------------------------------------------------------------------
[
seal bit 8 =		// must be 110B on an Alto
   [			// for simulated multiple disks on D0 and Dorado:
   shortSeal bit 5	// must be 11B
   partition bit 3	// 0: default; 1-7: specific partition number
   ]
action bit 8 =
   [
   headerAction bit 2
   labelAction bit 2
   dataAction bit 2
   seekOnly bit 1
   exchangeDisks bit 1	// controller inverts KCB.diskAddress if set
   ]
]

manifest
[
// disk commands as full-word constants
commandSeal = 44000B

readHLD = 44000B	// read  Header, read  Label, read Data
readLD = 44100B		// check Header, read  Label, read Data
readD = 44120B		// check Header, check Label, read Data
writeHLD = 44250B	// write Header, write Label, write Data
writeLD = 44150B	// check Header, write Label, write Data
writeD = 44130B		// check Header, check Label, write Data
seekOnly = 44002B	// no transfer
]

//----------------------------------------------------------------------------
structure KCB:		// Disk Command Block
//----------------------------------------------------------------------------
[
link word		// -> next KCB or 0 if end of chain
status @DST		// set when command is completed
command @DC
headerAddress word	// memory addresses for header record
labelAddress word	// memory addresses for header record
dataAddress word	// memory addresses for header record
normalWakeups word
errorWakeups word
header @DH =
   [
   blank word
   diskAddress @DA	// if DA argument ne fillInDA
   ]
]
manifest lKCB = size KCB/16

//----------------------------------------------------------------------------
structure CBZ:
//----------------------------------------------------------------------------
[
length word
cleanup word
error word
retry word
errorCount word
errorDA word
head word
tail word
CBs word 0
]
manifest lCBZ = size CBZ/16	// fixed part of CBZ

// each CBZ contains a CB for each possible transfer enqueued
// a free CB must have status = DSTfreeStatus (initialization does that)
//----------------------------------------------------------------------------
structure CB:
//----------------------------------------------------------------------------
[
// The KCB must come first
@KCB			// free CB must have status = DSTgoodStatus
// remaining words are not zeroed by BfsGetCb
cbz word		// -> CBZ which owns this cb
nextCB word		// -> next CB on CBZ queue
]
manifest
[
lCB = size CB/16
lVarCB = offset CB.cbz/16
]

// CopyDisk stuff
manifest
[
numCBs = 12		// 1 tracks's worth of CBs
lenCBZ = lCBZ + numCBs*lCB

lenBFSData = 256
lenBFSLabel = 8
lenBFSHeader = 2

// disk type
AltoDiablo = 10

// error types
EtSoft = 2B8
EtHard = 1B8
EtRead = 1
EtWrite = 2
]

//----------------------------------------------------------------------------
structure BFSSS:
//----------------------------------------------------------------------------
[
@SS
cbz word
currentDA @DA
driveNumber word
retryCount word
partition word
]
manifest lenBFSSS = size BFSSS/16

//----------------------------------------------------------------------------
structure BFSBuffer:
//----------------------------------------------------------------------------
[
@Buffer
header @DH
label @DL
data word lenBFSData
]
manifest
[
lenBFSBuffer = size BFSBuffer/16
lenFreePage = (offset BFSBuffer.data - offset BFSBuffer.length)/16
]

//----------------------------------------------------------------------------
structure BFSErrors:
//----------------------------------------------------------------------------
[
hardError word
softError word
]
manifest lenBFSErrors = size BFSErrors/16

//----------------------------------------------------------------------------
structure BFSXferParams:
//----------------------------------------------------------------------------
[
firstDA @DA
lastDA @DA
]
manifest lenBFSXferParams = size BFSXferParams/16

//----------------------------------------------------------------------------
structure BFSDiskParams:
//----------------------------------------------------------------------------
[
nCylinders word
nHeads word
nSectors word
nDisks word
]
manifest lenBFSDiskParams = size BFSDiskParams/16