// D1SimT.bcpl--final initialization stuff for SimTest and SimGo.
//	Last edited: 25 July 1979

manifest [ get "d1regmem.d" ]

external [
// MASM
	GetField

// MDATA
	@ShouldBe

// MGO
	HaltWaitMenu

// MPATTERN
	NextData

// D1I0
	@SaveMIR

// D1ASM
	@DoStrobe; @D1In; LoadDAddr; IMtoMIR; LoadMIR; ReadDMux

// D1GO
	OneStep

// Defined here
	LoadSimGo; LoadandDoInst
]


//LoadandDoInst is called both to complete init and every time through the
//loop during SimTest.
let LoadandDoInst() = valof
[	[ NextData()
	  switchon GetField(22B,10B,ShouldBe) into	//ff
	  [
case 36B:		//OUTPUT← (avoid activating io devices)
case 101B:		//TEST← (avoid Testing and Mar←Pcf)
case 140B to 141B:	//USEDMD, MIDASSTROBE←
	  loop
default: break
	  ]
	] repeat
//Have to preserve Block bit of data actually read from IM because
//dBlock is used in calculation of Switch prior to loading into MIR.
	LoadDAddr(60B)	//CABlock
	ShouldBe!1 = (ShouldBe!1 & 137777B)+((rv D1In & 4000B) lshift 3)
	IMtoMIR(SaveMIR,ShouldBe); LoadMIR(SaveMIR); ReadDMux()
	DoStrobe(Clock)
	OneStep(Control+SetRun+SetSS)
	resultis HaltWaitMenu
]


and LoadSimGo() = HaltWaitMenu