// PressInternals.df -- Definitions universal to press printing code.

//  last modified by PolleZ and Swinehart August 27, 1984
//  Enlarge space for FPREQ;   version 5.1

//  last modified by Williams February 14, 1983  10:35 AM 
//  -- added BandWidth to PageG
// last modified by Butterfield, October 16, 1980  10:56 AM
// BEMaxH, increase by 14 from 8 to 22 to include more rectangles - 10/15
// - F, replace DATable with fmap - 4/18/80

// File stuff

manifest
 [				//Must be ne 0 for WindowChangeType
   FILERW=1			//Read-write
   FILERO=2			//Read only
   FILEWO=3			//Write only

   FILEBits=0			//Bit-map output file
   FILEScratch=1		//Scratch file
   FILELeftOver1=2		//Left-over files
   FILELeftOver2=3		//	"
   FILEBands=4			//File for storing band information
   FILEMeter=5			//File for metering information
   FILEFontDictionary=6		//File for font dictionary
   FILEPressProgram=7		//The program file for overlays
   FILEExternal=8			//a file referenced from the Press file (dots,fonts)
   FILEPress=1000		//The Press file !!!!!!!!
 ]

structure F:			//"FILE" structure
 [
   Type	word			//Type of file (read only, etc.)
   Name	word			//"Name" (integer code)
   Device	word		//Device code
   Pagesize word		// -- page size of device
   LogPagesize word		// -- and its log base 2
   Pagecnt	word		//Length in pages
   fp 	word 3 =
	[
	serialNumber word 2
	version word		//File ID for BFS
	]
   DAFirst	word		//If non-zero, page n is at logical
				// adr DAFirst+n.
   fmap word 0			// ISF fmap (if file is random allocated)
 ]

structure Color :
 [ Hue	byte	//"WaveLength"
   Saturation	byte	//"Purity"
   Intensity	byte	//"Luminance"
   spare	byte
 ]
manifest lColor=size Color/16

manifest
 [
   DISK31=0			//File resides on Model 31
   DISK31B=1			//Second model 31 disk
   DISKT80=2			//File resides on T80 disk
 ]

// Window Stuff

manifest
 [				//Must be ne 0 for WindowChangeType
   WINDOWNoStrategy=1		//No special windowing strategy
   WINDOWPageAhead=2		//Read on ahead.
 ]


structure block :		//Describes a buffer in core.
 [
   CoreAdr	word		//Core address of buffer.
   PN		word		//File page number in this buffer.
   Age		word		//For LRU strategy
   Status	word		//For clean,dirty
 ]

structure W :			//Window descriptor. 
 [
   spare1	word		//Leave a few here so that people who
   spare2	word		//use windows for other purposes can
   spare3	word		//define structures that have special
   spare4	word		//purpose entries here

   Base		word		//For current buffer
   Offset	word		//  "
   WhichByte	word		//=0 for left, 1 for right.
   ByteCount	word		//Bumped for each "byte" read
   File		word		//File for this window.
   Strategy	word		//Paging strategy
   BufSize	word		//Size of the buffer
   LogBufSize	word		//Log (base 2) of buffer size
   CurPN	word		//Current page number
   CurBuf	word		//Current "buffer" structure
   NumBlocks	word		//Number of available block strs.
   @block↑1,40
 ]


// Page stuff

structure PageG :		//Page Goodie block
 [
   FirstBand	word		//Lowest used band
   LastBand	word		//Highest used band
   BitMargin	word		//Margin and
   BitWc	word		//Word count of scan lines
   BandPos	word 2	//File position of band stuff
   BitPage	word		//File position of bits (units = 1024 words)
   CopyCrucial	bit	//True if different version needed for different copies.
   SimplePage	bit
   ColorPass		bit 2	//for color printers: 0=magenta,1=yellow,2=cyan,3=black
   ColorUsed		bit	//True if color used (only scan convert once for black)
   blank	bit 11
   PageNumber word	//From original Press file.

   //*** added for Spruce-like operation
   nRecords	word
   fontLoad	word
   BandWidth     word		//This is used for high-resolution slicing.
 ]

