Trailing-Edge - PDP-10 Archives - decuslib10-07 - 43,50433/paspty.mac
There are 4 other files named paspty.mac in the archive. Click here to see a list.
	title PASPTY - a routine to open a PTY on Tops-10

printx  Warning: the routine has not yet been converted for new I/O


	search uuosym,pasunv

	reloc 400000

	entry ptyopn
	extern rewrite,resetf


;ptyopn(infile,outfile,name,open bits, buffer bits)
;  This routine is designed to solve a problem in the design of
;	the pascal language:  Because buffer variables are
;	associated with a pascal file, you cannot do input and
;	output over the same file.  When you did output, you
;	would lose what was left in the buffer from the last
;	input.  This is important because Pascal uses one-
;	character lookahead.  So this routine opens two files
;	on the same monitor channel, one for input and the
;	other for output.  Open bits and buffer bits are the
;	last two arguments from a standard RESET or REWRITE.
;	They should usually be zero.  The bit is automatically
;	set that suppresses the implicit GET after the open.
;	The following example program shows how to use it.
;	However any realistic program would have to handle
;	synchronization, probably by using non-blocking I/O
;	and interrupts, though easier ways are possible.

repeat 0,<
procedure ptyopn(var i:file;var out:file; name:string; open,buffer:integer); extern;

writeln(output,chr(3),'systat');  {put out systat command}
break(output);			  {force output the buffer}
while true do			  {now copy everything you see from pty}
  ttyoutput^ := input^;
end.				  {assume the user will end this with ^C}

ptyopn:	push p,b	;infile
	push p,d	;name - addr
	push p,e	;name - length
	push p,f	;open bits
	push p,g	;buffer bits
;first open the output side
	move b,c	;b _ outfile
	move c,d	;c,d _ name
	move d,e
	move h,g	;h _ buffer bits
	move g,f	;g _ open bits
	setzb e,f	;clear protection, lookup block
	pushj p,rewrite	;open output side
	skipn fileof(b)	;be sure it worked
	jrst [sub p,[xwd 4,4] ;clean up stack - top is now infile
	      pop p,b	;infile
	      movei t,1	;set eof, so get fail return for both files
	      movem t,fileof(b)
	      jrst return]
;now open the input side - actually this is a reopen of the same channel
	pop p,h		;h _ buffer bits
	pop p,g		;g _ open bits
	pop p,d		;c,d _ name
	pop p,c
	seto e,		;suppress initial get
	setz f,		;no lookup block
	hrli t,filbfh(b) ;get output buffer
	ldb a,[point 4,filcls(b),12] ;get channel used for output
	pop p,b		;b _ input file
	hrri t,filbfh(b) ;t _ output,,input buffer
	skipe filbfp(b)	;if there was something
	xct filcls(b)	;there was an open file - close it
	movem t,filbfp(b) ;now save this so reset doesn' throw away chnl
	dpb a,[point 4,fillkp(b),12] ;use same channel as for output
	dpb a,[point 4,filent(b),12] ;use same channel as for output
	dpb a,[point 4,filin(b),12] ;use same channel as for output
	dpb a,[point 4,filout(b),12] ;use same channel as for output
	dpb a,[point 4,filcls(b),12] ;use same channel as for output
	pushj p,resetf+4 ;now open the input side
	hrrzs filbfp(b)	;clear the output pointer in the open block, so
			;error routines know this is the input side
return:	pop p,a		;return address
	subi p,1	;last argument was pushed onto the stack, too
	jrst (a)