Subversion Repositories Kolibri OS

Rev

Rev 6262 | Rev 6471 | 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: 6468 $
9
 
6468 pathoswith 10
; CD external functions
11
;   in:
12
; esi -> path string
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
6468 pathoswith 607
; in: esi -> path string
2288 clevermous 608
; out: CF=1 - file not found
609
; else CF=0 and [cd_current_pointer_of_input] direntry
610
        push    eax esi
4700 mario79 611
; Sector 16 - start set of volume descriptors
2288 clevermous 612
        call    WaitUnitReady
613
        cmp     [DevErrorCode], 0
614
        jne     .access_denied
615
 
616
        call    prevent_medium_removal
4700 mario79 617
; testing of reading
2288 clevermous 618
        mov     [CDSectorAddress], dword 16
619
        mov     [CDDataBuf_pointer], CDDataBuf
620
        call    ReadCDWRetr;_1
621
        cmp     [DevErrorCode], 0
622
        jne     .access_denied
623
 
4700 mario79 624
; calculation of the last session
2288 clevermous 625
        call    WaitUnitReady
626
        cmp     [DevErrorCode], 0
627
        jne     .access_denied
4700 mario79 628
 
2288 clevermous 629
        call    Read_TOC
630
        mov     ah, [CDDataBuf+4+4]
631
        mov     al, [CDDataBuf+4+5]
632
        shl     eax, 16
633
        mov     ah, [CDDataBuf+4+6]
634
        mov     al, [CDDataBuf+4+7]
635
        add     eax, 15
636
        mov     [CDSectorAddress], eax
637
;  mov  [CDSectorAddress],dword 15
638
        mov     [CDDataBuf_pointer], CDDataBuf
4700 mario79 639
;--------------------------------------
2288 clevermous 640
.start:
641
        inc     dword [CDSectorAddress]
642
        call    ReadCDWRetr;_1
643
        cmp     [DevErrorCode], 0
644
        jne     .access_denied
645
 
646
.start_check:
4700 mario79 647
; checking for "lice"
2288 clevermous 648
        cmp     [CDDataBuf+1], dword 'CD00'
649
        jne     .access_denied
4700 mario79 650
 
2288 clevermous 651
        cmp     [CDDataBuf+5], byte '1'
652
        jne     .access_denied
4700 mario79 653
; sector is the terminator of set of descriptors volumes?
2288 clevermous 654
        cmp     [CDDataBuf], byte 0xff
655
        je      .access_denied
4700 mario79 656
; sector is an additional and improved descriptor of volume?
2288 clevermous 657
        cmp     [CDDataBuf], byte 0x2
658
        jne     .start
4700 mario79 659
; sector is an additional descriptor of volume?
2288 clevermous 660
        cmp     [CDDataBuf+6], byte 0x1
661
        jne     .start
662
 
4700 mario79 663
; parameters of root directory
664
        mov     eax, [CDDataBuf+0x9c+2]; start of root directory
2288 clevermous 665
        mov     [CDSectorAddress], eax
4700 mario79 666
        mov     eax, [CDDataBuf+0x9c+10]; size of root directory
2288 clevermous 667
        cmp     byte [esi], 0
668
        jnz     @f
4700 mario79 669
 
2288 clevermous 670
        mov     [cd_current_pointer_of_input], CDDataBuf+0x9c
671
        jmp     .done
4700 mario79 672
;--------------------------------------
2288 clevermous 673
@@:
4700 mario79 674
; start the search
2288 clevermous 675
.mainloop:
676
        dec     dword [CDSectorAddress]
4700 mario79 677
;--------------------------------------
2288 clevermous 678
.read_to_buffer:
679
        inc     dword [CDSectorAddress]
680
        mov     [CDDataBuf_pointer], CDDataBuf
4700 mario79 681
        call    ReadCDWRetr      ; read sector of directory
2288 clevermous 682
        cmp     [DevErrorCode], 0
683
        jne     .access_denied
684
        call    cd_find_name_in_buffer
685
        jnc     .found
686
        sub     eax, 2048
4700 mario79 687
; directory is over?
2288 clevermous 688
        cmp     eax, 0
689
        ja      .read_to_buffer
4700 mario79 690
; desired element of chain is not found
2288 clevermous 691
.access_denied:
692
        pop     esi eax
693
        mov     [cd_appl_data], 1
694
        stc
695
        ret
4700 mario79 696
;--------------------------------------
697
; desired element of chain found
698
.found:
699
; the end of the file path
2288 clevermous 700
        cmp     byte [esi-1], 0
701
        jz      .done
