Google
 

Trailing-Edge - PDP-10 Archives - AP-D471B-SB_1978 - ttyio.bli
There are no other files named ttyio.bli in the archive.
!***COPYRIGHT (C) 1974, 1975, 1976, 1977 DIGITAL EQUIPMENT CORP., MAYNARD, MASS.***
%%
%
	TTY INTERFACE ROUTINES
	=== ========= ========

	TTYCLR - CLEAR INPUT BUFFER AND RESET OLDBREAK
	TTYINC - INPUT A CHARACTER
	TTYINT - INPUT A TOKEN
	TTYOTL - OUTPUT A <CRLF>
	TTYOTC - OUTPUT A CHARACTER
	TTYOTS - OUTPUT A STRING
	TTYOTN - OUTPUT A STRING FOLLOWED BY A <CRLF>
	TTYOSX - OUTPUT A SIXBIT WORD
	TTYOVR - OUTPUT A VARYING CHARACTER STRING

%
%%

MODULE TTYIO (MLIST,FSAVE,TIMER=EXTERNAL(SIX12)) =
BEGIN
	MACHOP	TTCALL = #51;
	BIND	OUTCHR = 1,
		OUTSTR = 3,
		INCHWL = 4,
		CLRBFI = 9;
	OWN	TOKEN[9],
		OLDBREAK[2],
		OLDCHAR;
REQUIRE COMMON.BLI;
REQUIRE ENTRY.BLI;
COMMENT(TTYCLR);

! SUBROUTINE TTYCLR
! ========== ======

! THIS ROUTINE CLEARS THE TTY INPUT BUFFER AND RESETS OLDBREAK
! LAST MODIFIED ON 23 JUN 74 BY JG

GLOBAL ROUTINE TTYCLR =
BEGIN
	TTCALL(CLRBFI);
	ZERO(OLDBREAK,2);
	OLDCHAR _ 0
END;
COMMENT(TTYINC);

! SUBROUTINE TTYINC
! ========== ======

! THIS ROUTINE READS A CHARACTER FROM THE TTY.
! LAST MODIFIED ON 23 JUN 74 BY JG.

GLOBAL ROUTINE TTYINC =
BEGIN
	REGISTER CHAR;
	TTCALL(INCHWL,CHAR);
	.CHAR
END;
COMMENT(TTYINT);

! SUBROUTINE TTYINT
! ========== ======

! THIS ROUTINE READS A TOKEN FROM THE TTY AND RETURNS
! A POINTER TO A VARYING CHARACTER STRING. A TOKEN IS DEFINED
! TO BE A STRING BOUNDED BY BREAK CHARACTERS OR A NON-BLANK
! BREAK CHARACTER ITSELF. IF THE COUNT OF THE VARYING CHARACTER
! STRING IS -1 THEN THE TOKEN IS A BREAK CHARACTER,
! IF IT IS -40, THE THIS IS ONLY THE FIRST PART OF A TOKEN THAT
! IS LONGER THAT 40 CHARACTERS. EVERYTING AFTER A "!" ON A LINE IS
! CONSIDERED A COMMENT AND IGNORED. A PROMPT CHARACTER OF
! "*" IS PRINTED ON THE TTY WHENEVER A <LF> IS ENCOUNTERED.
! LAST MODIFIED ON 29 JUL BY JG.

GLOBAL ROUTINE TTYINT =
BEGIN
	LOCAL	CHAR,OLDPTR,TOKENPTR;
	LABEL	GATHER,BRK;
	MACRO	BETWEEN(LOWER,UPPER) = .CHAR GEQ LOWER AND .CHAR LEQ UPPER$;

	IF .OLDBREAK[0] NEQ 0			! LAST CALL FOUND A BREAK
	THEN BEGIN
		TOKEN[0] _ .OLDBREAK[0];	! SIMPLY HAND IT BACK
		TOKEN[1] _ .OLDBREAK[1];
		OLDBREAK[0] _ 0;		! BUT DON'T DO IT AGAIN
		RETURN TOKEN
	END;

	ZERO(TOKEN,9);				! CLEAR THE WHOLE THING
	OLDPTR _ OLDBREAK[1]<FIRSTCHAR>;	! FORMS A BYTE PTR TO OLDBREAK
	TOKENPTR _ TOKEN[1]<FIRSTINCR>;		! AND ONE TO THE TOKEN
	WHILE  .TOKEN[0] LSS 40			! ARBITRARY LIMIT
	DO GATHER: BEGIN
		IF .OLDCHAR NEQ NULL		! KLUDGE FOR HANDLING "#"
		THEN BEGIN
			CHAR _ .OLDCHAR;	! THIS CHAR SHOULD BE A DIGIT
			OLDCHAR _ NULL		! NOW FORGET ABOUT IT
		END
		ELSE CHAR _ TTYINC();		! READ FROM TTY LIKE NORMAL
		IF .CHAR EQL "!"		! FOUND A COMMENT
		THEN REPEAT BEGIN
			CHAR _ TTYINC();
			IF .CHAR EQL #12	! JUST SCAN FOR A <LF>
			THEN BEGIN
				TTYOTC("*");	! PROMPT
				LEAVE GATHER	! KEEP LOOKING
			END
		END;
		IF .CHAR LEQ #40		! MEANS BREAK, BUT IGNORE BREAK ITSELF
		THEN BEGIN
			IF .CHAR EQL #12 THEN TTYOTC("*");! BUT PROMPT ON <LF>
			IF .TOKEN[0] EQL 0
				THEN LEAVE GATHER! NO CURRENT TOKEN
				ELSE RETURN TOKEN! RETURN WHAT WE HAVE
		END;
