From:	CSBVAX::MRGATE!x_gaure_s%use.uio.uninett@NTA-VAX.ARPA@SMTP  1-OCT-1987 14:31
To:	EVERHART
Subj:	RE: PTYs not putting me in RWAST.

Date: Thu, 1 Oct 87 11:28:24 +0100
Posted-Date: Thu, 1 Oct 87 11:28:24 +0100
Received: by tor.nta.no (5.54/3.21)
	id AA16783; Thu, 1 Oct 87 11:28:24 +0100
From: Simen Gaure <x_gaure_s%use.uio.uninett@NTA-VAX.ARPA>
To: <Everhart%arisia.decnet@ge-crd.arpa>
In-Reply-To: <8709301928.AA14283@tor.nta.no>
Message-Id: <146:x_gaure_s@use.uio.uninett>
Subject: RE: PTYs not putting me in RWAST.

$!	This command file is self unpacking.
$!	Please run it in an empty directory
$ say := write sys$output
$ say "Creating PTY.B32"
$ CREATE PTY.B32
!File : PTY.B32
!This program allows you to create multiple PTYs, switching
!between them, logging output to a file...
!It assumes you have installed the PYDRIVER/TPDRIVER by
!Dale Moore / Kevin Carosso & whoever.
!
!Author : Simen Gaure   X_GAURE_S%use.uio.uninett@tor.arpa
!			X_GAURE_S@inger.arpa
!Date : 30-Sep-1987
!
!Please report errors and/or suggestions to the above address.
!
!The sources contained herein can be distributed freely to anyone.
!The author accepts no responsibility for any harm this program
!might do to anything.
!
!You may modify any part of this program, but remember to 
!make an entry in the history list.
!
!Modification history :
!New entries on top of list.
!
!30-Sep-1987 : First version
!

MODULE pty (main = main) =
BEGIN

!
! TABLE OF CONTENTS:
!
FORWARD ROUTINE
    exithandler,
    setctrly : NOVALUE,
    clearctrly : NOVALUE,
    set_term,
    reset_term,
    findpty,
    flushbuffer : NOVALUE,
    activate,
    passivate,
    passivateall : NOVALUE,
    passivatesome : NOVALUE,
    pty_input : NOVALUE,
    logit,
    newpty,
    deletepty : NOVALUE,
    init,
    dopty,    
    getident,
    acceptpty,
    break,
    suppress,
    help,
    showbreak,
    ptystatus,
    log,
    close,
    remove,
    connect,
    spawn,
    exit,
    okexit;
!
! INCLUDE FILES:
!
LIBRARY 'sys$library:starlet';
!
! MACROS:
!


MACRO

    iostatus =
	BLOCK[8,BYTE] FIELD( iosbfields) %,
    
!output error approriate error message if status is even

    $messerr(status) =
        IF NOT status THEN
	BEGIN

	LOCAL
	    messdesc : BLOCK[8,byte];
	$init_dyndesc(messdesc);
	stat = lib$sys_getmsg(%ref(status),0,messdesc);
	IF .stat THEN
	  lib$put_output(messdesc);
	END %,

    $reterr (status) = 
        IF NOT status THEN return status %;

!Layout of one PTY
FIELD ptyfields =
    SET
    flink = [0,0,32,0],	!Forward link
    blink = [4,0,32,0], !Backward link
    bufadr = [8,0,32,0],    !Address of read buffer
    iosbadr = [12,0,32,0],  !Address of iosb
    chan = [16,0,16,0],	    !Channel number
    buflen = [18,0,16,0],   !number of bytes in buffer
    buffer = [20,0,32,0],   !Address of write buffer
    ident  = [24,0,32,0],    !Pty identification
    flags  = [28,0,32,0],   !Pty control flags
    accept = [28,0,1,0],    !Accept output from pty when at command level
    active = [28,1,1,0],     !Pty writes output to terminal
    xoffed = [28,2,1,0],    !Pty writes to much, I have sent a ^S.
    displayid = [32,4,1,0]
    TES;

LITERAL
!length in bytes of one PTY.
    ptylen = 36;


!allocate and initialize one PTY
MACRO makepty(ptyadr,id) =
	BEGIN
        LOCAL
            ptyid : REF pty,
	    stat;

        stat = lib$get_vm(%ref(ptylen),ptyadr);
        $messerr(.stat);
	stat = lib$get_vm(%ref(ptybufsiz),ptyadr[bufadr]);
        $messerr(.stat);
        stat = lib$get_vm(%ref(8),ptyadr[iosbadr]);
        $messerr(.stat);
        stat = lib$get_vm(%ref(ptybufsiz),ptyadr[buffer]);
        $messerr(.stat);
        ptyadr[flags] = 0;
        ptyadr[buflen] = 0;
        ptyadr[accept] = 0;
	ptyadr[xoffed] = 0;
        ptyadr[ident] = id;
        ptyadr[displayid] = 0;
        END %,

    $fixdesc(buffer) =
	BLOCK[8,byte] PRESET
			  ([dsc$b_class] = dsc$k_class_s,
			   [dsc$w_length] = %ALLOCATION(buffer),
			   [dsc$a_pointer] = buffer)%,

    empty(head) =
        BEGIN
	(.head[0] EQLA .head[1])
	END %;




LITERAL
    logbufsiz = 2048,  !size of the buffer we use for logging

    ptybufsiz = 1024,  !size of the buffer that receives output from PTY
    xoff = %C'S' - %C'A' + 1,  !^S
    xon = %C'Q' - %C'A' + 1,   !^Q
    xofflim = ptybufsiz*3/4;   !highwater mark in buffer

MACRO
    pty =
	BLOCK[ptylen,byte] field(ptyfields) %;

!layout of a terminal iosb
FIELD iosbfields =
    SET
    status = [0,0,16,0],
    count = [2,0,16,0],
    terminator = [4,0,16,0],
    termsize = [6,0,16,0]
    TES;
!
! EQUATED SYMBOLS:
!
!
! OWN STORAGE:
!
OWN
    oldrwm,  !resource wait mode when program was started
    crlf : VECTOR[2,byte] PRESET
			      ([0] = 13,
			       [1] = 10),
    loglen : word INITIAL(0),  !bytes in log buffer
    logbuf : BLOCK[logbufsiz,BYTE],  !logbuffer
    logfab : $FAB(rfm = var,   !FAB for the log file
		  rat = cr,
		  fac = <put>,
		  fop = <cif>),
    lograb : $RAB(FAB = logfab,  !RAB for the log file
		  rop = eof,
		  rbf = logbuf,
		  rsz = %ALLOCATION(logbuf)),
    logopen : word INITIAL(0),   !is the log file open
    currpty : REF pty,		 !current PTY
    ptyhead : VECTOR[2,long] 
              INITIAL(ptyhead,ptyhead), !queue head for the PTYs
    exitreason : VOLATILE,
    desblk : BLOCK[4,LONG] 
             INITIAL(0,exithandler,0,exitreason), !descriptor block
						  !for exit handler
    old_termchar : BLOCK[12,BYTE],  !initial terminal characteristics
    breakchar : byte INITIAL(28),   !break character
    doexit : byte INITIAL(0),
    astchan : byte,		    !channel to TTY for ^Y ast
    tt_char : byte,		    !character read from TTY
    tt_chan : word,		    !Channel to read/write from TTY	
    tt_iosb : iostatus;		    !iosb for tty

!
! EXTERNAL REFERENCES:
!
EXTERNAL ROUTINE
    lib$pause : ADDRESSING_MODE(GENERAL),
    lib$sys_getmsg : ADDRESSING_MODE(GENERAL),
    lib$sys_fao : ADDRESSING_MODE(GENERAL),
    lib$put_output : ADDRESSING_MODE(GENERAL),
    lib$getjpi : ADDRESSING_MODE(GENERAL),
    lib$get_input : ADDRESSING_MODE(GENERAL),
    lib$analyze_sdesc : ADDRESSING_MODE(GENERAL),
    cli$present : ADDRESSING_MODE(GENERAL),
    cli$get_value : ADDRESSING_MODE(GENERAL),
    lib$signal : ADDRESSING_MODE(GENERAL),
    lib$free_vm : ADDRESSING_MODE(GENERAL),
    lib$get_vm : ADDRESSING_MODE(GENERAL);
EXTERNAL LITERAL
    pty__breakis,
    pty__connect,
    pty__accept,
    pty__refuse,
    pty__logging,
    pty__nolog,
    pty__closelog,
    pty__logopen,
    pty__nopty,
    pty__actpty;

%SBTTL 'Exithandler'


ROUTINE exithandler(reason) =
    BEGIN
    LOCAL
	stat;
!reset resource wait mode
    $setrwm(watflg = (IF .oldrwm eqlu ss$_wasclr THEN 0 ELSE 1));
!reset terminal charcteristics
    reset_term()
    
    END;


%SBTTL 'interception of ctrl/y & term characteristics'

ROUTINE ctrly : NOVALUE =
    BEGIN

!tell user about active PTYs
    okexit();  

!Tell user how to continue
    lib$put_output(%ASCID %STRING(%char(7),
		    'Type continue to resume',%char(7,7)));
!simulate ^Y
    lib$pause();
    END;


!^Y & ^C trap
ROUTINE setctrly : NOVALUE =
    BEGIN
    $assign(devnam = %ASCID 'SYS$INPUT',chan = astchan);
    !Set out of band ast for ^C and ^Y
    $qiow(chan = .astchan,func=io$_setmode+io$m_outband+
	  io$m_tt_abort + io$m_include,
	  p1 = ctrly,p2 = uplit(0,%X '2000008'));
    END;


ROUTINE clearctrly : NOVALUE =
    BEGIN
    $dassgn(chan = .astchan);
    END;

!set appropriate term chars for PTY operation
ROUTINE set_term =
    BEGIN
    BUILTIN
	movc3;

    LOCAL
        iosb : iostatus,
        stat,
	termchar : BLOCK[%ALLOCATION(old_termchar),BYTE],
	charlen : word INITIAL(%ALLOCATION(termchar));
    BIND
	chars = termchar + 4 : BLOCK[3, byte],
	extchars = termchar + 8 : BLOCK[8, byte];

!modify initial term chars
    MOVC3(%REF(%ALLOCATION(old_termchar)), old_termchar, termchar);   
    chars[tt$v_noecho] = 1;
    chars[tt$v_hostsync] = 0;
    chars[tt$v_ttsync] = 0;
    extchars[tt2$v_pasthru] = 1;
    
    stat = $qiow(chan = .tt_chan,func=io$_setmode,iosb = iosb,
		 p1 = termchar,p2 = %ALLOCATION(termchar));
    IF .stat THEN stat = .iosb[status];
    .stat
    END;


!reset to initial term chars
ROUTINE reset_term =
    BEGIN
    LOCAL
	iosb : iostatus,
	stat;

    stat = $qiow(chan = .tt_chan,func = io$_setmode,iosb = iosb,
	         p1 = old_termchar,p2 = %ALLOCATION(old_termchar));
    $reterr(.stat);
    .iosb[status]
    END;



%SBTTL 'activation of ptys'
ROUTINE activate(ptyadr) =
    BEGIN
    LOCAL
	ptyid : REF pty INITIAL(.ptyadr);
!write pending output to TTY
    flushbuffer(.ptyid);
!Set active status 
    ptyid[active] = 1
    END;


ROUTINE passivate(ptyadr) =
    BEGIN
    LOCAL
	ptyid :REF pty INITIAL(.ptyadr);
!clear active status
    ptyid[active] = 0;
    1
    END;


!passivate all PTYs
ROUTINE passivateall : NOVALUE =
    BEGIN
    LOCAL
	ptyid : REF pty INITIAL(.ptyhead[0]);

    WHILE .ptyid NEQA ptyhead DO
    BEGIN
	passivate(.ptyid);
	ptyid = .ptyid[flink];
    END;
    END;


!Passivate all PTYs that can't accept output at command level
ROUTINE passivatesome : NOVALUE =
    BEGIN
    LOCAL
	ptyid : REF pty INITIAL(.ptyhead[0]);

    WHILE .ptyid NEQA ptyhead DO
    BEGIN
	IF NOT .ptyid[accept] THEN
	  passivate(.ptyid);
	ptyid = .ptyid[flink];
    END;
    END;


%SBTTL 'read from pty'
ROUTINE pty_input(ptyadr) : NOVALUE =
    BEGIN
    BUILTIN
	movc3;

    LOCAL
        ptyid : REF pty,
        iosb : REF iostatus,
	stat;

    ptyid = .ptyadr;
    iosb = .ptyid[iosbadr];
    IF .iosb[status] EQLU ss$_abort THEN RETURN;
    $messerr(.iosb[status]);
    IF .ptyid[active] THEN 
    BEGIN
        !Very well, the pty is active, write output to terminal
	stat = $qiow(chan = .tt_chan,func = io$_writevblk,
		     p1 = .ptyid[bufadr],p2 = .iosb[count]);
	$messerr(.stat);
	!log the output
        stat = logit(.ptyid[bufadr],.iosb[count]);
	$messerr(.stat);
    END ELSE
	BEGIN
	!The pty is not active, buffer output 
	LOCAL
	    charstomove : word,
	    bufleft : word;

!If buffer will be full, flush it to terminal
	IF .ptyid[buflen] + .iosb[count] GTR ptybufsiz THEN
          flushbuffer(.ptyid);

!move characters to buffer
	bufleft = ptybufsiz - .ptyid[buflen];
	charstomove = MIN(.bufleft,.iosb[count]);
	MOVC3(charstomove, 
	      .ptyid[bufadr],
	      .ptyid[buffer]+.ptyid[buflen]);
	ptyid[buflen] = .ptyid[buflen] + .charstomove;

!If highwater is reached, XOFF the PTY
	If (.ptyid[buflen] GTRU xofflim) THEN
	  BEGIN
          !Pty writes to much, xoff it
	  $qiow(chan = .ptyid[chan],func = io$_writevblk,
	        p1 = %ref(xoff),p2 = 1);
	  ptyid[xoffed] = 1
	  END;
	END;

!reenable the read request to the PTY
    stat = $qio(chan = .ptyid[chan],func = io$_readvblk,
		iosb = .ptyid[iosbadr],astadr = pty_input,astprm = .ptyid,
                p1 = .ptyid[bufadr],p2 = ptybufsiz);
    $messerr(.stat);
    END;


!flush the buffer to TTY
ROUTINE flushbuffer(ptyadr) : NOVALUE =
    BEGIN
    LOCAL
	ptyid : REF pty INITIAL(.ptyadr);

    $qiow(chan = .tt_chan,func=io$_writevblk+io$m_refresh,
	  p1 = .ptyid[buffer],p2 = .ptyid[buflen]);
    logit(.ptyid[buffer],.ptyid[buflen]);
    ptyid[buflen] = 0;

!xon the PTY
    IF .ptyid[xoffed] THEN $qiow(chan = .ptyid[chan],func=io$_writevblk,
				p1 = %ref(xon),p2 = 1);
    ptyid[xoffed] = 0;
    END;


!log characters to the log file
ROUTINE logit(adr,len) = 
    BEGIN
    BUILTIN
	matchc,
	movc3;

    LOCAL
	foo,
	stat,
	bytesleft : word,
	left : word,
	start,
	startrec,
	reclen : word;

    IF NOT .logopen THEN RETURN 1;
    !buffer the input
    IF .loglen + .len GTR logbufsiz THEN
    BEGIN
    !No more buffer space left in log buffer
    !We have to write the buffer to disk;
    lograb[rab$w_rsz] = .loglen;
    lograb[rab$l_rbf] = logbuf;
    stat = $PUT(RAB = lograb);
    $messerr(.stat);
    loglen = 0;
    END;

!move characters to log buffer
    MOVC3(%ref(.len),.adr, logbuf+.loglen);
    loglen = .loglen + .len;
    start = (startrec = logbuf);
    bytesleft = (left = .loglen);
    !write out records.

!records are separated by crlf
    DO
    BEGIN 
	IF MATCHC(%ref(2), crlf, left, .start ;foo,foo,left,start) THEN
	BEGIN
	    ! We have found the end of a record;
	    reclen = .start - 2 - .startrec;
	    ! write the record to the logfile
	    lograb[rab$w_rsz] = .reclen;
	    lograb[rab$l_rbf] = .startrec;
	    stat = $PUT(RAB = lograb);
	    startrec = .start;
	    IF (bytesleft = .left) EQL 0 THEN loglen = 0;
	END ELSE
	BEGIN
	!The buffer contains no more crlf, put rest of buffer
	! in front of buffer
	IF logbuf NEQU .startrec THEN
	    MOVC3(bytesleft, .startrec, logbuf);
	loglen = .bytesleft;
	bytesleft = 0;
	stat = 1;
	END;
    END
    UNTIL (.bytesleft EQL 0);
    .stat
    END;


%SBTTL 'Creation of ptys'

!find PTY with ptyis eqlu id
ROUTINE findpty(id) =
    BEGIN
    LOCAL
	ptyid : REF pty INITIAL(.ptyhead[0]);

    WHILE .ptyid NEQA ptyhead DO
	BEGIN
	IF .ptyid[ident] EQLU .id THEN EXITLOOP;
	ptyid = .ptyid[flink];
	END;

    IF .ptyid EQLA ptyhead THEN RETURN 0;
    .ptyid
    END;

!create a new PTY 
ROUTINE newpty(ptyadr,id) =
    BEGIN
    BUILTIN
	insque;
    LOCAL
        stat,
	ptyid : REF pty;

!allocate & init
    makepty(ptyid,.id);
    stat = $ASSIGN(devnam = %ASCID 'PYA0:',chan = ptyid[chan]);
    $reterr(.stat);

!issue a read request
    stat = $qio(chan = .ptyid[chan],func = io$_readvblk,
		iosb = .ptyid[iosbadr],astadr = pty_input,astprm = .ptyid,
                p1 = .ptyid[bufadr],p2 = ptybufsiz);
    $reterr(.stat);

!insert in queue, if first PTY set ^Y trap
    IF INSQUE(.ptyid, ptyhead) THEN
       setctrly();
    .ptyadr = .ptyid;
    .stat
    END;


!delete a PTY
ROUTINE deletepty(ptyadr) : NOVALUE =
    BEGIN
	BUILTIN
	    remque;
	LOCAL
	    ptyid : REF pty INITIAL(.ptyadr);

!remove it from the queue
	REMQUE(.ptyid,ptyid);

!if no more PTYs left, clear ^Y trap, we have no currpty anymore
        IF empty(ptyhead) THEN
	BEGIN
	  currpty = 0;
	  clearctrly();
        END
        ELSE
         currpty = .ptyhead[0];
!flush the buffer
	flushbuffer(.ptyid);
!deassign channel
	$dassgn(chan = ptyid[chan]);
!deallocate 
	lib$free_vm(%ref(ptybufsiz),ptyid[bufadr]);
	lib$free_vm(%ref(8),ptyid[iosbadr]);
	lib$free_vm(%ref(ptybufsiz),ptyid[buffer]);
	lib$free_vm(%ref(ptylen),ptyid);
    END;


%SBTTL 'main routine when connected to a pty'
ROUTINE dopty(ptyadr) =
    BEGIN
    LOCAL
	ctrlycount : byte INITIAL(0),
        stat,
	ptyid : REF pty;
    ptyid = .ptyadr;
!tell user which PTY we connect to
    lib$signal(pty__connect,2,4,ptyid[ident]);
!set terminal chars
    set_term();
!passivate all ptys
    passivateall();
!activate this one
    activate(.ptyid);

!read characters from TTY, write them to PTY
    DO
    BEGIN
    stat = $qiow(chan = .tt_chan,func=io$_readvblk,
		iosb = tt_iosb,
		p1 = tt_char,p2 = 1);
    $reterr(.stat);
    $reterr(.tt_iosb[status]);
    IF .tt_char EQL .breakchar THEN EXITLOOP;
!count ^Y & ^C s
    IF (.tt_char EQL 3) OR (.tt_char EQL 25) THEN
	BEGIN
	ctrlycount = .ctrlycount + 1;
	IF .ctrlycount GTR 2 THEN
	BEGIN
	 showbreak();
	 ctrlycount = 0;
	END;
	END;
    stat = $qio(chan = .ptyid[chan],func = io$_writevblk,
                 p1 = tt_char,p2=1);
    $messerr(.stat);
    END
    WHILE 7;   !that's odd, isn't it ?
    passivatesome();
    reset_term()
    END;



%SBTTL 'parse pty name'
ROUTINE getident =
    BEGIN
    BUILTIN
	movc3;

    LOCAL
	id : INITIAL(0),
	len : word,
        addr,
	stat,
	iddescr : BLOCK[8,BYTE];
    $init_dyndesc(iddescr);
    stat = cli$present(%ASCID 'PTYNAME');
    IF NOT .stat THEN RETURN 0;
    stat = cli$get_value(%ASCID 'PTYNAME',iddescr);
    IF NOT .stat THEN RETURN 0;
    stat = lib$analyze_sdesc(iddescr,len,addr);
    $reterr(.stat);
    MOVC3(%ref(MIN(4,.len)), .addr, id);
    .id
    END;

%SBTTL 'Command routines'
GLOBAL ROUTINE acceptpty =
    BEGIN
    LOCAL
	ptyid : REF pty,
	id,
	stat;
    id = getident();
    IF .id EQL 0 THEN ptyid = .currpty ELSE
      ptyid = findpty(.id);
    IF .ptyid NEQA 0 THEN
    BEGIN
    lib$signal(pty__accept,2,4,ptyid[ident]);
    ptyid[accept] = 1;
    activate(.ptyid);
    END ELSE lib$signal(pty__nopty,2,4,id);
    1
    END;



GLOBAL ROUTINE break =
    BEGIN
    LOCAL
	stat;

    showbreak();
    set_term(); 
    stat = $qiow(chan = .tt_chan,func = io$_readprompt,
		 p1 = breakchar,p2 = 1,
		 p5 = UPLIT(%STRING(%CHAR(13,10),'New break character : ')),
		 p6 = 24);
    reset_term();
    showbreak();
    .stat
    END;


