Google
 

Trailing-Edge - PDP-10 Archives - BB-H348C-RM_1982 - swskit-v21/debugging-tools/dts/dtsdat.mac
There are no other files named dtsdat.mac in the archive.


;THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED
;  OR COPIED IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE.
;
;COPYRIGHT (C) 1978 BY DIGITAL EQUIPMENT CORPORATION
;
	TITLE DTSDAT - DTS DATA TEST EXECUTION MODULE

	SEARCH DTSUNV,MACSYM,MONSYM
	SALL
	LIST

	ENTRY DTSDAT

	PRINT==200
	INTVLM==^D100		;FREQUENCY TO PRINT INTERVAL MESSAGE
	MSGSIZ==1000		;READ BUFFER SIZE
	WAITV==5		;WAIT VALUE FOR ECHO

	PAGE
	SUBTTL DTSDAT - DTS DATA TEST 

;+
;DTSDAT - THIS ROUTINE PERFORMS THE DTS DATA TEST TO A DTR SERVER ON
; ANOTHER NODE IN THE NETWORK. THE ROUTINE IS CALLED BY THE DTS DRIVER
; AFTER THE CONNECT INTERRUPT HAS OCCURED AND THE LINK HAS A ZERO
; REASON CODE. THE CONNECT INTERRUPT COULD HAVE BEEN THE RESULT OF THE
; MONITOR RECEIVING EITHER AN NSP DATA CONFIRM OR DISCONNECT INITIATE.
;
;ACCEPTS:	T1/ ADDRESS OF ARGUMENT BLOCK
;		LCBPTR/ ADDRESS OF LCB
;
;	ARGUMENT BLOCK/ (.DTTIM) ELAPSED TIME TO RUN TEST
;			(.DTBUF) NUMBER OF SEND BUFFERS TO USE
;			(.DTBAU) BAUD RATE
;			(.DTNOD) POINTER TO NODE NAME
;			(.DTCNT) OPTIONAL DATA BYTE COUNT
;			(.DTTYP) TEST TYPE + PRINT OPTION
;			(.DTSUB) TEST SUBTYPE
;			(.DTFCO) FLOW CONTROL OPTION
;			(.DTFCV) FLOW CONTROL VALUE
;			(.DTNAK) NAK VALUE
;			(.DTBPV) BACK-PRESSURE VALUE
;			(.DTMSG) MESSAGE LENGTH BYTE # 0
;				 MESSAGE LENGTH BYTE # 1
;				 USER DATA
;
;CALLED BY: CALL DTSDAT
;
;RETURNS+1: SUCCESS
;	+2: FAILURE
;-



DTSDAT:				;ENTRY
	TRVAR <ARGPTR>		;STORAGE FOR VARIABLES
	MOVEM T1,ARGPTR		;SAVE ADDRESS OF ARGUMENT BLOCK
	CALL DTSPRT		;PRINT MESSAGE

;RESET TIME EXPIRED FLAG

	SETZM TIMEUP		;ZERO FOR TEST TO CONTINUE
	SETZM EKERRF		;CLEAR ECHO ERROR FLAG

	CALL GTMSGL
	STOR T1,LCBMSZ		;STORE MAX MESSAGE LENGTH

;MAKE SURE WE GOT CONNECTED
; SEE THE NOTE IN THE MAINLINE DRIVER SOURCE CODE RELATIVE TO
; THE VERACITY OF WHETHER THE LINK WAS ACCPETED BY DTR

	LOAD T1,LCBSTS		;GET LINK STATUS
	TXZN T1,MO%LWC		;WAS LINK CONNECTED ?
	PRTERR <LINK NEVER CONNECTED>,,<$GOTO(DATABT)> ;NO....
				; THEN ASSUME NOT ACCEPTED BY DTR

;PRINT SEGMENT SIZE FOR THIS LINK

	CALL RSSLNK
	RETBAD LNKERR
	PRTINF <SEGMENT SIZE - >
	HRROI T1,RDBUF
	LOAD T2,LCBSGS
	MOVEI T3,^D10
	NOUT
	 JSCONT
	HRROI T1,RDBUF
	CALL SNDSTR

;SET UP TO GET INTERRUPT WHEN TEST TIME EXPIRES

	MOVE T1,ARGPTR		;GET POINTER TO ARGUMENT BLOCK
	MOVE T2,.DTTIM(T1)	;GET LENGTH OF TIME TO RUN TEST
	IMULI T2,^D1000		;MAKE IT MILLISECONDS
	LDB T3,[POINT 9,IHBLK+4,8] ;GET CHANNEL NUMBER
	MOVE T1,[.FHSLF,,.TIMEL] ;THIS PROCESS / ELAPSED TIME
	TIMER
	 JSRET 

