Subversion Repositories Kolibri OS

Rev

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