//RunMesa.d - Common Definitions for RunMesa files - R. Levin
//last modified by Johnsson:  May 16, 1980  8:46 AM 

//------------------------------------------------------------------
structure HardwareInfo:
//------------------------------------------------------------------
	[
	reserved bit 5
	AltoType bit 3
	XMmicrocode bit 1
	useXM bit 1
	MDSbank bit 4
	ControlStore bit 2
	banks word
	mesaMicrocodeVersion word
	]

manifest lHardwareInfo = (size HardwareInfo)/16

manifest [	// "Alto" types
	UnknownMachine = 0
	AltoI = 1
	AltoII = 2
	AltoIIXM = 3
	Dolphin = 4
	Dorado = 5
	]

manifest [	// control store types
	RAM0only = 0
	RAMandROM = 1
	RAM3K = 2
	]

manifest [
	bank0only = #100000
	banks0123 = #170000
	allBanks = #177777
	]

manifest HardwareConfiguration = #3 // where it's left in memory

// Some conventions:

//  AltoType is in [1..5]
//	0 => unknown
//	1 => Alto I
//	2 => Alto II
//	3 => Alto II XM
//	4 => Dolphin
//	5 => Dorado
//  ControlStore is in [0..2]
//	0 => RAM0 only
//	1 => RAM0 and ROM1
//	2 => RAM0, RAM1, and RAM2


//------------------------------------------------------------------
// UserParam types
//------------------------------------------------------------------

manifest mesaMemoryMask = privateType + 10


//------------------------------------------------------------------
structure BltItem:
//------------------------------------------------------------------
	[
	firstSourceM1 word
	lastDest word
	minusCount word
	]

manifest lBltItem = size BltItem/16


//------------------------------------------------------------------
structure BootMap:
//------------------------------------------------------------------
	[
	fp @FP
	firstpage word
	address↑0,(255-lFP-1) word
	]

manifest lBootMap = 256


//------------------------------------------------------------------
structure BootList:
//------------------------------------------------------------------
	[
	pageMap word
	firstDa word
	initialState word
	blt↑0,4 @BltItem // could be any number of these
	terminator word // = 0
	]

manifest lBootList = size BootList/16

manifest [	// indices for BootList.blt
	blMesaNova1 = 0
	blMesaNova2 = 1
	blInterruptVector = 2
	blInitialState = 3
	blPageMap = 4
	]


//------------------------------------------------------------------
structure VersionStamp:
//------------------------------------------------------------------
	[
	net bit 8
	host bit 8
	time:	[
		low word
		high word
		]
	]

manifest lVersionStamp = size VersionStamp/16


//------------------------------------------------------------------
structure StateVector:
//------------------------------------------------------------------
	[
	stk↑0,7 word
	instbyte byte
	fill bit 4
	stkptr bit 4
	X word
	Y word
	]

manifest lStateVector = size StateVector/16


//------------------------------------------------------------------
structure ImagePrefix:
//------------------------------------------------------------------
	[
	versionident word
	version @VersionStamp
	creator @VersionStamp
	options word
	diskAddresses word
	leaderDA word
	state @StateVector
	loadStateBase word
	initialLoadStateBase word
	type bit 2
	fill bit 1
	loadStatePages bit 13
	]

manifest lImagePrefix = size ImagePrefix/16

manifest
	[	// image types
	bootmesa = 0
	makeimage = 1
	checkfile = 2
	other = 3
	]


//------------------------------------------------------------------
structure MapItem:
//------------------------------------------------------------------
	[
	page byte
	count bit 7
	tag bit 1
	da word
	base word
	]

manifest
	[
	lnormalMapItem = 1
	lchangeMapItem = 3
	]


//------------------------------------------------------------------
// SD constants	- These must match SDDefs.mesa
//------------------------------------------------------------------
manifest
	[
	SystemDispatch = #1100
	sGoingAway = #111
	sProcessTrap = #17
	]


//------------------------------------------------------------------
// Magic addresses
//------------------------------------------------------------------
manifest
	[
	PointerToBootMap = #24
	TXV = #25		//Transfer Vector for Nova Code
	PuntData = #456
	FirstProcess = #1075
	LastProcess = #1076
	FirstStateVector = #1077
	xNovaCode = #174400
	MesaStart = #20		//Starting address in RAM
	]


//------------------------------------------------------------------
// Interrupt constants
//------------------------------------------------------------------
manifest
	[
	TimeoutInterruptLevel = 4
	TimeoutInterruptBit = 1 lshift TimeoutInterruptLevel
	ParityInterruptLevel = 0
	ParityInterruptBit = 1 lshift ParityInterruptLevel
	]


//------------------------------------------------------------------
// Interface Items
//------------------------------------------------------------------

external // OS
	[
	// procedures
	Closes
	CreateDiskStream
	DisableInterrupts
	EnableInterrupts
	Endofs
	GetCompleteFa
	GetCurrentFa
	Gets
	JumpToFa
	Junta
	InLd
	MoveBlock
	MyFrame
	OpenFile
	OsFinish
	OutLd
	PositionPage
	PositionPtr
	Puts
	ReadBlock
	RealDiskDA
	Resets
	SetFilePos
	TruncateDiskStream
	Wns
	Ws
	Zero
	// variables
	dsp
	fpComCm
	keys
	lvUserFinishProc
	sysDisk
	]

external // Run.bcpl
	[
	AbortMsg
	GiveMicrocodeVersion
	KeyboardWait
 	LoadInternalMicrocode
	memoryBanks		// bit mask (100000b rshift bank)
	microcodeLoaded		// bit mask (1 lshift bank)
 	Run
	]

external // Configuration.bcpl
	[
	DetermineConfiguration
	ROMCompatibility
	]

external // MesaImage.br
	[
	MesaImage
	]

external // XMesaImage.br
	[
	XMesaImage
	]

external // XMesaOverflow.br
	[
	XMesaOverflow
	]

external // Mesa-Nova (1 & 2) .asm
	[
	EMLOOP
	MesaNova1
	MesaNovaSize1
	AC1Ptr
	AbsoluteTXV
	CleanUpQueueUser
	RequeueSubUser
	WakeHeadImplementer
	STOPUser
	AdvanceTimerPtr
	processTrapPtr
	firstProcessPtr
	lastProcessPtr
	firstStateVectorPtr
	PScode
	MesaNova2
	MesaNovaSize2
	STOPImplementer
	CleanUpQueueImplementer
	RequeueSubImplementer
	WakeHeadUser
	OSFPtr
	OutLdPtr
	InLdPtr
	FinishPtr
	FinProcPtr
	]

external // MBOOT.asm
	[
	MBOOT
	SwatFlag
	]