GLOBAL ROUTINE suppress =
    BEGIN
    LOCAL
	ptyid : REF pty,
	id,
	stat;
    id = getident();
    IF .id EQL 0 THEN ptyid = .currpty ELSE
      ptyid = findpty(.id);
    IF .ptyid NEQA 0 THEN
    BEGIN
    lib$signal(pty__refuse,2,4,ptyid[ident]);
    ptyid[accept] = 0;
    passivate(.ptyid);
    END ELSE lib$signal(pty__nopty,2,4,id);
    1
    END;


GLOBAL ROUTINE remove =
    BEGIN
    LOCAL
	id,
	ptyid : ref pty;

    id = getident();

    IF .id EQL 0 THEN ptyid = .currpty ELSE
      ptyid = findpty(.id);

    IF .ptyid NEQA 0 THEN
      deletepty(.ptyid) ELSE lib$signal(pty__nopty,2,4,id);
    1     
    END;


GLOBAL ROUTINE help =
    BEGIN
    EXTERNAL ROUTINE
	lbr$output_help : ADDRESSING_MODE(GENERAL);

    LOCAL
	stat,
	helpdesc : BLOCK[8, byte];
    $init_dyndesc(helpdesc);

    stat = cli$present(%ASCID 'HELP');
    IF .stat THEN
      stat = cli$get_value(%ASCID 'HELP',helpdesc);

    lbr$output_help(lib$put_output,
		    0,helpdesc,%ASCID 'SYS$HELP:PTY',
		    %REF(hlp$M_prompt+hlp$m_help),
		    lib$get_input)
    END;


GLOBAL ROUTINE connect =
    BEGIN

    LOCAL
        ptyid,
	id,
	stat;
    id = getident();
    IF .id NEQU 0 THEN
    BEGIN
	ptyid = findpty(.id);
	IF .ptyid EQLA 0 THEN
	BEGIN
	   LOCAL bio; 

	    lib$getjpi(%ref(jpi$_bytcnt),0,0,bio);
	    IF .bio LSSU ptybufsiz THEN RETURN ss$_exbytlm;

	    stat = newpty(ptyid,.id);
	    $reterr(.stat);
	END;
        currpty = .ptyid;
    END ELSE
    BEGIN
	IF .currpty EQLA 0 THEN
	BEGIN
	stat = newpty(currpty,%C'A');
	$reterr(.stat)
	END
    END;
    dopty(.currpty)
    END;


ROUTINE showbreak =
    BEGIN
    LOCAL
	brstr : word INITIAL(0);
    IF .breakchar LSSU 32 THEN
      brstr = %C'^' + 256*(.breakchar + %C'A' - 1)
    ELSE
      brstr = .breakchar;
    lib$signal(pty__breakis,2,2,brstr)
    END;

GLOBAL ROUTINE ptystatus =
    BEGIN
    LOCAL
	stradr,
	messdesc : BLOCK[8, byte],
	ptyid : REF pty INITIAL(.ptyhead[0]);
    BIND
	supp = %ASCID 'suppressed output',
	acc = %ASCID 'accept output';

    showbreak();
    $init_dyndesc(messdesc);
    WHILE .ptyid NEQA ptyhead DO
	BEGIN
	IF .ptyid[accept] THEN stradr = acc ELSE
	 stradr = supp;
	lib$sys_fao(%ASCID 'Pty !AD !AS',
		    0,messdesc,4,ptyid[ident],
		    .stradr);
        lib$put_output(messdesc);
	ptyid = .ptyid[flink];
	END;
    1
    END;



GLOBAL ROUTINE log =
    BEGIN
    EXTERNAL ROUTINE
	sys$modify : ADDRESSING_MODE(GENERAL);

    LOCAL
	stat,
	filenamedesc : BLOCK[8,byte];

    IF .logopen THEN 
    BEGIN
    lib$signal(pty__logopen,2,.logfab[fab$b_fns],.logfab[fab$l_fna]);
    return 1
    END ;
    $init_dyndesc(filenamedesc);
    stat = cli$get_value(%ASCID 'FILENAME',filenamedesc);
    $reterr(.stat);
    stat = lib$analyze_sdesc(filenamedesc,logfab[fab$b_fns],logfab[fab$l_fna]);
    $reterr(.stat);
    stat = $CREATE(FAB = logfab);
    $reterr(.stat);
    stat = $connect(RAB = lograb);
    $reterr(.stat);
    lib$signal(pty__logging,2,.logfab[fab$b_fns],.logfab[fab$l_fna]);
    logopen = 1;
    1
    END;


GLOBAL ROUTINE close =
    BEGIN
    BUILTIN
	testbitsc;

    LOCAL
	stat;
    IF TESTBITSC(logopen) THEN
    BEGIN
    lograb[rab$w_rsz] = .loglen;
    stat = $put(rab = lograb);
    $reterr(.stat);
    lib$signal(pty__closelog,2,.logfab[fab$b_fns],.logfab[fab$l_fna]);
    RETURN $CLOSE(FAB = logfab);
    END;
    pty__nolog
    END;


ROUTINE init =
    BEGIN
    BUILTIN
	movc3;


    LOCAL
        iosb : iostatus,
	stat;

    oldrwm = $setrwm(watflg = 1);
    stat = $ASSIGN(devnam = %ASCID 'SYS$INPUT',chan = tt_chan);
    $reterr(.stat);
    stat = $qiow(chan = .tt_chan,func = io$_sensemode,iosb = iosb,
                 p1 = old_termchar,p2 = %ALLOCATION(old_termchar));
    $reterr(.stat);
    $reterr(.iosb[status]);

    stat = $dclexh(desblk = desblk);
    .stat
    END;


GLOBAL ROUTINE exit =
    BEGIN
    LOCAL
	stat;
    stat = okexit();
    doexit = .stat;
    1
    END;



GLOBAL ROUTINE spawn =
    BEGIN
    EXTERNAL ROUTINE
	lib$spawn : ADDRESSING_MODE(GENERAL);

    LOCAL
	stat,
	command : REF BLOCK[8,BYTE] INITIAL(0);
    stat = cli$present(%ASCID 'COMMAND');
    IF .stat THEN
    BEGIN
    lib$get_vm(%REF(8),command);
    $init_dyndesc(command);
    stat = cli$get_value(%ASCID 'COMMAND',.command);
    IF NOT .stat THEN command = 0;
    END;
    IF NOT empty(ptyhead) THEN clearctrly();
    lib$spawn(.command);
    IF NOT empty(ptyhead) THEN setctrly();
    1
    END;

ROUTINE okexit =
    BEGIN
    LOCAL
	stat : INITIAL(1),
	messdesc : BLOCK[8, byte],
	ptyid : REF pty INITIAL(.ptyhead[0]);

    $init_dyndesc(messdesc);
    WHILE .ptyid NEQA ptyhead DO
	BEGIN
	lib$signal(pty__actpty,2,4,ptyid[ident]);
	stat = 0;
	ptyid = .ptyid[flink];
	END;
    .stat
    END;

ROUTINE main =
    BEGIN

    EXTERNAL
	ptyparse;

    EXTERNAL ROUTINE
        lib$establish : ADDRESSING_MODE(GENERAL),
        cli$dispatch : ADDRESSING_MODE(GENERAL),
	cli$dcl_parse : ADDRESSING_MODE(GENERAL);

    LOCAL
	stat;


!    lib$establish(conditionhandler);
    init();
    DO
	BEGIN
	stat = cli$dcl_parse(0,ptyparse,lib$get_input,
		             lib$get_input,%ASCID 'PTY> ');
	IF .stat THEN
	BEGIN
	stat = cli$dispatch();
	$messerr(.stat);
	END ELSE
	IF .stat EQL RMS$_EOF THEN
	  doexit = okexit();
	END
    UNTIL .doexit;
    IF .logopen THEN
      close() ELSE 1
    END;
END                           ! End of module
ELUDOM
$ say "Creating PTY.MAR"
$ create pty.mar
;   0001  0	!File : PTY.B32
;   0002  0	!This program allows you to create multiple PTYs, switching
;   0003  0	!between them, logging output to a file...
;   0004  0	!It assumes you have installed the PYDRIVER/TPDRIVER by
;   0005  0	!Dale Moore / Kevin Carosso & whoever.
;   0006  0	!
;   0007  0	!Author : Simen Gaure   X_GAURE_S%use.uio.uninett@tor.arpa
;   0008  0	!			X_GAURE_S@inger.arpa
;   0009  0	!Date : 30-Sep-1987
;   0010  0	!
;   0011  0	!Please report errors and/or suggestions to the above address.
;   0012  0	!
;   0013  0	!The sources contained herein can be distributed freely to anyone.
;   0014  0	!The author accepts no responsibility for any harm this program
;   0015  0	!might do to anything.
;   0016  0	!
;   0017  0	!You may modify any part of this program, but remember to 
;   0018  0	!make an entry in the history list.
;   0019  0	!
;   0020  0	!Modification history :
;   0021  0	!New entries on top of list.
;   0022  0	!
;   0023  0	!30-Sep-1987 : First version
;   0024  0	!
;   0025  0	
;   0026  0	MODULE pty (main = main) =
;   0027  1	BEGIN
;   0028  1	
;   0029  1	!
;   0030  1	! TABLE OF CONTENTS:
;   0031  1	!
;   0032  1	FORWARD ROUTINE
;   0033  1	    exithandler,
;   0034  1	    setctrly : NOVALUE,
;   0035  1	    clearctrly : NOVALUE,
;   0036  1	    set_term,
;   0037  1	    reset_term,
;   0038  1	    findpty,
;   0039  1	    flushbuffer : NOVALUE,
;   0040  1	    activate,
;   0041  1	    passivate,
;   0042  1	    passivateall : NOVALUE,
;   0043  1	    passivatesome : NOVALUE,
;   0044  1	    pty_input : NOVALUE,
;   0045  1	    logit,
;   0046  1	    newpty,
;   0047  1	    deletepty : NOVALUE,
;   0048  1	    init,
;   0049  1	    dopty,    
;   0050  1	    getident,
;   0051  1	    acceptpty,
;   0052  1	    break,
;   0053  1	    suppress,
;   0054  1	    help,
;   0055  1	    showbreak,
;   0056  1	    ptystatus,
;   0057  1	    log,
;   0058  1	    close,
;   0059  1	    remove,
;   0060  1	    connect,
;   0061  1	    spawn,
;   0062  1	    exit,
;   0063  1	    okexit;
;   0064  1	!
;   0065  1	! INCLUDE FILES:
;   0066  1	!
;   0067  1	LIBRARY 'sys$library:starlet';
;   0068  1	!
;   0069  1	! MACROS:
;   0070  1	!
;   0071  1	
;   0072  1	
;   0073  1	MACRO
;   0074  1	
; M 0075  1	    iostatus =
;   0076  1		BLOCK[8,BYTE] FIELD( iosbfields) %,
;   0077  1	    
;   0078  1	!output error approriate error message if status is even
;   0079  1	
; M 0080  1	    $messerr(status) =
; M 0081  1	        IF NOT status THEN
; M 0082  1		BEGIN
; M 0083  1	
; M 0084  1		LOCAL
; M 0085  1		    messdesc : BLOCK[8,byte];
; M 0086  1		$init_dyndesc(messdesc);
; M 0087  1		stat = lib$sys_getmsg(%ref(status),0,messdesc);
; M 0088  1		IF .stat THEN
; M 0089  1		  lib$put_output(messdesc);
;   0090  1		END %,
;   0091  1	
; M 0092  1	    $reterr (status) = 
;   0093  1	        IF NOT status THEN return status %;
;   0094  1	
;   0095  1	!Layout of one PTY
;   0096  1	FIELD ptyfields =
;   0097  1	    SET
;   0098  1	    flink = [0,0,32,0],	!Forward link
;   0099  1	    blink = [4,0,32,0], !Backward link
;   0100  1	    bufadr = [8,0,32,0],    !Address of read buffer
;   0101  1	    iosbadr = [12,0,32,0],  !Address of iosb
;   0102  1	    chan = [16,0,16,0],	    !Channel number
;   0103  1	    buflen = [18,0,16,0],   !number of bytes in buffer
;   0104  1	    buffer = [20,0,32,0],   !Address of write buffer
;   0105  1	    ident  = [24,0,32,0],    !Pty identification
;   0106  1	    flags  = [28,0,32,0],   !Pty control flags
;   0107  1	    accept = [28,0,1,0],    !Accept output from pty when at command level
;   0108  1	    active = [28,1,1,0],     !Pty writes output to terminal
;   0109  1	    xoffed = [28,2,1,0],    !Pty writes to much, I have sent a ^S.
;   0110  1	    displayid = [32,4,1,0]
;   0111  1	    TES;
;   0112  1	
;   0113  1	LITERAL
;   0114  1	!length in bytes of one PTY.
;   0115  1	    ptylen = 36;
;   0116  1	
;   0117  1	
;   0118  1	!allocate and initialize one PTY
; M 0119  1	MACRO makepty(ptyadr,id) =
; M 0120  1		BEGIN
; M 0121  1	        LOCAL
; M 0122  1	            ptyid : REF pty,
; M 0123  1		    stat;
; M 0124  1	
; M 0125  1	        stat = lib$get_vm(%ref(ptylen),ptyadr);
; M 0126  1	        $messerr(.stat);
; M 0127  1		stat = lib$get_vm(%ref(ptybufsiz),ptyadr[bufadr]);
; M 0128  1	        $messerr(.stat);
; M 0129  1	        stat = lib$get_vm(%ref(8),ptyadr[iosbadr]);
; M 0130  1	        $messerr(.stat);
; M 0131  1	        stat = lib$get_vm(%ref(ptybufsiz),ptyadr[buffer]);
; M 0132  1	        $messerr(.stat);
; M 0133  1	        ptyadr[flags] = 0;
; M 0134  1	        ptyadr[buflen] = 0;
; M 0135  1	        ptyadr[accept] = 0;
; M 0136  1		ptyadr[xoffed] = 0;
; M 0137  1	        ptyadr[ident] = id;
; M 0138  1	        ptyadr[displayid] = 0;
;   0139  1	        END %,
;   0140  1	
; M 0141  1	    $fixdesc(buffer) =
; M 0142  1		BLOCK[8,byte] PRESET
; M 0143  1				  ([dsc$b_class] = dsc$k_class_s,
; M 0144  1				   [dsc$w_length] = %ALLOCATION(buffer),
;   0145  1				   [dsc$a_pointer] = buffer)%,
;   0146  1	
; M 0147  1	    empty(head) =
; M 0148  1	        BEGIN
; M 0149  1		(.head[0] EQLA .head[1])
;   0150  1		END %;
;   0151  1	
;   0152  1	
;   0153  1	
;   0154  1	
;   0155  1	LITERAL
;   0156  1	    logbufsiz = 2048,  !size of the buffer we use for logging
;   0157  1	
;   0158  1	    ptybufsiz = 1024,  !size of the buffer that receives output from PTY
;   0159  1	    xoff = %C'S' - %C'A' + 1,  !^S
;   0160  1	    xon = %C'Q' - %C'A' + 1,   !^Q
;   0161  1	    xofflim = ptybufsiz*3/4;   !highwater mark in buffer
;   0162  1	
;   0163  1	MACRO
; M 0164  1	    pty =
;   0165  1		BLOCK[ptylen,byte] field(ptyfields) %;
;   0166  1	
;   0167  1	!layout of a terminal iosb
;   0168  1	FIELD iosbfields =
;   0169  1	    SET
;   0170  1	    status = [0,0,16,0],
;   0171  1	    count = [2,0,16,0],
;   0172  1	    terminator = [4,0,16,0],
;   0173  1	    termsize = [6,0,16,0]
;   0174  1	    TES;
;   0175  1	!
;   0176  1	! EQUATED SYMBOLS:
;   0177  1	!
;   0178  1	!
;   0179  1	! OWN STORAGE:
;   0180  1	!
;   0181  1	OWN
;   0182  1	    oldrwm,  !resource wait mode when program was started
;   0183  1	    crlf : VECTOR[2,byte] PRESET
;   0184  1				      ([0] = 13,
;   0185  1				       [1] = 10),
;   0186  1	    loglen : word INITIAL(0),  !bytes in log buffer
;   0187  1	    logbuf : BLOCK[logbufsiz,BYTE],  !logbuffer
; P 0188  1	    logfab : $FAB(rfm = var,   !FAB for the log file
; P 0189  1			  rat = cr,
; P 0190  1			  fac = <put>,
;   0191  1			  fop = <cif>),
; P 0192  1	    lograb : $RAB(FAB = logfab,  !RAB for the log file
; P 0193  1			  rop = eof,
; P 0194  1			  rbf = logbuf,
;   0195  1			  rsz = %ALLOCATION(logbuf)),
;   0196  1	    logopen : word INITIAL(0),   !is the log file open
;   0197  1	    currpty : REF pty,		 !current PTY
;   0198  1	    ptyhead : VECTOR[2,long] 
;   0199  1	              INITIAL(ptyhead,ptyhead), !queue head for the PTYs
;   0200  1	    exitreason : VOLATILE,
;   0201  1	    desblk : BLOCK[4,LONG] 
;   0202  1	             INITIAL(0,exithandler,0,exitreason), !descriptor block
;   0203  1							  !for exit handler
;   0204  1	    old_termchar : BLOCK[12,BYTE],  !initial terminal characteristics
;   0205  1	    breakchar : byte INITIAL(28),   !break character
;   0206  1	    doexit : byte INITIAL(0),
;   0207  1	    astchan : byte,		    !channel to TTY for ^Y ast
;   0208  1	    tt_char : byte,		    !character read from TTY
;   0209  1	    tt_chan : word,		    !Channel to read/write from TTY	
;   0210  1	    tt_iosb : iostatus;		    !iosb for tty
;   0211  1	
;   0212  1	!
;   0213  1	! EXTERNAL REFERENCES:
;   0214  1	!
;   0215  1	EXTERNAL ROUTINE
;   0216  1	    lib$pause : ADDRESSING_MODE(GENERAL),
;   0217  1	    lib$sys_getmsg : ADDRESSING_MODE(GENERAL),
;   0218  1	    lib$sys_fao : ADDRESSING_MODE(GENERAL),
;   0219  1	    lib$put_output : ADDRESSING_MODE(GENERAL),
;   0220  1	    lib$getjpi : ADDRESSING_MODE(GENERAL),
;   0221  1	    lib$get_input : ADDRESSING_MODE(GENERAL),
;   0222  1	    lib$analyze_sdesc : ADDRESSING_MODE(GENERAL),
;   0223  1	    cli$present : ADDRESSING_MODE(GENERAL),
;   0224  1	    cli$get_value : ADDRESSING_MODE(GENERAL),
;   0225  1	    lib$signal : ADDRESSING_MODE(GENERAL),
;   0226  1	    lib$free_vm : ADDRESSING_MODE(GENERAL),
;   0227  1	    lib$get_vm : ADDRESSING_MODE(GENERAL);
;   0228  1	EXTERNAL LITERAL
;   0229  1	    pty__breakis,
;   0230  1	    pty__connect,
;   0231  1	    pty__accept,
;   0232  1	    pty__refuse,
;   0233  1	    pty__logging,
;   0234  1	    pty__nolog,
;   0235  1	    pty__closelog,
;   0236  1	    pty__logopen,
;   0237  1	    pty__nopty,
;   0238  1	    pty__actpty;
;   0239  1	
;   0240  1	%SBTTL 'Exithandler'
;   0241  1	
;   0242  1	
;   0243  1	ROUTINE exithandler(reason) =
;   0244  2	    BEGIN
;   0245  2	    LOCAL
;   0246  2		stat;
;   0247  2	!reset resource wait mode
;   0248  2	    $setrwm(watflg = (IF .oldrwm eqlu ss$_wasclr THEN 0 ELSE 1));
;   0249  2	!reset terminal charcteristics
;   0250  2	    reset_term()
;   0251  2	    
;   0252  1	    END;


	.TITLE  PTY

	.PSECT  $OWN$,NOEXE,2

;OLDRWM
U.32:	.BLKB   4									   ;				      00000
;CRLF
U.33:	.BYTE   13, 10				 ;				      	    			      0A  0D  00004
;LOGLEN
U.34:	.WORD   0				 ;				      	    				0000  00006
;LOGBUF
U.35:	.BLKB   2048									   ;				      00008
;LOGFAB
U.36:	.BYTE   3				 ;				      	    				  03  00808
	.BYTE   80				 ;				      	    				  50  00809
	.WORD   0				 ;				      	    				0000  0080A
	.LONG   33554432			 ;				      	    			    02000000  0080C
	.LONG   0				 ;				      	    			    00000000  00810
	.LONG   0				 ;				      	    			    00000000  00814
	.LONG   0				 ;				      	    			    00000000  00818
	.WORD   0				 ;				      	    				0000  0081C
	.BYTE   1				 ;				      	    				  01  0081E
	.BYTE   0				 ;				      	    				  00  0081F
	.LONG   0				 ;				      	    			    00000000  00820
	.BYTE   0				 ;				      	    				  00  00824
	.BYTE   0				 ;				      	    				  00  00825
	.BYTE   2				 ;				      	    				  02  00826
	.BYTE   2				 ;				      	    				  02  00827
	.LONG   0				 ;				      	    			    00000000  00828
	.LONG   0				 ;				      	    			    00000000  0082C
	.LONG   0				 ;				      	    			    00000000  00830
	.LONG   0				 ;				      	    			    00000000  00834
	.LONG   0				 ;				      	    			    00000000  00838
	.BYTE   0				 ;				      	    				  00  0083C
	.BYTE   0				 ;				      	    				  00  0083D
	.WORD   0				 ;				      	    				0000  0083E
	.LONG   0				 ;				      	    			    00000000  00840
	.WORD   0				 ;				      	    				0000  00844
	.BYTE   0				 ;				      	    				  00  00846
	.BYTE   0				 ;				      	    				  00  00847
	.LONG   0				 ;				      	    			    00000000  00848
	.LONG   0				 ;				      	    			    00000000  0084C
	.WORD   0				 ;				      	    				0000  00850
	.BYTE   0				 ;				      	    				  00  00852
	.BYTE   0				 ;				      	    				  00  00853
	.LONG   0				 ;				      	    			    00000000  00854
