Subversion Repositories Kolibri OS

Rev

Rev 4700 | Rev 6262 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5363 yogev_ezra 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
8
$Revision: 5363 $
9
 
4700 mario79 10
;-----------------------------------------------------------------------------
2288 clevermous 11
uglobal
12
cd_current_pointer_of_input    dd  0
13
cd_current_pointer_of_input_2  dd  0
14
cd_mem_location                dd  0
15
cd_counter_block               dd  0
16
endg
4700 mario79 17
;-----------------------------------------------------------------------------
2288 clevermous 18
reserve_cd:
19
        cli
20
        cmp     [cd_status], 0
21
        je      reserve_ok2
22
 
23
        sti
24
        call    change_task
25
        jmp     reserve_cd
4700 mario79 26
;-----------------------------------------------------------------------------
27
reserve_ok2:
2288 clevermous 28
        push    eax
29
        mov     eax, [CURRENT_TASK]
30
        shl     eax, 5
31
        mov     eax, [eax+CURRENT_TASK+TASKDATA.pid]
32
        mov     [cd_status], eax
33
        pop     eax
34
        sti
35
        ret
4700 mario79 36
;-----------------------------------------------------------------------------
37
reserve_cd_channel:
38
        pushad
39
        mov     eax, [cdpos]
40
        dec     eax
41
        shr     eax, 2
2288 clevermous 42
 
4700 mario79 43
        test    eax, eax
44
        jnz     .1
45
 
2288 clevermous 46
        cmp     [ChannelNumber], 1
4700 mario79 47
        jne     @f
48
 
3742 clevermous 49
        mov     ecx, ide_channel1_mutex
4700 mario79 50
        jmp     .mutex_lock
51
;--------------------------------------
52
@@:
53
        mov     ecx, ide_channel2_mutex
54
        jmp     .mutex_lock
55
;--------------------------------------
56
.1:
57
        dec     eax
58
        jnz     .2
59
 
60
        cmp     [ChannelNumber], 1
61
        jne     @f
62
 
63
        mov     ecx, ide_channel3_mutex
64
        jmp     .mutex_lock
65
;--------------------------------------
66
@@:
67
        mov     ecx, ide_channel4_mutex
68
        jmp     .mutex_lock
69
;--------------------------------------
70
.2:
71
        cmp     [ChannelNumber], 1
72
        jne     @f
73
 
74
        mov     ecx, ide_channel5_mutex
75
        jmp     .mutex_lock
76
;--------------------------------------
77
@@:
78
        mov     ecx, ide_channel6_mutex
79
.mutex_lock:
3742 clevermous 80
        call    mutex_lock
81
        popad
2288 clevermous 82
        ret
4700 mario79 83
;-----------------------------------------------------------------------------
84
free_cd_channel:
3742 clevermous 85
        pushad
4700 mario79 86
        mov     eax, [cdpos]
87
        dec     eax
88
        shr     eax, 2
2288 clevermous 89
 
4700 mario79 90
        test    eax, eax
91
        jnz     .1
92
 
2288 clevermous 93
        cmp     [ChannelNumber], 1
4700 mario79 94
        jne     @f
95
 
3742 clevermous 96
        mov     ecx, ide_channel1_mutex
4700 mario79 97
        jmp     .mutex_unlock
98
;--------------------------------------
99
@@:
3742 clevermous 100
        mov     ecx, ide_channel2_mutex
4700 mario79 101
        jmp     .mutex_unlock
102
;--------------------------------------
103
.1:
104
        dec     eax
105
        jnz     .2
106
 
107
        cmp     [ChannelNumber], 1
108
        jne     @f
109
 
110
        mov     ecx, ide_channel3_mutex
111
        jmp     .mutex_unlock
112
;--------------------------------------
113
@@:
114
        mov     ecx, ide_channel4_mutex
115
        jmp     .mutex_unlock
116
;--------------------------------------
117
.2:
118
        cmp     [ChannelNumber], 1
119
        jne     @f
120
 
121
        mov     ecx, ide_channel5_mutex
122
        jmp     .mutex_unlock
123
;--------------------------------------
124
@@:
125
        mov     ecx, ide_channel6_mutex
126
.mutex_unlock:
3742 clevermous 127
        call    mutex_unlock
128
        popad
2288 clevermous 129
        ret
