Google
 

Trailing-Edge - PDP-10 Archives - BB-J724A-SM_1980 - sources/msghdl.p11
There are 8 other files named msghdl.p11 in the archive. Click here to see a list.
.SBTTL	MESSAGE HANDLING
;
; SUBROUTINES IN THIS SECTION MANIPULATE MESSAGES.  THERE IS
;  A SUBROUTINE TO GET A CHARACTER FROM A MESSAGE, THREE FOR
;  TERMINATING THE GET PROCESS, ONE TO APPEND A CHARACTER
;  TO A MESSAGE AND ONE TO TERMINATE THE APPEND PROCESS.
;
.REPT 0


                          COPYRIGHT (c) 1980, 1979
            DIGITAL EQUIPMENT CORPORATION, maynard, mass.

THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
ONLY  IN  ACCORDANCE  WITH  THE  TERMS  OF  SUCH  LICENSE AND WITH THE
INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE OR  ANY  OTHER
COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
TRANSFERRED.

THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE  WITHOUT  NOTICE
AND  SHOULD  NOT  BE  CONSTRUED  AS  A COMMITMENT BY DIGITAL EQUIPMENT
CORPORATION.

DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR  RELIABILITY  OF  ITS
SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.

.ENDR
;
;
; SUBROUTINE TO GET A CHARACTER FROM THE INPUT STREAM.
;
;	TCTIM(R5) HAS NUMBER OF JIFFIES TO WAIT FOR RECEIVER
;	R3 = CHARS GOTTEN FROM THIS CHUNK ALREADY
;	R4 = POINTER TO CURRENT CHUNK (INITIALLY 0)
;	R5 = POINTER TO TCB
;
; ON RETURN: 
;
;	R1 = NEXT CHAR, C IS CLEAR; OR, C IS SET IF NO MORE DATA.
;
MSGGTC:	MOV	R0,-(SP)	;SAVE R0
11$:	MOV	#EBQCHK!EBINTR!EBTIME!EBWAIT,(R5) ;WAIT CONDITIONS
	TST	R4		;IS THERE A CHUNK?
	BNE	12$		;YES, GET A CHAR FROM IT.
	BIT	#LS.XGO!LS.XRN,@TCLCB(R5) ;TRANSMITTER STILL GOING?
	BNE	16$		;YES, WAIT FOR RECEIVER
	JSR	PC,DEQCHK	;NO, TRY TO GET A CHUNK FROM RECEIVER
	BCS	14$		;THERE IS NONE.
	MOV	R0,R4		;THERE IS ONE, PUT POINTER IN R4
	CLR	R3		;WE HAVE TAKEN NOTHING FROM IT YET
12$:	CMP	R3,CHLEN(R4)	;HAVE WE EMPTIED THE CHUNK?
	BNE	17$		;NO, GET ITS NEXT CHARACTER
13$:	BIT	#LS.RRN!LS.RGO,@TCLCB(R5) ;IS RECEIVER RUNNING?
	BNE	15$		;YES.
	MOV	R4,R0		;NO, PUT CHUNK IN R0
	MOV	TCIDLE,R1	;GET POINTER TO IDLE TASK
	JSR	PC,QUECHK	;SEND IT THE CHUNK TO FREE
	CLR	R4		;NO CURRENT CHUNK
	BR	11$		;SEE IF ANY MORE CHUNKS
;
; HERE TO GIVE ERROR RETURN.  THERE ARE NO MORE CHUNKS QUEUED
;  AND EITHER THE RECEIVER HAS STOPPED OR TIME IS UP OR
;  THERE HAS BEEN AN ERROR.
;
14$:	MOV	(SP)+,R0	;RESTORE R0
	SEC			;SIGNAL ERROR
	RTS	PC		; AND RETURN.
;
;
; HERE WHEN THE RECEIVER IS RUNNING BUT WE HAVE PROCESSED ALL
;  OF THE CHARACTERS IT HAS STORED IN THE CURRENT CHUNK.
;  IF WE HAVE MORE WAIT TIME, CONSIDER PROCESSING MORE CHARACTERS.
;
15$:	TST	TCTIM(R5)	;ANY WAITING TIME LEFT?
	BEQ	14$		;NO, WE HAVE WAITED TOO LONG