structure FontG:
 [
   nRecords	word
   bandPos	word
   fontLength	word
 ]

// Communication out of Fonts Pass.  Following is a font descriptor:

structure FPOS :		//File position descriptor
 [
   File	byte			//File identifier (see below)
   Len	byte 3
 ]

manifest
 [
   FPOSThis=0			//This file.
   FPOSScratch=1		//Scratch file.
   FPOSGod=2			//God file.
   FPOSDNE=#377			//Does not exist. (-1)
 ]

structure FDES :		//Font descriptor
 [
   set		byte
   font		byte
   bc		byte
   ec		byte
   WTPos: 	[ @FPOS ] = [ spare1 word; AuxSet byte; AuxFont byte ]
   ICCPos:	[ @FPOS ] = [ spare word; ICCBase word ]
 ]

// Following are abstracted definitions from IX -- names are changed
// so that there is no confusion (dammit) **************

structure CharWidthp :		//Modified version of IX.DFS defn.
 [
   WS	word 2			//Width in "scan" direction
   WB	word 2			//Width in "bit" direction
   OS	word 			//Offset in scan direction
   OB	word 			//Offset in bit direction
   DS	word			//Dimension in scan direction
   DB	word 			//Dimension in bit direction
 ]

manifest
 [
   DBNonExCode=-1		//DB contains this if nonex char
   DBSplineCode=-2		// or this if recorded as splines
 ]

// Stuff for scan conversion pass.

structure RB :			//"Read Block" for a leftover table
 [
   Sync	word			//Current sync count
   @Color
   =Color	word lColor			//Color after sync encountered
   Reading	word		//True if reading from this leftover
   Base	word			// entries in structure W
   Offset	word
 ]

// Magic constant for dots -- the "constant" for expressing magnificatio ratios

manifest DotsDeltaConst=#037777	//Must be small enough so 2*it is positive number

// Output device definitions:
manifest [
	printerDover=0
	printerSequoia=1
	printerPimlicoAlt=2
	printerPimlico=3
	printerPenguin=4
	printerPuffin=5
	printerDurango=6	//Durango must be last ORbit printer
	printerSlot=7
	printerVersatec=8
	printerHg=9
	]

// MicroCode Trap values

manifest [
	NoTrap=#55001		//STA 3,1,2

	ScanLoadVarsTrap=#70000
	ScanPutCharTrap=#70001
	ScanPutDotsTrap=#70002
	DoubleAddTrap=#70003
	DoubleSubTrap=#70004
	DoubleShrTrap=#70005
	PreRotorTrap=#70023

	PrintVersatecTrap=#70000
	PrintHgTrap=#70001
	]

// Band Bucket entries

structure BEH :			//Band Entry Header
 [
   Cbit		bit		//True if char (BEChar)
   Type		bit 15		// otherwise, type code.
 ]

structure BEChar :		//Band Entry for Character
 [
   Cbit		bit
   ICC		bit 15		//Internal Character Code
   Sr		bit 4		// delta scan line before start
   Bit		bit 12		//Address on scan line
 ]

structure BERectangle :		//Rectangle ("rule")
 [
   Type	word	//must be 1
   Sr		bit 4		// delta scan line before start
   Bit		bit 12		//Address on scan line
   nHeight	word		//-height in bits
   widthM1	word		//width-1 in bits
 ]

structure BELOChar :		//"Left over" version of character
 [
//*** down to *** definitions known to microcode
   Cbit		bit
   spare	bit 3
   orbitW	bit 12	//-height of character in bits
   [ orbitX	bit 4	//scan line in band to start on
     orbitY	bit 12	//y pos on scan line
   ]
  =Bit		word	//Addr on scan line (to set orbitX=0 (standard))
   bitOffset	bit 4	//offset of char start in word of font
   orbitS	bit 12	//ns from font (orbit mode, so ns-1), but ns decreases
   CoreAdr	word		//Pointer into char rep.
//*** end ***
 ]