4700 mario79 130
;-----------------------------------------------------------------------------
2288 clevermous 131
uglobal
132
cd_status dd 0
133
endg
4700 mario79 134
;-----------------------------------------------------------------------------
2288 clevermous 135
;
136
;  fs_CdRead - LFN variant for reading CD disk
137
;
138
;  esi  points to filename /dir1/dir2/.../dirn/file,0
139
;  ebx  pointer to 64-bit number = first wanted byte, 0+
140
;       may be ebx=0 - start from first byte
141
;  ecx  number of bytes to read, 0+
142
;  edx  mem location to return data
143
;
144
;  ret ebx = bytes read or 0xffffffff file not found
145
;      eax = 0 ok read or other = errormsg
146
;
4700 mario79 147
;-----------------------------------------------------------------------------
2288 clevermous 148
fs_CdRead:
149
        push    edi
150
        cmp     byte [esi], 0
151
        jnz     @f
4700 mario79 152
;--------------------------------------
2288 clevermous 153
.noaccess:
154
        pop     edi
4700 mario79 155
;--------------------------------------
2288 clevermous 156
.noaccess_2:
157
        or      ebx, -1
158
        mov     eax, ERROR_ACCESS_DENIED
159
        ret
4700 mario79 160
;--------------------------------------
2288 clevermous 161
.noaccess_3:
162
        pop     eax edx ecx edi
163
        jmp     .noaccess_2
4700 mario79 164
;--------------------------------------
2288 clevermous 165
@@:
166
        call    cd_find_lfn
167
        jnc     .found
4700 mario79 168
 
2288 clevermous 169
        pop     edi
170
        cmp     [DevErrorCode], 0
171
        jne     .noaccess_2
4700 mario79 172
 
2288 clevermous 173
        or      ebx, -1
174
        mov     eax, ERROR_FILE_NOT_FOUND
175
        ret
4700 mario79 176
;--------------------------------------
2288 clevermous 177
.found:
178
        mov     edi, [cd_current_pointer_of_input]
179
        test    byte [edi+25], 10b; do not allow read directories
180
        jnz     .noaccess
4700 mario79 181
 
2288 clevermous 182
        test    ebx, ebx
183
        jz      .l1
4700 mario79 184
 
2288 clevermous 185
        cmp     dword [ebx+4], 0
186
        jz      @f
4700 mario79 187
 
2288 clevermous 188
        xor     ebx, ebx
4700 mario79 189
;--------------------------------------
2288 clevermous 190
.reteof:
191
        mov     eax, 6; end of file
192
        pop     edi
193
        ret
4700 mario79 194
;--------------------------------------
2288 clevermous 195
@@:
196
        mov     ebx, [ebx]
4700 mario79 197
;--------------------------------------
2288 clevermous 198
.l1:
199
        push    ecx edx
200
        push    0
4700 mario79 201
        mov     eax, [edi+10] ; real size of the file section
2288 clevermous 202
        sub     eax, ebx
203
        jb      .eof
4700 mario79 204
 
2288 clevermous 205
        cmp     eax, ecx
206
        jae     @f
4700 mario79 207
 
2288 clevermous 208
        mov     ecx, eax
209
        mov     byte [esp], 6
4700 mario79 210
;--------------------------------------
2288 clevermous 211
@@:
212
        mov     eax, [edi+2]
213
        mov     [CDSectorAddress], eax
4700 mario79 214
;--------------------------------------
2288 clevermous 215
; now eax=cluster, ebx=position, ecx=count, edx=buffer for data
216
.new_sector:
217
        test    ecx, ecx
218
        jz      .done
4700 mario79 219
 
2288 clevermous 220
        sub     ebx, 2048
221
        jae     .next
4700 mario79 222
 
2288 clevermous 223
        add     ebx, 2048
224
        jnz     .incomplete_sector
4700 mario79 225
 
2288 clevermous 226
        cmp     ecx, 2048
227
        jb      .incomplete_sector
228
; we may read and memmove complete sector
229
        mov     [CDDataBuf_pointer], edx
4700 mario79 230
        call    ReadCDWRetr ; read sector of file
2288 clevermous 231
        cmp     [DevErrorCode], 0
232
        jne     .noaccess_3
4700 mario79 233
 
2288 clevermous 234
        add     edx, 2048
235
        sub     ecx, 2048
4700 mario79 236
;--------------------------------------
2288 clevermous 237
.next:
238
        inc     dword [CDSectorAddress]
239
        jmp     .new_sector
4700 mario79 240
;--------------------------------------
2288 clevermous 241
.incomplete_sector:
242
; we must read and memmove incomplete sector
243
        mov     [CDDataBuf_pointer], CDDataBuf
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
        push    ecx
249
        add     ecx, ebx
250
        cmp     ecx, 2048
251
        jbe     @f
4700 mario79 252
 
