Reorder some operands to increase frequency of multiply early termination on TDMI...
[kugel-rb.git] / firmware / hangul.c
blob01c6ba2fab2ea77c0921b109797351d16b62a890
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
10 * Copyright (C) 2006 by Frank Dischner
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "hangul.h"
23 const char jamo_table[51][3] = {
24 { 1, 0, 1},
25 { 2, 0, 2},
26 { 0, 0, 3},
27 { 3, 0, 4},
28 { 0, 0, 5},
29 { 0, 0, 6},
30 { 4, 0, 7},
31 { 5, 0, 0},
32 { 6, 0, 8},
33 { 0, 0, 9},
34 { 0, 0, 10},
35 { 0, 0, 11},
36 { 0, 0, 12},
37 { 0, 0, 13},
38 { 0, 0, 14},
39 { 0, 0, 15},
40 { 7, 0, 16},
41 { 8, 0, 17},
42 { 9, 0, 0},
43 { 0, 0, 18},
44 {10, 0, 19},
45 {11, 0, 20},
46 {12, 0, 21},
47 {13, 0, 22},
48 {14, 0, 0},
49 {15, 0, 23},
50 {16, 0, 24},
51 {17, 0, 25},
52 {18, 0, 26},
53 {19, 0, 27},
54 { 0, 1, 0},
55 { 0, 2, 0},
56 { 0, 3, 0},
57 { 0, 4, 0},
58 { 0, 5, 0},
59 { 0, 6, 0},
60 { 0, 7, 0},
61 { 0, 8, 0},
62 { 0, 9, 0},
63 { 0, 10, 0},
64 { 0, 11, 0},
65 { 0, 12, 0},
66 { 0, 13, 0},
67 { 0, 14, 0},
68 { 0, 15, 0},
69 { 0, 16, 0},
70 { 0, 17, 0},
71 { 0, 18, 0},
72 { 0, 19, 0},
73 { 0, 20, 0},
74 { 0, 21, 0},
77 /* takes three jamo chars and joins them into one hangul */
78 unsigned short hangul_join(unsigned short lead, unsigned short vowel,
79 unsigned short tail)
81 unsigned short ch = 0xfffd;
83 if (lead < 0x3131 || lead > 0x3163)
84 return ch;
85 lead = jamo_table[lead-0x3131][0];
87 if (vowel < 0x3131 || vowel > 0x3163)
88 return ch;
89 vowel = jamo_table[vowel-0x3131][1];
91 if (tail) {
92 if (tail < 0x3131 || tail > 0x3163)
93 return ch;
94 tail = jamo_table[tail-0x3131][2];
95 if (!tail)
96 return ch;
99 if (lead && vowel)
100 ch = tail + (vowel - 1)*28 + (lead - 1)*588 + 44032;
102 return ch;