MANIFEST[
	PAGESIZE = 256; ENDOFSTREAM = #100000
	MAXNUMCHS = PAGESIZE * 2 
	IOERRBIT = #40000
	BITTABLESIZE = ((203*2)*12)/16 + 1
	PAGE1DISKADDR = 521B
	PAGE1DISPLAYPTR=#420
	] 
  
// SUNDRY CONSTANTS 
  
MANIFEST[ 
	READDISK = #44000+0120B
	WRITEDISK = #44000+170B 
	FORCEWRITE = #44000+250B 
	FORCEREAD = #44000+0B
  
// OBJECT TYPES 
	DISKSTREAM = 1 
	STRINGSTREAM = 2 
	TTYSTREAM = 3; KEYBOARDSTREAM = TTYSTREAM
	FIDVEC = 4 
	DISPLAYSTREAM = 5
	LASTSTREAM = DISPLAYSTREAM
  
// OPEN ACTIONS 
	DISKRO = 0 
	DISKWO = 1 
	DISKRW = 2 
	DISKROCH = DISKRW + 1
	DISKWOCH = DISKROCH + 1
	DISKRWCH = DISKWOCH + 1
	STRINGOPEN = DISKRWCH + 1
	BIGSTRINGOPEN = STRINGOPEN + 1 
	SPECIALOPEN  = BIGSTRINGOPEN + 1 
	KEYSOPEN = SPECIALOPEN + 1
	DISPLAYOPEN = KEYSOPEN + 1
	]

// BCPL LAYOUT VECTOR CONSTANTS
MANIFEST [
	STATICLD=26
	STATICEND=27
	BEGINPC=28
	ENDPC=29
	ENDCODE=30
	]

MANIFEST CODEPTR=#335


// PARAMETERS OF BCPL FRAME
MANIFEST STACKOFFSET=4


STRUCTURE DCOMMAND[ 
	CHECK BIT 8	//CHECK BYTE TO GUARANTEE DISK COMMAND 
	HDRCTRL BIT 2	//HEADER CONTROL COMMAND 
	LBLCTRL BIT 2	//LABEL CONTROL COMMAND
	DATACTRL BIT 2	//DATA CONTROL COMMAND
	POSONLY BIT 1	//POSITION TO ADDR ONLY 
	DISKCOMPLIMENT BIT 1	// COMPLIMENT THE DISK BIT IN THE DISK ADDR
	]
  
STRUCTURE DISKADDR[ 
	SECTOR BIT 4	//SECTOR NUMBER 
	TRACK BIT 9	//TRACK NUMBER 
	HEAD BIT 1	//HEAD NUMBER 
	DISK BIT 1	//DISK NUMBER 
	RESTORE BIT 1
	]
  
STRUCTURE DISKSTAT[ 
	SECTOR BIT 4	//LAST SECTOR PROCESSED 
	FIN BIT 4	//FIN BITS TO TELL ITS DONE
	SEAKFAIL BIT 1	//SEAK FAILED 
	SEAKINP BIT 1	//SEAK IN PROGRESS 
	NRDY BIT 1	//DISK UNIT NOT READY 
	LATE BIT 1	//HARDWARE LATE DONT TRUST DATDA
	NOXFER BIT 1	//HARDWARE WAS NOT XFERING DATA LAST SECTOR 
	CHKSUM BIT 1	//CHECKSUM ERROR , CMMD ALLOWED TO PROCEED
	STATUS BIT 2	// FINAL STATUS 
	]

STRUCTURE STATBITS[ 
	EOS BIT 1
	EOD BIT 1
	IOERR BIT 1
	BLANK BIT 13
	]
  
STRUCTURE SN1BITS[
	DIR BIT
	RANDOM BIT 
	BLANK BIT 14
	]
  
STRUCTURE STREAMBITS[ 
	DIRTY BIT 1
	PUTBACKBIT BIT 1 
	BLANK BIT 14
	]

//	DEFINE THE BASIC STREAM PREAMBLE FOR BENEFIT OF OTHERS

STRUCTURE STREAMPREAMBLE[
	SPTR	WORD	//BUFFER PTR AND OTHER STREAM DEPENDENT THINGS
//	CODE PTRS
	OPENIT	WORD	// OPEN THE STREAM
	CLOSEIT	WORD	// CLOSE THE STREAM
	GETIT	WORD	// GET AN ITEM FROM THE STREAM
	PUTIT	WORD	// PUT AN ITEM INTO THE STREAM
	RESETIT	WORD	// RESET THE STREAM
	PUTITBACK WORD	// PUT AN ITME BACK ONTO THE STREAM
	ERRORIT	WORD	// ERROR FUNCTION
	ENDOFIT	WORD	// TRUE IF END-OF-STREAM
	STATEOFIT WORD	// RETURN STATE INFO

// STREAM STATE INFO
	STATE WORD = @STATBITS	//STREAM DEPENDENT
	STREAMSTATE WORD = @STREAMBITS	// ETC.
	STYPE	WORD	// STREAM TYPE
	PBITEM	WORD	// CURRENT PUT-BACK ITEM
	SFID WORD = STRINGOUT WORD	// STREAM DEPENDENT
	]

