diff --git a/programs/develop/fp/rtl/buildrtl.pp b/programs/develop/fp/rtl/buildrtl.pp index d064562877..d8fc480a74 100644 --- a/programs/develop/fp/rtl/buildrtl.pp +++ b/programs/develop/fp/rtl/buildrtl.pp @@ -6,9 +6,9 @@ uses sysinitpas, {sysinitcyg, sysinitgprof,} ctypes, strings, lineinfo, lnfodwrf, heaptrc, matrix, - {windows, winsock, winsock2, initc, cmem, dynlibs, signals,} + {windows, winsock, winsock2, initc, cmem, }dynlibs, {signals,} dos, crt, objects{, messages, - rtlconsts, sysconst}, sysutils{, math, types, + rtlconsts, sysconst}, sysutils, math{, types, strutils, dateutils, varutils, variants, typinfo, fgl}, classes{, convutils, stdconvs, cpu, mmx, charset, ucomplex, getopts, winevent, sockets, printer, diff --git a/programs/develop/fp/rtl/kos.inc b/programs/develop/fp/rtl/kos.inc index d18b04f71f..83036d21a8 100644 --- a/programs/develop/fp/rtl/kos.inc +++ b/programs/develop/fp/rtl/kos.inc @@ -146,6 +146,28 @@ asm popl %ebx end; +procedure kos_setkeyboardmode(mode: DWord); assembler; register; +asm + pushl %eax + pushl %ebx + movl $66, %ecx + movl $1, %ebx + xchgl %eax, %ecx + int $0x40 + xchgl %eax, %ecx + popl %ebx + popl %eax +end; + +function kos_getkeyboardmode(): DWord; assembler; register; +asm + pushl %ebx + movl $66, %eax + movl $2, %ebx + int $0x40 + popl %ebx +end; + procedure kos_setcaption(caption: PChar); assembler; register; asm pushl %ecx diff --git a/programs/develop/fp/rtl/kosh.inc b/programs/develop/fp/rtl/kosh.inc index 5550b9240d..76a2a1e6b5 100644 --- a/programs/develop/fp/rtl/kosh.inc +++ b/programs/develop/fp/rtl/kosh.inc @@ -23,6 +23,8 @@ function kos_getmousepos(): TKosPoint; function kos_getmousewinpos(): TKosPoint; function kos_getmousebuttons(): DWord; procedure kos_maskevents(mask: DWord); +procedure kos_setkeyboardmode(mode: DWord); +function kos_getkeyboardmode(): DWord; procedure kos_setcaption(caption: PChar); { Graphics } diff --git a/programs/develop/fp/rtl/sysfile.inc b/programs/develop/fp/rtl/sysfile.inc index fdec72cb27..e6dcbc486f 100644 --- a/programs/develop/fp/rtl/sysfile.inc +++ b/programs/develop/fp/rtl/sysfile.inc @@ -1,18 +1,18 @@ -{cp866} +{utf8} function DecodeErrNo(ErrNo: DWord): Word; -{0 = ᯥ譮 - 1 = । / ࠧ ⪮ ᪠ (㭪ﬨ 7, 8 㭪樨 21) - 2 = 㭪 ন 䠩 ⥬ - 3 = ⭠ 䠩 ⥬ - 4 = १ࢨ஢, 頥 ⥪饩 ॠ樨 - 5 = 䠩 - 6 = 䠩 稫 - 7 = 㪠⥫ ਫ - 8 = - 9 = ⠡ FAT ࠧ襭 - 10 = - 11 = 訡 ன⢠} +{0 = успешно + 1 = не определена база и/или раздел жёсткого диска (подфункциями 7, 8 функции 21) + 2 = функция не поддерживается для данной файловой системы + 3 = неизвестная файловая система + 4 = зарезервировано, никогда не возвращается в текущей реализации + 5 = файл не найден + 6 = файл закончился + 7 = указатель вне памяти приложения + 8 = диск заполнен + 9 = таблица FAT разрушена + 10 = доступ запрещён + 11 = ошибка устройства} begin case ErrNo of 0: Result := 0; @@ -24,7 +24,7 @@ begin 6: Result := 0; 8: Result := 101; else - Result := 153; { Unknown command (⭠ ) } + Result := 153; { Unknown command (неизвестная команда) } end; end; @@ -96,6 +96,8 @@ begin InOutRes := 211; end; + +{ FIXME: Поправить RTL, факт отсутствия файла не фиксируется при его открытии. } procedure do_open(var f; p: PChar; flags: Longint); var KosFile: PKosFile; @@ -104,6 +106,7 @@ var RecSize: Longint; CurrDir: array[0..2048] of Char; CurrDirLen: Longint; + Dummy: Longint; begin case flags and 3 of 0: FileRec(f).Mode := fmInput; @@ -111,11 +114,11 @@ begin 2: FileRec(f).Mode := fmInOut; end; - {ନ஢ ᮫⭮ } + {Формирование имени абсолютного пути} FilePathLen := Length(p); if p^ <> DirectorySeparator then begin - {XXX: ࠧ CurrDir } + {XXX: размер буфера CurrDir может оказаться недостаточным} CurrDirLen := kos_getdir(@CurrDir, SizeOf(CurrDir) - FilePathLen - 1) - 1; FilePath := @CurrDir; @@ -129,7 +132,7 @@ begin end else FilePath := p; - { TKosFile} + {Создание структуры TKosFile} RecSize := SizeOf(TKosFile) + FilePathLen; KosFile := GetMem(RecSize); FillChar(KosFile^, RecSize, 0); @@ -138,8 +141,16 @@ begin if flags and $1000 <> 0 then begin - { ᮧ 䠩 } + { создать файл } InOutRes := DecodeErrNo(kos_rewritefile(KosFile, RecSize)); end else - InOutRes := 0; + begin + { попытаться прочитать файл } + KosFile^.Size := 1; + KosFile^.Data := @Dummy; + InOutRes := DecodeErrNo(kos_readfile(KosFile, Dummy)); + end; + + if InOutRes <> 0 then + FreeMem(KosFile); end; diff --git a/programs/develop/fp/rtl/windows.pp b/programs/develop/fp/rtl/windows.pp index d26aa6ac8f..1f3a776220 100644 --- a/programs/develop/fp/rtl/windows.pp +++ b/programs/develop/fp/rtl/windows.pp @@ -1,7 +1,100 @@ unit Windows; +{$mode objfpc} + + interface + +type + WinBool = LongBool; + Bool = WinBool; + Handle = System.THandle; + THandle = Handle; + + OVERLAPPED = record + Internal : DWORD; + InternalHigh : DWORD; + Offset : DWORD; + OffsetHigh : DWORD; + hEvent : HANDLE; + end; + LPOVERLAPPED = ^OVERLAPPED; + _OVERLAPPED = OVERLAPPED; + TOVERLAPPED = OVERLAPPED; + POVERLAPPED = ^OVERLAPPED; + + + +function GetStdHandle(nStdHandle: DWord): Handle; +{function SetStdHandle(nStdHandle:DWORD; hHandle:HANDLE): WinBool;} + +function WriteFile(hFile: THandle; const Buffer; nNumberOfBytesToWrite: DWord; var lpNumberOfBytesWritten: DWord; lpOverlapped: POverlapped): Bool; + +function Std_Input_Handle: DWord; +function Std_Output_Handle: DWord; +function Std_Error_Handle: DWord; + +function GetTickCount: DWord; +function QueryPerformanceCounter(var lpPerformanceCount: Int64): WinBool; +function QueryPerformanceFrequency(var lpFrequency: Int64): WinBool; + +function AllocConsole: WinBool; +{function FreeConsole: WinBool;} + + implementation + +function GetStdHandle(nStdHandle: DWord): Handle; +begin + Result := 0; +end; + +function Std_Input_Handle: DWord; +begin + Result := 0; +end; + +function Std_Output_Handle: DWord; +begin + Result := 1; +end; + +function Std_Error_Handle: DWord; +begin + Result := 2; +end; + + +function WriteFile(hFile: THandle; const Buffer; nNumberOfBytesToWrite: DWord; var lpNumberOfBytesWritten: DWord; lpOverlapped: POverlapped): Bool; +begin + Result := True; +end; + + +function GetTickCount: DWord; +begin + Result := kos_timecounter() * 10; +end; + +function QueryPerformanceCounter(var lpPerformanceCount: Int64): WinBool; +begin + lpPerformanceCount := kos_timecounter(); + Result := True +end; + +function QueryPerformanceFrequency(var lpFrequency: Int64): WinBool; +begin + lpFrequency := 100; + Result := True +end; + + +function AllocConsole: WinBool; +begin + Result := True; +end; + + end. diff --git a/programs/develop/fp/exe2kos/exe2kos.pp b/programs/develop/fp/utils/exe2kos/exe2kos.pp similarity index 97% rename from programs/develop/fp/exe2kos/exe2kos.pp rename to programs/develop/fp/utils/exe2kos/exe2kos.pp index 7d3c75f830..ad9691aa44 100644 --- a/programs/develop/fp/exe2kos/exe2kos.pp +++ b/programs/develop/fp/utils/exe2kos/exe2kos.pp @@ -257,6 +257,8 @@ var i: Integer; begin ExeImage := TExeImage.Create(InputFile); + +{$ifdef debug} WriteHead('NT Header'); WriteLn(Format('Size of Code: %d', [ExeImage.SizeOfCode])); WriteLn(Format('Size of Init Data: %d', [ExeImage.SizeOfInitializedData])); @@ -267,6 +269,7 @@ begin WriteLn(Format('Image Size: %d; Header Size: %d', [ExeImage.ImageSize, ExeImage.HeaderSize])); WriteLn(Format('Stack Reserve Size: %d; Stack Commit Size: %d', [ExeImage.StackReserveSize, ExeImage.StackCommitSize])); WriteLn(Format('Heap Reserve Size: %d; Heap Comit Size: %d', [ExeImage.HeapReserveSize, ExeImage.HeapCommitSize])); +{$endif} ImageBase := ExeImage.ImageBase; ImageSize := 0; @@ -276,9 +279,12 @@ begin for i:=0 to ExeImage.Sections.Count-1 do with ExeImage.Sections[i] do begin + +{$ifdef debug} WriteHead(Format('Section %s (0x%x)', [Name, ObjectFlags])); WriteLn(Format('Section RVA/Size: 0x%x / %d', [SectionRVA, VirtualSize])); WriteLn(Format('Physical Offset/Size: 0x%x / %d', [PhysicalOffset, PhysicalSize])); +{$endif} Size := ImageBase + SectionRVA; FileStream.Position := Size; @@ -292,13 +298,6 @@ begin FileStream.Write(Buffer^, PhysicalSize); FreeMem(Buffer); end; - {if VirtualSize - PhysicalSize > 0 then - begin - GetMem(Buffer, VirtualSize - PhysicalSize); - FillByte(Buffer^, VirtualSize - PhysicalSize, 0); - FileStream.Write(Buffer^, VirtualSize - PhysicalSize); - FreeMem(Buffer); - end;} end; FillByte(KosHeader, SizeOf(KosHeader), 0); diff --git a/programs/develop/fp/exe2kos/exeimage.pp b/programs/develop/fp/utils/exe2kos/exeimage.pp similarity index 100% rename from programs/develop/fp/exe2kos/exeimage.pp rename to programs/develop/fp/utils/exe2kos/exeimage.pp diff --git a/programs/develop/fp/exe2kos/exetypes.pp b/programs/develop/fp/utils/exe2kos/exetypes.pp similarity index 100% rename from programs/develop/fp/exe2kos/exetypes.pp rename to programs/develop/fp/utils/exe2kos/exetypes.pp diff --git a/programs/develop/fp/exe2kos/kostypes.pp b/programs/develop/fp/utils/exe2kos/kostypes.pp similarity index 100% rename from programs/develop/fp/exe2kos/kostypes.pp rename to programs/develop/fp/utils/exe2kos/kostypes.pp