;LOGRAB
U.37:	.BYTE   1				 ;				      	    				  01  00858
	.BYTE   68				 ;				      	    				  44  00859
	.WORD   0				 ;				      	    				0000  0085A
	.LONG   256				 ;				      	    			    00000100  0085C
	.LONG   0				 ;				      	    			    00000000  00860
	.LONG   0				 ;				      	    			    00000000  00864
	.WORD   0[3]				 ;				      	    				0000# 00868
	.WORD   0				 ;				      	    				0000  0086E
	.LONG   0				 ;				      	    			    00000000  00870
	.WORD   0				 ;				      	    				0000  00874
	.BYTE   0				 ;				      	    				  00  00876
	.BYTE   0				 ;				      	    				  00  00877
	.WORD   0				 ;				      	    				0000  00878
	.WORD   2048				 ;				      	    				0800  0087A
	.LONG   0				 ;				      	    			    00000000  0087C
	.ADDRESS U.35				 ;				      	    			    00000000' 00880
	.LONG   0				 ;				      	    			    00000000  00884
	.LONG   0				 ;				      	    			    00000000  00888
	.BYTE   0				 ;				      	    				  00  0088C
	.BYTE   0				 ;				      	    				  00  0088D
	.BYTE   0				 ;				      	    				  00  0088E
	.BYTE   0				 ;				      	    				  00  0088F
	.LONG   0				 ;				      	    			    00000000  00890
	.ADDRESS U.36				 ;				      	    			    00000000' 00894
	.LONG   0				 ;				      	    			    00000000  00898
;LOGOPEN
U.38:	.WORD   0				 ;				      	    				0000  0089C
	.BLKB   2									   ;				      0089E
;CURRPTY
U.39:	.BLKB   4									   ;				      008A0
;PTYHEAD
U.40:	.ADDRESS U.40, U.40			 ;				      	    		  00000000' 00000000' 008A4
;EXITREASON
U.41:	.BLKB   4									   ;				      008AC
;DESBLK
U.42:	.LONG   0				 ;				      	    			    00000000  008B0
	.ADDRESS U.1				 ;				      	    			    00000000' 008B4
	.LONG   0				 ;				      	    			    00000000  008B8
	.ADDRESS U.41				 ;				      	    			    00000000' 008BC
;OLD_TERMCHAR
U.43:	.BLKB   12									   ;				      008C0
;BREAKCHAR
U.44:	.BYTE   28				 ;				      	    				  1C  008CC
;DOEXIT
U.45:	.BYTE   0				 ;				      	    				  00  008CD
;ASTCHAN
U.46:	.BLKB   1									   ;				      008CE
;TT_CHAR
U.47:	.BLKB   1									   ;				      008CF
;TT_CHAN
U.48:	.BLKB   2									   ;				      008D0
	.BLKB   2									   ;				      008D2
;TT_IOSB
U.49:	.BLKB   8									   ;				      008D4

	.EXTRN  LIB$PAUSE, LIB$SYS_GETMSG, LIB$SYS_FAO, LIB$PUT_OUTPUT, LIB$GETJPI, LIB$GET_INPUT
	.EXTRN  LIB$ANALYZE_SDESC, CLI$PRESENT, CLI$GET_VALUE, LIB$SIGNAL, LIB$FREE_VM, LIB$GET_VM
	.EXTRN  PTY__BREAKIS, PTY__CONNECT, PTY__ACCEPT, PTY__REFUSE, PTY__LOGGING, PTY__NOLOG, PTY__CLOSELOG
	.EXTRN  PTY__LOGOPEN, PTY__NOPTY, PTY__ACTPTY, SYS$SETRWM

	.PSECT  $CODE$,NOWRT,2

;EXITHANDLER
U.1:	.WORD   ^M<>				 ;Save nothing			       0243 			       0000   00000
	CMPL    W^U.32, #1			 ;U.32, #1			       0248 	       01     0000'  CF  D1   00002
	BNEQ    1$				 ;1$				      	    			     04  12   00007
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00009
	BRB     2$				 ;2$				      	    			     02  11   0000B
1$:	PUSHL   #1				 ;#1				      	    			     01  DD   0000D
2$:	CALLS   #1, G^SYS$SETRWM		 ;#1, SYS$SETRWM		      	    00000000G  00	     01  FB   0000F
	CALLS   #0, W^U.5			 ;#0, U.5			       0250 	0000V  CF	     00  FB   00016
	RET     				 ;				       0252 				 04   0001B

; Routine Size:  28 bytes,    Routine Base:  $CODE$ + 0000


;   0253  1	
;   0254  1	
;   0255  1	%SBTTL 'interception of ctrl/y & term characteristics'
;   0256  1	
;   0257  1	ROUTINE ctrly : NOVALUE =
;   0258  2	    BEGIN
;   0259  2	
;   0260  2	!tell user about active PTYs
;   0261  2	    okexit();  
;   0262  2	
;   0263  2	!Tell user how to continue
; L 0264  2	    lib$put_output(%ASCID %STRING(%char(7),
;   0265  2			    'Type continue to resume',%char(7,7)));
;   0266  2	!simulate ^Y
;   0267  2	    lib$pause();
;   0268  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.AAB:	.ASCII  <7>\Type continue to resume\<7><7><0><0>
						 ;				      	      6F  63  20  65  70  79  54  07  00000
						 ;					      74  20  65  75  6E  69  74  6E  00008
						 ;					      65  6D  75  73  65  72  20  6F  00010
						 ;					    		      00  00  07  07  00018
P.AAA:	.LONG   17694746			 ;				      	    			    010E001A  0001C
	.ADDRESS P.AAB				 ;				      	    			    00000000' 00020



	.PSECT  $CODE$,NOWRT,2

;CTRLY
U.50:	.WORD   ^M<>				 ;Save nothing			       0257 			       0000   00000
	CALLS   #0, W^U.31			 ;#0, U.31			       0261 	0000V  CF	     00  FB   00002
	PUSHAB  W^P.AAA				 ;P.AAA				       0265 		      0000'  CF  9F   00007
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   0000B
	CALLS   #0, G^LIB$PAUSE			 ;#0, LIB$PAUSE			       0267 00000000G  00	     00  FB   00012
	RET     				 ;				       0268 				 04   00019

; Routine Size:  26 bytes,    Routine Base:  $CODE$ + 001C


;   0269  1	
;   0270  1	
;   0271  1	!^Y & ^C trap
;   0272  1	ROUTINE setctrly : NOVALUE =
;   0273  2	    BEGIN
;   0274  2	    $assign(devnam = %ASCID 'SYS$INPUT',chan = astchan);
;   0275  2	    !Set out of band ast for ^C and ^Y
; P 0276  2	    $qiow(chan = .astchan,func=io$_setmode+io$m_outband+
; P 0277  2		  io$m_tt_abort + io$m_include,
;   0278  2		  p1 = ctrly,p2 = uplit(0,%X '2000008'));
;   0279  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.AAD:	.ASCII  \SYS$INPUT\<0><0><0>		 ;				      	      55  50  4E  49  24  53  59  53  00024
						 ;					    		      00  00  00  54  0002C
P.AAC:	.LONG   17694729			 ;				      	    			    010E0009  00030
	.ADDRESS P.AAD				 ;				      	    			    00000000' 00034
P.AAE:	.LONG   0, 33554440			 ;				      	    		  02000008  00000000  00038

	.EXTRN  SYS$ASSIGN, SYS$QIOW

	.PSECT  $CODE$,NOWRT,2

;SETCTRLY
U.2:	.WORD   ^M<>				 ;Save nothing			       0272 			       0000   00000
	CLRQ    -(SP)				 ;-(SP)				       0274 			     7E  7C   00002
	PUSHAB  W^U.46				 ;U.46				      	    		      0000'  CF  9F   00004
	PUSHAB  W^P.AAC				 ;P.AAC				      	    		      0000'  CF  9F   00008
	CALLS   #4, G^SYS$ASSIGN		 ;#4, SYS$ASSIGN		      	    00000000G  00	     04  FB   0000C
	CLRQ    -(SP)				 ;-(SP)				       0278 			     7E  7C   00013
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00015
	PUSHAB  W^P.AAE				 ;P.AAE				      	    		      0000'  CF  9F   00017
	PUSHAB  B^U.50				 ;U.50				      	    			C8   AF  9F   0001B
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0001E
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00020
	MOVZWL  #7203, -(SP)			 ;#7203, -(SP)			      	    	       7E     1C23   8F  3C   00022
	MOVZBL  W^U.46, -(SP)			 ;U.46, -(SP)			      	    	       7E     0000'  CF  9A   00027
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0002C
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   0002E
	RET     				 ;				       0279 				 04   00035

; Routine Size:  54 bytes,    Routine Base:  $CODE$ + 0036


;   0280  1	
;   0281  1	
;   0282  1	ROUTINE clearctrly : NOVALUE =
;   0283  2	    BEGIN
;   0284  2	    $dassgn(chan = .astchan);
;   0285  1	    END;



	.EXTRN  SYS$DASSGN

;CLEARCTRLY
U.3:	.WORD   ^M<>				 ;Save nothing			       0282 			       0000   00000
	MOVZBL  W^U.46, -(SP)			 ;U.46, -(SP)			       0284 	       7E     0000'  CF  9A   00002
	CALLS   #1, G^SYS$DASSGN		 ;#1, SYS$DASSGN		      	    00000000G  00	     01  FB   00007
	RET     				 ;				       0285 				 04   0000E

; Routine Size:  15 bytes,    Routine Base:  $CODE$ + 006C


;   0286  1	
;   0287  1	!set appropriate term chars for PTY operation
;   0288  1	ROUTINE set_term =
;   0289  2	    BEGIN
;   0290  2	    BUILTIN
;   0291  2		movc3;
;   0292  2	
;   0293  2	    LOCAL
;   0294  2	        iosb : iostatus,
;   0295  2	        stat,
;   0296  2		termchar : BLOCK[%ALLOCATION(old_termchar),BYTE],
;   0297  2		charlen : word INITIAL(%ALLOCATION(termchar));
;   0298  2	    BIND
;   0299  2		chars = termchar + 4 : BLOCK[3, byte],
;   0300  2		extchars = termchar + 8 : BLOCK[8, byte];
;   0301  2	
;   0302  2	!modify initial term chars
;   0303  2	    MOVC3(%REF(%ALLOCATION(old_termchar)), old_termchar, termchar);   
;   0304  2	    chars[tt$v_noecho] = 1;
;   0305  2	    chars[tt$v_hostsync] = 0;
;   0306  2	    chars[tt$v_ttsync] = 0;
;   0307  2	    extchars[tt2$v_pasthru] = 1;
;   0308  2	    
; P 0309  2	    stat = $qiow(chan = .tt_chan,func=io$_setmode,iosb = iosb,
;   0310  2			 p1 = termchar,p2 = %ALLOCATION(termchar));
;   0311  2	    IF .stat THEN stat = .iosb[status];
;   0312  2	    .stat
;   0313  1	    END;





;SET_TERM
U.4:	.WORD   ^M<R2,R3,R4,R5>			 ;Save R2,R3,R4,R5		       0288 			       003C   00000
	SUBL2   #20, SP				 ;#20, SP			      	    	       5E	     14  C2   00002
	MOVW    #12, R0				 ;#12, CHARLEN			       0289 	       50	     0C  B0   00005
	MOVC3   #12, W^U.43, (SP)		 ;#12, U.43, TERMCHAR		       0303 	0000'  CF	     0C  28   00008
						 ;					    			     6E       0000D
	BISB2   #2, 4(SP)			 ;#2, CHARS			       0304 	  04   AE	     02  88   0000E
	BICB2   #48, 4(SP)			 ;#48, CHARS			       0305 	  04   AE	     30  8A   00012
	BISB2   #4, 10(SP)			 ;#4, EXTCHARS+2		       0307 	  0A   AE	     04  88   00016
	CLRQ    -(SP)				 ;-(SP)				       0310 			     7E  7C   0001A
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0001C
	PUSHL   #12				 ;#12				      	    			     0C  DD   0001E
	PUSHAB  20(SP)				 ;TERMCHAR			      	    			14   AE  9F   00020
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00023
	PUSHAB  44(SP)				 ;IOSB				      	    			2C   AE  9F   00025
	PUSHL   #35				 ;#35				      	    			     23  DD   00028
	MOVZWL  W^U.48, -(SP)			 ;U.48, -(SP)			      	    	       7E     0000'  CF  3C   0002A
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0002F
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   00031
	BLBC    R0, 1$				 ;STAT, 1$			       0311 	       04	     50  E9   00038
	MOVZWL  12(SP), R0			 ;IOSB, STAT			      	    	       50	0C   AE  3C   0003B
1$:	RET     				 ;				       0313 				 04   0003F

; Routine Size:  64 bytes,    Routine Base:  $CODE$ + 007B


;   0314  1	
;   0315  1	
;   0316  1	!reset to initial term chars
;   0317  1	ROUTINE reset_term =
;   0318  2	    BEGIN
;   0319  2	    LOCAL
;   0320  2		iosb : iostatus,
;   0321  2		stat;
;   0322  2	
; P 0323  2	    stat = $qiow(chan = .tt_chan,func = io$_setmode,iosb = iosb,
;   0324  2		         p1 = old_termchar,p2 = %ALLOCATION(old_termchar));
;   0325  2	    $reterr(.stat);
;   0326  2	    .iosb[status]
;   0327  1	    END;





;RESET_TERM
U.5:	.WORD   ^M<>				 ;Save nothing			       0317 			       0000   00000
	SUBL2   #8, SP				 ;#8, SP			      	    	       5E	     08  C2   00002
	CLRQ    -(SP)				 ;-(SP)				       0324 			     7E  7C   00005
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00007
	PUSHL   #12				 ;#12				      	    			     0C  DD   00009
	PUSHAB  W^U.43				 ;U.43				      	    		      0000'  CF  9F   0000B
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0000F
	PUSHAB  32(SP)				 ;IOSB				      	    			20   AE  9F   00011
	PUSHL   #35				 ;#35				      	    			     23  DD   00014
	MOVZWL  W^U.48, -(SP)			 ;U.48, -(SP)			      	    	       7E     0000'  CF  3C   00016
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0001B
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   0001D
	BLBC    R0, 1$				 ;STAT, 1$			       0325 	       03	     50  E9   00024
	MOVZWL  (SP), R0			 ;IOSB, R0			       0326 	       50	     6E  3C   00027
1$:	RET     				 ;				       0327 				 04   0002A

; Routine Size:  43 bytes,    Routine Base:  $CODE$ + 00BB


;   0328  1	
;   0329  1	
;   0330  1	
;   0331  1	%SBTTL 'activation of ptys'
;   0332  1	ROUTINE activate(ptyadr) =
;   0333  2	    BEGIN
;   0334  2	    LOCAL
;   0335  2		ptyid : REF pty INITIAL(.ptyadr);
;   0336  2	!write pending output to TTY
;   0337  2	    flushbuffer(.ptyid);
;   0338  2	!Set active status 
;   0339  2	    ptyid[active] = 1
;   0340  1	    END;





;ACTIVATE
U.8:	.WORD   ^M<R2>				 ;Save R2			       0332 			       0004   00000
	MOVL    4(AP), R2			 ;PTYADR, PTYID			       0335 	       52	04   AC  D0   00002
	PUSHL   R2				 ;PTYID				       0337 			     52  DD   00006
	CALLS   #1, W^U.7			 ;#1, U.7			      	    	0000V  CF	     01  FB   00008
	BISB2   #2, 28(R2)			 ;#2, 28(PTYID)			       0339 	  1C   A2	     02  88   0000D
	MOVL    #1, R0				 ;#1, R0			       0340 	       50	     01  D0   00011
	RET     				 ;				      	    				 04   00014

; Routine Size:  21 bytes,    Routine Base:  $CODE$ + 00E6


;   0341  1	
;   0342  1	
;   0343  1	ROUTINE passivate(ptyadr) =
;   0344  2	    BEGIN
;   0345  2	    LOCAL
;   0346  2		ptyid :REF pty INITIAL(.ptyadr);
;   0347  2	!clear active status
;   0348  2	    ptyid[active] = 0;
;   0349  2	    1
;   0350  1	    END;





;PASSIVATE
U.9:	.WORD   ^M<>				 ;Save nothing			       0343 			       0000   00000
	MOVL    4(AP), R0			 ;PTYADR, PTYID			       0346 	       50	04   AC  D0   00002
	BICB2   #2, 28(R0)			 ;#2, 28(PTYID)			       0348 	  1C   A0	     02  8A   00006
	MOVL    #1, R0				 ;#1, R0			       0350 	       50	     01  D0   0000A
	RET     				 ;				      	    				 04   0000D

; Routine Size:  14 bytes,    Routine Base:  $CODE$ + 00FB


;   0351  1	
;   0352  1	
;   0353  1	!passivate all PTYs
;   0354  1	ROUTINE passivateall : NOVALUE =
;   0355  2	    BEGIN
;   0356  2	    LOCAL
;   0357  2		ptyid : REF pty INITIAL(.ptyhead[0]);
;   0358  2	
;   0359  2	    WHILE .ptyid NEQA ptyhead DO
;   0360  3	    BEGIN
;   0361  3		passivate(.ptyid);
;   0362  3		ptyid = .ptyid[flink];
;   0363  2	    END;
;   0364  1	    END;





;PASSIVATEALL
U.10:	.WORD   ^M<R2>				 ;Save R2			       0354 			       0004   00000
	MOVL    W^U.40, R2			 ;U.40, PTYID			       0357 	       52     0000'  CF  D0   00002
	BRB     2$				 ;2$				       0359 			     09  11   00007
1$:	PUSHL   R2				 ;PTYID				       0361 			     52  DD   00009
	CALLS   #1, B^U.9			 ;#1, U.9			      	    	  E3   AF	     01  FB   0000B
	MOVL    (R2), R2			 ;(PTYID), PTYID		       0362 	       52	     62  D0   0000F
2$:	MOVAB   W^U.40, R0			 ;U.40, R0			       0359 	       50     0000'  CF  9E   00012
	CMPL    R2, R0				 ;PTYID, R0			      	    	       50	     52  D1   00017
	BNEQ    1$				 ;1$				      	    			     ED  12   0001A
	RET     				 ;				       0364 				 04   0001C

; Routine Size:  29 bytes,    Routine Base:  $CODE$ + 0109


;   0365  1	
;   0366  1	
;   0367  1	!Passivate all PTYs that can't accept output at command level
;   0368  1	ROUTINE passivatesome : NOVALUE =
;   0369  2	    BEGIN
;   0370  2	    LOCAL
;   0371  2		ptyid : REF pty INITIAL(.ptyhead[0]);
;   0372  2	
;   0373  2	    WHILE .ptyid NEQA ptyhead DO
;   0374  3	    BEGIN
;   0375  3		IF NOT .ptyid[accept] THEN
;   0376  3		  passivate(.ptyid);
;   0377  3		ptyid = .ptyid[flink];
;   0378  2	    END;
;   0379  1	    END;





;PASSIVATESOME
U.11:	.WORD   ^M<R2>				 ;Save R2			       0368 			       0004   00000
	MOVL    W^U.40, R2			 ;U.40, PTYID			       0371 	       52     0000'  CF  D0   00002
	BRB     3$				 ;3$				       0373 			     0D  11   00007
1$:	BLBS    28(R2), 2$			 ;28(PTYID), 2$			       0375 	       06	1C   A2  E8   00009
	PUSHL   R2				 ;PTYID				       0376 			     52  DD   0000D
	CALLS   #1, B^U.9			 ;#1, U.9			      	    	  C2   AF	     01  FB   0000F
2$:	MOVL    (R2), R2			 ;(PTYID), PTYID		       0377 	       52	     62  D0   00013
3$:	MOVAB   W^U.40, R0			 ;U.40, R0			       0373 	       50     0000'  CF  9E   00016
	CMPL    R2, R0				 ;PTYID, R0			      	    	       50	     52  D1   0001B
	BNEQ    1$				 ;1$				      	    			     E9  12   0001E
	RET     				 ;				       0379 				 04   00020

; Routine Size:  33 bytes,    Routine Base:  $CODE$ + 0126


;   0380  1	
;   0381  1	
;   0382  1	%SBTTL 'read from pty'
;   0383  1	ROUTINE pty_input(ptyadr) : NOVALUE =
;   0384  2	    BEGIN
;   0385  2	    BUILTIN
;   0386  2		movc3;
;   0387  2	
;   0388  2	    LOCAL
;   0389  2	        ptyid : REF pty,
;   0390  2	        iosb : REF iostatus,
;   0391  2		stat;
;   0392  2	
;   0393  2	    ptyid = .ptyadr;
;   0394  2	    iosb = .ptyid[iosbadr];
;   0395  2	    IF .iosb[status] EQLU ss$_abort THEN RETURN;
;   0396  2	    $messerr(.iosb[status]);
;   0397  2	    IF .ptyid[active] THEN 
;   0398  3	    BEGIN
;   0399  3	        !Very well, the pty is active, write output to terminal
; P 0400  3		stat = $qiow(chan = .tt_chan,func = io$_writevblk,
;   0401  3			     p1 = .ptyid[bufadr],p2 = .iosb[count]);
;   0402  3		$messerr(.stat);
;   0403  3		!log the output
;   0404  3	        stat = logit(.ptyid[bufadr],.iosb[count]);
;   0405  3		$messerr(.stat);
;   0406  2	    END ELSE
;   0407  3		BEGIN
;   0408  3		!The pty is not active, buffer output 
;   0409  3		LOCAL
;   0410  3		    charstomove : word,
;   0411  3		    bufleft : word;
;   0412  3	
;   0413  3	!If buffer will be full, flush it to terminal
;   0414  3		IF .ptyid[buflen] + .iosb[count] GTR ptybufsiz THEN
;   0415  3	          flushbuffer(.ptyid);
;   0416  3	
;   0417  3	!move characters to buffer
;   0418  3		bufleft = ptybufsiz - .ptyid[buflen];
;   0419  3		charstomove = MIN(.bufleft,.iosb[count]);
;   0420  3		MOVC3(charstomove, 
;   0421  3		      .ptyid[bufadr],
;   0422  3		      .ptyid[buffer]+.ptyid[buflen]);
;   0423  3		ptyid[buflen] = .ptyid[buflen] + .charstomove;
;   0424  3	
;   0425  3	!If highwater is reached, XOFF the PTY
;   0426  3		If (.ptyid[buflen] GTRU xofflim) THEN
;   0427  4		  BEGIN
;   0428  4	          !Pty writes to much, xoff it
; P 0429  4		  $qiow(chan = .ptyid[chan],func = io$_writevblk,
;   0430  4		        p1 = %ref(xoff),p2 = 1);
;   0431  4		  ptyid[xoffed] = 1
;   0432  3		  END;
;   0433  2		END;
;   0434  2	
;   0435  2	!reenable the read request to the PTY
; P 0436  2	    stat = $qio(chan = .ptyid[chan],func = io$_readvblk,
; P 0437  2			iosb = .ptyid[iosbadr],astadr = pty_input,astprm = .ptyid,
;   0438  2	                p1 = .ptyid[bufadr],p2 = ptybufsiz);
;   0439  2	    $messerr(.stat);
;   0440  1	    END;



	.EXTRN  SYS$QIO

