diff options
Diffstat (limited to 'firmware/unicode.c')
-rw-r--r-- | firmware/unicode.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/firmware/unicode.c b/firmware/unicode.c new file mode 100644 index 0000000000..150dd5171e --- /dev/null +++ b/firmware/unicode.c | |||
@@ -0,0 +1,101 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alex Gitelman | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "unicode.h" | ||
20 | #include "string.h" | ||
21 | |||
22 | #define MAX_TYPE 3 | ||
23 | |||
24 | unsigned char *conversion_table[255]; | ||
25 | unsigned char *reverse_conversion_table[255]; | ||
26 | |||
27 | static unsigned char page_04[] = { | ||
28 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
29 | 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, | ||
30 | 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, | ||
31 | 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, | ||
32 | 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, | ||
33 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
34 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
35 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
36 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
37 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
38 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
39 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
40 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
41 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
42 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
43 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||
44 | }; | ||
45 | |||
46 | void install_unicode_tables(void) | ||
47 | { | ||
48 | install_conversion_table(0x04, page_04); | ||
49 | } | ||
50 | |||
51 | void unicode_init(void) | ||
52 | { | ||
53 | memset(conversion_table, 0, sizeof(conversion_table)); | ||
54 | memset(reverse_conversion_table, 0, sizeof(reverse_conversion_table)); | ||
55 | install_unicode_tables(); | ||
56 | } | ||
57 | |||
58 | /** | ||
59 | Convertion table defines how chars in ing given page map to ascii | ||
60 | */ | ||
61 | void install_conversion_table(unsigned char page, unsigned char* conv_table) | ||
62 | { | ||
63 | if (conv_table!=0) | ||
64 | conversion_table[page] = conv_table; | ||
65 | else | ||
66 | conversion_table[page] = 0; | ||
67 | } | ||
68 | |||
69 | void install_reverse_conversion_table(unsigned char page, | ||
70 | unsigned char* rev_conv_table) | ||
71 | { | ||
72 | if (rev_conv_table!=0) | ||
73 | reverse_conversion_table[page] = rev_conv_table; | ||
74 | else | ||
75 | reverse_conversion_table[page] = 0; | ||
76 | } | ||
77 | |||
78 | |||
79 | unsigned char from_unicode(const unsigned char *uni_char) | ||
80 | { | ||
81 | /* | ||
82 | Here we should get proper code page conversions. | ||
83 | For now hack for Cyrrilic->Unicode | ||
84 | */ | ||
85 | unsigned char *table = conversion_table[uni_char[0]]; | ||
86 | if (table!=0) | ||
87 | return table[uni_char[1]]; | ||
88 | /* If page is not present -> no conversion */ | ||
89 | return uni_char[1]; | ||
90 | |||
91 | } | ||
92 | |||
93 | void to_unicode(unsigned char c, unsigned char page, unsigned char *uni_char) | ||
94 | { | ||
95 | unsigned char *table = reverse_conversion_table[page]; | ||
96 | if (table!=0) | ||
97 | uni_char[1] = table[c]; | ||
98 | else | ||
99 | uni_char[1] = c; | ||
100 | uni_char[0] = page; | ||
101 | } | ||