1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; Copyright (C) KolibriOS team 2013-2015. All rights reserved. ;;
4 ;; Distributed under terms of the GNU General Public License ;;
6 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8 ; fetch the UTF-8 character in addrspace:offs to char
9 macro fetch_utf8_char addrspace, offs, char
12 load first_byte byte from addrspace:offs
16 else if first_byte < 0xC0
17 err Invalid UTF-8 string
18 else if first_byte < 0xE0
19 char = first_byte and 0x1F
20 load b byte from addrspace:offs + 1
21 char = (char shl 6) + (b and 0x3F)
23 else if first_byte < 0xF0
24 char = first_byte and 0xF
25 load b byte from addrspace:offs + 1
26 char = (char shl 6) + (b and 0x3F)
27 load b byte from addrspace:offs + 2
28 char = (char shl 6) + (b and 0x3F)
30 else if first_byte < 0xF8
31 char = first_byte and 0x7
32 load b byte from addrspace:offs + 1
33 char = (char shl 6) + (b and 0x3F)
34 load b byte from addrspace:offs + 2
35 char = (char shl 6) + (b and 0x3F)
36 load b byte from addrspace:offs + 3
37 char = (char shl 6) + (b and 0x3F)
40 err Invalid UTF-8 string
44 ; Worker macro for all encodings.
45 ; Common part for all encodings: map characters 0-0x7F trivially,
46 ; translate pseudographics.
47 ; Pseudographics for the boot screen:
48 ; 0x2500 -> 0xC4, 0x2502 -> 0xB3, 0x250C -> 0xDA, 0x2510 -> 0xBF,
49 ; 0x2514 -> 0xC0, 0x2518 -> 0xD9, 0x252C -> 0xC2, 0x2534 -> 0xC1, 0x2551 -> 0xBA
50 macro convert_utf8 encoding, [arg]
52 local ..addrspace, offs, char
58 while offs < ..addrspace#.size
59 fetch_utf8_char ..addrspace, offs, char
86 macro declare_encoding encoding
89 \{ common convert_utf8 encoding#char, arg \}
91 \{ common convert_utf8 encoding#char, arg \}
92 macro encoding#char char
96 ; 0x410-0x43F -> 0x80-0xAF
97 ; 0x440-0x44F -> 0xE0-0xEF
98 ; 0x401 -> 0xF0, 0x451 -> 0xF1
99 declare_encoding cp866
105 else if (char < 0x410) | (char > 0x44F)
106 err Failed to convert to CP866
108 db char - 0x410 + 0x80
110 db char - 0x440 + 0xE0
115 ; 0x00-0xFF - trivial map
116 declare_encoding latin1
121 err Failed to convert to Latin-1
126 declare_encoding cp850
141 err Failed to convert to CP850