CRT unit API made closest to original one

GotoXY/WhereXY coordinates start from 1, ClrEOL procedure added.
This commit is contained in:
2021-01-08 18:42:38 +03:00
parent 6a77197098
commit 8ea48f49ba

View File

@@ -52,6 +52,7 @@ function TextBackground(Color: Byte): LongWord; overload;
function TextColor: Byte; overload; function TextColor: Byte; overload;
function TextColor(Color: Byte): LongWord; overload; function TextColor(Color: Byte): LongWord; overload;
procedure ClrEOL;
procedure ClrScr; procedure ClrScr;
function CursorBig: Integer; function CursorBig: Integer;
@@ -74,6 +75,7 @@ uses
KolibriOS; KolibriOS;
var var
ClrEOLWidth: Integer = 80;
CloseWindow: Boolean; CloseWindow: Boolean;
procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean; procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean;
@@ -81,6 +83,8 @@ procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean;
begin begin
con_init(WndWidth, WndHeight, ScrWidth, ScrHeight, Title); con_init(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
CloseWindow := CloseWindowOnExit; CloseWindow := CloseWindowOnExit;
if ScrWidth <> LongWord(-1) then
ClrEOLWidth := ScrWidth;
end; end;
procedure SetTitle(Title: PKolibriChar); procedure SetTitle(Title: PKolibriChar);
@@ -130,12 +134,12 @@ end;
procedure GotoXY(X, Y: Integer); procedure GotoXY(X, Y: Integer);
begin begin
con_set_cursor_pos(X, Y); con_set_cursor_pos(X - 1, Y - 1);
end; end;
procedure GotoXY(const Point: TCursorXY); procedure GotoXY(const Point: TCursorXY);
begin begin
con_set_cursor_pos(Point.X, Point.Y); con_set_cursor_pos(Point.X - 1, Point.Y - 1);
end; end;
function WhereX: Integer; function WhereX: Integer;
@@ -143,6 +147,7 @@ var
Y: Integer; Y: Integer;
begin begin
con_get_cursor_pos(Result, Y); con_get_cursor_pos(Result, Y);
Inc(Result);
end; end;
function WhereY: Integer; function WhereY: Integer;
@@ -150,11 +155,17 @@ var
X: Integer; X: Integer;
begin begin
con_get_cursor_pos(X, Result); con_get_cursor_pos(X, Result);
Inc(Result);
end; end;
function WhereXY: TCursorXY; function WhereXY: TCursorXY;
begin begin
con_get_cursor_pos(Result.X, Result.Y); with Result do
begin
con_get_cursor_pos(X, Y);
Inc(X);
Inc(Y);
end;
end; end;
function CursorBig: Integer; function CursorBig: Integer;
@@ -182,6 +193,22 @@ begin
Result := con_set_cursor_height(2); Result := con_set_cursor_height(2);
end; end;
procedure ClrEOL;
var
I, X, Y, Count: Integer;
Buf: array[0..127] of KolibriChar;
begin
con_get_cursor_pos(X, Y);
Count := ClrEOLWidth - X - 1;
if Count <> 0 then
begin
FillChar(Buf, SizeOf(Buf), ' ');
for I := 0 to Count div Length(Buf) - 1 do
con_write_string(Buf, Length(Buf));
con_write_string(Buf, Count mod Length(Buf));
end;
end;
procedure ClrScr; procedure ClrScr;
begin begin
con_cls; con_cls;
@@ -220,12 +247,12 @@ initialization
Pointer(@con_cls) := GetProcAddress(hConsole, 'con_cls'); Pointer(@con_cls) := GetProcAddress(hConsole, 'con_cls');
Pointer(@con_exit) := GetProcAddress(hConsole, 'con_exit'); Pointer(@con_exit) := GetProcAddress(hConsole, 'con_exit');
Pointer(@con_getch) := GetProcAddress(hConsole, 'con_getch');
Pointer(@con_getch2) := GetProcAddress(hConsole, 'con_getch2');
Pointer(@con_get_cursor_pos) := GetProcAddress(hConsole, 'con_get_cursor_pos'); Pointer(@con_get_cursor_pos) := GetProcAddress(hConsole, 'con_get_cursor_pos');
Pointer(@con_get_cursor_height) := GetProcAddress(hConsole, 'con_get_cursor_height'); Pointer(@con_get_cursor_height) := GetProcAddress(hConsole, 'con_get_cursor_height');
Pointer(@con_get_flags) := GetProcAddress(hConsole, 'con_get_flags'); Pointer(@con_get_flags) := GetProcAddress(hConsole, 'con_get_flags');
Pointer(@con_get_font_height) := GetProcAddress(hConsole, 'con_get_font_height'); Pointer(@con_get_font_height) := GetProcAddress(hConsole, 'con_get_font_height');
Pointer(@con_getch) := GetProcAddress(hConsole, 'con_getch');
Pointer(@con_getch2) := GetProcAddress(hConsole, 'con_getch2');
Pointer(@con_gets) := GetProcAddress(hConsole, 'con_gets'); Pointer(@con_gets) := GetProcAddress(hConsole, 'con_gets');
Pointer(@con_init) := GetProcAddress(hConsole, 'con_init'); Pointer(@con_init) := GetProcAddress(hConsole, 'con_init');
Pointer(@con_kbhit) := GetProcAddress(hConsole, 'con_kbhit'); Pointer(@con_kbhit) := GetProcAddress(hConsole, 'con_kbhit');