;PTY_INPUT
U.12:	.WORD   ^M<R2,R3,R4,R5,R6,R7,R8>	 ;Save R2,R3,R4,R5,R6,R7,R8	       0383 			       01FC   00000
	SUBL2   #12, SP				 ;#12, SP			      	    	       5E	     0C  C2   00002
	MOVL    4(AP), R6			 ;PTYADR, PTYID			       0393 	       56	04   AC  D0   00005
	MOVL    12(R6), R2			 ;12(PTYID), IOSB		       0394 	       52	0C   A6  D0   00009
	CMPW    (R2), #44			 ;(IOSB), #44			       0395 	       2C	     62  B1   0000D
	BNEQ    1$				 ;1$				      	    			     01  12   00010
	RET     				 ;				      	    				 04   00012
1$:	BLBS    (R2), 2$			 ;(IOSB), 2$			       0396 	       2E	     62  E8   00013
	MOVL    #34471936, 4(SP)		 ;#34471936, MESSDESC		      	    	  04   AE 020E0000   8F  D0   00016
	CLRL    8(SP)				 ;MESSDESC+4			      	    			08   AE  D4   0001E
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   00021
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00024
	MOVZWL  (R2), 8(SP)			 ;(IOSB), 8(SP)			      	    	  08   AE	     62  3C   00026
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   0002A
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   0002D
	MOVL    R0, R7				 ;R0, STAT			      	    	       57	     50  D0   00034
	BLBC    R7, 2$				 ;STAT, 2$			      	    	       0A	     57  E9   00037
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   0003A
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   0003D
2$:	BBS     #1, 28(R6), 3$			 ;#1, 28(PTYID), 3$		       0397 	  1C   A6	     01  E0   00044
						 ;					    			     03       00048
	BRW     6$				 ;6$				      	    			   0097  31   00049
3$:	CLRQ    -(SP)				 ;-(SP)				       0401 			     7E  7C   0004C
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0004E
	MOVZWL  2(R2), -(SP)			 ;2(IOSB), -(SP)		      	    	       7E	02   A2  3C   00050
	PUSHL   8(R6)				 ;8(PTYID)			      	    			08   A6  DD   00054
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00057
	MOVQ    #48, -(SP)			 ;#48, -(SP)			      	    	       7E	     30  7D   00059
	MOVZWL  W^U.48, -(SP)			 ;U.48, -(SP)			      	    	       7E     0000'  CF  3C   0005C
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00061
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   00063
	MOVL    R0, R7				 ;R0, STAT			      	    	       57	     50  D0   0006A
	BLBS    R7, 4$				 ;STAT, 4$			       0402 	       2E	     57  E8   0006D
	MOVL    #34471936, 4(SP)		 ;#34471936, MESSDESC		      	    	  04   AE 020E0000   8F  D0   00070
	CLRL    8(SP)				 ;MESSDESC+4			      	    			08   AE  D4   00078
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   0007B
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0007E
	MOVL    R7, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     57  D0   00080
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   00084
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   00087
	MOVL    R0, R7				 ;R0, STAT			      	    	       57	     50  D0   0008E
	BLBC    R7, 4$				 ;STAT, 4$			      	    	       0A	     57  E9   00091
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   00094
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   00097
4$:	MOVZWL  2(R2), -(SP)			 ;2(IOSB), -(SP)		       0404 	       7E	02   A2  3C   0009E
	PUSHL   8(R6)				 ;8(PTYID)			      	    			08   A6  DD   000A2
	CALLS   #2, W^U.13			 ;#2, U.13			      	    	0000V  CF	     02  FB   000A5
	MOVL    R0, R7				 ;R0, STAT			      	    	       57	     50  D0   000AA
	BLBC    R7, 5$				 ;STAT, 5$			       0405 	       03	     57  E9   000AD
	BRW     9$				 ;9$				      	    			   009E  31   000B0
5$:	MOVL    #34471936, 4(SP)		 ;#34471936, MESSDESC		      	    	  04   AE 020E0000   8F  D0   000B3
	CLRL    8(SP)				 ;MESSDESC+4			      	    			08   AE  D4   000BB
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   000BE
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   000C1
	MOVL    R7, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     57  D0   000C3
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   000C7
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   000CA
	MOVL    R0, R7				 ;R0, STAT			      	    	       57	     50  D0   000D1
	BLBC    R7, 9$				 ;STAT, 9$			      	    	       7A	     57  E9   000D4
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   000D7
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   000DA
	BRB     9$				 ;9$				      	    			     6E  11   000E1
6$:	MOVZWL  18(R6), R0			 ;18(PTYID), R0			       0414 	       50	12   A6  3C   000E3
	MOVZWL  2(R2), R1			 ;2(IOSB), R1			      	    	       51	02   A2  3C   000E7
	ADDL2   R1, R0				 ;R1, R0			      	    	       50	     51  C0   000EB
	CMPL    R0, #1024			 ;R0, #1024			      	    00000400   8F	     50  D1   000EE
	BLEQ    7$				 ;7$				      	    			     07  15   000F5
	PUSHL   R6				 ;PTYID				       0415 			     56  DD   000F7
	CALLS   #1, W^U.7			 ;#1, U.7			      	    	0000V  CF	     01  FB   000F9
7$:	SUBW3   18(R6), #1024, R0		 ;18(PTYID), #1024, BUFLEFT	       0418 	0400   8F	12   A6  A3   000FE
						 ;					    			     50       00104
	MOVZWL  R0, R0				 ;BUFLEFT, R0			       0419 	       50	     50  3C   00105
	CMPW    2(R2), R0			 ;2(IOSB), R0			      	    	       50	02   A2  B1   00108
	BGEQU   8$				 ;8$				      	    			     04  1E   0010C
	MOVZWL  2(R2), R0			 ;2(IOSB), R0			      	    	       50	02   A2  3C   0010E
8$:	MOVW    R0, R8				 ;R0, CHARSTOMOVE		      	    	       58	     50  B0   00112
	MOVZWL  18(R6), R0			 ;18(PTYID), R0			       0422 	       50	12   A6  3C   00115
	ADDL2   20(R6), R0			 ;20(PTYID), R0			      	    	       50	14   A6  C0   00119
	MOVC3   R8, @8(R6), (R0)		 ;CHARSTOMOVE, @8(PTYID), (R0)	      	    	  08   B6	     58  28   0011D
						 ;					    			     60       00121
	ADDW2   R8, 18(R6)			 ;CHARSTOMOVE, 18(PTYID)	       0423 	  12   A6	     58  A0   00122
	CMPW    18(R6), #768			 ;18(PTYID), #768		       0426 	0300   8F	12   A6  B1   00126
	BLEQU   9$				 ;9$				      	    			     23  1B   0012C
	CLRQ    -(SP)				 ;-(SP)				       0430 			     7E  7C   0012E
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00130
	PUSHL   #1				 ;#1				      	    			     01  DD   00132
	MOVL    #19, 20(SP)			 ;#19, 20(SP)			      	    	  14   AE	     13  D0   00134
	PUSHAB  20(SP)				 ;20(SP)			      	    			14   AE  9F   00138
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0013B
	MOVQ    #48, -(SP)			 ;#48, -(SP)			      	    	       7E	     30  7D   0013D
	MOVZWL  16(R6), -(SP)			 ;16(PTYID), -(SP)		      	    	       7E	10   A6  3C   00140
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00144
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   00146
	BISB2   #4, 28(R6)			 ;#4, 28(PTYID)			       0431 	  1C   A6	     04  88   0014D
9$:	CLRQ    -(SP)				 ;-(SP)				       0438 			     7E  7C   00151
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00153
	MOVZWL  #1024, -(SP)			 ;#1024, -(SP)			      	    	       7E     0400   8F  3C   00155
	PUSHL   8(R6)				 ;8(PTYID)			      	    			08   A6  DD   0015A
	PUSHL   R6				 ;PTYID				      	    			     56  DD   0015D
	PUSHAB  W^U.12				 ;U.12				      	    		      FE9D   CF  9F   0015F
	PUSHL   12(R6)				 ;12(PTYID)			      	    			0C   A6  DD   00163
	PUSHL   #49				 ;#49				      	    			     31  DD   00166
	MOVZWL  16(R6), -(SP)			 ;16(PTYID), -(SP)		      	    	       7E	10   A6  3C   00168
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0016C
	CALLS   #12, G^SYS$QIO			 ;#12, SYS$QIO			      	    00000000G  00	     0C  FB   0016E
	MOVL    R0, R7				 ;R0, STAT			      	    	       57	     50  D0   00175
	BLBS    R7, 10$				 ;STAT, 10$			       0439 	       2E	     57  E8   00178
	MOVL    #34471936, 4(SP)		 ;#34471936, MESSDESC		      	    	  04   AE 020E0000   8F  D0   0017B
	CLRL    8(SP)				 ;MESSDESC+4			      	    			08   AE  D4   00183
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   00186
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00189
	MOVL    R7, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     57  D0   0018B
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   0018F
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   00192
	MOVL    R0, R7				 ;R0, STAT			      	    	       57	     50  D0   00199
	BLBC    R7, 10$				 ;STAT, 10$			      	    	       0A	     57  E9   0019C
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   0019F
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   001A2
10$:	RET     				 ;				       0440 				 04   001A9

; Routine Size:  426 bytes,    Routine Base:  $CODE$ + 0147


;   0441  1	
;   0442  1	
;   0443  1	!flush the buffer to TTY
;   0444  1	ROUTINE flushbuffer(ptyadr) : NOVALUE =
;   0445  2	    BEGIN
;   0446  2	    LOCAL
;   0447  2		ptyid : REF pty INITIAL(.ptyadr);
;   0448  2	
; P 0449  2	    $qiow(chan = .tt_chan,func=io$_writevblk+io$m_refresh,
;   0450  2		  p1 = .ptyid[buffer],p2 = .ptyid[buflen]);
;   0451  2	    logit(.ptyid[buffer],.ptyid[buflen]);
;   0452  2	    ptyid[buflen] = 0;
;   0453  2	
;   0454  2	!xon the PTY
; P 0455  2	    IF .ptyid[xoffed] THEN $qiow(chan = .ptyid[chan],func=io$_writevblk,
;   0456  2					p1 = %ref(xon),p2 = 1);
;   0457  2	    ptyid[xoffed] = 0;
;   0458  1	    END;





;FLUSHBUFFER
U.7:	.WORD   ^M<R2>				 ;Save R2			       0444 			       0004   00000
	SUBL2   #4, SP				 ;#4, SP			      	    	       5E	     04  C2   00002
	MOVL    4(AP), R2			 ;PTYADR, PTYID			       0447 	       52	04   AC  D0   00005
	CLRQ    -(SP)				 ;-(SP)				       0450 			     7E  7C   00009
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0000B
	MOVZWL  18(R2), -(SP)			 ;18(PTYID), -(SP)		      	    	       7E	12   A2  3C   0000D
	PUSHL   20(R2)				 ;20(PTYID)			      	    			14   A2  DD   00011
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00014
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00016
	MOVZWL  #8240, -(SP)			 ;#8240, -(SP)			      	    	       7E     2030   8F  3C   00018
	MOVZWL  W^U.48, -(SP)			 ;U.48, -(SP)			      	    	       7E     0000'  CF  3C   0001D
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00022
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   00024
	MOVZWL  18(R2), -(SP)			 ;18(PTYID), -(SP)		       0451 	       7E	12   A2  3C   0002B
	PUSHL   20(R2)				 ;20(PTYID)			      	    			14   A2  DD   0002F
	CALLS   #2, W^U.13			 ;#2, U.13			      	    	0000V  CF	     02  FB   00032
	CLRW    18(R2)				 ;18(PTYID)			       0452 			12   A2  B4   00037
	BBC     #2, 28(R2), 1$			 ;#2, 28(PTYID), 1$		       0455 	  1C   A2	     02  E1   0003A
						 ;					    			     1F       0003E
	CLRQ    -(SP)				 ;-(SP)				       0456 			     7E  7C   0003F
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00041
	PUSHL   #1				 ;#1				      	    			     01  DD   00043
	MOVL    #17, 20(SP)			 ;#17, 20(SP)			      	    	  14   AE	     11  D0   00045
	PUSHAB  20(SP)				 ;20(SP)			      	    			14   AE  9F   00049
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0004C
	MOVQ    #48, -(SP)			 ;#48, -(SP)			      	    	       7E	     30  7D   0004E
	MOVZWL  16(R2), -(SP)			 ;16(PTYID), -(SP)		      	    	       7E	10   A2  3C   00051
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00055
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   00057
1$:	BICB2   #4, 28(R2)			 ;#4, 28(PTYID)			       0457 	  1C   A2	     04  8A   0005E
	RET     				 ;				       0458 				 04   00062

; Routine Size:  99 bytes,    Routine Base:  $CODE$ + 02F1


;   0459  1	
;   0460  1	
;   0461  1	!log characters to the log file
;   0462  1	ROUTINE logit(adr,len) = 
;   0463  2	    BEGIN
;   0464  2	    BUILTIN
;   0465  2		matchc,
;   0466  2		movc3;
;   0467  2	
;   0468  2	    LOCAL
;   0469  2		foo,
;   0470  2		stat,
;   0471  2		bytesleft : word,
;   0472  2		left : word,
;   0473  2		start,
;   0474  2		startrec,
;   0475  2		reclen : word;
;   0476  2	
;   0477  2	    IF NOT .logopen THEN RETURN 1;
;   0478  2	    !buffer the input
;   0479  2	    IF .loglen + .len GTR logbufsiz THEN
;   0480  3	    BEGIN
;   0481  3	    !No more buffer space left in log buffer
;   0482  3	    !We have to write the buffer to disk;
;   0483  3	    lograb[rab$w_rsz] = .loglen;
;   0484  3	    lograb[rab$l_rbf] = logbuf;
;   0485  3	    stat = $PUT(RAB = lograb);
;   0486  3	    $messerr(.stat);
;   0487  3	    loglen = 0;
;   0488  2	    END;
;   0489  2	
;   0490  2	!move characters to log buffer
;   0491  2	    MOVC3(%ref(.len),.adr, logbuf+.loglen);
;   0492  2	    loglen = .loglen + .len;
;   0493  2	    start = (startrec = logbuf);
;   0494  2	    bytesleft = (left = .loglen);
;   0495  2	    !write out records.
;   0496  2	
;   0497  2	!records are separated by crlf
;   0498  2	    DO
;   0499  3	    BEGIN 
;   0500  3		IF MATCHC(%ref(2), crlf, left, .start ;foo,foo,left,start) THEN
;   0501  4		BEGIN
;   0502  4		    ! We have found the end of a record;
;   0503  4		    reclen = .start - 2 - .startrec;
;   0504  4		    ! write the record to the logfile
;   0505  4		    lograb[rab$w_rsz] = .reclen;
;   0506  4		    lograb[rab$l_rbf] = .startrec;
;   0507  4		    stat = $PUT(RAB = lograb);
;   0508  4		    startrec = .start;
;   0509  4		    IF (bytesleft = .left) EQL 0 THEN loglen = 0;
;   0510  3		END ELSE
;   0511  4		BEGIN
;   0512  4		!The buffer contains no more crlf, put rest of buffer
;   0513  4		! in front of buffer
;   0514  4		IF logbuf NEQU .startrec THEN
;   0515  4		    MOVC3(bytesleft, .startrec, logbuf);
;   0516  4		loglen = .bytesleft;
;   0517  4		bytesleft = 0;
;   0518  4		stat = 1;
;   0519  3		END;
;   0520  3	    END
;   0521  2	    UNTIL (.bytesleft EQL 0);
;   0522  2	    .stat
;   0523  1	    END;



	.EXTRN  SYS$PUT

;LOGIT
U.13:	.WORD   ^M<R2,R3,R4,R5,R6,R7,R8,R9,R10,- ;Save R2,R3,R4,R5,R6,R7,R8,R9,R10,-   0462 			       0FFC   00000
		R11>				 ;R11
	SUBL2   #12, SP				 ;#12, SP			      	    	       5E	     0C  C2   00002
	BLBS    W^U.38, 1$			 ;U.38, 1$			       0477 	       04     0000'  CF  E8   00005
	MOVL    #1, R0				 ;#1, R0			      	    	       50	     01  D0   0000A
	RET     				 ;				      	    				 04   0000D
1$:	MOVZWL  W^U.34, R0			 ;U.34, R0			       0479 	       50     0000'  CF  3C   0000E
	ADDL2   8(AP), R0			 ;LEN, R0			      	    	       50	08   AC  C0   00013
	CMPL    R0, #2048			 ;R0, #2048			      	    00000800   8F	     50  D1   00017
	BLEQ    3$				 ;3$				      	    			     51  15   0001E
	MOVW    W^U.34, W^U.37+34		 ;U.34, U.37+34			       0483 	0000'  CF     0000'  CF  B0   00020
	MOVAB   W^U.35, W^U.37+40		 ;U.35, U.37+40			       0484 	0000'  CF     0000'  CF  9E   00027
	PUSHAB  W^U.37				 ;U.37				       0485 		      0000'  CF  9F   0002E
	CALLS   #1, G^SYS$PUT			 ;#1, SYS$PUT			      	    00000000G  00	     01  FB   00032
	MOVL    R0, R11				 ;R0, STAT			      	    	       5B	     50  D0   00039
	BLBS    R11, 2$				 ;STAT, 2$			       0486 	       2E	     5B  E8   0003C
	MOVL    #34471936, 4(SP)		 ;#34471936, MESSDESC		      	    	  04   AE 020E0000   8F  D0   0003F
	CLRL    8(SP)				 ;MESSDESC+4			      	    			08   AE  D4   00047
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   0004A
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0004D
	MOVL    R11, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     5B  D0   0004F
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   00053
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   00056
	MOVL    R0, R11				 ;R0, STAT			      	    	       5B	     50  D0   0005D
	BLBC    R11, 2$				 ;STAT, 2$			      	    	       0A	     5B  E9   00060
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   00063
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   00066
2$:	CLRW    W^U.34				 ;U.34				       0487 		      0000'  CF  B4   0006D
3$:	MOVZWL  W^U.34, R0			 ;U.34, R0			       0491 	       50     0000'  CF  3C   00071
	MOVC3   8(AP), @4(AP), W^U.35[R0]	 ;LEN, @ADR, U.35[R0]		      	    	  04   BC	08   AC  28   00076
						 ;					    		      0000'CF40       0007B
	ADDW2   8(AP), W^U.34			 ;LEN, U.34			       0492 	0000'  CF	08   AC  A0   0007F
	MOVAB   W^U.35, R6			 ;U.35, STARTREC		       0493 	       56     0000'  CF  9E   00085
	MOVL    R6, R9				 ;STARTREC, START		      	    	       59	     56  D0   0008A
	MOVZWL  W^U.34, R0			 ;U.34, R0			       0494 	       50     0000'  CF  3C   0008D
	MOVW    R0, R8				 ;R0, LEFT			      	    	       58	     50  B0   00092
	MOVW    R0, R7				 ;R0, BYTESLEFT			      	    	       57	     50  B0   00095
4$:	MATCHC  #2, W^U.33, R8, (R9)		 ;#2, U.33, LEFT, (START)	       0500 	0000'  CF	     02  39   00098
						 ;					    	       69	     58       0009D
	MOVPSL  R4				 ;R4				      	    			     54  DC   0009F
	MOVL    R0, (SP)			 ;R0, (SP)			      	    	       6E	     50  D0   000A1
	MOVL    R1, (SP)			 ;R1, (SP)			      	    	       6E	     51  D0   000A4
	MOVQ    R2, R8				 ;R2, LEFT			      	    	       58	     52  7D   000A7
	BBC     #2, R4, 5$			 ;#2, R4, 5$			      	    	       54	     02  E1   000AA
						 ;					    			     2E       000AD
	SUBL3   R6, R9, R3			 ;STARTREC, START, R3		       0503 	       59	     56  C3   000AE
						 ;					    			     53       000B1
	SUBW3   #2, R3, R10			 ;#2, R3, RECLEN		      	    	       53	     02  A3   000B2
						 ;					    			     5A       000B5
	MOVW    R10, W^U.37+34			 ;RECLEN, U.37+34		       0505 	0000'  CF	     5A  B0   000B6
	MOVL    R6, W^U.37+40			 ;STARTREC, U.37+40		       0506 	0000'  CF	     56  D0   000BB
	PUSHAB  W^U.37				 ;U.37				       0507 		      0000'  CF  9F   000C0
	CALLS   #1, G^SYS$PUT			 ;#1, SYS$PUT			      	    00000000G  00	     01  FB   000C4
	MOVL    R0, R11				 ;R0, STAT			      	    	       5B	     50  D0   000CB
	MOVL    R9, R6				 ;START, STARTREC		       0508 	       56	     59  D0   000CE
	MOVW    R8, R7				 ;LEFT, BYTESLEFT		       0509 	       57	     58  B0   000D1
	BNEQ    7$				 ;7$				      	    			     20  12   000D4
	CLRW    W^U.34				 ;U.34				      	    		      0000'  CF  B4   000D6
	BRB     7$				 ;7$				      	    			     1A  11   000DA
5$:	MOVAB   W^U.35, R0			 ;U.35, R0			       0514 	       50     0000'  CF  9E   000DC
	CMPL    R6, R0				 ;STARTREC, R0			      	    	       50	     56  D1   000E1
	BEQL    6$				 ;6$				      	    			     06  13   000E4
	MOVC3   R7, (R6), W^U.35		 ;BYTESLEFT, (STARTREC), U.35	       0515 	       66	     57  28   000E6
						 ;					    		      0000'  CF       000E9