;STORE DISPATCH ADDRESSES IN LCB

	$PIOFF			;TURN OFF PI WHILE CHANGING DISPATCH ADDRS
	MOVEI T1,TIMEXP		;GET ADDRESS OF ROUTINE TO END TEST
	STOR T1,LCBTID		;STORE TIMER DISPATCH ADDRESS IN LCB
	MOVEI T1,READST		;GET ADDRESS OF ROUTINE TO READ STATUS
	STOR T1,LCBDID		;STORE DATA DISPATCH ADDRESS IN LCB
	$PION

;INITIALIZE LCB FIELDS

	MOVE T3,STDPAT		;GET STRING POINTER TO STANDARD DATA PATTERN
	STOR T3,LCBSMB		;STORE IT IN LCB
	SETZRO LCBSND		;SET MESSAGE SEND COUNT TO ZERO
	SETZRO LCBSBC		;CLEAR SEND BYTE COUNT
	SETZRO LCBRBC		;DITTO RECEIVE COUNTS
	SETZRO LCBRCV

; SAVE THE CURRENT CLOCK TIME FOR BAUD RATE CALCULATION

	TIME
	 JSCONT
	MOVEM T1,STIME		;SAVE TIME STARTED TESTING

	CALL PSTART		;PRINT START TIME
	MOVE T1,ARGPTR		;GET POINTER TO ARGUMENT BLOCK
	MOVE T2,.DTSUB(T1)	;GET DATATYPE

;DISPATCH BASED ON DATATYPE

	CALL @DATTBL(T2)	;DISPATCH TO SPECIFIC TEST TYPE
	RETBAD DATABT		;FAIL RETURN, ABORT LINK
	RETSKP			;SUCCESS RETURN

DATSYN:				;HERE TO DISCONNECT LINK
	SETZRO LCBABT		;SYNCH DISCONNECT
	SETZRO LCBRSN		;REASON CODE ZERO
	SETZRO LCBSOC		;SEND NO OPTIONAL DATA
	CALL REJLNK		;DISCONNECT LINK WITH REASON = 0
	RETBAD LNKERR		;FAILED, TELL WHY..
	SETZRO LCBRJF		;RELEASE JFN
	CALL CLZLNK		;NOW CLOSE IT
	RETBAD ERXLNK
	RET


DATABT:				;HERE TO ABORT LINK & CLOSE JFN
	SETONE LCBABT		;ABORT LINK
	SETZRO LCBRJF		;RELEASE JFN
	CALL CLZLNK		;NOW CLOSE IT
	RETBAD ERXLNK
	RET

DATTBL:				;DATA TEST DISPATCH TABLE
	DATSNK			;DATATYPE=0 - DATA SINK TEST
	DATSEQ			;DATATYPE=1 - DATA SEQUENCE TEST
	DATPAT			;DATATYPE=2 - DATA PATTERN TEST
	DATECH			;DATATYPE=3 - DATA ECHO TEST

	PAGE
	SUBTTL DATSNK - DATA SINK TEST

;HERE TO PERFORM THE IDEAL DATA SINK TEST

DATSNK:				;ENTRY FROM DISPATCH TABLE
	STKVAR <MSGLN>		;STORAGE FOR MESSAGE LENGTH
	CALL GTMSGL		;GO GET MESSAGE LENGTH
	MOVEM T1,MSGLN		;SAVE IT FOR USE IN LOOP

DATSN1:				;HERE TO SEND EACH MESSAGE
	LOAD T1,LCBSTS		;GET LINK STATUS
	TXNN T1,MO%CON		;CONNECTED NOW ?
	RET			;NO, RETURN BAD

	MOVE T1,MSGLN		;NO, RESTORE MESSAGE LENGTH
	CALL SNDMSG		;GO SEND MESSAGE
	RET			;RETURN IF ERROR ON SEND
	SKIPE TIMEUP		;TIME EXPIRED ?
	JRST DATDON		;YES, GO TO DONE ROUTINE
	JRST DATSN1		;KEEP GOING UNTIL TIME EXPIRES

	PAGE
	SUBTTL DATSEQ - DATA SEQUENCE TEST

;HERE TO PERFORM DATA SEQUENCE TEST

DATSEQ:				;ENTRY FROM DISPATCH 
	STKVAR <MSGLN>		;STORAGE FOR MESSAGE LENGTH
	CALL GTMSGL		;GO GET MESSAGE LENGTH
	MOVEM T1,MSGLN		;SAVE IT FOR USE IN LOOP

