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