Subversion Repositories Kolibri OS

Rev

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