;TOP OF LOOP TO SEND EACH MESSAGE

DATSE1:
	LOAD T1,LCBSTS		;GET LINK STATUS
	TXNN T1,MO%CON		;CONNECTED NOW ?
	RET			;NO, RETURN BAD

	CALL SNDCNT		;GO SEND COUNT FIELD
	RET			;RETURN IF ERROR ON SEND
	MOVE T1,MSGLN		;RESTORE MESSAGE LENGTH
	SUBI T1,4		;LESS LENGTH OF COUNT FIELD
	CALL SNDMSG		;GO SEND MESSAGE
	RET			;RETURN IF ERROR ON SEND
	SKIPE TIMEUP		;TIME EXPIRED ?
	JRST DATDON		;YES, GO TO DONE ROUTINE
	JRST DATSE1		;NO, KEEP GOING

	PAGE
	SUBTTL DATPAT - DATA PATTERN TEST

;HERE TO PERFORM DATA PATTERN TEST

DATPAT:				;ENTRY
	STKVAR <MSGLN>		;STORAGE FOR MESSAGE LENGTH
	CALL GTMSGL		;GO GET MESSAGE LENGTH
	MOVEM T1,MSGLN		;SAVE IT FOR USE IN LOOP

;TOP OF LOOP TO SEND EACH MESSAGE

DATPA1:
	LOAD T1,LCBSTS		;GET LINK STATUS
	TXNN T1,MO%CON		;CONNECTED NOW ?
	RET			;NO, RETURN BAD

	CALL SNDCNT		;GO SEND COUNT FIELD
	RET			;RETURN IF ERROR ON SEND
	MOVE T1,MSGLN		;RESTORE MESSAGE LENGTH
	SUBI T1,4		;LESS LENGTH OF COUNT FIELD
	CALL SNDMSG		;GO SEND MESSAGE
	RET			;RETURN IF ERROR ON SEND
	SKIPE TIMEUP		;TIME EXPIRED ?
	JRST DATDON		;YES, GO TO DONE ROUTINE
	JRST DATPA1		;KEEP GOING

	PAGE
	SUBTTL DATECH - DATA ECHO TEST

;HERE TO PERFORM DATA ECHO TEST

DATECH:				;ENTRY
	STKVAR <MSGLN>		;STORAGE FOR MESSAGE LENGTH
	CALL GTMSGL		;GO GET MESSAGE LENGTH
	MOVEM T1,MSGLN		;SAVE IT FOR USE IN LOOP
	$PIOFF			;DON'T ALLOW INTERRUPTS
	MOVEI T1,READAT		;GET ADDRESS OF ROUTINE TO READ DATA
	STOR T1,LCBDID		;STORE DATA DISPATCH ADDRESS IN LCB
	$PION			;ALLOW INTERRUPTS

;TOP OF LOOP TO SEND EACH MESSAGE

DATEC1:
	LOAD T1,LCBSTS		;GET LINK STATUS
	TXNN T1,MO%CON		;CONNECTED NOW ?
	RET			;NO, RETURN BAD

	CALL SNDCNT		;GO SEND COUNT FIELD
	RET			;RETURN IF ERROR ON SEND
	MOVE T1,MSGLN		;RESTORE MESSAGE LENGTH
	SUBI T1,4		;LESS LENGTH OF COUNT FIELD
	CALL SNDMSG		;GO SEND MESSAGE
	RET			;RETURN IF ERROR ON SEND
	SKIPN TIMEUP		;TIME EXPIRED ?
	JRST DATEC1		;NO, KEEP GOING
	JRST DATEC2		;YES, SENT ALL WE'RE GOING TO

	PAGE
	SUBTTL DATECH - DATA ECHO TEST

;HERE WHEN ECHO TEST TIME EXPIRES, WAIT FOR RECEIVES TO COMPLETE
; AND PRINT THE RECEIVE COUNT

DATEC2:
	LOAD T2,LCBRCV		;GET RECEIVE COUNT
	OPSTR <CAMN T2,>,LCBSND	;EQUAL TO SEND COUNT ?
	JRST ECHDON		;YES, WE'RE THROUGH
	MOVEI T1,WAITV		;WAIT FOR A WHILE
	CALL SLEEP
	SKIPN TIMOUT		;DID WE TIME OUT ?
	JRST DATEC2		;NO, LOOP UNTIL RECEIVE ALL
	PRTERR <DATA TEST FAILED, ECHO TIMEOUT>,,<$RET>