2288 clevermous 253
        mov     ecx, 2048
4700 mario79 254
;--------------------------------------
2288 clevermous 255
@@:
256
        sub     ecx, ebx
257
        push    edi esi ecx
258
        mov     edi, edx
259
        lea     esi, [CDDataBuf + ebx]
260
        cld
261
        rep movsb
262
        pop     ecx esi edi
263
        add     edx, ecx
264
        sub     [esp], ecx
265
        pop     ecx
266
        xor     ebx, ebx
267
        jmp     .next
4700 mario79 268
;--------------------------------------
2288 clevermous 269
.done:
270
        mov     ebx, edx
271
        pop     eax edx ecx edi
272
        sub     ebx, edx
273
        ret
4700 mario79 274
;--------------------------------------
2288 clevermous 275
.eof:
276
        mov     ebx, edx
277
        pop     eax edx ecx
278
        sub     ebx, edx
279
        jmp     .reteof
4700 mario79 280
;-----------------------------------------------------------------------------
2288 clevermous 281
;
282
;  fs_CdReadFolder - LFN variant for reading CD disk folder
283
;
284
;  esi  points to filename  /dir1/dir2/.../dirn/file,0
285
;  ebx  pointer to structure 32-bit number = first wanted block, 0+
286
;                          & flags (bitfields)
287
; flags: bit 0: 0=ANSI names, 1=UNICODE names
288
;  ecx  number of blocks to read, 0+
289
;  edx  mem location to return data
290
;
291
;  ret ebx = blocks read or 0xffffffff folder not found
292
;      eax = 0 ok read or other = errormsg
293
;
4700 mario79 294
;-----------------------------------------------------------------------------
2288 clevermous 295
fs_CdReadFolder:
296
        push    edi
297
        call    cd_find_lfn
298
        jnc     .found
4700 mario79 299
 
2288 clevermous 300
        pop     edi
301
        cmp     [DevErrorCode], 0
302
        jne     .noaccess_1
4700 mario79 303
 
2288 clevermous 304
        or      ebx, -1
305
        mov     eax, ERROR_FILE_NOT_FOUND
306
        ret
4700 mario79 307
;--------------------------------------
2288 clevermous 308
.found:
309
        mov     edi, [cd_current_pointer_of_input]
310
        test    byte [edi+25], 10b    ; do not allow read directories
311
        jnz     .found_dir
4700 mario79 312
 
2288 clevermous 313
        pop     edi
4700 mario79 314
;--------------------------------------
2288 clevermous 315
.noaccess_1:
316
        or      ebx, -1
317
        mov     eax, ERROR_ACCESS_DENIED
318
        ret
4700 mario79 319
;--------------------------------------
2288 clevermous 320
.found_dir:
321
        mov     eax, [edi+2]    ; eax=cluster
322
        mov     [CDSectorAddress], eax
4700 mario79 323
        mov     eax, [edi+10]   ; directory size
324
;--------------------------------------
2288 clevermous 325
.doit:
326
; init header
327
        push    eax ecx
328
        mov     edi, edx
329
        mov     ecx, 32/4
330
        xor     eax, eax
331
        rep stosd
332
        pop     ecx eax
333
        mov     byte [edx], 1   ; version
334
        mov     [cd_mem_location], edx
335
        add     [cd_mem_location], 32
336
;.mainloop:
337
        mov     [cd_counter_block], dword 0
338
        dec     dword [CDSectorAddress]
339
        push    ecx
4700 mario79 340
;--------------------------------------
2288 clevermous 341
.read_to_buffer:
342
        inc     dword [CDSectorAddress]
343
        mov     [CDDataBuf_pointer], CDDataBuf
4700 mario79 344
        call    ReadCDWRetr         ; read sector of directory
2288 clevermous 345
        cmp     [DevErrorCode], 0
346
        jne     .noaccess_1
4700 mario79 347
 
2288 clevermous 348
        call    .get_names_from_buffer
349
        sub     eax, 2048
4700 mario79 350
; directory is over?
2288 clevermous 351
        ja      .read_to_buffer
4700 mario79 352
 
2288 clevermous 353
        mov     edi, [cd_counter_block]
354
        mov     [edx+8], edi
355
        mov     edi, [ebx]
356
        sub     [edx+4], edi
357
        xor     eax, eax
358
        dec     ecx
359
        js      @f
4700 mario79 360
 
2288 clevermous 361
        mov     al, ERROR_END_OF_FILE
4700 mario79 362
;--------------------------------------
2288 clevermous 363
@@:
364
        pop     ecx edi
