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