Rev 9692 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
6468 | pathoswith | 3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License. ;; |
||
2288 | clevermous | 5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | $Revision: 9828 $ |
||
9 | |||
6468 | pathoswith | 10 | ; CD external functions |
11 | ; in: |
||
6471 | pathoswith | 12 | ; esi -> path string in UTF-8 |
6872 | pathoswith | 13 | ; ebx -> parameter structure +4 |
6468 | pathoswith | 14 | ; ecx = bytes to read |
15 | ; edx -> buffer |
||
16 | ; out: |
||
17 | ; eax, ebx = return values for sysfunc 70 |
||
18 | iglobal |
||
19 | align 4 |
||
20 | fs_CdServices: |
||
21 | dd fs_CdRead |
||
22 | dd fs_CdReadFolder |
||
23 | dd fs_NotImplemented |
||
24 | dd fs_NotImplemented |
||
25 | dd fs_NotImplemented |
||
26 | dd fs_CdGetFileInfo |
||
27 | dd fs_NotImplemented |
||
28 | dd 0 |
||
29 | dd fs_NotImplemented |
||
30 | dd fs_NotImplemented |
||
31 | fs_NumCdServices = ($ - fs_CdServices)/4 |
||
32 | endg |
||
33 | |||
2288 | clevermous | 34 | uglobal |
6468 | pathoswith | 35 | align 4 |
36 | cd_current_pointer_of_input dd 0 |
||
37 | cd_current_pointer_of_input_2 dd 0 |
||
38 | cd_mem_location dd 0 |
||
39 | cd_counter_block dd 0 |
||
40 | cd_status dd 0 |
||
2288 | clevermous | 41 | endg |
6468 | pathoswith | 42 | |
4700 | mario79 | 43 | ;----------------------------------------------------------------------------- |
6468 | pathoswith | 44 | fs_NotImplemented: |
45 | movi eax, ERROR_UNSUPPORTED_FS |
||
46 | ret |
||
47 | ;----------------------------------------------------------------------------- |
||
2288 | clevermous | 48 | reserve_cd: |
49 | cli |
||
50 | cmp [cd_status], 0 |
||
51 | je reserve_ok2 |
||
52 | |||
53 | sti |
||
54 | call change_task |
||
55 | jmp reserve_cd |
||
4700 | mario79 | 56 | ;----------------------------------------------------------------------------- |
57 | reserve_ok2: |
||
2288 | clevermous | 58 | push eax |
9828 | Doczom | 59 | mov eax, [current_slot] |
60 | mov eax, [eax + APPDATA.tid] |
||
2288 | clevermous | 61 | mov [cd_status], eax |
62 | pop eax |
||
63 | sti |
||
64 | ret |
||
4700 | mario79 | 65 | ;----------------------------------------------------------------------------- |
66 | reserve_cd_channel: |
||
67 | pushad |
||
68 | mov eax, [cdpos] |
||
69 | dec eax |
||
70 | shr eax, 2 |
||
2288 | clevermous | 71 | |
4700 | mario79 | 72 | test eax, eax |
73 | jnz .1 |
||
74 | |||
2288 | clevermous | 75 | cmp [ChannelNumber], 1 |
4700 | mario79 | 76 | jne @f |
77 | |||
3742 | clevermous | 78 | mov ecx, ide_channel1_mutex |
4700 | mario79 | 79 | jmp .mutex_lock |
80 | ;-------------------------------------- |
||
81 | @@: |
||
82 | mov ecx, ide_channel2_mutex |
||
83 | jmp .mutex_lock |
||
84 | ;-------------------------------------- |
||
85 | .1: |
||
86 | dec eax |
||
87 | jnz .2 |
||
88 | |||
89 | cmp [ChannelNumber], 1 |
||
90 | jne @f |
||
91 | |||
92 | mov ecx, ide_channel3_mutex |
||
93 | jmp .mutex_lock |
||
94 | ;-------------------------------------- |
||
95 | @@: |
||
96 | mov ecx, ide_channel4_mutex |
||
97 | jmp .mutex_lock |
||
98 | ;-------------------------------------- |
||
99 | .2: |
||
100 | cmp [ChannelNumber], 1 |
||
101 | jne @f |
||
102 | |||
103 | mov ecx, ide_channel5_mutex |
||
104 | jmp .mutex_lock |
||
105 | ;-------------------------------------- |
||
106 | @@: |
||
107 | mov ecx, ide_channel6_mutex |
||
108 | .mutex_lock: |
||
3742 | clevermous | 109 | call mutex_lock |
110 | popad |
||
2288 | clevermous | 111 | ret |
4700 | mario79 | 112 | ;----------------------------------------------------------------------------- |
113 | free_cd_channel: |
||
3742 | clevermous | 114 | pushad |
4700 | mario79 | 115 | mov eax, [cdpos] |
116 | dec eax |
||
117 | shr eax, 2 |
||
2288 | clevermous | 118 | |
4700 | mario79 | 119 | test eax, eax |
120 | jnz .1 |
||
121 | |||
2288 | clevermous | 122 | cmp [ChannelNumber], 1 |
4700 | mario79 | 123 | jne @f |
124 | |||
3742 | clevermous | 125 | mov ecx, ide_channel1_mutex |
4700 | mario79 | 126 | jmp .mutex_unlock |
127 | ;-------------------------------------- |
||
128 | @@: |
||
3742 | clevermous | 129 | mov ecx, ide_channel2_mutex |
4700 | mario79 | 130 | jmp .mutex_unlock |
131 | ;-------------------------------------- |
||
132 | .1: |
||
133 | dec eax |
||
134 | jnz .2 |
||
135 | |||
136 | cmp [ChannelNumber], 1 |
||
137 | jne @f |
||
138 | |||
139 | mov ecx, ide_channel3_mutex |
||
140 | jmp .mutex_unlock |
||
141 | ;-------------------------------------- |
||
142 | @@: |
||
143 | mov ecx, ide_channel4_mutex |
||
144 | jmp .mutex_unlock |
||
145 | ;-------------------------------------- |
||
146 | .2: |
||
147 | cmp [ChannelNumber], 1 |
||
148 | jne @f |
||
149 | |||
150 | mov ecx, ide_channel5_mutex |
||
151 | jmp .mutex_unlock |
||
152 | ;-------------------------------------- |
||
153 | @@: |
||
154 | mov ecx, ide_channel6_mutex |
||
155 | .mutex_unlock: |
||
3742 | clevermous | 156 | call mutex_unlock |
157 | popad |
||
2288 | clevermous | 158 | ret |
6468 | pathoswith | 159 | |
4700 | mario79 | 160 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 161 | fs_CdRead: |
162 | call cd_find_lfn |
||
6845 | pathoswith | 163 | jc .notFound |
2288 | clevermous | 164 | mov edi, [cd_current_pointer_of_input] |
6845 | pathoswith | 165 | test byte [edi+25], 10b ; do not allow read directories |
2288 | clevermous | 166 | jnz .noaccess |
167 | test ebx, ebx |
||
168 | jz .l1 |
||
169 | cmp dword [ebx+4], 0 |
||
170 | jz @f |
||
6845 | pathoswith | 171 | xor ebx, ebx |
172 | movi eax, ERROR_END_OF_FILE |
||
173 | ret |
||
4700 | mario79 | 174 | |
6845 | pathoswith | 175 | .notFound: |
176 | cmp [DevErrorCode], 0 |
||
177 | jne .noaccess |
||
2288 | clevermous | 178 | xor ebx, ebx |
6845 | pathoswith | 179 | movi eax, ERROR_FILE_NOT_FOUND |
2288 | clevermous | 180 | ret |
6845 | pathoswith | 181 | |
182 | .noaccess_3: |
||
183 | pop eax edx ecx |
||
184 | .noaccess: |
||
185 | xor ebx, ebx |
||
186 | movi eax, ERROR_ACCESS_DENIED |
||
187 | ret |
||
188 | |||
2288 | clevermous | 189 | @@: |
190 | mov ebx, [ebx] |
||
191 | .l1: |
||
6845 | pathoswith | 192 | push ecx edx 0 |
193 | mov eax, [edi+10] ; real size of the file section |
||
2288 | clevermous | 194 | sub eax, ebx |
195 | jb .eof |
||
196 | cmp eax, ecx |
||
197 | jae @f |
||
198 | mov ecx, eax |
||
6845 | pathoswith | 199 | pop eax |
200 | push ERROR_END_OF_FILE |
||
2288 | clevermous | 201 | @@: |
202 | mov eax, [edi+2] |
||
203 | mov [CDSectorAddress], eax |
||
204 | ; now eax=cluster, ebx=position, ecx=count, edx=buffer for data |
||
205 | .new_sector: |
||
206 | test ecx, ecx |
||
207 | jz .done |
||
208 | sub ebx, 2048 |
||
209 | jae .next |
||
210 | add ebx, 2048 |
||
211 | jnz .incomplete_sector |
||
212 | cmp ecx, 2048 |
||
213 | jb .incomplete_sector |
||
214 | ; we may read and memmove complete sector |
||
215 | mov [CDDataBuf_pointer], edx |
||
6845 | pathoswith | 216 | call ReadCDWRetr |
2288 | clevermous | 217 | cmp [DevErrorCode], 0 |
218 | jne .noaccess_3 |
||
219 | add edx, 2048 |
||
220 | sub ecx, 2048 |
||
221 | .next: |
||
222 | inc dword [CDSectorAddress] |
||
223 | jmp .new_sector |
||
6845 | pathoswith | 224 | |
225 | .eof: |
||
226 | pop eax |
||
227 | push ERROR_END_OF_FILE |
||
228 | .done: |
||
229 | mov ebx, edx |
||
230 | pop eax edx ecx |
||
231 | sub ebx, edx |
||
232 | ret |
||
233 | |||
234 | .incomplete_sector: ; we must read and memmove incomplete sector |
||
2288 | clevermous | 235 | mov [CDDataBuf_pointer], CDDataBuf |
6845 | pathoswith | 236 | call ReadCDWRetr |
2288 | clevermous | 237 | cmp [DevErrorCode], 0 |
238 | jne .noaccess_3 |
||
239 | push ecx |
||
240 | add ecx, ebx |
||
241 | cmp ecx, 2048 |
||
242 | jbe @f |
||
243 | mov ecx, 2048 |
||
244 | @@: |
||
245 | sub ecx, ebx |
||
246 | push edi esi ecx |
||
247 | mov edi, edx |
||
248 | lea esi, [CDDataBuf + ebx] |
||
249 | cld |
||
250 | rep movsb |
||
251 | pop ecx esi edi |
||
252 | add edx, ecx |
||
253 | sub [esp], ecx |
||
254 | pop ecx |
||
255 | xor ebx, ebx |
||
256 | jmp .next |
||
6468 | pathoswith | 257 | |
4700 | mario79 | 258 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 259 | fs_CdReadFolder: |
260 | push edi |
||
261 | call cd_find_lfn |
||
262 | jnc .found |
||
263 | pop edi |
||
264 | cmp [DevErrorCode], 0 |
||
265 | jne .noaccess_1 |
||
6880 | pathoswith | 266 | xor ebx, ebx |
2288 | clevermous | 267 | mov eax, ERROR_FILE_NOT_FOUND |
268 | ret |
||
6798 | pathoswith | 269 | |
2288 | clevermous | 270 | .found: |
271 | mov edi, [cd_current_pointer_of_input] |
||
272 | test byte [edi+25], 10b ; do not allow read directories |
||
273 | jnz .found_dir |
||
274 | pop edi |
||
275 | .noaccess_1: |
||
6880 | pathoswith | 276 | xor ebx, ebx |
2288 | clevermous | 277 | mov eax, ERROR_ACCESS_DENIED |
278 | ret |
||
6798 | pathoswith | 279 | |
280 | .end_buffer: |
||
281 | pop edx eax |
||
282 | sub eax, 2048 ; directory is over? |
||
283 | ja .read_to_buffer |
||
284 | mov eax, [cd_counter_block] |
||
285 | mov [edx+8], eax |
||
286 | mov eax, [ebx] |
||
287 | sub [edx+4], eax |
||
288 | xor eax, eax |
||
289 | dec ecx |
||
290 | js @f |
||
291 | mov al, ERROR_END_OF_FILE |
||
292 | @@: |
||
293 | pop ecx edi |
||
294 | mov ebx, [edx+4] |
||
295 | ret |
||
296 | |||
2288 | clevermous | 297 | .found_dir: |
298 | mov eax, [edi+2] ; eax=cluster |
||
299 | mov [CDSectorAddress], eax |
||
4700 | mario79 | 300 | mov eax, [edi+10] ; directory size |
2288 | clevermous | 301 | push eax ecx |
302 | mov edi, edx |
||
303 | mov ecx, 32/4 |
||
304 | xor eax, eax |
||
305 | rep stosd |
||
306 | pop ecx eax |
||
307 | mov byte [edx], 1 ; version |
||
308 | mov [cd_mem_location], edx |
||
309 | add [cd_mem_location], 32 |
||
310 | mov [cd_counter_block], dword 0 |
||
311 | dec dword [CDSectorAddress] |
||
312 | push ecx |
||
313 | .read_to_buffer: |
||
314 | inc dword [CDSectorAddress] |
||
315 | mov [CDDataBuf_pointer], CDDataBuf |
||
6798 | pathoswith | 316 | call ReadCDWRetr ; read sector of directory |
2288 | clevermous | 317 | cmp [DevErrorCode], 0 |
318 | jne .noaccess_1 |
||
6798 | pathoswith | 319 | mov [cd_current_pointer_of_input_2], CDDataBuf |
320 | push eax edx |
||
2288 | clevermous | 321 | .get_names_from_buffer: |
322 | call cd_get_name |
||
323 | jc .end_buffer |
||
324 | inc dword [cd_counter_block] |
||
325 | mov eax, [cd_counter_block] |
||
326 | cmp [ebx], eax |
||
6798 | pathoswith | 327 | jae .get_names_from_buffer |
2288 | clevermous | 328 | test ecx, ecx |
6798 | pathoswith | 329 | jz .get_names_from_buffer |
2288 | clevermous | 330 | mov edi, [cd_counter_block] |
331 | mov [edx+4], edi |
||
332 | dec ecx |
||
333 | mov esi, ebp |
||
6798 | pathoswith | 334 | call cd_get_parameters_of_file |
2288 | clevermous | 335 | add edi, 40 |
6798 | pathoswith | 336 | mov ax, '.' |
337 | cmp dword[ebx+4], 2 |
||
338 | jz .utf16 |
||
339 | cmp dword[ebx+4], 3 |
||
340 | jz .utf8 |
||
2288 | clevermous | 341 | cmp [cd_counter_block], 2 |
6798 | pathoswith | 342 | jbe .parentDirectory |
343 | @@: |
||
2288 | clevermous | 344 | lodsw |
345 | xchg ah, al |
||
346 | call uni2ansi_char |
||
347 | stosb |
||
6798 | pathoswith | 348 | call .checkForEnd |
349 | jc @b |
||
350 | @@: |
||
2288 | clevermous | 351 | mov [edi], byte 0 |
352 | add [cd_mem_location], 304 |
||
6798 | pathoswith | 353 | jmp .get_names_from_buffer |
354 | |||
355 | .parentDirectory: |
||
356 | stosb |
||
2288 | clevermous | 357 | cmp [cd_counter_block], 2 |
6798 | pathoswith | 358 | jnz @b |
359 | stosb |
||
360 | jmp @b |
||
4700 | mario79 | 361 | |
6798 | pathoswith | 362 | .utf8: |
363 | add [cd_mem_location], 256 |
||
364 | cmp [cd_counter_block], 2 |
||
365 | jbe .parentDirectory |
||
366 | push ecx |
||
367 | mov ecx, 519 |
||
2288 | clevermous | 368 | @@: |
6798 | pathoswith | 369 | lodsw |
370 | xchg ah, al |
||
371 | call UTF16to8 |
||
372 | js @f |
||
373 | call .checkForEnd |
||
374 | jc @b |
||
375 | @@: |
||
376 | pop ecx |
||
377 | mov [edi], byte 0 |
||
378 | add [cd_mem_location], 304 |
||
379 | jmp .get_names_from_buffer |
||
4700 | mario79 | 380 | |
6798 | pathoswith | 381 | .checkForEnd: |
2288 | clevermous | 382 | mov ax, [esi] |
6798 | pathoswith | 383 | cmp ax, 3B00h ; ';' |
384 | jz @f |
||
4700 | mario79 | 385 | ; check for files not ending with separator |
2288 | clevermous | 386 | movzx eax, byte [ebp-33] |
387 | add eax, ebp |
||
388 | sub eax, 34 |
||
389 | cmp esi, eax |
||
6798 | pathoswith | 390 | jz @f |
4700 | mario79 | 391 | ; check the end of the directory |
2288 | clevermous | 392 | movzx eax, byte [ebp-1] |
393 | add eax, ebp |
||
394 | cmp esi, eax |
||
6798 | pathoswith | 395 | @@: |
396 | ret |
||
397 | |||
398 | .utf16: |
||
399 | cmp [cd_counter_block], 2 |
||
400 | jbe .utf16ParentDirectory |
||
401 | @@: |
||
402 | lodsw |
||
403 | xchg ah, al |
||
404 | stosw |
||
405 | call .checkForEnd |
||
406 | jc @b |
||
407 | @@: |
||
2288 | clevermous | 408 | mov [edi], word 0 |
409 | add [cd_mem_location], 560 |
||
6798 | pathoswith | 410 | jmp .get_names_from_buffer |
411 | |||
412 | .utf16ParentDirectory: |
||
413 | stosw |
||
2288 | clevermous | 414 | cmp [cd_counter_block], 2 |
6798 | pathoswith | 415 | jnz @b |
416 | stosw |
||
417 | jmp @b |
||
4700 | mario79 | 418 | |
2288 | clevermous | 419 | cd_get_parameters_of_file: |
420 | mov edi, [cd_mem_location] |
||
421 | cd_get_parameters_of_file_1: |
||
4700 | mario79 | 422 | ; get file attributes |
2288 | clevermous | 423 | xor eax, eax |
4700 | mario79 | 424 | ; file is not archived |
2288 | clevermous | 425 | inc eax |
426 | shl eax, 1 |
||
4700 | mario79 | 427 | ; is a directory? |
2288 | clevermous | 428 | test [ebp-8], byte 2 |
429 | jz .file |
||
430 | inc eax |
||
431 | .file: |
||
4700 | mario79 | 432 | ; not as a volume label in the FAT, in this form not available |
433 | ; file is not a system |
||
2288 | clevermous | 434 | shl eax, 3 |
4700 | mario79 | 435 | ; file is hidden? (attribute of existence) |
2288 | clevermous | 436 | test [ebp-8], byte 1 |
437 | jz .hidden |
||
438 | inc eax |
||
439 | .hidden: |
||
440 | shl eax, 1 |
||
4700 | mario79 | 441 | ; file is always read-only, as this CD |
2288 | clevermous | 442 | inc eax |
443 | mov [edi], eax |
||
6798 | pathoswith | 444 | mov eax, [ebx+4] |
445 | mov [edi+4], eax |
||
4700 | mario79 | 446 | ; get the time to file |
447 | ; hour |
||
2288 | clevermous | 448 | movzx eax, byte [ebp-12] |
449 | shl eax, 8 |
||
4700 | mario79 | 450 | ; minute |
2288 | clevermous | 451 | mov al, [ebp-11] |
452 | shl eax, 8 |
||
4700 | mario79 | 453 | ; second |
2288 | clevermous | 454 | mov al, [ebp-10] |
4700 | mario79 | 455 | ; file creation time |
2288 | clevermous | 456 | mov [edi+8], eax |
4700 | mario79 | 457 | ; last access time |
2288 | clevermous | 458 | mov [edi+16], eax |
4700 | mario79 | 459 | ; last write time |
2288 | clevermous | 460 | mov [edi+24], eax |
4700 | mario79 | 461 | ; get date for file |
462 | ; year |
||
2288 | clevermous | 463 | movzx eax, byte [ebp-15] |
464 | add eax, 1900 |
||
465 | shl eax, 8 |
||
4700 | mario79 | 466 | ; month |
2288 | clevermous | 467 | mov al, [ebp-14] |
468 | shl eax, 8 |
||
4700 | mario79 | 469 | ; day |
2288 | clevermous | 470 | mov al, [ebp-13] |
4700 | mario79 | 471 | ; file creation date |
2288 | clevermous | 472 | mov [edi+12], eax |
4700 | mario79 | 473 | ; last access date |
2288 | clevermous | 474 | mov [edi+20], eax |
6468 | pathoswith | 475 | ; last write date |
2288 | clevermous | 476 | mov [edi+28], eax |
4700 | mario79 | 477 | ; get the file size in bytes |
2288 | clevermous | 478 | xor eax, eax |
479 | mov [edi+32+4], eax |
||
480 | mov eax, [ebp-23] |
||
481 | mov [edi+32], eax |
||
482 | ret |
||
6468 | pathoswith | 483 | |
4700 | mario79 | 484 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 485 | fs_CdGetFileInfo: |
6872 | pathoswith | 486 | call cd_find_lfn |
487 | movi eax, ERROR_FILE_NOT_FOUND |
||
488 | jc @f |
||
489 | mov edi, edx |
||
490 | mov eax, [ebx+4] |
||
491 | mov [edx+4], eax |
||
2288 | clevermous | 492 | cmp byte [esi], 0 |
6872 | pathoswith | 493 | jz .volume |
494 | mov ebp, [cd_current_pointer_of_input] |
||
495 | add ebp, 33 |
||
496 | call cd_get_parameters_of_file_1 |
||
497 | xor eax, eax |
||
498 | @@: |
||
2288 | clevermous | 499 | ret |
4700 | mario79 | 500 | |
6872 | pathoswith | 501 | .volume: |
6876 | pathoswith | 502 | test eax, eax |
503 | jz .size |
||
6872 | pathoswith | 504 | mov ecx, 16 |
505 | mov esi, CDDataBuf+40 |
||
506 | add edi, 40 |
||
507 | cmp eax, 2 |
||
508 | jz .utf16 |
||
509 | cmp eax, 3 |
||
510 | jz .utf8 |
||
2288 | clevermous | 511 | @@: |
6872 | pathoswith | 512 | lodsw |
513 | xchg al, ah |
||
514 | call uni2ansi_char |
||
515 | stosb |
||
516 | loop @b |
||
517 | jmp .size |
||
4700 | mario79 | 518 | |
6872 | pathoswith | 519 | .utf16: |
520 | lodsw |
||
521 | xchg al, ah |
||
522 | stosw |
||
523 | loop .utf16 |
||
524 | jmp .size |
||
525 | |||
526 | .utf8: |
||
527 | mov ebx, ecx |
||
528 | shl ecx, 1 |
||
2288 | clevermous | 529 | @@: |
6872 | pathoswith | 530 | lodsw |
531 | xchg ah, al |
||
532 | call UTF16to8 |
||
533 | dec ebx |
||
534 | jnz @b |
||
535 | .size: |
||
536 | mov eax, [CDDataBuf+80] |
||
537 | shl eax, 11 |
||
538 | mov [edx+32], eax |
||
2288 | clevermous | 539 | xor eax, eax |
6872 | pathoswith | 540 | mov [edx+36], eax |
541 | stosw |
||
6876 | pathoswith | 542 | mov byte [edx], 8 |
2288 | clevermous | 543 | ret |
6872 | pathoswith | 544 | |
4700 | mario79 | 545 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 546 | cd_find_lfn: |
547 | mov [cd_appl_data], 0 |
||
6471 | pathoswith | 548 | ; in: esi -> path string in UTF-8 |
549 | ; out: [cd_current_pointer_of_input] -> direntry, CF=1 -> file not found |
||
2288 | clevermous | 550 | push eax esi |
4700 | mario79 | 551 | ; Sector 16 - start set of volume descriptors |
2288 | clevermous | 552 | call WaitUnitReady |
553 | cmp [DevErrorCode], 0 |
||
554 | jne .access_denied |
||
555 | |||
556 | call prevent_medium_removal |
||
4700 | mario79 | 557 | ; testing of reading |
2288 | clevermous | 558 | mov [CDSectorAddress], dword 16 |
559 | mov [CDDataBuf_pointer], CDDataBuf |
||
560 | call ReadCDWRetr;_1 |
||
561 | cmp [DevErrorCode], 0 |
||
562 | jne .access_denied |
||
563 | |||
4700 | mario79 | 564 | ; calculation of the last session |
2288 | clevermous | 565 | call WaitUnitReady |
566 | cmp [DevErrorCode], 0 |
||
567 | jne .access_denied |
||
4700 | mario79 | 568 | |
2288 | clevermous | 569 | call Read_TOC |
570 | mov ah, [CDDataBuf+4+4] |
||
571 | mov al, [CDDataBuf+4+5] |
||
572 | shl eax, 16 |
||
573 | mov ah, [CDDataBuf+4+6] |
||
574 | mov al, [CDDataBuf+4+7] |
||
575 | add eax, 15 |
||
576 | mov [CDSectorAddress], eax |
||
577 | ; mov [CDSectorAddress],dword 15 |
||
578 | mov [CDDataBuf_pointer], CDDataBuf |
||
4700 | mario79 | 579 | ;-------------------------------------- |
2288 | clevermous | 580 | .start: |
581 | inc dword [CDSectorAddress] |
||
582 | call ReadCDWRetr;_1 |
||
583 | cmp [DevErrorCode], 0 |
||
584 | jne .access_denied |
||
585 | |||
586 | .start_check: |
||
4700 | mario79 | 587 | ; checking for "lice" |
2288 | clevermous | 588 | cmp [CDDataBuf+1], dword 'CD00' |
589 | jne .access_denied |
||
4700 | mario79 | 590 | |
2288 | clevermous | 591 | cmp [CDDataBuf+5], byte '1' |
592 | jne .access_denied |
||
4700 | mario79 | 593 | ; sector is the terminator of set of descriptors volumes? |
2288 | clevermous | 594 | cmp [CDDataBuf], byte 0xff |
595 | je .access_denied |
||
4700 | mario79 | 596 | ; sector is an additional and improved descriptor of volume? |
2288 | clevermous | 597 | cmp [CDDataBuf], byte 0x2 |
598 | jne .start |
||
4700 | mario79 | 599 | ; sector is an additional descriptor of volume? |
2288 | clevermous | 600 | cmp [CDDataBuf+6], byte 0x1 |
601 | jne .start |
||
602 | |||
4700 | mario79 | 603 | ; parameters of root directory |
604 | mov eax, [CDDataBuf+0x9c+2]; start of root directory |
||
2288 | clevermous | 605 | mov [CDSectorAddress], eax |
4700 | mario79 | 606 | mov eax, [CDDataBuf+0x9c+10]; size of root directory |
2288 | clevermous | 607 | cmp byte [esi], 0 |
608 | jnz @f |
||
4700 | mario79 | 609 | |
2288 | clevermous | 610 | mov [cd_current_pointer_of_input], CDDataBuf+0x9c |
611 | jmp .done |
||
4700 | mario79 | 612 | ;-------------------------------------- |
2288 | clevermous | 613 | @@: |
4700 | mario79 | 614 | ; start the search |
2288 | clevermous | 615 | .mainloop: |
616 | dec dword [CDSectorAddress] |
||
4700 | mario79 | 617 | ;-------------------------------------- |
2288 | clevermous | 618 | .read_to_buffer: |
619 | inc dword [CDSectorAddress] |
||
620 | mov [CDDataBuf_pointer], CDDataBuf |
||
4700 | mario79 | 621 | call ReadCDWRetr ; read sector of directory |
2288 | clevermous | 622 | cmp [DevErrorCode], 0 |
623 | jne .access_denied |
||
624 | call cd_find_name_in_buffer |
||
625 | jnc .found |
||
626 | sub eax, 2048 |
||
4700 | mario79 | 627 | ; directory is over? |
2288 | clevermous | 628 | cmp eax, 0 |
629 | ja .read_to_buffer |
||
4700 | mario79 | 630 | ; desired element of chain is not found |
2288 | clevermous | 631 | .access_denied: |
632 | pop esi eax |
||
633 | mov [cd_appl_data], 1 |
||
634 | stc |
||
635 | ret |
||
4700 | mario79 | 636 | ;-------------------------------------- |
637 | ; desired element of chain found |
||
638 | .found: |
||
639 | ; the end of the file path |
||
2288 | clevermous | 640 | cmp byte [esi-1], 0 |
641 | jz .done |
||
642 | mov eax, [cd_current_pointer_of_input] |
||
643 | push dword [eax+2] |
||
4700 | mario79 | 644 | pop dword [CDSectorAddress] ; beginning of the directory |
645 | mov eax, [eax+2+8] ; size of directory |
||
2288 | clevermous | 646 | jmp .mainloop |
4700 | mario79 | 647 | ;-------------------------------------- |
648 | ; file pointer found |
||
649 | .done: |
||
2288 | clevermous | 650 | pop esi eax |
651 | mov [cd_appl_data], 1 |
||
652 | clc |
||
653 | ret |
||
4700 | mario79 | 654 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 655 | cd_find_name_in_buffer: |
656 | mov [cd_current_pointer_of_input_2], CDDataBuf |
||
4700 | mario79 | 657 | ;-------------------------------------- |
2288 | clevermous | 658 | .start: |
659 | call cd_get_name |
||
660 | jc .not_found |
||
4700 | mario79 | 661 | |
2288 | clevermous | 662 | call cd_compare_name |
663 | jc .start |
||
4700 | mario79 | 664 | ;-------------------------------------- |
2288 | clevermous | 665 | .found: |
666 | clc |
||
667 | ret |
||
4700 | mario79 | 668 | ;-------------------------------------- |
2288 | clevermous | 669 | .not_found: |
670 | stc |
||
671 | ret |
||
4700 | mario79 | 672 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 673 | cd_get_name: |
674 | push eax |
||
675 | mov ebp, [cd_current_pointer_of_input_2] |
||
676 | mov [cd_current_pointer_of_input], ebp |
||
677 | mov eax, [ebp] |
||
4700 | mario79 | 678 | test eax, eax ; entry's is over? |
2288 | clevermous | 679 | jz .next_sector |
4700 | mario79 | 680 | |
681 | cmp ebp, CDDataBuf+2048 ; buffer is over? |
||
2288 | clevermous | 682 | jae .next_sector |
4700 | mario79 | 683 | |
2288 | clevermous | 684 | movzx eax, byte [ebp] |
4700 | mario79 | 685 | add [cd_current_pointer_of_input_2], eax ; next entry of directory |
686 | add ebp, 33; pointer is set to the beginning of the name |
||
2288 | clevermous | 687 | pop eax |
688 | clc |
||
689 | ret |
||
4700 | mario79 | 690 | ;-------------------------------------- |
2288 | clevermous | 691 | .next_sector: |
692 | pop eax |
||
693 | stc |
||
694 | ret |
||
4700 | mario79 | 695 | ;----------------------------------------------------------------------------- |
2288 | clevermous | 696 | cd_compare_name: |
6471 | pathoswith | 697 | ; in: esi -> UTF-8 name, ebp -> UTF-16BE name |
698 | ; out: CF=0 -> names match, esi -> next component of name |
||
699 | ; CF=1 -> esi is not changed |
||
700 | push edx edi eax esi |
||
2288 | clevermous | 701 | mov edi, ebp |
702 | .loop: |
||
6471 | pathoswith | 703 | call utf8to16 |
704 | call utf16toUpper |
||
705 | mov edx, eax |
||
706 | mov ax, [edi] |
||
707 | xchg al, ah |
||
708 | call utf16toUpper |
||
709 | cmp ax, dx |
||
2288 | clevermous | 710 | jne .name_not_coincide |
6471 | pathoswith | 711 | add edi, 2 |
4700 | mario79 | 712 | cmp [esi], byte '/' ; path separator is end of current element |
2288 | clevermous | 713 | je .done |
4700 | mario79 | 714 | cmp [esi], byte 0 ; path separator end of name |
6471 | pathoswith | 715 | jne .loop |
2288 | clevermous | 716 | .done: |
4700 | mario79 | 717 | ; check end of file |
718 | cmp [edi], word 3B00h; separator end of file ';' |
||
2288 | clevermous | 719 | je .done_1 |
4700 | mario79 | 720 | ; check for files not ending with separator |
2288 | clevermous | 721 | movzx eax, byte [ebp-33] |
722 | add eax, ebp |
||
723 | sub eax, 34 |
||
724 | cmp edi, eax |
||
725 | je .done_1 |
||
4700 | mario79 | 726 | ; check the end of directory |
2288 | clevermous | 727 | movzx eax, byte [ebp-1] |
728 | add eax, ebp |
||
729 | cmp edi, eax |
||
730 | jne .name_not_coincide |
||
731 | .done_1: |
||
6471 | pathoswith | 732 | pop eax eax edi edx |
2288 | clevermous | 733 | inc esi |
734 | ret |
||
6471 | pathoswith | 735 | |
736 | .name_not_coincide: |
||
737 | pop esi eax edi edx |
||
738 | stc |
||
739 | ret |