365
        mov     ebx, [edx+4]
366
        ret
4700 mario79 367
;--------------------------------------
2288 clevermous 368
.get_names_from_buffer:
369
        mov     [cd_current_pointer_of_input_2], CDDataBuf
370
        push    eax esi edi edx
4700 mario79 371
;--------------------------------------
2288 clevermous 372
.get_names_from_buffer_1:
373
        call    cd_get_name
374
        jc      .end_buffer
4700 mario79 375
 
2288 clevermous 376
        inc     dword [cd_counter_block]
377
        mov     eax, [cd_counter_block]
378
        cmp     [ebx], eax
379
        jae     .get_names_from_buffer_1
4700 mario79 380
 
2288 clevermous 381
        test    ecx, ecx
382
        jz      .get_names_from_buffer_1
4700 mario79 383
 
2288 clevermous 384
        mov     edi, [cd_counter_block]
385
        mov     [edx+4], edi
386
        dec     ecx
387
        mov     esi, ebp
388
        mov     edi, [cd_mem_location]
389
        add     edi, 40
390
        test    dword [ebx+4], 1; 0=ANSI, 1=UNICODE
391
        jnz     .unicode
4700 mario79 392
;--------------------------------------
2288 clevermous 393
.ansi:
394
        cmp     [cd_counter_block], 2
395
        jbe     .ansi_parent_directory
4700 mario79 396
 
2288 clevermous 397
        cld
398
        lodsw
399
        xchg    ah, al
400
        call    uni2ansi_char
401
        cld
402
        stosb
4700 mario79 403
; check end of file
2288 clevermous 404
        mov     ax, [esi]
4700 mario79 405
        cmp     ax, word 3B00h ; separator end of file ';'
2288 clevermous 406
        je      .cd_get_parameters_of_file_1
4700 mario79 407
; check for files not ending with separator
2288 clevermous 408
        movzx   eax, byte [ebp-33]
409
        add     eax, ebp
410
        sub     eax, 34
411
        cmp     esi, eax
412
        je      .cd_get_parameters_of_file_1
4700 mario79 413
; check the end of the directory
2288 clevermous 414
        movzx   eax, byte [ebp-1]
415
        add     eax, ebp
416
        cmp     esi, eax
417
        jb      .ansi
4700 mario79 418
;--------------------------------------
2288 clevermous 419
.cd_get_parameters_of_file_1:
420
        mov     [edi], byte 0
421
        call    cd_get_parameters_of_file
422
        add     [cd_mem_location], 304
423
        jmp     .get_names_from_buffer_1
4700 mario79 424
;--------------------------------------
2288 clevermous 425
.ansi_parent_directory:
426
        cmp     [cd_counter_block], 2
427
        je      @f
4700 mario79 428
 
2288 clevermous 429
        mov     [edi], byte '.'
430
        inc     edi
431
        jmp     .cd_get_parameters_of_file_1
4700 mario79 432
;--------------------------------------
2288 clevermous 433
@@:
434
        mov     [edi], word '..'
435
        add     edi, 2
436
        jmp     .cd_get_parameters_of_file_1
4700 mario79 437
;--------------------------------------
2288 clevermous 438
.unicode:
439
        cmp     [cd_counter_block], 2
440
        jbe     .unicode_parent_directory
4700 mario79 441
 
2288 clevermous 442
        cld
443
        movsw
4700 mario79 444
; check end of file
2288 clevermous 445
        mov     ax, [esi]
4700 mario79 446
        cmp     ax, word 3B00h; separator end of file ';'
2288 clevermous 447
        je      .cd_get_parameters_of_file_2
4700 mario79 448
; check for files not ending with separator
2288 clevermous 449
        movzx   eax, byte [ebp-33]
450
        add     eax, ebp
451
        sub     eax, 34
452
        cmp     esi, eax
453
        je      .cd_get_parameters_of_file_2
4700 mario79 454
; check the end of the directory
2288 clevermous 455
        movzx   eax, byte [ebp-1]
456
        add     eax, ebp
457
        cmp     esi, eax
458
        jb      .unicode
4700 mario79 459
;--------------------------------------
2288 clevermous 460
.cd_get_parameters_of_file_2:
461
        mov     [edi], word 0
462
        call    cd_get_parameters_of_file
463
        add     [cd_mem_location], 560
464
        jmp     .get_names_from_buffer_1
4700 mario79 465
;--------------------------------------
2288 clevermous 466
.unicode_parent_directory:
467
        cmp     [cd_counter_block], 2
468
        je      @f
4700 mario79 469
 
