	SUBROUTINE DRAWR(X,Y)
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	COMMON /POPSC/I1,I2
	CALL CHXY(X,Y,IX,IY)
	IX=IX+I1
	IY=IY+I2
C	IY=360-IY
	CALL LINE (I1,I2,IX,IY,2)
	I1=IX
	I2=IY
	RETURN
	END
	SUBROUTINE DRAWA(X,Y)
	COMMON /POPSC/I1,I2
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	CALL CHXY(X,Y,IX,IY)
C	IY=360-IY
	CALL LINE (I1,I2,IX,IY,2)
	I1=IX
	I2=IY
	RETURN
	END
	SUBROUTINE DRWABS (IX,IY)
 	COMMON /VIDEO/ICM,IGR,IXM,IYM,ICHX,ICHY,IXB,IYB
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	COMMON /POPSC/I1,I2
	CALL CHIXY(IX,IY,IXX,IYY)
CIYY=360-IYY
	CALL LINE (I1,I2,IXX,IYY,2)
	I1=IXX
	I2=IYY
	RETURN
	END
	SUBROUTINE DRWREL(IX,IY)
 	COMMON /VIDEO/ICM,IGR,IXM,IYM,ICHX,ICHY,IXB,IYB
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	COMMON /POPSC/I1,I2
	CALL CHIXY(IX,IY,IXX,IYY)
	IXX=IXX+I1
	IYY=IYY+I2
C	IYY=360-IYY
	CALL LINE (I1,I2,IXX,IYY,2)
	I1=IXX
	I2=IYY
	RETURN
	END
	SUBROUTINE DRWREL1(IX,IY)
 	COMMON /VIDEO/ICM,IGR,IXM,IYM,ICHX,ICHY,IXB,IYB
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	COMMON /POPSC/I1,I2
	CALL CHIXY(IX,IY,IXX,IYY)
	IXX=IXX+I1
	IYY=IYY+I2
C	IYY=360-IYY
	CALL LINE (I1,I2,IXX,IYY,3)
	I1=IXX
	I2=IYY
	RETURN
	END
	SUBROUTINE CHXY(X,Y,IX,IY)
	COMMON /WENDU/XM1,XM2,YM1,YM2
	COMMON /TWENDU/MIX,MAX,MIY,MAY
 	COMMON /VIDEO/ICM,IGR,IXM,IYM,ICHX,ICHY,IXB,IYB
	XL=XM2-XM1
	YL=YM2-YM1
	X1=(X-XM1)*(MAX-MIX)/XL
	Y1=(Y-YM1)*(MAY-MIY)/YL
	IX=X1
	IY=Y1
	RETURN
	END
	SUBROUTINE CHIXY(I1,I2,IX,IY)
	COMMON /WENDU/XM1,XM2,YM1,YM2
	COMMON /TWENDU/MIX,MAX,MIY,MAY
 	COMMON /VIDEO/ICM,IGR,IXM,IYM,ICHX,ICHY,IXB,IYB
	IX=I1*(MAX-MIX)/1024
	IY=I2*(MAY-MIY)/960
	RETURN
	END
	SUBROUTINE VWINDO(X1,X2,Y1,Y2)
	XMAX=X1+X2
	YMAX=Y1+Y2
	CALL DWINDO(X1,XMAX,Y1,YMAX)
	RETURN
	END
	SUBROUTINE SWINDO(MINX,LENX,MINY,LENY)
	MAXX=MINX+LENX
	MAXY=MINY+LENY
	CALL TWINDO(MINX,MAXX,MINY,MAXY)
	RETURN
	END
	SUBROUTINE TWINDO(MINX,MAXX,MINY,MAXY)
	COMMON /TWENDU/MIX,MAX,MIY,MAY
 	COMMON /VIDEO/ICM,IGR,IXM,IYM,ICHX,ICHY,IXB,IYB
	MIX=MINX*IXM/1024
	MIY=MINY*IYM/1024
	MAX=MAXX*IXM/970
	MAY=MAXY*IYM/970
	IF (MIX.LT.0.OR.MIX.GE.IXM) MIX=0
	IF (MIY.LT.0.OR.MIX.GE.IYM) MIY=0
	IF (MAX.LE.0.OR.MAX.GT.IXM) MAX=IXM
	IF (MAY.LE.0.OR.MAY.GT.IYM) MAY=IYM
	CALL WGRAP(MIX,MIY,MAX,MAY)
	RETURN
	END
	SUBROUTINE DWINDO(XMIN,XMAX,YMIN,YMAX)
	COMMON /WENDU/XM1,XM2,YM1,YM2
	XM1=XMIN
	XM2=XMAX
	YM1=YMIN
	YM2=YMAX
	RETURN
	END
	SUBROUTINE MOVEA(X,Y)
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	COMMON /POPSC/IX,IY
	CALL CHXY(X,Y,IX,IY)
