CRT unit made more compatible with Turbo/FreePascal one

This commit is contained in:
Владислав Джавадов 2020-06-09 00:44:44 +03:00
parent f59ec2420a
commit 9868828cc2
4 changed files with 72 additions and 35 deletions

View File

@ -39,7 +39,7 @@ begin
TextBackground(White);
WriteLn('White');
ResetAttributes;
NormVideo;
TextColor(Black);
WriteLn('Black');

View File

@ -4,29 +4,25 @@ uses
KolibriOS, CRT;
var
SystemDate: TSystemDate;
SystemTime: TSystemTime;
CursorPos: TConsolePoint;
CursorXY: TCursorXY;
begin
InitConsole('Date/Time');
SetCursorHeight(0);
SetCursorPos(27, 11);
CursorOff;
GotoXY(27, 11);
Write(
'System Date and System Time'#10 +
' '
);
CursorPos := GetCursorPos;
CursorXY := WhereXY;
repeat
SystemDate := GetSystemDate;
SystemTime := GetSystemTime;
with SystemDate, SystemTime do
with GetSystemDate, GetSystemTime do
begin
Write('%02x.%02x.%02x', Day, Month, Year);
Write(' - %02x:%02x:%02x', Hours, Minutes, Seconds);
end;
SetCursorPos(CursorPos);
Sleep(50);
GotoXY(CursorXY);
Delay(500);
until KeyPressed;
end.

View File

@ -9,7 +9,6 @@ var
begin
InitConsole('Load File', False);
Buffer := LoadFile('/sys/example.asm', FileSize);
WriteText(Buffer, FileSize);
end.

View File

@ -1,3 +1,7 @@
(*
KolibriOS CRT unit
*)
unit CRT;
interface
@ -6,8 +10,8 @@ uses
KolibriOS;
type
TConsolePoint = record
X, Y: Integer;
TCursorXY = record
X, Y: LongWord;
end;
const
@ -31,11 +35,13 @@ const
procedure InitConsole(Caption: PKolibriChar; CloseWindowOnExit: Boolean = True;
WndWidth: LongWord = $FFFFFFFF; WndHeight: LongWord = $FFFFFFFF; ScrWidth: LongWord = $FFFFFFFF; ScrHeight: LongWord = $FFFFFFFF);
function GetCursorPos: TConsolePoint;
procedure SetCursorPos(X, Y: Integer); overload;
procedure SetCursorPos(const Point: TConsolePoint); overload;
procedure GotoXY(X, Y: Integer); overload;
procedure GotoXY(const Point: TCursorXY); overload;
function WhereX: Integer;
function WhereY: Integer;
function WhereXY: TCursorXY;
procedure ResetAttributes;
procedure NormVideo; // reset text attributes
procedure TextAttribute(Color, Background: Integer);
procedure TextBackground(Color: Integer);
procedure TextColor(Color: Integer);
@ -43,10 +49,16 @@ procedure TextColor(Color: Integer);
function WriteLn(LineBreaks: Integer = 1): LongInt; overload;
function WriteLn(Text: PKolibriChar; LineBreaks: Integer = 1): LongInt; overload;
function CursorBig: LongWord;
function CursorOff: LongWord;
function CursorOn: LongWord;
procedure Delay(Milliseconds: LongWord); // absolute Sleep(Milliseconds);
var
CursorHeight: function(Height: LongWord): LongWord; stdcall;
KeyPressed: function: Boolean;
ReadKey: function: KolibriChar; stdcall;
SetCursorHeight: function(Height: Integer): Integer; stdcall;
Write: function(const Text: PKolibriChar): LongInt; cdecl varargs;
WriteText: procedure(Text: PKolibriChar; Length: LongWord); stdcall;
@ -55,7 +67,7 @@ implementation
var
CloseWindow: Boolean;
procedure ResetAttributes;
procedure NormVideo;
begin
Write(#27'[0m');
end;
@ -130,12 +142,17 @@ begin
Result := Write(Text) + WriteLn(LineBreaks);
end;
procedure Delay(Milliseconds: LongWord);
begin
Sleep(Milliseconds div 10);
end;
var
hConsole: Pointer;
ConsoleExit: procedure(CloseWindow: Boolean); stdcall;
ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Caption: PKolibriChar); stdcall;
GetCursorPosProc: procedure(var X, Y: Integer); stdcall;
SetCursorPosProc: procedure(X, Y: Integer); stdcall;
GotoXYProc: procedure(X, Y: LongWord); stdcall;
WhereXYProc: procedure(var X, Y: LongWord); stdcall;
procedure InitConsole(Caption: PKolibriChar; CloseWindowOnExit: Boolean;
WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord);
@ -143,11 +160,11 @@ begin
hConsole := LoadLibrary('/sys/lib/console.obj');
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
ConsoleInit := GetProcAddress(hConsole, 'con_init');
GetCursorPosProc := GetProcAddress(hConsole, 'con_get_cursor_pos');
CursorHeight := GetProcAddress(hConsole, 'con_set_cursor_height');
KeyPressed := GetProcAddress(hConsole, 'con_kbhit');
ReadKey := GetProcAddress(hConsole, 'con_getch');
SetCursorHeight := GetProcAddress(hConsole, 'con_set_cursor_height');
SetCursorPosProc := GetProcAddress(hConsole, 'con_set_cursor_pos');
GotoXYProc := GetProcAddress(hConsole, 'con_set_cursor_pos');
WhereXYProc := GetProcAddress(hConsole, 'con_get_cursor_pos');
Write := GetProcAddress(hConsole, 'con_printf');
WriteText := GetProcAddress(hConsole, 'con_write_string');
@ -155,20 +172,45 @@ begin
CloseWindow := CloseWindowOnExit;
end;
function GetCursorPos: TConsolePoint;
procedure GotoXY(X, Y: Integer);
begin
GetCursorPosProc(Result.X, Result.Y);
GotoXYProc(X, Y);
end;
procedure SetCursorPos(X, Y: Integer);
begin
SetCursorPosProc(X, Y);
end;
procedure SetCursorPos(const Point: TConsolePoint);
procedure GotoXY(const Point: TCursorXY);
begin
with Point do
SetCursorPosProc(X, Y);
GotoXYProc(X, Y);
end;
function WhereX: Integer;
begin
Result := WhereXY.X;
end;
function WhereY: Integer;
begin
Result := WhereXY.Y;
end;
function WhereXY: TCursorXY;
begin
WhereXYProc(Result.X, Result.Y);
end;
function CursorBig: LongWord;
begin
Result := CursorHeight(15);
end;
function CursorOff: LongWord;
begin
Result := CursorHeight(0);
end;
function CursorOn: LongWord;
begin
Result := CursorHeight(2);
end;
initialization