git-svn-id: svn://kolibrios.org@763 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
bw 2008-02-29 17:47:04 +00:00
parent a5131135c4
commit 5780544c0f
9 changed files with 155 additions and 28 deletions

View File

@ -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,

View File

@ -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

View File

@ -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 }

View File

@ -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;

View File

@ -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.

View File

@ -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);