CRT unit with colored console example added

This commit is contained in:
2020-06-07 18:33:22 +03:00
parent ec5f97eecf
commit 69fbd69abc
13 changed files with 381 additions and 128 deletions

View File

@@ -0,0 +1,34 @@
program DateTime;
uses
KolibriOS, CRT;
var
SystemDate: TSystemDate;
SystemTime: TSystemTime;
CursorPos: TConsolePoint;
begin
ConsoleInit('Date/Time');
SetCursorHeight(0);
SetCursorPos(27, 11);
Write(
'System Date and System Time'#10 +
' '
);
CursorPos := GetCursorPos;
repeat
SystemDate := GetSystemDate;
SystemTime := GetSystemTime;
with SystemDate, SystemTime do
begin
Write('%02x.%02x.%02x', Day, Month, Year);
Write(' - %02x:%02x:%02x', Hours, Minutes, Seconds);
end;
SetCursorPos(CursorPos);
Sleep(50);
until KeyPressed;
ConsoleExit(True);
end.

View File

@@ -0,0 +1,80 @@
program ConsoleColors;
uses
CRT;
begin
ConsoleInit('Console Colors');
TextBackground(Black);
WriteLn('Black');
TextBackground(Blue);
WriteLn('Blue');
TextBackground(Green);
WriteLn('Green');
TextBackground(Cyan);
WriteLn('Cyan');
TextBackground(Red);
WriteLn('Red');
TextBackground(Magenta);
WriteLn('Magenta');
TextBackground(Brown);
WriteLn('Brown');
TextBackground(LightGray);
WriteLn('LightGray');
TextBackground(DarkGray);
WriteLn('DarkGray');
TextBackground(LightBlue);
WriteLn('LightBlue');
TextBackground(LightGreen);
WriteLn('LightGreen');
TextBackground(LightCyan);
WriteLn('LightCyan');
TextBackground(LightRed);
WriteLn('LightRed');
TextBackground(LightMagenta);
WriteLn('LightMagenta');
TextBackground(Yellow);
WriteLn('Yellow');
TextBackground(White);
WriteLn('White');
ResetAttributes;
TextColor(Black);
WriteLn('Black');
TextColor(Blue);
WriteLn('Blue');
TextColor(Green);
WriteLn('Green');
TextColor(Cyan);
WriteLn('Cyan');
TextColor(Red);
WriteLn('Red');
TextColor(Magenta);
WriteLn('Magenta');
TextColor(Brown);
WriteLn('Brown');
TextColor(LightGray);
WriteLn('LightGray');
TextColor(DarkGray);
WriteLn('DarkGray');
TextColor(LightBlue);
WriteLn('LightBlue');
TextColor(LightGreen);
WriteLn('LightGreen');
TextColor(LightCyan);
WriteLn('LightCyan');
TextColor(LightRed);
WriteLn('LightRed');
TextColor(LightMagenta);
WriteLn('LightMagenta');
TextColor(Yellow);
WriteLn('Yellow');
TextColor(White);
WriteLn('White');
ReadKey;
ConsoleExit(True);
end.

View File

@@ -0,0 +1 @@
@call "%~dp0..\..\Lib\build.bat" "%~dp0ConsoleColors"

View File

