// D0res.bcpl -- resident procedures
//	Last edited: 18 December 1979

get "mcommon.d"
get "d0.d"
manifest [ get "d0regmem.d" ]

external [
// MINIT0
	MStatus

// MMPRGN
	UpdateMPDValues

// MMENU
	WssMark

// D0I0
	OldGFrame; HWStatus

// D0ACTIONS
	AbsAct; VirtAct

// D0VM
	@VirtualP

// Defined here
	FinishHardware; DetachHardware; CmdFinish
	FormHWMenu; HWEveryTime; HWShowAddr; HWAlwaysUpdate 
]

static [ MicState = 0 ]

//Form conditional parts of machine-dependent command menu
let FormHWMenu() be
[	test VirtualP
	ifso WssMark(VirtAct!0,AbsAct)
	ifnot WssMark(AbsAct!0,VirtAct)
]


and HWEveryTime(nil) be
[	test MicState < 4
	ifso
	[ MicState = MicState+1
	]
//Every so often update the Always-updated registers
//(presently the error counters COMM-ER0, COMM-ER1, COMM-ER2)
	ifnot
	[ MicState = 0; UpdateMPDValues(true)
	]
]


//Called from ShowAddr in MMPRGN
and HWShowAddr(MemX,AVec) be return


and HWAlwaysUpdate(MorRCON,X,AVec) =
	MorRCON<<MRType.AlwaysUpdate ne 0 ? 1,
		(X eq MADDRx) & (AVec!1 ge 11B) & 1


//This is called prior to exit from Midas
and FinishHardware() be
[	DetachHardware(); rv #370 = OldGFrame
]


//This is called at onset of the "Boot" action
and DetachHardware() be
[	unless MStatus>>MStatus.MachRunning do
	[
//***Should setup as though about to continue here***
	]
//Indicate Boot required to D0I2
	HWStatus>>HWStatus.ConnectedMachine = -1
]


and CmdFinish(nil,nil,nil) be finish