;
; HERE WHEN WE APPEAR TO HAVE PROCESSED ALL OF THE DQ11 CHARACTERS.
;  HOWEVER, THE DQ11 MAY HAVE STORED SOME CHARACTERS SINCE IT
;  LAST INTERRUPTED.  IF IT HAS, PROCESS THEM.  IF NOT, WAIT.
;
	JSR	PC,DQINWQ	;ANY CHARACTERS HIDDEN IN THE DQ11?
	BCS	11$		;IF THERE WERE, GO PROCESS THEM.
;
; HERE IF THE DQ11 HAS STORED NO MORE CHARACTERS SINCE
;  THE LAST ONE WE HAVE PROCESSED.  WE ARE ENABLED FOR SPECIAL
;  CHARACTER INTERRUPTS SO WE SHOULD BE AWAKENED AS SOON AS
;  THERE IS ANYTHING INTERESTING TO PROCESS.
; ALSO COME HERE IF THE TRANSMITTER IS RUNNING.  THE PRESUMPTION
;  IS THAT COMPLETION OF THE TRANSMISSION WILL START THE RECEIVER.
;  IF THIS IS FALSE (A TRANSMITTER ERROR) WE WILL CATCH IT BY
;  NOTICING THAT THE DQ11 GOES IDLE WITHOUT RETURNING ANY
;  CHARACTERS.
;
16$:	MOV	R4,-(SP)	;SAVE R4
	MOV	R3,-(SP)	; AND R3
	MOV	R2,-(SP)	;SAVE R2
	MOV	R1,-(SP)	; AND R1
	KGSAVE	-(SP)		;SAVE STATE OF BCC ACCUMULATION
	JSR	PC,WAIT		;WAIT FOR RECEIVE EVENT OR TIME UP
	MOV	TCLCB(R5),R4	;POINT R4 TO LCB
	KGLOAD	(SP)+		;RESTORE STATE OF BCC ACCUMULATION
	MOV	(SP)+,R1	;RESTORE R1
	MOV	(SP)+,R2	; AND R2
	MOV	(SP)+,R3	; AND R3
	MOV	(SP)+,R4	; AND R4
	BR	11$		;TRY AGAIN.
;
;
; HERE WHEN THE CURRENT CHUNK HAS AT LEAST ONE UNPROCESSED CHARACTER
;
17$:	MOV	R3,R0		;GET CURRENT COUNT
	ADD	R4,R0		;ADD CHUNK BASE ADDRESS
	MOVB	CHDAT(R0),R1	;GET NEXT CHARACTER FROM CHUNK
	INC	R3		;INCREMENT COUNT OF CHARS
	CMP	#CHDATL,R3	;HAVE WE GOTTEN THEM ALL?
	BNE	18$		;NO, RETURN TO USER.
;
; COME HERE WHEN WE HAVE GOTTEN THE LAST CHARACTER FROM THE
;  CURRENT CHUNK.
;
	MOV	R1,-(SP)	;SAVE THE CHARACTER
	MOV	R4,R0		;PUT CHUNK POINTER IN R0
	MOV	TCIDLE,R1	;POINT TO IDLE TASK
	JSR	PC,QUECHK	;SEND CHUNK TO BACKGROUND TASK 
				; (WHO WILL RETURN IT TO THE FREE LIST)
	MOV	(SP)+,R1	;RESTORE CHARACTER
	CLR	R4		;NOTE NO CURRENT CHUNK
18$:	MOV	(SP)+,R0	;RESTORE R0
	TRACE	TRCDQD,R1	;TRACE A CHARACTER READ
.IF NE,DEBUG
	KGSAVE	-(SP)		;GET CURRENT BCC
	TRACE	TRCBCC,(SP)	;TRACE CURRENT BCC
	TST	(SP)+		;DELETE FROM STACK
.ENDC ;.IF NE,DEBUG
	CLC			;SIGNAL SUCCESS
	RTS	PC		;RETURN.
