/* BCPL I/O Library
 * Stream control block definitions
 */

GLOBAL $(
   MakeNewStream : 135;
   EndStream: 136 $);

MANIFEST $(
s.name.max.size  = 32

// Stream vector offsets
s.magic 	 = 0			// Must be s.is.a.stream
s.stream.chain	 = s.magic	    + 1 // All streams are linked on this
s.flags 	 = s.stream.chain   + 1 // A flag word
s.name		 = s.flags	    + 1 // First byte of stream name
s.name.end	 = s.name + ( s.name.max.size / bytesperword )
s.channel	 = s.name.end		// The OS file handle
s.error.handler  = s.channel	    + 1 // Caller if any serious errors
s.selecter	 = s.error.handler  + 1 // Called before any IO on this stream
s.reader	 = s.selecter	    + 1 // The rdch() function
s.writer	 = s.reader	    + 1 // The wrch() routine
s.unreader	 = s.writer	    + 1 // The unrdch() routine
s.last.char	 = s.unreader	    + 1 // Last character read by the reader()
s.real.reader	 = s.last.char	    + 1 // The real reader if unreadch pending
s.error.count	 = s.real.reader    + 1 // Number of OS errors since created
s.last.error	 = s.error.count    + 1 // The last OS error from this stream
s.endreader	 = s.last.error     + 1 // The endread() routine
s.endwriter	 = s.endreader	    + 1 // The endwrite() routine
s.buffer.size	 = s.endwriter	    + 1 // The size of the IO buffer
s.buffer.address = s.buffer.size    + 1 // The machine address of the buffer
s.buffer.pointer = s.buffer.address + 1 // The extraction pointer
s.buffer.count	 = s.buffer.pointer + 1 // Number of elements in the buffer

s.stream.size	 = s.buffer.count	// The size of the stream block

s.is.a.stream	 = #x52A5A552 // A magic number indicating the stream is valid
s.is.a.store.file= (('s'<<8|'t')<<8|'o')<<8|'r'

s.stream.type.bits    = #b00000000000000000000000011111111
s.is.wrch.bit	      = #b00000000000000000000000000000001
s.is.vdu.bits	      = #b00000000000000000000000000000011
s.is.printer.bits     = #b00000000000000000000000000000101
s.is.serial.bits      = #b00000000000000000000000000001001
s.is.store.bits       = #b00000000000000000000000000010000
s.is.null.bits	      = #b00000000000000000000000001000000
s.is.file.bits	      = #b00000000000000000000000010000000
s.has.channel.bit     = #b00000100000000000000000000000000
s.is.input.bit	      = #b00010000000000000000000000000000
s.is.output.bit       = #b00100000000000000000000000000000
s.ended.bit	      = #b10000000000000000000000000000000


// Store file vector offsets
store.magic	   = 0			  // magic to test validity
store.nextfile	   = store.magic + 1	  // Pointer to next store file
store.name	   = store.nextfile + 1   // name of the file (first byte)
store.name.end	   = store.name + (s.name.max.size/bytesperword)
store.start	   = store.name.end + 1   // where file is in store (bcpl ptr)
store.size	   = store.start + 1	  // size of data (bytes)
store.maxsize	   = store.size + 1	  // space allocated for file (bytes)
store.block.size   = store.maxsize	  // The size of the file block


e.no.work.space 	     = 700
e.bad.input.stream	     = 701
e.bad.output.stream	     = 702
e.has.been.ended	     = 703
e.must.not.read 	     = 704
e.must.not.write	     = 705
e.no.buffer.room	     = 706
e.nasty.error		     = 707
e.cant.load.file	     = 708
e.store.file.full	     = 709

s.op.close		     = #x00
s.op.input		     = #x40
s.op.output		     = #x80
s.op.update		     = #xC0

$)