@@ -1,53 +1,34 @@
program DateTime;
uses
KolibriOS;
KolibriOS, CRT;
var
hConsole: Pointer;
ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Caption: PKolibriChar); stdcall;
ConsoleExit: procedure(bCloseWindow: Cardinal); stdcall;
Printf: function(const Format: PKolibriChar): Integer; cdecl varargs;
GetConsoleCursorPos: procedure(X, Y: PInteger); stdcall;
SetConsoleCursorPos: procedure(X, Y: Integer); stdcall;
kbhit: function: Boolean;
SetConsoleCursorHeight: function(Height: Integer): Integer; stdcall;
// ConsoleCls: procedure;
SystemDate: TSystemDate;
SystemTime: TSystemTime;
X, Y: Integer;
CursorPos: TConsolePoint;
begin
hConsole := LoadLibrary('/sys/lib/console.obj');
ConsoleInit := GetProcAddress(hConsole, 'con_init');
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
GetConsoleCursorPos := GetProcAddress(hConsole, 'con_get_cursor_pos');
SetConsoleCursorPos := GetProcAddress(hConsole, 'con_set_cursor_pos');
SetConsoleCursorHeight := GetProcAddress(hConsole, 'con_set_cursor_height');
Printf := GetProcAddress(hConsole, 'con_printf');
KBHit := GetProcAddress(hConsole, 'con_kbhit');
ConsoleInit('Date/Time');
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'Date/Time');
SetConsoleCursorHeight(0);
SetConsoleCursorPos(27, 11);
Printf(
'SystemDate and SystemTime'#10 +
' '
SetCursorHeight(0);
SetCursorPos(27, 11);
Write(
'System Date and System Time'#10 +
' '
);
GetConsoleCursorPos(@X, @Y);
CursorPos := GetCursorPos;
repeat
SystemDate := GetSystemDate;
SystemTime := GetSystemTime;
with SystemDate, SystemTime do
begin
Printf('%02x.%02x.%02x', Day, Month, Year);
Printf(' - %02x:%02x:%02x', Hours, Minutes, Seconds);
Write('%02x.%02x.%02x', Day, Month, Year);
Write(' - %02x:%02x:%02x', Hours, Minutes, Seconds);
end;
SetConsoleCursorPos(X, Y);
SetCursorPos(CursorPos);
Sleep(50);
until KBHit;
until Escape;
ConsoleExit(1);
ConsoleExit(True);
end.

View File

@@ -9,8 +9,8 @@ MAKE = $(ROOT)\bin\make.exe -$(MAKEFLAGS) -f$**
DCC = $(ROOT)\bin\dcc32.exe $**
BRCC = $(ROOT)\bin\brcc32.exe $**
#------------------------------------------------------------------------------
PROJECTS = ColorButtons.exe DateTime.exe DrawImage.exe DrawImageEx.exe DrawText.exe GetCurrentDirectory.exe GetPixel.exe \
GetPointOwner.exe Hello.exe LoadFile.exe ReadFolder.exe Screenshot.exe SetCursor.exe SetPixel.exe SetWindowPos.exe
PROJECTS = ColorButtons.exe ConsoleColors.exe DateTime.exe DrawImage.exe DrawImageEx.exe DrawText.exe GetCurrentDirectory.exe \
GetPixel.exe GetPointOwner.exe Hello.exe HelloGUI.exe LoadFile.exe ReadFolder.exe Screenshot.exe SetCursor.exe SetPixel.exe SetWindowPos.exe
#------------------------------------------------------------------------------
default: $(PROJECTS)
#------------------------------------------------------------------------------
@@ -18,6 +18,9 @@ default: $(PROJECTS)
ColorButtons.exe: ColorButtons\ColorButtons.dpr
$(DCC)
ConsoleColors.exe: ConsoleColors\ConsoleColors.dpr
$(DCC)
DateTime.exe: DateTime\DateTime.dpr
$(DCC)
@@ -42,6 +45,9 @@ GetPointOwner.exe: GetPointOwner\GetPointOwner.dpr
Hello.exe: Hello\Hello.dpr
$(DCC)
HelloGUI.exe: Hello\HelloGUI.dpr
$(DCC)
LoadFile.exe: LoadFile\LoadFile.dpr
$(DCC)
@@ -58,6 +64,4 @@ SetPixel.exe: SetPixel\SetPixel.dpr
$(DCC)
SetWindowPos.exe: SetWindowPos\SetWindowPos.dpr
$(DCC)
$(DCC)

View File

@@ -1,7 +1,7 @@
program GetCurrentDir;
uses
KolibriOS;
KolibriOS, CRT;
const
AppPath = PPKolibriChar(32);
@@ -10,26 +10,16 @@ const
BUFFER_SIZE = 256;
var
hConsole: Pointer;
ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Caption: PKolibriChar); stdcall;
ConsoleExit: procedure(bCloseWindow: Cardinal); stdcall;
printf: function(const Format: PKolibriChar): Integer; CDecl varargs;
Buffer: array[0..BUFFER_SIZE - 1] of Char;
begin
hConsole := LoadLibrary('/sys/lib/console.obj');
ConsoleInit := GetProcAddress(hConsole, 'con_init');
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
printf := GetProcAddress(hConsole, 'con_printf');
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'Get Current Directory');
ConsoleInit('Get Current Directory');
GetCurrentDirectory(Buffer, BUFFER_SIZE);
printf('AppPath is "%s"'#10, AppPath^);
printf('CmdLine is "%s"'#10, CmdLine^);
printf('CurrentDirectory is "%s"'#10, Buffer);
Write('AppPath is "%s"'#10, AppPath^);
Write('CmdLine is "%s"'#10, CmdLine^);
Write('Current Directory is "%s"'#10, Buffer);
ConsoleExit(0);
ConsoleExit(False);
end.

View File

@@ -1,33 +1,13 @@
program Hello;
uses
KolibriOS;
var
WndLeft, WndTop, WndWidth, WndHeight: Integer;
CRT;
begin
with GetScreenSize do
begin
WndWidth := Width div 4;
WndHeight := Height div 4;
WndLeft := (Width - WndWidth) div 2;
WndTop := (Height - WndHeight) div 2;
end;
ConsoleInit('Hello');
while True do
case WaitEvent of
REDRAW_EVENT:
begin
BeginDraw;
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Hello!', $00FFFFFF,
WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
EndDraw;
end;
KEY_EVENT:
GetKey;
BUTTON_EVENT:
if GetButton.ID = 1 then
TerminateThread;
end;
WriteLn('Hello, world!');
ReadKey;
ConsoleExit(True);
end.

View File

@@ -0,0 +1,33 @@
program HelloGUI;
uses
KolibriOS;
var
WndLeft, WndTop, WndWidth, WndHeight: Integer;
begin
with GetScreenSize do
begin
WndWidth := Width div 4;
WndHeight := Height div 4;
WndLeft := (Width - WndWidth) div 2;
WndTop := (Height - WndHeight) div 2;
end;
while True do
case WaitEvent of
REDRAW_EVENT:
begin
BeginDraw;
DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Hello!', $00FFFFFF,
WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE);
EndDraw;
end;
KEY_EVENT:
GetKey;
BUTTON_EVENT:
if GetButton.ID = 1 then
TerminateThread;
end;
end.

View File

@@ -1 +1,3 @@
@call "%~dp0..\..\Lib\build.bat" "%~dp0Hello"
@echo off
call "%~dp0..\..\Lib\build.bat" "%~dp0Hello"
call "%~dp0..\..\Lib\build.bat" "%~dp0HelloGUI"

View File

@@ -1,27 +1,17 @@
program LoadFileApp;
uses
KolibriOS;
KolibriOS, CRT;
var
hConsole: Pointer;
ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Caption: PKolibriChar); stdcall;
ConsoleExit: procedure(bCloseWindow: Cardinal); stdcall;
WriteN: procedure(Str: PKolibriChar; Count: LongWord); stdcall;
FileSize: LongWord;
Buffer: Pointer;
begin
hConsole := LoadLibrary('/sys/lib/console.obj');
ConsoleInit := GetProcAddress(hConsole, 'con_init');
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
WriteN := GetProcAddress(hConsole, 'con_write_string');
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'Load File');
ConsoleInit('Load File');
Buffer := LoadFile('/sys/example.asm', FileSize);
WriteN(Buffer, FileSize);
WriteText(Buffer, FileSize);
ConsoleExit(0);
ConsoleExit(False);
end.

View File

@@ -1,19 +1,13 @@
program ReadFolderApp;
uses
KolibriOS;
KolibriOS, CRT;
type
TInt64Rec = packed record
Lo, Hi: LongWord;
end;
var
hConsole: Pointer;
ConsoleInit: procedure(WndWidth, WndHeight, ScrWidth, ScrHeight: LongWord; Caption: PKolibriChar); stdcall;
ConsoleExit: procedure(bCloseWindow: Cardinal); stdcall;
printf: function(const Format: PKolibriChar): Integer; cdecl varargs;
const
FolderPath = '/sys';
@@ -23,46 +17,42 @@ var
Pos: LongWord;
begin
hConsole := LoadLibrary('/sys/lib/console.obj');
ConsoleInit := GetProcAddress(hConsole, 'con_init');
ConsoleExit := GetProcAddress(hConsole, 'con_exit');
printf := GetProcAddress(hConsole, 'con_printf');
ConsoleInit('Read Folder');
if ReadFolder(FolderPath, FolderInformation, 0, 0, 0, BlocksRead) = 0 then
with FolderInformation do
begin
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, {11 printf In Loop}11 * FileCount + {2 printf below}2 + 1, 'ReadFolder');
printf('Folder "%s" contains %u files and/or folders.'#10, FolderPath, FileCount);
printf(#10);
end
Write('Folder "%s" contains %u files and/or folders.'#10#10, FolderPath, FileCount)
else
begin
ConsoleInit($FFFFFFFF, $FFFFFFFF, $FFFFFFFF, $FFFFFFFF, 'Read Folder');
printf('Folder "%s" can not be read.'#10, FolderPath);
end;
Write('Folder "%s" can not be read.'#10, FolderPath);
Pos := 0;
while ReadFolder(FolderPath, FolderInformation, 1, Pos, 0, BlocksRead) = 0 do
begin
with FolderInformation, FileInformation[0] do
begin
printf('FileName = %s'#10, Name);
Write('FileName = %s'#10, Name);
with Attributes do
begin
printf('SizeLo = %u'#10, TInt64Rec(Size).Lo);
printf('SizeHi = %u'#10, TInt64Rec(Size).Hi);
with Modify.Date do printf('modifyDate = %02d.%02d.%02d'#10, Day, Month, Year);
with Modify.Time do printf('modifyTime = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
with Access.Date do printf('AccessDate = %02d.%02d.%02d'#10, Day, Month, Year);
with Access.Time do printf('AccessTime = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
with Creation.Date do printf('CreationDate = %02d.%02d.%02d'#10, Day, Month, Year);
with Creation.Time do printf('CreationTime = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
printf('Attributes = 0x%08x'#10, Attributes);
Write( 'SizeLo = %u'#10, TInt64Rec(Size).Lo);
Write( 'SizeHi = %u'#10, TInt64Rec(Size).Hi);
with Modify.Date do
Write('Modify Date = %02d.%02d.%02d'#10, Day, Month, Year);
with Modify.Time do
Write('Modify Time = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
with Access.Date do
Write('Access Date = %02d.%02d.%02d'#10, Day, Month, Year);
with Access.Time do
Write('Access Time = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
with Creation.Date do
Write('Creation Date = %02d.%02d.%02d'#10, Day, Month, Year);
with Creation.Time do
Write('Creation Time = %02d:%02d:%02d'#10, Hours, Minutes, Seconds);
Write( 'Attributes = 0x%08x'#10, Attributes);
end;
end;
printf(#10);
Write(#10);
Inc(Pos);
end;
ConsoleExit(0);
ConsoleExit(False);
end.