ECHDON:
	CALL DATDON		;PRINT RESULTS OF SENDS
	JFCL			;IGNORE
	PRTINF <DATA MESSAGES RECEIVED = >
	HRROI T1,RDBUF
	LOAD T2,LCBRCV
	MOVX T3,^D10
	NOUT
	 JSCONT
	HRROI T1,RDBUF
	CALL SNDSTR
	RETSKP			;GOOD RETURN

	PAGE
	SUBTTL DATDON - DATA TEST DONE ROUTINE


DATDON:				;HERE TO PRINT RESULTS OF TEST IF GOOD
	TIME
	 JSCONT
	SUB T1,STIME		;ELAPSED TIME OF TEST
	MOVEM T1,ETIME		;SAVE IT
	CALL DATSYN		;GO ABORT THE LINK
	CALL PINTVL		;PRINT TOTAL MESSAGES SENT
	CALL PFINIS		;PRINT FINISH TIME
	CALL PETIME		;PRINT ELAPSED TIME
	LOAD T1,LCBSBC		;TOTAL BYTES SENT
	OPSTR <ADD T1,>,LCBRBC	; PLUS RECEIVED
	OPSTR <MUL T1,>,LCBBSZ	;TOTAL BITS SENT + RECEIVED
	CAIE T1,0		;ANY OVERFLOW ?
	PRTERR <OVERFLOW IN RATE CALCULATION>,,<$RET>
	MULI T2,^D1000		;BITS X 1000
	CAIE T2,0		;ANY OVERFLOW ?
	PRTERR <OVERFLOW IN RATE CALCULATION>,,<$RET>
	DIV T2,ETIME		;BITS PER SECOND
	MOVE P1,T2		;SAVE BPS
	PRTINF <BITS PER SECOND = >
	HRROI T1,RDBUF
	MOVE T2,P1		;RESTORE BPS
	MOVX T3,^D10
	NOUT
	 JSCONT
	HRROI T1,RDBUF
	CALL SNDSTR
	MOVE T1,ARGPTR
	SKIPN T2,.DTBAU(T1)	;GET BAUD RATE IF NOT ZERO
	RETSKP			;YES, DONE
	PRTINF <% LINE EFFICIENCY = >
	FLTR T1,P1		;GET BPS FLOATED
	MOVE T2,ARGPTR
	FLTR T2,.DTBAU(T2)	;GET BAUD RATE FLOATED
	FDV T1,T2		; BPS/BAUD
	FMP T1,[100.0]		; % EFFICIENCY
	FIXR T2,T1		;FIXED FORMAT ROUNDED
	HRROI T1,RDBUF
	MOVX T3,^D10
	NOUT
	 JSCONT
	HRROI T1,RDBUF
	CALL SNDSTR
	RETSKP			;RETURN GOOD

	PAGE
	SUBTTL GTMSGL - GET MESSAGE LENGTH FROM ARGUMENT BLOCK

;ACCEPTS: NOTHING
;
;RETURNS+1: ALWAYS, T1/ MESSAGE LENGTH

GTMSGL:				;ENTRY POINT
	MOVE T1,ARGPTR		;GET POINTER TO ARGUMENT BLOCK
	MOVE T2,.DTMSG+1(T1)	;GET BYTE 1
	LSH T2,^D8		;SHIFT IT TO BYTE 1 POSITION
	MOVE T1,.DTMSG(T1)	;GET MESSAGE LENGTH BYTE 0
	ADDI T1,(T2)		;MESSAGE LENGTH IN T1
	RET

	PAGE
	SUBTTL SNDCNT - SEND THE COUNT FIELD FOR DTR/DTS MESSAGE

;ACCEPTS: NOTHING
;
;RETURNS+1: ALWAYS

SNDCNT:				;ENTRY POINT

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
;CONVERT MESSAGE NUMBER TO 8 BIT FORMAT
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	MOVE T1,[POINT 8,COUNT] ;GET BYTE POINTER TO 4 DIGIT STRING
	LOAD T2,LCBSND		;GET CURRENT SEND COUNT
	ADDI T2,1		;BUMP COUNT
	MOVEI T3,4		;FOUR BYTES
	CALL DEP11		;CONVERT INTEGER TO STRING 
	MOVE T1,[POINT 8,COUNT] ;GET BYTE POINTER TO 4 DIGIT STRING
	STOR T1,LCBSMB		;STORE IN LCB

;	LOAD T3,LCBSTS		;GET CURRENT STATUS
	LOAD T3,LCBFLG		;GET FLAG WORD
	LOAD T2,LCBMSZ		;GET MSG SIZE
	CAIG T2,4		;IS SEQ # WHOLE MSG ?
