Subversion Repositories Kolibri OS

Rev

Rev 7129 | Rev 8089 | 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: 7132 $
  9.  
  10. iglobal
  11. full_file_name_table    dd  sysdir_name
  12. .size                   dd  1
  13. endg
  14.  
  15. uglobal
  16. sysdir_name     rb  64  ; 'sys',0
  17. sysdir_path     rb  64
  18. sysdir_name1    rb  64
  19. sysdir_path1    rb  64
  20. endg
  21. ; Example:
  22. ; align 64
  23. ; sysdir_name1 db 'KolibriOS',0
  24. ; align 64
  25. ; sysdir_path1 db 'HD0/1',0
  26.  
  27. proc Parser_params
  28.     locals
  29.         buff    rb  4   ; for test cd
  30.     endl
  31.         mov     ax, [BOOT.bx_from_load]
  32.         mov     ecx, sysdir_path
  33.         mov     [ecx-64], dword 'sys'
  34.         mov     [ecx-2], byte 3
  35.         mov     [ecx-1], byte '/'
  36.         cmp     al, 'r' ; ram disk
  37.         jnz     @f
  38.         mov     [ecx], dword 'RD/?'
  39.         mov     [ecx+3], byte ah
  40.         mov     [ecx+4], byte 0
  41.         ret
  42.  
  43. @@:
  44.         cmp     al, 'm'
  45.         jnz     .hard_disk
  46.         mov     [ecx], dword 'CD?/'
  47.         mov     [ecx+4], byte '1'
  48.         mov     [ecx+5], dword '/KOL'
  49.         mov     [ecx+9], dword 'IBRI'
  50.         mov     [ecx+13], byte 0
  51. .next_cd:
  52.         mov     [ecx+2], byte ah
  53.         inc     ah
  54.         cmp     ah, '5'
  55.         je      @f
  56.         lea     edx, [buff]
  57.         pushad
  58.         stdcall read_file, read_firstapp, edx, 0, 4
  59.         popad
  60.         cmp     [edx], dword 'MENU'
  61.         jne     .next_cd
  62. @@:
  63.         ret
  64.  
  65. .hard_disk:
  66.         sub     al, '1'
  67.         mov     [ecx], dword 'HD?/'
  68.         mov     [ecx+2], byte al
  69.         mov     [ecx+4], byte ah
  70.         mov     [ecx+5], dword '/KOL'
  71.         mov     [ecx+9], dword 'IBRI'
  72.         mov     [ecx+13], byte 0
  73.         ret
  74. endp
  75.  
  76. cp866toUpper:
  77. ; convert cp866 character in al to uppercase
  78.         cmp     al, 'a'
  79.         jb      .ret
  80.         cmp     al, 'z'
  81.         jbe     @f
  82.         cmp     al, 0xA0
  83.         jb      .ret
  84.         cmp     al, 0xB0
  85.         jb      @f
  86.         cmp     al, 0xE0
  87.         jb      .ret
  88.         cmp     al, 0xF0
  89.         jb      .rus
  90.         cmp     al, 0xF7
  91.         ja      .ret
  92.         and     eax, -2
  93. .ret:
  94.         ret
  95.  
  96. @@:
  97.         sub     eax, 32
  98.         ret
  99.  
  100. .rus:
  101.         sub     eax, 0xE0-0x90
  102.         ret
  103.  
  104. utf16toUpper:
  105. ; convert UTF-16 character in ax to uppercase
  106.         cmp     ax, 'a'
  107.         jb      .ret
  108.         cmp     ax, 'z'
  109.         jbe     @f
  110.         cmp     ax, 430h
  111.         jb      .ret
  112.         cmp     ax, 450h
  113.         jb      @f
  114.         cmp     ax, 460h
  115.         jnc     .ret
  116.         sub     eax, 80
  117. .ret:
  118.         ret
  119.  
  120. @@:
  121.         sub     eax, 32
  122.         ret
  123.  
  124. uni2ansi_char:
  125. ; convert UNICODE character in ax to ANSI character in al using cp866 encoding
  126.         cmp     ax, 0x80
  127.         jb      .ret
  128.         cmp     ax, 0xB6
  129.         jz      .B6
  130.         cmp     ax, 0x400
  131.         jb      .unk
  132.         cmp     ax, 0x410
  133.         jb      @f
  134.         cmp     ax, 0x440
  135.         jb      .rus1
  136.         cmp     ax, 0x450
  137.         jb      .rus2
  138.         cmp     ax, 0x460
  139.         jb      @f
  140. .unk:
  141.         mov     al, '_'
  142. .ret:
  143.         ret
  144.  
  145. .B6:
  146.         mov     al, 20
  147.         ret
  148.  
  149. .rus1:  ; 0x410-0x43F -> 0x80-0xAF
  150.         add     al, 0x70
  151.         ret
  152.  
  153. .rus2:  ; 0x440-0x44F -> 0xE0-0xEF
  154.         add     al, 0xA0
  155.         ret
  156.  
  157. @@:
  158.         push    ecx edi
  159.         mov     ecx, 8
  160.         mov     edi, .table
  161.         repnz scasb
  162.         mov     ah, cl
  163.         pop     edi ecx
  164.         jnz     .unk
  165.         mov     al, 0xF7
  166.         sub     al, ah
  167.         ret
  168.  
  169. .table  db  1, 51h, 4, 54h, 7, 57h, 0Eh, 5Eh
  170.  
  171. ansi2uni_char:
  172. ; convert ANSI character in al to UNICODE character in ax, using cp866 encoding
  173.         movzx   eax, al
  174.         cmp     al, 0x80
  175.         jb      @f      ; 0x00-0x7F - trivial map
  176.         cmp     al, 0xB0
  177.         jb      .rus    ; 0x80-0xAF -> 0x410-0x43F
  178.         cmp     al, 0xE0
  179.         jb      .unk
  180.         cmp     al, 0xF0
  181.         jb      .rus2   ; 0xE0-0xEF -> 0x440-0x44F
  182.         cmp     al, 0xF8
  183.         jnc     .unk
  184.         mov     al, [eax+uni2ansi_char.table-0xF0]
  185.         add     ax, 400h
  186.         ret
  187.  
  188. @@:
  189.         cmp     al, 20
  190.         jnz     .ret
  191.         mov     al, 0xB6
  192. .ret:
  193.         ret
  194.  
  195. .rus:
  196.         add     ax, 0x410-0x80
  197.         ret
  198.  
  199. .rus2:
  200.         add     ax, 0x440-0xE0
  201.         ret
  202.  
  203. .unk:
  204.         mov     al, '_'
  205.         ret
  206.  
  207. cp866toUTF8_string:
  208. ;   in:
  209. ; esi -> cp866 string (could be zero terminated)
  210. ; edi -> buffer for UTF-8 string
  211. ; ecx = buffer size (signed)
  212.         lodsb
  213.         call    ansi2uni_char
  214.         push    eax
  215.         call    UTF16to8
  216.         pop     eax
  217.         js      @f
  218.         test    eax, eax
  219.         jnz     cp866toUTF8_string
  220. @@:
  221.         ret
  222.  
  223. ; SF=1 -> counter
  224. ; ZF=1 -> zero char
  225.  
  226. UTF16to8_string:
  227. ;   in:
  228. ; esi -> UTF-16 string (could be zero terminated)
  229. ; edi -> buffer for UTF-8 string
  230. ; ecx = buffer size (signed)
  231.         xor     eax, eax
  232. @@:
  233.         lodsw
  234.         push    eax
  235.         call    UTF16to8
  236.         pop     eax
  237.         js      @f
  238.         test    eax, eax
  239.         jnz     @b
  240. @@:
  241.         ret
  242.  
  243. UTF16to8:
  244. ;   in:
  245. ; eax = UTF-16 char
  246. ; edi -> buffer for UTF-8 char (increasing)
  247. ; ecx = byte counter (decreasing)
  248.         dec     ecx
  249.         js      .ret
  250.         cmp     eax, 80h
  251.         jnc     @f
  252.         stosb
  253.         test    eax, eax    ; SF=0
  254. .ret:
  255.         ret
  256.  
  257. @@:
  258.         dec     ecx
  259.         js      .ret
  260.         cmp     eax, 800h
  261.         jnc     @f
  262.         shl     eax, 2
  263.         shr     al, 2
  264.         or      eax, 1100000010000000b
  265.         xchg    al, ah
  266.         stosw
  267.         ret
  268.  
  269. @@:
  270.         dec     ecx
  271.         js      .ret
  272.         shl     eax, 4
  273.         shr     ax, 2
  274.         shr     al, 2
  275.         or      eax, 111000001000000010000000b
  276.         bswap   eax
  277.         shr     eax, 8
  278.         stosb
  279.         shr     eax, 8
  280.         stosw
  281.         ret
  282.  
  283. utf8to16:
  284. ; in: esi -> UTF-8 char (increasing)
  285. ; out: ax = UTF-16 char
  286.         lodsb
  287.         test    al, al
  288.         jns     .got
  289.         shl     al, 2
  290.         jnc     utf8to16
  291. @@:
  292.         shl     ax, 8
  293.         lodsb
  294.         test    al, al
  295.         jns     .got
  296.         shl     al, 2
  297.         jc      @b
  298.         shr     ah, 2
  299.         shl     ax, 3
  300.         jnc     @f
  301.         shl     eax, 3
  302.         lodsb
  303.         test    al, al
  304.         jns     .got
  305.         shl     al, 2
  306.         jc      @b
  307.         shr     eax, 2
  308.         ret
  309.  
  310. @@:
  311.         shr     ax, 5
  312.         ret
  313.  
  314. .got:
  315.         xor     ah, ah
  316.         ret
  317.  
  318. strlen:
  319. ; in: esi -> source
  320. ; out: ecx = length
  321.         push    edi eax
  322.         or      ecx, -1
  323.         mov     edi, esi
  324.         xor     eax, eax
  325.         repnz scasb
  326.         inc     ecx
  327.         not     ecx
  328.         pop     eax edi
  329.         ret
  330.