manifest CharBit=#100000	//For "anding" and testing Cbit

structure BESync :		//Band Entry for Sync counter
 [
   H		word
   Sync		word		//Sync counter
   @Color		//Color information
   =Color	word lColor
 ]

structure BECopy :		//Band Entry for Copy Number
 [
   H		word
   Copy		word		//Copy number
 ]

structure BEDots :		//Band Entry for Dots stuff
 [
   H		word		//Type
//*** down to *** definitions known to microcode
   Bstart	word		//Starting Bit position in output buffer
   Bincr	word		//Bit direction (+1,-1)
   Bdim		word		//Dimension in B of dots region

   Opaque	bit		//True if white bits are opaque
   Smagnify	bit		//True if magnified in S direction
   Bmagnify	bit		//True if magnified in B direction
   Code		bit 13		//Code entry from <<Set-coding>>
   Bdelta	word		// Magnification ratio (denominator = DotsDeltaConst)

   BitBuf	word		//Pointer to first word of input bits
   BitPhase	word		//Bit position in word where first sample begins

   ErrorBuffer	word	//Pointer to error propagation vector
   ScreenModulus word	//n x n bit screen => put n here
   ScreenAddress word	//Core address of screen (0=> dont use)
   IMin		word		//Intensity ranges for 1/2 toning
   IMax		word
//*** end ***
   BitFilePos	word 2		//Bit position in file of start of bits
   BitFileInc	word 2		//Delta to add to above each scanline
   BitFileSLWC	word 		//Number of words of bits file that need to
				// be read for each scan-line (<BitFileInc if windowed)

   Sstart	word		//Beginning scan-line
   Sdim		word		//Dimension in S of dots region
   Sdelta	word		// Magnification ratio

   File		word		//File with bits (FILEPress or FILEScratch)
				//Following are kept only at scan-conversion time
   WindowNumber	word		//Index in window table for this dots file.
   Scount	word		//Phase of S magnification operation

   TempSLBuf	word		//For holding one scan-line during blow-up
   ScreenStart	word		//holds screen values for halftone
   ScreenAmplitude	word
   ScreenAngle	word
   [ OMinB 	byte
     OMinH 	byte
     OMinS 	byte
     OMaxB	byte
     OMaxH	byte
     OMaxS	byte
   ]
   =OStats	word 3
 ]

structure SH :
 [				//"header" for graphics things
   H		word		//Type
   Sbegin	word		//Leftmost Scan line
   Send		word		//Rightmost Scan line
 ]

structure BELine :		//Line (see SCV.DFS)
 [
   @SH
   Bit		word 2		//Current bit position
   dBit		word 2		// delta
 ]

structure BESpline :		//Spline (see SCV.DFS)
 [
   @SH
   Stuff	word 8*2	//Recursive quantities
 ]

structure BEEndObject :
 [
   H		word		//Type
 ]

structure BEEnd :		//End of band
 [
   H		word
   filler	word
 ]

manifest
 [
//Op codes for BE's that are not chars (BEH.Type):
   BEEndH=0			//Planning ahead for OrBit
   BERectangleH=1		//Planning ahead for OrBit
   BEDotsH=2
   BESyncH=3
   BECopyH=4
   BELineH=5
   BESplineH=6
   BEEndObjectH=7

   BEExtendedRectangleH = 8;	// rectangle with bit + 2↑13
   // 9 through 22 are more extended rectangles (with bit + (H - 7) * 2↑13)
   BELastRectangleH = 22;	// rectangle with bit +  15 * 2↑13
   // (before adding consider adding one to make the rectangles a block of 16)

   BEMaxH=22			//Max value of H entries

   BEMaxSize=60			//Maximum size of a BE entry (plus a little!).
 ]
// Ether Reporting definitions

