mirror of
https://github.com/red-prig/fpPS4.git
synced 2025-02-19 22:01:00 +00:00
sys crt extended
This commit is contained in:
parent
f2d4f52331
commit
0e78854da2
@ -393,7 +393,7 @@ begin
|
||||
end else
|
||||
if (Info^.sBind<>STB_WEAK) then
|
||||
begin
|
||||
Writeln(StdErr,'Warn^:',Info^.lib^.strName,':',ps4libdoc.GetFunctName(Info^.Nid),':',HexStr(Info^.Nid,16));
|
||||
Writeln(StdWrn,'[Warn]:',Info^.lib^.strName,':',ps4libdoc.GetFunctName(Info^.Nid),':',HexStr(Info^.Nid,16));
|
||||
end;
|
||||
|
||||
end;
|
||||
@ -423,7 +423,7 @@ begin
|
||||
|
||||
if (Result=nil) then
|
||||
begin
|
||||
Writeln(StdErr,'Warn^:',Info^.lib^.strName,':',ps4libdoc.GetFunctName(Info^.Nid),':',HexStr(Info^.Nid,16));
|
||||
Writeln(StdWrn,'[Warn]:',Info^.lib^.strName,':',ps4libdoc.GetFunctName(Info^.Nid),':',HexStr(Info^.Nid,16));
|
||||
Exit(nil); //Don't reload!
|
||||
end;
|
||||
|
||||
@ -477,7 +477,7 @@ begin
|
||||
|
||||
if not cpu.AVX2Support then
|
||||
begin
|
||||
Writeln('AVX2 not supported!');
|
||||
Writeln(StdErr,'AVX2 not support!');
|
||||
Assert(false,'AVX2 not supported!');
|
||||
Exit;
|
||||
end;
|
||||
|
@ -8,6 +8,7 @@ uses
|
||||
Windows,
|
||||
RWLock,
|
||||
sys_types,
|
||||
sys_crt,
|
||||
mmap,
|
||||
mm_adr_direct,
|
||||
mm_adr_virtual,
|
||||
@ -718,7 +719,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelAllocateDirectMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelAllocateDirectMemory:',Result);
|
||||
end;
|
||||
_set_errno(Result);
|
||||
|
||||
@ -739,7 +740,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelAllocateMainDirectMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelAllocateMainDirectMemory:',Result);
|
||||
end;
|
||||
_set_errno(Result);
|
||||
|
||||
@ -762,7 +763,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelAvailableDirectMemorySize:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelAvailableDirectMemorySize:',Result);
|
||||
end;
|
||||
_set_errno(Result);
|
||||
|
||||
@ -783,7 +784,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelDirectMemoryQuery:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelDirectMemoryQuery:',Result);
|
||||
end;
|
||||
_set_errno(Result);
|
||||
|
||||
@ -805,7 +806,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelGetDirectMemoryType:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelGetDirectMemoryType:',Result);
|
||||
end;
|
||||
_set_errno(Result);
|
||||
|
||||
@ -819,7 +820,7 @@ begin
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Result:=_sceKernelCheckedReleaseDirectMemory(start,len);
|
||||
Writeln(StdErr,'[WARN]:sceKernelCheckedReleaseDirectMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelCheckedReleaseDirectMemory:',Result);
|
||||
end;
|
||||
_set_errno(Result);
|
||||
|
||||
@ -832,7 +833,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelReleaseDirectMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelReleaseDirectMemory:',Result);
|
||||
end;
|
||||
_set_errno(Result);
|
||||
|
||||
@ -1142,7 +1143,7 @@ begin
|
||||
Exit(SCE_KERNEL_ERROR_EINVAL);
|
||||
end;
|
||||
flags:=flags and $ffffffef;
|
||||
Writeln('[WARNING] map(addr=0, flags=MAP_FIXED)');
|
||||
Writeln(StdWrn,'[WARNING] map(addr=0, flags=MAP_FIXED)');
|
||||
end;
|
||||
|
||||
if (((flags and MAP_FIXED)=0) and (addr=nil)) then
|
||||
@ -1394,7 +1395,7 @@ begin
|
||||
Result:=addr;
|
||||
end else
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:mmap:',err);
|
||||
Writeln(StdWrn,'[WARN]:mmap:',err);
|
||||
Result:=MAP_FAILED;
|
||||
end;
|
||||
end;
|
||||
@ -1419,7 +1420,7 @@ begin
|
||||
res^:=addr;
|
||||
end else
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMmap:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMmap:',Result);
|
||||
end;
|
||||
|
||||
Result:=px2sce(Result);
|
||||
@ -1432,7 +1433,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:munmap:',Result);
|
||||
Writeln(StdWrn,'[WARN]:munmap:',Result);
|
||||
end;
|
||||
|
||||
Result:=_set_errno(Result);
|
||||
@ -1445,7 +1446,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMunmap:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMunmap:',Result);
|
||||
end;
|
||||
|
||||
Result:=px2sce(Result);
|
||||
@ -1458,7 +1459,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelReleaseFlexibleMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelReleaseFlexibleMemory:',Result);
|
||||
end;
|
||||
|
||||
Result:=px2sce(Result);
|
||||
@ -1473,7 +1474,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:mprotect:',Result);
|
||||
Writeln(StdWrn,'[WARN]:mprotect:',Result);
|
||||
end;
|
||||
|
||||
Result:=_set_errno(Result);
|
||||
@ -1488,7 +1489,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMprotect:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMprotect:',Result);
|
||||
end;
|
||||
|
||||
Result:=px2sce(Result);
|
||||
@ -1503,7 +1504,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMtypeprotect:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMtypeprotect:',Result);
|
||||
end;
|
||||
|
||||
Result:=px2sce(Result);
|
||||
@ -1518,7 +1519,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelQueryMemoryProtection:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelQueryMemoryProtection:',Result);
|
||||
end;
|
||||
|
||||
Result:=px2sce(Result);
|
||||
@ -1534,7 +1535,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelVirtualQuery:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelVirtualQuery:',Result);
|
||||
end;
|
||||
|
||||
Result:=px2sce(Result);
|
||||
@ -1547,7 +1548,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelSetVirtualRangeName:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelSetVirtualRangeName:',Result);
|
||||
end;
|
||||
|
||||
Result:=px2sce(Result);
|
||||
@ -1562,7 +1563,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMapFlexibleMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMapFlexibleMemory:',Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1580,7 +1581,7 @@ begin
|
||||
end else
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMapNamedFlexibleMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMapNamedFlexibleMemory:',Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1594,7 +1595,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMapNamedSystemFlexibleMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMapNamedSystemFlexibleMemory:',Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1608,7 +1609,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelReserveVirtualRange:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelReserveVirtualRange:',Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1628,7 +1629,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMapDirectMemory2:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMapDirectMemory2:',Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1648,7 +1649,7 @@ begin
|
||||
|
||||
if (Result<>0) then
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMapDirectMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMapDirectMemory:',Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -1672,7 +1673,7 @@ begin
|
||||
_sys_mname(virtualAddrDest^,length,name);
|
||||
end else
|
||||
begin
|
||||
Writeln(StdErr,'[WARN]:sceKernelMapNamedDirectMemory:',Result);
|
||||
Writeln(StdWrn,'[WARN]:sceKernelMapNamedDirectMemory:',Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -11,6 +11,7 @@ uses
|
||||
RWLock,
|
||||
hamt,
|
||||
sys_types,
|
||||
sys_crt,
|
||||
sys_kernel,
|
||||
ps4_handles;
|
||||
|
||||
@ -726,7 +727,7 @@ begin
|
||||
|
||||
if (PP^<>Pointer(node)) then
|
||||
begin
|
||||
Writeln(StdErr,'Warn, ',node.pFileName,' file is registred');
|
||||
Writeln(StdWrn,'[Warn]:',node.pFileName,' file is registred');
|
||||
Result:=False;
|
||||
end;
|
||||
|
||||
@ -788,7 +789,7 @@ begin
|
||||
nid:=ps4_nid_hash(strName);
|
||||
PP:=HAMT_insert64(@mods.hamt,nid,Pointer(node));
|
||||
Assert(PP<>nil);
|
||||
if (PP^<>Pointer(node)) then Writeln(StdErr,'Warn, ',strName,' module is registred');
|
||||
if (PP^<>Pointer(node)) then Writeln(StdWrn,'[Warn]:',strName,' module is registred');
|
||||
end;
|
||||
|
||||
Procedure Tps4_program.SetLib(lib:PLIBRARY);
|
||||
@ -802,7 +803,7 @@ begin
|
||||
nid:=ps4_nid_hash(lib^.strName);
|
||||
PP:=HAMT_insert64(@libs.hamt,nid,Pointer(lib));
|
||||
Assert(PP<>nil);
|
||||
if (PP^<>Pointer(lib)) then Writeln(StdErr,'Warn, ',lib^.strName,' lib is registred');
|
||||
if (PP^<>Pointer(lib)) then Writeln(StdWrn,'[Warn]:',lib^.strName,' lib is registred');
|
||||
end;
|
||||
|
||||
function Tps4_program.GetLib(const strName:RawByteString):PLIBRARY;
|
||||
@ -891,7 +892,7 @@ begin
|
||||
pre_load.LockWr;
|
||||
if not pre_load._set_proc(nid,Pointer(cb)) then
|
||||
begin
|
||||
Writeln(StdErr,'Warn, ',strName,' is registred')
|
||||
Writeln(StdWrn,'[Warn]:',strName,' is registred')
|
||||
end;
|
||||
pre_load.Unlock;
|
||||
end;
|
||||
@ -905,7 +906,7 @@ begin
|
||||
fin_load.LockWr;
|
||||
if not fin_load._set_proc(nid,Pointer(cb)) then
|
||||
begin
|
||||
Writeln(StdErr,'Warn, ',strName,' is registred')
|
||||
Writeln(StdWrn,'[Warn]:',strName,' is registred')
|
||||
end;
|
||||
fin_load.Unlock;
|
||||
end;
|
||||
@ -1079,7 +1080,7 @@ begin
|
||||
node:=Loader(S);
|
||||
if (node=nil) then
|
||||
begin
|
||||
Writeln(StdErr,'Warn, file ',S,' not loaded!');
|
||||
Writeln(StdWrn,'[Warn]:',' file ',S,' not loaded!');
|
||||
end else
|
||||
begin
|
||||
PopupFile(node);
|
||||
|
@ -6,6 +6,7 @@ interface
|
||||
|
||||
uses
|
||||
ps4libdoc,
|
||||
sys_crt,
|
||||
ps4_map_mm,
|
||||
ps4_pthread,
|
||||
ps4_time,
|
||||
@ -212,12 +213,12 @@ begin
|
||||
lib:=ps4_app.GetLib('libc');
|
||||
if (lib<>nil) then
|
||||
begin
|
||||
Writeln(StdErr,'Redirected:',HexStr(Nid,16),':',ps4libdoc.GetFunctName(Nid));
|
||||
Writeln(StdWrn,'Redirected:',HexStr(Nid,16),':',ps4libdoc.GetFunctName(Nid));
|
||||
Result:=lib^.get_proc(Nid);
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
Writeln(StdErr,'Operator:',HexStr(Nid,16),':',ps4libdoc.GetFunctName(Nid));
|
||||
Writeln(StdWrn,'Operator:',HexStr(Nid,16),':',ps4libdoc.GetFunctName(Nid));
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -15,6 +15,7 @@ uses
|
||||
ps4_program,
|
||||
spinlock,
|
||||
sys_types,
|
||||
sys_crt,
|
||||
sys_signal,
|
||||
sys_path,
|
||||
sys_time,
|
||||
@ -356,7 +357,7 @@ begin
|
||||
if (data=nil) then Exit;
|
||||
player:=data;
|
||||
handle:=player^.handle;
|
||||
Writeln('WARNING: Leftover AvPlayer handle, let me clean it up: ', handle);
|
||||
Writeln(StdWrn,'WARNING: Leftover AvPlayer handle, let me clean it up: ', handle);
|
||||
FreeMem(player);
|
||||
end;
|
||||
|
||||
@ -630,7 +631,7 @@ begin
|
||||
end;
|
||||
//
|
||||
if frame^.format<>Integer(AV_SAMPLE_FMT_FLTP) then
|
||||
Writeln('ERROR: Unknown audio format: ',frame^.format);
|
||||
Writeln(StdErr,'ERROR: Unknown audio format: ',frame^.format);
|
||||
lastAudioTimeStamp:=av_rescale_q(frame^.best_effort_timestamp,formatContext^.streams[audioStreamId]^.time_base,AV_TIME_BASE_Q);
|
||||
channelCount:=frame^.channels;
|
||||
sampleCount:=frame^.nb_samples;
|
||||
@ -676,7 +677,7 @@ begin
|
||||
end;
|
||||
//
|
||||
if frame^.format<>Integer(AV_PIX_FMT_YUV420P) then
|
||||
Writeln('ERROR: Unknown video format: ',frame^.format);
|
||||
Writeln(StdErr,'ERROR: Unknown video format: ',frame^.format);
|
||||
lastVideoTimeStamp:=av_rescale_q(frame^.best_effort_timestamp,formatContext^.streams[videoStreamId]^.time_base,AV_TIME_BASE_Q);
|
||||
Result.nSize:=videoCodecContext^.width*videoCodecContext^.height*3 div 2;
|
||||
GetMem(Result.pAddr,Result.nSize);
|
||||
@ -764,7 +765,7 @@ begin
|
||||
|
||||
if not _test_mem_alloc(pInit^.memoryReplacement) then
|
||||
begin
|
||||
Writeln(SysLogPrefix,'ERROR: All allocators are required for AVPlayer Initialisation.');
|
||||
Writeln(StdErr,SysLogPrefix,'ERROR: All allocators are required for AVPlayer Initialisation.');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
@ -800,7 +801,7 @@ begin
|
||||
|
||||
if not _test_mem_alloc(pInit^.memoryReplacement) then
|
||||
begin
|
||||
Writeln(SysLogPrefix,'ERROR: All allocators are required for AVPlayer Initialisation.');
|
||||
Writeln(StdErr,SysLogPrefix,'ERROR: All allocators are required for AVPlayer Initialisation.');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
@ -944,7 +945,7 @@ begin
|
||||
if sourceDetails^.sourceType=1 then
|
||||
Writeln('Source type: MP4')
|
||||
else
|
||||
Writeln('ERROR: Source type: Unknown ',sourceDetails^.sourceType);
|
||||
Writeln(StdErr,'ERROR: Source type: Unknown ',sourceDetails^.sourceType);
|
||||
Result:=_sceAvPlayerAddSource(handle,sourceDetails^.uri.name)
|
||||
end else
|
||||
begin
|
||||
|
208
sys/sys_crt.pas
208
sys/sys_crt.pas
@ -6,10 +6,13 @@ interface
|
||||
|
||||
uses
|
||||
windows,
|
||||
sys_pthread,
|
||||
spinlock;
|
||||
sys_pthread;
|
||||
|
||||
var
|
||||
StdWrn:Text;
|
||||
|
||||
Procedure sys_crt_init;
|
||||
Procedure CrtOutWriteDirect(T:PText;data:Pointer;len:SizeInt);
|
||||
|
||||
implementation
|
||||
|
||||
@ -23,6 +26,7 @@ var
|
||||
|
||||
const
|
||||
StdErrColor=FOREGROUND_RED;
|
||||
StdWrnColor=14;
|
||||
|
||||
function GetConsoleTextAttribute(hConsoleOutput:HANDLE;var wAttributes:WORD):WINBOOL;
|
||||
var
|
||||
@ -46,82 +50,47 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
Procedure _CrtOutWrite(var t:TextRec;data:Pointer;len:SizeInt);
|
||||
var
|
||||
n:DWORD;
|
||||
Begin
|
||||
if (data=nil) or (len=0) then exit;
|
||||
n:=0;
|
||||
|
||||
_sig_lock(SL_NOINTRRUP);
|
||||
EnterCriticalSection(StdOutLock);
|
||||
|
||||
if Boolean(t.UserData[2]) then //IsChar
|
||||
begin
|
||||
SetConsoleTextAttribute(t.Handle,t.UserData[1]);
|
||||
WriteConsole(t.Handle,
|
||||
data,
|
||||
len,
|
||||
@n,
|
||||
nil);
|
||||
end else
|
||||
begin
|
||||
WriteFile(t.Handle,
|
||||
data^,
|
||||
len,
|
||||
n,
|
||||
nil);
|
||||
end;
|
||||
|
||||
LeaveCriticalSection(StdOutLock);
|
||||
_sig_unlock(SL_NOINTRRUP);
|
||||
end;
|
||||
|
||||
Procedure CrtOutWrite(var t:TextRec);
|
||||
var
|
||||
n:DWORD;
|
||||
Begin
|
||||
if (t.BufPos=0) then exit;
|
||||
n:=0;
|
||||
|
||||
_sig_lock(SL_NOINTRRUP);
|
||||
EnterCriticalSection(StdOutLock);
|
||||
|
||||
WriteConsole(t.Handle,
|
||||
t.Bufptr,
|
||||
t.BufPos,
|
||||
@n,
|
||||
nil);
|
||||
|
||||
LeaveCriticalSection(StdOutLock);
|
||||
_sig_unlock(SL_NOINTRRUP);
|
||||
|
||||
_CrtOutWrite(t,t.Bufptr,t.BufPos);
|
||||
t.BufPos:=0;
|
||||
end;
|
||||
|
||||
Procedure CrtErrWrite(var t:TextRec);
|
||||
var
|
||||
n:DWORD;
|
||||
dwCursorPosition:COORD;
|
||||
Begin
|
||||
if (t.BufPos=0) then exit;
|
||||
n:=0;
|
||||
|
||||
_sig_lock(SL_NOINTRRUP);
|
||||
EnterCriticalSection(StdOutLock);
|
||||
|
||||
dwCursorPosition:=Default(COORD);
|
||||
|
||||
GetConsoleCursorPosition(t.Handle,
|
||||
dwCursorPosition);
|
||||
|
||||
WriteConsole(t.Handle,
|
||||
t.Bufptr,
|
||||
t.BufPos,
|
||||
@n,
|
||||
nil);
|
||||
|
||||
FillConsoleOutputAttribute(t.Handle,
|
||||
StdErrColor,
|
||||
t.BufPos,
|
||||
dwCursorPosition,
|
||||
n);
|
||||
|
||||
LeaveCriticalSection(StdOutLock);
|
||||
_sig_unlock(SL_NOINTRRUP);
|
||||
|
||||
t.BufPos:=0;
|
||||
end;
|
||||
|
||||
Procedure CrtFileWrite(var t:TextRec);
|
||||
var
|
||||
n:DWORD;
|
||||
Begin
|
||||
if (t.BufPos=0) then exit;
|
||||
n:=0;
|
||||
|
||||
_sig_lock(SL_NOINTRRUP);
|
||||
EnterCriticalSection(StdOutLock);
|
||||
|
||||
WriteFile(t.Handle,
|
||||
t.Bufptr^,
|
||||
t.BufPos,
|
||||
n,
|
||||
nil);
|
||||
|
||||
LeaveCriticalSection(StdOutLock);
|
||||
_sig_unlock(SL_NOINTRRUP);
|
||||
|
||||
t.BufPos:=0;
|
||||
Procedure CrtOutWriteDirect(T:PText;data:Pointer;len:SizeInt);
|
||||
begin
|
||||
if (T=nil) then Exit;
|
||||
_CrtOutWrite(TextRec(T^),data,len);
|
||||
end;
|
||||
|
||||
Procedure CrtClose(Var F:TextRec);
|
||||
@ -130,68 +99,75 @@ Begin
|
||||
end;
|
||||
|
||||
Procedure CrtOpenOut(Var F:TextRec);
|
||||
var
|
||||
_type:Shortint;
|
||||
IsChar:Boolean;
|
||||
Begin
|
||||
TextRec(F).Handle:=GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
_type:=Shortint(TextRec(F).UserData[2]);
|
||||
|
||||
if (SwGetFileType(TextRec(F).Handle)=FILE_TYPE_CHAR) then
|
||||
begin
|
||||
TextRec(F).InOutFunc:=@CrtOutWrite;
|
||||
TextRec(F).FlushFunc:=@CrtOutWrite;
|
||||
TextRec(F).CloseFunc:=@CrtClose;
|
||||
end else
|
||||
begin
|
||||
TextRec(F).InOutFunc:=@CrtFileWrite;
|
||||
TextRec(F).FlushFunc:=@CrtFileWrite;
|
||||
TextRec(F).CloseFunc:=@CrtClose;
|
||||
end;
|
||||
TextRec(F).Handle:=GetStdHandle(_type);
|
||||
|
||||
IsChar:=SwGetFileType(TextRec(F).Handle)=FILE_TYPE_CHAR;
|
||||
TextRec(F).UserData[2]:=ord(IsChar);
|
||||
|
||||
TextRec(F).InOutFunc:=@CrtOutWrite;
|
||||
TextRec(F).FlushFunc:=@CrtOutWrite;
|
||||
TextRec(F).CloseFunc:=@CrtClose;
|
||||
end;
|
||||
|
||||
Procedure CrtOpenErr(Var F:TextRec);
|
||||
Begin
|
||||
TextRec(F).Handle:=GetStdHandle(STD_ERROR_HANDLE);
|
||||
|
||||
if (SwGetFileType(TextRec(F).Handle)=FILE_TYPE_CHAR) then
|
||||
begin
|
||||
TextRec(F).InOutFunc:=@CrtErrWrite;
|
||||
TextRec(F).FlushFunc:=@CrtErrWrite;
|
||||
TextRec(F).CloseFunc:=@CrtClose;
|
||||
end else
|
||||
begin
|
||||
TextRec(F).InOutFunc:=@CrtFileWrite;
|
||||
TextRec(F).FlushFunc:=@CrtFileWrite;
|
||||
TextRec(F).CloseFunc:=@CrtClose;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure AssignCrt(var F:Text;cb:codepointer);
|
||||
procedure AssignCrt(var F:Text;_type:DWORD;clr:Byte);
|
||||
begin
|
||||
Assign(F,'');
|
||||
TextRec(F).OpenFunc:=cb;
|
||||
TextRec(F).OpenFunc:=@CrtOpenOut;
|
||||
TextRec(F).UserData[1]:=clr;
|
||||
TextRec(F).UserData[2]:=Shortint(Integer(_type));
|
||||
end;
|
||||
|
||||
Procedure sys_crt_init;
|
||||
begin
|
||||
tcb_thread:=nil; //need zero tcb
|
||||
|
||||
AssignCrt(Output,@CrtOpenOut);
|
||||
AssignCrt(Output ,STD_OUTPUT_HANDLE,StdOutColor);
|
||||
AssignCrt(StdOut ,STD_OUTPUT_HANDLE,StdOutColor);
|
||||
AssignCrt(ErrOutput,STD_ERROR_HANDLE ,StdErrColor);
|
||||
AssignCrt(StdErr ,STD_ERROR_HANDLE ,StdErrColor);
|
||||
|
||||
Rewrite(Output);
|
||||
|
||||
AssignCrt(StdOut,@CrtOpenOut);
|
||||
Rewrite(StdOut);
|
||||
|
||||
AssignCrt(ErrOutput,@CrtOpenErr);
|
||||
Rewrite(ErrOutput);
|
||||
|
||||
AssignCrt(StdErr,@CrtOpenErr);
|
||||
Rewrite(StdErr);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
InitCriticalSection(StdOutLock);
|
||||
|
||||
Procedure _sys_crt_init;
|
||||
var
|
||||
F:Thandle;
|
||||
begin
|
||||
StdOutColor:=7;
|
||||
GetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),StdOutColor);
|
||||
F:=GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (SwGetFileType(F)=FILE_TYPE_CHAR) then
|
||||
begin
|
||||
GetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),StdOutColor);
|
||||
end;
|
||||
//
|
||||
AssignCrt(StdWrn,STD_OUTPUT_HANDLE,StdWrnColor);
|
||||
Rewrite(StdWrn);
|
||||
end;
|
||||
|
||||
procedure _sys_crt_fini;
|
||||
var
|
||||
F:Thandle;
|
||||
begin
|
||||
F:=GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (SwGetFileType(F)=FILE_TYPE_CHAR) then
|
||||
begin
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),StdOutColor);
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
AddExitProc(@_sys_crt_fini);
|
||||
InitCriticalSection(StdOutLock);
|
||||
_sys_crt_init
|
||||
|
||||
end.
|
||||
|
||||
|
@ -10,6 +10,7 @@ uses
|
||||
SysUtils,
|
||||
RWLock,
|
||||
sys_kernel,
|
||||
sys_crt,
|
||||
sys_fd;
|
||||
|
||||
procedure _sys_dev_init;
|
||||
@ -278,17 +279,15 @@ begin
|
||||
end;
|
||||
|
||||
function TDevStd.write (data:Pointer;size:Int64):Int64;
|
||||
var
|
||||
S:RawByteString;
|
||||
begin
|
||||
SetString(S,data,size);
|
||||
System.Write(WText^,S);
|
||||
CrtOutWriteDirect(WText,data,size);
|
||||
Result:=size;
|
||||
end;
|
||||
|
||||
function TDevStd.pwrite(data:Pointer;size,offset:Int64):Int64;
|
||||
begin
|
||||
Result:=write(data,size);
|
||||
CrtOutWriteDirect(WText,data,size);
|
||||
Result:=size;
|
||||
end;
|
||||
|
||||
function TDevStd.writev(vector:p_iovec;count:Integer):Int64;
|
||||
|
Loading…
x
Reference in New Issue
Block a user