BRK:		IF %CHAR IS% BETWEEN(#41,#57) OR BETWEEN(#72,#100) OR BETWEEN(#133,#140) OR BETWEEN(#173,#177)
		THEN BEGIN
			IF .CHAR IS "#"		! CHECK FOR BREAK ESCAPE OR OCTAL ESCAPE
			THEN BEGIN
				OLDCHAR _ TTYINC();! FETCH NEXT CHAR
				IF .OLDCHAR LSS #60 OR .OLDCHAR GTR #71 ! NOT A DIGIT, KEEP
				THEN BEGIN
					CHAR _ .OLDCHAR; ! INSERT THE CHAR AS IF IT WERE ALPHANUMERIC
					OLDCHAR _ NULL;
					LEAVE BRK
				END;
			END;
			IF .TOKEN[LANGTH] IS 0	! HERE, EITHER CHAR FOLLOWING # WAS A DIGIT OR CHAR WAS BREAK
			THEN BEGIN
				TOKEN[0] _ -1;	! MEANS A BREAK TOKEN
				REPLACEI(TOKENPTR,.CHAR);
				RETURN TOKEN
			END
			ELSE BEGIN
				OLDBREAK[0] _ -1;! STUFF AWAY THE BREAK
				REPLACEN(OLDPTR,.CHAR);
				RETURN TOKEN	! BUT RETURN THE TOKEN
			END
		END;
		TOKEN[0] _ .TOKEN[0]+1;		! HO HUM... ADD TO THE TOKEN, NOTHING FANCY
		REPLACEI(TOKENPTR,.CHAR);
	END;
	TOKEN[0] _ -40;				! WE HAVE 40 CHARS SO FAR, -40 MEANS THERE IS MORE
	TOKEN
END;
COMMENT(TTYOTL);

! SUBROUTINE TTYOTL
! ========== ======

! THIS ROUTINE TYPES A <CRLF> ON THE TTY.
! LAST MODIFIED ON 23 JUN 74 BY JG.

GLOBAL ROUTINE TTYOTL = TTCALL(OUTSTR,PLIT ASCIZ '?M?J');
COMMENT(TTYOTC);

! SUBROUTINE TTYOTC
! ========== ======

! THIS ROUTINE TYPES A CHAR ON THE TTY.
! LAST MODIFIED ON 23 JUN 74 BY JG.

GLOBAL ROUTINE TTYOTC(CHAR) = TTCALL(OUTCHR,CHAR);
COMMENT(TTYOTS);

! SUBROUTINE TTYOTS
! ========== ======

! THIS ROUTINE TYPES OUT A STRING ON THE TTY.
! IF COUNT IS 0, AN ASCIZ STRING IS ASSUMED.
! LAST MODIFIED ON 23 JUN 74 BY JG.

GLOBAL ROUTINE TTYOTS(COUNT,STRING) =
BEGIN
	LOCAL CHAR,STRPTR;
	IF .COUNT EQL 0				! TYPE AN ASCIZ STRING
	THEN TTCALL(OUTSTR,.STRING)		! THAT'S THE EASY ONE
	ELSE BEGIN
		STRPTR _ (.STRING)<36,7>;	! SET UP BYTE POINTER
		DECR I FROM .COUNT-1 TO 0
		DO BEGIN
			CHAR _ SCANI(STRPTR);	! GET ONE (AND ONLY ONE!) CHAR
			TTYOTC(.CHAR)		! SEND IT OUT TO THE CRUEL WORLD
		END
	END
END;
COMMENT(TTYOTN);

! SUBROUTINE TTYOTN
! ========== ======

! THIS ROUTINE IS LIKE TTYOTS EXCEPT IT ADDS A <CRLF>.
! LAST MODIFIED ON 23 JUN 74 BY JG.

GLOBAL ROUTINE TTYOTN(COUNT,STRING) =
BEGIN
	TTYOTS(.COUNT,.STRING);			! FOOLED YOU, DIDN'T I!
	TTYOTL()				! WE CAN AFFORD TO BE LAZY TO THE TTY
END;
COMMENT(TTYOSX);

! SUBROUTINE TTYOSX
! ========== ======

! THIS ROUTINE TYPES A WORD OF SIXBIT
! CHARACTERS ON THE TTY.
! LAST MODIFIED ON 22 JUL BY JG.

GLOBAL ROUTINE TTYOSX (SIXWORD) =
BEGIN
	LOCAL PTR,CHARS[6],LNB;
	PTR _ SIXWORD<36,6>;			! FORM SIXBIT POINTER TO INPUT WORD
	INCR I FROM 0 TO 5			! STEP THROUGH IT
	DO BEGIN
		CHARS[.I] _ #40 + SCANI(PTR);	! CONVERT TO ASCII AND PLACE IN CHARS
		IF .CHARS[.I] NEQ #40		! DON'T TYPE TRAILING BLANKS (ASSUMES NO IMBEDDED BLANKS)
		THEN LNB _ .I			! REMEMBER LAST NON-BLANK
	END;
	INCR I FROM 0 TO .LNB			! NOW TYPE ALL THE NON-BLANK CHARS
		DO TTYOTC(.CHARS[.I]);
END;
COMMENT(TTYOVR);

! SUBROUTINE TTYOVR
! ========== ======

! THIS ROUTINE TYPES VARYING STRINGS ON THE TTY
! LAST MODIFIED ON 29 JUL 74 BY JG.

GLOBAL ROUTINE TTYOVR(VARPTR) =
BEGIN
	MAP VARYINGCHAR VARPTR;
	TTYOTS(.VARPTR[LANGTH],VARPTR[STRING])	! SIMPLY FAKE OUT TYOTS, SAVES TYPING ELSEWHERE
END;

END ELUDOM; !END OF TTY I/O INTERFACE