;	TXOA T3,MO%EOM		;YES, SET END-OF-MESSAGE
	TXOA T3,LCB%SM		;YES, SET SEND MESSAGE FLAG
;	TXZ T3,MO%EOM		;NO, CLEAR END-OF-MESSAGE FLAG
	TXZ T3,LCB%SM		;NO, CLEAR SEND MESSAGE FLAG
;	STOR T3,LCBSTS		;STORE IT BACK
	STOR T3,LCBFLG		;STORE BACK FLAG WORD
	MOVEI T3,4		;WANT TO SEND 4 BYTE COUNT
	STOR T3,LCBCSZ		;STORE IT IN LCB
	CALL SNDLNK		;SEND COUNT ON LINK
	RETBAD LNKERR
	RETSKP			;RETURN

	PAGE
	SUBTTL DEP11 - DEPOSIT INTEGER INTO STRING IN PDP-11 FORMAT

;DEP11 - CREATES A STRING OF 8 BIT BYTES WITH LEAST SIGNIFICANT BYTE
;	IN BYTE POSITION ZERO

;ACCEPTS:	T1/ 8 BIT STRING POINTER
;		T2/ INTEGER TO CONVERT
;		T3/ BYTE COUNT

DEP11:				;ENTRY POINT
	IDPB T2,T1		;DEPOSIT BYTE IN STRING
	LSH T2,-8		;SHIFT TO NEXT BYTE
	SOJG T3,DEP11		;KEEP GOING UNTIL COUNT IS EXHAUSTED
	RET			;DONE

	PAGE
	SUBTTL SNDMSG - SEND A DTS MESSAGE PATTERN

;ACCEPTS: T1/ MESSAGE LENGTH

SNDMSG:				;ENTRY POINT
	STKVAR <REMCNT>
	MOVEM T1,REMCNT
	CAIGE T1,0		;NEGATIVE ?
	PRTERR <SNDMSG CALLED WITH NEGATIVE MESSAGE LENGTH>,,<$RET>
	CAIG T1,0		;GREATER THAN ZERO ?
	RETSKP			;GOOD RETURN FOR ZERO LENGTH CASE
	MOVE T1,STDPAT		;POINTER TO STANDARD PATTERN
	STOR T1,LCBSMB		;STORE IT IN LCB

SNDMS0:				;TOP OF LOOP FOR EACH 36 CHARACTERS OF MESSAGE
	SKIPG REMCNT		;ANYTHING LEFT TO SEND ?
	JRST SNDMS3		;NO, RETURN
	MOVE T3,REMCNT		;GET CURRENT REMAINING COUNT
	CAILE T3,^D36		;LESS OR EQUAL TO STANDARD PATTERN LENGTH ?
	JRST SNDMS1		;NO, 

;HERE TO SEND REMAINDER OF MESSAGE

	SUBM T3,REMCNT		;DECREMENT TO ZERO
	STOR T3,LCBCSZ		;STORE REMAINDER OF MESSAGE LENGTH
;	LOAD T2,LCBSTS		;GET STATUS
;	TXO T2,MO%EOM		;SET END-OF-MESSAGE FLAG IN LINK STATUS
;	STOR T2,LCBSTS
	SETONE LCBSLM		;TURN ON SEND MESSAGE FLAG
	JRST SNDMS2

SNDMS1:				;HERE TO SEND STANDARD PATTERN
	SUBI T3,^D36		;DECREMENT BY LENGTH OF STD PAT
	MOVEM T3,REMCNT
	MOVEI T2,^D36
	STOR T2,LCBCSZ		;STORE STD PAT LENGTH IN LCB
;	LOAD T2,LCBSTS		;GET STATUS
;	TXZ T2,MO%EOM		;CLEAR END-OF-MESSAGE FLAG IN LINK STATUS
;	STOR T2,LCBSTS
	SETZRO LCBSLM		;CLEAR SEND MESSAGE FLAG

SNDMS2:				;HERE TO SEND EITHER PART OR ALL OF MESSAGE
	CALL SNDLNK
	RETBAD LNKERR
	JRST SNDMS0		;GO SEND REST OF MESSAGE

SNDMS3:				;HERE WHEN MESSAGE SENT
	LOAD T1,LCBSND		;GET COUNT OF DATA MSG SENT
	IDIVI T1,INTVLM		;GET COUNT MOD INTERVAL
	CAIN T2,0		;PRINT A MESSAGE ?
	CALL PINTVL		;YES, TELL HOW MANY WE'VE SENT
	RETSKP			;DONE, RETURN

	PAGE
	SUBTTL PINTVL - PRINT INTERVAL SENT MESSAGE

;HERE TO PRINT MESSAGE AT INTERVAL OF MESSAGES

