2020-06-08 23:44:44 +02:00
|
|
|
(*
|
|
|
|
KolibriOS CRT unit
|
|
|
|
*)
|
|
|
|
|
2020-06-07 17:33:22 +02:00
|
|
|
unit CRT;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
type
|
2020-06-08 23:44:44 +02:00
|
|
|
TCursorXY = record
|
2020-06-09 01:00:49 +02:00
|
|
|
X, Y: Integer;
|
2020-06-07 17:33:22 +02:00
|
|
|
end;
|
|
|
|
|
2020-12-26 22:39:15 +01:00
|
|
|
TKey = packed record
|
2020-06-24 15:38:03 +02:00
|
|
|
CharCode, ScanCode: KolibriChar;
|
2020-06-20 21:19:49 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-07 17:33:22 +02:00
|
|
|
const
|
|
|
|
Black = 0;
|
|
|
|
Blue = 1;
|
|
|
|
Green = 2;
|
|
|
|
Cyan = 3;
|
|
|
|
Red = 4;
|
|
|
|
Magenta = 5;
|
2020-06-08 22:18:54 +02:00
|
|
|
Brown = 6;
|
2020-06-07 17:33:22 +02:00
|
|
|
LightGray = 7;
|
2020-06-08 22:18:54 +02:00
|
|
|
DarkGray = 8;
|
2020-06-07 17:33:22 +02:00
|
|
|
LightBlue = 9;
|
|
|
|
LightGreen = 10;
|
|
|
|
LightCyan = 11;
|
|
|
|
LightRed = 12;
|
|
|
|
LightMagenta = 13;
|
|
|
|
Yellow = 14;
|
|
|
|
White = 15;
|
|
|
|
|
2020-06-12 11:01:19 +02:00
|
|
|
procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean = False;
|
2020-06-07 18:39:30 +02:00
|
|
|
WndWidth: LongWord = $FFFFFFFF; WndHeight: LongWord = $FFFFFFFF; ScrWidth: LongWord = $FFFFFFFF; ScrHeight: LongWord = $FFFFFFFF);
|
2020-06-09 21:19:49 +02:00
|
|
|
procedure SetTitle(Title: PKolibriChar);
|
2020-06-07 17:33:22 +02:00
|
|
|
|
2020-06-08 23:44:44 +02:00
|
|
|
procedure GotoXY(X, Y: Integer); overload;
|
|
|
|
procedure GotoXY(const Point: TCursorXY); overload;
|
|
|
|
function WhereX: Integer;
|
|
|
|
function WhereY: Integer;
|
|
|
|
function WhereXY: TCursorXY;
|
2020-06-07 17:33:22 +02:00
|
|
|
|
2020-06-09 00:43:32 +02:00
|
|
|
function NormVideo: LongWord; // reset text attributes
|
2020-06-09 21:05:24 +02:00
|
|
|
function TextAttr: Byte; overload;
|
|
|
|
function TextAttr(Attr: Byte): LongWord; overload;
|
|
|
|
function TextAttr(Color, Background: Byte): LongWord; overload;
|
2020-06-09 00:43:32 +02:00
|
|
|
function TextBackground: Byte; overload;
|
|
|
|
function TextBackground(Color: Byte): LongWord; overload;
|
|
|
|
function TextColor: Byte; overload;
|
|
|
|
function TextColor(Color: Byte): LongWord; overload;
|
2020-06-07 17:33:22 +02:00
|
|
|
|
2020-06-09 02:30:39 +02:00
|
|
|
procedure ClrScr;
|
|
|
|
|
2020-06-09 00:57:27 +02:00
|
|
|
function CursorBig: Integer;
|
|
|
|
function CursorHeight: Integer; overload;
|
|
|
|
function CursorHeight(Height: Integer): Integer; overload;
|
|
|
|
function CursorOff: Integer;
|
|
|
|
function CursorOn: Integer;
|
2020-06-08 23:44:44 +02:00
|
|
|
|
2020-06-09 02:30:39 +02:00
|
|
|
function KeyPressed: Boolean;
|
|
|
|
function ReadKey: KolibriChar;
|
2020-12-26 22:39:15 +01:00
|
|
|
function ReadKeyEx: TKey;
|
2020-06-08 23:44:44 +02:00
|
|
|
|
2020-06-09 02:30:39 +02:00
|
|
|
function FontHeight: Integer;
|
|
|
|
|
2020-06-09 21:35:08 +02:00
|
|
|
procedure Delay(Milliseconds: LongWord);
|
2020-06-07 17:33:22 +02:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2020-06-20 21:19:49 +02:00
|
|
|
uses
|
2020-12-26 22:39:15 +01:00
|
|
|
KolibriOS;
|
2020-06-20 21:19:49 +02:00
|
|
|
|
2020-06-07 18:39:30 +02:00
|
|
|
var
|
2020-06-21 02:08:13 +02:00
|
|
|
CloseWindow: Boolean;
|
2020-06-07 17:33:22 +02:00
|
|
|
|
2020-06-09 21:19:49 +02:00
|
|
|
procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean;
|
2020-06-07 18:39:30 +02:00
|
|
|
WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord);
|
2020-06-07 17:33:22 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
con_init(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
|
2020-06-24 15:38:03 +02:00
|
|
|
CloseWindow := CloseWindowOnExit;
|
2020-06-07 17:33:22 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-09 21:19:49 +02:00
|
|
|
procedure SetTitle(Title: PKolibriChar);
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
con_set_title(Title);
|
2020-06-09 21:19:49 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-09 00:43:32 +02:00
|
|
|
function NormVideo: LongWord;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_flags(con_get_flags and $300 or $07);
|
2020-06-09 00:43:32 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-09 21:05:24 +02:00
|
|
|
function TextAttr: Byte;
|
2020-06-09 00:43:32 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_get_flags and $FF;
|
2020-06-09 00:43:32 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-09 21:05:24 +02:00
|
|
|
function TextAttr(Attr: Byte): LongWord;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_flags(con_get_flags and $300 or Attr);
|
2020-06-09 21:05:24 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TextAttr(Color, Background: Byte): LongWord;
|
2020-06-09 00:43:32 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_flags(con_get_flags and $300 or Color and $0F or Background and $0F shl 4);
|
2020-06-09 00:43:32 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TextBackground: Byte;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_get_flags and $F0 shr 4;
|
2020-06-09 00:43:32 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TextBackground(Color: Byte): LongWord;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_flags(con_get_flags and $30F or Color and $0F shl 4);
|
2020-06-09 00:43:32 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TextColor: Byte;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_get_flags and $0F;
|
2020-06-09 00:43:32 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TextColor(Color: Byte): LongWord;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_flags(con_get_flags and $3F0 or Color and $0F);
|
2020-06-09 00:43:32 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-08 23:44:44 +02:00
|
|
|
procedure GotoXY(X, Y: Integer);
|
2020-06-07 17:33:22 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
con_set_cursor_pos(X, Y);
|
2020-06-07 17:33:22 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-08 23:44:44 +02:00
|
|
|
procedure GotoXY(const Point: TCursorXY);
|
2020-06-07 17:33:22 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
con_set_cursor_pos(Point.X, Point.Y);
|
2020-06-07 17:33:22 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-08 23:44:44 +02:00
|
|
|
function WhereX: Integer;
|
2020-06-24 15:38:03 +02:00
|
|
|
var
|
|
|
|
Y: Integer;
|
2020-06-07 17:33:22 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
con_get_cursor_pos(Result, Y);
|
2020-06-08 23:44:44 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function WhereY: Integer;
|
2020-06-24 15:38:03 +02:00
|
|
|
var
|
|
|
|
X: Integer;
|
2020-06-08 23:44:44 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
con_get_cursor_pos(X, Result);
|
2020-06-08 23:44:44 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function WhereXY: TCursorXY;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
con_get_cursor_pos(Result.X, Result.Y);
|
2020-06-08 23:44:44 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-09 00:57:27 +02:00
|
|
|
function CursorBig: Integer;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_cursor_height(15);
|
2020-06-09 00:57:27 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CursorHeight: Integer;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_get_cursor_height;
|
2020-06-09 00:57:27 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function CursorHeight(Height: Integer): Integer;
|
2020-06-08 23:44:44 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_cursor_height(Height);
|
2020-06-08 23:44:44 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-09 00:57:27 +02:00
|
|
|
function CursorOff: Integer;
|
2020-06-08 23:44:44 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_cursor_height(0);
|
2020-06-08 23:44:44 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-09 00:57:27 +02:00
|
|
|
function CursorOn: Integer;
|
2020-06-08 23:44:44 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_set_cursor_height(2);
|
2020-06-07 17:33:22 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-09 02:30:39 +02:00
|
|
|
procedure ClrScr;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
con_cls;
|
2020-06-20 21:19:49 +02:00
|
|
|
end;
|
|
|
|
|
2020-12-26 22:39:15 +01:00
|
|
|
function KeyPressed: Boolean;
|
2020-06-20 21:19:49 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_kbhit;
|
2020-06-20 21:19:49 +02:00
|
|
|
end;
|
|
|
|
|
2020-12-26 22:39:15 +01:00
|
|
|
function ReadKey: KolibriChar;
|
2020-06-09 02:30:39 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := Chr(con_getch);
|
2020-06-09 02:30:39 +02:00
|
|
|
end;
|
|
|
|
|
2020-12-26 22:39:15 +01:00
|
|
|
function ReadKeyEx: TKey;
|
2020-06-09 02:30:39 +02:00
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Word(Result) := con_getch2;
|
2020-06-09 02:30:39 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function FontHeight: Integer;
|
|
|
|
begin
|
2020-12-26 22:39:15 +01:00
|
|
|
Result := con_get_font_height;
|
2020-06-09 02:30:39 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Delay(Milliseconds: LongWord);
|
|
|
|
begin
|
2020-06-09 21:35:08 +02:00
|
|
|
Sleep((Milliseconds + 10 div 2) div 10);
|
2020-06-09 02:30:39 +02:00
|
|
|
end;
|
|
|
|
|
2020-06-24 16:50:45 +02:00
|
|
|
var
|
|
|
|
hConsole: Pointer;
|
|
|
|
|
2020-06-07 18:39:30 +02:00
|
|
|
initialization
|
2020-06-24 16:50:45 +02:00
|
|
|
hConsole := LoadLibrary('/sys/lib/console.obj');
|
2020-12-26 22:39:15 +01:00
|
|
|
|
|
|
|
Pointer(@con_cls) := GetProcAddress(hConsole, 'con_cls');
|
|
|
|
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_height) := GetProcAddress(hConsole, 'con_get_cursor_height');
|
|
|
|
Pointer(@con_get_flags) := GetProcAddress(hConsole, 'con_get_flags');
|
|
|
|
Pointer(@con_get_font_height) := GetProcAddress(hConsole, 'con_get_font_height');
|
|
|
|
Pointer(@con_gets) := GetProcAddress(hConsole, 'con_gets');
|
|
|
|
Pointer(@con_init) := GetProcAddress(hConsole, 'con_init');
|
|
|
|
Pointer(@con_kbhit) := GetProcAddress(hConsole, 'con_kbhit');
|
|
|
|
Pointer(@con_printf) := GetProcAddress(hConsole, 'con_printf');
|
|
|
|
Pointer(@con_set_cursor_height) := GetProcAddress(hConsole, 'con_set_cursor_height');
|
|
|
|
Pointer(@con_set_cursor_pos) := GetProcAddress(hConsole, 'con_set_cursor_pos');
|
|
|
|
Pointer(@con_set_flags) := GetProcAddress(hConsole, 'con_set_flags');
|
|
|
|
Pointer(@con_set_title) := GetProcAddress(hConsole, 'con_set_title');
|
|
|
|
Pointer(@con_write_asciiz) := GetProcAddress(hConsole, 'con_write_asciiz');
|
|
|
|
Pointer(@con_write_string) := GetProcAddress(hConsole, 'con_write_string');
|
2020-06-07 18:39:30 +02:00
|
|
|
|
2020-12-26 23:34:54 +01:00
|
|
|
if IsConsole then
|
|
|
|
InitConsole(AppPath);
|
|
|
|
|
2020-06-07 18:39:30 +02:00
|
|
|
finalization
|
2020-12-26 22:39:15 +01:00
|
|
|
if Assigned(con_exit) then
|
|
|
|
con_exit(CloseWindow);
|
2020-06-07 18:39:30 +02:00
|
|
|
|
2020-06-07 17:33:22 +02:00
|
|
|
end.
|