structure REPFont[
	fam		byte		//Family code from dictionary
	face		byte		//Face code requested
	siz		word		//Size of font
	used		byte		//Which family was actually used
	splines		bit		//Scan-converted from splines
	spare		bit 7
	]

manifest REPFontLen=(size REPFont/16)
manifest nReportFonts=10

structure REP[
	Version		word		//Version of the program
	Directive	word		//What he asked to have done
	Success		bit		//Completed successfully
	Jams		bit 3		//Number of paper jams
	PaperOut	bit		//Did hopper exhaust?
	spare		bit 11
	lastError	word		//Last value encountered by PressError
	nCopies		word		//Number of copies printed
	nPages		word		//Number of pages processed
	totalTime	word		//Elapsed time of session
	nChars		word 2		//Total number of characters
	nObjects	word		//Total number of objects (incl. rectangles)
	nDots		word		//Number of bit-maps
	nHalfTones	word		//Number of half-tones
	FontTime	word		//Time spend in fonts pass
	PreTime		word		//Time spent in pre-scan
	RotTime		word		//Time spent in rotation
	ConvertTime	word		//Time spent in scan-converting
	nCharFaults	 word	//Number of font storage faults
	BandSize	word 2		//Number of words of band information
	BandFileSorts	 word	//Number of times in-core sort failed
	DotsOut		word 2		//Number of output dots generated by PutDots
	User		word 16		//User name from document directory
	File		word 20		//File name from document directory
	FontsUsed	word		//#fonts he used
	FontsRecorded	word	//# fonts recorded below
	fonts		word nReportFonts*REPFontLen
	]

// Metering definitions

manifest
 [
   METERRead=0			//Page read (FLStat)
   METERWrite=1			//Page write (FLStat)

   METERFontPass=10		//Font pass entry (FPStat)
   METERFontCharConvert=11	//Converted a "font part character"
   METERFontConvert=12		//Converted a font (FPCStat)

   METERShowPage=13		//PreScan pass for page (PSStat)
    BandDist=30			// ...size of distribution table...
    BandDistUnit=4		// (one character)
    nFMCycleDist=60		// ...size of FM cycle distribution table...
    FMCycleUnit=20
   METERBandFlush=14		//Called when bands flushed

   METERConvertPage=15		//ScanConvert pass for a page (SCStat)

   METERRep=16			//REP structure for print task
   METERFault=17		//Character fault
   METEREnd=127			//Last of all....
 ]

structure METERH:
 [
   Type	byte			//Op code
   Count	byte		//Number of words (inc this one)
 ]

structure METERTimes:
 [
   TimeIn	word		//Times for a pass
   TimeOut	word
 ]

structure FLStat:		//For recording a page transaction.
 [
   File byte			//File number
   Cnt byte			//Page count
   Page word			//Beginning page number
 ]

structure FPStat:
 [
   @METERTimes
   ICCtotal	word		//Total number of different chars.
 ]

structure FPCStat:
 [
   @METERTimes
   fpreq word 29		//FPREQ structure!
 ]

structure PSStat:
 [
   @METERTimes
   PG: @PageG			//PageG entry for this page.
   Entities	word		//Number of entities
   CharCount	word		//Number of characters
   ObjCount	word		//Number of objects
   DotCount	word		//Number of "dots" regions
   RectCount	word		//Number of rectangles
   FontChanges	word		//Number of font changes
   ColorChanges	word		//Number of color changes
   ShowChars	word		//Number of separate "show chars" coms
   BandSizes	word BandDist	//Distribution of band sizes
 ]

structure SCStat:
 [
   @METERTimes
   LOSizes	word BandDist	//Distribution of leftover sizes
   TotSizes	word BandDist	//Distribution of LOin+EnterIn sizes
   FMCycleDist	word nFMCycleDist //Distribution of Font memory cycles
 ]

structure FAULTStat:
 [
   ICC	word			//Internal character code of needed char
 ]