
C =======================================================================
C
C this routine moves the cursor around the screen under control of
C the cursor keys and the tab...etc.
C
C cursor starts at Row,Col on entry and is left at Row,Col on exit.
C
C TermKeys holds the keys to exit on ( special functions ), the
C entry in TermKeys is the nuber of termkeys.
C
C =======================================================================

	subroutine MoveCsr( Row, Col, TermKeys, Lastkey )

	integer*2 Row,Col,TermKeys(30),LastKey,IIchar,I
	logical*1 ChrRdy


100    	if( .not. chrrdy(0) ) call snooze(100)
	if ( .not. chrrdy(0) ) call PosReport( Row, Col )

	call CsrPos( Row, Col )

	call FPGetChar(IIchar)

	if (IIchar.eq.128) then
	   Row=Row-1
	   if (Row.lt.1) then
	      Row=21
	   endif
	elseif (IIchar.eq.129) then
	   Row=Row+1
	   if (Row.gt.21) then
	      Row=1
	   endif
	elseif (IIchar.eq.130) then
	   Col=Col-1
	   if (Col.lt.1) then
	      Col=80
	   endif
	elseif (IIchar.eq.131) then
	   Col=Col+1
	   if (Col.ge.80) then
	      Col=1
	   endif
	elseif (IIchar.eq.13) then
	   Col=1
	   Row=Row+1
	   if (Row.gt.21) then
	      Row=1
	   endif
	elseif ( IIchar .eq. 9 ) then
	   if (Mod(Col-1,8) .eq. 0) then
	      Col=Col+8
	   else
	      Col=Col-mod(Col-1,8)+8
	   endif
	   if (Col .gt. 79) Col=1

	elseif ( IIchar .eq. 132 ) then
	   if (Mod(Col-1,8) .eq. 0) then
	      Col=Col-8
	   else
	      Col=Col-mod(Col-1,8)
	   endif
	   if (Col .lt. 1) Col=79

	end if

	do 5 I=1,TermKeys(1)

	   if ( IIchar .eq. TermKeys(I+1) ) then
	      LastKey = IIchar
	      goto 500
	   endif

5	continue

	goto 100

500	continue

	end


C ===========================================================================
C
C	this package is for storage and retrieval with TmpMap( 21, 80, 3)
C
C ===========================================================================

	subroutine TmpMapInit

	integer*2 map( 21, 80 ,3 ), TmpMap( 21, 80, 3 )
	integer*2 Row1,Col1,Row2,Col2,NI,I,NJ,J,K

	common /blk1/map

	return


	entry CopyRegion ( Row1, Col1, Row2, Col2 )

	ni=1
	do 100 i = Row1, Row2

	   nj=1
	   do 200 j = Col1, Col2

	      do 300 k = 1, 3

	         TmpMap( ni , nj , k ) = map ( i , j , k )

300	      continue

	   nj=nj+1
200	   continue

	ni=ni+1
100	continue

	return


	entry RestoreRegion ( Row1, Col1, Row2, Col2 )


	ni=1
	do 400 i = Row1, Row2

	   nj=1
	   do 500 j = Col1, Col2

	      do 600 k = 1, 3

	         map( i , j , k ) = TmpMap ( ni , nj , k )

600	      continue

	   nj=nj+1
500	   continue

	ni=ni+1
400	continue

	return


	end



	logical*1 function LegalReg ( Row1, Col1, Row2, Col2 )

	integer*2 Row1, Col1, Row2, Col2


	if (Row1 .gt. Row2) then
	   LegalReg = .false.
	elseif (Col1 .gt. Col2) then
	   LegalReg = .false.
   	elseif (Row1 .lt. 1 .or. Row2 .gt. 21 ) then
 	   LegalReg = .false.
	elseif (Col1 .lt. 1 .or. Col2 .gt. 79 ) then
	   LegalReg = .false.
	else
	   LegalReg = .true.
	end if


	end



	subroutine RevRegion ( Row1,Col1,Row2,Col2 )

	integer*2 Row1,Col1,Row2,Col2,map(21,80,3),I,J

	common /blk1/map


	do 100 i = Row1, Row2

	   do 200 j = Col1, Col2

	      map(i, j, 2) = Ieor( map(i, j, 2), 1 )

200	   continue

100	continue

	end


	subroutine DspRegion( Row1, Col1, Row2, Col2 )

	integer*2 Row1,Col1,Row2,Col2,I

	do 100 i = Row1, Row2
	   call DspStr( i, Col1, Col2 )
100	continue


	end

