Subversion Repositories Kolibri OS

Rev

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