From be915bb843b7797ee09ade0ac12fdf45bcc03fcc Mon Sep 17 00:00:00 2001 From: Freeman Date: Sun, 10 Jan 2021 03:11:36 +0300 Subject: [PATCH] Debug board support in KoW --- Lib/KoW/KolibriOS.inc | 40 ++++++++++++++++++++++++++++++++++++++++ Lib/KolibriOS.pas | 2 ++ 2 files changed, 42 insertions(+) diff --git a/Lib/KoW/KolibriOS.inc b/Lib/KoW/KolibriOS.inc index 2da621b..9c0421f 100644 --- a/Lib/KoW/KolibriOS.inc +++ b/Lib/KoW/KolibriOS.inc @@ -14,10 +14,50 @@ type szCSDVersion: array[0..127] of KolibriChar; end; +const + BoardLog = 'BOARDLOG.TXT'; + +var + hBoard: THandle; + DebugReadPos: UInt64; + function GetFileSizeEx(hFile: THandle; var FileSize: UInt64): LongBool; stdcall; external kernel32 name 'GetFileSizeEx'; function GetVersionExA(var Info: TOSVersionInfoA): LongBool; stdcall; external kernel32 name 'GetVersionExA'; +function SetFilePointerEx(hFile: THandle; Distance: Int64; NewFilePtr: PUInt64; Method: LongWord): LongBool; stdcall; + external kernel32 name 'SetFilePointerEx'; + +function InitBoard: Boolean; +begin + if hBoard = 0 then + begin + hBoard := CreateFileA(BoardLog, GENERIC_READ or GENERIC_WRITE, + FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_ALWAYS, 0, 0); + Result := hBoard <> INVALID_HANDLE_VALUE; + end + else + Result := True; +end; + +function DebugRead(var Data: KolibriChar): Boolean; stdcall; +var + BytesRead: LongWord; +begin + Result := InitBoard and SetFilePointerEx(hBoard, DebugReadPos, @DebugReadPos, FILE_BEGIN) and + ReadFile(hBoard, Data, SizeOf(Data), BytesRead, nil) and (BytesRead <> 0); + Inc(DebugReadPos, BytesRead); +end; + +procedure DebugWrite(Data: KolibriChar); stdcall; +var + BytesWritten: LongWord; +begin + if not InitBoard or not SetFilePointerEx(hBoard, 0, nil, FILE_END) or + not System.WriteFile(hBoard, Data, SizeOf(Data), BytesWritten, nil) or (BytesWritten = 0) + then + RunError(ERROR_ACCESS_DENIED); +end; procedure ExitThread; stdcall; begin diff --git a/Lib/KolibriOS.pas b/Lib/KolibriOS.pas index 6fd0ea6..f28deb7 100644 --- a/Lib/KolibriOS.pas +++ b/Lib/KolibriOS.pas @@ -543,8 +543,10 @@ const {62.8} function WritePCIByte(Bus, Device, Func, Reg: Byte; Data: Byte): LongWord; stdcall; {62.9} function WritePCIWord(Bus, Device, Func, Reg: Byte; Data: Word): LongWord; stdcall; {62.10} function WritePCILongWord(Bus, Device, Func, Reg: Byte; Data: LongWord): LongWord; stdcall; +{$ENDIF} {63.1} procedure DebugWrite(Data: KolibriChar); stdcall; {63.2} function DebugRead(var Data: KolibriChar): Boolean; stdcall; +{$IFDEF KolibriOS} {64} function ReallocAppMemory(Count: LongWord): LongInt; stdcall; {65} procedure DrawImageEx(const Image; Left, Top: LongInt; Width, Height, BPP: LongWord; Palette: Pointer; Padding: LongWord); stdcall; {66.1} procedure SetKeyboardInputMode(Mode: LongWord); stdcall;