Subversion Repositories Kolibri OS

Rev

Rev 6468 | Rev 6798 | 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: 6471 $
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
4700 mario79 300
 
2288 clevermous 301
        pop     edi
302
        cmp     [DevErrorCode], 0
303
        jne     .noaccess_1
4700 mario79 304
 
2288 clevermous 305
        or      ebx, -1
306
        mov     eax, ERROR_FILE_NOT_FOUND
307
        ret
4700 mario79 308
;--------------------------------------
2288 clevermous 309
.found:
310
        mov     edi, [cd_current_pointer_of_input]
311
        test    byte [edi+25], 10b    ; do not allow read directories
312
        jnz     .found_dir
4700 mario79 313
 
2288 clevermous 314
        pop     edi
4700 mario79 315
;--------------------------------------
2288 clevermous 316
.noaccess_1:
317
        or      ebx, -1
318
        mov     eax, ERROR_ACCESS_DENIED
319
        ret
4700 mario79 320
;--------------------------------------
2288 clevermous 321
.found_dir:
322
        mov     eax, [edi+2]    ; eax=cluster
323
        mov     [CDSectorAddress], eax
4700 mario79 324
        mov     eax, [edi+10]   ; directory size
325
;--------------------------------------
2288 clevermous 326
.doit:
327
; init header
328
        push    eax ecx
329
        mov     edi, edx
330
        mov     ecx, 32/4
331
        xor     eax, eax
332
        rep stosd
333
        pop     ecx eax
334
        mov     byte [edx], 1   ; version
335
        mov     [cd_mem_location], edx
336
        add     [cd_mem_location], 32
337
;.mainloop:
338
        mov     [cd_counter_block], dword 0
339
        dec     dword [CDSectorAddress]
340
        push    ecx
4700 mario79 341
;--------------------------------------
2288 clevermous 342
.read_to_buffer:
343
        inc     dword [CDSectorAddress]
344
        mov     [CDDataBuf_pointer], CDDataBuf
4700 mario79 345
        call    ReadCDWRetr         ; read sector of directory
2288 clevermous 346
        cmp     [DevErrorCode], 0
347
        jne     .noaccess_1
4700 mario79 348
 
2288 clevermous 349
        call    .get_names_from_buffer
350
        sub     eax, 2048
4700 mario79 351
; directory is over?
2288 clevermous 352
        ja      .read_to_buffer
4700 mario79 353
 
2288 clevermous 354
        mov     edi, [cd_counter_block]
355
        mov     [edx+8], edi
356
        mov     edi, [ebx]
357
        sub     [edx+4], edi
358
        xor     eax, eax
359
        dec     ecx
360
        js      @f
4700 mario79 361
 
2288 clevermous 362
        mov     al, ERROR_END_OF_FILE
4700 mario79 363
;--------------------------------------
2288 clevermous 364
@@:
365
        pop     ecx edi
366
        mov     ebx, [edx+4]
367
        ret
4700 mario79 368
;--------------------------------------
2288 clevermous 369
.get_names_from_buffer:
370
        mov     [cd_current_pointer_of_input_2], CDDataBuf
371
        push    eax esi edi edx
4700 mario79 372
;--------------------------------------
2288 clevermous 373
.get_names_from_buffer_1:
374
        call    cd_get_name
375
        jc      .end_buffer
4700 mario79 376
 
2288 clevermous 377
        inc     dword [cd_counter_block]
378
        mov     eax, [cd_counter_block]
379
        cmp     [ebx], eax
380
        jae     .get_names_from_buffer_1
4700 mario79 381
 
2288 clevermous 382
        test    ecx, ecx
383
        jz      .get_names_from_buffer_1
4700 mario79 384
 
2288 clevermous 385
        mov     edi, [cd_counter_block]
386
        mov     [edx+4], edi
387
        dec     ecx
388
        mov     esi, ebp
389
        mov     edi, [cd_mem_location]
390
        add     edi, 40
391
        test    dword [ebx+4], 1; 0=ANSI, 1=UNICODE
392
        jnz     .unicode
4700 mario79 393
;--------------------------------------
2288 clevermous 394
.ansi:
395
        cmp     [cd_counter_block], 2
396
        jbe     .ansi_parent_directory
4700 mario79 397
 
2288 clevermous 398
        cld
