{
File name StringField.mc
Description: Mesa String op-codes
Author: DXC     
Created: February 26, 1980
JPM 10-Oct-84 13:47:44 Fix bug in @RS (uncaught use of XRefBr = bit 11; change LRot4 to LRot0 and use masked XLDisp instead).
JPM 11-Sep-84 13:18:34 Fix BRANCH mask after XWtOKDisp; fix allocation problem in @WLS and @WF.
Last edited: DEG,  1-Sep-84 19:51:32   add copyright notice
JPM 9-May-84 13:20:24 Replaced XDirtyDisp by XWtOKDisp
AXD 15-Jun-83 18:37:12 New instruction set
JGS November 2, 1981  4:06 PM New instruction set
Last edited: RXJ, March 13, 1981  5:43 PM
Last edited: DXC, April 8, 1980  5:44 PM
Last edited: RXG, April 8, 1980  7:09 PM
Last edited: RXJ, March 13, 1981  5:43 PM
}

{ 	Copyright (C) 1980, 1981, 1984 by Xerox Corporation.  All rights reserved.}

{
RS	Read String
RLS	Read Long String

WS	Write String
WLS	Write Long String

R0F	Read Zero Field
RF	Read Field
RCFS	Read Code Field Stack (ESC opcode)
RL0F	Read Long Zero Field
RLF	Read Long Field
RLFS	Read Long Field Stack
RLIPF	Read Local Indirect Pair Field
RLILPF	Read Local Indirect Long Pair Field

W0F	Write Zero Field
WF	Write Field
WL0F	Write Long Zero Field
WLF	Write Long Field
WLFS	Write Long Field Stack
WS0F	Write Swapped Zero Field

PS0F	Put Swapped Zero Field
PSF	Put Swapped Field
PSLF	Put Swapped Long Field
}

{*****************************************************************************
	RS
*****************************************************************************}