2288 clevermous 470
        mov     [edi], word 2E00h; '.'
471
        add     edi, 2
472
        jmp     .cd_get_parameters_of_file_2
4700 mario79 473
;--------------------------------------
2288 clevermous 474
@@:
475
        mov     [edi], dword 2E002E00h; '..'
476
        add     edi, 4
477
        jmp     .cd_get_parameters_of_file_2
4700 mario79 478
;--------------------------------------
2288 clevermous 479
.end_buffer:
480
        pop     edx edi esi eax
481
        ret
4700 mario79 482
;-----------------------------------------------------------------------------
2288 clevermous 483
cd_get_parameters_of_file:
484
        mov     edi, [cd_mem_location]
485
cd_get_parameters_of_file_1:
4700 mario79 486
; get file attributes
2288 clevermous 487
        xor     eax, eax
4700 mario79 488
; file is not archived
2288 clevermous 489
        inc     eax
490
        shl     eax, 1
4700 mario79 491
; is a directory?
2288 clevermous 492
        test    [ebp-8], byte 2
493
        jz      .file
4700 mario79 494
 
2288 clevermous 495
        inc     eax
4700 mario79 496
;--------------------------------------
2288 clevermous 497
.file:
4700 mario79 498
; not as a volume label in the FAT, in this form not available
499
; file is not a system
2288 clevermous 500
        shl     eax, 3
4700 mario79 501
; file is hidden? (attribute of existence)
2288 clevermous 502
        test    [ebp-8], byte 1
503
        jz      .hidden
4700 mario79 504
 
2288 clevermous 505
        inc     eax
4700 mario79 506
;--------------------------------------
2288 clevermous 507
.hidden:
508
        shl     eax, 1
4700 mario79 509
; file is always read-only, as this CD
2288 clevermous 510
        inc     eax
511
        mov     [edi], eax
4700 mario79 512
; get the time to file
513
; hour
2288 clevermous 514
        movzx   eax, byte [ebp-12]
515
        shl     eax, 8
4700 mario79 516
; minute
2288 clevermous 517
        mov     al, [ebp-11]
518
        shl     eax, 8
4700 mario79 519
; second
2288 clevermous 520
        mov     al, [ebp-10]
4700 mario79 521
; file creation time
2288 clevermous 522
        mov     [edi+8], eax
4700 mario79 523
; last access time
2288 clevermous 524
        mov     [edi+16], eax
4700 mario79 525
; last write time
2288 clevermous 526
        mov     [edi+24], eax
4700 mario79 527
; get date for file
528
; year
2288 clevermous 529
        movzx   eax, byte [ebp-15]
530
        add     eax, 1900
531
        shl     eax, 8
4700 mario79 532
; month
2288 clevermous 533
        mov     al, [ebp-14]
534
        shl     eax, 8
4700 mario79 535
; day
2288 clevermous 536
        mov     al, [ebp-13]
4700 mario79 537
; file creation date
2288 clevermous 538
        mov     [edi+12], eax
4700 mario79 539
; last access date
2288 clevermous 540
        mov     [edi+20], eax
4700 mario79 541
; last write date
2288 clevermous 542
        mov     [edi+28], eax
4700 mario79 543
; get the data type of name
2288 clevermous 544
        xor     eax, eax
545
        test    dword [ebx+4], 1; 0=ANSI, 1=UNICODE
546
        jnz     .unicode_1
4700 mario79 547
 
2288 clevermous 548
        mov     [edi+4], eax
549
        jmp     @f
4700 mario79 550
;--------------------------------------
2288 clevermous 551
.unicode_1:
552
        inc     eax
553
        mov     [edi+4], eax
4700 mario79 554
;--------------------------------------
2288 clevermous 555
@@:
4700 mario79 556
; get the file size in bytes
2288 clevermous 557
        xor     eax, eax
558
        mov     [edi+32+4], eax
559
        mov     eax, [ebp-23]
560
        mov     [edi+32], eax
561
        ret
4700 mario79 562
;-----------------------------------------------------------------------------
2288 clevermous 563
;
564
;  fs_CdGetFileInfo - LFN variant for CD
565
;                     get file/directory attributes structure
566
;
4700 mario79 567
;-----------------------------------------------------------------------------
2288 clevermous 568
fs_CdGetFileInfo:
569
        cmp     byte [esi], 0
570
        jnz     @f
4700 mario79 571
 
2288 clevermous 572
        mov     eax, 2
573
        ret
4700 mario79 574
;--------------------------------------
2288 clevermous 575
@@:
576
        push    edi
577
        call    cd_find_lfn
