	INTEGER LMODE,CMODE,TMODE,FMODE,BMODE,FFLG,HFLG,BUFI(1)
	BYTE BUF(2,80,48),BUFS(7680),NCHAR(2),ZERO(2),TBUF(80)
	BYTE LNAME(30),RNAME(30),WNAME(30)
	COMMON IGO,FMODE,BMODE,IFOR,IBAC,IFORD,IBACD
	EQUIVALENCE (BUF(1,1,1),BUFS(1))
	EQUIVALENCE (BUFS(1),BUFI(1))
	DATA ZERO/0,0/,IFORD,IBACD/7,"70/
	CALL KBINIT(,,1)
	CALL WDFUIC("300,"324)
	IFILE=0
	IHELP=1
	IESC=.FALSE.
	IGOT=.FALSE.		!DON'T KNOW LAST CHAR
	NUM=0
	IYC=4			!CURRENT Y POS'N
	IXC=1			!   "    X  "
	IXS=IXC
	IYS=IYC
	IPOS=.TRUE.		!WE KNOW CURRENT POS'N
	ISTATC="007
	IFOR=7
	IBAC="00
	IFORD=0
	IBACD=0-1
	HFLG=.TRUE.		!HORIZONTAL TEXT MODE
	FFLG=.TRUE.		!FORGROUND(FG) FLAG
	LMODE=.TRUE.		!LINE MODE
	CMODE=.FALSE.		!FILL MODE
	TMODE=.FALSE.		!TEXT MODE
	SMODE=.FALSE.		!SCROLL MODE
	FMODE=.TRUE.		!FOREGROUND (FG) DELETE
	BMODE=.FALSE.		!BACKGROUND (BG) DELETE
1	DO (I=1,7680,2)
	   BUFS(I)="40
	   BUFS(I+1)="00
	FIN
	CALL INIT		!CLEAR AND INIT ISC
	GOTO 3000		!BRANCH TO HELP FILE AND RETURN
7	IF(.NOT.IPOS)CALL GPOS(IXC,IYC)!GET CURSOR POS'N
	IF(.NOT.HFLG)CALL ANGLE(2)
	IPOS=.TRUE.		!SHOW WE KNOW IT
	CALL HOME
	CALL SSTAT(7)
	CALL CLRLIN		!CLEAR TOP LINE
	CALL APOSV(8,1)
	IF(TMODE)CALL KBWR(8,'***TEXT')
	IF(LMODE)CALL KBWR(8,'***LINE')
	IF(CMODE)CALL KBWR(8,'***FILL')
	IF(SMODE)CALL KBWR(9,'***SCROLL')
	CALL KBWR(8,' MODE***')
	CALL APOSV(43,1)
	CALL KBWR(29,'FLAG  COLOR  OVERLAY  DELETE')
	CALL CLRNXT		!CLR NEXT LINE
	CALL APOSV(32,2)
	CALL KBWRW(10,'BACKGROUND')
	IF(.NOT.FFLG)
	CALL APOSV(44,2)		!FLAG POINTS TO BG
	CALL KBWR(1,'*')
	FIN
	CALL APOSV(51,2)		!POS'N FOR BG COLOR
	CALL SSTAT(IBAC)
	CALL KBWR(1,' ')		!DISPLAY BG COLOR
	CALL APOSV(56,2)		!POS'N FOR DOMINANT STATUS
	CALL SSTAT(7)
	IF(BMODE)CALL KBWR(3,'YES')
	IF(.NOT.BMODE)CALL KBWR(2,'NO')
	CALL APOSV(65,2)		!POS'N FOR DELETE STATUS OR COLOR
	CONDITIONAL
	(BMODE)CALL KBWR(3,'ALL')
	(IBACD.LT.0)CALL KBWR(3,'NIL')		!NO DELETEABLE BG COLOR
	(OTHERWISE)
	CALL SSTAT(IBACD)		!SHOW BG COLOR WHICH WILL ALWAYS
	CALL KBWR(1,' ')		!BE OVER WRITTEN
	CALL SSTAT(7)
	FIN
	FIN
	CALL CLRNXT			!CLR NEXT LINE
	IF(TMODE)
	CALL APOSV(11,3)
	IF(HFLG)CALL KBWR(10,'HORIZONTAL')
	IF(.NOT.HFLG)CALL KBWR(8,'VERTICAL')
	FIN
	CALL APOSV(32,3)
	CALL KBWR(10,'FOREGROUND')
	IF(FFLG)
	CALL APOSV(44,3)		!SHOW FLAG POINTING AT BG
	CALL KBWR(1,'*')
	FIN
	CALL APOSV(51,3)		!POS'N FOR FG COLOR
	IFA=IFOR*"10
	CALL SSTAT(IFA)
	CALL KBWRW(1,' ')		!SHOW FG COLOUR
	CALL SSTAT(7)
	CALL APOSV(56,3)		!POS'N FOR FG DOMINANT STATUS
	IF(.NOT.FMODE)CALL KBWR(2,'NO')	!SHOW FG DOMINANT STATUS
	IF(FMODE)CALL KBWR(3,'YES')	   
	CALL APOSV(65,3)		!POS'N FOR FG DELETE STATUS
	CONDITIONAL
	(FMODE)CALL KBWR(3,'ALL')
	(IFORD.GE.0)CALL KBWR(3,'NIL')
	(OTHERWISE)
	IFA=IFORD*"10
	CALL SSTAT(IFA)
	CALL KBWRW(1,' ')		!SHOW FG DELETE COLOUR
	FIN
	FIN
	CALL APOSV(IXC,IYC)
	IGO=.TRUE.
	CALL SPRINT(ZERO,ISTATC)