6$:	MOVW    R7, W^U.34			 ;BYTESLEFT, U.34		       0516 	0000'  CF	     57  B0   000EC
	CLRW    R7				 ;BYTESLEFT			       0517 			     57  B4   000F1
	MOVL    #1, R11				 ;#1, STAT			       0518 	       5B	     01  D0   000F3
7$:	TSTW    R7				 ;BYTESLEFT			       0521 			     57  B5   000F6
	BNEQ    4$				 ;4$				      	    			     9E  12   000F8
	MOVL    R11, R0				 ;STAT, R0			       0523 	       50	     5B  D0   000FA
	RET     				 ;				      	    				 04   000FD

; Routine Size:  254 bytes,    Routine Base:  $CODE$ + 0354


;   0524  1	
;   0525  1	
;   0526  1	%SBTTL 'Creation of ptys'
;   0527  1	
;   0528  1	!find PTY with ptyis eqlu id
;   0529  1	ROUTINE findpty(id) =
;   0530  2	    BEGIN
;   0531  2	    LOCAL
;   0532  2		ptyid : REF pty INITIAL(.ptyhead[0]);
;   0533  2	
;   0534  2	    WHILE .ptyid NEQA ptyhead DO
;   0535  3		BEGIN
;   0536  3		IF .ptyid[ident] EQLU .id THEN EXITLOOP;
;   0537  3		ptyid = .ptyid[flink];
;   0538  2		END;
;   0539  2	
;   0540  2	    IF .ptyid EQLA ptyhead THEN RETURN 0;
;   0541  2	    .ptyid
;   0542  1	    END;





;FINDPTY
U.6:	.WORD   ^M<>				 ;Save nothing			       0529 			       0000   00000
	MOVL    W^U.40, R0			 ;U.40, PTYID			       0532 	       50     0000'  CF  D0   00002
	BRB     2$				 ;2$				       0536 			     0A  11   00007
1$:	CMPL    24(R0), 4(AP)			 ;24(PTYID), ID			      	    	  04   AC	18   A0  D1   00009
	BEQL    3$				 ;3$				      	    			     0D  13   0000E
	MOVL    (R0), R0			 ;(PTYID), PTYID		       0537 	       50	     60  D0   00010
2$:	MOVAB   W^U.40, R1			 ;U.40, R1			       0534 	       51     0000'  CF  9E   00013
	CMPL    R0, R1				 ;PTYID, R1			      	    	       51	     50  D1   00018
	BNEQ    1$				 ;1$				      	    			     EC  12   0001B
3$:	MOVAB   W^U.40, R1			 ;U.40, R1			       0540 	       51     0000'  CF  9E   0001D
	CMPL    R0, R1				 ;PTYID, R1			      	    	       51	     50  D1   00022
	BNEQ    4$				 ;4$				      	    			     02  12   00025
	CLRL    R0				 ;R0				      	    			     50  D4   00027
4$:	RET     				 ;				       0542 				 04   00029

; Routine Size:  42 bytes,    Routine Base:  $CODE$ + 0452


;   0543  1	
;   0544  1	!create a new PTY 
;   0545  1	ROUTINE newpty(ptyadr,id) =
;   0546  2	    BEGIN
;   0547  2	    BUILTIN
;   0548  2		insque;
;   0549  2	    LOCAL
;   0550  2	        stat,
;   0551  2		ptyid : REF pty;
;   0552  2	
;   0553  2	!allocate & init
;   0554  2	    makepty(ptyid,.id);
;   0555  2	    stat = $ASSIGN(devnam = %ASCID 'PYA0:',chan = ptyid[chan]);
;   0556  2	    $reterr(.stat);
;   0557  2	
;   0558  2	!issue a read request
; P 0559  2	    stat = $qio(chan = .ptyid[chan],func = io$_readvblk,
; P 0560  2			iosb = .ptyid[iosbadr],astadr = pty_input,astprm = .ptyid,
;   0561  2	                p1 = .ptyid[bufadr],p2 = ptybufsiz);
;   0562  2	    $reterr(.stat);
;   0563  2	
;   0564  2	!insert in queue, if first PTY set ^Y trap
;   0565  2	    IF INSQUE(.ptyid, ptyhead) THEN
;   0566  2	       setctrly();
;   0567  2	    .ptyadr = .ptyid;
;   0568  2	    .stat
;   0569  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.AAG:	.ASCII  \PYA0:\<0><0><0>		 ;				      	      00  00  00  3A  30  41  59  50  00040
P.AAF:	.LONG   17694725			 ;				      	    			    010E0005  00048
	.ADDRESS P.AAG				 ;				      	    			    00000000' 0004C



	.PSECT  $CODE$,NOWRT,2

;NEWPTY
U.14:	.WORD   ^M<R2,R3>			 ;Save R2,R3			       0545 			       000C   00000
	SUBL2   #16, SP				 ;#16, SP			      	    	       5E	     10  C2   00002
	PUSHAB  4(SP)				 ;PTYID				       0554 			04   AE  9F   00005
	MOVL    #36, 4(SP)			 ;#36, 4(SP)			      	    	  04   AE	     24  D0   00008
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   0000C
	CALLS   #2, G^LIB$GET_VM		 ;#2, LIB$GET_VM		      	    00000000G  00	     02  FB   0000F
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   00016
	BLBS    R3, 1$				 ;STAT, 1$			      	    	       2E	     53  E8   00019
	MOVL    #34471936, 8(SP)		 ;#34471936, MESSDESC		      	    	  08   AE 020E0000   8F  D0   0001C
	CLRL    12(SP)				 ;MESSDESC+4			      	    			0C   AE  D4   00024
	PUSHAB  8(SP)				 ;MESSDESC			      	    			08   AE  9F   00027
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0002A
	MOVL    R3, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     53  D0   0002C
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   00030
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   00033
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   0003A
	BLBC    R3, 1$				 ;STAT, 1$			      	    	       0A	     53  E9   0003D
	PUSHAB  8(SP)				 ;MESSDESC			      	    			08   AE  9F   00040
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   00043
1$:	MOVL    4(SP), R2			 ;PTYID, R2			      	    	       52	04   AE  D0   0004A
	PUSHAB  8(R2)				 ;8(R2)				      	    			08   A2  9F   0004E
	MOVZWL  #1024, 4(SP)			 ;#1024, 4(SP)			      	    	  04   AE     0400   8F  3C   00051
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   00057
	CALLS   #2, G^LIB$GET_VM		 ;#2, LIB$GET_VM		      	    00000000G  00	     02  FB   0005A
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   00061
	BLBS    R3, 2$				 ;STAT, 2$			      	    	       2E	     53  E8   00064
	MOVL    #34471936, 8(SP)		 ;#34471936, MESSDESC		      	    	  08   AE 020E0000   8F  D0   00067
	CLRL    12(SP)				 ;MESSDESC+4			      	    			0C   AE  D4   0006F
	PUSHAB  8(SP)				 ;MESSDESC			      	    			08   AE  9F   00072
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00075
	MOVL    R3, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     53  D0   00077
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   0007B
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   0007E
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   00085
	BLBC    R3, 2$				 ;STAT, 2$			      	    	       0A	     53  E9   00088
	PUSHAB  8(SP)				 ;MESSDESC			      	    			08   AE  9F   0008B
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   0008E
2$:	PUSHAB  12(R2)				 ;12(R2)			      	    			0C   A2  9F   00095
	MOVL    #8, 4(SP)			 ;#8, 4(SP)			      	    	  04   AE	     08  D0   00098
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   0009C
	CALLS   #2, G^LIB$GET_VM		 ;#2, LIB$GET_VM		      	    00000000G  00	     02  FB   0009F
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   000A6
	BLBS    R3, 3$				 ;STAT, 3$			      	    	       2E	     53  E8   000A9
	MOVL    #34471936, 8(SP)		 ;#34471936, MESSDESC		      	    	  08   AE 020E0000   8F  D0   000AC
	CLRL    12(SP)				 ;MESSDESC+4			      	    			0C   AE  D4   000B4
	PUSHAB  8(SP)				 ;MESSDESC			      	    			08   AE  9F   000B7
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   000BA
	MOVL    R3, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     53  D0   000BC
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   000C0
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   000C3
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   000CA
	BLBC    R3, 3$				 ;STAT, 3$			      	    	       0A	     53  E9   000CD
	PUSHAB  8(SP)				 ;MESSDESC			      	    			08   AE  9F   000D0
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   000D3
3$:	PUSHAB  20(R2)				 ;20(R2)			      	    			14   A2  9F   000DA
	MOVZWL  #1024, 4(SP)			 ;#1024, 4(SP)			      	    	  04   AE     0400   8F  3C   000DD
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   000E3
	CALLS   #2, G^LIB$GET_VM		 ;#2, LIB$GET_VM		      	    00000000G  00	     02  FB   000E6
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   000ED
	BLBS    R3, 4$				 ;STAT, 4$			      	    	       2E	     53  E8   000F0
	MOVL    #34471936, 8(SP)		 ;#34471936, MESSDESC		      	    	  08   AE 020E0000   8F  D0   000F3
	CLRL    12(SP)				 ;MESSDESC+4			      	    			0C   AE  D4   000FB
	PUSHAB  8(SP)				 ;MESSDESC			      	    			08   AE  9F   000FE
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00101
	MOVL    R3, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     53  D0   00103
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   00107
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   0010A
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   00111
	BLBC    R3, 4$				 ;STAT, 4$			      	    	       0A	     53  E9   00114
	PUSHAB  8(SP)				 ;MESSDESC			      	    			08   AE  9F   00117
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   0011A
4$:	CLRL    28(R2)				 ;28(R2)			      	    			1C   A2  D4   00121
	CLRW    18(R2)				 ;18(R2)			      	    			12   A2  B4   00124
	BICB2   #5, 28(R2)			 ;#5, 28(R2)			      	    	  1C   A2	     05  8A   00127
	MOVL    8(AP), 24(R2)			 ;ID, 24(R2)			      	    	  18   A2	08   AC  D0   0012B
	BICB2   #16, 32(R2)			 ;#16, 32(R2)			      	    	  20   A2	     10  8A   00130
	CLRQ    -(SP)				 ;-(SP)				       0555 			     7E  7C   00134
	PUSHAB  16(R2)				 ;16(PTYID)			      	    			10   A2  9F   00136
	PUSHAB  W^P.AAF				 ;P.AAF				      	    		      0000'  CF  9F   00139
	CALLS   #4, G^SYS$ASSIGN		 ;#4, SYS$ASSIGN		      	    00000000G  00	     04  FB   0013D
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   00144
	BLBC    R3, 6$				 ;STAT, 6$			       0556 	       3A	     53  E9   00147
	CLRQ    -(SP)				 ;-(SP)				       0561 			     7E  7C   0014A
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0014C
	MOVZWL  #1024, -(SP)			 ;#1024, -(SP)			      	    	       7E     0400   8F  3C   0014E
	PUSHL   8(R2)				 ;8(PTYID)			      	    			08   A2  DD   00153
	PUSHL   R2				 ;PTYID				      	    			     52  DD   00156
	PUSHAB  W^U.12				 ;U.12				      	    		      FB6F   CF  9F   00158
	PUSHL   12(R2)				 ;12(PTYID)			      	    			0C   A2  DD   0015C
	PUSHL   #49				 ;#49				      	    			     31  DD   0015F
	MOVZWL  16(R2), -(SP)			 ;16(PTYID), -(SP)		      	    	       7E	10   A2  3C   00161
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00165
	CALLS   #12, G^SYS$QIO			 ;#12, SYS$QIO			      	    00000000G  00	     0C  FB   00167
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   0016E
	BLBC    R3, 6$				 ;STAT, 6$			       0562 	       10	     53  E9   00171
	INSQUE  (R2), W^U.40			 ;(PTYID), U.40			       0565 	0000'  CF	     62  0E   00174
	BNEQ    5$				 ;5$				      	    			     05  12   00179
	CALLS   #0, W^U.2			 ;#0, U.2			       0566 	FA3A   CF	     00  FB   0017B
5$:	MOVL    R2, @4(AP)			 ;PTYID, @PTYADR		       0567 	  04   BC	     52  D0   00180
6$:	MOVL    R3, R0				 ;STAT, R0			       0569 	       50	     53  D0   00184
	RET     				 ;				      	    				 04   00187

; Routine Size:  392 bytes,    Routine Base:  $CODE$ + 047C


;   0570  1	
;   0571  1	
;   0572  1	!delete a PTY
;   0573  1	ROUTINE deletepty(ptyadr) : NOVALUE =
;   0574  2	    BEGIN
;   0575  2		BUILTIN
;   0576  2		    remque;
;   0577  2		LOCAL
;   0578  2		    ptyid : REF pty INITIAL(.ptyadr);
;   0579  2	
;   0580  2	!remove it from the queue
;   0581  2		REMQUE(.ptyid,ptyid);
;   0582  2	
;   0583  2	!if no more PTYs left, clear ^Y trap, we have no currpty anymore
;   0584  2	        IF empty(ptyhead) THEN
;   0585  3		BEGIN
;   0586  3		  currpty = 0;
;   0587  3		  clearctrly();
;   0588  3	        END
;   0589  2	        ELSE
;   0590  2	         currpty = .ptyhead[0];
;   0591  2	!flush the buffer
;   0592  2		flushbuffer(.ptyid);
;   0593  2	!deassign channel
;   0594  2		$dassgn(chan = ptyid[chan]);
;   0595  2	!deallocate 
;   0596  2		lib$free_vm(%ref(ptybufsiz),ptyid[bufadr]);
;   0597  2		lib$free_vm(%ref(8),ptyid[iosbadr]);
;   0598  2		lib$free_vm(%ref(ptybufsiz),ptyid[buffer]);
;   0599  2		lib$free_vm(%ref(ptylen),ptyid);
;   0600  1	    END;





;DELETEPTY
U.15:	.WORD   ^M<R2>				 ;Save R2			       0573 			       0004   00000
	SUBL2   #8, SP				 ;#8, SP			      	    	       5E	     08  C2   00002
	MOVL    4(AP), 4(SP)			 ;PTYADR, PTYID			       0578 	  04   AE	04   AC  D0   00005
	REMQUE  @4(SP), 4(SP)			 ;@PTYID, PTYID			       0581 	  04   AE	04   BE  0F   0000A
	CMPL    W^U.40, W^U.40+4		 ;U.40, U.40+4			       0584 	0000'  CF     0000'  CF  D1   0000F
	BNEQ    1$				 ;1$				      	    			     0B  12   00016
	CLRL    W^U.39				 ;U.39				       0586 		      0000'  CF  D4   00018
	CALLS   #0, W^U.3			 ;#0, U.3			       0587 	FA47   CF	     00  FB   0001C
	BRB     2$				 ;2$				      	    			     07  11   00021
1$:	MOVL    W^U.40, W^U.39			 ;U.40, U.39			       0590 	0000'  CF     0000'  CF  D0   00023
2$:	MOVL    4(SP), R2			 ;PTYID, R2			       0592 	       52	04   AE  D0   0002A
	PUSHL   R2				 ;R2				      	    			     52  DD   0002E
	CALLS   #1, W^U.7			 ;#1, U.7			      	    	FCB8   CF	     01  FB   00030
	PUSHAB  16(R2)				 ;16(R2)			       0594 			10   A2  9F   00035
	CALLS   #1, G^SYS$DASSGN		 ;#1, SYS$DASSGN		      	    00000000G  00	     01  FB   00038
	PUSHAB  8(R2)				 ;8(R2)				       0596 			08   A2  9F   0003F
	MOVZWL  #1024, 4(SP)			 ;#1024, 4(SP)			      	    	  04   AE     0400   8F  3C   00042
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   00048
	CALLS   #2, G^LIB$FREE_VM		 ;#2, LIB$FREE_VM		      	    00000000G  00	     02  FB   0004B
	PUSHAB  12(R2)				 ;12(R2)			       0597 			0C   A2  9F   00052
	MOVL    #8, 4(SP)			 ;#8, 4(SP)			      	    	  04   AE	     08  D0   00055
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   00059
	CALLS   #2, G^LIB$FREE_VM		 ;#2, LIB$FREE_VM		      	    00000000G  00	     02  FB   0005C
	PUSHAB  20(R2)				 ;20(R2)			       0598 			14   A2  9F   00063
	MOVZWL  #1024, 4(SP)			 ;#1024, 4(SP)			      	    	  04   AE     0400   8F  3C   00066
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   0006C
	CALLS   #2, G^LIB$FREE_VM		 ;#2, LIB$FREE_VM		      	    00000000G  00	     02  FB   0006F
	PUSHAB  4(SP)				 ;PTYID				       0599 			04   AE  9F   00076
	MOVL    #36, 4(SP)			 ;#36, 4(SP)			      	    	  04   AE	     24  D0   00079
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   0007D
	CALLS   #2, G^LIB$FREE_VM		 ;#2, LIB$FREE_VM		      	    00000000G  00	     02  FB   00080
	RET     				 ;				       0600 				 04   00087

; Routine Size:  136 bytes,    Routine Base:  $CODE$ + 0604


;   0601  1	
;   0602  1	
;   0603  1	%SBTTL 'main routine when connected to a pty'
;   0604  1	ROUTINE dopty(ptyadr) =
;   0605  2	    BEGIN
;   0606  2	    LOCAL
;   0607  2		ctrlycount : byte INITIAL(0),
;   0608  2	        stat,
;   0609  2		ptyid : REF pty;
;   0610  2	    ptyid = .ptyadr;
;   0611  2	!tell user which PTY we connect to
;   0612  2	    lib$signal(pty__connect,2,4,ptyid[ident]);
;   0613  2	!set terminal chars
;   0614  2	    set_term();
;   0615  2	!passivate all ptys
;   0616  2	    passivateall();
;   0617  2	!activate this one
;   0618  2	    activate(.ptyid);
;   0619  2	
;   0620  2	!read characters from TTY, write them to PTY
;   0621  2	    DO
;   0622  3	    BEGIN
; P 0623  3	    stat = $qiow(chan = .tt_chan,func=io$_readvblk,
; P 0624  3			iosb = tt_iosb,
;   0625  3			p1 = tt_char,p2 = 1);
;   0626  3	    $reterr(.stat);
;   0627  3	    $reterr(.tt_iosb[status]);
;   0628  3	    IF .tt_char EQL .breakchar THEN EXITLOOP;
;   0629  3	!count ^Y & ^C s
;   0630  3	    IF (.tt_char EQL 3) OR (.tt_char EQL 25) THEN
;   0631  4		BEGIN
;   0632  4		ctrlycount = .ctrlycount + 1;
;   0633  4		IF .ctrlycount GTR 2 THEN
;   0634  5		BEGIN
;   0635  5		 showbreak();
;   0636  5		 ctrlycount = 0;
;   0637  4		END;
;   0638  3		END;
; P 0639  3	    stat = $qio(chan = .ptyid[chan],func = io$_writevblk,
;   0640  3	                 p1 = tt_char,p2=1);
;   0641  3	    $messerr(.stat);
;   0642  3	    END
;   0643  2	    WHILE 7;   !that's odd, isn't it ?
;   0644  2	    passivatesome();
;   0645  2	    reset_term()
;   0646  1	    END;





;DOPTY
U.17:	.WORD   ^M<R2,R3,R4>			 ;Save R2,R3,R4			       0604 			       001C   00000
	SUBL2   #12, SP				 ;#12, SP			      	    	       5E	     0C  C2   00002
	CLRB    R4				 ;CTRLYCOUNT			       0605 			     54  94   00005
	MOVL    4(AP), R2			 ;PTYADR, PTYID			       0610 	       52	04   AC  D0   00007
	PUSHAB  24(R2)				 ;24(PTYID)			       0612 			18   A2  9F   0000B
	PUSHL   #4				 ;#4				      	    			     04  DD   0000E
	PUSHL   #2				 ;#2				      	    			     02  DD   00010
	PUSHL   #PTY__CONNECT			 ;#PTY__CONNECT			      	    		  00000000G  8F  DD   00012
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   00018
	CALLS   #0, W^U.4			 ;#0, U.4			       0614 	F9CB   CF	     00  FB   0001F
	CALLS   #0, W^U.10			 ;#0, U.10			       0616 	FA54   CF	     00  FB   00024
	PUSHL   R2				 ;PTYID				       0618 			     52  DD   00029
	CALLS   #1, W^U.8			 ;#1, U.8			      	    	FA2A   CF	     01  FB   0002B
1$:	CLRQ    -(SP)				 ;-(SP)				       0625 			     7E  7C   00030
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00032
	PUSHL   #1				 ;#1				      	    			     01  DD   00034
	PUSHAB  W^U.47				 ;U.47				      	    		      0000'  CF  9F   00036
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0003A
	PUSHAB  W^U.49				 ;U.49				      	    		      0000'  CF  9F   0003C
	PUSHL   #49				 ;#49				      	    			     31  DD   00040
	MOVZWL  W^U.48, -(SP)			 ;U.48, -(SP)			      	    	       7E     0000'  CF  3C   00042
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00047
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   00049
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   00050
	BLBS    R3, 2$				 ;STAT, 2$			       0626 	       04	     53  E8   00053
	MOVL    R3, R0				 ;STAT, R0			      	    	       50	     53  D0   00056
	RET     				 ;				      	    				 04   00059
2$:	BLBS    W^U.49, 3$			 ;U.49, 3$			       0627 	       06     0000'  CF  E8   0005A
	MOVZWL  W^U.49, R0			 ;U.49, R0			      	    	       50     0000'  CF  3C   0005F
	RET     				 ;				      	    				 04   00064
3$:	MOVZBL  W^U.47, R0			 ;U.47, R0			       0628 	       50     0000'  CF  9A   00065
	CMPB    W^U.44, R0			 ;U.44, R0			      	    	       50     0000'  CF  91   0006A
	BEQL    7$				 ;7$				      	    			     6E  13   0006F
	CMPB    R0, #3				 ;R0, #3			       0630 	       03	     50  91   00071
	BEQL    4$				 ;4$				      	    			     05  13   00074
	CMPB    R0, #25				 ;R0, #25			      	    	       19	     50  91   00076
	BNEQ    5$				 ;5$				      	    			     0E  12   00079