// DEFINE A DISK STREAM!!!!
  
STRUCTURE [ST 
	@STREAMPREAMBLE
	FN WORD 1
	[ DCBBLK WORD 10 ] =
		[ 
		DCBNPTR WORD 1
		DCBSTATUS@DISKSTAT
		DCBCMMD@DCOMMAND
		DCBHPTR WORD
		DCBLPTR WORD 1
		DCBDPTR WORD 1
		DCBOKINTS WORD
		DCBERRINTS WORD
		HEADERBLOCK WORD 2 =
			[
			DCBHDR1 WORD
			DCBHDR2 WORD = CURRENT@DISKADDR
			]
		] 
	[ LABELBLOCK WORD 8 ] =
		[
		NEXTP@DISKADDR
		BACKP@DISKADDR
		UNUSED WORD
		NUMCHARS WORD
		PN WORD
		VN WORD = [ VNBITS BIT 4; VER BIT 12]
		SN1@SN1BITS
		SN2 WORD
		]
	[ BUF WORD 1]↑1,PAGESIZE 
	LASTWORD WORD 1
	]ST
  
// DEFINE A  DISK-LABEL BLOCK 
  
STRUCTURE DL[ 
	NXTCMMD WORD	//PTR TO NEXT SUCH BLOCK
	STATUS@DISKSTAT	//DISK CMMD STATUS WHEN COMPLETED
	CMMD@DCOMMAND	// DISK COMMAND TO BE  EXECUTED
	HDRPTR WORD	//PTR TO HEADER BLOCK
	LBLPTR WORD	//PTR TO LABEL BLOCK  PORTION
	CMADDR WORD	//PTR TO MEMORY BUFFER 
	OKINTS WORD	//OR'ED WITH NWW AFTER OK DISK ACTION
	ERRINTS WORD	// OR'ED WITH NWW AFTER ERROR ON DISK ACTION

	HEADERBLOCK WORD 2 =
	[
	HDR1 WORD	//FIRST WORD OF HEADER 
	CURRENT @DISKADDR	// 2ND WD OF HEADER.DISK ADDRESS OF PAGE 
	]
	LABELBLOCK WORD 8 =
		[
		NEXTP@DISKADDR	// PTR TO NEXT PAGE ON DISK
		BACKP@DISKADDR		// PTR TO LAST PAGE ON DISK
		UNUSED WORD
		NUMCHARS WORD
		PN WORD		// PAGE NUMBER
		VN WORD = [ VNBITS BIT 4; VER BIT 12] //VERSION NUMBER
		SN1@SN1BITS		// SERIAL NUMBER WD 1
		SN2 WORD		// SERIAL NUMBER WD 2
		]
	]
  
// DEFINE A DISK BLOCK STRUCTURE--A "PAGE 1" ENTITY
STRUCTURE DB[ 
	CMMDPTR WORD =	//PTR TO CURRENT /"DL" BEING EXECUTED 
	     ACTIVE WORD	//SYNONYM FOR CMMD PTR
	STATUS@DISKSTAT	// CURRENT DISK STATUS 
	DISKADDR@DISKADDR	// ADDR OF CURRENT OR LAST(IF IDLE)CMMD
	]
  
MANIFEST[ STREAMSIZE = (OFFSET LASTWORD)/16 - 1 
	DCBBLKINDEX = (OFFSET DCBBLK)/16 
	HDRBLKINDEX = (OFFSET HEADERBLOCK)/16
	LBLKINDEX = (OFFSET LABELBLOCK)/16
	BUFINDEX = (OFFSET BUF)/16 - 1	//BACKUP ONE SO INDEXING WORKS OK 
	DLBLINDEX = (OFFSET DL.LABELBLOCK)/16 
	DLSIZE = (OFFSET DL.SN2)/16 + 1	//+1 FOR BLANK
  
	PREAMBLESIZE = OFFSET STREAMPREAMBLE.SFID/16
// Note that the next two sizes contain constants derived
// from structure declarations in EIS.OS
  	DISPLAYSTREAMSIZE = PREAMBLESIZE+17
  	TTYSTREAMSIZE = PREAMBLESIZE+25+6

	STRINGSTREAMSIZE = PREAMBLESIZE
	OBJPTRSIZE = 16+1	//JUST DEFINE A CONSTANT 
	]
  
// DEFINE A SOURCE-VECTOR STRUCTURE...
STRUCTURE SV[ 
	[ BITS BIT 1]↑0,15	//"RESERVED" BITS 
	[ PTR WORD 1]↑0,15	//PTRS TO OBJECTS.
	]
  
// DEFINE AN  FID.  (FILE IDENTIFIER) 
STRUCTURE FID[
	SN1@SN1BITS
	SN2 WORD 1 
	VN WORD 1
	FN WORD 1
	LA@DISKADDR
	DSN1@SN1BITS 
	DSN2 WORD 1
	DVN WORD 1 
	DPN WORD 1 
	DLA@DISKADDR 
	]
MANIFEST FIDSIZE = (OFFSET FID.DLA)/16