PINTVL:				;ENTRY
	PRTINF <DATA MESSAGES SENT = >
	HRROI T1,RDBUF		;USE THE DATA BUFFER
	LOAD T2,LCBSND		;GET NUMBER WE SENT
	MOVX T3,^D10		;IN DECIMAL
	NOUT
	 JSCONT
	HRROI T1,RDBUF
	CALL SNDSTR
	RET

	PAGE
	SUBTTL PSTART - PRINT START TEST MESSAGE AND TIME

PSTART:				;HERE TO PRINT MESSAGE TELLING TIME OF START
	PRTINF <TEST STARTED AT -- >
	HRROI T1,RDBUF		;USE SPARE BUFFER
	SETOI T2,		;CURRENT TIME
	SETZI T3,		;DEFAULT FORMAT DATE/TIME
	ODTIM
	 JSCONT
	HRROI T1,RDBUF
	CALL SNDSTR
	RET

	PAGE
	SUBTTL PFINIS - PRINT FINISH MESSAGE

PFINIS:				;HERE TO PRINT FINISH TIME
	PRTINF <TEST FINISHED AT -- >
	HRROI T1,RDBUF		;USE SPARE BUFFER
	SETOI T2,		;CURRENT TIME
	SETZI T3,		;DEFAULT FORMAT DATE/TIME
	ODTIM
	 JSCONT
	HRROI T1,RDBUF
	CALL SNDSTR
	RET

	PAGE
	SUBTTL PETIME - PRINT ELAPSED TIME

PETIME:				;HERE TO PRINT ELAPSED TIME
	PRTINF <ELAPSED TIME IN MILLISECONDS - >
	HRROI T1,RDBUF
	MOVE T2,ETIME
	MOVEI T3,^D10
	NOUT
	 JSCONT
	HRROI T1,RDBUF
	CALL SNDSTR
	RET

	PAGE
	SUBTTL TIMEXP - TIME EXPIRATION ROUTINE

;TIMEXP - INTERRUPT LEVEL ROUTINE TO HANDLE ELAPSED TIME INTERRUPT
;	WHICH SIGNIFIES THE TEST HAS COMPLETED

TIMEXP:				;ENTRY FROM IHTIME

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
; JUST SET A FLAG TO INDICATE TIME IS UP
; CLEAR OUT THE DISPATCH ADDRESS IN LCB
; THEN RETURN
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	SETOM TIMEUP		;SET FLAG TO SAY TIME EXPIRED
	SETZRO LCBTID		;CLEAR OUT TIME INTERRUPT DISPATCH ADDRESS
	RET

	PAGE
	SUBTTL READAT - READ DATA ROUTINE

;READAT - INTERRUPT LEVEL ROUTINE TO HANDLE DATA AVAILABLE INTERRUPTS
;	FOR DATA TESTS
;	IF DATA IS AVAILABLE IT READS IT
;	IF DOING AN ECHO TEST IT VERIFIES PATTERN AND SEQUENCE
;	IF INTERRUPT IS FOR ABORT OR DISCONNECT IT PRINTS A MESSAGE
;	AND SETS A FLAG TO SAY LINK WAS CLOSED

READAT:				;NO, CHECK NEXT LCB
	STKVAR <PATCNT,SAVCSZ>	;STACK VARIABLES
	CALL RLSLNK		;READ LINK STATUS
	RETBAD ERXLNK		;FAILED
	LOAD T1,LCBSTS		;GET STATUS
	TXNN T1,MO%CON		;CONNECTED ?
	JRST DATERR		;NO, GO SAY DATA ERROR
	LOAD T1,LCBJFN		;GET JFN FOR THIS LINK
	SIBE			;ANY DATA RECEIVED ?
	JRST READA1		;YES, BUFFER NOT EMPTY, GO READ
	RET			;NO, RETURN WHEN NO MORE BYTES AVAILABLE

	PAGE
	SUBTTL READAT - READ DATA ROUTINE

;READ DATA RECEIVED ON LINK
; T2 HAS NUMBER OF BYTES AVAILABLE

READA1:				;HERE WHEN DATA IN BUFFER FOR A LINK
	LOAD T3,LCBCSZ		;GET CURRENT MSG SIZE FROM LCB
	MOVEM T3,SAVCSZ		;SAVE IT IN TEMPORARY
	STOR   (T2,LCBCSZ)	;STORE NUMBER OF BYTES AVAILABLE

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

;HACK FOR NOW, THIS CODE WILL BLOCK UNTIL ENTIRE MESSAGE IS READY

	SETZM RDBUF		;ZERO THE READ BUFFER
	MOVE T1,[RDBUF,,RDBUF+1]
	BLT T1,RDBUF+MSGSIZ-1