4$:	INCB    R4				 ;CTRLYCOUNT			       0632 			     54  96   0007B
	CMPB    R4, #2				 ;CTRLYCOUNT, #2		       0633 	       02	     54  91   0007D
	BLEQU   5$				 ;5$				      	    			     07  1B   00080
	CALLS   #0, W^U.23			 ;#0, U.23			       0635 	0000V  CF	     00  FB   00082
	CLRB    R4				 ;CTRLYCOUNT			       0636 			     54  94   00087
5$:	CLRQ    -(SP)				 ;-(SP)				       0640 			     7E  7C   00089
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0008B
	PUSHL   #1				 ;#1				      	    			     01  DD   0008D
	PUSHAB  W^U.47				 ;U.47				      	    		      0000'  CF  9F   0008F
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00093
	MOVQ    #48, -(SP)			 ;#48, -(SP)			      	    	       7E	     30  7D   00095
	MOVZWL  16(R2), -(SP)			 ;16(PTYID), -(SP)		      	    	       7E	10   A2  3C   00098
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0009C
	CALLS   #12, G^SYS$QIO			 ;#12, SYS$QIO			      	    00000000G  00	     0C  FB   0009E
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   000A5
	BLBS    R3, 1$				 ;STAT, 1$			       0641 	       85	     53  E8   000A8
	MOVL    #34471936, 4(SP)		 ;#34471936, MESSDESC		      	    	  04   AE 020E0000   8F  D0   000AB
	CLRL    8(SP)				 ;MESSDESC+4			      	    			08   AE  D4   000B3
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   000B6
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   000B9
	MOVL    R3, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     53  D0   000BB
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   000BF
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   000C2
	MOVL    R0, R3				 ;R0, STAT			      	    	       53	     50  D0   000C9
	BLBS    R3, 6$				 ;STAT, 6$			      	    	       03	     53  E8   000CC
	BRW     1$				 ;1$				      	    			   FF5E  31   000CF
6$:	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   000D2
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   000D5
	BRW     1$				 ;1$				      	    			   FF51  31   000DC
7$:	CALLS   #0, W^U.11			 ;#0, U.11			       0644 	F9B6   CF	     00  FB   000DF
	CALLS   #0, W^U.5			 ;#0, U.5			       0645 	F946   CF	     00  FB   000E4
	RET     				 ;				       0646 				 04   000E9

; Routine Size:  234 bytes,    Routine Base:  $CODE$ + 068C


;   0647  1	
;   0648  1	
;   0649  1	
;   0650  1	%SBTTL 'parse pty name'
;   0651  1	ROUTINE getident =
;   0652  2	    BEGIN
;   0653  2	    BUILTIN
;   0654  2		movc3;
;   0655  2	
;   0656  2	    LOCAL
;   0657  2		id : INITIAL(0),
;   0658  2		len : word,
;   0659  2	        addr,
;   0660  2		stat,
;   0661  2		iddescr : BLOCK[8,BYTE];
;   0662  2	    $init_dyndesc(iddescr);
;   0663  2	    stat = cli$present(%ASCID 'PTYNAME');
;   0664  2	    IF NOT .stat THEN RETURN 0;
;   0665  2	    stat = cli$get_value(%ASCID 'PTYNAME',iddescr);
;   0666  2	    IF NOT .stat THEN RETURN 0;
;   0667  2	    stat = lib$analyze_sdesc(iddescr,len,addr);
;   0668  2	    $reterr(.stat);
;   0669  2	    MOVC3(%ref(MIN(4,.len)), .addr, id);
;   0670  2	    .id
;   0671  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.AAI:	.ASCII  \PTYNAME\<0>			 ;				      	      00  45  4D  41  4E  59  54  50  00050
P.AAH:	.LONG   17694727			 ;				      	    			    010E0007  00058
	.ADDRESS P.AAI				 ;				      	    			    00000000' 0005C
P.AAK:	.ASCII  \PTYNAME\<0>			 ;				      	      00  45  4D  41  4E  59  54  50  00060
P.AAJ:	.LONG   17694727			 ;				      	    			    010E0007  00068
	.ADDRESS P.AAK				 ;				      	    			    00000000' 0006C



	.PSECT  $CODE$,NOWRT,2

;GETIDENT
U.18:	.WORD   ^M<R2,R3,R4,R5>			 ;Save R2,R3,R4,R5		       0651 			       003C   00000
	SUBL2   #20, SP				 ;#20, SP			      	    	       5E	     14  C2   00002
	CLRL    8(SP)				 ;ID				       0652 			08   AE  D4   00005
	MOVL    #34471936, 12(SP)		 ;#34471936, IDDESCR		       0662 	  0C   AE 020E0000   8F  D0   00008
	CLRL    16(SP)				 ;IDDESCR+4			      	    			10   AE  D4   00010
	PUSHAB  W^P.AAH				 ;P.AAH				       0663 		      0000'  CF  9F   00013
	CALLS   #1, G^CLI$PRESENT		 ;#1, CLI$PRESENT		      	    00000000G  00	     01  FB   00017
	BLBC    R0, 1$				 ;STAT, 1$			       0664 	       11	     50  E9   0001E
	PUSHAB  12(SP)				 ;IDDESCR			       0665 			0C   AE  9F   00021
	PUSHAB  W^P.AAJ				 ;P.AAJ				      	    		      0000'  CF  9F   00024
	CALLS   #2, G^CLI$GET_VALUE		 ;#2, CLI$GET_VALUE		      	    00000000G  00	     02  FB   00028
	BLBS    R0, 2$				 ;STAT, 2$			       0666 	       03	     50  E8   0002F
1$:	CLRL    R0				 ;R0				      	    			     50  D4   00032
	RET     				 ;				      	    				 04   00034
2$:	PUSHL   SP				 ;SP				       0667 			     5E  DD   00035
	PUSHAB  8(SP)				 ;LEN				      	    			08   AE  9F   00037
	PUSHAB  20(SP)				 ;IDDESCR			      	    			14   AE  9F   0003A
	CALLS   #3, G^LIB$ANALYZE_SDESC		 ;#3, LIB$ANALYZE_SDESC		      	    00000000G  00	     03  FB   0003D
	BLBC    R0, 4$				 ;STAT, 4$			       0668 	       16	     50  E9   00044
	MOVZWL  4(SP), R0			 ;LEN, R0			       0669 	       50	04   AE  3C   00047
	CMPW    R0, #4				 ;R0, #4			      	    	       04	     50  B1   0004B
	BLEQU   3$				 ;3$				      	    			     03  1B   0004E
	MOVL    #4, R0				 ;#4, R0			      	    	       50	     04  D0   00050
3$:	MOVC3   R0, @0(SP), 8(SP)		 ;R0, @ADDR, ID			      	    	  00   BE	     50  28   00053
						 ;					    			08   AE       00057
	MOVL    8(SP), R0			 ;ID, R0			       0671 	       50	08   AE  D0   00059
4$:	RET     				 ;				      	    				 04   0005D

; Routine Size:  94 bytes,    Routine Base:  $CODE$ + 0776


;   0672  1	
;   0673  1	%SBTTL 'Command routines'
;   0674  1	GLOBAL ROUTINE acceptpty =
;   0675  2	    BEGIN
;   0676  2	    LOCAL
;   0677  2		ptyid : REF pty,
;   0678  2		id,
;   0679  2		stat;
;   0680  2	    id = getident();
;   0681  2	    IF .id EQL 0 THEN ptyid = .currpty ELSE
;   0682  2	      ptyid = findpty(.id);
;   0683  2	    IF .ptyid NEQA 0 THEN
;   0684  3	    BEGIN
;   0685  3	    lib$signal(pty__accept,2,4,ptyid[ident]);
;   0686  3	    ptyid[accept] = 1;
;   0687  3	    activate(.ptyid);
;   0688  2	    END ELSE lib$signal(pty__nopty,2,4,id);
;   0689  2	    1
;   0690  1	    END;





U.19:
	.ENTRY  ACCEPTPTY, ^M<R2>		 ;ACCEPTPTY, Save R2		       0674 			       0004   00000
	SUBL2   #4, SP				 ;#4, SP			      	    	       5E	     04  C2   00002
	CALLS   #0, B^U.18			 ;#0, U.18			       0680 	  99   AF	     00  FB   00005
	MOVL    R0, (SP)			 ;R0, ID			      	    	       6E	     50  D0   00009
	BNEQ    1$				 ;1$				       0681 			     07  12   0000C
	MOVL    W^U.39, R2			 ;U.39, PTYID			      	    	       52     0000'  CF  D0   0000E
	BRB     2$				 ;2$				      	    			     0A  11   00013
1$:	PUSHL   (SP)				 ;ID				       0682 			     6E  DD   00015
	CALLS   #1, W^U.6			 ;#1, U.6			      	    	FC62   CF	     01  FB   00017
	MOVL    R0, R2				 ;R0, PTYID			      	    	       52	     50  D0   0001C
2$:	BEQL    3$				 ;3$				       0683 			     21  13   0001F
	PUSHAB  24(R2)				 ;24(PTYID)			       0685 			18   A2  9F   00021
	PUSHL   #4				 ;#4				      	    			     04  DD   00024
	PUSHL   #2				 ;#2				      	    			     02  DD   00026
	PUSHL   #PTY__ACCEPT			 ;#PTY__ACCEPT			      	    		  00000000G  8F  DD   00028
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   0002E
	BISB2   #1, 28(R2)			 ;#1, 28(PTYID)			       0686 	  1C   A2	     01  88   00035
	PUSHL   R2				 ;PTYID				       0687 			     52  DD   00039
	CALLS   #1, W^U.8			 ;#1, U.8			      	    	F8D2   CF	     01  FB   0003B
	BRB     4$				 ;4$				      	    			     13  11   00040
3$:	PUSHL   SP				 ;SP				       0688 			     5E  DD   00042
	PUSHL   #4				 ;#4				      	    			     04  DD   00044
	PUSHL   #2				 ;#2				      	    			     02  DD   00046
	PUSHL   #PTY__NOPTY			 ;#PTY__NOPTY			      	    		  00000000G  8F  DD   00048
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   0004E
4$:	MOVL    #1, R0				 ;#1, R0			       0690 	       50	     01  D0   00055
	RET     				 ;				      	    				 04   00058

; Routine Size:  89 bytes,    Routine Base:  $CODE$ + 07D4


;   0691  1	
;   0692  1	
;   0693  1	
;   0694  1	GLOBAL ROUTINE break =
;   0695  2	    BEGIN
;   0696  2	    LOCAL
;   0697  2		stat;
;   0698  2	
;   0699  2	    showbreak();
;   0700  2	    set_term(); 
; P 0701  2	    stat = $qiow(chan = .tt_chan,func = io$_readprompt,
; P 0702  2			 p1 = breakchar,p2 = 1,
; P 0703  2			 p5 = UPLIT(%STRING(%CHAR(13,10),'New break character : ')),
;   0704  2			 p6 = 24);
;   0705  2	    reset_term();
;   0706  2	    showbreak();
;   0707  2	    .stat
;   0708  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.AAL:	.ASCII  <13><10>\New break character : \ ;				      	      72  62  20  77  65  4E  0A  0D  00070
						 ;					      72  61  68  63  20  6B  61  65  00078
						 ;					      20  3A  20  72  65  74  63  61  00080



	.PSECT  $CODE$,NOWRT,2

U.20:
	.ENTRY  BREAK, ^M<R2>			 ;BREAK, Save R2		       0694 			       0004   00000
	CALLS   #0, W^U.23			 ;#0, U.23			       0699 	0000V  CF	     00  FB   00002
	CALLS   #0, W^U.4			 ;#0, U.4			       0700 	F842   CF	     00  FB   00007
	PUSHL   #24				 ;#24				       0704 			     18  DD   0000C
	PUSHAB  W^P.AAL				 ;P.AAL				      	    		      0000'  CF  9F   0000E
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00012
	PUSHL   #1				 ;#1				      	    			     01  DD   00014
	PUSHAB  W^U.44				 ;U.44				      	    		      0000'  CF  9F   00016
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0001A
	MOVQ    #55, -(SP)			 ;#55, -(SP)			      	    	       7E	     37  7D   0001C
	MOVZWL  W^U.48, -(SP)			 ;U.48, -(SP)			      	    	       7E     0000'  CF  3C   0001F
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00024
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   00026
	MOVL    R0, R2				 ;R0, STAT			      	    	       52	     50  D0   0002D
	CALLS   #0, W^U.5			 ;#0, U.5			       0705 	F859   CF	     00  FB   00030
	CALLS   #0, W^U.23			 ;#0, U.23			       0706 	0000V  CF	     00  FB   00035
	MOVL    R2, R0				 ;STAT, R0			       0708 	       50	     52  D0   0003A
	RET     				 ;				      	    				 04   0003D

; Routine Size:  62 bytes,    Routine Base:  $CODE$ + 082D


;   0709  1	
;   0710  1	
;   0711  1	GLOBAL ROUTINE suppress =
;   0712  2	    BEGIN
;   0713  2	    LOCAL
;   0714  2		ptyid : REF pty,
;   0715  2		id,
;   0716  2		stat;
;   0717  2	    id = getident();
;   0718  2	    IF .id EQL 0 THEN ptyid = .currpty ELSE
;   0719  2	      ptyid = findpty(.id);
;   0720  2	    IF .ptyid NEQA 0 THEN
;   0721  3	    BEGIN
;   0722  3	    lib$signal(pty__refuse,2,4,ptyid[ident]);
;   0723  3	    ptyid[accept] = 0;
;   0724  3	    passivate(.ptyid);
;   0725  2	    END ELSE lib$signal(pty__nopty,2,4,id);
;   0726  2	    1
;   0727  1	    END;





U.21:
	.ENTRY  SUPPRESS, ^M<R2>		 ;SUPPRESS, Save R2		       0711 			       0004   00000
	SUBL2   #4, SP				 ;#4, SP			      	    	       5E	     04  C2   00002
	CALLS   #0, W^U.18			 ;#0, U.18			       0717 	FF01   CF	     00  FB   00005
	MOVL    R0, (SP)			 ;R0, ID			      	    	       6E	     50  D0   0000A
	BNEQ    1$				 ;1$				       0718 			     07  12   0000D
	MOVL    W^U.39, R2			 ;U.39, PTYID			      	    	       52     0000'  CF  D0   0000F
	BRB     2$				 ;2$				      	    			     0A  11   00014
1$:	PUSHL   (SP)				 ;ID				       0719 			     6E  DD   00016
	CALLS   #1, W^U.6			 ;#1, U.6			      	    	FBCA   CF	     01  FB   00018
	MOVL    R0, R2				 ;R0, PTYID			      	    	       52	     50  D0   0001D
2$:	BEQL    3$				 ;3$				       0720 			     21  13   00020
	PUSHAB  24(R2)				 ;24(PTYID)			       0722 			18   A2  9F   00022
	PUSHL   #4				 ;#4				      	    			     04  DD   00025
	PUSHL   #2				 ;#2				      	    			     02  DD   00027
	PUSHL   #PTY__REFUSE			 ;#PTY__REFUSE			      	    		  00000000G  8F  DD   00029
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   0002F
	BICB2   #1, 28(R2)			 ;#1, 28(PTYID)			       0723 	  1C   A2	     01  8A   00036
	PUSHL   R2				 ;PTYID				       0724 			     52  DD   0003A
	CALLS   #1, W^U.9			 ;#1, U.9			      	    	F84F   CF	     01  FB   0003C
	BRB     4$				 ;4$				      	    			     13  11   00041
3$:	PUSHL   SP				 ;SP				       0725 			     5E  DD   00043
	PUSHL   #4				 ;#4				      	    			     04  DD   00045
	PUSHL   #2				 ;#2				      	    			     02  DD   00047
	PUSHL   #PTY__NOPTY			 ;#PTY__NOPTY			      	    		  00000000G  8F  DD   00049
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   0004F
4$:	MOVL    #1, R0				 ;#1, R0			       0727 	       50	     01  D0   00056
	RET     				 ;				      	    				 04   00059

; Routine Size:  90 bytes,    Routine Base:  $CODE$ + 086B


;   0728  1	
;   0729  1	
;   0730  1	GLOBAL ROUTINE remove =
;   0731  2	    BEGIN
;   0732  2	    LOCAL
;   0733  2		id,
;   0734  2		ptyid : ref pty;
;   0735  2	
;   0736  2	    id = getident();
;   0737  2	
;   0738  2	    IF .id EQL 0 THEN ptyid = .currpty ELSE
;   0739  2	      ptyid = findpty(.id);
;   0740  2	
;   0741  2	    IF .ptyid NEQA 0 THEN
;   0742  2	      deletepty(.ptyid) ELSE lib$signal(pty__nopty,2,4,id);
;   0743  2	    1     
;   0744  1	    END;





U.27:
	.ENTRY  REMOVE, ^M<>			 ;REMOVE, Save nothing		       0730 			       0000   00000
	SUBL2   #4, SP				 ;#4, SP			      	    	       5E	     04  C2   00002
	CALLS   #0, W^U.18			 ;#0, U.18			       0736 	FEA7   CF	     00  FB   00005
	MOVL    R0, (SP)			 ;R0, ID			      	    	       6E	     50  D0   0000A
	BNEQ    1$				 ;1$				       0738 			     07  12   0000D
	MOVL    W^U.39, R0			 ;U.39, PTYID			      	    	       50     0000'  CF  D0   0000F
	BRB     2$				 ;2$				      	    			     07  11   00014
1$:	PUSHL   (SP)				 ;ID				       0739 			     6E  DD   00016
	CALLS   #1, W^U.6			 ;#1, U.6			      	    	FB70   CF	     01  FB   00018
2$:	TSTL    R0				 ;PTYID				       0741 			     50  D5   0001D
	BEQL    3$				 ;3$				      	    			     09  13   0001F
	PUSHL   R0				 ;PTYID				       0742 			     50  DD   00021
	CALLS   #1, W^U.15			 ;#1, U.15			      	    	FD17   CF	     01  FB   00023
	BRB     4$				 ;4$				      	    			     13  11   00028
3$:	PUSHL   SP				 ;SP				      	    			     5E  DD   0002A
	PUSHL   #4				 ;#4				      	    			     04  DD   0002C
	PUSHL   #2				 ;#2				      	    			     02  DD   0002E
	PUSHL   #PTY__NOPTY			 ;#PTY__NOPTY			      	    		  00000000G  8F  DD   00030
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   00036
4$:	MOVL    #1, R0				 ;#1, R0			       0744 	       50	     01  D0   0003D
	RET     				 ;				      	    				 04   00040

; Routine Size:  65 bytes,    Routine Base:  $CODE$ + 08C5


;   0745  1	
;   0746  1	
;   0747  1	GLOBAL ROUTINE help =
;   0748  2	    BEGIN
;   0749  2	    EXTERNAL ROUTINE
;   0750  2		lbr$output_help : ADDRESSING_MODE(GENERAL);
;   0751  2	
;   0752  2	    LOCAL
;   0753  2		stat,
;   0754  2		helpdesc : BLOCK[8, byte];
;   0755  2	    $init_dyndesc(helpdesc);
;   0756  2	
;   0757  2	    stat = cli$present(%ASCID 'HELP');
;   0758  2	    IF .stat THEN
;   0759  2	      stat = cli$get_value(%ASCID 'HELP',helpdesc);
;   0760  2	
;   0761  2	    lbr$output_help(lib$put_output,
;   0762  2			    0,helpdesc,%ASCID 'SYS$HELP:PTY',
;   0763  2			    %REF(hlp$M_prompt+hlp$m_help),
;   0764  2			    lib$get_input)
;   0765  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.AAN:	.ASCII  \HELP\				 ;				      	    		      50  4C  45  48  00088
P.AAM:	.LONG   17694724			 ;				      	    			    010E0004  0008C
	.ADDRESS P.AAN				 ;				      	    			    00000000' 00090
P.AAP:	.ASCII  \HELP\				 ;				      	    		      50  4C  45  48  00094
P.AAO:	.LONG   17694724			 ;				      	    			    010E0004  00098
	.ADDRESS P.AAP				 ;				      	    			    00000000' 0009C
P.AAR:	.ASCII  \SYS$HELP:PTY\			 ;				      	      50  4C  45  48  24  53  59  53  000A0
						 ;					    		      59  54  50  3A  000A8
P.AAQ:	.LONG   17694732			 ;				      	    			    010E000C  000AC
	.ADDRESS P.AAR				 ;				      	    			    00000000' 000B0

	.EXTRN  LBR$OUTPUT_HELP

	.PSECT  $CODE$,NOWRT,2

U.22:
	.ENTRY  HELP, ^M<>			 ;HELP, Save nothing		       0747 			       0000   00000
	SUBL2   #12, SP				 ;#12, SP			      	    	       5E	     0C  C2   00002
	MOVL    #34471936, 4(SP)		 ;#34471936, HELPDESC		       0755 	  04   AE 020E0000   8F  D0   00005
	CLRL    8(SP)				 ;HELPDESC+4			      	    			08   AE  D4   0000D
	PUSHAB  W^P.AAM				 ;P.AAM				       0757 		      0000'  CF  9F   00010
	CALLS   #1, G^CLI$PRESENT		 ;#1, CLI$PRESENT		      	    00000000G  00	     01  FB   00014
	BLBC    R0, 1$				 ;STAT, 1$			       0758 	       0E	     50  E9   0001B
	PUSHAB  4(SP)				 ;HELPDESC			       0759 			04   AE  9F   0001E
	PUSHAB  W^P.AAO				 ;P.AAO				      	    		      0000'  CF  9F   00021
	CALLS   #2, G^CLI$GET_VALUE		 ;#2, CLI$GET_VALUE		      	    00000000G  00	     02  FB   00025
1$:	PUSHAB  G^LIB$GET_INPUT			 ;LIB$GET_INPUT			       0761 		  00000000G  00  9F   0002C
	MOVL    #33, 4(SP)			 ;#33, 4(SP)			       0763 	  04   AE	     21  D0   00032
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   00036
	PUSHAB  W^P.AAQ				 ;P.AAQ				       0762 		      0000'  CF  9F   00039
	PUSHAB  16(SP)				 ;HELPDESC			       0761 			10   AE  9F   0003D
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00040
	PUSHAB  G^LIB$PUT_OUTPUT		 ;LIB$PUT_OUTPUT		      	    		  00000000G  00  9F   00042
	CALLS   #6, G^LBR$OUTPUT_HELP		 ;#6, LBR$OUTPUT_HELP		      	    00000000G  00	     06  FB   00048
	RET     				 ;				       0765 				 04   0004F

