Rev 7113 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7113 | GerdtR | 1 | |
2 | _FILE: |
||
3 | .pos dq ? |
||
4 | .bufpos dq ? |
||
5 | .bufsize dd ? |
||
6 | .mode dd ? |
||
7 | .hPlugin dd ? |
||
8 | .hFile dd ? |
||
9 | .fileinfo: |
||
10 | .fimode dd ? |
||
11 | .fioffset dq ? |
||
12 | .fisize dd ? |
||
13 | .fibuf dd ? |
||
14 | .finame rb 1024 |
||
15 | .attr rb 40 |
||
16 | align 512 |
||
17 | .buf rb 2048 |
||
18 | .size = $ |
||
19 | end virtual |
||
20 | |||
21 | |||
22 | O_WRITE = 2 ; allows write to file |
||
23 | O_CREATE = 4 ; if file does not exist and this flag is set, create file; |
||
24 | ; if file does not exist and this flag is not set, fail |
||
25 | O_TRUNCATE = 8 ; truncate file if it exists |
||
26 | O_SEQUENTIAL_ONLY = 10h ; there will be no 'seek'/'setpos' calls |
||
27 | |||
28 | |||
29 | |||
30 | close: |
||
31 | pushad |
||
32 | mov ecx, [esp+24h] |
||
33 | mov eax, [ecx+_FILE.hPlugin] |
||
34 | test eax, eax |
||
35 | jz @f |
||
36 | push ecx |
||
37 | push [ecx+_FILE.hFile] |
||
38 | call [aClose] |
||
39 | pop ecx |
||
40 | @@: |
||
41 | call pgfree |
||
42 | popad |
||
43 | ret 4 |
||
44 | |||
45 | |||
46 | read: |
||
47 | xor eax, eax |
||
48 | pushad |
||
49 | mov ecx, [esp+36] |
||
50 | test [ecx+_FILE.mode], O_READ |
||
51 | jnz @f |
||
52 | .ret: |
||
53 | popad |
||
54 | ret 12 |
||
55 | @@: |
||
56 | cmp dword [esp+44], eax |
||
57 | jz .ret |
||
58 | mov [ecx+_FILE.fimode], eax |
||
59 | mov ebx, [ecx+_FILE.bufsize] |
||
60 | mov eax, dword [ecx+_FILE.pos] |
||
61 | and eax, 2047 |
||
62 | sub ebx, eax |
||
63 | jbe .nobuf0 |
||
64 | cmp ebx, [esp+44] |
||
65 | jbe @f |
||
66 | mov ebx, [esp+44] |
||
67 | @@: |
||
68 | push ecx |
||
69 | lea esi, [ecx+eax+_FILE.buf] |
||
70 | mov ecx, ebx |
||
71 | mov edi, [esp+44] |
||
72 | rep movsb |
||
73 | pop ecx |
||
74 | mov [esp+40], edi |
||
75 | add [esp+28], ebx |
||
76 | add dword [ecx+_FILE.pos], ebx |
||
77 | adc dword [ecx+_FILE.pos+4], 0 |
||
78 | test dword [ecx+_FILE.pos], 2047 |
||
79 | jnz @f |
||
80 | and [ecx+_FILE.bufsize], 0 |
||
81 | @@: |
||
82 | sub [esp+44], ebx |
||
83 | jz .ret |
||
84 | .nobuf0: |
||
85 | test dword [ecx+_FILE.pos], 2047 |
||
86 | jz .aligned |
||
87 | cmp dword [ecx+_FILE.bufsize], 0 |
||
88 | jnz .ret |
||
89 | lea ebx, [ecx+_FILE.fileinfo] |
||
90 | mov dword [ebx+12], 2048 |
||
91 | lea eax, [ecx+_FILE.buf] |
||
92 | mov dword [ebx+16], eax |
||
93 | mov eax, dword [ecx+_FILE.fioffset] |
||
94 | mov dword [ecx+_FILE.bufpos], eax |
||
95 | mov eax, dword [ecx+_FILE.fioffset+4] |
||
96 | mov dword [ecx+_FILE.bufpos+4], eax |
||
97 | call .doread |
||
98 | test eax, eax |
||
99 | jnz .ret |
||
100 | mov [ecx+_FILE.bufsize], ebx |
||
101 | mov eax, dword [ecx+_FILE.pos] |
||
102 | and eax, 2047 |
||
103 | sub ebx, eax |
||
104 | jbe .ret |
||
105 | cmp ebx, [esp+44] |
||
106 | jbe @f |
||
107 | mov ebx, [esp+44] |
||
108 | @@: |
||
109 | push ecx |
||
110 | lea esi, [ecx+eax+_FILE.buf] |
||
111 | mov ecx, ebx |
||
112 | mov edi, [esp+44] |
||
113 | rep movsb |
||
114 | pop ecx |
||
115 | add dword [ecx+_FILE.pos], ebx |
||
116 | adc dword [ecx+_FILE.pos+4], 0 |
||
117 | mov [esp+40], edi |
||
118 | add [esp+28], ebx |
||
119 | sub [esp+44], ebx |
||
120 | jz .ret |
||
121 | test dword [ecx+_FILE.pos], 2047 |
||
122 | jnz .ret |
||
123 | .aligned: |
||
124 | lea ebx, [ecx+_FILE.fileinfo] |
||
125 | mov eax, [esp+44] |
||
126 | and eax, not 2047 |
||
127 | jz .finish |
||
128 | and [ecx+_FILE.bufsize], 0 |
||
129 | mov [ebx+12], eax |
||
130 | mov eax, [esp+40] |
||
131 | mov [ebx+16], eax |
||
132 | call .doread |
||
133 | test eax, eax |
||
134 | jnz .ret |
||
135 | add dword [ecx+_FILE.pos], ebx |
||
136 | adc dword [ecx+_FILE.pos+4], 0 |
||
137 | add [esp+28], ebx |
||
138 | add [esp+40], ebx |
||
139 | sub [esp+44], ebx |
||
140 | jz .ret |
||
141 | cmp ebx, [ecx+_FILE.fisize] |
||
142 | jb .ret |
||
143 | .finish: |
||
144 | lea ebx, [ecx+_FILE.fileinfo] |
||
145 | mov dword [ebx+12], 2048 |
||
146 | lea eax, [ecx+_FILE.buf] |
||
147 | mov [ebx+16], eax |
||
148 | and [ecx+_FILE.bufsize], 0 |
||
149 | mov eax, dword [ecx+_FILE.fioffset] |
||
150 | mov dword [ecx+_FILE.bufpos], eax |
||
151 | mov eax, dword [ecx+_FILE.fioffset+4] |
||
152 | mov dword [ecx+_FILE.bufpos+4], eax |
||
153 | call .doread |
||
154 | test eax, eax |
||
155 | jnz .ret |
||
156 | mov [ecx+_FILE.bufsize], ebx |
||
157 | cmp ebx, [esp+44] |
||
158 | jb @f |
||
159 | mov ebx, [esp+44] |
||
160 | @@: |
||
161 | add [esp+28], ebx |
||
162 | add dword [ecx+_FILE.pos], ebx |
||
163 | adc dword [ecx+_FILE.pos+4], 0 |
||
164 | lea esi, [ecx+_FILE.buf] |
||
165 | mov edi, [esp+40] |
||
166 | mov ecx, ebx |
||
167 | rep movsb |
||
168 | popad |
||
169 | ret 12 |
||
170 | .doread: |
||
171 | mov eax, [ecx+_FILE.hPlugin] |
||
172 | test eax, eax |
||
173 | jz .native |
||
174 | push ecx |
||
175 | push [ecx+_FILE.fisize] |
||
176 | push [ecx+_FILE.fibuf] |
||
177 | push [ecx+_FILE.hFile] |
||
178 | call [eax+aRead] |
||
179 | pop ecx |
||
180 | cmp eax, -1 |
||
181 | jz @f |
||
182 | mov ebx, eax |
||
183 | xor eax, eax |
||
184 | jmp .addpos |
||
185 | @@: |
||
186 | ret |
||
187 | .native: |
||
188 | push 70 |
||
189 | pop eax |
||
190 | int 0x40 |
||
191 | test eax, eax |
||
192 | jz .addpos |
||
193 | cmp eax, 6 |
||
194 | jnz @b |
||
195 | xor eax, eax |
||
196 | .addpos: |
||
197 | add dword [ecx+_FILE.fioffset], ebx |
||
198 | adc dword [ecx+_FILE.fioffset+4], 0 |
||
199 | ret |
||
200 | |||
201 | |||
202 | seek: |
||
203 | pushad |
||
204 | mov ecx, [esp+36] |
||
205 | mov eax, [esp+44] |
||
206 | mov edx, [esp+48] |
||
207 | cmp dword [esp+40], 1 |
||
208 | jb .set |
||
209 | ja .end |
||
210 | add eax, dword [ecx+_FILE.pos] |
||
211 | adc edx, dword [ecx+_FILE.pos+4] |
||
212 | jmp .set |
||
213 | .end: |
||
214 | add eax, dword [ecx+_FILE.attr+32] |
||
215 | adc edx, dword [ecx+_FILE.attr+36] |
||
216 | .set: |
||
217 | mov dword [ecx+_FILE.pos], eax |
||
218 | mov dword [ecx+_FILE.pos+4], edx |
||
219 | and eax, not 2047 |
||
220 | cmp eax, dword [ecx+_FILE.bufpos] |
||
221 | jnz @f |
||
222 | cmp edx, dword [ecx+_FILE.bufpos+4] |
||
223 | jz .bufposok |
||
224 | @@: |
||
225 | and [ecx+_FILE.bufsize], 0 |
||
226 | mov dword [ecx+_FILE.bufpos], eax |
||
227 | mov dword [ecx+_FILE.bufpos+4], edx |
||
228 | .bufposok: |
||
229 | cmp [ecx+_FILE.bufsize], 0 |
||
230 | jnz .ret |
||
231 | cmp eax, dword [ecx+_FILE.fioffset] |
||
232 | jnz @f |
||
233 | cmp edx, dword [ecx+_FILE.fioffset+4] |
||
234 | jz .ret |
||
235 | @@: |
||
236 | mov dword [ecx+_FILE.fioffset], eax |
||
237 | mov dword [ecx+_FILE.fioffset+4], edx |
||
238 | mov eax, [ecx+_FILE.hPlugin] |
||
239 | test eax, eax |
||
240 | jz @f |
||
241 | push dword [ecx+_FILE.fioffset+4] |
||
242 | push dword [ecx+_FILE.fioffset] |
||
243 | push [ecx+_FILE.hFile] |
||
244 | call [eax+aSetpos] |
||
245 | @@: |
||
246 | .ret: |
||
247 | popad |
||
248 | ret 16 |
||
249 | |||
250 | |||
251 | |||
252 | tell: |
||
253 | mov eax, [esp+4] |
||
254 | mov edx, dword [eax+_FILE.pos+4] |
||
255 | mov eax, dword [eax+_FILE.pos] |
||
256 | ret 4 |
||
257 | |||
258 | |||
259 | ; Opens physical file |
||
260 | open: |
||
261 | pushad |
||
262 | mov ecx, _FILE.size |
||
263 | call xpgalloc |
||
264 | test eax, eax |
||
265 | jz .ret0z |
||
266 | mov [esp+28], eax |
||
267 | mov ecx, eax |
||
268 | mov esi, [esp+36] |
||
269 | lea edi, [eax+_FILE.finame] |
||
270 | lea edx, [eax+_FILE.finame+1024] |
||
271 | @@: |
||
272 | lodsb |
||
273 | stosb |
||
274 | test al, al |
||
275 | jz @f |
||
276 | cmp edi, edx |
||
277 | jb @b |
||
278 | .ret0: |
||
279 | call pgfree |
||
280 | .ret0z: |
||
281 | popad |
||
282 | xor eax, eax |
||
283 | ret 8 |
||
284 | @@: |
||
285 |