;	LOAD T1,LCBSTS
;	TXO T1,MO%EOM		;TURN ON EOM FLAG, WANT TO DO SINR
;	STOR T1,LCBSTS
	SETONE LCBRLM		;TURN ON RECEIVE MESSAGE FLAG
	CALL GTMSGL		;GET MESSAGE LENGTH WE SENT
	STOR T1,LCBCSZ		;CURRENT SIZE TO READ


;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
;GET MESSAGE SIZE FROM ARGUMENT BLOCK
; MAKE SURE WE DON'T HAVE MORE AVAILABLE THAN THIS
; MAKE SURE IF AVAILABLE = MSG SIZE THAT MO%EOM IS ON
;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	MOVE T2,[POINT 8,RDBUF]	;GET POINTER TO INPUT BUFFER
	STOR   T2,LCBRMB	;STORE BYTE POINTER FOR RECEIVE BUFFER IN LCB
	CALL   RCVLNK		;GO RECEIVE ON LINK
	RETBAD LNKERR		;FAILED, PRINT LINK ERROR, RETURN BAD
	MOVE T1,SAVCSZ		;RESTORE OLD VALUE OF LCBCSZ
	STOR T1,LCBCSZ

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
;HERE IF DOING ECHO TEST TYPE VERIFY SEQUENCE NUMBER AND PATTERN

	LOAD   T1,LCBRMB	;GET POINTER TO RECEIVED MESSAGE
	MOVEI  T2,4		;GET A 4 BYTE -11 INTEGER
	CALL   LOAD11		;GO GET IT
	LOAD   T3,LCBRCV	;GET CURRENT RECEIVE COUNT
	CAME   T2,T3		;DO THEY AGREE ??
	PRTERR (<SEQUENCE ERROR ENCOUNTERED>,,<$GOTO(ECHERR)>) ;YES.... ABORT
				;.... T1 HAS POINTER TO MESSAGE
;%%%%%%%% MOVED TO READAT
;	STKVAR <PATCNT>		;VARIABLE TO HOLD COUNT OF BYTES TO CHECK
	LOAD   T3,LCBMSZ	;GET LENGTH OF MESSAGE WE SENT
	SUBI   T3,4		;LESS THE LENGTH OF THE SEQ NUMBER
	CAILE T3,0		;ZERO LENGTH PATTERN ?
	JRST READAT		;YES, GO READ SOME MORE
DTRPT1:				;HERE TO CHECK EACH PATTERN OCCURENCE
	MOVE   T2,STDPAT	;GET POINTER TO STANDARD PATTERN
	MOVEM  T3,PATCNT	;SAVE THE COUNT
	CAILE  T3,^D36		;MORE THAN THE STANDARD PATTERN ?
	MOVEI  T3,^D36		;YES, COMPARE FOR LENGTH OF STANDARD PATTERN
	CALL   STRCMP		;GO COMPARE THE STRINGS
	PRTERR (<PATTERN ERROR ENCOUNTERED>,,<$GOTO(ECHERR)>) ;UNEQUAL, GO ABORT
	MOVE   T3,PATCNT	;EQUAL COMPARE, RESTORE THE COUNT
	SUBI   T3,^D36		;DECREMENT BY LENGTH OF STANDARD PATTERN
	JUMPG  T3,DTRPT1	;IF MORE TO COMPARE GO DO IT

;
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	JRST READAT		;GO TRY AGAIN


	PAGE
	SUBTTL READAT - READ DATA ROUTINE

;HERE WHEN LINK DISCONNECT OCCURS, MEANS WE GOT AN ERROR
; SET FLAG TO SAY ERROR ENCOUNTERED AND LINK CLOSED

DATERR:				;HERE TO CLOSE LINK
	LOAD T1,LCBSTS		;GET STATUS
	PRTDCX <T1>,<DATA TEST ERROR>
	RET

ECHERR:				;HERE TO SAY ECHO ERROR
	SETOM EKERRF		;SET ECHO ERROR FLAG
	RET

	PAGE
	SUBTTL READST - READ STATUS ON DATA INTERRUPT

READST:				;HERE ON DATA INTERRUPT
	STKVAR <SAVCSZ>		;STACK VARIABLES
	CALL RLSLNK		;READ LINK STATUS
	RETBAD ERXLNK		;FAILED
	LOAD T1,LCBSTS		;GET STATUS
	TXNE T1,MO%ABT		;ABORTED ?
	JRST DATERR		;YES, GO CLOSE UP
	TXNN T1,MO%CON		;CONNECTED ?
	JRST DATERR		;NO, GO CLOSE UP
	LOAD T1,LCBJFN		;GET JFN FOR THIS LINK
	SIBE			;ANY DATA RECEIVED ?
	SKIPA			;YES, READ IT
	RET
