//D0I0.bcpl First init for D0--Load RAM and start special microcode
//	Initialization done here is always executed.  Storage allocated
//	is not saved in Midas.State.
//	Last edited: 1 March 1982

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


external [
// OS
	SetBlock

// MASM
	GetStorage

// MIDAS
	MidasSwat

// MINIT1
	GetZStorage

// LOADRAM
	LoadRam; //SetBLV

// DORADOMC
	RamImage

// BCPLRUNTIME
	InitBcplRuntime

// D0ASM
	GFrameX
	recvbyte; recvword; sendbyte; sendword
	d0recvbyte; d0recvword; d0sendbyte; d0sendword

// D0GO
	Stop; d0Stop

//Defined here
	InitHardware1; MachVersion; OldGFrame; HWStatus; DefRadix
	BPTable; DVx
]


static [
	OldGFrame; MachVersion; HWStatus; DefRadix = 8
	BPTable; DVx
	]

//This routine will do something if special Alto microcode is added for
//use with the D0.
let InitHardware1() be
[	MachVersion = ", D0Midas 3/1/82; 14d-word stack"
//Initialize special Alto microcode.  Note:  using Dorado Alto microcode
//for now, which includes the bcpl runtime microcode.
	RamImage!0 = #177777	//Zeroes enable tasks in Ram if silent boot
//Load microcode for Alto1's (EngNum = 0 or 1) and Alto2's (EngNum = 2 or 3).
//Don't load microcode for Dolphin's (EngNum=4) and Dorado's (EngNum=5);
//they already have BCPL runtime microcode.
	OldGFrame = rv #370
	let EngNum = (table[ #61014; #1401 ] )()
	EngNum = EngNum rshift 12
	test EngNum < 4	//Midas running on an Alto?
	ifso
	[ 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 opcode--IS THIS USELESS?
	  rv #370 = GFrameX
	]
	ifnot test EngNum eq 4	//Midas running on a Dolphin?
	  ifso
	  [ recvword,recvbyte = d0recvword,d0recvbyte
	    sendword,sendbyte = d0sendword,d0sendbyte
	    Stop = d0Stop
	  ]
	  ifnot MidasSwat(BadEngNum)

	HWStatus = GetZStorage(size HWStatus/16)
//For now, -1 indicates that a Boot is required
	HWStatus>>HWStatus.ConnectedMachine = -1
	DVx = GetStorage(16)
	BPTable = GetStorage(BPlen*4)
	SetBlock(BPTable,7777B,BPlen*4)
]