85	IF(.NOT.HFLG)CALL ANGLE(4)
C
100	IESC=.FALSE.
105	IF(IGOT)GOTO 110			!WE ALREADY KNOW CHAR.
	I=ICHAR()
	IF(I.GT.0)GOTO 110
	CALL KBRDW(1,NCHAR(1))		!READ ONE CHARACTER
	I=NCHAR(1)
110	IGOT=.FALSE.
	IF(I.EQ.1)GOTO 2500	!WE EXIT
	IF(I.EQ.3)GOTO 2500	!WE EXIT
	IF(I.LT.7)GOTO 100	!IGNORE THESE CHAR.
	IF(I.EQ.8)GOTO 125	!HOME
	IF(I.LT.11)GOTO 130	!GO ECHO TAB(9), LF(10)
	IF(I.EQ.13)GOTO 140	!ECHO CR
	IF(I.EQ.25)GOTO 130	!CUR RIGHT
	IF(I.EQ.26)GOTO 130	!CUR LEFT
	IF(I.EQ.28)GOTO 130	!CUR UP
	IF(I.LT.16)GOTO 100	!IGNORE
	IF(I.LE.23)GOTO 150	!COLOUR
	IF(I.EQ.27)GOTO 190	!ESC SPECIAL CHARACTER
	IF(I.LT.29)GOTO 100
	IF(I.EQ.29)GOTO 160	!FG ON
	IF(I.EQ.30)GOTO 170	!BG ON
	IF(I.EQ.31)GOTO 100	!BLINK MODE
	IF(IESC)GOTO 120
	IF(TMODE)GOTO 500
