Subversion Repositories Kolibri OS

Rev

Rev 9828 | Details | Compare with Previous | Last modification | View Log | RSS feed

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