702
        mov     eax, [cd_current_pointer_of_input]
703
        push    dword [eax+2]
4700 mario79 704
        pop     dword [CDSectorAddress] ; beginning of the directory
705
        mov     eax, [eax+2+8] ; size of directory
2288 clevermous 706
        jmp     .mainloop
4700 mario79 707
;--------------------------------------
708
; file pointer found
709
.done:
2288 clevermous 710
        pop     esi eax
711
        mov     [cd_appl_data], 1
712
        clc
713
        ret
4700 mario79 714
;-----------------------------------------------------------------------------
2288 clevermous 715
cd_find_name_in_buffer:
716
        mov     [cd_current_pointer_of_input_2], CDDataBuf
4700 mario79 717
;--------------------------------------
2288 clevermous 718
.start:
719
        call    cd_get_name
720
        jc      .not_found
4700 mario79 721
 
2288 clevermous 722
        call    cd_compare_name
723
        jc      .start
4700 mario79 724
;--------------------------------------
2288 clevermous 725
.found:
726
        clc
727
        ret
4700 mario79 728
;--------------------------------------
2288 clevermous 729
.not_found:
730
        stc
731
        ret
4700 mario79 732
;-----------------------------------------------------------------------------
2288 clevermous 733
cd_get_name:
734
        push    eax
735
        mov     ebp, [cd_current_pointer_of_input_2]
736
        mov     [cd_current_pointer_of_input], ebp
737
        mov     eax, [ebp]
4700 mario79 738
        test    eax, eax ; entry's is over?
2288 clevermous 739
        jz      .next_sector
4700 mario79 740
 
741
        cmp     ebp, CDDataBuf+2048  ; buffer is over?
2288 clevermous 742
        jae     .next_sector
4700 mario79 743
 
2288 clevermous 744
        movzx   eax, byte [ebp]
4700 mario79 745
        add     [cd_current_pointer_of_input_2], eax ; next entry of directory
746
        add     ebp, 33; pointer is set to the beginning of the name
2288 clevermous 747
        pop     eax
748
        clc
749
        ret
4700 mario79 750
;--------------------------------------
2288 clevermous 751
.next_sector:
752
        pop     eax
753
        stc
754
        ret
4700 mario79 755
;-----------------------------------------------------------------------------
2288 clevermous 756
cd_compare_name:
757
; compares ASCIIZ-names, case-insensitive (cp866 encoding)
758
; in: esi->name, ebp->name
759
; out: if names match: ZF=1 and esi->next component of name
760
;      else: ZF=0, esi is not changed
761
; destroys eax
762
        push    esi eax edi
763
        mov     edi, ebp
4700 mario79 764
;--------------------------------------
2288 clevermous 765
.loop:
766
        cld
767
        lodsb
768
        push    eax
769
        call    char_todown
770
        call    ansi2uni_char
771
        xchg    ah, al
772
        scasw
773
        pop     eax
774
        je      .coincides
775
        call    char_toupper
776
        call    ansi2uni_char
777
        xchg    ah, al
778
        sub     edi, 2
779
        scasw
780
        jne     .name_not_coincide
4700 mario79 781
;--------------------------------------
2288 clevermous 782
.coincides:
4700 mario79 783
        cmp     [esi], byte '/' ; path separator is end of current element
2288 clevermous 784
        je      .done
4700 mario79 785
 
786
        cmp     [esi], byte 0 ; path separator end of name
2288 clevermous 787
        je      .done
4700 mario79 788
 
2288 clevermous 789
        jmp     .loop
4700 mario79 790
;--------------------------------------
2288 clevermous 791
.name_not_coincide:
792
        pop     edi eax esi
793
        stc
794
        ret
4700 mario79 795
;--------------------------------------
2288 clevermous 796
.done:
4700 mario79 797
; check end of file
798
        cmp     [edi], word 3B00h; separator end of file ';'
2288 clevermous 799
        je      .done_1
4700 mario79 800
; check for files not ending with separator
2288 clevermous 801
        movzx   eax, byte [ebp-33]
802
        add     eax, ebp
803
        sub     eax, 34
804
        cmp     edi, eax
805
        je      .done_1
4700 mario79 806
; check the end of directory
2288 clevermous 807
        movzx   eax, byte [ebp-1]
808
        add     eax, ebp
809
        cmp     edi, eax
810
        jne     .name_not_coincide
4700 mario79 811
;--------------------------------------
2288 clevermous 812
.done_1:
813
        pop     edi eax
814
        add     esp, 4
815
        inc     esi
816
        clc
817
        ret