File: filectrl.inc

package info (click to toggle)
fpc 0.99.13-19991013-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 23,104 kB
  • ctags: 9,760
  • sloc: pascal: 253,711; ansic: 5,236; makefile: 3,855; yacc: 2,016; lex: 707; asm: 526; xml: 443; sh: 200; perl: 87; sed: 21; csh: 12; cpp: 1
file content (235 lines) | stat: -rw-r--r-- 4,918 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
{
  System independent filecontrol interface for tp7

  $Id: filectrl.inc,v 1.1 1998/12/04 12:48:57 peter Exp $
}

{ no known 16 bit compilers support overriding }

function OpenFileStr(FName: PChar; Flags: Longint): TFileHandle; assembler;
asm
@@Retry:
        push    ds
        lds     dx,FName
        mov     al,byte ptr Flags
        mov     ah,3dh
        int     21h
        pop     ds
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax      { ErrorCode: Longint }
        les     dx,FName
        push    es
        push    dx      { FName as ErrorInfo }
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
        mov     ax,-1
@@1:
end;

function CreateFileStr(FName: PChar): TFileHandle; assembler;
asm
@@Retry:
        push    ds
        lds     dx,FName
        mov     cl,20h
        xor     ch,ch
        mov     ah,3Ch
        int     21h
        pop     ds
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax
        les     dx,FName
        push    es
        push    dx              { FName as errorinfo }
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
        mov     ax,-1
@@1:
end;

procedure DeleteFileStr(FName: PChar); assembler;
asm
@@Retry:
        push    ds
        lds     dx,FName
        mov     AH,41h
        int     21h
        pop     ds
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax
        les     dx,FName
        push    es
        push    dx
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
@@1:
end;

procedure CloseFile(Handle: TFileHandle); assembler;
asm
@@Retry:
        mov     bx,Handle
        mov     ah,3eh
        int     21h
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax
        push    ax
        push    ax
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
@@1:
end;

function SeekFile(Handle: TFileHandle; Pos: TFileInt; SeekType: Word): TFileInt; assembler;
asm
@@Retry:
        mov     ah,42H
        mov     bx,Handle
        mov     dx,word ptr Pos[0]
        mov     cx,word ptr Pos[2]
        mov     al,byte ptr SeekType
        int     21h
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax
        push    ax
        push    ax
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
        mov     ax,-1
        mov     dx,-1
@@1:
end;

function ReadFile(Handle: TFileHandle; var Buff; Count: CPUWord): CPUWord; assembler;
asm
@@Retry:
        push    ds
        lds     dx,Buff
        mov     cx,Count
        mov     bx,Handle
        mov     ah,3fh
        int     21h
        pop     ds
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax
        push    ax
        push    ax
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
        xor     ax,ax
@@1:
end;

function WriteFile(Handle: TFileHandle; var Buff; Count: CPUWord): CPUWord; assembler;
asm
@@Retry:
        push    ds
        lds     dx,Buff
        mov     cx,Count
        mov     bx,Handle
        mov     ah,40h
        int     21h
        pop     ds
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax
        push    ax
        push    ax
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
        xor     ax,ax
@@1:
end;

procedure FlushFile(Handle: TFileHandle); assembler;
asm
@@Retry:
        mov     bx,Handle
        mov     ah,68H
        int     21h
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax
        push    ax
        push    ax
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
@@1:
end;

procedure TruncateFile(Handle: TFileHandle);
begin
  WriteFile(Handle, Handle, 0);
end;

function EndOfFile(Handle: TFileHandle): Boolean; assembler;
asm
@@Retry:
        mov     ax,4400h
        mov     bx,Handle
        int     21h
        jnc     @@1
        push    ax
        mov     ax,0
        push    ax
        push    ax
        push    ax
        call    [ErrorHandler]
        cmp     ax,errRetry
        je      @@Retry
        jmp     @@3      { Set result to 1, though an error has happened }
@@1:
        test    ax,40h
        jz      @@3
        xor     al,al
        jmp     @@2
@@3:
        mov     al,1
@@2:
end;

function FilePos(Handle: TFileHandle): TFileInt;
begin
  FilePos := SeekFile(Handle, 0, skCur);
end;

function FileSize(Handle: TFileHandle): TFileInt;
var
  L: Longint;
begin
  L := FilePos(Handle);
  FileSize := SeekFile(Handle, 0, skEnd);
  SeekFile(Handle, L, skBeg);
end;

{
  $Log: filectrl.inc,v $
  Revision 1.1  1998/12/04 12:48:57  peter
    * moved some dirs

  Revision 1.1  1998/10/26 11:31:49  peter
    + inital include files

}