;
;
; SUBROUTINE TO CLEAR OUT THE RECEIVER.  CALLED WHEN THE END
;  OF A MESSAGE IS RECOGNIZED.
;
; CALLED WITH R5 POINTING TO TCB.  DESTROYS R1 AND R4.
;
MSGGTE:	MOV	R3,-(SP)	;SAVE R3
	MOV	R0,-(SP)	;SAVE R0
	MOV	R4,-(SP)	;SAVE R4
	KGSAVE	-(SP)		;SAVE BCC ACCUMULATION [2(747)]
	MOV	TCLCB(R5),R4	;POINT R4 TO LCB
	JSR	PC,DQKILL	;STOP ALL DQ11 OPERATIONS
	KGLOAD	(SP)+		;RESTORE BCC ACCUMULATION [2(747)]
	MOV	(SP)+,R4	;RESTORE R4
	MOV	R4,R0		;IS THERE A CHUNK?
	BEQ	11$		;NO.
	MOV	TCIDLE,R1	;YES, SEND IT TO IDLE TASK
	JSR	PC,QUECHK	; TO BE FREED.
11$:	MOV	(SP)+,R0	;RESTORE R0
	MOV	(SP)+,R3	;RESTORE R3
.IF NE,DEBUG
	TST	TCCHK1(R5)	;ANY CHUNKS QUEUED?
	BEQ	12$		;NO, THAT'S GOOD.
	STOPCD	DBG		;YES, MSGGTE DIDNT CLEAN THINGS OUT
12$:	MOV	TCLCB(R5),R4	;POINT TO LCB
	TST	LB.CCH(R4)	;IS THERE A CURRENT CHUNK?
	BEQ	13$		;NO, THAT'S GOOD.
	STOPCD	DBG		;YES, SHOULDN'T BE.
13$:
.ENDC ;.IF NE,DEBUG
	RTS	PC		;RETURN WHEN ALL GOTTEN.
;
;
; SUBROUTINE TO CLEAR OUT THE RECEIVER AND WAIT THE REMAINDER
;  OF THE TIMEOUT INTERVAL, IF ANY.  CALLED WHEN A MESSAGE IS
;  DEEMED UNRECOGNIZABLE OR WHEN AN ERROR IS FOUND PART WAY
;  THROUGH A MESSAGE.
;
; DESTROYS ALL BUT R0
;
MSGGTT:	JSR	PC,MSGGTE	;CLEAR OUT RECEIVER
	TST	TCTIM(R5)	;ANY TIMEOUT INTERVAL LEFT?
	BEQ	11$		;NO.
	MOV	#EBWAIT!EBTIME,(R5) ;YES, WAIT FOR IT
	MOV	R0,-(SP)	;SAVE R0
	JSR	PC,WAIT
	MOV	(SP)+,R0	;RESTORE R0
11$:	RTS	PC		;RETURN.
;
; SUBROUTINE TO TERMINATE READING AND WAIT FOR THE
;  TWO-SECOND TIMEOUT TO BE UP.  SOME WAITING MAY HAVE ALREADY
;  BEEN DONE.   CALLED BY RECEIVER BECAUSE THE
;  RECEIVER'S DATA TIMEOUT INTERVAL HAS TO BE LONGER THAN 2 SECONDS
;  IN ORDER TO BE SURE WE CAN READ A MAX-LENGTH
;  MESSAGE AT LOWEST SPEED.
;
MSGGT2:	SUB	#<<600./150.>*JIFSEC>+1,TCTIM(R5) ;COMPUTE TIME WAITED ALREADY
				; (THIS EXPRESSION ALSO USED AT DQRCVB)
	ADD	#JIFSEC*2,TCTIM(R5) ;COMPUTE REST OF 2 SECONDS
	BGT	11$		;MORE THAN 0 TICKS LEFT
	CLR	TCTIM(R5)	;NO TIME LEFT.
11$:	JSR	PC,MSGGTT	;TERMINATE READING AND WAIT
	RTS	PC		;RETURN.
