C COPYRIGHT (C) 1983 GLENN EVERHART
C PERMISSION IS GIVEN TO ANYONE TO USE, DISTRIBUTE, OR COPY THIS
C PROGRAM FREELY BUT NOT TO SELL IT COMMERICALLY.
C
C	VT100 VIDEO DISPLAY COMMAND PROGRAM. CALLING SEQUENCE IS
C	CALL UVT100(CMD,N1,N2THE MANDS IN
C	THE PARAMETER LIST BELOW, AND N1 AND N2 ARE OPTIONAL PARAMETERS
C	DEPENDING UPON CMD. SEE THE UVT100 USER'S MANUAL FOR MORE DETAILS.
C
C
C THIS VERSION MODIFIED FOR USE WITH PORTACALC.
C  ENTRIES NOT USED ARE DELETED.
C THIS VERSION IS MODIFIED FOR USE WITH TELEVIDEO 925 TERMINALS.
C
C THESE TERMINALS HAVE THE FOLLOWING CODES:
C CURSOR ADDRESSING:
C  <ESC>=ab
C	WHERE a= ROW # (BINARY) +31
C	      b= COL # (BINARY) +31
C NORMAL VIDEO:
C	<ESC>G0
C REVERSE VIDEO:
C	<ESC>G4
C UNDERLINE NORMAL:
C	<ESC>G8
C UNDERLINE REVERSE:
C	<ESC>G<
C CLEAR TO EOL
C	<ESC>T
C CLEAR TO EOP
C	<ESC>Y
C HOME
C	CTRL ^ (36 OCTAL OR 30 DECIMAL)
C
C	AUTHOR:	GLENN EVERHART
C
      SUBROUTINE UVT100 ( CMD, N1, N2 )
      IMPLICIT INTEGER ( A - Z )
	INCLUDE 'VKLUGPRM.FTN'
      DIMENSION PRL ( 6 )
      PARAMETER CUP = 1, CUU = 2, CUD = 3, CUF = 4, CUB = 5, DECDWL = 6
     $, DECDHL = 7, DECRC = 8, DECSC = 9, DECSWL = 10, ED = 11, EL = 12
     $, SGR = 13, NEL = 14, SCS = 15, SM = 16, RM = 17, ANSI = 18
C NOTE WE DECLARE THESE VARIABLES USED IN PORTACALC. THEY ARE ALL IN
C COMMONS, SO WE ADD NOTHING TO LENGTH OF THIS PROGRAM BY ADDING THEM.
	LOGICAL*1 FVLD
	DIMENSION FVLD(RRWP,RCLP)
	COMMON /FVLDC/FVLD
	INTEGER*2 PROW,PCOL,DROW,DCOL,DRWV,DCLV
	COMMON/DCTL/PROW,PCOL,DROW,DCOL,DRWV,DCLV
	INTEGER*2 TYPE(RRWP,RCLP),VLEN(9)
	REAL*8 XVBLS(RRWP,RCLP)
	LOGICAL*1 AVBLS(20,27),VBLS(8,RRWP,RCLP)
	EQUIVALENCE(XVBLS(1,1),VBLS(1,1,1))
	COMMON/V/TYPE,AVBLS,VBLS,VLEN
C CONTROLS TO SET VARIOUS VISUAL ATTRIBUTES
C NORMAL, BOLD
	INTEGER*2 N1SV,N2SV,NNFG,N222
	LOGICAL*1 CLSV(4)
	LOGICAL*1 NORMIT(3),BOLDIT(3),OUTBUF(8)
	DATA N222/0/
	DATA NORMIT/27,'G','0'/
C SET ATTRIBUTE 4 (UNDERLINE) RATHER THAN 1 (BOLD) FOR ALTERNATE LINES.
	DATA BOLDIT/27,'G','8'/
      OUTBUF ( 1 ) = 27
      DO 20000  I = 2, 8
      OUTBUF ( I ) = 0
20000 CONTINUE
20001 CONTINUE
      IF (.NOT.( CMD .EQ. CUP )) GOTO 20002
C CURSOR POSITION.
C SHIP OUT APPROPRIATE CHARACTERISTICS.
	N1CP=N1
	IF(N1.LT.3.OR.N1.GE.LCMDR) GOTO 1500
C HERE WE ARE IN DISPLAY ROW RANGE.
C
C SEE IF N2=1. IF SO FLAG AND SAVE COORDS.
C DO THIS TO TRY TO SHIP OUT COORDS.
	IF(N2.NE.1)GOTO 1655
	IF(NNFG.EQ.0)GOTO 1667
C GO BACK TO LAST LOC. AND DRAW NUMBER LABELS IN.
	WRITE(6,1105)CLSV
	NN=N1SV-2
	IF(NN.GT.0)WRITE(6,1106)NN
1106	FORMAT(I2,'=')
C THEN ON TO SET UP LOCATION.
1667	CONTINUE
	NNFG=N222
	N1SV=N1
	N2SV=N2
	GOTO 1656
1655	CONTINUE
	NNFG=0
1656	CONTINUE
C NO CHECK FOR AVO ON COLUMNS (NOT ENOUGH VARIATIONS AVAILABLE)
C THUS JUST DECIDE ON
C  1. UNDERLINING
	NBD=0
	NNR=N1/2
	NNR=NNR*2
	IF(NNR.NE.N1)NBD=1
C NOW HAVE ALL SET UP, NBD=1 IF UNDERLINING, NUL=1 IF UNDERLINE NEEDED.
C NEVER BOLD 1ST COLUMN ON SCREEN...LABELS ONLY THERE.
	IF(N2.LE.1)NBD=0
	IF(N2.EQ.1)GOTO 1500
	IF(NBD.EQ.0)WRITE(6,1105)NORMIT
	IF(NBD.EQ.1)WRITE(6,1105)BOLDIT
1500	CONTINUE
C CURSOR POSITIONS ARE <ESC>=ab AS ABOVE WHERE a,b ARE ROW OR COL # + 31
C CLAMP COL # TO NOT OVER 95 TOO.
      OUTBUF ( 2 ) = 1H=
      IF (.NOT.( N1 .GT. 0 . AND . N1 .LT. 25 )) GOTO 20004
	OUTBUF(3)=N1+31
20004 CONTINUE
      IF (.NOT.( N2 .GT. 0 . AND . N2 .LT. 95 )) GOTO 20006
	OUTBUF(4)=N2+31
20006 CONTINUE
      LEN = 4
	IF(N2.NE.1)GOTO 20003
	IF(N1.LE.2.OR.N1.GE.LCMDR)GOTO 20003
C SAVE LAST COORD BUFFER WHERE COL 1 WAS SELECTED.
	DO 1670 NN=1,4
1670	CLSV(NN)=OUTBUF(NN)
      GOTO 20003
20002 CONTINUE
      IF (.NOT.( CMD .EQ. ED )) GOTO 20036
C ERASE DISPLAY
	NNFG=0
	N222=0
	OUTBUF(1)=30
	OUTBUF(2)=27
	OUTBUF(3)=1HY
20039 CONTINUE
      LEN = 3
      GOTO 20037
20036 CONTINUE
      IF (.NOT.( CMD .EQ. EL )) GOTO 20042
C ERASE LINE
	N222=0
	NNFG=0
      IF (.NOT.( N1 .EQ. 0 )) GOTO 20044
C ERASE TO END OF LINE.
	OUTBUF(2)=1HT
	LEN=2
      GOTO 20045
20044 CONTINUE
      IF (.NOT.( N1 .EQ. 2 )) GOTO 20046
C ERASE WHOLE LINE
	OUTBUF(1)=13
	OUTBUF(2)=27
	OUTBUF(3)=1HT
	LEN=3
C DO C.R., THEN ERASE TO EOL
      GOTO 20047
20046 CONTINUE
	RETURN
20047 CONTINUE
20045 CONTINUE
      GOTO 20043
20042 CONTINUE
      IF (.NOT.( CMD .EQ. SGR )) GOTO 20048
C SET GRAPHICS RENDITION (7=REVERSE VIDEO, 0=NORMAL,4=UNDERSCORE,1=BOLD
C  5=BLINK) (PORTACALC CALLS WITH 0 OR 7 (VT100 W/O AVO))
	OUTBUF(2)=1HG
      IF (.NOT.( N1 .EQ. 7 )) GOTO 20050
C SET REVERSE VIDEO
      OUTBUF ( 3 ) = 1H4
	IF(N1CP.EQ.2)N222=1
      GOTO 20051
20050 CONTINUE
      OUTBUF ( 3 ) = 1H0
	IF(NNFG.EQ.0)GOTO 1672
	NNFG=0
	WRITE(6,1105)CLSV
	NN=N1SV-2
	IF(NN.GT.0)WRITE(6,1106)NN
1672	CONTINUE
20051 CONTINUE
      LEN = 3
      GOTO 20049
20048 CONTINUE
      IF (.NOT.( CMD .EQ. SCS )) GOTO 20054
C SCS. IGNORE THIS ... NEVER REALLY USED.
	RETURN
20054 CONTINUE
      IF (.NOT.( CMD .EQ. SM )) GOTO 20062
C SET MODE. IGNORE.
	RETURN
20062  IF (.NOT.( CMD .EQ. RM )) GOTO 20066
C RESET MODE. IGNORE.
	RETURN
20066 CONTINUE
      IF (.NOT.( CMD .EQ. ANSI )) GOTO 20070
C ANSI MODE CALL. IGNORE.
	RETURN
20070 CONTINUE
20049 CONTINUE
20043 CONTINUE
20037 CONTINUE
20003 CONTINUE
20073 CONTINUE
C USE A FORTRAN WRITE SO THIS WILL WORK ON VAX OR PDP11 (OR WHATEVER...)
C  UNIT 6 MUST BE THE TERMINAL...
	WRITE(6,1105)(OUTBUF(IV),IV=1,LEN)
1105	FORMAT(16A1)
5     FORMAT ( I1 )
10    FORMAT ( I2 )
105    FORMAT(I3)
      RETURN
      END
