Все протестино и работает, за комментами сюда или в личку.
Код: Выделить всё
{ (C) Somewhere 01.03.07 00:37 }
const
FAM_Read = 0; {File access mode}
FAM_Write = 1;
FAM_ReadWrite = 2;
FSM_Compat = 0; { File share mode }
FSM_DenyAll = 16;
FSM_DenyWrite = 32;
FSM_DenyRead = 48;
FSM_DenyNone = 64;
FAC_ReadOnly = 1; { File attribute constant }
FAC_Hidden = 2;
FAC_System = 4;
FAC_Volume = 8;
FAC_Archive = 32;
var
IOError : Word;
hFile : Word;
rCount : Word;
Buf : Array[0..199] of Word;
procedure OpenFile(var fHandle: Word; fPath :String; fAccessMode: Byte);
var h: Word;
begin
fPath := fPath + #0;
asm
push ds
push ss
pop ds
lea dx, fPath
inc dx
mov al, fAccessMode
mov ah, 3Dh
int 21h
pop ds
jnc @noerr
mov IOError, ax
jmp @ex
@noerr:
mov h, ax
@ex:
end;
fHandle := h;
end;
procedure CreateFile(var fHandle: Word; fPath :String; fAttr: Byte);
var h : Word;
begin
fPath := fPath + #0;
asm
push ds
push ss
pop ds
mov cl, fAttr
sub ch, ch
lea dx, fPath + 1
mov ah, 3Ch
int 21h
pop ds
jnc @noerr
mov IOError, ax
jmp @ex
@noerr:
mov h, ax
@ex:
end;
fHandle := h;
end;
procedure CloseFile(fHandle:Word);
begin
asm
mov bx, fHandle
mov ah, 3Eh
int 21h
jnc @ex
mov IOError, ax
@ex:
end;end;
procedure ReadFile(fHandle: Word; Buffer :Pointer; Count: Word);
begin
asm
lea bx, buffer
mov dx, ss:[bx]
mov cx, ss:count
mov bx, ss:fHandle
mov ah, 3Fh
int 21h
jnc @ex
mov IOError, ax
@ex:
end;
end;
procedure ReadFileEx(fHandle: Word; Buffer :Pointer; Count:Word; var Readed: Word);
var h : Word;
begin
asm
lea bx, buffer
mov dx, ss:[bx]
mov cx, ss:count
mov bx, ss:fHandle
mov ah, 3Fh
int 21h
jnc @noerr
mov IOError, ax
jmp @ex
@noerr:
mov h, ax
@ex:
end;
Readed := h;
end;
procedure WriteFile(fHandle: Word; Buffer :Pointer; Count: Word);
begin
asm
lea bx, buffer
mov dx, ss:[bx]
mov cx, ss:count
mov bx, ss:fHandle
mov ah, 40h
int 21h
jnc @ex
mov IOError, ax
@ex:
end;
end;
procedure SetFilePosition(fHandle:Word; fPosition:Longint); { Seek analog }
begin
asm
mov ax, 4200h
mov bx, ss:fHandle
mov dx, word ptr ss:fPosition
mov cx, word ptr ss:fPosition+2
int 21h
end;end;
function GetFilePosition(fHandle:Word):Longint; { FilePos analog }
var h: Longint;
begin
asm
mov ax, 4201h
mov bx, ss:fHandle
xor dx, dx
xor cx, cx
int 21h
mov word ptr h, ax
mov word ptr h+2, dx
end;
GetFilePosition := h;
end;
function GetFileSize(fHandle:Word):Longint; { FileSize analog }
var h: Longint;
begin
asm
mov ax, 4202h
mov bx, ss:fHandle
xor dx, dx
xor cx, cx
int 21h
mov word ptr h, ax
mov word ptr h+2, dx
end;
GetFileSize := h;
end;
begin
OpenFile(hFile, 'D:\Other\Pascal\abcde\abcde\abcde\abcde\abcde\abcde\abcde\abcde\abcde\abcde\aaaddd.fff', FAM_ReadWrite);
ReadFileEx(hFile, @Buf, 100, rCount);
SetFilePosition(hFile, 10);
WriteFile(hFile, @Buf, rCount);
Writeln(GetFileSize(hFile));
end.