; Routine Size:  80 bytes,    Routine Base:  $CODE$ + 0906


;   0766  1	
;   0767  1	
;   0768  1	GLOBAL ROUTINE connect =
;   0769  2	    BEGIN
;   0770  2	
;   0771  2	    LOCAL
;   0772  2	        ptyid,
;   0773  2		id,
;   0774  2		stat;
;   0775  2	    id = getident();
;   0776  2	    IF .id NEQU 0 THEN
;   0777  3	    BEGIN
;   0778  3		ptyid = findpty(.id);
;   0779  3		IF .ptyid EQLA 0 THEN
;   0780  4		BEGIN
;   0781  4		   LOCAL bio; 
;   0782  4	
;   0783  4		    lib$getjpi(%ref(jpi$_bytcnt),0,0,bio);
;   0784  4		    IF .bio LSSU ptybufsiz THEN RETURN ss$_exbytlm;
;   0785  4	
;   0786  4		    stat = newpty(ptyid,.id);
;   0787  4		    $reterr(.stat);
;   0788  3		END;
;   0789  3	        currpty = .ptyid;
;   0790  2	    END ELSE
;   0791  3	    BEGIN
;   0792  3		IF .currpty EQLA 0 THEN
;   0793  4		BEGIN
;   0794  4		stat = newpty(currpty,%C'A');
;   0795  4		$reterr(.stat)
;   0796  4		END
;   0797  2	    END;
;   0798  2	    dopty(.currpty)
;   0799  1	    END;





U.28:
	.ENTRY  CONNECT, ^M<R2>			 ;CONNECT, Save R2		       0768 			       0004   00000
	SUBL2   #12, SP				 ;#12, SP			      	    	       5E	     0C  C2   00002
	CALLS   #0, W^U.18			 ;#0, U.18			       0775 	FE16   CF	     00  FB   00005
	MOVL    R0, R2				 ;R0, ID			      	    	       52	     50  D0   0000A
	BEQL    3$				 ;3$				       0776 			     47  13   0000D
	PUSHL   R2				 ;ID				       0778 			     52  DD   0000F
	CALLS   #1, W^U.6			 ;#1, U.6			      	    	FAE6   CF	     01  FB   00011
	MOVL    R0, 8(SP)			 ;R0, PTYID			      	    	  08   AE	     50  D0   00016
	BNEQ    2$				 ;2$				       0779 			     32  12   0001A
	PUSHAB  4(SP)				 ;BIO				       0783 			04   AE  9F   0001C
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   0001F
	MOVZWL  #785, 12(SP)			 ;#785, 12(SP)			      	    	  0C   AE     0311   8F  3C   00021
	PUSHAB  12(SP)				 ;12(SP)			      	    			0C   AE  9F   00027
	CALLS   #4, G^LIB$GETJPI		 ;#4, LIB$GETJPI		      	    00000000G  00	     04  FB   0002A
	CMPL    4(SP), #1024			 ;BIO, #1024			       0784 00000400   8F	04   AE  D1   00031
	BGEQU   1$				 ;1$				      	    			     06  1E   00039
	MOVZWL  #10772, R0			 ;#10772, R0			      	    	       50     2A14   8F  3C   0003B
	RET     				 ;				      	    				 04   00040
1$:	PUSHL   R2				 ;ID				       0786 			     52  DD   00041
	PUSHAB  12(SP)				 ;PTYID				      	    			0C   AE  9F   00043
	CALLS   #2, W^U.14			 ;#2, U.14			      	    	FADB   CF	     02  FB   00046
	BLBC    R0, 5$				 ;STAT, 5$			       0787 	       27	     50  E9   0004B
2$:	MOVL    8(SP), W^U.39			 ;PTYID, U.39			       0789 	0000'  CF	08   AE  D0   0004E
	BRB     4$				 ;4$				      	    			     16  11   00054
3$:	TSTL    W^U.39				 ;U.39				       0792 		      0000'  CF  D5   00056
	BNEQ    4$				 ;4$				      	    			     10  12   0005A
	MOVZBL  #65, -(SP)			 ;#65, -(SP)			       0794 	       7E	41   8F  9A   0005C
	PUSHAB  W^U.39				 ;U.39				      	    		      0000'  CF  9F   00060
	CALLS   #2, W^U.14			 ;#2, U.14			      	    	FABD   CF	     02  FB   00064
	BLBC    R0, 5$				 ;STAT, 5$			       0795 	       09	     50  E9   00069
4$:	PUSHL   W^U.39				 ;U.39				       0798 		      0000'  CF  DD   0006C
	CALLS   #1, W^U.17			 ;#1, U.17			      	    	FCC1   CF	     01  FB   00070
5$:	RET     				 ;				       0799 				 04   00075

; Routine Size:  118 bytes,    Routine Base:  $CODE$ + 0956


;   0800  1	
;   0801  1	ROUTINE showbreak =
;   0802  2	    BEGIN
;   0803  2	    LOCAL
;   0804  2		brstr : word INITIAL(0);
;   0805  2	    IF .breakchar LSSU 32 THEN
;   0806  3	      brstr = %C'^' + 256*(.breakchar + %C'A' - 1)
;   0807  2	    ELSE
;   0808  2	      brstr = .breakchar;
;   0809  2	    lib$signal(pty__breakis,2,2,brstr)
;   0810  1	    END;





;SHOWBREAK
U.23:	.WORD   ^M<>				 ;Save nothing			       0801 			       0000   00000
	SUBL2   #4, SP				 ;#4, SP			      	    	       5E	     04  C2   00002
	CLRW    (SP)				 ;BRSTR				       0802 			     6E  B4   00005
	MOVZBL  W^U.44, R0			 ;U.44, R0			       0805 	       50     0000'  CF  9A   00007
	CMPB    R0, #32				 ;R0, #32			      	    	       20	     50  91   0000C
	BGEQU   1$				 ;1$				      	    			     0C  1E   0000F
	ASHL    #8, R0, R0			 ;#8, R0, R0			       0806 	       50	     08  78   00011
						 ;					    			     50       00014
	ADDW3   #16478, R0, (SP)		 ;#16478, R0, BRSTR		      	    	       50     405E   8F  A1   00015
						 ;					    			     6E       0001A
	BRB     2$				 ;2$				      	    			     03  11   0001B
1$:	MOVW    R0, (SP)			 ;R0, BRSTR			       0808 	       6E	     50  B0   0001D
2$:	PUSHL   SP				 ;SP				       0809 			     5E  DD   00020
	PUSHL   #2				 ;#2				      	    			     02  DD   00022
	PUSHL   #2				 ;#2				      	    			     02  DD   00024
	PUSHL   #PTY__BREAKIS			 ;#PTY__BREAKIS			      	    		  00000000G  8F  DD   00026
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   0002C
	RET     				 ;				       0810 				 04   00033

; Routine Size:  52 bytes,    Routine Base:  $CODE$ + 09CC


;   0811  1	
;   0812  1	GLOBAL ROUTINE ptystatus =
;   0813  2	    BEGIN
;   0814  2	    LOCAL
;   0815  2		stradr,
;   0816  2		messdesc : BLOCK[8, byte],
;   0817  2		ptyid : REF pty INITIAL(.ptyhead[0]);
;   0818  2	    BIND
;   0819  2		supp = %ASCID 'suppressed output',
;   0820  2		acc = %ASCID 'accept output';
;   0821  2	
;   0822  2	    showbreak();
;   0823  2	    $init_dyndesc(messdesc);
;   0824  2	    WHILE .ptyid NEQA ptyhead DO
;   0825  3		BEGIN
;   0826  3		IF .ptyid[accept] THEN stradr = acc ELSE
;   0827  3		 stradr = supp;
;   0828  3		lib$sys_fao(%ASCID 'Pty !AD !AS',
;   0829  3			    0,messdesc,4,ptyid[ident],
;   0830  3			    .stradr);
;   0831  3	        lib$put_output(messdesc);
;   0832  3		ptyid = .ptyid[flink];
;   0833  2		END;
;   0834  2	    1
;   0835  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.AAT:	.ASCII  \suppressed output\<0><0><0>	 ;				      	      73  73  65  72  70  70  75  73  000B4
						 ;					      75  70  74  75  6F  20  64  65  000BC
						 ;					    		      00  00  00  74  000C4
P.AAS:	.LONG   17694737			 ;				      	    			    010E0011  000C8
	.ADDRESS P.AAT				 ;				      	    			    00000000' 000CC
P.AAV:	.ASCII  \accept output\<0><0><0>	 ;				      	      6F  20  74  70  65  63  63  61  000D0
						 ;					      00  00  00  74  75  70  74  75  000D8
P.AAU:	.LONG   17694733			 ;				      	    			    010E000D  000E0
	.ADDRESS P.AAV				 ;				      	    			    00000000' 000E4
P.AAX:	.ASCII  \Pty !AD !AS\<0>		 ;				      	      20  44  41  21  20  79  74  50  000E8
						 ;					    		      00  53  41  21  000F0
P.AAW:	.LONG   17694731			 ;				      	    			    010E000B  000F4
	.ADDRESS P.AAX				 ;				      	    			    00000000' 000F8

U.53=		    P.AAS
U.54=		    P.AAU


	.PSECT  $CODE$,NOWRT,2

U.24:
	.ENTRY  PTYSTATUS, ^M<R2,R3>		 ;PTYSTATUS, Save R2,R3		       0812 			       000C   00000
	SUBL2   #8, SP				 ;#8, SP			      	    	       5E	     08  C2   00002
	MOVL    W^U.40, R2			 ;U.40, PTYID			       0817 	       52     0000'  CF  D0   00005
	CALLS   #0, B^U.23			 ;#0, U.23			       0822 	  BE   AF	     00  FB   0000A
	MOVL    #34471936, (SP)			 ;#34471936, MESSDESC		       0823 	       6E 020E0000   8F  D0   0000E
	CLRL    4(SP)				 ;MESSDESC+4			      	    			04   AE  D4   00015
	BRB     4$				 ;4$				       0824 			     33  11   00018
1$:	BLBC    28(R2), 2$			 ;28(PTYID), 2$			       0826 	       07	1C   A2  E9   0001A
	MOVAB   W^U.54, R3			 ;U.54, STRADR			      	    	       53     0000'  CF  9E   0001E
	BRB     3$				 ;3$				      	    			     05  11   00023
2$:	MOVAB   W^U.53, R3			 ;U.53, STRADR			       0827 	       53     0000'  CF  9E   00025
3$:	PUSHL   R3				 ;STRADR			       0830 			     53  DD   0002A
	PUSHAB  24(R2)				 ;24(PTYID)			       0829 			18   A2  9F   0002C
	PUSHL   #4				 ;#4				      	    			     04  DD   0002F
	PUSHAB  12(SP)				 ;MESSDESC			       0828 			0C   AE  9F   00031
	CLRL    -(SP)				 ;-(SP)				       0829 			     7E  D4   00034
	PUSHAB  W^P.AAW				 ;P.AAW				       0828 		      0000'  CF  9F   00036
	CALLS   #6, G^LIB$SYS_FAO		 ;#6, LIB$SYS_FAO		       0829 00000000G  00	     06  FB   0003A
	PUSHL   SP				 ;SP				       0831 			     5E  DD   00041
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   00043
	MOVL    (R2), R2			 ;(PTYID), PTYID		       0832 	       52	     62  D0   0004A
4$:	MOVAB   W^U.40, R0			 ;U.40, R0			       0824 	       50     0000'  CF  9E   0004D
	CMPL    R2, R0				 ;PTYID, R0			      	    	       50	     52  D1   00052
	BNEQ    1$				 ;1$				      	    			     C3  12   00055
	MOVL    #1, R0				 ;#1, R0			       0835 	       50	     01  D0   00057
	RET     				 ;				      	    				 04   0005A

; Routine Size:  91 bytes,    Routine Base:  $CODE$ + 0A00


;   0836  1	
;   0837  1	
;   0838  1	
;   0839  1	GLOBAL ROUTINE log =
;   0840  2	    BEGIN
;   0841  2	    EXTERNAL ROUTINE
;   0842  2		sys$modify : ADDRESSING_MODE(GENERAL);
;   0843  2	
;   0844  2	    LOCAL
;   0845  2		stat,
;   0846  2		filenamedesc : BLOCK[8,byte];
;   0847  2	
;   0848  2	    IF .logopen THEN 
;   0849  3	    BEGIN
;   0850  3	    lib$signal(pty__logopen,2,.logfab[fab$b_fns],.logfab[fab$l_fna]);
;   0851  3	    return 1
;   0852  2	    END ;
;   0853  2	    $init_dyndesc(filenamedesc);
;   0854  2	    stat = cli$get_value(%ASCID 'FILENAME',filenamedesc);
;   0855  2	    $reterr(.stat);
;   0856  2	    stat = lib$analyze_sdesc(filenamedesc,logfab[fab$b_fns],logfab[fab$l_fna]);
;   0857  2	    $reterr(.stat);
;   0858  2	    stat = $CREATE(FAB = logfab);
;   0859  2	    $reterr(.stat);
;   0860  2	    stat = $connect(RAB = lograb);
;   0861  2	    $reterr(.stat);
;   0862  2	    lib$signal(pty__logging,2,.logfab[fab$b_fns],.logfab[fab$l_fna]);
;   0863  2	    logopen = 1;
;   0864  2	    1
;   0865  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.AAZ:	.ASCII  \FILENAME\			 ;				      	      45  4D  41  4E  45  4C  49  46  000FC
P.AAY:	.LONG   17694728			 ;				      	    			    010E0008  00104
	.ADDRESS P.AAZ				 ;				      	    			    00000000' 00108

	.EXTRN  SYS$MODIFY, SYS$CREATE, SYS$CONNECT

	.PSECT  $CODE$,NOWRT,2

U.25:
	.ENTRY  LOG, ^M<>			 ;LOG, Save nothing		       0839 			       0000   00000
	SUBL2   #8, SP				 ;#8, SP			      	    	       5E	     08  C2   00002
	BLBC    W^U.38, 1$			 ;U.38, 1$			       0848 	       1A     0000'  CF  E9   00005
	PUSHL   W^U.36+44			 ;U.36+44			       0850 		      0000'  CF  DD   0000A
	MOVZBL  W^U.36+52, -(SP)		 ;U.36+52, -(SP)		      	    	       7E     0000'  CF  9A   0000E
	PUSHL   #2				 ;#2				      	    			     02  DD   00013
	PUSHL   #PTY__LOGOPEN			 ;#PTY__LOGOPEN			      	    		  00000000G  8F  DD   00015
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   0001B
	BRB     2$				 ;2$				       0851 			     68  11   00022
1$:	MOVL    #34471936, (SP)			 ;#34471936, FILENAMEDESC	       0853 	       6E 020E0000   8F  D0   00024
	CLRL    4(SP)				 ;FILENAMEDESC+4		      	    			04   AE  D4   0002B
	PUSHL   SP				 ;SP				       0854 			     5E  DD   0002E
	PUSHAB  W^P.AAY				 ;P.AAY				      	    		      0000'  CF  9F   00030
	CALLS   #2, G^CLI$GET_VALUE		 ;#2, CLI$GET_VALUE		      	    00000000G  00	     02  FB   00034
	BLBC    R0, 3$				 ;STAT, 3$			       0855 	       51	     50  E9   0003B
	PUSHAB  W^U.36+44			 ;U.36+44			       0856 		      0000'  CF  9F   0003E
	PUSHAB  W^U.36+52			 ;U.36+52			      	    		      0000'  CF  9F   00042
	PUSHAB  8(SP)				 ;FILENAMEDESC			      	    			08   AE  9F   00046
	CALLS   #3, G^LIB$ANALYZE_SDESC		 ;#3, LIB$ANALYZE_SDESC		      	    00000000G  00	     03  FB   00049
	BLBC    R0, 3$				 ;STAT, 3$			       0857 	       3C	     50  E9   00050
	PUSHAB  W^U.36				 ;U.36				       0858 		      0000'  CF  9F   00053
	CALLS   #1, G^SYS$CREATE		 ;#1, SYS$CREATE		      	    00000000G  00	     01  FB   00057
	BLBC    R0, 3$				 ;STAT, 3$			       0859 	       2E	     50  E9   0005E
	PUSHAB  W^U.37				 ;U.37				       0860 		      0000'  CF  9F   00061
	CALLS   #1, G^SYS$CONNECT		 ;#1, SYS$CONNECT		      	    00000000G  00	     01  FB   00065
	BLBC    R0, 3$				 ;STAT, 3$			       0861 	       20	     50  E9   0006C
	PUSHL   W^U.36+44			 ;U.36+44			       0862 		      0000'  CF  DD   0006F
	MOVZBL  W^U.36+52, -(SP)		 ;U.36+52, -(SP)		      	    	       7E     0000'  CF  9A   00073
	PUSHL   #2				 ;#2				      	    			     02  DD   00078
	PUSHL   #PTY__LOGGING			 ;#PTY__LOGGING			      	    		  00000000G  8F  DD   0007A
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   00080
	MOVW    #1, W^U.38			 ;#1, U.38			       0863 	0000'  CF	     01  B0   00087
2$:	MOVL    #1, R0				 ;#1, R0			       0865 	       50	     01  D0   0008C
3$:	RET     				 ;				      	    				 04   0008F

; Routine Size:  144 bytes,    Routine Base:  $CODE$ + 0A5B


;   0866  1	
;   0867  1	
;   0868  1	GLOBAL ROUTINE close =
;   0869  2	    BEGIN
;   0870  2	    BUILTIN
;   0871  2		testbitsc;
;   0872  2	
;   0873  2	    LOCAL
;   0874  2		stat;
;   0875  2	    IF TESTBITSC(logopen) THEN
;   0876  3	    BEGIN
;   0877  3	    lograb[rab$w_rsz] = .loglen;
;   0878  3	    stat = $put(rab = lograb);
;   0879  3	    $reterr(.stat);
;   0880  3	    lib$signal(pty__closelog,2,.logfab[fab$b_fns],.logfab[fab$l_fna]);
;   0881  3	    RETURN $CLOSE(FAB = logfab);
;   0882  2	    END;
;   0883  2	    pty__nolog
;   0884  1	    END;



	.EXTRN  SYS$CLOSE

U.26:
	.ENTRY  CLOSE, ^M<>			 ;CLOSE, Save nothing		       0868 			       0000   00000
	BBCC    #0, W^U.38, 1$			 ;#0, U.38, 1$			       0875 	0000'  CF	     00  E5   00002
						 ;					    			     39       00007
	MOVW    W^U.34, W^U.37+34		 ;U.34, U.37+34			       0877 	0000'  CF     0000'  CF  B0   00008
	PUSHAB  W^U.37				 ;U.37				       0878 		      0000'  CF  9F   0000F
	CALLS   #1, G^SYS$PUT			 ;#1, SYS$PUT			      	    00000000G  00	     01  FB   00013
	BLBC    R0, 2$				 ;STAT, 2$			       0879 	       2B	     50  E9   0001A
	PUSHL   W^U.36+44			 ;U.36+44			       0880 		      0000'  CF  DD   0001D
	MOVZBL  W^U.36+52, -(SP)		 ;U.36+52, -(SP)		      	    	       7E     0000'  CF  9A   00021
	PUSHL   #2				 ;#2				      	    			     02  DD   00026
	PUSHL   #PTY__CLOSELOG			 ;#PTY__CLOSELOG		      	    		  00000000G  8F  DD   00028
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   0002E
	PUSHAB  W^U.36				 ;U.36				       0881 		      0000'  CF  9F   00035
	CALLS   #1, G^SYS$CLOSE			 ;#1, SYS$CLOSE			      	    00000000G  00	     01  FB   00039
	RET     				 ;				      	    				 04   00040
1$:	MOVL    #PTY__NOLOG, R0			 ;#PTY__NOLOG, R0		       0884 	       50 00000000G  8F  D0   00041
2$:	RET     				 ;				      	    				 04   00048

; Routine Size:  73 bytes,    Routine Base:  $CODE$ + 0AEB


;   0885  1	
;   0886  1	
;   0887  1	ROUTINE init =
;   0888  2	    BEGIN
;   0889  2	    BUILTIN
;   0890  2		movc3;
;   0891  2	
;   0892  2	
;   0893  2	    LOCAL
;   0894  2	        iosb : iostatus,
;   0895  2		stat;
;   0896  2	
;   0897  2	    oldrwm = $setrwm(watflg = 1);
;   0898  2	    stat = $ASSIGN(devnam = %ASCID 'SYS$INPUT',chan = tt_chan);
;   0899  2	    $reterr(.stat);
; P 0900  2	    stat = $qiow(chan = .tt_chan,func = io$_sensemode,iosb = iosb,
;   0901  2	                 p1 = old_termchar,p2 = %ALLOCATION(old_termchar));
;   0902  2	    $reterr(.stat);
;   0903  2	    $reterr(.iosb[status]);
;   0904  2	
;   0905  2	    stat = $dclexh(desblk = desblk);
;   0906  2	    .stat
;   0907  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.ABB:	.ASCII  \SYS$INPUT\<0><0><0>		 ;				      	      55  50  4E  49  24  53  59  53  0010C
						 ;					    		      00  00  00  54  00114
P.ABA:	.LONG   17694729			 ;				      	    			    010E0009  00118
	.ADDRESS P.ABB				 ;				      	    			    00000000' 0011C

	.EXTRN  SYS$DCLEXH

	.PSECT  $CODE$,NOWRT,2

