{File name:  FixedStartMesa.mc
 Description: Mesa Emulator initialization,
 Author: R. Johnsson,
 Last Edited:
  Sturgis: 16-Sep-83 10:47:37: add a patch to zero uStickyReg for Floating point,
	a Kludge added because rollBack dosn't do it.  Once rollback zeros the
	register, all is well and this patch can be removed.
  Fiala 11-Jun-86 15:40:48:  Prepare for Initial changes by inserting init for u200
	and uSDAddr; remove def'n for uStickyRegx.
  Fiala 23-Jul-86 15:36:19 Insert changes for alternate configurations from 12.0
   	product microcode; do not assume that uIOPage contains bank number in rh;
	SAx000 code gets new init of PCtl.
  Fiala 25-Jul-86  9:47:58 Removed uStickyReg and uSDAddr init to InitDLion.mc.
  Fiala 30-Jul-86 10:29:20 Cosmetic.
  Fiala  9-Sep-86 15:13:40 Move Display IOPage defn's to Dandelion.dfn.
  Fiala 18-Nov-86 14:01:33 Add assembly config switch for Dicentra.
}

Reserve[0F6F]; Reserve[0F78]; Reserve[0F7F,0FFF];	{Kernel}

{Assembly Config #	File
	  0		Mesa.db
	  1		RavenMesa.db
	  2		TridentMesa.db
	  3		TridentRavenMesa.db
	  4		MagTapeMesa.db
	  5		TridentMagTapeMesa.db
	  6		Multiport.db
	  7		Dicentra
}

Set[xtFC0, 1] {see description of bits in Xfer};



StartAddress[Germ];

{	Normal boot starts at Germ,
	Floppy boot starts at Germ+1
	Start at Go for Burdock loaded bootfile without germ
}

Germ:	TOS ← 3E, rhMDS ← 3E, CANCELBR[SetMDS,0F],	c1, at[0,2,Germ];
Go:	TOS ← 2, rhMDS ← 2, CANCELBR[SetMDS,0F],	c1, at[1,2,Germ];
SetMDS:	UvMDS ← TOS,	c2;
	rhT ← xtFC0,	c3;

	uPCValid ← 0, ClrIntErr,				c1;


IfEqual[Config, 6, SkipTo[Multiport], ];
IfGreater[Config, 3, SkipTo[MagTape], ];
IfEqual[Config, 3, SkipTo[Printer], ];
IfEqual[Config, 1, SkipTo[Printer], ];

	TT ← 41,						c2;
	DCtl ← TT LRot0,					c3;

	Noop,							c1;
	TT ← 11,						c2;
	PCtl ← TT LRot0,					c3;

SkipTo[DisplayOrPrinterOrMagTape];
Printer!
	DCtl ← 2,						c2;
	PCtl ← 3,						c3;

SkipTo[DisplayOrPrinterOrMagTape];
MagTape!
	DCtl ← 2,						c2;
	TCtl ← 1,						c3;
	
SkipTo[DisplayOrPrinterOrMagTape];
Multiport!
	DCtl ← 0,						c2;
	PCtl ← 3,						c3;			
DisplayOrPrinterOrMagTape!



MoreInit:
	IOPCtl ← IOPInMode,					c1;
	UvG ← TOS ← 0,						c2;
	UBrkByte ← 0,						c3;

{set all keys up; 1403A thru 14040 ← -1}
	rhTT ← TT ← uIOPage,					c1;
	uXTS ← stackP ← 0,					c2;
	Q ← 7,							c3;

	rhTT ← cedarIOPageHigh,					c1;
	Noop,							c2;
	Noop,							c3;

KeyLoop:
	MAR ← [rhTT,IOPage.keyBitsm1+Q], BRANCH[$,KeyDone],	c1;
	uTickCount ← MDR ← L xor ~L, CANCELBR[$,0],		c2;
	Q ← Q - 1, ZeroBr, GOTO[KeyLoop],			c3;

KeyDone:

IfGreater[Config, 1, , SkipTo[ShugartInit]];
IfEqual[Config, 4, SkipTo[ShugartInit],];
IfEqual[Config, 6, SkipTo[ShugartInit],];
{Config = 2, 3, or 5 => Trident init}
	PC ← 0+0+1, CANCELBR[$,0],				c2;
	uWDC ← PC,						c3;

	RCnt ← 0F,						c1;
	KCtl ← RCnt LRot12,					c2;
	KCmd ← U0400,						c3;
SkipTo[EitherDisk];

ShugartInit! {Config = 0, 1, 4, or 6 => SAx000 init}
	KCtl ← 0, PC ← 0+0+1, CANCELBR[$, 0],			c2;
	uWDC ← PC,						c3;

EitherDisk!
	MAR ← [rhTT,IOPage.DCSB.mask+0]{display interrupt mask},	c1;
	MDR ← 0, uWP ← 0,					c2;
	T ← 88,							c3;

	MAR ← [rhTT,IOPage.DCSB.flags+0]{display flags},	c1;
	MDR ← u8000,						c2;
	T ← T LRot8,						c3;

	MAR ← [rhTT,IOPage.DCSB.border+0]{display border},	c1;
	MDR ← T or 22{8822},					c2;
	uPCCross ← 0,						c3;

LastChance:	
	TT ← uSDAddr,						c1;
	T ← TT + 276'b {T ← 1376'b},				c2;
	Udest ← T, YDisp, L ← 0, GOTO[EFCHaveLink],		c3;