;	JRST ABRTIT		;GO ABORT THE LINK

;READ DATA RECEIVED ON LINK
; T2 HAS NUMBER OF BYTES AVAILABLE

READS1:				;HERE WHEN DATA IN BUFFER FOR A LINK
	LOAD T3,LCBCSZ		;GET CURRENT MSG SIZE FROM LCB
	MOVEM T3,SAVCSZ		;SAVE IT IN TEMPORARY
	STOR   (T2,LCBCSZ)	;STORE NUMBER OF BYTES AVAILABLE
	PRTERR <UNEXPECTED DATA RECEIVED>
	MOVX T2,.NULIO		;JUST IGNORE ANY DATA WE GET
	STOR   T2,LCBRMB	;STORE BYTE POINTER FOR RECEIVE BUFFER IN LCB
	CALL   RCVLNK		;GO RECEIVE ON LINK
	RETBAD LNKERR		;FAILED, PRINT LINK ERROR, RETURN BAD
	MOVE T1,SAVCSZ		;RESTORE OLD VALUE OF LCBCSZ
	STOR T1,LCBCSZ
	JRST READST		;GO TRY AGAIN

	PAGE
	SUBTTL LNKERR - LINK ERROR ROUTINE

LNKERR:				;HERE TO PRINT LINK ERROR ON JSYS FAILURE
	CALL ERXLNK		;PRINT OUT THE JSYS ERROR FOR LINK
	LOAD T1,LCBRSN		;GET NSP REASON CODE
	PRTDCX <T1>,<NSP REASON> ;PRINT OUT THE NSP ERROR TEXT
	RET			;AND RETURN

	PAGE
	SUBTTL STRCMP - STRING COMPARISON ROUTINE
;
;STRCMP - STRING COMPARE FOR ANY BYTE SIZE STRING, STRICTLY EQUAL COMPARE
;	  NO UPPER/LOWER CASE STUFF
;
;ACCEPTS: T1/ BYTE POINTER TO STRING 
;	  T2/ BYTE POINTER TO STING TO COMPARE WITH
;	  T3/ LENGTH TO COMPARE
;
;	CALL  STRCMP
;
;RETURNS+1: STRINGS UNEQUAL, T1,T2/ UPDATED
;	+2: STRINGS EQUAL
STRCMP:				;ENTRY
	STKVAR <STRPT1,STRPT2> ;VARIABLES
	MOVEM  T1,STRPT1	;SAVE POINTER TO FIRST STRING
	MOVEM  T2,STRPT2	;AND SECOND ALSO
STRCM1:				;LOOP THRU HERE FOR EACH BYTE OF STRINGS
	ILDB   T1,STRPT1	;GET BYTE FROM FIRST STRING
	ILDB   T2,STRPT2	;AND BYTE FROM SECOND
	CAME   T1,T2		;COMPARE THEM
	RET			;NOT EQUAL, RETURN +1
	SOJG   T3,STRCM1	;EQUAL, LOOP FOR NEXT BYTE
	MOVE   T1,STRPT1	;RESTORE UPDATED POINTERS
	MOVE   T2,STRPT2
	RETSKP			;DONE, RETURN

	PAGE
	SUBTTL LITERAL POOL AND CONSTANTS

	XLIST
LTPOOL:	LIT			;BEGINNING OF LITERAL POOL
	LIST

TIMEUP:	BLOCK 1			;FLAG FOR TIME EXPIRED

STDPAT:				;STANDARD DATA PATTERN FOR DTR
STDINT:	POINT 8,.+1		;POINTER TO STANDARD INTERRUPT MESSAGE
	BYTE (8)"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"
	BYTE (8)"Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5"
	BYTE (8)"6","7","8","9"

BT8TBL:				;TABLE OF 256 8 BIT BYTES
	TABLE8			;GENERATE THE TABLE

	PAGE
	SUBTTL VARIABLE DATA STORAGE

	VAR

;START AND ELAPSED TIMES

STIME:	BLOCK 1
ETIME:	BLOCK 1

COUNT:	BLOCK 1			;FOUR BYTE COUNT

;ECHO ERROR FLAG

EKERRF:	BLOCK 1			;FLAG TO SAY ECHO ERROR OCCURRED


;BUFFER FOR RECEIVED DATA

RDBUF:	BLOCK MSGSIZ


	END