120	IF((I.GE."60).AND.(I.LE."71))GOTO 290	!NUMBER
	NUM=0
	IF(I.GT."141)I=I.AND."137	!LOWER TO UPER
	IF(I.EQ."110)GOTO 3005		!H HELP
	IF(I.EQ."115)GOTO 2000	!M SHOW WHOLE SCREEN
	IF(I.EQ."104)GOTO 210	!D SET DELET COLOR
	IF(I.EQ."106)GOTO 230	!F FILL
	IF(I.EQ."124)GOTO 240	!T TEXT
	IF(I.EQ."114)GOTO 250	!L LINE
	IF(I.EQ."130)GOTO 225	!Z SCROLL MODE
	IF(I.EQ."117)GOTO 260	!O OVERLAY STATUS
	IF(I.EQ."126)GOTO 280	!V HORIZONTAT/VERTICAL
	IF(I.EQ."122)GOTO 300	!R READ
	IF(I.EQ."127)GOTO 310	!W WRITE
	IF(I.EQ."103)GOTO 320	!C CLOSE
	IF(I.EQ."120)GOTO 330	!P PAGE
	IF(I.EQ."131)GOTO 340	!Y ANK
	IF(I.EQ."125)GOTO 350	!U OUTPUT PAGE
	IF(I.EQ."123)GOTO 1000	!S TART
	IF(I.EQ."105)GOTO 1010	!E END
	GOTO 3000
C
125	IF(NUM.EQ.0)GOTO 130	!HOME
	IF(.NOT.IPOS)CALL GPOS(IXC,IYC)
	IX=NUM/100
	IY=NUM-(IX*100)
	IF(IX.GT.81)IX=80
	IF(IX.EQ.0)IX=IXC
	IF(IY.GT.48)IY=48
	IF(IY.EQ.0)IY=IYC
	IXC=IX
	IYC=IY
128	CALL APOSV(IXC,IYC)
	IPOS=.TRUE.
	GOTO 146
130	IF(NUM.EQ.0)NUM=1	!CURSER MOVEMENTS
	IF(SMODE)GOTO 360	!GO FOR SCROL MODE
C JUST ECHO MOVE CHAR.
	DO(J=1,NUM)CALL KBWR(1,I)
	GOTO 145
140	CALL CRLF
145	IPOS=.FALSE.		!WE NO LONGER KNOW POS'N
146	NUM=0			!CLEAR MOVEMENT COUNTER
	GOTO 100		!AND GO READ NEXT CHARCTER
C	COLOR CHANGE
150	I=I.AND.7		!GET RID OF EXTRA BITS
	IF(.NOT.FFLG)I=I*"10	!SHIFT BITS FOR BG
	IF(.NOT.FFLG)ISTATC=ISTATC.AND."307.OR.I
	IF(FFLG)ISTATC=ISTATC.AND."370.OR.I
	IFOR=ISTATC.AND."7
	IBAC=ISTATC.AND."70
	GOTO 7
C
160	FFLG=.TRUE.		!FLAG SET TO FG
	GOTO 172
170	FFLG=.FALSE.		!FLAG SET TO BG
172	CALL KBRDW(1,NCHAR(1))		!READ ONE CHAR.
	I=NCHAR(1)
	IF((I.GE."120).AND.(I.LE."127))GOTO 150	!COLOR
	IGOT=.TRUE.
	GOTO 7
C
190	NUM=0
	IF(IESC)GOTO 7
	IESC=.TRUE.
	GOTO 105
C
210	CALL KBRDW(1,I)
	IF((I.GE."120).AND.(I.LE."127))GOTO 220	!COLOR
	   IGOT=.TRUE.
	   IF(.NOT.FFLG)IBACD=-IBACD-1
	   IF(FFLG)IFORD=-IFORD-1
	   GOTO 7
220	I=I.AND.7
	IF(FFLG)IFORD=I
	IF(.NOT.FFLG)IBACD=I*"10
	GOTO 7
225	SMODE=.TRUE.		!SCROLL MODE
	CMODE=.FALSE.
	GOTO 235
230	IF(CMODE)GOTO 1100	!GO FILL IN SQUARE
	CMODE=.TRUE.		!FILL MODE
	SMODE=.FALSE.
235	TMODE=.FALSE.
	BMODE=.TRUE.
	FMODE=.FALSE.
	FFLG=.FALSE.
	LMODE=.FALSE.
	IF(IBACD.LT.0)IBACD=-IBACD-1
	GOTO 255
240	TMODE=.TRUE.		!TEXT MODE
	CMODE=.FALSE.
	SMODE=.FALSE.
	BMODE=.FALSE.
	FMODE=.TRUE.
	FFLG=.TRUE.
	LMODE=.FALSE.
	HFLG=.TRUE.
	IF(IBACD.LT.0)IBACD=-IBACD-1
	GOTO 285
C
250	LMODE=.TRUE.		!LINE MODE
	CMODE=.FALSE.
	SMODE=.FALSE.
	TMODE=.FALSE.
	BMODE=.FALSE.
	FMODE=.TRUE.
	FFLG=.TRUE.
	IF(IBACD.GE.0)IBACD=-IBACD-1
255	HFLG=.TRUE.
	GOTO 285
C
260	IF(FFLG)FMODE=.NOT.FMODE	!FG DOMINANT SWITCH
	IF(.NOT.FFLG)BMODE=.NOT.BMODE	!BG DOMINENT SWITCH
	GOTO 7
C
280	IF(.NOT.TMODE)GOTO 3000
	HFLG=.NOT.HFLG			!VERTICAL/HORIZONTAL
285	IF(HFLG)CALL ANGLE(2)
	IF(.NOT.HFLG)CALL ANGLE(4)
	GOTO 7
C
290	I=I.AND."17			!CREATE NUMBER
	IF(NUM.GT.3760)NUM=NUM-3760
	NUM=NUM*10+I
	GOTO 105
C
300	CALL CLRTOP
	IF((IFILE.AND.1).NE.0)CALL CLMES(2,RNAME,-1)	!READ
	IFILE=IFILE.AND.2		!SHOW ITS CLOSED
	LUN=2
	GOTO 3500
C
310	CALL CLRTOP
	LUN=3
	IF((IFILE.AND.2).EQ.0)GOTO 3500
	I=IRESP('DO YOU WANT TO SAVE YOUR OUTPUT FILE? ')
	IF(I.GT.0)GOTO 85		!^Z IGNORE WRITE REQUEST
	CALL CLMES(3,WNAME,I)
	IFILE=IFILE.AND.1		!SHOW ITS CLOSED
	GOTO 3500
C
320	CALL CLRTOP
	IF((IFILE.AND.1).NE.0)CALL CLMES(2,RNAME,-1)	!CLOSE
	IF((IFILE.AND.2).NE.0)CALL CLMES(3,WNAME,-1)
	IF(IFILE.EQ.0)CALL CLMES(0)
	IF(IFILE.EQ.0)GOTO 3000			!GO SEE IF HE NEEDS HELP
	IFILE=0
	GOTO 85
C
330	CALL CLRTOP
	IF(IFILE.EQ.3)GOTO 3600
	IF((IFILE.AND.1).EQ.0)CALL PRINTW(' NO FILE TO READ')
	IF((IFILE.AND.2).EQ.0)CALL PRINTW(' NO FILE TO WRITE')
	GOTO 3000
340	CALL CLRTOP
	IF((IFILE.AND.1).NE.0)GOTO 3635
	CALL PRINTW(' NO FILE TO READ')
	GOTO 3000
350	CALL CLRTOP
	IF((IFILE.AND.2).NE.0)GOTO 355
	CALL PRINTW(' NO FILE TO WRITE')
	GOTO 3000
355	IF(IWRITW(BUFI,7680,3).LT.0)GOTO 3670
	CALL PRINTW('$I HAVE WRITTEN TO ')
	CALL PRINTW(0,WNAME)
	GOTO 85
360	IF(I.NE.10.AND.I.NE.28)GOTO 85
	IF(.NOT.IPOS)CALL GPOS(IXC,IYC)
	CALL HOME
C CURSER UP
	IF(I.EQ.28)
	ITO=47
	IFR=1
	INC=1
	NCHAR(2)="126
	FIN
	IF(I.EQ.10)
C	CURSER DOWN
	ITO=2
	IFR=48
	INC=-1
	NCHAR(2)="125
	FIN
	NCHAR(1)=27
	J1="40
	J2=ISTATC.AND."77
	IGO=.TRUE.
	CALL SPRINT(ZERO,J2)
	DO(I=1,NUM)
	CALL KBWRW(2,NCHAR)
	DO(IR=IFR,ITO,INC)
	DO(IC=1,80)
	BUF(1,IC,IR)=BUF(1,IC,IR+INC)
	BUF(2,IC,IR)=BUF(2,IC,IR+INC)
	FIN
	FIN
	DO(IC=1,80)
	BUF(1,IC,ITO+INC)=J1
	BUF(2,IC,ITO+INC)=J2
	FIN
	FIN
	GOTO 128
C
C TEXT MODE
500	IF(IPOS)GOTO 510	!DO WE KNOW CURRENT POS'N
	   CALL GPOS(IXC,IYC)	!NO, SO GET IT
	   IPOS=.TRUE.
510	J1=I
	J2=BUF(2,IXC,IYC).AND."77	!GET CURRENT COLORS
	CALL SPRINT(J1,J2)
	BUF(1,IXC,IYC)=J1
	BUF(2,IXC,IYC)=J2
	IF(.NOT.HFLG)GOTO 530	!GO FOR VERTICAL
	IF(IXC.GE.80)GOTO 145
	   IXC=IXC+1
	   GOTO 100
530	IF(IYC.GE.48)GOTO 145
	IYC=IYC+1
	GOTO 100
C
C LINE AND FILL MODE
1000	CALL GPOS(IXS,IYS)	!GET START POS'N
	GOTO 100
1010	CALL GPOS(IXE,IYE)	!GET END POS'N
	IYES=IYE		!SAVE CURRENT POS'N
	IXES=IXE
	IXC=IXE
	IYC=IYE
	IF(IXS.LE.IXE)GOTO 1020	!SORT OUT SMALLEST X & Y
	   IXE=IXS
	   IXS=IXES
1020	IF(IYS.LE.IYE)GOTO 1030
	   IYE=IYS
	   IYS=IYES
1030	IG0=.TRUE.
	CALL SPRINT(0,ISTATC)
	IF(.NOT.CMODE)GOTO 1500
	GOTO 1200
C
C FIND BOUNDRIES FOR FILL
1100	IF(.NOT.IPOS)CALL GPOS(IXC,IYC)
	IPOS=.TRUE.
	DO 1120 IXS=IXC,1,-1
	   IF((BUF(2,IXS,IYC).AND."200).NE.0)GOTO 1125
1120	CONTINUE
	IXS=1
1125	DO 1130 IXE=IXC,80
	   IF((BUF(2,IXE,IYC).AND."200).NE.0)GOTO 1135
1130	CONTINUE
	IXE=80
1135	DO 1140 IYS=IYC,1,-1
	   IF((BUF(2,IXC,IYS).AND."200).NE.0)GOTO 1145
1140	CONTINUE
	IYS=1
1145	DO 1150 IYE=IYC,48
	   IF((BUF(2,IXC,IYE).AND."200).NE.0)GOTO 1155
1150	CONTINUE
	IYE=48
1155	IF(IXE.LT.80)IXE=IXE-1
	IF(IYE.LT.48)IYE=IYE-1
C
C FILL MODE
1200	DO 1250 IY=IYS,IYE
	   CALL APOSV(IXS,IY)
	   DO 1240 IX=IXS,IXE
	      J1=BUF(1,IX,IY)
	      J2=BUF(2,IX,IY)
	      CALL SPRINT(J1,J2)	!SPECIAL PRINT
	      BUF(2,IX,IY)=J2
	      BUF(1,IX,IY)=J1
1240	   CONTINUE
	   IGO=.TRUE.
	   CALL SPRINT(0,ISTATC)	!GET OUT OF SPECIAL PRINT MODE
1250	CONTINUE
1260	IXS=IXES
	IYS=IYES
	CALL APOSV(IXC,IYC)	!RETURN TO ORIGINAL POS'N
	IPOS=.TRUE.		!SHOW WE KNOW IT
	GOTO 100
C
C LINE MODE
1500	IF(IXS.EQ.IXE)GOTO 1555
	CALL ANGLE(2)
	INC=IYE-IYS
	IF(INC.EQ.0)INC=1
	N1="21
	N2=1
	DO 1550 IY=IYS,IYE,INC
	   CALL APOSV(IXS,IY)
	   IF(IY.EQ.48)N1="210
	   IF(IY.EQ.48)N2="10
	   DO 1540 IX=IXS,IXE
	      J1=BUF(1,IX,IY)
	      J2=BUF(2,IX,IY)
	      IF((J2.AND."200).NE.0)GOTO 1520
	         J1=0
	         J2=J2.OR."200
1520	      J1=J1.OR.N2
	      IF(IX.NE.IXE)J1=J1.OR.N1
	      IF(IX.EQ.80)J1=J1.OR.N1
	      CALL SPRINT(J1,J2)
	      BUF(1,IX,IY)=J1
	      BUF(2,IX,IY)=J2
1540	   CONTINUE
	   IGO=.TRUE.
	   CALL SPRINT(0,ISTATC)
1550	CONTINUE
1555	IF(IYS.EQ.IYE)GOTO 1260
	CALL ANGLE(4)
	INC=IXE-IXS
	IF(INC.EQ.0)INC=1
	N1="17
	N2="1
	DO 1590 IX=IXS,IXE,INC
	   IF(IX.EQ.80)N1="360
	   IF(IX.EQ.80)N2="20
	   CALL APOSV(IX,IYS)
	   DO 1570 IY=IYS,IYE
	      J1=BUF(1,IX,IY)
	      J2=BUF(2,IX,IY)
	      IF((J2.AND."200).NE.0)GOTO 1560
	         J1=0
	         J2=J2.OR."200
1560	      J1=J1.OR.N2
	      IF(IY.NE.IYE)J1=J1.OR.N1
	      IF(IY.EQ.48)J1=J1.OR.N1
	      CALL SPRINT(J1,J2)
	      BUF(1,IX,IY)=J1
	      BUF(2,IX,IY)=J2
1570	   CONTINUE
	   IGO=.TRUE.
	   CALL SPRINT(0,ISTATC)
1590	CONTINUE
	CALL ANGLE(2)
	GOTO 1260
C
2000	IF(.NOT.IPOS)CALL GPOS(IXC,IYC)	!SAVE CURRENT POS'N
	IPOS=.TRUE.
2005	CALL INIT
	CALL APOSB(1,1,7)
	NCHAR(1)=27
	NCHAR(2)=29
	CALL KBWR(2,NCHAR)	!PUT ISC IN BLOCK RECEIVE MODE
	DO 2010 I=1,7680,160
	   CALL KBWRW(160,BUFS(I))	!FILL ISC MEMORY
2010	CONTINUE
	NCHAR(1)="377
	NCHAR(2)=0
	CALL KBWRW(2,NCHAR)	!TERMINATE BLOCK RECEIVE MODE
	J1=BUF(1,1,1)
	J2=BUF(2,1,1)
	CALL HOME
	IGO=.TRUE.
	CALL SPRINT(J1,J2)
	CALL SPRINT(ZERO,ISTATC)	!RESTORE STATUS
	IF(IPOS)CALL APOSV(IXC,IYC)	!RETURN TO SAVED POS'N
	IF(.NOT.IPOS)CALL APOSV(81,48)
	GOTO 100
C
C EXIT FROM PROGRAM
2500	IF((IFILE.AND.2).EQ.0)GOTO 2520	!EXIT IF NO OUTPUT FILE OPEN
	CALL CLRTOP
	I=IRESP('DO YOU WANT TO SAVE YOUR OUTPUT FILE? ')
	IF(I.GT.0)GOTO 85		!^Z IGNORE CLOSE COMMAND
	CALL CLMES(3,WNAME,I)
2520	CALL ANGLE(2)
	CALL KBWRW(1,27)
	CALL KBWRW(1,11)	!SET ROLL UP
	CALL SSTAT("47)
	CALL APOSV(1,47)
	CALL EXIT
C
C HELP FUNCTION
3000	IHELP=IHELP-1
	IF(IHELP.GT.0)GOTO 100
3005	IHELP=6
	CALL SSTAT(7)
	IF(.NOT.IPOS)CALL GPOS(IXC,IYC)
	IPOS=.TRUE.
	CALL CLRTOP
	IF(.NOT.IRESP('DO YOU NEED HELP? '))GOTO 7
3010	CALL ASSIGN(1,'ISC.DOC')
	CALL SSTAT("47)
	CALL HOME
	CALL KBWR(1,27)
	CALL KBWR(1,11)
	CALL CLRLIN
3009	FORMAT(Q,80A1)
3020	READ(1,3009,END=3050)N,(TBUF(I),I=1,N)
	CALL KBWR(N,TBUF)
	CALL CLRNXT
	GOTO 3020
3050	CALL CLOSE(1)
	CALL KBWR(1,27)
	CALL KBWR(1,24)
	CALL KBRDW(1,I)
	IPOS=.FALSE.
	GOTO 7
C
C READ OR WRITE
3500	CALL CLR2		!CLEAR NEXT TWO LINES
	CALL PRINTW('$FILENAME? < ')
	CALL PRINTW(0,LNAME)
	CALL PRINTW(0,' >')
	J=LNAME(1)
	N=NS
	READ (5,3009,END=7)NS,(LNAME(I),I=1,NS)
	LNAME(NS+1)=0
	IF(NS.GT.0)GOTO 3510			!GO IF WE GOT A FILE NAME
	IF(N.EQ.0)GOTO 3000		!WE NEVER HAD A NAME
	   LNAME(1)=J			!RESTORE LAST NAME
	   NS=N
3510	IF(LUN.EQ.3)GOTO 3550		!GO FOR WRITE
	DO 3520 I=1,NS			!SAVE READ NAME
	   RNAME(I)=LNAME(I)
3520	CONTINUE
	RNAME(NS+1)=0			!TERMINATOR
	NR=NS				!AND # OF CHARACTERS
3540	IF(IOPENR(RNAME,NR,2,'.PIC').LT.0)GOTO 3500
	IFILE=IFILE.OR.1
	IF((IFILE.AND.2).EQ.0)GOTO 3635
	CALL PRINTW(' I AM NOT UPDATING YOUR SCREEN AUTOMATICALY')
	CALL PRINTW(' BECAUSE YOU HAVE A FILE OPEN FOR OUTPUT')
	GOTO 85
C
3550	CONTINUE			!HERE FOR WRITE
	DO 3560 I=1,NS			!SAVE NAME
	   WNAME(I)=LNAME(I)
3560	CONTINUE
	WNAME(NS+1)=0
	NW=NS
	IF(IOPENW(WNAME,NW,3,'.PIC').LT.0)GOTO 3500
	IFILE=IFILE.OR.2
	GOTO 85
3600	IF(IWRITW(BUFI,7680,3).LT.0)GOTO 3670
	CALL PRINTW('$I HAVE WRITTEN TO ')
	CALL PRINTW(0,WNAME)
3635	IF(IREADW(BUFI,7680,2).LT.0)GOTO 3660
	IPOS=.FALSE.
	GOTO 2005
C READ ERROR OR END OF FILE
3660	IFILE=IFILE.AND.2
	CALL CLMES(2,RNAME,-1)
	GOTO 85
3670	IFILE=IFILE.AND.1
	CALL CLMES(3,WNAME,-1)
	GOTO 85
	END
C SUBROUTINE COMPARES ISTAT TO CURRENT DOMINATE FG AND BG COLORS
C AND CHANGES IT ACCORDINGLY
C IT THEN MAKES SURE TERMINAL SET TO CORRECT STATUS
C AND OUTPUTS CHARACTER IN PLOT OR NORMAL MODE
	SUBROUTINE SPRINT(NCHAR,ISTAT)
	BYTE ENTER(2),LEAVE(2),ISTAT(2),ISTATS(2),NCHAR(2)
	INTEGER PLOT
	INTEGER FMODE,BMODE
	COMMON IGO,FMODE,BMODE,IFOR,IBAC,IFORD,IBACD
	DATA ENTER/2,254/,LEAVE/255,0/,ISTATS/"377,"377/,PLOT/0/
	IF(IGO)GOTO 25		!SPECIAL CASE
	I=ISTAT(1).AND."7		!NEW FG COLOR
	IF(IFORD.LT.0)GOTO 3		!GO NO FG DELETE COLOR
	   IF(I.EQ.IFORD)GOTO 5		!ALWAYS OVERRIDDEN
3	   IF(.NOT.FMODE)GOTO 10
5	      ISTAT(1)=(ISTAT(1).AND."370).OR.IFOR	!CHANGE CURRENT COLOR
10	I=ISTAT(1).AND."70
	IF(IBACD.LT.0)GOTO 13		! GO NO BG DELETE COLOR
	   IF(I.EQ.IBACD)GOTO 15
13	   IF(.NOT.BMODE)GOTO 20
15	      ISTAT(1)=(ISTAT(1).AND."307).OR.IBAC
20	CONTINUE
	IF((ISTAT(1).AND."200).EQ.0)GOTO 23
	   IFA=ISTAT(1).AND.7
	   IB=(ISTAT(1).AND."70)/"10
	   IF(IFA.NE.IB)GOTO 23
	      ISTAT(1)=ISTAT(1).AND."77
	      NCHAR(1)="40
23	IF(ISTAT(1).EQ.ISTATS(1))GOTO 40
25	   IF(.NOT.PLOT)GOTO 30
	      CALL KBWRW(1,LEAVE)
	      PLOT=.FALSE.
30	   CALL SSTAT(ISTAT(1))
	   ISTATS(1)=ISTAT(1)
C
40	IF((ISTAT(1).AND."200).EQ.0) GOTO 50	!GO FOR NORMAL MODE
	IF(PLOT)GOTO 70
	   CALL KBWRW(2,ENTER)		!ENTER PLOT MODE
	   PLOT=.TRUE.
	   GOTO 70
C
50	IF(.NOT.PLOT)GOTO 70
	   CALL KBWRW(1,LEAVE)		!LEAVE PLOT MODE
	   PLOT=.FALSE.
70	IF(NCHAR(1).NE.0)CALL KBWR(1,NCHAR)
	IGO=.FALSE.
	RETURN
C
	END
C CLOSES FILE AND PRINTS A MESSAGE
C
	SUBROUTINE CLMES(LUN,NAME,ISAVE)
	IF(LUN.GT.0)GOTO 10
	CALL PRINTW(' NO FILES TO CLOSE')
	GOTO 30
10	IF(ISAVE)I=ICLOSE(LUN)
	IF(.NOT.ISAVE)I=IDELET(LUN)
	IF(ISAVE)CALL PRINTW('$I HAVE CLOSED ')
	IF(ISAVE)CALL PRINTW('+',NAME)
30	RETURN
	END
C SUBROUTINE TO CLEAR TOP 3 LINES OF SCREEN
C
	SUBROUTINE CLRTOP
	CALL SSTAT(7)
	CALL ANGLE(2)
	CALL HOME
	CALL CLRLIN
	CALL CLRNXT
	CALL CLRNXT
	CALL HOME
	RETURN
	END
C
	SUBROUTINE CLR2
	CALL GPOS(IX,IY)
	CALL CLRNXT
	CALL CLRNXT
	CALL APOSV(IX,IY)
	RETURN
	END
C
	FUNCTION IRESP(BUF)
	BYTE BUF(2),TBUF(10)
5	CALL PRINTW('$',BUF)
	READ (5,9,END=10)N,(TBUF(I),I=1,N)
9	FORMAT(Q,10A1)
	IF(N.EQ.0)TBUF(1)="116
	I=TBUF(1).AND."137
	IF(I.NE."116.AND.I.NE."131)GOTO 5
	IF(I.EQ."116)IRESP=.FALSE.
	IF(I.EQ."131)IRESP=.TRUE.
	RETURN
10	IRESP=1			!TRUE, BUT +VE FOR ^Z
	RETURN
	END
