{File name QdlNewLisp.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 ← 60, L2 ← L2.0,	c2;
	TOS ← MD and TOS, XRefBr,	c3;

	TOS ← TOS LRot8, BRANCH[rmNoRef, rmRef],	c1;
rmNoRef:	TOS ← TOS RShift1, SE←0, IBDisp, GOTO[DNI.pc1],	c2;
rmRef:	TOS ← TOS RShift1, SE←1, IBDisp, 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 ← ~0F0, L2 ← L2.0,	c2;
	TOS ← MD and TOS,	XDirtyDisp, c3;

	PC ← PC + PC16, BRANCH[$, rrpi, 1],	c1;
	IBDisp, GOTO[rrpj],	c2;
rrpi:	TOS ← TOS + 0F + 1, IBDisp, GOTO[rrpj],	c2;
rrpj:	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;

	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,	 XRefBr{>2mb}, c2;
	Q ← MD{vpH},	BRANCH[$, wmi], c3;
	
	Noop, GOTO[wmj],	c1;
wmi:	Rx ← Rx or 80, GOTO[wmj],	c1;
wmj:	Ybus ← Q xor smallpl, NZeroBr,	c2;
	rhTT ← TT ← TT LRot8, BRANCH[$, ufnWM2],	c3;

	S ← S -1, Xbus ← TOS LRot4, XDisp,	c1;
	Rx ← Rx and ~070, DISP4[wmf, 4],	c2;

	Rx ← Rx or 0, GOTO[wMap],	c3, at[4, 10, wmf];
	Rx ← Rx or 10, GOTO[wMap],	c3, at[0C,10,wmf];
	Rx ← Rx or 20, GOTO[wMap], 	c3, at[5, 10, wmf];
	Rx ← Rx or 30, GOTO[wMap],	c3, at[0D,10,wmf];
	Rx ← Rx or 40, GOTO[wMap],	c3, at[6, 10, wmf];
	Rx ← Rx or 50, GOTO[wMap],	c3, at[0E,10,wmf];
	Rx ← Rx or 60, GOTO[wMap],	c3, at[7, 10, wmf];
	Rx ← Rx or 70, GOTO[wMap], {reserved}	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;

{******************************************************************}
PFault:	, at[BBFault],
	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 FAULTFXP, ZeroBr{faultExit}, L2← 0{NotInCall},	c1;
	Rx← TOS, BRANCH[$,  SwFault],	c2;
	TOSH ← 0, CANCELBR[ConJn],	c3;

SwFault:	TOSH ← 0,	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;
	MDR{next} ← PV, Rx ← Rx{punt}-1, ZeroBr{KeyFXP},	c2;
	PV ← MD, BRANCH[RTN2, RTN2K],	c3;
{******************************************************************}

	{ E N D }