@RS:	T ← TOS{inx} + ib,					c1, opcode[141'b];
	Q ← STK{ptr}, pop, L1←L1.Push,					c2;
	TT ← RShift1 T, pop,						c3;

	Map ← Q ← [rhMDS,TT + Q], push,					c1;
	rhTT ← UvMDS,							c2;
RSa:	Rx ← rhRx ← MD, XRefBr,						c3;

	MAR ← [rhRx,Q + 0], L0←L0.RS, BRANCH[RSMUD,$],		c1, RLMFRet[L0.RS];
	PC ← PC + 1, Xbus ← T LRot0, XLDisp,				c2;
	TOS ← MD, BRANCH[RSb,RSc,2],					c3;

RSc:	TOS ← TOS and 0FF, GOTO[IBDispOnly],				c1;
RSb:	TOS ← TOS and ~0FF,						c1;
	TOS ← TOS LRot8, IBDisp, GOTO[DISPNIonly],			c2;

RSMUD:	CALL[RLMapFix],							c2;


{*****************************************************************************
	RLS
*****************************************************************************}

@RLS:	T ← TOS{inx} + ib, CarryBr, L3←0,			c1, opcode[142'b];
	rhTT ← STK{ptrH}, BRANCH[RLSa,RLSb],				c2;
RLSa:	Rx ← RShift1 T, SE←0, pop, GOTO[RLSc],				c3;
RLSb:	Rx ← RShift1 T, SE←1, pop, GOTO[RLSc],				c3;

RLSc:	TT ← STK{ptrL}, pop, L2←L2.xSL,					c1;
	TT ← TT + Rx, CarryBr, L1←L1.Push2,				c2;
	fXpop, push, BRANCH[RLSd, RLSe],				c3;

RLSe:	CALL[VAHiInc],							c1;

RLSd:	Map ← Q ← [rhTT,TT], L3Disp,				c1, VAHiRet[L2.xSL];
	TT ← 0FF, BRANCH[RSa, WLSc],					c2;


{*****************************************************************************
	WS
*****************************************************************************}

@WS:	T ← TOS{inx} + ib, L0←L0.WS,				c1, opcode[143'b];
	Q ← STK{ptr}, L1←L1.Push,					c2;
	TT ← RShift1 T,							c3;

	Map ← Q ← [rhMDS,TT + Q],					c1;
	TT ← 0FF,							c2;
	Rx ← rhRx ← MD, XWtOKDisp, pop,				c3;

	MAR ← [rhRx,Q + 0], BRANCH[WSMUD,$,0D],			c1, WMFRet[L0.WS];
	PC ← PC + 1,							c2;
WSa:	TOS ← MD, Ybus ← T, YDisp,					c3;

	T ← STK and TT, pop, BRANCH[WSl, WSr, 0E],			c1;
WSl:	T ← T LRot8,							c2;
	TOS ← TOS and TT, GOTO[WSb],					c3;

WSr:	TOS ← TOS and ~TT,						c2;
	Noop, GOTO[WSb],						c3;

WSb:	MAR ← [rhRx,Q + 0],						c1;
	MDR ← TOS or T, IBDisp, GOTO[SLa],				c2;

WSMUD:	CALL[WMapFix],							c2;


{*****************************************************************************
	WLS
*****************************************************************************}

@WLS:	T ← TOS{inx} + ib, CarryBr, L3←1,			c1, opcode[144'b];
	rhTT ← STK{ptrH}, BRANCH[RLSa,RLSb],				c2;

WLSc:	Rx ← rhRx ← MD, XWtOKDisp,					c3;

	MAR ← [rhRx,Q + 0], BRANCH[WLSMUD,$,0D],	      c1, WLMFRet[L0.WLS];
	PC ← PC + 1, GOTO[WSa],						c2;

WLSMUD:	L0←L0.WLS, CALL[WLMapFix],					c2;


{*****************************************************************************
	R0F
*****************************************************************************}

@R0F:	TT ← TOS, L1←L1.Dec,					c1, opcode[145'b];
	rhTT ← UvMDS,							c2;
R0Fa:	PC ← PC + PC16, GOTO[RFa],					c3;


{*****************************************************************************
	RF
*****************************************************************************}

@RF:	TT ← TOS + ib{alpha}, L1←L1.Dec2,			c1, opcode[146'b];
	rhTT ← UvMDS,							c2;
	PC ← PC + 1,							c3;

RFa:	Map ← Q ← [rhTT,TT], L0←L0.RF,				c1, IPRet[L0.RLIPF];
	T ← fd.pos, pop,						c2;
	Rx ← rhRx ← MD, XRefBr, push,					c3;

RFc:	MAR ← [rhRx,Q + 0], BRANCH[RFMUD,$],			c1, RLMFRet[L0.RF];
	T ← T + ib{fd.size} + 1, rhT ← ib{fd.size},			c2;
RFd:	T ← MD{data}, Ybus ← T{shift}, YDisp, L2←L2.RF,			c3;

RFe:	TT ← LRot1 T, DISP4[CycleMask],					c1;

	{CycleMask Subroutine Here}

RFf:	TOS ← TOS and TT, IBDisp, GOTO[NegNI],			c2, at[L2.RF,10,MaskRet];

RFMUD:	CALL[RLMapFix],						c2;


{*****************************************************************************
	RL0F
*****************************************************************************}

@RL0F:	TT ← STK{ptrL}, pop, L1←L1.PushDec,			c1, opcode[147'b];
	rhTT ← TOS{ptrH} LRot0, GOTO[R0Fa],				c2;


{*****************************************************************************
	RLF
*****************************************************************************}

@RLF:	TT ← STK{ptrL}, pop, L1←L1.PushDec2,			c1, opcode[150'b];
	TT ← TT + ib{alpha}, CarryBr, L2←L2.RLF,			c2;
	rhTT ← TOS{ptrH} LRot0, BRANCH[RLFa,RLFb],			c3;

RLFb:	CALL[VAHiInc],							c1;

RLFa:	PC ← PC + 1,						c1, VAHiRet[L2.RLF];
RLFc:	Noop,								c2;
	GOTO[RFa],						c3, ILPRet[L0.RLILPF];


{*****************************************************************************
	RLFS
*****************************************************************************}

@RLFS:	T ← TOS{desc} LRot8, L1←L1.Push2,			c1, opcode[151'b];
	T ← 0FF and T{desc.offset},					c2;
	rhTT ← STK{ptrH}, pop,						c3;

RLFSc:	TT ← STK{ptrL}, pop, L2←L2.RLFS,				c1;
	TT ← TT + T, CarryBr,						c2;
	BRANCH[RLFSa,RLFSb],						c3;

RLFSb:	CALL[VAHiInc],							c1;

RLFSa:	Map ← Q ← [rhTT,TT], L0←L0.RLFS,			c1, VAHiRet[L2.RLFS];
	T ← TOS LRot12 + TOS + 1, LOOPHOLE[niblTiming], pop,		c2;
	Rx ← rhRx ← MD, XRefBr, push,					c3;

	MAR ← [rhRx,Q + 0], BRANCH[RLFSMUD,$],			c1, RLMFRet[L0.RLFS];
	rhT ← TOS{desc.size} LRot0, GOTO[RFd],				c2;

RLFSMUD:
	CALL[RLMapFix],						c2;


{*****************************************************************************
	RCFS
*****************************************************************************}

@RCFS:	TT ← UvC, L1←L1.PushDec,			c1, at[0A,10,ESC1n];
	T ← TOS LRot8,							c2;
	T ← 0FF and T,							c3;

	T ← TT + T,							c1;
	rhTT ← UvChigh,							c2;
	PC ← PC - PC16, GOTO[RLFSc],					c3;


{*****************************************************************************
	RLIPF
*****************************************************************************}

@RLIPF:	MAR ← Q ← [rhL, L+alpha.left], L0←L0.RLIPF, push,	c1, opcode[152'b];
	STK ← TOS, PC ← PC + 1, L2←L2.LIP, BRANCH[LIPa,LIPb,1],		c2;


{*****************************************************************************
	RLILPF
*****************************************************************************}

@RLILPF:
	MAR ← Q ← [rhL, L+alpha.left], L0←L0.RLILPF, push,	c1, opcode[153'b];
	STK ← TOS, PC ← PC + 1, L2←L2.LILP0, BRANCH[LILPa,LILPb,1],	c2;


{*****************************************************************************
	W0F
*****************************************************************************}

@W0F:	TT ← TOS, push, L1←L1.Dec,				c1, opcode[154'b];
	STK ← TOS, pop, PC ← PC + PC16,					c2;
	rhTT ← UvMDS, GOTO[WFb],					c3;

{*****************************************************************************
	WF
*****************************************************************************}

@WF:	TT ← TOS + ib{alpha}, push, L1←L1.Dec2,			c1, opcode[155'b];
	STK ← TOS, pop,							c2;
	rhTT ← UvMDS, GOTO[WLFa],					c3;

WFb:	Map ← uTTemp ← Q ← [rhTT, TT],					c1;
	T ← STK, L0←L0.WF,						c2;
WFd:	Rx ← rhRx ← MD, XWtOKDisp,					c3;

	MAR ← [rhRx,Q + 0], BRANCH[WFMUD,$,0D],		       c1, WLMFRet[L0.WF];
	TOS ← ib{fd}, pop,						c2;
WFc:	Q ← MD{data},							c3;

	Xbus ← ~TOS LRot12, XDisp,					c1;
	Xbus ← L2.WF0, XDisp, DISP4[MaskTbl],				c2;
	{MaskTbl Subroutine here,	c3:}

	PC ← PC + PC16, uTT ← TT,			c1, at[L2.WF0,10,MaskRet];
	TOS ← TOS LRot12 + TOS, LOOPHOLE[niblTiming], L2←L2.WF1,	c2;
	rhT ← ~TOS LRot0, XDisp,					c3;

	TT←LRot1 T, DISP4[CycleMask],					c1;

	{CycleMask Subroutine Here}

	TT ← RShift1 ~TT, SE←1,				c2, at[L2.WF1,10,MaskRet];
	TT ← uTT and TT{TT now has mem alligned mask},			c3;

	T ← Q and ~TT							c1;
	TOS ← TOS and TT,						c2;
	Q ← uTTemp, GOTO[WSb],						c3;

WFMUD:	CALL[WLMapFix],							c2;


{*****************************************************************************
	PSF
*****************************************************************************}

@PSF:	TT ← STK, fXpop, fZpop, push,				c1, opcode[156'b];
	TT ← TT + ib, L1←L1.PopDec2,					c2;
	rhTT ← UvMDS, push,						c3;

	STK ← TOS, GOTO[WLFc],						c1;


{*****************************************************************************
	PS0F
*****************************************************************************}

@PS0F:	TT ← STK, push, L1←L1.PopDec,				c1, opcode[157'b];
	STK ← T ← TOS, GOTO[WS0Fa],					c2;


{*****************************************************************************
	WS0F
*****************************************************************************}

@WS0F:	TT ← STK, push, L1←L1.Dec,				c1, opcode[160'b];
	STK ← T ← TOS, pop,						c2;
WS0Fa:	rhTT ← UvMDS,							c3;

	Map ← uTTemp ← Q ← [rhTT, TT],					c1;
	PC ← PC + PC16, L0←L0.WF, GOTO[WFd],				c2;


{*****************************************************************************
	WL0F
*****************************************************************************}

@WL0F:	TT ← STK, pop, L1←L1.PushDec,				c1, opcode[161'b];
	PC ← PC + PC16,							c2;
	rhTT ← TOS{ptrH} LRot0, GOTO[WFb],				c3;


{*****************************************************************************
	WLF
*****************************************************************************}

@WLF:	TT ← STK{ptrL}, pop, L2←L2.WLF,				c1, opcode[162'b];
	TT ← TT + ib{alpha}, CarryBr, L1←L1.PushDec2,			c2;
	rhTT ← TOS{ptrH} LRot0, BRANCH[WLFa,WLFb],			c3;

WLFb:	CALL[VAHiInc],							c1;

WLFa:	Noop,						c1, VAHiRet[L2.WLF];
WLFc:	PC ← PC + 1,							c2;
	GOTO[WFb],							c3;


{*****************************************************************************
	PLSF
*****************************************************************************}

@PSLF:	rhTT ← Q ← STK, pop,					c1, opcode[163'b];
	TT ← STK, fXpop, fZpop, push,					c2;
	TT ← TT + ib, push, CarryBr,					c3;

	PC ← PC + 1, push, BRANCH[PSLFa, PSLFb],			c1;
PSLFa:	STK ← TOS, Rx ← Q,  L1←L1.PopDec2, GOTO[PSLFc],			c2;
PSLFb:	STK ← TOS, Rx ← Q + 1,  L1←L1.PopDec2, GOTO[PSLFc],		c2;
PSLFc:	rhTT ← Rx LRot0, GOTO[WFb],					c3;


{*****************************************************************************
	WLFS
*****************************************************************************}

@WLFS:	T ← TOS{desc} LRot8, L1←L1.Push2,			c1, opcode[164'b];
	T ← 0FF and T{desc.offset},					c2;
	rhTT ← STK{ptrH}, pop,						c3;

	TT ← STK{ptrL}, pop, L2←L2.WLFS,				c1;
	TT ← TT + T, CarryBr,						c2;
	BRANCH[WLFSa,WLFSb],						c3;

WLFSb:	CALL[VAHiInc],							c1;

WLFSa:	Map ← uTTemp ← Q ← [rhTT,TT], L0←L0.WLFS,	c1, VAHiRet[L2.WLFS];
	T ← STK,							c2;
	Rx ← rhRx ← MD, XWtOKDisp,					c3;

	MAR ← [rhRx,Q + 0], BRANCH[WLFSMUD,$,0D],	c1, WLMFRet[L0.WLFS];
	pop, GOTO[WFc],							c2;

WLFSMUD:
	CALL[WLMapFix],							c2;


	{ E N D }