From b52068a7f2b7b55823b3c275dc6965dc0b39ad0a Mon Sep 17 00:00:00 2001 From: Freeman Date: Sun, 27 Dec 2020 01:34:54 +0300 Subject: [PATCH] {$APPTYPE CONSOLE} support added --- .../Console/GetCurrentDir/GetCurrentDir.dpr | 9 +++------ Examples/Console/Hello/Hello.dpr | 3 ++- Examples/GUI/DrawImage/DrawImage.dpr | 7 ++----- Examples/GUI/DrawImageEx/DrawImageEx.dpr | 6 ++---- Examples/GUI/SetCursor/SetCursor.dpr | 6 ++---- Lib/CRT.pas | 3 +++ RTL/System.pas | 17 ++++++++++++----- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Examples/Console/GetCurrentDir/GetCurrentDir.dpr b/Examples/Console/GetCurrentDir/GetCurrentDir.dpr index b781639..09dce1a 100644 --- a/Examples/Console/GetCurrentDir/GetCurrentDir.dpr +++ b/Examples/Console/GetCurrentDir/GetCurrentDir.dpr @@ -3,10 +3,7 @@ program GetCurrentDir; uses KolibriOS, CRT; -const - AppPath = PPKolibriChar(32); - CmdLine = PPKolibriChar(28); - +const BUFFER_SIZE = 256; var @@ -17,7 +14,7 @@ begin GetCurrentDirectory(Buffer, BUFFER_SIZE); - con_printf('AppPath is "%s"'#10, AppPath^); - con_printf('CmdLine is "%s"'#10, CmdLine^); + con_printf('Application Path is "%s"'#10, AppPath); + con_printf('Command Line is "%s"'#10, CmdLine); con_printf('Current Directory is "%s"'#10, Buffer); end. diff --git a/Examples/Console/Hello/Hello.dpr b/Examples/Console/Hello/Hello.dpr index d424d38..b7abb34 100644 --- a/Examples/Console/Hello/Hello.dpr +++ b/Examples/Console/Hello/Hello.dpr @@ -1,9 +1,10 @@ program Hello; +{$APPTYPE CONSOLE} + uses CRT; begin - InitConsole('Hello'); WriteLn('Hello, world!'); end. diff --git a/Examples/GUI/DrawImage/DrawImage.dpr b/Examples/GUI/DrawImage/DrawImage.dpr index 1ae8d13..c69c651 100644 --- a/Examples/GUI/DrawImage/DrawImage.dpr +++ b/Examples/GUI/DrawImage/DrawImage.dpr @@ -3,9 +3,6 @@ program DrawImageApp; uses KolibriOS; -const - AppPath = PPKolibriChar(32); - type THeader = packed record IDLength: Byte; @@ -59,8 +56,8 @@ var begin HeapInit; - ExtractFileDirectory(AppPath^, AppPath^); - SetCurrentDirectory(AppPath^); + ExtractFileDirectory(AppPath, AppPath); + SetCurrentDirectory(AppPath); TargaFile := LoadFile('Lena.tga', FileSize); diff --git a/Examples/GUI/DrawImageEx/DrawImageEx.dpr b/Examples/GUI/DrawImageEx/DrawImageEx.dpr index c16e1ba..9460872 100644 --- a/Examples/GUI/DrawImageEx/DrawImageEx.dpr +++ b/Examples/GUI/DrawImageEx/DrawImageEx.dpr @@ -4,8 +4,6 @@ uses KolibriOS; const - AppPath = PPKolibriChar(32); - Picture1 = 'Flower(4bpp).bmp'; Picture2 = 'Mario(1bpp).bmp'; Picture3 = 'House(24bpp).bmp'; @@ -81,8 +79,8 @@ var begin HeapInit; - ExtractFileDirectory(AppPath^, AppPath^); - SetCurrentDirectory(AppPath^); + ExtractFileDirectory(AppPath, AppPath); + SetCurrentDirectory(AppPath); GetFileAttributes(Picture1, FileAttributes); BitmapFile1 := HeapAllocate(FileAttributes.Size); diff --git a/Examples/GUI/SetCursor/SetCursor.dpr b/Examples/GUI/SetCursor/SetCursor.dpr index 3bb6cd1..3bf3ddd 100644 --- a/Examples/GUI/SetCursor/SetCursor.dpr +++ b/Examples/GUI/SetCursor/SetCursor.dpr @@ -4,8 +4,6 @@ uses KolibriOS; const - AppPath = PPKolibriChar(32); - ARROW_BUTTON = 2; POINT_BUTTON = 3; WAIT_BUTTON = 4; @@ -74,8 +72,8 @@ var begin HeapInit; - ExtractFileDirectory(AppPath^, AppPath^); - SetCurrentDirectory(AppPath^); + ExtractFileDirectory(AppPath, AppPath); + SetCurrentDirectory(AppPath); ArrowBitmapFile := LoadFile('arrow.bmp', FileSize); PointBitmapFile := LoadFile('point.bmp', FileSize); diff --git a/Lib/CRT.pas b/Lib/CRT.pas index 7dd630e..4bb96a4 100644 --- a/Lib/CRT.pas +++ b/Lib/CRT.pas @@ -237,6 +237,9 @@ initialization Pointer(@con_write_asciiz) := GetProcAddress(hConsole, 'con_write_asciiz'); Pointer(@con_write_string) := GetProcAddress(hConsole, 'con_write_string'); + if IsConsole then + InitConsole(AppPath); + finalization if Assigned(con_exit) then con_exit(CloseWindow); diff --git a/RTL/System.pas b/RTL/System.pas index d39d367..2c17b0b 100644 --- a/RTL/System.pas +++ b/RTL/System.pas @@ -161,6 +161,7 @@ function _LStrToPChar(const S: KolibriString): PKolibriChar; var IOResult: Integer; Input, Output: Text; + IsConsole: Boolean; function _Flush(var T: TTextRec): Integer; procedure __IOTest; @@ -184,6 +185,9 @@ procedure _WriteString(var T: TTextRec; const S: ShortString; Width: LongInt); procedure _WriteLString(var T: TTextRec; const S: KolibriString; Width: LongInt); procedure _WriteLn(var T: TTextRec); +var + AppPath, CmdLine: PKolibriChar; + { Console Library API } type @@ -493,10 +497,13 @@ end; initialization -asm // InitFPU - FNINIT - FWAIT - FLDCW Default8087CW -end; + asm // InitFPU + FNINIT + FWAIT + FLDCW Default8087CW + end; + + AppPath := PPKolibriChar(32)^; + CmdLine := PPKolibriChar(28)^; end.