;
;
; SUBROUTINE TO APPEND A CHARACTER TO A MESSAGE.
;
;  R0 = POINTER TO THE FIRST CHUNK OF THE MESSAGE
;  R1 = THE CHARACTER TO APPEND
;  R5 = POINTER TO THIS TASK'S TCB
;
;  ON RETURN, C = 0 IS OK, C = 1 MEANS OUT OF CHUNKS.
;
MSGAPC:	TST	MSGCNT(R0)	;ANY ROOM LEFT IN LAST CHUNK?
	BEQ	11$		;NO, GET ANOTHER.
	DEC	MSGCNT(R0)	;YES, ONE LESS BYTE LEFT
	MOVB	R1,@MSGPTR(R0)	;STORE CHARACTER IN CHUNK
	INC	MSGPTR(R0)	;POINT TO NEXT POSITION
	INC	@MSGCLP(R0)	;INCREMENT COUNT IN LAST CHUNK
	INC	MSGLEN(R0)	;COUNT ONE MORE CHAR IN MESSAGE
	TRACE	TRCDQD,R1	;TRACE CHARACTER WRITTEN
.IF NE,DEBUG
	KGSAVE	-(SP)		;GET CURRENT BCC
	TRACE	TRCBCC,(SP)	;TRACE CURRENT BCC
	TST	(SP)+		;DELETE FROM STACK
.ENDC ;.IF NE,DEBUG
	CLC			;INDICATE ALL OK
	RTS	PC		;AND RETURN.
;
;
; HERE IF THE LAST CHUNK HAS RUN OUT.
;
11$:	MOV	R2,-(SP)	;SAVE R2
	MOV	R3,-(SP)	;SAVE R3
	MOV	R1,-(SP)	;SAVE R1
	MOV	R0,-(SP)	;SAVE R0
	MOV	@MSGLCH(R0),R0	;ANY PRE-ALLOCATED CHUNKS?
	BNE	13$		;YES, USE THEM.
12$:	MOV	CHLST,R0	;NO, GET POINTER TO LAST FREE CHUNK
	JSR	PC,GETCHK	;TRY TO GET IT OFF LIST
	BCS	14$		;BRANCH IF UNABLE TO GET IT
13$:	MOV	(SP)+,R1	;POINT R1 TO MESSAGE
	MOV	R0,@MSGLCH(R1)	;APPEND CHUNK TO LIST OF CHUNKS
	MOV	R0,MSGLCH(R1)	;NEW CHUNK IS LAST CHUNK
	ADD	#CHLEN,R0	;POINT TO COUNT FIELD IN CHUNK
	MOV	R0,MSGCLP(R1)	;STORE POINTER TO COUNT FIELD
	ADD	#CHDAT-CHLEN,R0	;POINT TO DATA PART OF CHUNK
	MOV	R0,MSGPTR(R1)	;POINT TO FRONT OF CHUNK
	MOV	R1,R0		;PUT MESSAGE POINTER IN R0
	MOV	#CHDATL,MSGCNT(R0) ;MARK NEW CHUNK EMPTY
	MOV	(SP)+,R1	;RESTORE CHARACTER TO STORE
	MOV	(SP)+,R3	;RESTORE R3
	MOV	(SP)+,R2	;RESTORE R2
	BR	MSGAPC		;TRY AGAIN TO STORE IT
;
; HERE IF WE RUN OUT OF CHUNKS.  GIVE ERROR RETURN.
;
14$:	MOV	(SP)+,R0	;RESTORE R0
	MOV	(SP)+,R1	;RESTORE R1
	MOV	(SP)+,R3	;RESTORE R3
	MOV	(SP)+,R2	;RESTORE R2
	SEC			;FLAG FAILURE
	RTS	PC		;RETURN.
;
;
; SUBROUTINE TO RETURN THE UNUSED PRE-ALLOCATED CHUNKS
;  AT THE END OF A MESSAGE.
;
; R0 = POINTER TO THE FIRST CHUNK OF THE MESSAGE
;
MSGAPE:	MOV	@MSGLCH(R0),R1	;ANY UNUSED PRE-ALLOACTED CHUNKS?
	BEQ	11$		;NO.
	MOV	R0,-(SP)	;YES, SAVE POINTER TO MESSAGE
	CLR	@MSGLCH(R0)	;REMOVE POINTER TO UNUSED CHUNKS
	MOV	R1,R0		;PUT POINTER TO UNUSED CHUNKS IN R0
	MOV	TCIDLE,R1	;POINT TO BACKGROUND TASK
	JSR	PC,QUEMSG	;SEND IT THE UNUSED CHUNKS TO FREE
	MOV	(SP)+,R0	;RESTORE POINTER TO MESSAGE
11$:	RTS	PC		;RETURN.
;