	SUBROUTINE CLS(N)	! brisanje DO KONCA ekrana (& cursor home-N=0)

**-	SUBROUTINE CLS(N)	! brisanje DO KONCA ekrana (& cursor home-N=0)
**- clears screen to the end
**- input parameters:	n<i> - home flag
**-				n=0 => cursor home first

        INTEGER N
	CHARACTER*1 CSI

	CSI=CHAR(155)
        IF (N.EQ.0) WRITE (*,'($,A1,''H'')') CSI
	WRITE (*,'($,A1,''J'')') CSI
        CALL FLUSH_STD
	RETURN
	END


	SUBROUTINE SCROLL_MAR(NTOP,NBOT)

**-	SUBROUTINE SCROLL_MAR(NTOP,NBOT)
**- defines the scroll region
**- input parameters:	ntop<i> - top line
**-			nbot<i> - bottom line

	CHARACTER CSI,TOP*3,BOT*3   
        INTEGER NTOP,NBOT,NT,NB

	CSI=CHAR(155)    
        WRITE (TOP,'(SP,I3)') NTOP
        NT=INDEX(TOP,'+')+1
        WRITE (BOT,'(SP,I3)') NBOT
        NB=INDEX(BOT,'+')+1
	WRITE (*,100) CSI//TOP(NT:3)//';'//BOT(NB:3)//'r'
100	FORMAT($,A)
        CALL FLUSH_STD
	RETURN
	END


	SUBROUTINE SET_TERM(STR)        ! POSLJE POLJUBNO KODO

**-	SUBROUTINE SET_TERM(STR)        ! POSLJE POLJUBNO KODO
**- sends ESC + code
**- input parameters:	str<c> - code to be sent

	CHARACTER ESC,STR*(*)

	ESC=CHAR(27)
	WRITE (*,100) ESC,STR
100	FORMAT($,2A)
        CALL FLUSH_STD
	RETURN
	END

	SUBROUTINE CURSOR_ON
                    
**-	SUBROUTINE CURSOR_ON
**- switch cursor on

	CHARACTER*1 CSI

	CSI=CHAR(155)
	WRITE (*,100) CSI
100	FORMAT($,A1,'?25h')         
        CALL FLUSH_STD
	RETURN
	END

                               
	SUBROUTINE CURSOR_OFF

**-	SUBROUTINE CURSOR_OFF
**- switch cursor off

	CHARACTER*1 CSI

	CSI=CHAR(155)
	WRITE (*,100) CSI
100	FORMAT($,A1,'?25l')
        CALL FLUSH_STD
	RETURN
	END


	SUBROUTINE CURSOR_HOME
                     
**-	SUBROUTINE CURSOR_HOME
**- cursor to uper left corner

	CHARACTER*1 CSI

	CSI=CHAR(155)
	WRITE (*,100) CSI
100	FORMAT($,A1,'H')
        CALL FLUSH_STD
	RETURN
	END



	SUBROUTINE CURSOR_POS(I,J)	

**-	SUBROUTINE CURSOR_POS(I,J)	
**- puts cursor to i-row and j-coulumen
**- input parameters:	i<i> - row
**-			j<i> - coulumen

	CHARACTER*1 CSI,ICH*3,JCH*4                  
        INTEGER I,J,NI,NJ

	CSI=CHAR(155)        
                          
        WRITE (ICH,'(SP,I3)') I    
        NI=INDEX(ICH,'+')+1
        WRITE (JCH,'(SP,I4)') J    
        NJ=INDEX(JCH,'+')+1
        WRITE (*,'($,A)') CSI//ICH(NI:3)//';'//JCH(NJ:4)//'H'    
        CALL FLUSH_STD
	RETURN
	END


	SUBROUTINE PRINT_AT(I,J,TEKST)

**-	SUBROUTINE PRINT_AT(I,J,TEKST)
**- prints tekst to position i,j
**- input parameters:	i<i> - row
**-			j<I> - coulumen
**-			tekst<c> - text to be printed

	CHARACTER*(*) TEKST

	CALL CURSOR_POS(I,J)
	WRITE (*,100) TEKST
100	FORMAT($,A)
        CALL FLUSH_STD
	RETURN
	END


	SUBROUTINE SET_ATTRIBUTE(ATTR_NAME)
                                 
**-	SUBROUTINE SET_ATTRIBUTE(ATTR_NAME)
**- sets write style attr_name=attr1,attr2,...
**- input parameters:	attr_name<c> - style attributes

	CHARACTER*(*) ATTR_NAME
	CHARACTER CSI,ATTR*15   
        INTEGER NZ,NK,IN
        NK=0

**- 	'OFF'		all attributes off
**-	'BOLD'		display bold
**-	'UNDERL'	display underlined
**-	'BLINK'		display blinking
**-	'REVERSE'	display reverse character
**-	'NOT_BOLD'	display normal intensity
**-	'NOT_UNDERL'	display not underlined
**-	'NOT_BLINK'	display not blinking
**-	'NOT_REVERSE'	display normal character
                                                              
	CSI=CHAR(155)              

10      NZ=NK+1 
        IN=INDEX(ATTR_NAME(NZ:),',')
        NK=NK+IN
	IF (IN.EQ.0)THEN
          ATTR=ATTR_NAME(NZ:)
        ELSE
          ATTR=ATTR_NAME(NZ:NK-1)
        ENDIF
          IF(ATTR.EQ.'OFF') WRITE (*,100) CSI 
	  IF(ATTR.EQ.'BOLD') WRITE (*,101) CSI 
	  IF(ATTR.EQ.'UNDERL') WRITE (*,102) CSI 
	  IF(ATTR.EQ.'BLINK') WRITE (*,103) CSI 
          IF(ATTR.EQ.'REVERSE') WRITE (*,104) CSI 
	  IF(ATTR.EQ.'NOT_BOLD') WRITE (*,105) CSI 
	  IF(ATTR.EQ.'NOT_UNDERL') WRITE (*,106) CSI 
	  IF(ATTR.EQ.'NOT_BLINK') WRITE (*,107) CSI 
	  IF(ATTR.EQ.'NOT_REVERSE') WRITE (*,108) CSI 
        IF (IN.NE.0) GOTO 10
100	FORMAT($,A1,'0m')
101	FORMAT($,A1,'1m')
102	FORMAT($,A1,'4m')
103	FORMAT($,A1,'5m')
104	FORMAT($,A1,'7m')
105	FORMAT($,A1,'22m')
106	FORMAT($,A1,'24m')
107	FORMAT($,A1,'25m')
108	FORMAT($,A1,'27m')

        CALL FLUSH_STD

	RETURN
	END


