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