;INIT
U.16:	.WORD   ^M<>				 ;Save nothing			       0887 			       0000   00000
	SUBL2   #8, SP				 ;#8, SP			      	    	       5E	     08  C2   00002
	PUSHL   #1				 ;#1				       0897 			     01  DD   00005
	CALLS   #1, G^SYS$SETRWM		 ;#1, SYS$SETRWM		      	    00000000G  00	     01  FB   00007
	MOVL    R0, W^U.32			 ;R0, U.32			      	    	0000'  CF	     50  D0   0000E
	CLRQ    -(SP)				 ;-(SP)				       0898 			     7E  7C   00013
	PUSHAB  W^U.48				 ;U.48				      	    		      0000'  CF  9F   00015
	PUSHAB  W^P.ABA				 ;P.ABA				      	    		      0000'  CF  9F   00019
	CALLS   #4, G^SYS$ASSIGN		 ;#4, SYS$ASSIGN		      	    00000000G  00	     04  FB   0001D
	BLBC    R0, 2$				 ;STAT, 2$			       0899 	       34	     50  E9   00024
	CLRQ    -(SP)				 ;-(SP)				       0901 			     7E  7C   00027
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00029
	PUSHL   #12				 ;#12				      	    			     0C  DD   0002B
	PUSHAB  W^U.43				 ;U.43				      	    		      0000'  CF  9F   0002D
	CLRQ    -(SP)				 ;-(SP)				      	    			     7E  7C   00031
	PUSHAB  32(SP)				 ;IOSB				      	    			20   AE  9F   00033
	PUSHL   #39				 ;#39				      	    			     27  DD   00036
	MOVZWL  W^U.48, -(SP)			 ;U.48, -(SP)			      	    	       7E     0000'  CF  3C   00038
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0003D
	CALLS   #12, G^SYS$QIOW			 ;#12, SYS$QIOW			      	    00000000G  00	     0C  FB   0003F
	BLBC    R0, 2$				 ;STAT, 2$			       0902 	       12	     50  E9   00046
	BLBS    (SP), 1$			 ;IOSB, 1$			       0903 	       04	     6E  E8   00049
	MOVZWL  (SP), R0			 ;IOSB, R0			      	    	       50	     6E  3C   0004C
	RET     				 ;				      	    				 04   0004F
1$:	PUSHAB  W^U.42				 ;U.42				       0905 		      0000'  CF  9F   00050
	CALLS   #1, G^SYS$DCLEXH		 ;#1, SYS$DCLEXH		      	    00000000G  00	     01  FB   00054
2$:	RET     				 ;				       0907 				 04   0005B

; Routine Size:  92 bytes,    Routine Base:  $CODE$ + 0B34


;   0908  1	
;   0909  1	
;   0910  1	GLOBAL ROUTINE exit =
;   0911  2	    BEGIN
;   0912  2	    LOCAL
;   0913  2		stat;
;   0914  2	    stat = okexit();
;   0915  2	    doexit = .stat;
;   0916  2	    1
;   0917  1	    END;





U.30:
	.ENTRY  EXIT, ^M<>			 ;EXIT, Save nothing		       0910 			       0000   00000
	CALLS   #0, W^U.31			 ;#0, U.31			       0914 	0000V  CF	     00  FB   00002
	MOVB    R0, W^U.45			 ;STAT, U.45			       0915 	0000'  CF	     50  90   00007
	MOVL    #1, R0				 ;#1, R0			       0917 	       50	     01  D0   0000C
	RET     				 ;				      	    				 04   0000F

; Routine Size:  16 bytes,    Routine Base:  $CODE$ + 0B90


;   0918  1	
;   0919  1	
;   0920  1	GLOBAL ROUTINE spawn =
;   0921  2	    BEGIN
;   0922  2	    EXTERNAL ROUTINE
;   0923  2		lib$spawn : ADDRESSING_MODE(GENERAL);
;   0924  2	
;   0925  2	    LOCAL
;   0926  2		stat,
;   0927  2		command : REF BLOCK[8,BYTE] INITIAL(0);
;   0928  2	    stat = cli$present(%ASCID 'COMMAND');
;   0929  2	    IF .stat THEN
;   0930  3	    BEGIN
;   0931  3	    lib$get_vm(%REF(8),command);
;   0932  3	    $init_dyndesc(command);
;   0933  3	    stat = cli$get_value(%ASCID 'COMMAND',.command);
;   0934  3	    IF NOT .stat THEN command = 0;
;   0935  2	    END;
;   0936  2	    IF NOT empty(ptyhead) THEN clearctrly();
;   0937  2	    lib$spawn(.command);
;   0938  2	    IF NOT empty(ptyhead) THEN setctrly();
;   0939  2	    1
;   0940  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.ABD:	.ASCII  \COMMAND\<0>			 ;				      	      00  44  4E  41  4D  4D  4F  43  00120
P.ABC:	.LONG   17694727			 ;				      	    			    010E0007  00128
	.ADDRESS P.ABD				 ;				      	    			    00000000' 0012C
P.ABF:	.ASCII  \COMMAND\<0>			 ;				      	      00  44  4E  41  4D  4D  4F  43  00130
P.ABE:	.LONG   17694727			 ;				      	    			    010E0007  00138
	.ADDRESS P.ABF				 ;				      	    			    00000000' 0013C

	.EXTRN  LIB$SPAWN

	.PSECT  $CODE$,NOWRT,2

U.29:
	.ENTRY  SPAWN, ^M<R2>			 ;SPAWN, Save R2		       0920 			       0004   00000
	SUBL2   #8, SP				 ;#8, SP			      	    	       5E	     08  C2   00002
	CLRL    4(SP)				 ;COMMAND			       0921 			04   AE  D4   00005
	PUSHAB  W^P.ABC				 ;P.ABC				       0928 		      0000'  CF  9F   00008
	CALLS   #1, G^CLI$PRESENT		 ;#1, CLI$PRESENT		      	    00000000G  00	     01  FB   0000C
	MOVL    R0, R2				 ;R0, STAT			      	    	       52	     50  D0   00013
	BLBC    R2, 1$				 ;STAT, 1$			       0929 	       35	     52  E9   00016
	PUSHAB  4(SP)				 ;COMMAND			       0931 			04   AE  9F   00019
	MOVL    #8, 4(SP)			 ;#8, 4(SP)			      	    	  04   AE	     08  D0   0001C
	PUSHAB  4(SP)				 ;4(SP)				      	    			04   AE  9F   00020
	CALLS   #2, G^LIB$GET_VM		 ;#2, LIB$GET_VM		      	    00000000G  00	     02  FB   00023
	MOVL    4(SP), R0			 ;COMMAND, R0			       0932 	       50	04   AE  D0   0002A
	MOVL    #34471936, (R0)			 ;#34471936, (R0)		      	    	       60 020E0000   8F  D0   0002E
	CLRL    4(R0)				 ;4(R0)				      	    			04   A0  D4   00035
	PUSHL   R0				 ;R0				       0933 			     50  DD   00038
	PUSHAB  W^P.ABE				 ;P.ABE				      	    		      0000'  CF  9F   0003A
	CALLS   #2, G^CLI$GET_VALUE		 ;#2, CLI$GET_VALUE		      	    00000000G  00	     02  FB   0003E
	MOVL    R0, R2				 ;R0, STAT			      	    	       52	     50  D0   00045
	BLBS    R2, 1$				 ;STAT, 1$			       0934 	       03	     52  E8   00048
	CLRL    4(SP)				 ;COMMAND			      	    			04   AE  D4   0004B
1$:	CMPL    W^U.40, W^U.40+4		 ;U.40, U.40+4			       0936 	0000'  CF     0000'  CF  D1   0004E
	BEQL    2$				 ;2$				      	    			     05  13   00055
	CALLS   #0, W^U.3			 ;#0, U.3			      	    	F470   CF	     00  FB   00057
2$:	PUSHL   4(SP)				 ;COMMAND			       0937 			04   AE  DD   0005C
	CALLS   #1, G^LIB$SPAWN			 ;#1, LIB$SPAWN			      	    00000000G  00	     01  FB   0005F
	CMPL    W^U.40, W^U.40+4		 ;U.40, U.40+4			       0938 	0000'  CF     0000'  CF  D1   00066
	BEQL    3$				 ;3$				      	    			     05  13   0006D
	CALLS   #0, W^U.2			 ;#0, U.2			      	    	F422   CF	     00  FB   0006F
3$:	MOVL    #1, R0				 ;#1, R0			       0940 	       50	     01  D0   00074
	RET     				 ;				      	    				 04   00077

; Routine Size:  120 bytes,    Routine Base:  $CODE$ + 0BA0


;   0941  1	
;   0942  1	ROUTINE okexit =
;   0943  2	    BEGIN
;   0944  2	    LOCAL
;   0945  2		stat : INITIAL(1),
;   0946  2		messdesc : BLOCK[8, byte],
;   0947  2		ptyid : REF pty INITIAL(.ptyhead[0]);
;   0948  2	
;   0949  2	    $init_dyndesc(messdesc);
;   0950  2	    WHILE .ptyid NEQA ptyhead DO
;   0951  3		BEGIN
;   0952  3		lib$signal(pty__actpty,2,4,ptyid[ident]);
;   0953  3		stat = 0;
;   0954  3		ptyid = .ptyid[flink];
;   0955  2		END;
;   0956  2	    .stat
;   0957  1	    END;





;OKEXIT
U.31:	.WORD   ^M<R2,R3>			 ;Save R2,R3			       0942 			       000C   00000
	SUBL2   #4, SP				 ;#4, SP			      	    	       5E	     04  C2   00002
	MOVL    #1, R3				 ;#1, STAT			       0943 	       53	     01  D0   00005
	MOVL    W^U.40, R2			 ;U.40, PTYID			       0947 	       52     0000'  CF  D0   00008
	PUSHL   #34471936			 ;#34471936			       0949 		  020E0000   8F  DD   0000D
	CLRL    4(SP)				 ;MESSDESC+4			      	    			04   AE  D4   00013
	BRB     2$				 ;2$				       0950 			     19  11   00016
1$:	PUSHAB  24(R2)				 ;24(PTYID)			       0952 			18   A2  9F   00018
	PUSHL   #4				 ;#4				      	    			     04  DD   0001B
	PUSHL   #2				 ;#2				      	    			     02  DD   0001D
	PUSHL   #PTY__ACTPTY			 ;#PTY__ACTPTY			      	    		  00000000G  8F  DD   0001F
	CALLS   #4, G^LIB$SIGNAL		 ;#4, LIB$SIGNAL		      	    00000000G  00	     04  FB   00025
	CLRL    R3				 ;STAT				       0953 			     53  D4   0002C
	MOVL    (R2), R2			 ;(PTYID), PTYID		       0954 	       52	     62  D0   0002E
2$:	MOVAB   W^U.40, R0			 ;U.40, R0			       0950 	       50     0000'  CF  9E   00031
	CMPL    R2, R0				 ;PTYID, R0			      	    	       50	     52  D1   00036
	BNEQ    1$				 ;1$				      	    			     DD  12   00039
	MOVL    R3, R0				 ;STAT, R0			       0957 	       50	     53  D0   0003B
	RET     				 ;				      	    				 04   0003E

; Routine Size:  63 bytes,    Routine Base:  $CODE$ + 0C18


;   0958  1	
;   0959  1	ROUTINE main =
;   0960  2	    BEGIN
;   0961  2	
;   0962  2	    EXTERNAL
;   0963  2		ptyparse;
;   0964  2	
;   0965  2	    EXTERNAL ROUTINE
;   0966  2	        lib$establish : ADDRESSING_MODE(GENERAL),
;   0967  2	        cli$dispatch : ADDRESSING_MODE(GENERAL),
;   0968  2		cli$dcl_parse : ADDRESSING_MODE(GENERAL);
;   0969  2	
;   0970  2	    LOCAL
;   0971  2		stat;
;   0972  2	
;   0973  2	
;   0974  2	!    lib$establish(conditionhandler);
;   0975  2	    init();
;   0976  2	    DO
;   0977  3		BEGIN
;   0978  3		stat = cli$dcl_parse(0,ptyparse,lib$get_input,
;   0979  3			             lib$get_input,%ASCID 'PTY> ');
;   0980  3		IF .stat THEN
;   0981  4		BEGIN
;   0982  4		stat = cli$dispatch();
;   0983  4		$messerr(.stat);
;   0984  3		END ELSE
;   0985  3		IF .stat EQL RMS$_EOF THEN
;   0986  3		  doexit = okexit();
;   0987  3		END
;   0988  2	    UNTIL .doexit;
;   0989  2	    IF .logopen THEN
;   0990  2	      close() ELSE 1
;   0991  1	    END;



	.PSECT  $PLIT$,NOWRT,NOEXE,2

P.ABH:	.ASCII  \PTY> \<0><0><0>		 ;				      	      00  00  00  20  3E  59  54  50  00140
P.ABG:	.LONG   17694725			 ;				      	    			    010E0005  00148
	.ADDRESS P.ABH				 ;				      	    			    00000000' 0014C

	.EXTRN  PTYPARSE, LIB$ESTABLISH, CLI$DISPATCH, CLI$DCL_PARSE

	.PSECT  $CODE$,NOWRT,2

;MAIN
U.55:	.WORD   ^M<R2>				 ;Save R2			       0959 			       0004   00000
	SUBL2   #12, SP				 ;#12, SP			      	    	       5E	     0C  C2   00002
	CALLS   #0, W^U.16			 ;#0, U.16			       0975 	FED3   CF	     00  FB   00005
1$:	PUSHAB  W^P.ABG				 ;P.ABG				       0979 		      0000'  CF  9F   0000A
	PUSHAB  G^LIB$GET_INPUT			 ;LIB$GET_INPUT			       0978 		  00000000G  00  9F   0000E
	PUSHAB  G^LIB$GET_INPUT			 ;LIB$GET_INPUT			      	    		  00000000G  00  9F   00014
	PUSHAB  W^PTYPARSE			 ;PTYPARSE			      	    		      0000G  CF  9F   0001A
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   0001E
	CALLS   #5, G^CLI$DCL_PARSE		 ;#5, CLI$DCL_PARSE		      	    00000000G  00	     05  FB   00020
	MOVL    R0, R2				 ;R0, STAT			      	    	       52	     50  D0   00027
	BLBC    R2, 2$				 ;STAT, 2$			       0980 	       3D	     52  E9   0002A
	CALLS   #0, G^CLI$DISPATCH		 ;#0, CLI$DISPATCH		       0982 00000000G  00	     00  FB   0002D
	MOVL    R0, R2				 ;R0, STAT			      	    	       52	     50  D0   00034
	BLBS    R2, 3$				 ;STAT, 3$			       0983 	       43	     52  E8   00037
	MOVL    #34471936, 4(SP)		 ;#34471936, MESSDESC		      	    	  04   AE 020E0000   8F  D0   0003A
	CLRL    8(SP)				 ;MESSDESC+4			      	    			08   AE  D4   00042
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   00045
	CLRL    -(SP)				 ;-(SP)				      	    			     7E  D4   00048
	MOVL    R2, 8(SP)			 ;STAT, 8(SP)			      	    	  08   AE	     52  D0   0004A
	PUSHAB  8(SP)				 ;8(SP)				      	    			08   AE  9F   0004E
	CALLS   #3, G^LIB$SYS_GETMSG		 ;#3, LIB$SYS_GETMSG		      	    00000000G  00	     03  FB   00051
	MOVL    R0, R2				 ;R0, STAT			      	    	       52	     50  D0   00058
	BLBC    R2, 3$				 ;STAT, 3$			      	    	       1F	     52  E9   0005B
	PUSHAB  4(SP)				 ;MESSDESC			      	    			04   AE  9F   0005E
	CALLS   #1, G^LIB$PUT_OUTPUT		 ;#1, LIB$PUT_OUTPUT		      	    00000000G  00	     01  FB   00061
	BRB     3$				 ;3$				      	    			     13  11   00068
2$:	CMPL    R2, #98938			 ;STAT, #98938			       0985 0001827A   8F	     52  D1   0006A
	BNEQ    3$				 ;3$				      	    			     0A  12   00071
	CALLS   #0, W^U.31			 ;#0, U.31			       0986 	FF49   CF	     00  FB   00073
	MOVB    R0, W^U.45			 ;R0, U.45			      	    	0000'  CF	     50  90   00078
3$:	BLBC    W^U.45, 1$			 ;U.45, 1$			       0988 	       88     0000'  CF  E9   0007D
	BLBC    W^U.38, 4$			 ;U.38, 4$			       0989 	       06     0000'  CF  E9   00082
	CALLS   #0, W^U.26			 ;#0, U.26			       0990 	FE08   CF	     00  FB   00087
	RET     				 ;				      	    				 04   0008C
4$:	MOVL    #1, R0				 ;#1, R0			       0989 	       50	     01  D0   0008D
	RET     				 ;				       0991 				 04   00090

; Routine Size:  145 bytes,    Routine Base:  $CODE$ + 0C57


;   0992  1	END                           ! End of module
;   0993  0	ELUDOM






;				       PSECT SUMMARY
;
;	Name			 Bytes			       Attributes
;
;  $OWN$			     2268  NOVEC,  WRT,  RD ,NOEXE,NOSHR,  LCL,  REL,  CON,NOPIC,ALIGN(2)
;  $CODE$			     3304  NOVEC,NOWRT,  RD ,  EXE,NOSHR,  LCL,  REL,  CON,NOPIC,ALIGN(2)
;  $PLIT$			      336  NOVEC,NOWRT,  RD ,NOEXE,NOSHR,  LCL,  REL,  CON,NOPIC,ALIGN(2)




;				Library Statistics
;
;					     -------- Symbols --------	    Pages	Processing
;	File				     Total    Loaded   Percent      Mapped	Time
;
;  SYS$COMMON:[SYSLIB]STARLET.L32;2	     10093        69         0       598          00:00.2







;					COMMAND QUALIFIERS

;	BLI/MACH=(ASS,UNIQ)/SOU=NOHEAD/LIS=PTY.MAR/OPT=(LEV=3,SPEED) PTY

; Compilation Complete

	.END	U.55

$ say "Creating PTYMSG.MSG"
$ create ptymsg.msg
..facility pty,2030/prefix = pty__
breakis <break character is !AD>/info/fao=2
logging <logging on !AD>/info/fao=2
nolog   <no log file open>/warn/fao=2
closelog <closing !AD>/info/fao=2
nopty <no such pty : !AD>/warn/fao=2
actpty <active pty : !AD>/warn/fao=2
logopen <log file !AD already open>/fao=2/warn
connect <connecting to PTY !AD>/info/fao=2
accept <accepting input from PTY !AD>/info/fao=2
refuse <suppressing input from PTY !AD>/info/fao=2
break <new break character is !AD>/info/fao=2
..end
$ say "Creating PTYPARSE.CLD"
$ create ptyparse.cld
module ptyparse
define verb connect
  synonym c
  routine connect
  parameter p1 label PTYNAME
define verb accept
  routine acceptpty
  parameter p1 label ptyname
define verb suppress
  synonym refuse
  routine suppress
  parameter p1 label ptyname
define verb KILL
  synonym delete
  synonym zap
  synonym abandon
  routine remove
  parameter p1 label ptyname prompt "Pty " value(required)
define verb help
  synonym urk
  routine help
  parameter p1 label help value(type = $rest_of_line)
define verb status
  synonym show
  routine ptystatus
define verb log
  synonym open
  routine log
  parameter p1 label filename value(type = $FILE,default = "PTY.LOG")
define verb close
  routine close
define verb break
  synonym escape
  routine break
define verb exit
  synonym quit
  routine exit
define verb spawn
  synonym $
  routine spawn 
  parameter p1 label command value(type = $rest_of_line)
$ say "Creating PTY.HLP"
$ create pty.hlp
1 HELP
  PTY is a program that allows you to have multiple
  jobs running on one terminal.
  To create a job, you simply issue the command CONNECT [ptyid].
  You may also log output from the PTY to a file by issuing 
  the LOG command.
1 ACCEPT
  Format : ACCEPT [ptyid]
  Accept input from the desired PTY even if in command mode
1 BREAK
  Format : BREAK
           New break character : 
  Sets the break character.
  
  The break character is the character you type when you want
  to return to PTY command level.
  The default break character is ^\.
1 CONNECT 
  Format : CONNECT [ptyid]
  Connect to PTY.
1 KILL
  Format : KILL ptyid
  KILL a PTY.

  When removing a PTY that has pending output, the pending output
  will be written to your terminal.
1 Ptyid
  Ptyid is the name of a PTY.
  It consist of up to four printable  characters.

  Default ptyid is the last pty you were connected to.
  If you haven't connected to a pty yet, the default name
  is 'A'.
  If you have KILLed the current pty, the default pty is
  the one most recently created.
1 SPAWN
  Format : SPAWN [dcl-command]
  Spawns a sub-process, optionally executes a command.

  Of course, things that happen in the sub-process are
  *not* logged to the log-file.
  If that was possible, why do you think this program was written ?
1 STATUS
  Format : STATUS
  Reports the current break character and
  PTYs with their name and accept status.
1 SUPPRESS [ptyid]
  Suppress input from PTY when in command mode.
1 LOG 
  Format : LOG [filespec]
  Start logging on the file specified by filespec.

  Default filespec is "PTY.LOG"
  Everything received from all PTYs is logged.
1 CLOSE
  Format : CLOSE
  Close the log file opened by the command LOG
1 EXIT
  Format : EXIT or <CTRL/Z>
  Exit from the PTY program.

  You are not allowed to exit if there are active PTYs.
  I.e. You have to KILL all PTYs first.
  However ^Y or ^C will let you exit with a warning message,
  you will then have the opportunity to continue with the 
  CONTINUE DCL command.
$ say "Creating PTYBUILD.COM"
$ create ptybuild.com
$ DECK
$ say := write sys$output
$ BLISSp = f$search("SYS$SYSTEM:BLISS32.EXE")
$ IF BLISSp .eqs. "" THEN GOTO ibm
$ say "Compiling PTY.B32"
$ BLISS pty/opt=(lev:3,speed)
$ GOTO cont
$ibm:
$ say "You miss the BLISS compiler, I'll use the MACRO version.."
$ say "Assembling PTY.MAR"
$ macro pty
$cont:
$ say "Making help library PTY.HLB"
$ libr/crea/help pty pty
$ say "Compiling the message file PTYMSG.MSG"
$ mess ptymsg
$ say "Compiling the command file PTYPARSE.CLD"
$ set comm/obj ptyparse
$ say "Linking stuff..."
$ link pty,ptyparse,ptymsg/notrace
$ EOD
$ type sys$input
You may now run the procedure PTYBUILD.COM to
compile and link the PTY program.
The program assumes that you move PTY.HLB to SYS$HELP,
if you don't want to put it there, you should edit
the file PTY.B32 (or PTY.MAR) (search for SYS$HELP)
prior to running the PTYBUILD file.
