MODULE T16;

IMPORT IO, Strings, ASCII, NumberIO, termios, FIO;


VAR
    cursorposStr : ARRAY [0..15] OF CHAR;
    resultStr    : ARRAY [0..15] OF CHAR;
    tmpString : ARRAY[0..10] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: Strings.String1;
    x,y       : CARDINAL;
    i : CARDINAL;
    theTermios : termios.TERMIOS;
    TCSAFLUSH   : INTEGER;

PROCEDURE Card2Str ( x : CARDINAL; VAR str : ARRAY OF CHAR);

BEGIN
IF x < 10 THEN
        NumberIO.CardToStr(x,1,str);
    ELSIF x < 100 THEN
        NumberIO.CardToStr(x,2,str);
    ELSE
        NumberIO.CardToStr(x,3,str);
    END;
END Card2Str;

BEGIN
    TCSAFLUSH := termios.tcsflush (); 
    theTermios := termios.InitTermios();
    IF termios.tcgetattr(FIO.StdIn, theTermios) = -1 THEN
        HALT
    END;
    IO.UnBufferedMode(0,TRUE);
    IO.UnBufferedMode(1,TRUE);

    x := 30;
    y := 30;

    cursorposStr := "";
    Strings.Concat(cursorposStr, ASCII.esc,cursorposStr);
    Strings.Concat(cursorposStr, "[",cursorposStr);
    tmpString := "";
    Strings.Concat(tmpString,cursorposStr, tmpString);
    tmpString1 := "";
    Card2Str(y,tmpString1);
    Strings.Concat(tmpString,tmpString1, tmpString);
    tmpString2[0] := ";";
    Strings.Concat(tmpString, tmpString2,tmpString);
    tmpString1 := "";
    Card2Str(x,tmpString1);
    Strings.Concat(tmpString,tmpString1, tmpString);
    tmpString2[0] := "H";
    Strings.Concat(tmpString, tmpString2,tmpString);
    FOR i := 0 TO Strings.Length(tmpString) DO
        IO.Write(tmpString[i])
    END;

    IO.BufferedMode(0,TRUE);
    IO.BufferedMode(1,TRUE);
    IF termios.tcsetattr(FIO.StdIn, TCSAFLUSH, theTermios) = -1 THEN
        HALT
    END;
END T16.