Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2013-2015. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 5363 $
  9.  
  10. ; fetch the UTF-8 character in addrspace:offs to char
  11. macro fetch_utf8_char addrspace, offs, char
  12. { local first_byte, b
  13.   ; fetch first byte
  14.   load first_byte byte from addrspace:offs
  15.   if first_byte < 0x80
  16.     char = first_byte
  17.     offs = offs + 1
  18.   else if first_byte < 0xC0
  19.     err Invalid UTF-8 string
  20.   else if first_byte < 0xE0
  21.     char = first_byte and 0x1F
  22.     load b byte from addrspace:offs + 1
  23.     char = (char shl 6) + (b and 0x3F)
  24.     offs = offs + 2
  25.   else if first_byte < 0xF0
  26.     char = first_byte and 0xF
  27.     load b byte from addrspace:offs + 1
  28.     char = (char shl 6) + (b and 0x3F)
  29.     load b byte from addrspace:offs + 2
  30.     char = (char shl 6) + (b and 0x3F)
  31.     offs = offs + 3
  32.   else if first_byte < 0xF8
  33.     char = first_byte and 0x7
  34.     load b byte from addrspace:offs + 1
  35.     char = (char shl 6) + (b and 0x3F)
  36.     load b byte from addrspace:offs + 2
  37.     char = (char shl 6) + (b and 0x3F)
  38.     load b byte from addrspace:offs + 3
  39.     char = (char shl 6) + (b and 0x3F)
  40.     offs = offs + 4
  41.   else
  42.     err Invalid UTF-8 string
  43.   end if
  44. }
  45.  
  46. ; Worker macro for all encodings.
  47. ; Common part for all encodings: map characters 0-0x7F trivially,
  48. ; translate pseudographics.
  49. ; Pseudographics for the boot screen:
  50. ; 0x2500 -> 0xC4, 0x2502 -> 0xB3, 0x250C -> 0xDA, 0x2510 -> 0xBF,
  51. ; 0x2514 -> 0xC0, 0x2518 -> 0xD9, 0x252C -> 0xC2, 0x2534 -> 0xC1, 0x2551 -> 0xBA
  52. macro convert_utf8 encoding, [arg]
  53. { common
  54.   local ..addrspace, offs, char
  55.   offs = 0
  56.   virtual at 0
  57.   ..addrspace:: db arg
  58.   ..addrspace#.size = $
  59.   end virtual
  60.   while offs < ..addrspace#.size
  61.     fetch_utf8_char ..addrspace, offs, char
  62.     if char = 0x2500
  63.       db 0xC4
  64.     else if char = 0x2502
  65.       db 0xB3
  66.     else if char = 0x250C
  67.       db 0xDA
  68.     else if char = 0x2510
  69.       db 0xBF
  70.     else if char = 0x2514
  71.       db 0xC0
  72.     else if char = 0x2518
  73.       db 0xD9
  74.     else if char = 0x252C
  75.       db 0xC2
  76.     else if char = 0x2534
  77.       db 0xC1
  78.     else if char = 0x2551
  79.       db 0xBA
  80.     else if char < 0x80
  81.       db char
  82.     else
  83.       encoding char
  84.     end if
  85.   end while
  86. }
  87.  
  88. macro declare_encoding encoding
  89. {
  90.   macro encoding [arg]
  91.   \{ common convert_utf8 encoding#char, arg \}
  92.   struc encoding [arg]
  93.   \{ common convert_utf8 encoding#char, arg \}
  94.   macro encoding#char char
  95. }
  96.  
  97. ; Russian: use CP866.
  98. ; 0x410-0x43F -> 0x80-0xAF
  99. ; 0x440-0x44F -> 0xE0-0xEF
  100. ; 0x401 -> 0xF0, 0x451 -> 0xF1
  101. declare_encoding cp866
  102. {
  103.   if char = 0x401
  104.     db 0xF0
  105.   else if char = 0x451
  106.     db 0xF1
  107.   else if (char < 0x410) | (char > 0x44F)
  108.     err Failed to convert to CP866
  109.   else if char < 0x440
  110.     db char - 0x410 + 0x80
  111.   else
  112.     db char - 0x440 + 0xE0
  113.   end if
  114. }
  115.  
  116. ; Latin-1 encoding
  117. ; 0x00-0xFF - trivial map
  118. declare_encoding latin1
  119. {
  120.   if char < 0x100
  121.     db char
  122.   else
  123.     err Failed to convert to Latin-1
  124.   end if
  125. }
  126.  
  127. ; CP850 encoding
  128. declare_encoding cp850
  129. {
  130.   if char = 0xBF
  131.     db 0xA8
  132.   else if char = 0xE1
  133.     db 0xA0
  134.   else if char = 0xE9
  135.     db 0x82
  136.   else if char = 0xED
  137.     db 0xA1
  138.   else if char = 0xF3
  139.     db 0xA2
  140.   else if char = 0xFA
  141.     db 0xA3
  142.   else
  143.     err Failed to convert to CP850
  144.   end if
  145. }
  146.