mirror of
https://github.com/vapaamies/KolibriOS.git
synced 2025-09-21 22:53:51 +02:00
CRT console API made interfaced
This commit is contained in:
106
Lib/CRT.pas
106
Lib/CRT.pas
@@ -91,111 +91,107 @@ uses
|
|||||||
SysUtils;
|
SysUtils;
|
||||||
|
|
||||||
var
|
var
|
||||||
CloseWindow: Boolean;
|
|
||||||
|
|
||||||
hConsole: Pointer;
|
hConsole: Pointer;
|
||||||
ClrScrProc: procedure; stdcall;
|
ConsoleInterface: TConsoleInterface;
|
||||||
ConsoleExit: procedure(CloseWindow: Boolean); stdcall;
|
ConsoleExit: procedure(CloseWindow: Boolean); stdcall;
|
||||||
ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Caption: PKolibriChar); stdcall;
|
CloseWindow: Boolean;
|
||||||
GetCh: function: Integer; stdcall;
|
|
||||||
GetCh2: function: Word; stdcall;
|
|
||||||
GetS: function(Str: PKolibriChar; Length: Integer): PKolibriChar; stdcall;
|
|
||||||
GetCursorHeight: function: Integer; stdcall;
|
|
||||||
GetFlags: function: LongWord; stdcall;
|
|
||||||
GetFontHeight: function: Integer; stdcall;
|
|
||||||
GotoXYProc: procedure(X, Y: Integer); stdcall;
|
|
||||||
KeyPressedFunc: function: Boolean; stdcall;
|
|
||||||
PrintF: function(const Str: PKolibriChar): Integer; cdecl varargs;
|
|
||||||
ReadKeyFunc: function: KolibriChar; stdcall;
|
|
||||||
SetFlags: function(Flags: LongWord): LongWord; stdcall;
|
|
||||||
SetCursorHeight: function(Height: Integer): Integer; stdcall;
|
|
||||||
SetTitleProc: procedure(Title: PKolibriChar); stdcall;
|
|
||||||
WhereXYProc: procedure(var X, Y: Integer); stdcall;
|
|
||||||
WritePChar: procedure(Str: PKolibriChar); stdcall;
|
|
||||||
WritePCharLen: procedure(Str: PKolibriChar; Length: LongWord); stdcall;
|
|
||||||
|
|
||||||
procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean;
|
procedure InitConsole(Title: PKolibriChar; CloseWindowOnExit: Boolean;
|
||||||
WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord);
|
WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord);
|
||||||
|
var
|
||||||
|
ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Title: PKolibriChar); stdcall;
|
||||||
|
begin
|
||||||
|
if hConsole = nil then
|
||||||
begin
|
begin
|
||||||
hConsole := LoadLibrary('/sys/lib/console.obj');
|
hConsole := LoadLibrary('/sys/lib/console.obj');
|
||||||
ClrScrProc := GetProcAddress(hConsole, 'con_cls');
|
with ConsoleInterface do
|
||||||
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
|
begin
|
||||||
ConsoleInit := GetProcAddress(hConsole, 'con_init');
|
ClrScr := GetProcAddress(hConsole, 'con_cls');
|
||||||
GetCh := GetProcAddress(hConsole, 'con_getch');
|
GetCh := GetProcAddress(hConsole, 'con_getch');
|
||||||
GetCh2 := GetProcAddress(hConsole, 'con_getch2');
|
GetCh2 := GetProcAddress(hConsole, 'con_getch2');
|
||||||
GetS := GetProcAddress(hConsole, 'con_gets');
|
GetS := GetProcAddress(hConsole, 'con_gets');
|
||||||
GetCursorHeight := GetProcAddress(hConsole, 'con_get_cursor_height');
|
GetCursorHeight := GetProcAddress(hConsole, 'con_get_cursor_height');
|
||||||
GetFlags := GetProcAddress(hConsole, 'con_get_flags');
|
GetFlags := GetProcAddress(hConsole, 'con_get_flags');
|
||||||
GetFontHeight := GetProcAddress(hConsole, 'con_get_font_height');
|
GetFontHeight := GetProcAddress(hConsole, 'con_get_font_height');
|
||||||
GotoXYProc := GetProcAddress(hConsole, 'con_set_cursor_pos');
|
GotoXY := GetProcAddress(hConsole, 'con_set_cursor_pos');
|
||||||
KeyPressedFunc := GetProcAddress(hConsole, 'con_kbhit');
|
KeyPressed := GetProcAddress(hConsole, 'con_kbhit');
|
||||||
PrintF := GetProcAddress(hConsole, 'con_printf');
|
PrintF := GetProcAddress(hConsole, 'con_printf');
|
||||||
ReadKeyFunc := GetProcAddress(hConsole, 'con_getch');
|
ReadKey := GetProcAddress(hConsole, 'con_getch');
|
||||||
SetCursorHeight := GetProcAddress(hConsole, 'con_set_cursor_height');
|
SetCursorHeight := GetProcAddress(hConsole, 'con_set_cursor_height');
|
||||||
SetFlags := GetProcAddress(hConsole, 'con_set_flags');
|
SetFlags := GetProcAddress(hConsole, 'con_set_flags');
|
||||||
SetTitleProc := GetProcAddress(hConsole, 'con_set_title');
|
SetTitle := GetProcAddress(hConsole, 'con_set_title');
|
||||||
WhereXYProc := GetProcAddress(hConsole, 'con_get_cursor_pos');
|
WhereXY := GetProcAddress(hConsole, 'con_get_cursor_pos');
|
||||||
WritePChar := GetProcAddress(hConsole, 'con_write_asciiz');
|
WritePChar := GetProcAddress(hConsole, 'con_write_asciiz');
|
||||||
WritePCharLen := GetProcAddress(hConsole, 'con_write_string');
|
WritePCharLen := GetProcAddress(hConsole, 'con_write_string');
|
||||||
|
end;
|
||||||
|
|
||||||
|
ConsoleInit := GetProcAddress(hConsole, 'con_init');
|
||||||
ConsoleInit(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
|
ConsoleInit(WndWidth, WndHeight, ScrWidth, ScrHeight, Title);
|
||||||
|
|
||||||
|
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
|
||||||
CloseWindow := CloseWindowOnExit;
|
CloseWindow := CloseWindowOnExit;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure SetTitle(Title: PKolibriChar);
|
procedure SetTitle(Title: PKolibriChar);
|
||||||
begin
|
begin
|
||||||
SetTitleProc(Title);
|
ConsoleInterface.SetTitle(Title);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function NormVideo: LongWord;
|
function NormVideo: LongWord;
|
||||||
begin
|
begin
|
||||||
|
with ConsoleInterface do
|
||||||
Result := SetFlags(GetFlags and $300 or $07);
|
Result := SetFlags(GetFlags and $300 or $07);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TextAttr: Byte;
|
function TextAttr: Byte;
|
||||||
begin
|
begin
|
||||||
Result := GetFlags and $FF;
|
Result := ConsoleInterface.GetFlags and $FF;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TextAttr(Attr: Byte): LongWord;
|
function TextAttr(Attr: Byte): LongWord;
|
||||||
begin
|
begin
|
||||||
|
with ConsoleInterface do
|
||||||
Result := SetFlags(GetFlags and $300 or Attr);
|
Result := SetFlags(GetFlags and $300 or Attr);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TextAttr(Color, Background: Byte): LongWord;
|
function TextAttr(Color, Background: Byte): LongWord;
|
||||||
begin
|
begin
|
||||||
|
with ConsoleInterface do
|
||||||
Result := SetFlags(GetFlags and $300 or Color and $0F or Background and $0F shl 4);
|
Result := SetFlags(GetFlags and $300 or Color and $0F or Background and $0F shl 4);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TextBackground: Byte;
|
function TextBackground: Byte;
|
||||||
begin
|
begin
|
||||||
Result := GetFlags and $F0 shr 4;
|
Result := ConsoleInterface.GetFlags and $F0 shr 4;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TextBackground(Color: Byte): LongWord;
|
function TextBackground(Color: Byte): LongWord;
|
||||||
begin
|
begin
|
||||||
|
with ConsoleInterface do
|
||||||
Result := SetFlags(GetFlags and $30F or Color and $0F shl 4);
|
Result := SetFlags(GetFlags and $30F or Color and $0F shl 4);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TextColor: Byte;
|
function TextColor: Byte;
|
||||||
begin
|
begin
|
||||||
Result := GetFlags and $0F;
|
Result := ConsoleInterface.GetFlags and $0F;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TextColor(Color: Byte): LongWord;
|
function TextColor(Color: Byte): LongWord;
|
||||||
begin
|
begin
|
||||||
|
with ConsoleInterface do
|
||||||
Result := SetFlags(GetFlags and $3F0 or Color and $0F);
|
Result := SetFlags(GetFlags and $3F0 or Color and $0F);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure GotoXY(X, Y: Integer);
|
procedure GotoXY(X, Y: Integer);
|
||||||
begin
|
begin
|
||||||
GotoXYProc(X, Y);
|
ConsoleInterface.GotoXY(X, Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure GotoXY(const Point: TCursorXY);
|
procedure GotoXY(const Point: TCursorXY);
|
||||||
begin
|
begin
|
||||||
with Point do
|
with Point do
|
||||||
GotoXYProc(X, Y);
|
ConsoleInterface.GotoXY(X, Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function WhereX: Integer;
|
function WhereX: Integer;
|
||||||
@@ -210,52 +206,52 @@ end;
|
|||||||
|
|
||||||
function WhereXY: TCursorXY;
|
function WhereXY: TCursorXY;
|
||||||
begin
|
begin
|
||||||
WhereXYProc(Result.X, Result.Y);
|
ConsoleInterface.WhereXY(Result.X, Result.Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CursorBig: Integer;
|
function CursorBig: Integer;
|
||||||
begin
|
begin
|
||||||
Result := SetCursorHeight(15);
|
Result := ConsoleInterface.SetCursorHeight(15);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CursorHeight: Integer;
|
function CursorHeight: Integer;
|
||||||
begin
|
begin
|
||||||
Result := GetCursorHeight;
|
Result := ConsoleInterface.GetCursorHeight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CursorHeight(Height: Integer): Integer;
|
function CursorHeight(Height: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
Result := SetCursorHeight(Height);
|
Result := ConsoleInterface.SetCursorHeight(Height);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CursorOff: Integer;
|
function CursorOff: Integer;
|
||||||
begin
|
begin
|
||||||
Result := SetCursorHeight(0);
|
Result := ConsoleInterface.SetCursorHeight(0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CursorOn: Integer;
|
function CursorOn: Integer;
|
||||||
begin
|
begin
|
||||||
Result := SetCursorHeight(2);
|
Result := ConsoleInterface.SetCursorHeight(2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ClrScr;
|
procedure ClrScr;
|
||||||
begin
|
begin
|
||||||
ClrScrProc;
|
ConsoleInterface.ClrScr;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Write(Str: PKolibriChar);
|
procedure Write(Str: PKolibriChar);
|
||||||
begin
|
begin
|
||||||
WritePChar(Str);
|
ConsoleInterface.WritePChar(Str);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Write(Str: PKolibriChar; Length: LongWord);
|
procedure Write(Str: PKolibriChar; Length: LongWord);
|
||||||
begin
|
begin
|
||||||
WritePCharLen(Str, Length);
|
ConsoleInterface.WritePCharLen(Str, Length);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Write(const Str: ShortString);
|
procedure Write(const Str: ShortString);
|
||||||
begin
|
begin
|
||||||
WritePCharLen(@Str[1], Length(Str));
|
ConsoleInterface.WritePCharLen(@Str[1], Length(Str));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Write(Format: PKolibriChar; const Args: array of const): Integer;
|
function Write(Format: PKolibriChar; const Args: array of const): Integer;
|
||||||
@@ -272,7 +268,7 @@ asm
|
|||||||
LOOP @@arg
|
LOOP @@arg
|
||||||
@@call:
|
@@call:
|
||||||
PUSH EAX
|
PUSH EAX
|
||||||
CALL PrintF
|
CALL ConsoleInterface.PrintF
|
||||||
|
|
||||||
MOV ESP, EBX
|
MOV ESP, EBX
|
||||||
POP EBX
|
POP EBX
|
||||||
@@ -283,24 +279,24 @@ var
|
|||||||
I: Integer;
|
I: Integer;
|
||||||
begin
|
begin
|
||||||
for I := 0 to LineBreaks - 1 do
|
for I := 0 to LineBreaks - 1 do
|
||||||
WritePCharLen(#10, 1);
|
ConsoleInterface.WritePCharLen(#10, 1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure WriteLn(Str: PKolibriChar; LineBreaks: Integer);
|
procedure WriteLn(Str: PKolibriChar; LineBreaks: Integer);
|
||||||
begin
|
begin
|
||||||
WritePChar(Str);
|
ConsoleInterface.WritePChar(Str);
|
||||||
WriteLn(LineBreaks);
|
WriteLn(LineBreaks);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure WriteLn(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer);
|
procedure WriteLn(Str: PKolibriChar; Length: LongWord; LineBreaks: Integer);
|
||||||
begin
|
begin
|
||||||
WritePCharLen(Str, Length);
|
ConsoleInterface.WritePCharLen(Str, Length);
|
||||||
WriteLn(LineBreaks);
|
WriteLn(LineBreaks);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure WriteLn(const Str: ShortString; LineBreaks: Integer);
|
procedure WriteLn(const Str: ShortString; LineBreaks: Integer);
|
||||||
begin
|
begin
|
||||||
WritePCharLen(@Str[1], Length(Str));
|
ConsoleInterface.WritePCharLen(@Str[1], Length(Str));
|
||||||
WriteLn(LineBreaks);
|
WriteLn(LineBreaks);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -312,14 +308,14 @@ end;
|
|||||||
|
|
||||||
procedure Read(var Result: KolibriChar);
|
procedure Read(var Result: KolibriChar);
|
||||||
begin
|
begin
|
||||||
Result := Chr(GetCh);
|
Result := Chr(ConsoleInterface.GetCh);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Read(var Result: TKey);
|
procedure Read(var Result: TKey);
|
||||||
var
|
var
|
||||||
K: Word;
|
K: Word;
|
||||||
begin
|
begin
|
||||||
K := GetCh2;
|
K := ConsoleInterface.GetCh2;
|
||||||
with WordRec(K), Result do
|
with WordRec(K), Result do
|
||||||
begin
|
begin
|
||||||
CharCode := Lo;
|
CharCode := Lo;
|
||||||
@@ -332,7 +328,7 @@ var
|
|||||||
P, Limit: PKolibriChar;
|
P, Limit: PKolibriChar;
|
||||||
begin
|
begin
|
||||||
P := PKolibriChar(@Result[1]);
|
P := PKolibriChar(@Result[1]);
|
||||||
GetS(P, High(Byte));
|
ConsoleInterface.GetS(P, High(Byte));
|
||||||
Limit := P + High(Byte);
|
Limit := P + High(Byte);
|
||||||
while (P < Limit) and not (P^ in [#0, #10]) do
|
while (P < Limit) and not (P^ in [#0, #10]) do
|
||||||
Inc(P);
|
Inc(P);
|
||||||
@@ -341,17 +337,17 @@ end;
|
|||||||
|
|
||||||
function KeyPressed: Boolean;
|
function KeyPressed: Boolean;
|
||||||
begin
|
begin
|
||||||
Result := KeyPressedFunc;
|
Result := ConsoleInterface.KeyPressed;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ReadKey: KolibriChar;
|
function ReadKey: KolibriChar;
|
||||||
begin
|
begin
|
||||||
Result := ReadKeyFunc;
|
Result := ConsoleInterface.ReadKey;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FontHeight: Integer;
|
function FontHeight: Integer;
|
||||||
begin
|
begin
|
||||||
Result := GetFontHeight;
|
Result := ConsoleInterface.GetFontHeight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Delay(Milliseconds: LongWord);
|
procedure Delay(Milliseconds: LongWord);
|
||||||
|
@@ -124,6 +124,27 @@ type
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
PConsoleInterface = ^TConsoleInterface;
|
||||||
|
TConsoleInterface = record
|
||||||
|
ClrScr: procedure; stdcall;
|
||||||
|
GetCh: function: Integer; stdcall;
|
||||||
|
GetCh2: function: Word; stdcall;
|
||||||
|
GetS: function(Str: PKolibriChar; Length: Integer): PKolibriChar; stdcall;
|
||||||
|
GetCursorHeight: function: Integer; stdcall;
|
||||||
|
GetFlags: function: LongWord; stdcall;
|
||||||
|
GetFontHeight: function: Integer; stdcall;
|
||||||
|
GotoXY: procedure(X, Y: Integer); stdcall;
|
||||||
|
KeyPressed: function: Boolean; stdcall;
|
||||||
|
PrintF: function(Str: PKolibriChar): Integer; cdecl varargs;
|
||||||
|
ReadKey: function: KolibriChar; stdcall;
|
||||||
|
SetFlags: function(Flags: LongWord): LongWord; stdcall;
|
||||||
|
SetCursorHeight: function(Height: Integer): Integer; stdcall;
|
||||||
|
SetTitle: procedure(Title: PKolibriChar); stdcall;
|
||||||
|
WhereXY: procedure(var X, Y: Integer); stdcall;
|
||||||
|
WritePChar: procedure(Str: PKolibriChar); stdcall;
|
||||||
|
WritePCharLen: procedure(Str: PKolibriChar; Length: LongWord); stdcall;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure _Halt0;
|
procedure _Halt0;
|
||||||
procedure _HandleFinally;
|
procedure _HandleFinally;
|
||||||
procedure _StartExe(InitTable: PPackageInfo);
|
procedure _StartExe(InitTable: PPackageInfo);
|
||||||
|
Reference in New Issue
Block a user