CIY=360-IY
	CALL POINT(IX,IY,7)
	RETURN
	END
	SUBROUTINE MOVABS(IX,IY)
	COMMON /POPSC/I1,I2
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	CALL CHIXY(IX,IY,I1,I2)
CI2=360-I2
	CALL POINT (I1,I2,7)
	RETURN
	END
	SUBROUTINE MOVER(X,Y)
	COMMON /POPSC/I1,I2
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	CALL CHXY(X,Y,IX,IY)
	IX=IX+I1
	IY=IY+I2
C	IY=360-IY
	CALL POINT (IX,IY,7)
	I1=IX
	I2=IY
	RETURN
	END
	SUBROUTINE MOVREL(IX,IY)
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	COMMON /POPSC/I1,I2
	CALL CHIXY (IX,IY,I3,I4)
	I3=I3+I1
	I4=I4+I2
CI4=360-I4
	CALL POINT (I3,I4,7)
	I1=I3
	I2=I4
	RETURN
	END
	SUBROUTINE INITT(I)
 	COMMON /VIDEO/ICM,IGR,IXM,IYM,ICHX,ICHY,IXB,IYB
	COMMON/LAB/ILAB
	INTEGER*2 C,XXA,YYA,XXB,YYB,XM,YM,CM,CHX,CHY,XB,YB,GR
	INTEGER*2 XW1,YW1,XW2,YW2,XCW1,YCW1,XCW2,YCW2,X00,Y00
	INTEGER*2 X0,Y0,R,TH1,TH2,CHLIN,CDX,CDY,CCX,CCY,XCC,YCC,CCC,FCC
	ICF=0
	CALL VIDEO(CM,GR,XM,YM,CHX,CHY,XB,YB)
	ICM=CM
	IGR=GR
	IXM=XM
	IYM=YM
	IF(IXM.EQ.320.AND.IYM.EQ.200) GOTO 120
        ILAB=0
	GOTO 130
120	ILAB=1
130	ICHX=CHX
	ICHY=CHY
	IXB=XB
	IYB=YB
	IF(CM.EQ.0) GOTO 1000
   	CHLIN=4+ICF*2
	YM=YM/8
	YM=YM*8
	C=1
	CALL SCREEN(C)
	CALL CLSG
	C=CM
	IF(GR.EQ.CM) C=C-1
	CCC=CM+256
	XW1=0
	YW1=0
	XW2=XM
	YW2=YM-8*CHLIN-8
	CALL LLIN(XW1,YW2,XW2,YW2,C)
	XCW1=0
	YCW1=CHY-CHLIN
	XCW2=CHX
	YCW2=CHY
	CALL WTEXT(XCW1,YCW1,XCW2,YCW2)
	RETURN
1000	WRITE (*,'('' TERMINAL INITIALIZATION ERROR !! '')')
	STOP
	END
	SUBROUTINE NEWPAG
	CALL CLSG
	CALL CLST
	RETURN
	END
	SUBROUTINE DASHA (X,Y)
	COMMON /POPSC/I1,I2
	CALL CHXY (X,Y,IX,IY)
	CALL LINE (I1,I2,IX,IY,3)
	I1=IX
	I2=IY
	RETURN
	END
	SUBROUTINE ERASE
	CALL CLSG
	CALL CLST
	RETURN
	END
	SUBROUTINE POINTA (X,Y)
	COMMON /POPSC/I1,I2
	CALL CHXY(X,Y,I1,I2)
	CALL POINT (IX,IY)
	RETURN
	END
	SUBROUTINE ANSTR (NC,CHAR,NW)
	DIMENSION CHAR(1)
	COMMON /POPSC/I1,I2
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	IX=I1+MIX
	IY=I2+MIY
	ILX=IX*0.125
C    ILX=IX*0.125
C    ILY=36-IY*0.125
	ILY=36-IY*0.125
	CALL LOCATE (ILX,ILY)
	CALL MODE (1)
	WRITE (*,'(1X,15A4)')(CHAR(JJ),JJ=1,NW)
	CALL MODE (0)
CI1=I1+NC*8
	I1=I1+NC*6
	CALL POS(ILX,ILY)
	ILY=ILY+1
	CALL INTO (ILX,ILY)
	RETURN
	END
	SUBROUTINE TOUTPT(ICHAR)
	COMMON /POPSC/I1,I2
	CALL ANSTR (1,ICHAR,1)
	I1=I1+8
	RETURN
	END
	SUBROUTINE VCURSR (ICHAR,X,Y)
	COMMON /POPSC/I1,I2
	COMMON /WENDU/XM1,XM2,YM1,YM2
	COMMON /TWENDU/MIX,MAX,MIY,MAY
	CALL DRAWC
	READ(*,1) CHAR
1	FORMAT(A1)
	CALL RCORD(XI,YI,IF)
	IX=XI
	IY=YI
	LX=IX-MIX
	LY=IY-MIY
	X=XM1+LX*(XM2-XM1)/(MAX-MIX)
	Y=YM1+LY*(YM2-YM1)/(MAY-MIY)
	WRITE (*,*)' IX,IY,MIX,MIY,MAX,MAY',XI,YI,MIX,MIY,MAX,MAY
	RETURN
	END
	SUBROUTINE FINIT (I)
	CALL QUIT
	RETURN
	END
