IMPLEMENTATION MODULE VT100;

IMPORT ASCII;
FROM STextIO IMPORT WriteString, WriteChar, WriteLn, ReadString;
FROM NumberIO IMPORT WriteCard, CardToStr,StrToCard;
FROM Strings IMPORT Concat, Length, String1, Assign, Delete;
FROM NumberIO IMPORT WriteHex;
FROM Delay IMPORT Delay;
IMPORT SplitV1;
IMPORT termios;

(*
Name                  DASCII.escription                            ASCII.esc Code

setnl LMN             Set new line mode                      ^[[20h
setappl DECCKM        Set cursor key to application          ^[[?1h
setansi DECANM        Set ANSI (versus VT52)                 none
setcol DECCOLM        Set number of columns to 132           ^[[?3h
setsmooth DECSCLM     Set smooth scrolling                   ^[[?4h
setrevscrn DECSCNM    Set reverse video on screen            ^[[?5h
setorgrel DECOM       Set origin to relative                 ^[[?6h
setwrap DECAWM        Set auto-wrap mode                     ^[[?7h
setrep DECARM         Set auto-repeat mode                   ^[[?8h
setinter DECINLM      Set interlacing mode                   ^[[?9h

setlf LMN             Set line feed mode                     ^[[20l
setcursor DECCKM      Set cursor key to cursor               ^[[?1l
setvt52 DECANM        Set VT52 (versus ANSI)                 ^[[?2l
resetcol DECCOLM      Set number of columns to 80            ^[[?3l
setjump DECSCLM       Set jump scrolling                     ^[[?4l
setnormscrn DECSCNM   Set normal video on screen             ^[[?5l
setorgabs DECOM       Set origin to absolute                 ^[[?6l
resetwrap DECAWM      Reset auto-wrap mode                   ^[[?7l
resetrep DECARM       Reset auto-repeat mode                 ^[[?8l
resetinter DECINLM    Reset interlacing mode                 ^[[?9l

altkeypad DECKPAM     Set alternate keypad mode              ^[=
numkeypad DECKPNM     Set numeric keypad mode                ^[>

setukg0               Set United Kingdom G0 character set    ^[(A
setukg1               Set United Kingdom G1 character set    ^[)A
setusg0               Set United States G0 character set     ^[(B
setusg1               Set United States G1 character set     ^[)B
setspecg0             Set G0 special chars. & line set       ^[(0
setspecg1             Set G1 special chars. & line set       ^[)0
setaltg0              Set G0 alternate character ROM         ^[(1
setaltg1              Set G1 alternate character ROM         ^[)1
setaltspecg0          Set G0 alt char ROM and spec. graphics ^[(2
setaltspecg1          Set G1 alt char ROM and spec. graphics ^[)2

setss2 SS2            Set single shift 2                     ^[N
setss3 SS3            Set single shift 3                     ^[O

modesoff SGR0         Turn off character attributes          ^[[m
modesoff SGR0         Turn off character attributes          ^[[0m
bold SGR1             Turn bold mode on                      ^[[1m
lowint SGR2           Turn low intensity mode on             ^[[2m
underline SGR4        Turn underline mode on                 ^[[4m
blink SGR5            Turn blinking mode on                  ^[[5m
reverse SGR7          Turn reverse video on                  ^[[7m
invisible SGR8        Turn invisible text mode on            ^[[8m

setwin DECSTBM        Set top and bottom line#s of a window  ^[[<v>;<v>r

cursorup(n) CUU       Move cursor up n lines                 ^[[<n>A
cursordn(n) CUD       Move cursor down n lines               ^[[<n>B
cursorrt(n) CUF       Move cursor right n lines              ^[[<n>C
cursorlf(n) CUB       Move cursor left n lines               ^[[<n>D
cursorhome            Move cursor to upper left corner       ^[[H
cursorhome            Move cursor to upper left corner       ^[[;H
cursorpos(v,h) CUP    Move cursor to screen location v,h     ^[[<v>;<h>H
hvhome                Move cursor to upper left corner       ^[[f
hvhome                Move cursor to upper left corner       ^[[;f
hvpos(v,h) CUP        Move cursor to screen location v,h     ^[[<v>;<h>f
index IND             Move/scroll window up one line         ^[D
revindex RI           Move/scroll window down one line       ^[M
nextline NEL          Move to next line                      ^[E
savecursor DECSC      Save cursor position and attributes    ^[7
restorecursor DECSC   Restore cursor position and attributes ^[8

tabset HTS            Set a tab at the current column        ^[H
tabclr TBC            Clear a tab at the current column      ^[[g
tabclr TBC            Clear a tab at the current column      ^[[0g
tabclrall TBC         Clear all tabs                         ^[[3g

dhtop DECDHL          Double-height letters, top half        ^[#3
dhbot DECDHL          Double-height letters, bottom half     ^[#4
swsh DECSWL           Single width, single height letters    ^[#5
dwsh DECDWL           Double width, single height letters    ^[#6

cleareol EL0          Clear line from cursor right           ^[[K
cleareol EL0          Clear line from cursor right           ^[[0K
clearbol EL1          Clear line from cursor left            ^[[1K
clearline EL2         Clear entire line                      ^[[2K

cleareos ED0          Clear screen from cursor down          ^[[J
cleareos ED0          Clear screen from cursor down          ^[[0J
clearbos ED1          Clear screen from cursor up            ^[[1J
clearscreen ED2       Clear entire screen                    ^[[2J

devstat DSR           Device status report                   ^[5n
termok DSR               Response: terminal is OK            ^[0n
termnok DSR              Response: terminal is not OK        ^[3n

getcursor DSR         Get cursor position                    ^[6n
cursorpos CPR            Response: cursor is at v,h          ^[<v>;<h>R

ident DA              Identify what terminal type            ^[[c
ident DA              Identify what terminal type (another)  ^[[0c
gettype DA               Response: terminal type code n      ^[[?1;<n>0c

reset RIS             Reset terminal to initial state        ^[c

align DECALN          Screen alignment display               ^[#8
testpu DECTST         Confidence power up test               ^[[2;1y
testlb DECTST         Confidence loopback test               ^[[2;2y
testpurep DECTST      Repeat power up test                   ^[[2;9y
testlbrep DECTST      Repeat loopback test                   ^[[2;10y

ledsoff DECLL0        Turn off all four leds                 ^[[0q
led1 DECLL1           Turn on LED #1                         ^[[1q
led2 DECLL2           Turn on LED #2                         ^[[2q
led3 DECLL3           Turn on LED #3                         ^[[3q
led4 DECLL4           Turn on LED #4                         ^[[4q

#
#  All codes below are for use in VT52 compatibility mode.
#

setansi               Enter/exit ANSI mode (VT52)            ^[<

altkeypad             Enter alternate keypad mode            ^[=
numkeypad             Exit alternate keypad mode             ^[>

setgr                 Use special graphics character set     ^[F
resetgr               Use normal US/UK character set         ^[G

cursorup              Move cursor up one line                ^[A
cursordn              Move cursor down one line              ^[B
cursorrt              Move cursor right one char             ^[C
cursorlf              Move cursor left one char              ^[D
cursorhome            Move cursor to upper left corner       ^[H
cursorpos(v,h)        Move cursor to v,h location            ^[<v><h>
revindex              Generate a reverse line-feed           ^[I

cleareol              Erase to end of current line           ^[K
cleareos              Erase to end of screen                 ^[J

ident                 Identify what the terminal is          ^[Z
identresp             Correct response to ident              ^[/Z

*)

(*                    VT52 compatibility mode                 *)

TYPE 
    Array2  = ARRAY[0..1] OF CHAR;  
    Array3  = ARRAY[0..2] OF CHAR;
    Array4  = ARRAY[0..3] OF CHAR;
    Array5  = ARRAY[0..4] OF CHAR;
    Array6  = ARRAY[0..5] OF CHAR;
    Array8  = ARRAY[0..7] OF CHAR;
    Array10 = ARRAY[0..9] OF CHAR;


VAR 
    theterminal : termios.TERMIOS;
    savedFd     : INTEGER;

VAR                 (* cursor *)
    cursorupStr     : Array3;
    cursordnStr     : Array3;             
    cursorrtStr     : Array3;            
    cursorlfStr     : Array3;            
    cursorhomeStr   : Array3;       
    cursorposStr    : ARRAY [0..10] OF CHAR;
    revindexStr     : Array3;        

    cleareolStr     : Array3;         
    cleareosStr     : Array3; 
    
VAR                 (* ident *)
    identStr        : Array3; 
    identrespStr    : ARRAY [0..3] OF CHAR;

VAR                 (* graphic *)
    setgrStr        : Array3;
    resetgrStr      : Array3; 

VAR                 (* VT52 mode *)
    setansiStr      : Array3; 

VAR                 (* keypad switch *)
    altkeypadStr    : Array3;
    numkeypadStr    :   Array3; 

(*                                    VT100                                      *)
VAR
    setnlStr        : Array3;
    setapplStr      : Array3;
    setansi1Str     : Array3;
    setcolStr       : Array3;
    setsmoothStr    : Array3;
    setrevscrnStr   : Array3;
    setorgrelStr    : Array3;
    setwrapStr      : Array3;
    setrepStr       : Array3;
    setinterStr     : Array3;

    setlfStr        : Array3;
    setcursorStr    : Array3;
    setvt52Str      : Array3;
    resetcolStr     : Array3;
    setjumpStr      : Array3;
    setnormscrnStr  : Array3;
    setorgabsStr    : Array3;
    resetwrapStr    : Array3;
    resetrepStr     : Array3;
    resetinterStr   : Array3;

    altkeypad1Str   : Array3;
    numkeypad1Str   : Array3;

    setukg0Str      : Array3;
    setukg1Str      : Array3;
    setusg0Str      : Array3;
    setusg1Str      : Array3;
    setspecg0Str    : Array3;
    setspecg1Str    : Array3;
    setaltg0Str     : Array3;
    setaltg1Str     : Array3;
    setaltspecg0Str : Array3;
    setaltspecg1Str : Array3;

    setss2Str       : Array3;
    setss3Str       : Array3;

    modesoff0Str    : Array3;
    modesoff1Str    : Array4;
    boldStr         : Array4;
    lowintStr       : Array4;
    underlineStr    : Array4;
    blinkStr        : Array4;
    reverseStr      : Array4;
    invisibleStr    : Array4;
    italicStr       : Array4;
    strikethroughStr: Array4; 

    resetboldStr         : Array5;
    resetlowintStr       : Array5;
    resetunderlineStr    : Array5;
    resetblinkStr        : Array5;
    resetreverseStr      : Array5;
    resetinvisibleStr    : Array5;
    resetitalicStr       : Array5;
    resetstrikethroughStr: Array5;

    setwinStr       : Array3;

    cursorup1Str    : Array3;
    cursordn1Str    : Array3;
    cursorrt1Str    : Array3;
    cursorlf1Str    : Array3;
    cursorhome0Str  : Array3;
    cursorhome1Str  : Array4;
    cursorpos1Str   : Array3;
    hvhome0Str      : Array3;
    hvhome1Str      : Array3;
    hvposStr        : Array3;
    indexStr        : Array3;
    revindex1Str    : Array3;
    nextlineStr     : Array3;
    savecursStr     : Array3;
    restorecursorStr: Array3;
    requestCursorPositionStr: Array6;
    tabsetStr       : Array3;
    tabclr0Str      : Array3;
    tabclr1Str      : Array3;
    tabclrallStr    : Array3;

    dhtopStr        : Array3;
    dhbotStr        : Array3;
    swshStr         : Array3;
    dwshStr         : Array3;

    cleareol0Str    : Array3;
    cleareol1Str    : Array3;
    clearbol2Str    : Array3;
    clearlineStr    : Array3;

    cleareos0Str    : Array3;
    cleareos1Str    : Array3;
    clearbos2Str    : Array3;
    clearscreenStr  : Array4;

    devstatStr      : Array3;
    termokStr       : Array3;
    termnokStr      : Array3;

    getcursorStr    : Array3;
    cursorpos2Str   : Array3;
    cursorbnlStr    : Array3;
    cursorblplStr   : Array3;
    cursottocolStr  : Array3;
    ident1Str       : Array3;
    ident2Str       : Array3;
    gettypeStr      : Array3;

    resetStr        : Array3;

    alignStr        : Array3;
    testpuStr       : Array3;
    testlbStr       : Array3;
    testpurepStr    : Array3;
    testlbrepStr    : Array3;
    (* screen modes *)
    resetScreenModeStr : Array6;
    ledsoffStr      : Array3;
    led1Str         : Array3;
    led2Str         : Array3;
    led3Str         : Array3;
    led4Str         : Array3;
    M40x25BWStr      : Array4;
    M40x25CStr       : Array5;
    M80x25BWStr      : Array5;
    M80x25CStr       : Array5;
    M320x200C4Str     : Array6;
    M320x200BWStr    : Array6;
    M640x200BWStr    : Array6;
    M320x200C256Str     : Array6;
    M640x200CStr     : Array6;
    M640x350BWStr    : Array6;
    M640x350CStr     : Array6;
    M640x480BWStr    : Array6;
    M640x480CStr     : Array6;
    M320x200CStr     : Array6;
    lineWrappingStr  : Array6;
    resetLineWrappingStr : Array6;

    (* some proprietary extensions *)
    makeCursorInvisibleStr      : Array6;
    makeCursorVisibleStr        : Array6;
    restoreScreenStr            : Array6;
    saveScreenStr               : Array6;
    enableAlternativeBufferStr  : Array10;
    disableAlternativeBufferStr : Array10;

    doubleUnderlineStr           : Array6;
    resetDoubleUnderlineStr     : Array6;
    
    (* colors *)
    setAttributStr  : Array2;

VAR
    i : CARDINAL;

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

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

PROCEDURE affiche ( m : ARRAY OF CHAR; s : ARRAY OF CHAR);

BEGIN
    WriteString(m);WriteLn;
    FOR i := 0 TO Length(s) DO
        WriteHex(ORD(s[i]),2);
        WriteChar(" ")
    END; 
    WriteLn;
END affiche;

(*
PROCEDURE setnl;
(* LMN             Set new line mode                      ^[[20h *)
BEGIN
END ;

PROCEDURE setappl;
(* DECCKM        Set cursor key to application          ^[[?1h *)
BEGIN
END ;

PROCEDURE setansi;
(* DECANM        Set ANSI (versus VT52)                 none *)
BEGIN
END ;

PROCEDURE setcol;
(* DECCOLM        Set number of columns to 132           ^[[?3h *)
BEGIN
END ;

PROCEDURE setsmooth;
(* DECSCLM     Set smooth scrolling                   ^[[?4h *)
BEGIN
END ;

PROCEDURE setrevscrn;
(* DECSCNM    Set reverse video on screen            ^[[?5h *)
BEGIN
END ;

PROCEDURE setorgrel;
(* DECOM       Set origin to relative                 ^[[?6h *)
BEGIN
END ;

PROCEDURE setwrap;
(* DECAWM        Set auto-wrap mode                     ^[[?7h *)
BEGIN
END ;

PROCEDURE setrep;
(* DECARM         Set auto-repeat mode                   ^[[?8h *)
BEGIN
END ;

PROCEDURE setinter;
(* DECINLM      Set interlacing mode                   ^[[?9h *)
BEGIN
END ;

PROCEDURE setlf;
(* LMN             Set line feed mode                     ^[[20l *)
BEGIN
END ;

PROCEDURE setcursor;
(* DECCKM      Set cursor key to cursor               ^[[?1l *)
BEGIN
END ;

PROCEDURE setvt52;
(* DECANM        Set VT52 (versus ANSI)                 ^[[?2l *)
BEGIN
END ;

PROCEDURE resetcol;
(* DECCOLM      Set number of columns to 80            ^[[?3l *)
BEGIN
END ;

PROCEDURE setjump;
(* DECSCLM       Set jump scrolling                     ^[[?4l *)
BEGIN
END ;

PROCEDURE setnormscrn;
(* DECSCNM   Set normal video on screen             ^[[?5l *)
BEGIN
END ;

PROCEDURE setorgabs;
(* DECOM       Set origin to absolute                 ^[[?6l *)
BEGIN
END ;

PROCEDURE resetwrap;
(* DECAWM      Reset auto-wrap mode                   ^[[?7l *)
BEGIN
END ;

PROCEDURE resetrep;
(* DECARM       Reset auto-repeat mode                 ^[[?8l *)
BEGIN
END ;

PROCEDURE resetinter;
(* DECINLM    Reset interlacing mode                 ^[[?9l *)
BEGIN
END ;

PROCEDURE altkeypad;
(* DECKPAM     Set alternate keypad mode              ^[= *)
BEGIN
END ;

PROCEDURE numkeypad;
(* DECKPNM     Set numeric keypad mode                ^[> *)
BEGIN
END ;

PROCEDURE setukg0;
    (* Set United Kingdom G0 character set    ^[(A *)
BEGIN
END ;

PROCEDURE setukg1;
    (* Set United Kingdom G1 character set    ^[)A *)
BEGIN
END ;

PROCEDURE setusg0;
(* Set United States G0 character set     ^[(B *)
BEGIN
END ;

PROCEDURE setusg1;
(* Set United States G1 character set     ^[)B *)
BEGIN
END ;

PROCEDURE setspecg0;
(* Set G0 special chars. & line set       ^[(0 *)
BEGIN
END ;

PROCEDURE setspecg1;
(* Set G1 special chars. & line set       ^[)0 *)
BEGIN
END ;

PROCEDURE setaltg0;
(* Set G0 alternate character ROM         ^[(1 *)
BEGIN
END ;

PROCEDURE setaltg1;
(* Set G1 alternate character ROM         ^[)1 *)
BEGIN
END ;

PROCEDURE setaltspecg0;
(* Set G0 alt char ROM and spec. graphics ^[(2 *)
BEGIN
END ;

PROCEDURE setaltspecg1;
(* Set G1 alt char ROM and spec. graphics ^[)2 *)
BEGIN
END ;

PROCEDURE setss2 ;
(* SS2 Set single shift 2                 ^[N *)
BEGIN
END ;

PROCEDURE setss3;
(* SS3 Set single shift 3                  ^[O *)
BEGIN
END ;
*)
PROCEDURE modesoff;
(* SGR0 Turn off character attributes          ^[[m *)
BEGIN
    WriteString(modesoff0Str)
END modesoff;

PROCEDURE modesoff1;
(* SGR0 Turn off character attributes          ^[[0m *)
BEGIN
    WriteString(modesoff1Str)
END modesoff1;

PROCEDURE bold;
(* SGR1 Turn bold mode on                      ^[[1m *)
BEGIN
    WriteString(boldStr);
END bold;

PROCEDURE lowint;
(* SGR2 Turn low intensity mode on             ^[[2m *)
BEGIN
    WriteString(lowintStr)
END lowint;

PROCEDURE italic;
(* set italic mode                           ESC[3m *)
BEGIN
    WriteString(italicStr)
END italic;

PROCEDURE underline;
(* SGR4 Turn underline mode on                 ^[[4m *)
BEGIN
    WriteString(underlineStr)
END underline;

PROCEDURE blink;
(* SGR5 Turn blinking mode on                  ^[[5m *)
BEGIN
    WriteString(blinkStr)
END blink;

PROCEDURE reverse;
(* SGR7 Turn reverse video on                  ^[[7m *)
BEGIN
    WriteString(reverseStr)
END reverse;

PROCEDURE invisible;
(* SGR8 Turn invisible text mode on            ^[[8m *)
BEGIN
    WriteString(invisibleStr)
END invisible;

PROCEDURE strikethrough;
BEGIN
    WriteString(strikethroughStr)
END strikethrough;

PROCEDURE doubleUnderline;
(* ESC[21m *)
BEGIN
    WriteString(doubleUnderlineStr)
END doubleUnderline;

PROCEDURE resetbold;
(* SGR1 Turn bold mode on                      ^[[21m *)

BEGIN
    WriteString(resetboldStr)
END resetbold;

PROCEDURE resetlowint;
(* SGR2 Turn low intensity mode on             ^[[22m *)
BEGIN
    WriteString(resetlowintStr)
END resetlowint;


PROCEDURE resetitalic;
(* set italic mode                              ESC[23m *)
BEGIN
    WriteString(resetitalicStr)
END resetitalic;


PROCEDURE resetunderline;
(* SGR4 Turn underline mode on                 ^[[24m *)
BEGIN
    WriteString(resetunderlineStr)
END resetunderline;


PROCEDURE resetblink;
(* SGR5 Turn blinking mode on                  ^[[25m *)
BEGIN
    WriteString(resetblinkStr)
END resetblink;


PROCEDURE resetreverse;
(* SGR7 Turn reverse video on                  ^[[27m *)
BEGIN
    WriteString(resetreverseStr)
END resetreverse;


PROCEDURE resetinvisible;
(* SGR8 Turn invisible text mode on            ^[[28m *)
BEGIN
    WriteString(resetinvisibleStr)
END resetinvisible;


PROCEDURE resetstrikethrough;
(* ESC[9m 	ESC[29m 	set strikethrough mode. *)
BEGIN
    WriteString(resetstrikethroughStr)
END resetstrikethrough;

PROCEDURE resetDoubleUnderline;
(* ESC[24m. *)
BEGIN
    WriteString(resetDoubleUnderlineStr)
END resetDoubleUnderline;


(*
PROCEDURE setwin;
(* DECSTBM Set top and bottom line#s of a window  ^[[<v>;<v>r *)
BEGIN
END ;
*)
PROCEDURE cursorup(n : CARDINAL);
(* CUU Move cursor up n lines                 ^[[<n>A *)

VAR
    tmpString : ARRAY[0..5] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: String1;

BEGIN
    tmpString := "";
    Card2Str(n,tmpString1);
    tmpString2[0] := "A";

    Concat(tmpString,cursorup1Str, tmpString);
    Concat(tmpString, tmpString1,tmpString);
    Concat(tmpString, tmpString2,tmpString);
    WriteString(tmpString)
END cursorup;

PROCEDURE cursordn(n : CARDINAL);
(* CUD Move cursor down n lines               ^[[<n>B *)

VAR
    tmpString : ARRAY[0..5] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: String1;

BEGIN
    tmpString := "";
    Card2Str(n,tmpString1);
    tmpString2[0] := "B";

    Concat(tmpString,cursordn1Str, tmpString);
    Concat(tmpString, tmpString1,tmpString);
    Concat(tmpString, tmpString2,tmpString);
    WriteString(tmpString) 
END cursordn;

PROCEDURE cursorrt(n : CARDINAL);
(* CUF Move cursor right n lines              ^[[<n>C *)

VAR
    tmpString : ARRAY[0..5] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: String1;

BEGIN
    tmpString := "";
    Card2Str(n,tmpString1);
    tmpString2[0] := "C";

    Concat(tmpString,cursorrt1Str, tmpString);
    Concat(tmpString, tmpString1,tmpString);
    Concat(tmpString, tmpString2,tmpString);
    WriteString(tmpString)
END cursorrt;

PROCEDURE cursor1lf(n : CARDINAL);
(* CUB Move cursor left n lines               ^[[<n>D *)

VAR
    tmpString : ARRAY[0..5] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: String1;

BEGIN
    tmpString := "";
    Card2Str(n,tmpString1);
    tmpString2[0] := "D";

    Concat(tmpString,cursorlf1Str, tmpString);
    Concat(tmpString, tmpString1,tmpString);
    Concat(tmpString, tmpString2,tmpString);
    WriteString(tmpString)
END cursor1lf;

PROCEDURE cursorbnl(n : CARDINAL);
(* ESC[#E 	moves cursor to beginning of next line, # lines down *)

VAR
    tmpString : ARRAY[0..5] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: String1;
    
BEGIN
    tmpString     := "";
    tmpString2[0] := "E";
    Card2Str(n,tmpString1);
    Concat(tmpString,tmpString1,tmpString);
    Concat(tmpString,tmpString2,tmpString);
    WriteString(tmpString)
END cursorbnl;

PROCEDURE cursorblpl(n : CARDINAL);
(* ESC[#F 	moves cursor to beginning of previous line, # lines up *)

VAR
    tmpString : ARRAY[0..5] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: String1;
    
BEGIN
    tmpString := "";
    tmpString2[0] := "F";
    Card2Str(n,tmpString1);
    Concat(tmpString,tmpString1,tmpString);
    Concat(tmpString,tmpString2,tmpString);
    WriteString(tmpString)
END cursorblpl;

PROCEDURE cursottocol(n : CARDINAL);
(* ESC[#G 	moves cursor to column # *)

VAR
    tmpString : ARRAY[0..5] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: String1;
    
BEGIN
    tmpString := "";
    tmpString2[0] := "G";
    Card2Str(n,tmpString1);
    Concat(tmpString,tmpString1,tmpString);
    Concat(tmpString,tmpString2,tmpString);
    WriteString(tmpString)
END cursottocol;

PROCEDURE requestCursorPosition(VAR x,y : CARDINAL);
(* ESC[6n 	request cursor position (reports as ESC[#;#R) *)

VAR
    str          : ARRAY [0..15] OF CHAR;
    theStructure : SplitV1.Structure;

BEGIN
    SplitV1.InitStructure(theStructure);
    (* sending the request *)
    WriteString(requestCursorPositionStr);
    (* quering the answer *)
    ReadString(str);
    (* extracting coodinates from the answer *)
    (*PROCEDURE Delete (VAR stringVar: ARRAY OF CHAR; startIndex, numberToDelete: CARDINAL);
D   eletes at most numberToDelete characters from stringVar, starting at position startIndex.
    *)
    Delete(str,0,2);
    Delete(str,Length(str) -1 ,1);
    SplitV1.SplitStr(str, ";", theStructure);
    StrToCard(theStructure[0].element,x);
    StrToCard(theStructure[1].element,y);

END requestCursorPosition;

PROCEDURE cursorhome;
(* Move cursor to upper left corner       ^[[H *)
BEGIN
    WriteString(cursorhomeStr)
END cursorhome;

PROCEDURE cursorhome1;
(* Move cursor to upper left corner       ^[[;H *)
BEGIN
    WriteString(cursorhome1Str)
END cursorhome1;

PROCEDURE cursorpos(x,y : CARDINAL);
(* CUP Move cursor to screen location v,h     ^[[<v>;<h>H *)

VAR
    tmpString : ARRAY[0..10] OF CHAR;
    tmpString1: ARRAY[0..5] OF CHAR;
    tmpString2: String1;

BEGIN
    tmpString := "";
    (* the preamble *)
    Concat(tmpString,cursorpos1Str, tmpString);

    (* the first coordinate *)
    tmpString1 := "";
    Card2Str(y,tmpString1);
    Concat(tmpString,tmpString1, tmpString);

    (* the separator *)
    tmpString2[0] := ";";
    Concat(tmpString, tmpString2,tmpString);

    (* the second coordinate *)
    tmpString1 := "";
    Card2Str(x,tmpString1);
    Concat(tmpString,tmpString1, tmpString);

    (* the final *)
    tmpString2[0] := "H";
    Concat(tmpString, tmpString2,tmpString);

    (*End Debug*)
    WriteString(tmpString)

END cursorpos;
(*
PROCEDURE hvhome;
(* Move cursor to upper left corner       ^[[f *)
BEGIN
END ;

PROCEDURE hvhome;
(* Move cursor to upper left corner       ^[[;f *)
BEGIN
END ;

PROCEDURE hvpos(v,h);
(* CUP Move cursor to screen location v,h     ^[[<v>;<h>f *)
BEGIN
END ;

PROCEDURE index;
(* IND Move/scroll window up one line         ^[D *)

PROCEDURE revindex;
(* RI Move/scroll window down one line       ^[M *)
BEGIN
END ;

PROCEDURE nextline;
(* NEL Move to next line                      ^[E *)
BEGIN
END ;

PROCEDURE savecursor;
(* DECSC Save cursor position and attributes    ^[7 *)
BEGIN
END ;

PROCEDURE restorecursor;
(* DECSC Restore cursor position and attributes ^[8 *)
BEGIN
END ;

PROCEDURE tabset;
(* HTS Set a tab at the current column        ^[H *)
BEGIN
END ;

PROCEDURE tabclr;
(* TBC Clear a tab at the current column      ^[[g *)
BEGIN
END ;

PROCEDURE tabclr;
(* TBC Clear a tab at the current column      ^[[0g *)
BEGIN
END ;

PROCEDURE tabclrall;
(* TBC Clear all tabs                         ^[[3g *)
BEGIN
END ;

PROCEDURE dhtop;
(* DECDHL Double-height letters, top half        ^[#3 *)
BEGIN
END ;

PROCEDURE dhbot;
(* DECDHL Double-height letters, bottom half     ^[#4 *)
BEGIN
END ;

PROCEDURE swsh;
(* DECSWL Single width, single height letters    ^[#5 *)
BEGIN
END ;

PROCEDURE dwsh;
(* DECDWL Double width, single height letters    ^[#6 *)
BEGIN
END ;

PROCEDURE cleareol;
(* EL0 Clear line from cursor right           ^[[K *)
BEGIN
END ;

PROCEDURE cleareol;
(* EL0 Clear line from cursor right           ^[[0K *)
BEGIN
END ;

PROCEDURE clearbol;
(* EL1 Clear line from cursor left            ^[[1K *)
BEGIN
END ;

PROCEDURE clearline;
(* EL2 Clear entire line                      ^[[2K *)
BEGIN
END ;

PROCEDURE cleareos;
(* ED0 Clear screen from cursor down          ^[[J *)
BEGIN
END ;

PROCEDURE cleareos;
(* ED0 Clear screen from cursor down          ^[[0J *)
BEGIN
END ;

PROCEDURE clearbos;
(* ED1 Clear screen from cursor up            ^[[1J *)
BEGIN
END ;
*)
PROCEDURE clearscreen;
(* ED2 Clear entire screen                    ^[[2J *)
BEGIN
    WriteString(clearscreenStr)
END clearscreen;
(*
PROCEDURE devstat;
(* DSR Device status report                   ^[5n *)
BEGIN
END ;

PROCEDURE termok;
(* DSR Response: terminal is OK            ^[0n *)
BEGIN
END ;

PROCEDURE termnok;
(* DSR Response: terminal is not OK        ^[3n *)
BEGIN
END ;

PROCEDURE getcursor;
(* DSR Get cursor position                    ^[6n *)
BEGIN
END ;

PROCEDURE cursorpos;
(* CPR Response: cursor is at v,h          ^[<v>;<h>R *)
BEGIN
END ;

PROCEDURE ident;
(* DA Identify what terminal type            ^[[c *)
BEGIN
END ;

PROCEDURE ident;
(* DA Identify what terminal type (another)  ^[[0c *)
BEGIN
END ;

PROCEDURE gettype;
(* DA Response: terminal type code n      ^[[?1;<n>0c *)
BEGIN
END ;

PROCEDURE reset;
(* RIS Reset terminal to initial state        ^[c *)
BEGIN
END ;

PROCEDURE align;
(* DECALN Screen alignment display               ^[#8 *)
BEGIN
END ;

PROCEDURE testpu;
(* DECTST Confidence power up test               ^[[2;1y *)
BEGIN
END ;

PROCEDURE testlb;
(* DECTST Confidence loopback test               ^[[2;2y *)
BEGIN
END ;

PROCEDURE testpurep;
(* DECTST Repeat power up test                   ^[[2;9y *)
BEGIN
END ;

PROCEDURE testlbrep;
(* DECTST Repeat loopback test                   ^[[2;10y *)
BEGIN
END ;

PROCEDURE ledsoff;
(* DECLL0 Turn off all four leds                 ^[[0q *)
BEGIN
END ;

PROCEDURE led1;
(* DECLL1 Turn on LED #1                         ^[[1q *)
BEGIN
END ;

PROCEDURE led2;
(* DECLL2 Turn on LED #2                         ^[[2q *)
BEGIN
END ;

PROCEDURE led3;
(* DECLL3 Turn on LED #3                         ^[[3q *)
BEGIN
END ;

PROCEDURE led4;
(* DECLL4 Turn on LED #4                         ^[[4q *)
BEGIN
END ;
*)


PROCEDURE screenMode(mode : screenModes);
VAR
    tmpString   : Array4;
    scrMode     : screenModes;
BEGIN
    tmpString := "";
    CASE scrMode OF
        M40x25BW:       Assign(M40x25BWStr, tmpString);       |
        M40x25C:        Assign(M80x25BWStr, tmpString);       |
        M80x25BW:       Assign(M80x25BWStr, tmpString);       |
        M80x25C:        Assign(M80x25CStr, tmpString);        |
        M320x200C4:     Assign(M320x200C4Str, tmpString);     |
        M320x200BW:     Assign(M320x200BWStr, tmpString);     |
        M640x200BW:     Assign(M640x200BWStr, tmpString);     |
        M320x200C256:   Assign(M320x200C256Str, tmpString);   |
        M640x200C:      Assign(M640x200CStr, tmpString);      |
        M640x350BW:     Assign(M640x350BWStr, tmpString);     |
        M640x350C:      Assign(M640x350CStr, tmpString);      |
        M640x480BW:     Assign(M640x480BWStr, tmpString);     |
        M640x480C:      Assign(M640x480CStr, tmpString);      |
        M320x200C:      Assign(M320x200CStr, tmpString);
    END;
    WriteString(tmpString)
END screenMode;

PROCEDURE resetScreenMode(mode : screenModes);
BEGIN
   WriteString(resetScreenModeStr)
END resetScreenMode;

PROCEDURE lineWrapping;
BEGIN
   WriteString(lineWrappingStr)
END lineWrapping;

PROCEDURE resetLineWrapping;
BEGIN
   WriteString(resetLineWrappingStr)
END resetLineWrapping;

PROCEDURE makeCursorInvisible;
BEGIN
   WriteString(makeCursorInvisibleStr)
END makeCursorInvisible;

PROCEDURE makeCursorVisible;
BEGIN
   WriteString(makeCursorVisibleStr)
END makeCursorVisible;

PROCEDURE restoreScreen;
BEGIN
   WriteString(restoreScreenStr)
END restoreScreen;

PROCEDURE saveScreen;
BEGIN
   WriteString(saveScreenStr)
END saveScreen;

PROCEDURE enableAlternativeBuffer;
BEGIN
   WriteString(enableAlternativeBufferStr)
END enableAlternativeBuffer;

PROCEDURE disableAlternativeBuffer;
BEGIN
   WriteString(disableAlternativeBufferStr)
END disableAlternativeBuffer;

PROCEDURE setAttribut ( attribut : Attribut; front, back : Colors );
VAR
    tmpString  : ARRAY [0..15] OF CHAR;
    tmpString1 : ARRAY [0..1]  OF CHAR;
    tmpString2 : ARRAY [0..2]  OF CHAR;
    tmpString3 : String1;
    tmpString4 : String1;
    tmpString5 : String1;

    (* esc + [ + attribut + ; + front + ; back + m *)
BEGIN
    tmpString1 := "";
    tmpString2 := "";
    tmpString3[0] := ";";
    tmpString4[0] := "m";
    (* esc [ *)
    Concat(tmpString,setAttributStr,tmpString);
    (* attribute *)
    CASE attribut OF
      boldAt:           tmpString5[0] := "1";   |
      dimAt:            tmpString5[0] := "2";   |
      italicAt:         tmpString5[0] := "3";   |
      underlineAt:      tmpString5[0] := "4";   |
      blinkingAt:       tmpString5[0] := "5";   |
      inverseAt:        tmpString5[0] := "7";   |
      hiddenAt:         tmpString5[0] := "8";   |
      strikethroughAt:  tmpString5[0] := "9";   
      (* doubleunderlineAt:tmpString2 := "21"; *)
    END;
    Concat(tmpString,tmpString5,tmpString);
    (* special case with double underline *)
    IF attribut = doubleunderlineAt THEN
        Concat(tmpString,"21",tmpString);
    END;
    (* ; *)
    Concat(tmpString,tmpString3,tmpString);
    (* front *)
    CASE front OF
        Black:          tmpString1 := "30"; |
        Red:            tmpString1 := "31"; |
        Green:          tmpString1 := "32"; |
        Yellow:         tmpString1 := "33"; |
        Blue:           tmpString1 := "34"; |
        Magenta:        tmpString1 := "35"; |
        Cyan:           tmpString1 := "36"; |
        White:          tmpString1 := "37"; |
        Default:        tmpString1 := "39"; |
        BrightBlack:    tmpString1 := "90"; |
        BrightRed:      tmpString1 := "91"; |
        BrightGreen:    tmpString1 := "92"; |
        BrightYellow:   tmpString1 := "93"; |
        BrightBlue:     tmpString1 := "94"; |
        BrighMagenta:   tmpString1 := "95"; |
        BrightCyan:     tmpString1 := "96"; |
        BrightWhite:    tmpString1 := "97"; 
    END;
    Concat(tmpString,tmpString1,tmpString);
    Concat(tmpString,tmpString3,tmpString);
    (* back *)
    CASE back OF
        Black:          tmpString2 := "40";  |
        Red:            tmpString2 := "41";  |
        Green:          tmpString2 := "42";  |
        Yellow:         tmpString2 := "43";  |
        Blue:           tmpString2 := "44";  |
        Magenta:        tmpString2 := "45";  |
        Cyan:           tmpString2:= "46";   |
        White:          tmpString2 := "47";  |
        Default:        tmpString2 := "49";  |
        BrightBlack:    tmpString2 := "100"; |
        BrightRed:      tmpString2 := "101"; |
        BrightGreen:    tmpString2 := "102"; |
        BrightYellow:   tmpString2 := "103"; |
        BrightBlue:     tmpString2 := "104"; |
        BrighMagenta:   tmpString2 := "105"; |
        BrightCyan:     tmpString2 := "106"; |
        BrightWhite:    tmpString2 := "107"; 
    END;
    Concat(tmpString,tmpString2,tmpString);
    (* m *)
    Concat(tmpString,tmpString4,tmpString);
    WriteString(tmpString)

END setAttribut;

(* 
#
#  All codes below are for use in VT52 compatibility mode.
# 
*)

PROCEDURE VT52setansi;
               (* Enter/exit ANSI mode (VT52)            ^[< *)
BEGIN
    WriteString(setansiStr)
END VT52setansi ;

PROCEDURE VT52altkeypad;
             (* Enter alternate keypad mode            ^[= *)
BEGIN
    WriteString(altkeypadStr)
END VT52altkeypad;

PROCEDURE VT52numkeypad ;
            (* Exit alternate keypad mode             ^[> *)
BEGIN
    WriteString(numkeypadStr)
END VT52numkeypad;

PROCEDURE VT52setgr ;
                (* Use special graphics character set     ^[F *)
BEGIN
    WriteString(setgrStr)
END VT52setgr;

PROCEDURE VT52resetgr;
               (* Use normal US/UK character set         ^[G *)
BEGIN
    WriteString(resetgrStr)
END VT52resetgr;

PROCEDURE VT52cursorup;
              (* Move cursor up one line                ^[A *)
BEGIN
    WriteString(cursorupStr)
END VT52cursorup;

PROCEDURE VT52cursordn;
              (* Move cursor down one line              ^[B *)
BEGIN
    WriteString(cursordnStr)
END VT52cursordn;

PROCEDURE VT52cursorrt;
              (* Move cursor right one char             ^[C *)
BEGIN
    WriteString(cursorrtStr)
END VT52cursorrt;

PROCEDURE VT52cursorlf;
              (* Move cursor left one char              ^[D *)
BEGIN
    WriteString(cursorlfStr)
END VT52cursorlf;

PROCEDURE VT52cursorhome;
            (* Move cursor to upper left corner       ^[H *)
BEGIN
    WriteString(cursorhomeStr)
END VT52cursorhome;

PROCEDURE VT52cursorpos(y ,x : CARDINAL);
        (* Move cursor to v,h location            ^[<v><h> *)
    VAR
        tmpString       : ARRAY [0..10] OF CHAR;
        tmpString1,
        tmpString2,
        tmpString3      : String1;
        xPos, yPos      : CARDINAL;

BEGIN
    Concat(tmpString,cursorposStr,tmpString);
    xPos := x  + 31;  
    yPos := y + 31;  
    (* don't forget to flip x and y *)
    tmpString1[0] :=  CHR(yPos);
    tmpString2[0] :=  CHR(xPos);
    (* tmpString3[0] :=  "H"; *)
    Concat(tmpString,tmpString1, tmpString);
    Concat(tmpString,tmpString2, tmpString);  
    (* Concat(tmpString,tmpString3, tmpString); *)
    WriteString(tmpString)
END VT52cursorpos;

PROCEDURE VT52revindex;
              (* Generate a reverse line-feed           ^[I *)
BEGIN
    WriteString(revindexStr)
END VT52revindex;

PROCEDURE VT52cleareol;
              (* Erase to end of current line           ^[K *)
BEGIN
    WriteString(cleareolStr)
END VT52cleareol;

PROCEDURE VT52cleareos;
              (* Erase to end of screen                 ^[J *)
BEGIN
    WriteString(cleareosStr)
END VT52cleareos;

PROCEDURE VT52ident;
                 (* Identify what the terminal is          ^[Z *)
BEGIN
    WriteString(identStr)
END VT52ident;

PROCEDURE VT52identresp;
             (* Correct response to ident              ^[/Z *)
BEGIN
    WriteString(identrespStr)
END VT52identresp; 

PROCEDURE CloseTerminal;
    (* PROCEDURE tcsetattr (fd: INTEGER; option: INTEGER; t: TERMIOS) : INTEGER ; *)

   VAR
        theResult : INTEGER;
BEGIN
    theResult  := termios.tcsetattr(savedFd,termios.lflusho,theterminal);
    IF theResult <> 0 THEN
        WriteString(" Terminal state properly restored !")
    ELSE
        WriteString("Terminal not properly restored !")
    END;
END CloseTerminal;


PROCEDURE InitTerminal;
(* PROCEDURE tcgetattr (fd: INTEGER; t: TERMIOS) : INTEGER ; *)

    VAR
        theResult : INTEGER;
BEGIN
    theterminal := termios.InitTermios();
    theResult  := termios.tcgetattr(savedFd, theterminal);
    IF theResult <> -1 THEN
        WriteString(" Terminal state properly saved !")
    ELSE
        WriteString("Terminal state not properly saved")
    END;
    termios.cfmakeraw (theterminal) ;
END InitTerminal;

BEGIN
    (* VT 52 mode *)
    Concat(ASCII.esc,"[<",setansiStr);

    Concat(ASCII.esc,"[=",altkeypadStr);
    Concat(ASCII.esc,"[>",numkeypadStr);

    Concat(ASCII.esc,"[F",setgrStr);
    Concat(ASCII.esc,"[G",resetgrStr);

    Concat(ASCII.esc,"[A",cursorupStr);
    Concat(ASCII.esc,"[B",cursordnStr);
    Concat(ASCII.esc,"[C",cursorrtStr);
    Concat(ASCII.esc,"[D",cursorlfStr);
    Concat(ASCII.esc,"[H",cursorhomeStr);
    Concat(ASCII.esc,"[Y",cursorposStr);
    Concat(ASCII.esc,"[I",revindexStr);

    Concat(ASCII.esc,"[K",cleareolStr);
    Concat(ASCII.esc,"[J",cleareosStr);

    Concat(ASCII.esc,"[Z",identStr);
    Concat(ASCII.esc,"[/Z",identrespStr);

    (* VT100 mode *)
    Concat(ASCII.esc,"[",setnlStr);
    Concat(ASCII.esc,"[",setapplStr);
    Concat(ASCII.esc,"[",setansi1Str);
    Concat(ASCII.esc,"[",setcolStr);
    Concat(ASCII.esc,"[",setsmoothStr);
    Concat(ASCII.esc,"[",setrevscrnStr);
    Concat(ASCII.esc,"[",setorgrelStr);
    Concat(ASCII.esc,"[",setwrapStr);
    Concat(ASCII.esc,"[",setrepStr);
    Concat(ASCII.esc,"[",setinterStr);

    Concat(ASCII.esc,"[",setlfStr);
    Concat(ASCII.esc,"[",setcursorStr);
    Concat(ASCII.esc,"[",setvt52Str);
    Concat(ASCII.esc,"[",resetcolStr);
    Concat(ASCII.esc,"[",setjumpStr);
    Concat(ASCII.esc,"[",setnormscrnStr);
    Concat(ASCII.esc,"[",setorgabsStr);
    Concat(ASCII.esc,"[",resetwrapStr);
    Concat(ASCII.esc,"[",resetrepStr);
    Concat(ASCII.esc,"[",resetinterStr);

    Concat(ASCII.esc,"[",altkeypad1Str);
    Concat(ASCII.esc,"[",numkeypad1Str);

    Concat(ASCII.esc,"[",setukg0Str);
    Concat(ASCII.esc,"[",setukg1Str);
    Concat(ASCII.esc,"[",setusg0Str);
    Concat(ASCII.esc,"[",setusg1Str);
    Concat(ASCII.esc,"[",setspecg0Str);
    Concat(ASCII.esc,"[",setspecg1Str);
    Concat(ASCII.esc,"[",setaltg0Str);
    Concat(ASCII.esc,"[",setaltg1Str);
    Concat(ASCII.esc,"[",setaltspecg0Str);
    Concat(ASCII.esc,"[",setaltspecg1Str);

    Concat(ASCII.esc,"[",setss2Str);
    Concat(ASCII.esc,"[",setss3Str);

    Concat(ASCII.esc,"[m",modesoff0Str);
    Concat(ASCII.esc,"[0m",modesoff1Str);
    Concat(ASCII.esc,"[1m",boldStr);
    Concat(ASCII.esc,"[2m",lowintStr);
    Concat(ASCII.esc,"[3m",italicStr);
    Concat(ASCII.esc,"[4m",underlineStr);
    Concat(ASCII.esc,"[5m",blinkStr);
    Concat(ASCII.esc,"[7m",reverseStr);
    Concat(ASCII.esc,"[8m",invisibleStr);
    Concat(ASCII.esc,"[9m",strikethroughStr);

    Concat(ASCII.esc,"[22m",resetboldStr);
    Concat(ASCII.esc,"[22m",resetlowintStr);
    Concat(ASCII.esc,"[23m",resetitalicStr);
    Concat(ASCII.esc,"[24m",resetunderlineStr);
    Concat(ASCII.esc,"[25m",resetblinkStr);
    Concat(ASCII.esc,"[27m",resetreverseStr);
    Concat(ASCII.esc,"[28m",resetinvisibleStr);
    Concat(ASCII.esc,"[29m",resetstrikethroughStr);


    Concat(ASCII.esc,"[",setwinStr);

    Concat(ASCII.esc,"[",cursorup1Str);
    Concat(ASCII.esc,"[",cursordn1Str);
    Concat(ASCII.esc,"[",cursorrt1Str);
    Concat(ASCII.esc,"[",cursorlf1Str);
    Concat(ASCII.esc,"[",cursorhome0Str);
    Concat(ASCII.esc,"[;H",cursorhome1Str);
    Concat(ASCII.esc,"[",cursorpos1Str);
    Concat(ASCII.esc,"[6n",requestCursorPositionStr);
    Concat(ASCII.esc,"[",hvhome0Str);
    Concat(ASCII.esc,"[",hvhome1Str);
    Concat(ASCII.esc,"[",cursorbnlStr);
    Concat(ASCII.esc,"[",cursorblplStr);
    Concat(ASCII.esc,"[",cursottocolStr);
    Concat(ASCII.esc,"[",hvposStr);
    Concat(ASCII.esc,"[",indexStr);
    Concat(ASCII.esc,"[",revindex1Str);
    Concat(ASCII.esc,"[",nextlineStr);
    Concat(ASCII.esc,"[",savecursStr);
    Concat(ASCII.esc,"[",restorecursorStr);

    Concat(ASCII.esc,"[",tabsetStr);
    Concat(ASCII.esc,"[",tabclr0Str);
    Concat(ASCII.esc,"[",tabclr1Str);
    Concat(ASCII.esc,"[",tabclrallStr);

    Concat(ASCII.esc,"[",dhtopStr);
    Concat(ASCII.esc,"[",dhbotStr);
    Concat(ASCII.esc,"[",swshStr);
    Concat(ASCII.esc,"[",dwshStr);

    Concat(ASCII.esc,"[",cleareol0Str);
    Concat(ASCII.esc,"[",cleareol1Str);
    Concat(ASCII.esc,"[",clearbol2Str);
    Concat(ASCII.esc,"[",clearlineStr);

    Concat(ASCII.esc,"[",cleareos0Str);
    Concat(ASCII.esc,"[",cleareos1Str);
    Concat(ASCII.esc,"[",clearbos2Str);
    Concat(ASCII.esc,"[2J",clearscreenStr);

    Concat(ASCII.esc,"[",devstatStr);
    Concat(ASCII.esc,"[",termokStr);
    Concat(ASCII.esc,"[",termnokStr);

    Concat(ASCII.esc,"[",getcursorStr);
    Concat(ASCII.esc,"[",cursorpos2Str);

    Concat(ASCII.esc,"[",ident1Str);
    Concat(ASCII.esc,"[",ident2Str);
    Concat(ASCII.esc,"[",gettypeStr);

    Concat(ASCII.esc,"[",resetStr);

    Concat(ASCII.esc,"[",alignStr);
    Concat(ASCII.esc,"[",testpuStr);
    Concat(ASCII.esc,"[",testlbStr);
    Concat(ASCII.esc,"[",testpurepStr);
    Concat(ASCII.esc,"[",testlbrepStr);

    Concat(ASCII.esc,"[",ledsoffStr);
    Concat(ASCII.esc,"[",led1Str);
    Concat(ASCII.esc,"[",led2Str);
    Concat(ASCII.esc,"[",led3Str);
    Concat(ASCII.esc,"[",led4Str);
Concat(ASCII.esc,"[=0h",M40x25BWStr);    (*	40 x 25 monochrome (text)*)
Concat(ASCII.esc,"[=1h",M40x25CStr);     (* 	40 x 25 color (text)*)
Concat(ASCII.esc,"[=2h",M40x25CStr);     (* 	80 x 25 monochrome (text)*)
Concat(ASCII.esc,"[=3h",M80x25CStr);     (* 	80 x 25 color (text)*)
Concat(ASCII.esc,"[=4h",M320x200C4Str);   (* 	320 x 200 4-color (graphics)*)
Concat(ASCII.esc,"[=5h",M320x200BWStr);  (* 	320 x 200 monochrome (graphics)*)
Concat(ASCII.esc,"[=6h",M640x200BWStr);  (* 	640 x 200 monochrome (graphics)*)
Concat(ASCII.esc,"[=7h",resetLineWrappingStr);              (* 	Enables line wrapping*)
Concat(ASCII.esc,"[=13h",M640x200BWStr); (* 	320 x 200 color (graphics)*)
Concat(ASCII.esc,"[=14h",M640x200CStr);  (* 	640 x 200 color (16-color graphics)*)
Concat(ASCII.esc,"[=15h",M640x200CStr);  (* 	640 x 350 monochrome (2-color graphics)*)
Concat(ASCII.esc,"[=16h",M640x350CStr);  (* 	640 x 350 color (16-color graphics)*)
Concat(ASCII.esc,"[=17h",M640x480BWStr); (*	640 x 480 monochrome (2-color graphics)*)
Concat(ASCII.esc,"[=18h",M640x480CStr);  (* 	640 x 480 color (16-color graphics)*)
Concat(ASCII.esc,"[=19h",M320x200CStr);  (* 	320 x 200 color (256-color graphics)*)
(* ESC[={value}l *)


Concat(ASCII.esc,"[?25l",makeCursorInvisibleStr); (* ESC[?25l 	make cursor invisible *)
Concat(ASCII.esc,"[?25h",makeCursorVisibleStr); (* ESC[?25h 	make cursor visible *)
Concat(ASCII.esc,"[?47l",restoreScreenStr); (* ESC[?47l 	restore screen *)
Concat(ASCII.esc,"[?47h",saveScreenStr); (* ESC[?47h 	save screen *)
Concat(ASCII.esc,"[?1049h",enableAlternativeBufferStr); (* ESC[?1049h 	enables the alternative buffer *)
Concat(ASCII.esc,"[?1049l",disableAlternativeBufferStr); (* ESC[?1049l 	disables the alternative buffer *)


Concat(ASCII.esc,"[21m",resetinvisibleStr);             (* ESC[21m *)
Concat(ASCII.esc,"[24m",resetDoubleUnderlineStr);      (* ESC[24m. *)
Concat(ASCII.esc,"[", setAttributStr);

END VT100.

   (*Debug*)
    (* chaine := "toto"; *)
    (* FOR i := 0 TO Length(tmpString) DO
        WriteHex(ORD(tmpString[i]),2);
        WriteChar(" ")
    END; *)
    (*End Debug*)