399
        lodsw
400
        xchg    ah, al
401
        call    uni2ansi_char
402
        cld
403
        stosb
4700 mario79 404
; check end of file
2288 clevermous 405
        mov     ax, [esi]
4700 mario79 406
        cmp     ax, word 3B00h ; separator end of file ';'
2288 clevermous 407
        je      .cd_get_parameters_of_file_1
4700 mario79 408
; check for files not ending with separator
2288 clevermous 409
        movzx   eax, byte [ebp-33]
410
        add     eax, ebp
411
        sub     eax, 34
412
        cmp     esi, eax
413
        je      .cd_get_parameters_of_file_1
4700 mario79 414
; check the end of the directory
2288 clevermous 415
        movzx   eax, byte [ebp-1]
416
        add     eax, ebp
417
        cmp     esi, eax
418
        jb      .ansi
4700 mario79 419
;--------------------------------------
2288 clevermous 420
.cd_get_parameters_of_file_1:
421
        mov     [edi], byte 0
422
        call    cd_get_parameters_of_file
423
        add     [cd_mem_location], 304
424
        jmp     .get_names_from_buffer_1
4700 mario79 425
;--------------------------------------
2288 clevermous 426
.ansi_parent_directory:
427
        cmp     [cd_counter_block], 2
428
        je      @f
4700 mario79 429
 
2288 clevermous 430
        mov     [edi], byte '.'
431
        inc     edi
432
        jmp     .cd_get_parameters_of_file_1
4700 mario79 433
;--------------------------------------
2288 clevermous 434
@@:
435
        mov     [edi], word '..'
436
        add     edi, 2
437
        jmp     .cd_get_parameters_of_file_1
4700 mario79 438
;--------------------------------------
2288 clevermous 439
.unicode:
440
        cmp     [cd_counter_block], 2
441
        jbe     .unicode_parent_directory
4700 mario79 442
 
2288 clevermous 443
        cld
444
        movsw
4700 mario79 445
; check end of file
2288 clevermous 446
        mov     ax, [esi]
4700 mario79 447
        cmp     ax, word 3B00h; separator end of file ';'
2288 clevermous 448
        je      .cd_get_parameters_of_file_2
4700 mario79 449
; check for files not ending with separator
2288 clevermous 450
        movzx   eax, byte [ebp-33]
451
        add     eax, ebp
452
        sub     eax, 34
453
        cmp     esi, eax
454
        je      .cd_get_parameters_of_file_2
4700 mario79 455
; check the end of the directory
2288 clevermous 456
        movzx   eax, byte [ebp-1]
457
        add     eax, ebp
458
        cmp     esi, eax
459
        jb      .unicode
4700 mario79 460
;--------------------------------------
2288 clevermous 461
.cd_get_parameters_of_file_2:
462
        mov     [edi], word 0
463
        call    cd_get_parameters_of_file
464
        add     [cd_mem_location], 560
465
        jmp     .get_names_from_buffer_1
4700 mario79 466
;--------------------------------------
2288 clevermous 467
.unicode_parent_directory:
468
        cmp     [cd_counter_block], 2
469
        je      @f
4700 mario79 470
 
2288 clevermous 471
        mov     [edi], word 2E00h; '.'
472
        add     edi, 2
473
        jmp     .cd_get_parameters_of_file_2
4700 mario79 474
;--------------------------------------
2288 clevermous 475
@@:
476
        mov     [edi], dword 2E002E00h; '..'
477
        add     edi, 4
478
        jmp     .cd_get_parameters_of_file_2
4700 mario79 479
;--------------------------------------
2288 clevermous 480
.end_buffer:
481
        pop     edx edi esi eax
482
        ret
4700 mario79 483
;-----------------------------------------------------------------------------
2288 clevermous 484
cd_get_parameters_of_file:
485
        mov     edi, [cd_mem_location]
486
cd_get_parameters_of_file_1:
4700 mario79 487
; get file attributes
2288 clevermous 488
        xor     eax, eax
4700 mario79 489
; file is not archived
2288 clevermous 490
        inc     eax
491
        shl     eax, 1
4700 mario79 492
; is a directory?
2288 clevermous 493
        test    [ebp-8], byte 2
494
        jz      .file
4700 mario79 495
 
2288 clevermous 496
        inc     eax
