Subversion Repositories Kolibri OS

Rev

Rev 6262 | Rev 6471 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
  4. ;;  Distributed under terms of the GNU General Public License.  ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 6468 $
  9.  
  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.  
  34. uglobal
  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
  41. endg
  42.  
  43. ;-----------------------------------------------------------------------------
  44. fs_NotImplemented:
  45.         movi    eax, ERROR_UNSUPPORTED_FS
  46.         ret
  47. ;-----------------------------------------------------------------------------
  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
  56. ;-----------------------------------------------------------------------------
  57. reserve_ok2:
  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
  66. ;-----------------------------------------------------------------------------
  67. reserve_cd_channel:
  68.         pushad
  69.         mov     eax, [cdpos]
  70.         dec     eax
  71.         shr     eax, 2
  72.  
  73.         test    eax, eax
  74.         jnz     .1
  75.  
  76.         cmp     [ChannelNumber], 1
  77.         jne     @f
  78.  
  79.         mov     ecx, ide_channel1_mutex
  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:
  110.         call    mutex_lock
  111.         popad
  112.         ret
  113. ;-----------------------------------------------------------------------------
  114. free_cd_channel:
  115.         pushad
  116.         mov     eax, [cdpos]
  117.         dec     eax
  118.         shr     eax, 2
  119.  
  120.         test    eax, eax
  121.         jnz     .1
  122.  
  123.         cmp     [ChannelNumber], 1
  124.         jne     @f
  125.  
  126.         mov     ecx, ide_channel1_mutex
  127.         jmp     .mutex_unlock
  128. ;--------------------------------------
  129. @@:
  130.         mov     ecx, ide_channel2_mutex
  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:
  157.         call    mutex_unlock
  158.         popad
  159.         ret
  160.  
  161. ;-----------------------------------------------------------------------------
  162. fs_CdRead:
  163.         push    edi
  164.         cmp     byte [esi], 0
  165.         jnz     @f
  166. ;--------------------------------------
  167. .noaccess:
  168.         pop     edi
  169. ;--------------------------------------
  170. .noaccess_2:
  171.         or      ebx, -1
  172.         mov     eax, ERROR_ACCESS_DENIED
  173.         ret
  174. ;--------------------------------------
  175. .noaccess_3:
  176.         pop     eax edx ecx edi
  177.         jmp     .noaccess_2
  178. ;--------------------------------------
  179. @@:
  180.         call    cd_find_lfn
  181.         jnc     .found
  182.  
  183.         pop     edi
  184.         cmp     [DevErrorCode], 0
  185.         jne     .noaccess_2
  186.  
  187.         or      ebx, -1
  188.         mov     eax, ERROR_FILE_NOT_FOUND
  189.         ret
  190. ;--------------------------------------
  191. .found:
  192.         mov     edi, [cd_current_pointer_of_input]
  193.         test    byte [edi+25], 10b; do not allow read directories
  194.         jnz     .noaccess
  195.  
  196.         test    ebx, ebx
  197.         jz      .l1
  198.  
  199.         cmp     dword [ebx+4], 0
  200.         jz      @f
  201.  
  202.         xor     ebx, ebx
  203. ;--------------------------------------
  204. .reteof:
  205.         mov     eax, 6; end of file
  206.         pop     edi
  207.         ret
  208. ;--------------------------------------
  209. @@:
  210.         mov     ebx, [ebx]
  211. ;--------------------------------------
  212. .l1:
  213.         push    ecx edx
  214.         push    0
  215.         mov     eax, [edi+10] ; real size of the file section
  216.         sub     eax, ebx
  217.         jb      .eof
  218.  
  219.         cmp     eax, ecx
  220.         jae     @f
  221.  
  222.         mov     ecx, eax
  223.         mov     byte [esp], 6
  224. ;--------------------------------------
  225. @@:
  226.         mov     eax, [edi+2]
  227.         mov     [CDSectorAddress], eax
  228. ;--------------------------------------
  229. ; now eax=cluster, ebx=position, ecx=count, edx=buffer for data
  230. .new_sector:
  231.         test    ecx, ecx
  232.         jz      .done
  233.  
  234.         sub     ebx, 2048
  235.         jae     .next
  236.  
  237.         add     ebx, 2048
  238.         jnz     .incomplete_sector
  239.  
  240.         cmp     ecx, 2048
  241.         jb      .incomplete_sector
  242. ; we may read and memmove complete sector
  243.         mov     [CDDataBuf_pointer], edx
  244.         call    ReadCDWRetr ; read sector of file
  245.         cmp     [DevErrorCode], 0
  246.         jne     .noaccess_3
  247.  
  248.         add     edx, 2048
  249.         sub     ecx, 2048
  250. ;--------------------------------------
  251. .next:
  252.         inc     dword [CDSectorAddress]
  253.         jmp     .new_sector
  254. ;--------------------------------------
  255. .incomplete_sector:
  256. ; we must read and memmove incomplete sector
  257.         mov     [CDDataBuf_pointer], CDDataBuf
  258.         call    ReadCDWRetr ; read sector of file
  259.         cmp     [DevErrorCode], 0
  260.         jne     .noaccess_3
  261.  
  262.         push    ecx
  263.         add     ecx, ebx
  264.         cmp     ecx, 2048
  265.         jbe     @f
  266.  
  267.         mov     ecx, 2048
  268. ;--------------------------------------
  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
  282. ;--------------------------------------
  283. .done:
  284.         mov     ebx, edx
  285.         pop     eax edx ecx edi
  286.         sub     ebx, edx
  287.         ret
  288. ;--------------------------------------
  289. .eof:
  290.         mov     ebx, edx
  291.         pop     eax edx ecx
  292.         sub     ebx, edx
  293.         jmp     .reteof
  294.  
  295. ;-----------------------------------------------------------------------------
  296. fs_CdReadFolder:
  297.         push    edi
  298.         call    cd_find_lfn
  299.         jnc     .found
  300.  
  301.         pop     edi
  302.         cmp     [DevErrorCode], 0
  303.         jne     .noaccess_1
  304.  
  305.         or      ebx, -1
  306.         mov     eax, ERROR_FILE_NOT_FOUND
  307.         ret
  308. ;--------------------------------------
  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
  313.  
  314.         pop     edi
  315. ;--------------------------------------
  316. .noaccess_1:
  317.         or      ebx, -1
  318.         mov     eax, ERROR_ACCESS_DENIED
  319.         ret
  320. ;--------------------------------------
  321. .found_dir:
  322.         mov     eax, [edi+2]    ; eax=cluster
  323.         mov     [CDSectorAddress], eax
  324.         mov     eax, [edi+10]   ; directory size
  325. ;--------------------------------------
  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
  341. ;--------------------------------------
  342. .read_to_buffer:
  343.         inc     dword [CDSectorAddress]
  344.         mov     [CDDataBuf_pointer], CDDataBuf
  345.         call    ReadCDWRetr         ; read sector of directory
  346.         cmp     [DevErrorCode], 0
  347.         jne     .noaccess_1
  348.  
  349.         call    .get_names_from_buffer
  350.         sub     eax, 2048
  351. ; directory is over?
  352.         ja      .read_to_buffer
  353.  
  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
  361.  
  362.         mov     al, ERROR_END_OF_FILE
  363. ;--------------------------------------
  364. @@:
  365.         pop     ecx edi
  366.         mov     ebx, [edx+4]
  367.         ret
  368. ;--------------------------------------
  369. .get_names_from_buffer:
  370.         mov     [cd_current_pointer_of_input_2], CDDataBuf
  371.         push    eax esi edi edx
  372. ;--------------------------------------
  373. .get_names_from_buffer_1:
  374.         call    cd_get_name
  375.         jc      .end_buffer
  376.  
  377.         inc     dword [cd_counter_block]
  378.         mov     eax, [cd_counter_block]
  379.         cmp     [ebx], eax
  380.         jae     .get_names_from_buffer_1
  381.  
  382.         test    ecx, ecx
  383.         jz      .get_names_from_buffer_1
  384.  
  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
  393. ;--------------------------------------
  394. .ansi:
  395.         cmp     [cd_counter_block], 2
  396.         jbe     .ansi_parent_directory
  397.  
  398.         cld
  399.         lodsw
  400.         xchg    ah, al
  401.         call    uni2ansi_char
  402.         cld
  403.         stosb
  404. ; check end of file
  405.         mov     ax, [esi]
  406.         cmp     ax, word 3B00h ; separator end of file ';'
  407.         je      .cd_get_parameters_of_file_1
  408. ; check for files not ending with separator
  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
  414. ; check the end of the directory
  415.         movzx   eax, byte [ebp-1]
  416.         add     eax, ebp
  417.         cmp     esi, eax
  418.         jb      .ansi
  419. ;--------------------------------------
  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
  425. ;--------------------------------------
  426. .ansi_parent_directory:
  427.         cmp     [cd_counter_block], 2
  428.         je      @f
  429.  
  430.         mov     [edi], byte '.'
  431.         inc     edi
  432.         jmp     .cd_get_parameters_of_file_1
  433. ;--------------------------------------
  434. @@:
  435.         mov     [edi], word '..'
  436.         add     edi, 2
  437.         jmp     .cd_get_parameters_of_file_1
  438. ;--------------------------------------
  439. .unicode:
  440.         cmp     [cd_counter_block], 2
  441.         jbe     .unicode_parent_directory
  442.  
  443.         cld
  444.         movsw
  445. ; check end of file
  446.         mov     ax, [esi]
  447.         cmp     ax, word 3B00h; separator end of file ';'
  448.         je      .cd_get_parameters_of_file_2
  449. ; check for files not ending with separator
  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
  455. ; check the end of the directory
  456.         movzx   eax, byte [ebp-1]
  457.         add     eax, ebp
  458.         cmp     esi, eax
  459.         jb      .unicode
  460. ;--------------------------------------
  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
  466. ;--------------------------------------
  467. .unicode_parent_directory:
  468.         cmp     [cd_counter_block], 2
  469.         je      @f
  470.  
  471.         mov     [edi], word 2E00h; '.'
  472.         add     edi, 2
  473.         jmp     .cd_get_parameters_of_file_2
  474. ;--------------------------------------
  475. @@:
  476.         mov     [edi], dword 2E002E00h; '..'
  477.         add     edi, 4
  478.         jmp     .cd_get_parameters_of_file_2
  479. ;--------------------------------------
  480. .end_buffer:
  481.         pop     edx edi esi eax
  482.         ret
  483. ;-----------------------------------------------------------------------------
  484. cd_get_parameters_of_file:
  485.         mov     edi, [cd_mem_location]
  486. cd_get_parameters_of_file_1:
  487. ; get file attributes
  488.         xor     eax, eax
  489. ; file is not archived
  490.         inc     eax
  491.         shl     eax, 1
  492. ; is a directory?
  493.         test    [ebp-8], byte 2
  494.         jz      .file
  495.  
  496.         inc     eax
  497. ;--------------------------------------
  498. .file:
  499. ; not as a volume label in the FAT, in this form not available
  500. ; file is not a system
  501.         shl     eax, 3
  502. ; file is hidden? (attribute of existence)
  503.         test    [ebp-8], byte 1
  504.         jz      .hidden
  505.  
  506.         inc     eax
  507. ;--------------------------------------
  508. .hidden:
  509.         shl     eax, 1
  510. ; file is always read-only, as this CD
  511.         inc     eax
  512.         mov     [edi], eax
  513. ; get the time to file
  514. ; hour
  515.         movzx   eax, byte [ebp-12]
  516.         shl     eax, 8
  517. ; minute
  518.         mov     al, [ebp-11]
  519.         shl     eax, 8
  520. ; second
  521.         mov     al, [ebp-10]
  522. ; file creation time
  523.         mov     [edi+8], eax
  524. ; last access time
  525.         mov     [edi+16], eax
  526. ; last write time
  527.         mov     [edi+24], eax
  528. ; get date for file
  529. ; year
  530.         movzx   eax, byte [ebp-15]
  531.         add     eax, 1900
  532.         shl     eax, 8
  533. ; month
  534.         mov     al, [ebp-14]
  535.         shl     eax, 8
  536. ; day
  537.         mov     al, [ebp-13]
  538. ; file creation date
  539.         mov     [edi+12], eax
  540. ; last access date
  541.         mov     [edi+20], eax
  542. ; last write date
  543.         mov     [edi+28], eax
  544. ; get the data type of name
  545.         xor     eax, eax
  546.         test    dword [ebx+4], 1; 0=ANSI, 1=UNICODE
  547.         jnz     .unicode_1
  548.  
  549.         mov     [edi+4], eax
  550.         jmp     @f
  551. ;--------------------------------------
  552. .unicode_1:
  553.         inc     eax
  554.         mov     [edi+4], eax
  555. ;--------------------------------------
  556. @@:
  557. ; get the file size in bytes
  558.         xor     eax, eax
  559.         mov     [edi+32+4], eax
  560.         mov     eax, [ebp-23]
  561.         mov     [edi+32], eax
  562.         ret
  563.  
  564. ;-----------------------------------------------------------------------------
  565. fs_CdGetFileInfo:
  566.         cmp     byte [esi], 0
  567.         jnz     @f
  568.  
  569.         mov     eax, 2
  570.         ret
  571. ;--------------------------------------
  572. @@:
  573.         push    edi
  574.         call    cd_find_lfn
  575.         pushfd
  576.         cmp     [DevErrorCode], 0
  577.         jz      @f
  578.  
  579.         popfd
  580.         pop     edi
  581.         mov     eax, 11
  582.         ret
  583. ;--------------------------------------
  584. @@:
  585.         popfd
  586.         jnc     @f
  587.  
  588.         pop     edi
  589.         mov     eax, ERROR_FILE_NOT_FOUND
  590.         ret
  591. ;--------------------------------------
  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
  604. ;-----------------------------------------------------------------------------
  605. cd_find_lfn:
  606.         mov     [cd_appl_data], 0
  607. ; in: esi -> path string
  608. ; out: CF=1 - file not found
  609. ; else CF=0 and [cd_current_pointer_of_input] direntry
  610.         push    eax esi
  611. ; Sector 16 - start set of volume descriptors
  612.         call    WaitUnitReady
  613.         cmp     [DevErrorCode], 0
  614.         jne     .access_denied
  615.  
  616.         call    prevent_medium_removal
  617. ; testing of reading
  618.         mov     [CDSectorAddress], dword 16
  619.         mov     [CDDataBuf_pointer], CDDataBuf
  620.         call    ReadCDWRetr;_1
  621.         cmp     [DevErrorCode], 0
  622.         jne     .access_denied
  623.  
  624. ; calculation of the last session
  625.         call    WaitUnitReady
  626.         cmp     [DevErrorCode], 0
  627.         jne     .access_denied
  628.  
  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
  639. ;--------------------------------------
  640. .start:
  641.         inc     dword [CDSectorAddress]
  642.         call    ReadCDWRetr;_1
  643.         cmp     [DevErrorCode], 0
  644.         jne     .access_denied
  645.  
  646. .start_check:
  647. ; checking for "lice"
  648.         cmp     [CDDataBuf+1], dword 'CD00'
  649.         jne     .access_denied
  650.  
  651.         cmp     [CDDataBuf+5], byte '1'
  652.         jne     .access_denied
  653. ; sector is the terminator of set of descriptors volumes?
  654.         cmp     [CDDataBuf], byte 0xff
  655.         je      .access_denied
  656. ; sector is an additional and improved descriptor of volume?
  657.         cmp     [CDDataBuf], byte 0x2
  658.         jne     .start
  659. ; sector is an additional descriptor of volume?
  660.         cmp     [CDDataBuf+6], byte 0x1
  661.         jne     .start
  662.  
  663. ; parameters of root directory
  664.         mov     eax, [CDDataBuf+0x9c+2]; start of root directory
  665.         mov     [CDSectorAddress], eax
  666.         mov     eax, [CDDataBuf+0x9c+10]; size of root directory
  667.         cmp     byte [esi], 0
  668.         jnz     @f
  669.  
  670.         mov     [cd_current_pointer_of_input], CDDataBuf+0x9c
  671.         jmp     .done
  672. ;--------------------------------------
  673. @@:
  674. ; start the search
  675. .mainloop:
  676.         dec     dword [CDSectorAddress]
  677. ;--------------------------------------
  678. .read_to_buffer:
  679.         inc     dword [CDSectorAddress]
  680.         mov     [CDDataBuf_pointer], CDDataBuf
  681.         call    ReadCDWRetr      ; read sector of directory
  682.         cmp     [DevErrorCode], 0
  683.         jne     .access_denied
  684.         call    cd_find_name_in_buffer
  685.         jnc     .found
  686.         sub     eax, 2048
  687. ; directory is over?
  688.         cmp     eax, 0
  689.         ja      .read_to_buffer
  690. ; desired element of chain is not found
  691. .access_denied:
  692.         pop     esi eax
  693.         mov     [cd_appl_data], 1
  694.         stc
  695.         ret
  696. ;--------------------------------------
  697. ; desired element of chain found
  698. .found:
  699. ; the end of the file path
  700.         cmp     byte [esi-1], 0
  701.         jz      .done
  702.         mov     eax, [cd_current_pointer_of_input]
  703.         push    dword [eax+2]
  704.         pop     dword [CDSectorAddress] ; beginning of the directory
  705.         mov     eax, [eax+2+8] ; size of directory
  706.         jmp     .mainloop
  707. ;--------------------------------------
  708. ; file pointer found
  709. .done:
  710.         pop     esi eax
  711.         mov     [cd_appl_data], 1
  712.         clc
  713.         ret
  714. ;-----------------------------------------------------------------------------
  715. cd_find_name_in_buffer:
  716.         mov     [cd_current_pointer_of_input_2], CDDataBuf
  717. ;--------------------------------------
  718. .start:
  719.         call    cd_get_name
  720.         jc      .not_found
  721.  
  722.         call    cd_compare_name
  723.         jc      .start
  724. ;--------------------------------------
  725. .found:
  726.         clc
  727.         ret
  728. ;--------------------------------------
  729. .not_found:
  730.         stc
  731.         ret
  732. ;-----------------------------------------------------------------------------
  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]
  738.         test    eax, eax ; entry's is over?
  739.         jz      .next_sector
  740.  
  741.         cmp     ebp, CDDataBuf+2048  ; buffer is over?
  742.         jae     .next_sector
  743.  
  744.         movzx   eax, byte [ebp]
  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
  747.         pop     eax
  748.         clc
  749.         ret
  750. ;--------------------------------------
  751. .next_sector:
  752.         pop     eax
  753.         stc
  754.         ret
  755. ;-----------------------------------------------------------------------------
  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
  764. ;--------------------------------------
  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
  781. ;--------------------------------------
  782. .coincides:
  783.         cmp     [esi], byte '/' ; path separator is end of current element
  784.         je      .done
  785.  
  786.         cmp     [esi], byte 0 ; path separator end of name
  787.         je      .done
  788.  
  789.         jmp     .loop
  790. ;--------------------------------------
  791. .name_not_coincide:
  792.         pop     edi eax esi
  793.         stc
  794.         ret
  795. ;--------------------------------------
  796. .done:
  797. ; check end of file
  798.         cmp     [edi], word 3B00h; separator end of file ';'
  799.         je      .done_1
  800. ; check for files not ending with separator
  801.         movzx   eax, byte [ebp-33]
  802.         add     eax, ebp
  803.         sub     eax, 34
  804.         cmp     edi, eax
  805.         je      .done_1
  806. ; check the end of directory
  807.         movzx   eax, byte [ebp-1]
  808.         add     eax, ebp
  809.         cmp     edi, eax
  810.         jne     .name_not_coincide
  811. ;--------------------------------------
  812. .done_1:
  813.         pop     edi eax
  814.         add     esp, 4
  815.         inc     esi
  816.         clc
  817.         ret
  818.