{File name QdbNewLisp.mc
}

SetTask[0];

{******************************************************************
	READFLAGS
*******************************************************************}
READFLAGS:
	Xbus ← TOSH xor smallpl, NZeroBr,	c1, opcode[161'b]; {71}
	rhTT ← TT ← TOS LRot8, BRANCH[$, rdfUfn],	c2;
	TOSH ← smallpl,	c3;

	Map ← [rhTT, TT],	c1;
	TOS ← 0E0,	c2;
	TOS ← MD and TOS,	c3;

	TOS ← TOS LRot12,	c1;
	Ybus ← TOS and 0F, YDisp,	c2;
	DISP4[CvtFlags,1], c3;

	TOS ← 00, GOTO[RFExit], c1, at[01,10,CvtFlags];
	TOS ← 02, GOTO[RFExit], c1, at[03,10,CvtFlags];
	TOS ← 01, GOTO[RFExit], c1, at[05,10,CvtFlags];
	TOS ← 03, GOTO[RFExit], c1, at[07,10,CvtFlags];
	TOS ← 08, GOTO[RFExit], c1, at[09,10,CvtFlags];
	TOS ← 0A, GOTO[RFExit], c1, at[0B,10,CvtFlags];
	TOS ← 09, GOTO[RFExit], c1, at[0D,10,CvtFlags];
	TOS ← 0D, GOTO[RFExit], c1, at[0F,10,CvtFlags];
RFExit:	TOS ← TOS LRot12, IBDisp, L2 ← L2.0, GOTO[DNI.pc1],	c2;
rdfUfn:	Rx ← 161'b, GOTO[ufn1],	c3;

{******************************************************************
	READRP
*******************************************************************}
READRP:
	Xbus ← TOSH xor smallpl, NZeroBr,	c1, opcode[162'b];
	rhTT ← TT ← TOS LRot8, BRANCH[$, rdrpUfn],	c2;
	TOSH ← smallpl,	c3;

	Map ← [rhTT, TT],	c1;
	TOS ← ~0E0, L2 ← L2.0,	c2;
	TOS ← MD and TOS, c3;

	Ybus ← TOS - 1, PgCarryBr,	c1;
	BRANCH[rsect0, rsectN0],	c2;
rsect0:
	GOTO[readrpend],	c3;
rsectN0:
	TOS ← TOS - 3, GOTO[readrpend],	c3;

readrpend:
	PC ← PC + PC16,	c1;
	IBDisp,	c2;
	TOS ← TOS LRot8, L2 ← L2.0, DISPNI[OpTable],	c3;
rdrpUfn:	Rx ← 162'b, GOTO[ufn1],	c3; 

{******************************************************************
	WRITEMAP
*******************************************************************}
WRITEMAP:   {vp, rp, flag => vp}

	MAR ← [rhS, S], S ← S -1,	c1, opcode[163'b];{73}
	Ybus ← TOSH xor smallpl, NZeroBr, CANCELBR[$, 2],	c2;
	Rx ← MD{rp}, BRANCH[$, ufnWM0],	c3;

{ Test to see if the rp is in the display bank. If so, leave it alone else bump pg# by 300}
	TT ← Rx and ~0FF, c1;
	Ybus ← TT + 0, ZeroBr, c2;
	TT ← 3, BRANCH[notDB, isDB], c3;

notDB:	TT ← TT LRot8, c1;
	Rx ← Rx + TT, c2;  {add 3 segs}
	, c3;

	MAR ← [rhS, S + 0],	c1;
	S ← S -1, 	c2;
	Q ← MD{rpH},	c3;

	MAR ← [rhS, S], S ← S -1,	c1;
	Ybus ← Q xor smallpl, NZeroBr, CANCELBR[$,2],	c2;
	TT ← MD{vp}, BRANCH[$, ufnWM1],	c3;

	MAR ← [rhS, S+0], L2 ← L2.0,	c1;
	Rx ← Rx LRot8,			c2;
	Q ← MD{vpH},			c3;

	, 				c1;
	Ybus ← Q xor smallpl, NZeroBr,	c2;
	rhTT ← TT ← TT LRot8, BRANCH[$, ufnWM2],	c3;
	S ← S -1, Xbus ← TOS LRot4, XDisp,	c1;
	Rx ← Rx and ~0E0, DISP4[wmf, 4],	c2;
	Rx ← Rx or 0, GOTO[wMap],	c3, at[4, 10, wmf];
	Rx ← Rx or 80, GOTO[wMap],	c3, at[0C,10,wmf];
	Rx ← Rx or 040, GOTO[wMap], 	c3, at[5, 10, wmf];
	Rx ← Rx or 0C0, GOTO[wMap],	c3, at[0D,10,wmf];
	Rx ← Rx or 20, GOTO[wMap],	c3, at[6, 10, wmf];		Rx ← Rx or 0A0, GOTO[wMap],	c3, at[0E,10,wmf];
	Rx ← Rx or 060, GOTO[wMap],	c3, at[7, 10, wmf];
	Rx ← Rx or 0E0, GOTO[wMap],	c3, at[0F,10,wmf];

wMap:	Map ← [rhTT, TT],	c1;
	MDR ← Rx, PC ← PC + PC16, IBDisp,	c2;
	TOS ← TT LRot8, L2 ← L2.0, DISPNI[OpTable],	c3;

ufnWM0:	S ← S+1, GOTO[ufnX2],	c1;
ufnWM1:	S ← S+3, GOTO[ufnX2],	c1;
ufnWM2:	S ← S+3, GOTO[ufnX2],	c1;

{******************************************************************}
AnotherFault:	Noop, GOTO[PFault], c3, at[PFaultB0];
BBFault:
PFault:	rhRx ←  INTERFACEspace, 	c1;
	Rx ← INTERFACEbasePage{20'b}{INTERFACEbase=10000'b},	c2;
	Rx ← Rx LRot8, GOTO[PFaultcont],	c3;
{******************************************************************}
{% SHOULD CHECK IF ANY PENDING INTERRUPTS - CURRENTLY
 MAY MISS KEYSTROKES }

opcode[176'b],{7E}
	Ybus ← TOS xor ResetFXP, ZeroBr{faultExit}, L2← 0{NotInCall},	c1;
	Rx← TOS, BRANCH[$,  SwReset],	c2;
	TOSH ← 0, CANCELBR[ConJn],	c3;
SwReset: ClrIntErr,TOSH ← 1{Resetting},	c3;
	rhRio ← oldIOPageHigh, c1;
	Rio ← oldIOPageLow, c2;
	uWP ← 0, c3;
	MAR ← [rhRio, Rio + PeriodicInterruptOffset],c1;
	MDR ← 0, CANCELBR[$,2], LOOPHOLE[wok], c2;
	, c3;
ConJn:	uWDC ← TOSH, PC← PC + PC16 {advance PC}, GOTO[PuntFor2],	c1;
{note that this code winds up storing the context number on the stack and then
setting the no-push bit in the frame. This is not exactly the same as the Dorado, but no code relies on the value returned "to" a context}
{******************************************************************}
MidPuntmar:
	MAR ← [rhTT, Q + 0],	c1;
	,	c2;
	Rx ← MD,	c3;

	MAR ← [rhTT, Q + 0],	c1;
	MDR{next} ← PV,	c2;
	PV ← Rx, GOTO[RTN2],	c3;
{******************************************************************}

	{ E N D }