4700 mario79 497
;--------------------------------------
2288 clevermous 498
.file:
4700 mario79 499
; not as a volume label in the FAT, in this form not available
500
; file is not a system
2288 clevermous 501
        shl     eax, 3
4700 mario79 502
; file is hidden? (attribute of existence)
2288 clevermous 503
        test    [ebp-8], byte 1
504
        jz      .hidden
4700 mario79 505
 
2288 clevermous 506
        inc     eax
4700 mario79 507
;--------------------------------------
2288 clevermous 508
.hidden:
509
        shl     eax, 1
4700 mario79 510
; file is always read-only, as this CD
2288 clevermous 511
        inc     eax
512
        mov     [edi], eax
4700 mario79 513
; get the time to file
514
; hour
2288 clevermous 515
        movzx   eax, byte [ebp-12]
516
        shl     eax, 8
4700 mario79 517
; minute
2288 clevermous 518
        mov     al, [ebp-11]
519
        shl     eax, 8
4700 mario79 520
; second
2288 clevermous 521
        mov     al, [ebp-10]
4700 mario79 522
; file creation time
2288 clevermous 523
        mov     [edi+8], eax
4700 mario79 524
; last access time
2288 clevermous 525
        mov     [edi+16], eax
4700 mario79 526
; last write time
2288 clevermous 527
        mov     [edi+24], eax
4700 mario79 528
; get date for file
529
; year
2288 clevermous 530
        movzx   eax, byte [ebp-15]
531
        add     eax, 1900
532
        shl     eax, 8
4700 mario79 533
; month
2288 clevermous 534
        mov     al, [ebp-14]
535
        shl     eax, 8
4700 mario79 536
; day
2288 clevermous 537
        mov     al, [ebp-13]
4700 mario79 538
; file creation date
2288 clevermous 539
        mov     [edi+12], eax
4700 mario79 540
; last access date
2288 clevermous 541
        mov     [edi+20], eax
6468 pathoswith 542
; last write date
2288 clevermous 543
        mov     [edi+28], eax
4700 mario79 544
; get the data type of name
2288 clevermous 545
        xor     eax, eax
546
        test    dword [ebx+4], 1; 0=ANSI, 1=UNICODE
547
        jnz     .unicode_1
4700 mario79 548
 
2288 clevermous 549
        mov     [edi+4], eax
550
        jmp     @f
4700 mario79 551
;--------------------------------------
2288 clevermous 552
.unicode_1:
553
        inc     eax
554
        mov     [edi+4], eax
4700 mario79 555
;--------------------------------------
2288 clevermous 556
@@:
4700 mario79 557
; get the file size in bytes
2288 clevermous 558
        xor     eax, eax
559
        mov     [edi+32+4], eax
560
        mov     eax, [ebp-23]
561
        mov     [edi+32], eax
562
        ret
6468 pathoswith 563
 
4700 mario79 564
;-----------------------------------------------------------------------------
2288 clevermous 565
fs_CdGetFileInfo:
566
        cmp     byte [esi], 0
567
        jnz     @f
4700 mario79 568
 
2288 clevermous 569
        mov     eax, 2
570
        ret
4700 mario79 571
;--------------------------------------
2288 clevermous 572
@@:
573
        push    edi
574
        call    cd_find_lfn
575
        pushfd
576
        cmp     [DevErrorCode], 0
577
        jz      @f
4700 mario79 578
 
2288 clevermous 579
        popfd
580
        pop     edi
581
        mov     eax, 11
582
        ret
4700 mario79 583
;--------------------------------------
2288 clevermous 584
@@:
585
        popfd
586
        jnc     @f
4700 mario79 587
 
2288 clevermous 588
        pop     edi
589
        mov     eax, ERROR_FILE_NOT_FOUND
590
        ret
4700 mario79 591
;--------------------------------------
2288 clevermous 592
@@:
593
 
594
        mov     edi, edx
595
        push    ebp
596
        mov     ebp, [cd_current_pointer_of_input]
597
        add     ebp, 33
598
        call    cd_get_parameters_of_file_1
599
        pop     ebp
600
        and     dword [edi+4], 0
601
        pop     edi
602
        xor     eax, eax
603
        ret
4700 mario79 604
;-----------------------------------------------------------------------------
2288 clevermous 605
cd_find_lfn:
606
        mov     [cd_appl_data], 0
