// MINIT2.BCPL	Display initialization

//DInit0() does some display initialization which is needed by Init2().


get "mdecl.d"
get "streams.d"

external [
// OS
	Zero

// MIDAS
	GetStorage

// MDISP
	FontP; FontCharWidth; SavedDASTART
	NwdsPerScanLine; StandardLineHeight; BitBufferLen
	LinesInUse; LineCtrlBlockPtrsVector; DCBPoolSize; DCBPool
	BBblockSize; AvailBlockNLines; AvailBlockSize

// Machine dependent
	ScreenHeight		//Number of text lines on screen
	ScreenWidth		//Number of chars/line

//Defined here
	DInit0; MarkLineInUse; GetZStorage; GetHStorage
	NNonOvBitBuffers; FirstNonOvLine
]

static [ NNonOvBitBuffers; FirstNonOvLine ]

manifest [ ExtraBitBuffers = -2 ]	//Should be ge 2 - no. blank screen lines

let  DInit0() be
[//Max char width = exact if fixed pitch font
	FontCharWidth = (FontP!(-1)) & 377B
	NwdsPerScanLine = ((ScreenWidth*FontCharWidth-1) rshift 4)+1
	StandardLineHeight = (rv ( FontP - 2)) & 177776B
	LinesInUse = GetZStorage(ScreenHeight+1)
	let NLines = ScreenHeight
	BitBufferLen = StandardLineHeight * NwdsPerScanLine
	BBblockSize = (BitBufferLen+2) * (NLines + ExtraBitBuffers)
//The register menu lines become the OverlayZone.  Lines below that
//are put in service by Init3.
	let OvLines = ScreenHeight-10
	NNonOvBitBuffers = 10 + ExtraBitBuffers
	FirstNonOvLine = OvLines
	AvailBlockSize = OvLines*(BitBufferLen+2)
	AvailBlockNLines = OvLines
]


and GetHStorage(Size) = valof
[	let Vector = GetStorage(Size+1)
	Vector!0 = Size
	resultis Vector
]


and GetZStorage(Size) = valof
[	let Vector = GetStorage(Size)
	Zero(Vector,Size)
	resultis Vector
]


and MarkLineInUse(L) be LinesInUse!(L+1) = true