perm filename SIMRTS.MAC[SIM,SYS] blob sn#462261 filedate 1979-07-27 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002		SEARCH	SIMMAC,SIMMCR,SIMRPA
C00004 00003		SUBTTL	SIMRTS transfer vector
C00006 00004		SUBTTL	.OCSW - swap high segment
C00011 ENDMK
CāŠ—;
	SEARCH	SIMMAC,SIMMCR,SIMRPA

IF1,<
	Q==777
	IFNDEF	QNHGH,<QNHGH=1	;;Default only one high segment
			QHGH==Q>
	IFNDEF	QHGH,<QHGH=Q>
	IFE	QHGH,<QHGH=Q>
>;;END IF1

	SALL
IFG <QHGH-QNHGH>,<RTITLE	SIMRTS - Transfer vector>
IFE <QHGH-1>,<RTITLE	SIMR21 - Transfer vector and swap routine>
IFE <QHGH-2>,<RTITLE	SIMR22 - Transfer vector and swap routine>

X17=17
.JBOPS=135
.JBVER=137

	DEFINE	VER(N,MA,MI,ED,WH)<PRINTX	SIMRT'N VERSION MA,MI(ED)-WH>
	IF2,<IFL <QHGH-QNHGH-1>,<VER(\QHGH,\VSIMRT,\VRTUPD,\VRTEDI,\VRTCUS)>
		IFG <QHGH-QNHGH>,<VER(S,\VSIMRT,\VRTUPD,\VRTEDI,\VRTCUS)>
	>

	LOC	.JBOPS
	Z	;Informs OCSP that SIMRTS was loaded

	LOC	.JBVER
	VERRTS
	TWOSEG
	RELOC	400K
	MACINIT
	SUBTTL	SIMRTS transfer vector

.SIMRT=	.
	IF1,<
	DEFINE	X(A,B,C,D)<IFG	<A-400k>,<
		IFN <A-400010-.+.SIMRT>,<CFAIL RTSYM A phase error>
		Q==1
		IFNB <B>,<Q==B>
		Q==Q&QHGH
		IFN	Q,<IFNB	<D>,<
			GOTO	D'##
			>
			IFB	<D>,<
			GOTO	.'A'##
			>>
		IFE	Q,<
		PUSHJ	XPDP,.OCSW	;A
			>
	>;;END X>

	DEFINE	Y(NAM,SEG,S,F)<IFDIF	<L>,<SEG>,<
		Q==1
		IFNB <SEG>,<Q==SEG>
		Q==Q&QHGH
		IFN Q,<D%'NAM>
		IFE Q,<E%'NAM>
>>;;END Y

	QRTSNM==SIXBIT/SIMRTS/	;Default high segment name
	IFE	<QHGH-1>,<QRTSNM=SIXBIT/SIMR22/>
	IFE	<QHGH-2>,<QRTSNM=SIXBIT/SIMR21/>
	;NOTE!!! THE OTHER name is needed to swap high segments!!!
>;;END IF1
	XALL
	RTSYMBOLS
	SALL
	SUBTTL	.OCSW - swap high segment

	IFG	<QNHGH-1>,<

	EXTERN	.JBREL,.JBHRL,.OCLA
	OPDEF	LEGAL	[PUSHJ XPDP,.OCLA]


Comment;

Purpose:	If the called routine is not in the present high segment,
		.OCSW is called to swap in the other high segment
		and transfer control to the corresponding entry.

Entry:		Called with a PUSHJ	XPDP,.OCSW from the
		transfer vector (or from itself on a return).

Function:	All ac's are saved in YUUOAC(XLOW).
		A GETSEG UUO changes high segment and returns to the
		proper place in the new high segment. Channel 0 must now be 
		restored since it was used by GETSEG and released.
		The proper entry in the current high segment is found
		via XPDP.
		If the call to the transfer vector was a PUSHJ,
		the ultimately called routine must first return to .OCSW
		to swap back the other high segment, then return to caller.
		.OCSW is called to effect this swap.
		Otherwise, if control was passed with a branch,
		the registers are restored and control is relinquished
		to the invoked routine.
;

	OPDEF	LINKBUFF	[PUSHJ XPDP,.OCIND]
	EXTERN	.OCIND

.OCSW::	PROC
	SAVEALLACS
	HRRZ	X1,-1(XPDP)	;Check next lower element in stack

	IF
		LEGAL
		GOTO	FALSE
	THEN
		STACK	-1(X1)	;Save what should be calling instr
	ELSE
		STACK	[0]
	FI
	LOWADR
	SETZ	X1,
	IF	;[63] Channel zero is active
		DEVCHR	X1,
		JUMPE	X1,FALSE
	THEN	;Save its status (with -1 in left half)
		GETSTS	X1
		HRROS	X1
	FI	;[63]
	STACK	X1	;[63] or zero
	L	X1,[QRTSNM]
	JSR	@YOCGS(XLOW)	;Get the other hiseg
	L	XPDP,YUUOAC+XPDP(XLOW)
	;Retrieve calling instr from stack top+1
	L	X10,1(XPDP)
	IF	;Channel 0 was active before swap
		L	X1,2(XPDP)	;[63] Old status or zero
		JUMPE	X1,FALSE
		L	X4,YOCBST(XLOW)
		JUMPE	X4,FALSE
	THEN	;Restore it,  OPEN UUO arg's in X1-X3
		HRRZS	X1	;[63] Clear left half of status word
		MOVSI	X2,'TTY'
		HRRI	X3,1(X4)	;Input buffer address
		HRLI	X3,52+1(X4)	;Output buffer address
		OPEN	0,X1
		HALT
		LI	X6,23		;Buffer length
		LI	X7,2		;Number of buffers
		HRRI	X1,-1(X3)	;Input buffer address
		LINKBUFF
		HLRZ	X1,X3
		HRRI	X1,-1(X1)	;Output buffer address
		LINKBUFF
	FI

	UNSTK	X1		;Find address of called entry (in transfer
				;vector or L6)
	SUBI	X1,1
	HRLI	X1,(PUSHJ XPDP,);X1 has expected instruction
	HRRZ	X1	;[41] Destination address
	IF	;This was the instruction
		CAMN	X10,X1	;[41]
		GOTO	TRUE
		CAIE	OCUU	;[41] or OCUU or OCTR was entered
		CAIN	OCTR
		GOTO	TRUE
		GOTO	FALSE
	THEN	;Prepare return to a new swap
		STACK	[L6()]
	FI
	STACK			;[41] Put destination on stack
	MOVSI	X16,YUUOAC(XLOW);Restore ac's
	BLT	X16,X16
	RETURN

	IFE <QHGH-1>,<
L6():!	EXEC	.OCSW
	POPJ	XPDP,
>
	IFE <QHGH-2>,<
	POPJ	XPDP,
L6():!	EXEC	.OCSW
>
	EPROC
>;;END IFG


	ERRMAC(OC)
.PDERR::OCERR	1,Pushdown list underflow
	EXIT	1,

	END