578
        pushfd
579
        cmp     [DevErrorCode], 0
580
        jz      @f
4700 mario79 581
 
2288 clevermous 582
        popfd
583
        pop     edi
584
        mov     eax, 11
585
        ret
4700 mario79 586
;--------------------------------------
2288 clevermous 587
@@:
588
        popfd
589
        jnc     @f
4700 mario79 590
 
2288 clevermous 591
        pop     edi
592
        mov     eax, ERROR_FILE_NOT_FOUND
593
        ret
4700 mario79 594
;--------------------------------------
2288 clevermous 595
@@:
596
 
597
        mov     edi, edx
598
        push    ebp
599
        mov     ebp, [cd_current_pointer_of_input]
600
        add     ebp, 33
601
        call    cd_get_parameters_of_file_1
602
        pop     ebp
603
        and     dword [edi+4], 0
604
        pop     edi
605
        xor     eax, eax
606
        ret
4700 mario79 607
;-----------------------------------------------------------------------------
2288 clevermous 608
cd_find_lfn:
609
        mov     [cd_appl_data], 0
610
; in: esi+ebp -> name
611
; out: CF=1 - file not found
612
; else CF=0 and [cd_current_pointer_of_input] direntry
613
        push    eax esi
4700 mario79 614
; Sector 16 - start set of volume descriptors
2288 clevermous 615
        call    WaitUnitReady
616
        cmp     [DevErrorCode], 0
617
        jne     .access_denied
618
 
619
        call    prevent_medium_removal
4700 mario79 620
; testing of reading
2288 clevermous 621
        mov     [CDSectorAddress], dword 16
622
        mov     [CDDataBuf_pointer], CDDataBuf
623
        call    ReadCDWRetr;_1
624
        cmp     [DevErrorCode], 0
625
        jne     .access_denied
626
 
4700 mario79 627
; calculation of the last session
2288 clevermous 628
        call    WaitUnitReady
629
        cmp     [DevErrorCode], 0
630
        jne     .access_denied
4700 mario79 631
 
2288 clevermous 632
        call    Read_TOC
633
        mov     ah, [CDDataBuf+4+4]
634
        mov     al, [CDDataBuf+4+5]
635
        shl     eax, 16
636
        mov     ah, [CDDataBuf+4+6]
637
        mov     al, [CDDataBuf+4+7]
638
        add     eax, 15
639
        mov     [CDSectorAddress], eax
640
;  mov  [CDSectorAddress],dword 15
641
        mov     [CDDataBuf_pointer], CDDataBuf
4700 mario79 642
;--------------------------------------
2288 clevermous 643
.start:
644
        inc     dword [CDSectorAddress]
645
        call    ReadCDWRetr;_1
646
        cmp     [DevErrorCode], 0
647
        jne     .access_denied
648
 
649
.start_check:
4700 mario79 650
; checking for "lice"
2288 clevermous 651
        cmp     [CDDataBuf+1], dword 'CD00'
652
        jne     .access_denied
4700 mario79 653
 
2288 clevermous 654
        cmp     [CDDataBuf+5], byte '1'
655
        jne     .access_denied
4700 mario79 656
; sector is the terminator of set of descriptors volumes?
2288 clevermous 657
        cmp     [CDDataBuf], byte 0xff
658
        je      .access_denied
4700 mario79 659
; sector is an additional and improved descriptor of volume?
2288 clevermous 660
        cmp     [CDDataBuf], byte 0x2
661
        jne     .start
4700 mario79 662
; sector is an additional descriptor of volume?
2288 clevermous 663
        cmp     [CDDataBuf+6], byte 0x1
664
        jne     .start
665
 
4700 mario79 666
; parameters of root directory
667
        mov     eax, [CDDataBuf+0x9c+2]; start of root directory
2288 clevermous 668
        mov     [CDSectorAddress], eax
4700 mario79 669
        mov     eax, [CDDataBuf+0x9c+10]; size of root directory
2288 clevermous 670
        cmp     byte [esi], 0
671
        jnz     @f
4700 mario79 672
 
2288 clevermous 673
        mov     [cd_current_pointer_of_input], CDDataBuf+0x9c
674
        jmp     .done
4700 mario79 675
;--------------------------------------
2288 clevermous 676
@@:
4700 mario79 677
; start the search
2288 clevermous 678
.mainloop:
679
        dec     dword [CDSectorAddress]
4700 mario79 680
;--------------------------------------
2288 clevermous 681
.read_to_buffer:
682
        inc     dword [CDSectorAddress]
683
        mov     [CDDataBuf_pointer], CDDataBuf
