{File name:  FixedStartMesa.mc
 Description: Mesa Emulator initialization,
 Author: R. Johnsson,
 Last Edited: Sturgis: 16-Sep-83 10:44:46
 Last Edited: BJackson: 18-Nov-85 11:08:34
 
 }

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

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


Set[IOPage.DCSB.mask, 0EB];
Set[IOPage.DCSB.flags, 0EC];
Set[IOPage.DCSB.border, 0ED];
Set[IOPage.keyBitsm1, 39];


StartAddress[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, 1, , SkipTo[Display]]; }
	DCtl ← 2,	c2;
	PCtl ← 3,	c3;
{ Display!
IfEqual[Config, 1, SkipTo[DisplayOrPrinter], ];
	TT ← 41,	c2;
	DCtl ← TT LRot0,	c3;
DisplayOrPrinter! }

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;

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:
	KCtl ← 0, PC ← 0+0+1, CANCELBR[$,0],	c2;
	uWDC ← PC,	c3;

	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;

{following reg def is in cedarFptAll, without the x}
RegDef[uStickyRegx	,U,	24];
LastChance:
	uStickyRegx ← 0, {floating point}	c1;
	{noop}					c2;
	{noop}					c3;
	
	T ← uSDAddr,	c1;
	T ← T + 276'b{T←1376'b},	c2;
	Udest ← T, YDisp, L ← 0, GOTO[EFCHaveLink],	c3;

{16-Sep-83 10:47:37: Sturgis: add a patch to zero uStickyReg for Floating point, this is a Kludge added because rollBack dosn't do it.  Once rollback zeros the register, all is well and this patch can be removed}