6471 pathoswith 607
; in: esi -> path string in UTF-8
608
; out: [cd_current_pointer_of_input] -> direntry, CF=1 -> file not found
2288 clevermous 609
        push    eax esi
4700 mario79 610
; Sector 16 - start set of volume descriptors
2288 clevermous 611
        call    WaitUnitReady
612
        cmp     [DevErrorCode], 0
613
        jne     .access_denied
614
 
615
        call    prevent_medium_removal
4700 mario79 616
; testing of reading
2288 clevermous 617
        mov     [CDSectorAddress], dword 16
618
        mov     [CDDataBuf_pointer], CDDataBuf
619
        call    ReadCDWRetr;_1
620
        cmp     [DevErrorCode], 0
621
        jne     .access_denied
622
 
4700 mario79 623
; calculation of the last session
2288 clevermous 624
        call    WaitUnitReady
625
        cmp     [DevErrorCode], 0
626
        jne     .access_denied
4700 mario79 627
 
2288 clevermous 628
        call    Read_TOC
629
        mov     ah, [CDDataBuf+4+4]
630
        mov     al, [CDDataBuf+4+5]
631
        shl     eax, 16
632
        mov     ah, [CDDataBuf+4+6]
633
        mov     al, [CDDataBuf+4+7]
634
        add     eax, 15
635
        mov     [CDSectorAddress], eax
636
;  mov  [CDSectorAddress],dword 15
637
        mov     [CDDataBuf_pointer], CDDataBuf
4700 mario79 638
;--------------------------------------
2288 clevermous 639
.start:
640
        inc     dword [CDSectorAddress]
641
        call    ReadCDWRetr;_1
642
        cmp     [DevErrorCode], 0
643
        jne     .access_denied
644
 
645
.start_check:
4700 mario79 646
; checking for "lice"
2288 clevermous 647
        cmp     [CDDataBuf+1], dword 'CD00'
648
        jne     .access_denied
4700 mario79 649
 
2288 clevermous 650
        cmp     [CDDataBuf+5], byte '1'
651
        jne     .access_denied
4700 mario79 652
; sector is the terminator of set of descriptors volumes?
2288 clevermous 653
        cmp     [CDDataBuf], byte 0xff
654
        je      .access_denied
4700 mario79 655
; sector is an additional and improved descriptor of volume?
2288 clevermous 656
        cmp     [CDDataBuf], byte 0x2
657
        jne     .start
4700 mario79 658
; sector is an additional descriptor of volume?
2288 clevermous 659
        cmp     [CDDataBuf+6], byte 0x1
660
        jne     .start
661
 
4700 mario79 662
; parameters of root directory
663
        mov     eax, [CDDataBuf+0x9c+2]; start of root directory
2288 clevermous 664
        mov     [CDSectorAddress], eax
4700 mario79 665
        mov     eax, [CDDataBuf+0x9c+10]; size of root directory
2288 clevermous 666
        cmp     byte [esi], 0
667
        jnz     @f
4700 mario79 668
 
2288 clevermous 669
        mov     [cd_current_pointer_of_input], CDDataBuf+0x9c
670
        jmp     .done
4700 mario79 671
;--------------------------------------
2288 clevermous 672
@@:
4700 mario79 673
; start the search
2288 clevermous 674
.mainloop:
675
        dec     dword [CDSectorAddress]
4700 mario79 676
;--------------------------------------
2288 clevermous 677
.read_to_buffer:
678
        inc     dword [CDSectorAddress]
679
        mov     [CDDataBuf_pointer], CDDataBuf
4700 mario79 680
        call    ReadCDWRetr      ; read sector of directory
2288 clevermous 681
        cmp     [DevErrorCode], 0
682
        jne     .access_denied
683
        call    cd_find_name_in_buffer
684
        jnc     .found
685
        sub     eax, 2048
4700 mario79 686
; directory is over?
2288 clevermous 687
        cmp     eax, 0
688
        ja      .read_to_buffer
4700 mario79 689
; desired element of chain is not found
2288 clevermous 690
.access_denied:
691
        pop     esi eax
692
        mov     [cd_appl_data], 1
693
        stc
694
        ret
