Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8152 | dunkaist | 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 | ; fetch the UTF-8 character in addrspace:offs to char |
||
9 | macro fetch_utf8_char addrspace, offs, char |
||
10 | { local first_byte, b |
||
11 | ; fetch first byte |
||
12 | load first_byte byte from addrspace:offs |
||
13 | if first_byte < 0x80 |
||
14 | char = first_byte |
||
15 | offs = offs + 1 |
||
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) |
||
22 | offs = offs + 2 |
||
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) |
||
29 | offs = offs + 3 |
||
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) |
||
38 | offs = offs + 4 |
||
39 | else |
||
40 | err Invalid UTF-8 string |
||
41 | end if |
||
42 | } |
||
43 | |||
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] |
||
51 | { common |
||
52 | local ..addrspace, offs, char |
||
53 | offs = 0 |
||
54 | virtual at 0 |
||
55 | ..addrspace:: db arg |
||
56 | ..addrspace#.size = $ |
||
57 | end virtual |
||
58 | while offs < ..addrspace#.size |
||
59 | fetch_utf8_char ..addrspace, offs, char |
||
60 | if char = 0x2500 |
||
61 | db 0xC4 |
||
62 | else if char = 0x2502 |
||
63 | db 0xB3 |
||
64 | else if char = 0x250C |
||
65 | db 0xDA |
||
66 | else if char = 0x2510 |
||
67 | db 0xBF |
||
68 | else if char = 0x2514 |
||
69 | db 0xC0 |
||
70 | else if char = 0x2518 |
||
71 | db 0xD9 |
||
72 | else if char = 0x252C |
||
73 | db 0xC2 |
||
74 | else if char = 0x2534 |
||
75 | db 0xC1 |
||
76 | else if char = 0x2551 |
||
77 | db 0xBA |
||
78 | else if char < 0x80 |
||
79 | db char |
||
80 | else |
||
81 | encoding char |
||
82 | end if |
||
83 | end while |
||
84 | } |
||
85 | |||
86 | macro declare_encoding encoding |
||
87 | { |
||
88 | macro encoding [arg] |
||
89 | \{ common convert_utf8 encoding#char, arg \} |
||
90 | struc encoding [arg] |
||
91 | \{ common convert_utf8 encoding#char, arg \} |
||
92 | macro encoding#char char |
||
93 | } |
||
94 | |||
95 | ; Russian: use CP866. |
||
96 | ; 0x410-0x43F -> 0x80-0xAF |
||
97 | ; 0x440-0x44F -> 0xE0-0xEF |
||
98 | ; 0x401 -> 0xF0, 0x451 -> 0xF1 |
||
99 | declare_encoding cp866 |
||
100 | { |
||
101 | if char = 0x401 |
||
102 | db 0xF0 |
||
103 | else if char = 0x451 |
||
104 | db 0xF1 |
||
105 | else if (char < 0x410) | (char > 0x44F) |
||
106 | err Failed to convert to CP866 |
||
107 | else if char < 0x440 |
||
108 | db char - 0x410 + 0x80 |
||
109 | else |
||
110 | db char - 0x440 + 0xE0 |
||
111 | end if |
||
112 | } |
||
113 | |||
114 | ; Latin-1 encoding |
||
115 | ; 0x00-0xFF - trivial map |
||
116 | declare_encoding latin1 |
||
117 | { |
||
118 | if char < 0x100 |
||
119 | db char |
||
120 | else |
||
121 | err Failed to convert to Latin-1 |
||
122 | end if |
||
123 | } |
||
124 | |||
125 | ; CP850 encoding |
||
126 | declare_encoding cp850 |
||
127 | { |
||
128 | if char = 0xBF |
||
129 | db 0xA8 |
||
130 | else if char = 0xE1 |
||
131 | db 0xA0 |
||
132 | else if char = 0xE9 |
||
133 | db 0x82 |
||
134 | else if char = 0xED |
||
135 | db 0xA1 |
||
136 | else if char = 0xF3 |
||
137 | db 0xA2 |
||
138 | else if char = 0xFA |
||
139 | db 0xA3 |
||
140 | else |
||
141 | err Failed to convert to CP850 |
||
142 | end if |
||
143 | }>>>>>>>>>> |