4700 mario79 684
        call    ReadCDWRetr      ; read sector of directory
2288 clevermous 685
        cmp     [DevErrorCode], 0
686
        jne     .access_denied
4700 mario79 687
 
2288 clevermous 688
        push    ebp
689
        call    cd_find_name_in_buffer
690
        pop     ebp
691
        jnc     .found
4700 mario79 692
 
2288 clevermous 693
        sub     eax, 2048
4700 mario79 694
; directory is over?
2288 clevermous 695
        cmp     eax, 0
696
        ja      .read_to_buffer
4700 mario79 697
; desired element of chain is not found
2288 clevermous 698
.access_denied:
699
        pop     esi eax
700
        mov     [cd_appl_data], 1
701
        stc
702
        ret
4700 mario79 703
;--------------------------------------
704
; desired element of chain found
705
.found:
706
; the end of the file path
2288 clevermous 707
        cmp     byte [esi-1], 0
708
        jz      .done
709
  .nested:
710
        mov     eax, [cd_current_pointer_of_input]
711
        push    dword [eax+2]
4700 mario79 712
        pop     dword [CDSectorAddress] ; beginning of the directory
713
        mov     eax, [eax+2+8] ; size of directory
2288 clevermous 714
        jmp     .mainloop
4700 mario79 715
;--------------------------------------
716
; file pointer found
717
.done:
2288 clevermous 718
        test    ebp, ebp
719
        jz      @f
4700 mario79 720
 
2288 clevermous 721
        mov     esi, ebp
722
        xor     ebp, ebp
723
        jmp     .nested
4700 mario79 724
;--------------------------------------
2288 clevermous 725
@@:
726
        pop     esi eax
727
        mov     [cd_appl_data], 1
728
        clc
729
        ret
4700 mario79 730
;-----------------------------------------------------------------------------
2288 clevermous 731
cd_find_name_in_buffer:
732
        mov     [cd_current_pointer_of_input_2], CDDataBuf
4700 mario79 733
;--------------------------------------
2288 clevermous 734
.start:
735
        call    cd_get_name
736
        jc      .not_found
4700 mario79 737
 
2288 clevermous 738
        call    cd_compare_name
739
        jc      .start
4700 mario79 740
;--------------------------------------
2288 clevermous 741
.found:
742
        clc
743
        ret
4700 mario79 744
;--------------------------------------
2288 clevermous 745
.not_found:
746
        stc
747
        ret
4700 mario79 748
;-----------------------------------------------------------------------------
2288 clevermous 749
cd_get_name:
750
        push    eax
751
        mov     ebp, [cd_current_pointer_of_input_2]
752
        mov     [cd_current_pointer_of_input], ebp
753
        mov     eax, [ebp]
4700 mario79 754
        test    eax, eax ; entry's is over?
2288 clevermous 755
        jz      .next_sector
4700 mario79 756
 
757
        cmp     ebp, CDDataBuf+2048  ; buffer is over?
2288 clevermous 758
        jae     .next_sector
4700 mario79 759
 
2288 clevermous 760
        movzx   eax, byte [ebp]
4700 mario79 761
        add     [cd_current_pointer_of_input_2], eax ; next entry of directory
762
        add     ebp, 33; pointer is set to the beginning of the name
2288 clevermous 763
        pop     eax
764
        clc
765
        ret
4700 mario79 766
;--------------------------------------
2288 clevermous 767
.next_sector:
768
        pop     eax
769
        stc
770
        ret
4700 mario79 771
;-----------------------------------------------------------------------------
2288 clevermous 772
cd_compare_name:
773
; compares ASCIIZ-names, case-insensitive (cp866 encoding)
774
; in: esi->name, ebp->name
775
; out: if names match: ZF=1 and esi->next component of name
776
;      else: ZF=0, esi is not changed
777
; destroys eax
778
        push    esi eax edi
779
        mov     edi, ebp
4700 mario79 780
;--------------------------------------
2288 clevermous 781
.loop:
782
        cld
783
        lodsb
784
        push    eax
785
        call    char_todown
786
        call    ansi2uni_char
787
        xchg    ah, al
788
        scasw
789
        pop     eax
790
        je      .coincides
791
        call    char_toupper
792
        call    ansi2uni_char
793
        xchg    ah, al
794
        sub     edi, 2
795
        scasw
796
        jne     .name_not_coincide
4700 mario79 797
;--------------------------------------
2288 clevermous 798
.coincides:
4700 mario79 799
        cmp     [esi], byte '/' ; path separator is end of current element
2288 clevermous 800
        je      .done