4700 mario79 695
;--------------------------------------
696
; desired element of chain found
697
.found:
698
; the end of the file path
2288 clevermous 699
        cmp     byte [esi-1], 0
700
        jz      .done
701
        mov     eax, [cd_current_pointer_of_input]
702
        push    dword [eax+2]
4700 mario79 703
        pop     dword [CDSectorAddress] ; beginning of the directory
704
        mov     eax, [eax+2+8] ; size of directory
2288 clevermous 705
        jmp     .mainloop
4700 mario79 706
;--------------------------------------
707
; file pointer found
708
.done:
2288 clevermous 709
        pop     esi eax
710
        mov     [cd_appl_data], 1
711
        clc
712
        ret
4700 mario79 713
;-----------------------------------------------------------------------------
2288 clevermous 714
cd_find_name_in_buffer:
715
        mov     [cd_current_pointer_of_input_2], CDDataBuf
4700 mario79 716
;--------------------------------------
2288 clevermous 717
.start:
718
        call    cd_get_name
719
        jc      .not_found
4700 mario79 720
 
2288 clevermous 721
        call    cd_compare_name
722
        jc      .start
4700 mario79 723
;--------------------------------------
2288 clevermous 724
.found:
725
        clc
726
        ret
4700 mario79 727
;--------------------------------------
2288 clevermous 728
.not_found:
729
        stc
730
        ret
4700 mario79 731
;-----------------------------------------------------------------------------
2288 clevermous 732
cd_get_name:
733
        push    eax
734
        mov     ebp, [cd_current_pointer_of_input_2]
735
        mov     [cd_current_pointer_of_input], ebp
736
        mov     eax, [ebp]
4700 mario79 737
        test    eax, eax ; entry's is over?
2288 clevermous 738
        jz      .next_sector
4700 mario79 739
 
740
        cmp     ebp, CDDataBuf+2048  ; buffer is over?
2288 clevermous 741
        jae     .next_sector
4700 mario79 742
 
2288 clevermous 743
        movzx   eax, byte [ebp]
4700 mario79 744
        add     [cd_current_pointer_of_input_2], eax ; next entry of directory
745
        add     ebp, 33; pointer is set to the beginning of the name
2288 clevermous 746
        pop     eax
747
        clc
748
        ret
4700 mario79 749
;--------------------------------------
2288 clevermous 750
.next_sector:
751
        pop     eax
752
        stc
753
        ret
4700 mario79 754
;-----------------------------------------------------------------------------
2288 clevermous 755
cd_compare_name:
6471 pathoswith 756
; in: esi -> UTF-8 name, ebp -> UTF-16BE name
757
; out: CF=0 -> names match, esi -> next component of name
758
;      CF=1 -> esi is not changed
759
        push    edx edi eax esi
2288 clevermous 760
        mov     edi, ebp
761
.loop:
6471 pathoswith 762
        call    utf8to16
763
        call    utf16toUpper
764
        mov     edx, eax
765
        mov     ax, [edi]
766
        xchg    al, ah
767
        call    utf16toUpper
768
        cmp     ax, dx
2288 clevermous 769
        jne     .name_not_coincide
6471 pathoswith 770
        add     edi, 2
4700 mario79 771
        cmp     [esi], byte '/' ; path separator is end of current element
2288 clevermous 772
        je      .done
4700 mario79 773
        cmp     [esi], byte 0 ; path separator end of name
6471 pathoswith 774
        jne     .loop
2288 clevermous 775
.done:
4700 mario79 776
; check end of file
777
        cmp     [edi], word 3B00h; separator end of file ';'
2288 clevermous 778
        je      .done_1
4700 mario79 779
; check for files not ending with separator
2288 clevermous 780
        movzx   eax, byte [ebp-33]
781
        add     eax, ebp
782
        sub     eax, 34
783
        cmp     edi, eax
784
        je      .done_1
4700 mario79 785
; check the end of directory
2288 clevermous 786
        movzx   eax, byte [ebp-1]
787
        add     eax, ebp
788
        cmp     edi, eax
789
        jne     .name_not_coincide
790
.done_1:
6471 pathoswith 791
        pop     eax eax edi edx
2288 clevermous 792
        inc     esi
793
        ret
6471 pathoswith 794
 
795
.name_not_coincide:
796
        pop     esi eax edi edx
797
        stc
798
        ret