//D1i0.bcpl First init for D1--Load RAM and start special microcode
//	Initialization done here is always executed.  Storage allocated
//	is not saved in Midas.State.
//	19 May 1983

get "d1.d"
manifest [ get "d1dmux.d" ]
manifest [ get "d1regmem.d" ]


external [
// OS
	SetBlock

// MINIT1
	GetZStorage

// MIDAS
	MidasSwat

// MASM
	@MBlock; GetStorage

// LOADRAM
	LoadRam; //SetBLV

// BCPLRUNTIME
	InitBcplRuntime

// DORADOMC
	RamImage

// D1ASM
	GFrameX

//Defined here
	InitHardware1; MachVersion; OldGFrame; HWStatus; DefRadix
	@DMuxTab; @OldDMuxTab; DWrong; DChecked; DMuxSelect; @DHistTab
	@SaveMIR; BreakMIR; SaveBR36
]


static [
	MachVersion; OldGFrame; HWStatus; DefRadix = 8
	@DMuxTab; @OldDMuxTab; DWrong; DChecked; DMuxSelect; @DHistTab
	@SaveMIR; BreakMIR; SaveBR36
]

let InitHardware1() be
[	MachVersion = ", D1Midas 5/19/83"
//Initialize special Alto microcode.
//Note:  other implementations of Midas can use the Alto microcode
//for Dorado, if they do not have their own.  Bcpl runtime microcode
//may be assembled with other special microcode and improves performance
//about 6%.
	RamImage!0 = #177777	//Zeroes enable tasks in Ram if silent boot
	let res = LoadRam(RamImage,false)	//load, don't boot
	if res < 0 then MidasSwat(BadLoadRam)
	if res > 0 then MidasSwat(BadConstants)
	//SetBLV(#177776)	//Setup for silent boot at finish time
//Initialize for new microinstructions
	InitBcplRuntime()
	(table [ InitMC; #1401 ] )()
//Replace GetFrame procedure by special microinstruction
	OldGFrame = rv #370; rv #370 = GFrameX

	DMuxTab = GetStorage(DMUXlen)
	SaveMIR = DMuxTab+dSaveMIR
	DMuxSelect = DMuxTab
	BreakMIR = GetStorage(4)
	DWrong = GetZStorage(DMUXlen)
	OldDMuxTab = GetStorage(DMUXlen)
	DChecked = GetStorage(DMUXlen)
	DHistTab = GetZStorage(DHISTlen*3)
	SaveBR36 = GetStorage(2)
	HWStatus = GetZStorage(size HWStatus/16)
	HWStatus>>HWStatus.ConnectedMachine = -1
]