perm filename CODE.OLD[IP,NET]1 blob sn#702336 filedate 1983-03-14 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	INEMPT INPT INPTM INPT2 INPT2A INPT3 INPT4 INPT5 INPT6 INPT7 INPCLS INPCL1
C00010 ENDMK
C⊗;
;INEMPT INPT INPTM INPT2 INPT2A INPT3 INPT4 INPT5 INPT6 INPT7 INPCLS INPCL1

;Subroutine to check for data in current input stream.  Call with scanner off
;and TOPS-10 ACs set up.  Non-skip return if there's data, skip return if empty.
;This code based on INBYTC in IMPSER.MAC.

INEMPT:	SKIPLE IBFBC(F)			;Any bytes in current buffer?
	 JRST CPOPJ1			;Yes.
	PUSHJ P,INBUFR↑			;Set up input buffer (in IMPSER.MAC)
	POPJ P,				;Out of buffers.  Take error return
	MOVEM T2,IBFBC(F)		;Set byte count
	HRLI T1,(POINT 8)		;Make byte pointer
	MOVEM T1,IBFPNT(F)		;Save pointer
	JRST INEMPT			;See if it's empty

;Common input routine.  Enter with user address in TAC1 and desired word count
;in TAC. Returns count of words transferred in RH(DAT) and byte ptr to last byte
;transferred in LH(DAT).  Returns +1 if error or no data available, +2 on some
;data transferred.

INPT:	PUSHJ P,UUOIOK		; MAKE SURE HOST ALIVE AND ALL
	 POPJ P,		; HOST DEAD
INPTM:	SETZ DAT,		; CLEAR WORD COUNT

;Read data out of input list and into user core.  Some of this code similar to
;INPT in IMPSER.MAC, though cleaned up a bit.  Main difference is that we BLT
;data from input stream into user core instead of moving it byte-by-byte.

	PUSHACS				;Get into TOPS-10 mode
	SETT10
	SETAC(P1,TAC1)			;User address to store data
	SETAC(P2,TAC)			;Desired word count
	SETAC(P3,DAT)			;Words transferred
	MOVSI S,ALLWAT!IOBRKF!IO!IOFST
	ANDCAM S,IMPIOS(F)
	HRRI S,IODATA
	ANDCAB S,DEVIOS(F)		;CLEAR FLAGS
	TLNN S,IOBEG			;FIRST TIME AROUND?
	JRST INPT2			;NO
	SETZM ISHREG(F)			;YES
	MOVSI S,IOFST!IOBEG		;FIRST IO FLAG
	XORB S,DEVIOS(F)
INPT2:	MOVSI S,IDATWT
	IORM S,IMPIOS(F)
	IORB S,DEVIOS(F)		;SET IO WAIT FLAGS
	OFFSCN				; avoid anarchy
	PUSHJ P,INEMPT			;CALL CHECK ROUTINE
	 JRST INPT3			;DATA!

	PUSHJ P,TCPICK↑			;OPEN? (in TCPSER.MAC)
	 JRST [ ONSCN			;NO
		JRST INPCLS]		;Return error to caller with WAITS ACs
	SKIPE OKFLAG
	SKIPE STOPFLG			;IMP OK?
	 JRST INPT2A			;NO
	PUSHJ P,IMPW60			;WAIT
	JRST INPT2			;TRY FROM TOP

;Here if IMP not OK.
INPT2A:	ONSCN
	POPACS				;Back to WAITS mode
	JRST IMPLUZ

;Here we move data from the input stream into user core.
INPT3:	ONSCN
	HLRZ T1,IBFPNT(F)
	CAIN T1,(POINT 8)		;Are we on a word boundary?
	 JRST INPT4			;Yes
	CAIE T1,(POINT 8,0,31)		;It may look like this instead
	 PUSHJ P,IMPBUG			;Nope -- totally confused
	AOS T1,IBFPNT(F)		;If so, we fix it up
	HRLI T1,(POINT 8)
	MOVEM T1,IBFPNT(F)
INPT4:	MOVE T2,IBFBC(F)		;Number of bytes in this buffer
;JJW - we may have to be more careful here.
	ADDI T2,<1⊗WD2BYT>-1		;Round up to multiple of a word
	LSH T2,BYT2WD			;Convert to words
	CAILE T2,(P2)			;DOES THE USER WANT LESS THAN THERE IS?
	 MOVEI T2,(P2)			;YES, JUST GIVE HIM WHAT HE WANTS
	MOVEI T3,(P1)			;COPY OF USER'S ADDRESS
	MOVE T1,IBFPNT(F)
	HRLI T3,(T1)			;SOURCE,,RELATIVE DEST.
	MOVEI T4,(P1)			;FIRST DESTINATION
	ADDI T4,-1(T2)			;PLUS WC-1=LAST DEST.
	XCTR XBLTW,[BLT T3,(T4)]	;MOVE DATA FROM FREE STG TO USER.
	ADDM T2,IBFPNT(F)		;Update pointer into input stream
	ADDI P3,(T2)			;ADD INTO NUMBER OF WORDS TRANSFERRED
	SUBI P2,(T2)			;NOTE THAT HE HAS GOTTEN THAT MANY WORDS
	ADDI P1,(T2)			;INCREMENT USER ADDRESS
	SAVAC(TAC1,P1)			;Store these guys now
	SAVAC(TAC,P2)			;Store these guys now
	SAVAC(DAT,P3)
	MOVEI T3,(T2)			;Adjust byte count for current buffer
	LSH T3,WD2BYT
	SUBM T3,IBFBC(F)
	MOVNS IBFBC(F)
	ADDM T2,IBFBYT(F)		;Also this counter
	;Done with one buffer in input stream.  Try for another maybe.
	OFFSCN				;Be careful again
	JUMPG P2,INPT5			;Jump if he wants more
	PUSHJ P,INEMPT			;Doesn't.  See if any more in stream
	 SKIPA
	JRST INPT6			;Empty
	MOVEI S,IODATA			;Set data flag
	IORB S,DEVIOS(F)
	JRST INPT7
INPT5:	PUSHJ P,INEMPT			;Is there any more in input stream?
	 JRST INPT3			;Yes, go process it.
	;Input stream exhausted before user buffer.
	MOVEI S,IODATA			;Clear input data flag
	ANDCAB S,DEVIOS(F)
	;Input stream exhausted
INPT6:	PUSHJ P,TCPIFN↑			;Test for closed (in TCPSER.MAC)
	 JRST [				;Closed. Scanner now on. Tell user about EOF
		PUSHJ P,INPCLS		;Sets up WAITS ACs
		JRST CPOPJ1]
	;Here when done.
INPT7:	PUSHJ P,TCPWUP↑			;Update window information (in TCPSER.MAC)
	ONSCN				;Allow interrupts again
	PUSHJ P,IMPWK1↑			;Clear flags and such (in IMPSER.MAC)
	JRST POPPJ1			;Indicate success

;Here if socket not open (with scanner back on).  Returns with WAITS ACs set up.
INPCLS:	MOVSI S,IOEND			;End of file
	IORB S,DEVIOS(F)
	SKIPN IBFTHS(F)			;Any data in buffers?
	TLNN S,IOFST			;No was any input?
	 JRST INPCL1
	MOVEI S,IOIPM			;No. Error
	IORB S,DEVIOS(F)
INPCL1:	PUSHJ P,IMPWK1↑
	JRST POPPOJ