4700 mario79 801
 
802
        cmp     [esi], byte 0 ; path separator end of name
2288 clevermous 803
        je      .done
4700 mario79 804
 
2288 clevermous 805
        jmp     .loop
4700 mario79 806
;--------------------------------------
2288 clevermous 807
.name_not_coincide:
808
        pop     edi eax esi
809
        stc
810
        ret
4700 mario79 811
;--------------------------------------
2288 clevermous 812
.done:
4700 mario79 813
; check end of file
814
        cmp     [edi], word 3B00h; separator end of file ';'
2288 clevermous 815
        je      .done_1
4700 mario79 816
; check for files not ending with separator
2288 clevermous 817
        movzx   eax, byte [ebp-33]
818
        add     eax, ebp
819
        sub     eax, 34
820
        cmp     edi, eax
821
        je      .done_1
4700 mario79 822
; check the end of directory
2288 clevermous 823
        movzx   eax, byte [ebp-1]
824
        add     eax, ebp
825
        cmp     edi, eax
826
        jne     .name_not_coincide
4700 mario79 827
;--------------------------------------
2288 clevermous 828
.done_1:
829
        pop     edi eax
830
        add     esp, 4
831
        inc     esi
832
        clc
833
        ret
4700 mario79 834
;-----------------------------------------------------------------------------
2288 clevermous 835
char_todown:
836
; convert character to uppercase, using cp866 encoding
837
; in: al=symbol
838
; out: al=converted symbol
839
        cmp     al, 'A'
840
        jb      .ret
4700 mario79 841
 
2288 clevermous 842
        cmp     al, 'Z'
843
        jbe     .az
4700 mario79 844
 
3539 clevermous 845
        cmp     al, 0x80 ; 'А'
2288 clevermous 846
        jb      .ret
4700 mario79 847
 
3539 clevermous 848
        cmp     al, 0x90 ; 'Р'
2288 clevermous 849
        jb      .rus1
4700 mario79 850
 
3539 clevermous 851
        cmp     al, 0x9F ; 'Я'
2288 clevermous 852
        ja      .ret
853
; 0x90-0x9F -> 0xE0-0xEF
3539 clevermous 854
        add     al, 0xE0-0x90
4700 mario79 855
;--------------------------------------
2288 clevermous 856
.ret:
857
        ret
4700 mario79 858
;--------------------------------------
2288 clevermous 859
.rus1:
860
; 0x80-0x8F -> 0xA0-0xAF
861
.az:
862
        add     al, 0x20
863
        ret
4700 mario79 864
;-----------------------------------------------------------------------------
2288 clevermous 865
uni2ansi_char:
866
; convert UNICODE character in al to ANSI character in ax, using cp866 encoding
867
; in: ax=UNICODE character
868
; out: al=converted ANSI character
869
        cmp     ax, 0x80
870
        jb      .ascii
4700 mario79 871
 
2288 clevermous 872
        cmp     ax, 0x401
873
        jz      .yo1
4700 mario79 874
 
2288 clevermous 875
        cmp     ax, 0x451
876
        jz      .yo2
4700 mario79 877
 
2288 clevermous 878
        cmp     ax, 0x410
879
        jb      .unk
4700 mario79 880
 
2288 clevermous 881
        cmp     ax, 0x440
882
        jb      .rus1
4700 mario79 883
 
2288 clevermous 884
        cmp     ax, 0x450
885
        jb      .rus2
4700 mario79 886
;--------------------------------------
2288 clevermous 887
.unk:
888
        mov     al, '_'
889
        jmp     .doit
4700 mario79 890
;--------------------------------------
2288 clevermous 891
.yo1:
3539 clevermous 892
        mov     al, 0xF0 ; 'Ё' in cp866
2288 clevermous 893
        jmp     .doit
4700 mario79 894
;--------------------------------------
2288 clevermous 895
.yo2:
3539 clevermous 896
        mov     al, 0xF1 ; 'ё' in cp866
2288 clevermous 897
        jmp     .doit
4700 mario79 898
;--------------------------------------
2288 clevermous 899
.rus1:
900
; 0x410-0x43F -> 0x80-0xAF
901
        add     al, 0x70
902
        jmp     .doit
4700 mario79 903
;--------------------------------------
2288 clevermous 904
.rus2:
905
; 0x440-0x44F -> 0xE0-0xEF
906
        add     al, 0xA0
4700 mario79 907
;--------------------------------------
2288 clevermous 908
.ascii:
909
.doit:
910
        ret
4700 mario79 911
;-----------------------------------------------------------------------------