    	SUBROUTINE MARGIN( ITOP,IBOT )
C
C  PROGRAMMER: R.S. ZHOU
C
C  	THIS ROUTINE SETS TOP AND BOTTOM MARGINS OF SCREEN
C	FOR DIALOG IN ANSI MODE.
C
    	BYTE TEXT(9), ORGN(6)
     	DATA TEXT/ 0, 27, 91, 0, 0, 59, 0, 0, 114 /	!0<ESC>[00;00r
    	DATA ORGN/ 0, 27, 91, 63, 54, 108 /		!0<ESC>[?6l

    	IT = ITOP
    	IB = IBOT
    	LIMIT = 24
    	IF( IT.LT.1 ) IT = 1
    	IF( IT.GT.LIMIT ) IT = LIMIT
    	IF( IB.LT.1 ) IB = LIMIT
    	IF( IB.GT.LIMIT ) IB = LIMIT
    	IF( IT.GT.(IB-2)) IT = IB-2
     	IT0 = IT/10
     	IT1 = IT-10*IT0
     	IB0 = IB/10
     	IB1 = IB-10*IB0
     	TEXT(4) = IT0+48
     	TEXT(5) = IT1+48
     	TEXT(7) = IB0+48
     	TEXT(8) = IB1+48
     	IF( ITOP.GE.0 .AND. IBOT.GE.0 ) WRITE(6,1) ORGN
     	WRITE(6,2) TEXT
1	FORMAT(6A1$)
2	FORMAT(9A1$)
    	RETURN
    	END    	
