//MXI.BCPL initialization overlay

get "mx.d"

external [
// MASM
	GetStorage

// MIDAS
	GetEvenStorage

// MINIT2
	NewMPDispBlock; DefineRegister; DefineMemory
	DefIAction; DefHWAction

// MIOC
	RDatatoStream; MDatatoStream

// MCMD
	IMAddrXct; CmdGoOverlay; CmdStartM; CmdDebug; CallAltIO

// STATE
	SaveStatics

// MXALTR
	InitAltIOFP

// MXPRIN
	PrintIM; PrintARM

// Defined here
	InitMPInterface; NHWActions
	ScreenHeight; ScreenWidth
]

static [ NHWActions = 14	//Size of machine dependent command menu
				//action table filled in by DefHWAction
	ScreenHeight = 28	//Number of screen lines
	ScreenWidth = 76	//Number of chars/line
	AltMForms; AltRForms
 ]


//"InitMPInterface" allocates storage for vectors and the LDR memory and
//initializes screen areas.  Args to NewMPDispBlock
//are line number, left character (0 to 75), identifying character for
//use in command files, width in characters, and true for unnamed
//areas (STK only), or false for named areas
let InitMPInterface() be
[	MEMNAM = lv MName; REGNAM = lv RName
	MEMFORMS = lv MForm; REGFORMS = lv RForm
	NewMPDispBlock(0,0,$A,11,false)	//IMA
	NewMPDispBlock(0,13,$B,10,false)	//NPC
	for I = 1 to 4 do			//STK
	[ NewMPDispBlock(I,0,$A,11,false)
	  NewMPDispBlock(I,13,$B,4,true)
	  NewMPDispBlock(I,19,$C,4,true)
	]
	for I = 5 to 6 do			//X, Y, AC, KUNIT
	[ NewMPDispBlock(I,0,$A,11,false)
	  NewMPDispBlock(I,13,$B,10,false)
	]
	for I = 7 to 16 do NewMPDispBlock(I,0,$A,23,false)	//big regs
	for I = 0 to 13 do		//MAR-MDR, KMAR-KMDR, 36-bit regs
	[ NewMPDispBlock(I,26,$D,23,false)
	  NewMPDispBlock(I,52,$E,23,false)
	]
	for I = 14 to 16 do NewMPDispBlock(I,26,$D,49,false)	//random stuff

	LDRMEM = GetStorage(LDRSIZ*5)
	ITRCNT = LDRMEM+COUNT; INSTST = LDRMEM+TSTINS
	MEMCFG = LDRMEM+CONFIG; ADRANG = LDRMEM+ARANGE
	Q = GetStorage(3); F = GetStorage(3)
	EREG = GetStorage(3); SMFORF = GetStorage(3); STK = GetStorage(12)
//TMP and TMP1 must point at even words because they are used
//to hold addresses and data for the memory interface which
//requires even word boundaries.  They are also used in MXPOW
//as four-word vectors.
	TMP = GetEvenStorage(4)
	TMP1 = GetEvenStorage(4)
	TMP2 = GetEvenStorage(4)
	TAVEC = GetStorage(2)
	GOODD = GetStorage(5); ACTD = GetStorage(5); DMASK = GetStorage(5)
//REGACT, MEMACT, and PATACT must be contiguous and in order
	REGACT = GetStorage(NREALREGS)
	MEMACT = GetStorage(NREALMEMS-2)	//Omits MAIN
	PATACT = GetStorage(NPATS)
	AltRForms = GetStorage(NREGS)
	SetBlock(AltRForms,lv RDatatoStream,NREGS)
	AltRForms!6 = lv PrintIMA		//NPC
	AltRForms!11 = lv PrintARM		//ARM
	AltRForms!12 = lv PrintIMA		//IMA
	AltMForms = GetStorage(NMEMS)
	SetBlock(AltMForms,lv MDatatoStream,NMEMS)
	AltMForms!9 = lv PrintIMA		//STK
	AltMForms!4 = lv PrintDM		//DM
	AltMForms!10 = lv PrintDM		//DM1
	AltMForms!11 = lv PrintDM		//DM2
	AltMForms!2 = lv PrintIM		//IM
	for RegX = 0 to NREGS-1 do
		DefineRegister(REGNAM!RegX,RegX,REGWID!RegX)
//Subsidiary memories IM[0,35] and IM[36,71] aren't defined
	for MemX = 2 to 5 do
		DefineMemory(MEMNAM!MemX,MemX,MEMWID!MemX,0,MEMLEN!MemX)
	DefineMemory(MEMNAM!6,6,40,10B,0)	//MAIN
	for MemX = 7 to NMEMS-1 do
		DefineMemory(MEMNAM!MemX,MemX,MEMWID!MemX,0,MEMLEN!MemX)

	DefHWAction(0,"AltIO",lv CallAltIO,0,0,$A)
	DefHWAction(1,"Break",lv IMAddrXct,lv InsertBreak,0,$B)
	DefHWAction(2,"Kill-Break",lv IMAddrXct,lv RemoveBreak,0,$K)
	DefHWAction(3,"Go",lv CmdStartM,lv StartM,0,$G)
	DefHWAction(4,"Step",lv IMAddrXct,lv SingleStepM,0,$:)
	DefHWAction(5,"Power-On",lv CmdGoOverlay,lv MicGo)
	DefHWAction(6,"Power-Off",lv CmdGoOverlay,lv MicStop)
	DefHWAction(7,"Repeat-Go",lv CmdStartM,lv RepeatGo,0,$R)
	DefHWAction(8,"Repeat-Step",lv CmdStartM,lv RepeatSS,0,$S)
	DefHWAction(9,"Test",lv CmdGoOverlay,lv DataTest)
	DefHWAction(10,"Test-All",lv CmdGoOverlay,lv TestAll)
	DefHWAction(11,"Constructed-Test",lv CmdDebug,lv MicTest)
	DefHWAction(12,"Signal-Decode",lv CmdGoOverlay,lv FieldTest)
	DefHWAction(13,"LMPEscan",lv ScanForLMPE,0)

	DefIAction("Go",lv CmdStartM,lv StartM,$P)	//Synonym

	InitAltIOFP()

	SaveStatics(lv MEMNAM,lv REGNAM,lv MEMFORMS,lv REGFORMS,
		lv LDRMEM,lv ITRCNT,lv INSTST,lv MEMCFG,lv ADRANG,
		lv Q,lv F,lv EREG,lv SMFORF,lv STK,lv TMP,
		lv TMP1,lv TMP2)
	SaveStatics(lv TAVEC,lv GOODD,lv ACTD,lv DMASK,lv REGACT,
		lv MEMACT,lv PATACT)
]