{ GOTOXY for VT52 Terminal }

{$U-}	  { ALWAYS include this compiler directive. }
UNIT GOTOXY;
INTERFACE
  PROCEDURE AGOTOXY(X,Y: INTEGER);
  
IMPLEMENTATION
USES {$U SCREENOPS.CODE} SCREENOPS (SC_TX_PORT, SC_PORT);
  PROCEDURE AGOTOXY;
  
  CONST	 TELL_LENGTH_MINUS_1 = 3;
	  OFFSET = 32;
  { You may have to change these, depending on your terminal. }
  
  VAR	  TELL: PACKED ARRAY [0..TELL_LENGTH_MINUS_1]
		 OF 0..255;
  BEGIN
    IF X>79 THEN X:=79
       ELSE IF X<0 THEN X:=0;
    IF Y>23 THEN Y:=23
       ELSE IF Y<0 THEN Y:=0;
    {  This range-checking is necessary.  The actual
	screenwidth and height may be different for you. }
	
    WITH SC_PORT DO
      BEGIN
	CUR_X:=X-COL;
	CUR_Y:=Y-ROW;
      END;
      
    { These first elements of TELL must contain
       the characters which tell your terminal to
       position the cursor at (X,Y):
       fill in the blanks...	     }
    TELL[0] := 27;    TELL[1] := ORD('Y');
    { The actual X and Y values are usually the 
       last things in the array;
       the order may be different on your terminal. }
    TELL[TELL_LENGTH_MINUS_1 - 1] := Y + OFFSET;
    TELL[TELL_LENGTH_MINUS_1] := X + OFFSET;
    
    UNITWRITE(1,TELL,TELL_LENGTH_MINUS_1 + 1)
  END {AGOTOXY};
END {UNIT GOTOXY}.
                                                                                                                                                                                                                                            