1 // ----------------------------------------------------------------------------
2 //
3 // thorvaricode.cxx -- THOR Varicode
4 //
5 // Copyright (C) 2008
6 // Dave Freese, W1HKJ
7 //
8 // This file is part of fldigi.
9 //
10 // Fldigi is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Fldigi is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with fldigi. If not, see <http://www.gnu.org/licenses/>.
22 // ----------------------------------------------------------------------------
23
24 #include <config.h>
25
26 #include "mfskvaricode.h"
27 #include "thorvaricode.h"
28
29 // THOR varicode is an extended set of the IZ8BLY MFSK varicode that uses the
30 // unallocated remaining 12 bit codes for a secondary character set.
31
32 // Primary character set (same as MFSK)
33
34 // extended 12 bit codes for secondary characters
35 // 90 used, leaving 10 for possible special use
36
37 // encoding table
38
39 static const char *thor_varicode[] = {
40 "101110000000", /* 032 - <SPC> */
41 "101110100000", /* 033 - ! */
42 "101110101000", /* 034 - '"' */
43 "101110101100", /* 035 - # */
44 "101110110000", /* 036 - $ */
45 "101110110100", /* 037 - % */
46 "101110111000", /* 038 - & */
47 "101110111100", /* 039 - ' */
48 "101111000000", /* 040 - ( */
49 "101111010000", /* 041 - ) */
50 "101111010100", /* 042 - * */
51 "101111011000", /* 043 - + */
52 "101111011100", /* 044 - , */
53 "101111100000", /* 045 - - */
54 "101111101000", /* 046 - . */
55 "101111101100", /* 047 - / */
56 "101111110000", /* 048 - 0 */
57 "101111110100", /* 049 - 1 */
58 "101111111000", /* 050 - 2 */
59 "101111111100", /* 051 - 3 */
60 "110000000000", /* 052 - 4 */
61 "110100000000", /* 053 - 5 */
62 "110101000000", /* 054 - 6 */
63 "110101010100", /* 055 - 7 */
64 "110101011000", /* 056 - 8 */
65 "110101011100", /* 057 - 9 */
66 "110101100000", /* 058 - : */
67 "110101101000", /* 059 - ; */
68 "110101101100", /* 060 - < */
69 "110101110000", /* 061 - = */
70 "110101110100", /* 062 - > */
71 "110101111000", /* 063 - ? */
72 "110101111100", /* 064 - @ */
73 "110110000000", /* 065 - A */
74 "110110100000", /* 066 - B */
75 "110110101000", /* 067 - C */
76 "110110101100", /* 068 - D */
77 "110110110000", /* 069 - E */
78 "110110110100", /* 070 - F */
79 "110110111000", /* 071 - G */
80 "110110111100", /* 072 - H */
81 "110111000000", /* 073 - I */
82 "110111010000", /* 074 - J */
83 "110111010100", /* 075 - K */
84 "110111011000", /* 076 - L */
85 "110111011100", /* 077 - M */
86 "110111100000", /* 078 - N */
87 "110111101000", /* 079 - O */
88 "110111101100", /* 080 - P */
89 "110111110000", /* 081 - Q */
90 "110111110100", /* 082 - R */
91 "110111111000", /* 083 - S */
92 "110111111100", /* 084 - T */
93 "111000000000", /* 085 - U */
94 "111010000000", /* 086 - V */
95 "111010100000", /* 087 - W */
96 "111010101100", /* 088 - X */
97 "111010110000", /* 089 - Y */
98 "111010110100", /* 090 - Z */
99 "111010111000", /* 091 - [ */
100 "111010111100", /* 092 - \ */
101 "111011000000", /* 093 - ] */
102 "111011010000", /* 094 - ^ */
103 "111011010100", /* 095 - _ */
104 "111011011000", /* 096 - ` */
105 "111011011100", /* 097 - a */
106 "111011100000", /* 098 - b */
107 "111011101000", /* 099 - c */
108 "111011101100", /* 100 - d */
109 "111011110000", /* 101 - e */
110 "111011110100", /* 102 - f */
111 "111011111000", /* 103 - g */
112 "111011111100", /* 104 - h */
113 "111100000000", /* 105 - i */
114 "111101000000", /* 106 - j */
115 "111101010000", /* 107 - k */
116 "111101010100", /* 108 - l */
117 "111101011000", /* 109 - m */
118 "111101011100", /* 110 - n */
119 "111101100000", /* 111 - o */
120 "111101101000", /* 112 - p */
121 "111101101100", /* 113 - q */
122 "111101110000", /* 114 - r */
123 "111101110100", /* 115 - s */
124 "111101111000", /* 116 - t */
125 "111101111100", /* 117 - u */
126 "111110000000", /* 118 - v */
127 "111110100000", /* 119 - w */
128 "111110101000", /* 120 - x */
129 "111110101100", /* 121 - y */
130 "111110110000" /* 122 - z */
131 };
132
133 // unused 12 bit varicodes
134 /*
135 static char *unused[] = {
136 "111110110100",
137 "111110111000",
138 "111110111100",
139 "111111000000",
140 "111111010100",
141 "111111011000",
142 "111111011100",
143 "111111100000",
144 "111111101000",
145 "111111101100",
146 "111111110000",
147 "111111110100",
148 "111111111100"
149 };
150 */
151
152 // decoding table
153
154 static const unsigned int thor_varidecode[] = {
155 0xB80, 0xBA0, 0xBA8, 0xBAC, 0xBB0, 0xBB4, 0xBB8, 0xBBC,
156 0xBC0, 0xBD0, 0xBD4, 0xBD8, 0xBDC, 0xBE0, 0xBE8, 0xBEC,
157 0xBF0, 0xBF4, 0xBF8, 0xBFC, 0xC00, 0xD00, 0xD40, 0xD54,
158 0xD58, 0xD5C, 0xD60, 0xD68, 0xD6C, 0xD70, 0xD74, 0xD78,
159 0xD7C, 0xD80, 0xDA0, 0xDA8, 0xDAC, 0xDB0, 0xDB4, 0xDB8,
160 0xDBC, 0xDC0, 0xDD0, 0xDD4, 0xDD8, 0xDDC, 0xDE0, 0xDE8,
161 0xDEC, 0xDF0, 0xDF4, 0xDF8, 0xDFC, 0xE00, 0xE80, 0xEA0,
162 0xEAC, 0xEB0, 0xEB4, 0xEB8, 0xEBC, 0xEC0, 0xED0, 0xED4,
163 0xED8, 0xEDC, 0xEE0, 0xEE8, 0xEEC, 0xEF0, 0xEF4, 0xEF8,
164 0xEFC, 0xF00, 0xF40, 0xF50, 0xF54, 0xF58, 0xF5C, 0xF60,
165 0xF68, 0xF6C, 0xF70, 0xF74, 0xF78, 0xF7C, 0xF80, 0xFA0,
166 0xFA8, 0xFAC, 0xFB0
167 };
168 static int limit = sizeof(thor_varidecode)/sizeof(unsigned int);
169
thorvarienc(int c,int sec)170 const char *thorvarienc(int c, int sec)
171 {
172 if (sec == 0)
173 return varienc(c); // mfsk varicode
174 else
175 if (c >= ' ' && c <= 'z')
176 return thor_varicode[c - ' '];
177
178 return varienc(0); // return code for NULL if not in tables
179 }
180
thorvaridec(unsigned int symbol)181 int thorvaridec(unsigned int symbol)
182 {
183 int i;
184
185 if (symbol < 0xB80)
186 return varidec(symbol); // find in the MFSK decode table
187
188 for (i = 0; i < limit; i++)
189 if (symbol == thor_varidecode[i])
190 return (' ' + i + 0x100); // found in the extended decode table
191
192 return -1; // not found
193 }
194
195