-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
pokemon_char_encode.c
317 lines (309 loc) · 6.07 KB
/
pokemon_char_encode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#include <stdint.h>
#include <stddef.h>
#include "pokemon_char_encode.h"
char pokemon_char_to_encoded(int byte) {
switch(byte) {
case 'A':
return A_;
case 'B':
return B_;
case 'C':
return C_;
case 'D':
return D_;
case 'E':
return E_;
case 'F':
return F_;
case 'G':
return G_;
case 'H':
return H_;
case 'I':
return I_;
case 'J':
return J_;
case 'K':
return K_;
case 'L':
return L_;
case 'M':
return M_;
case 'N':
return N_;
case 'O':
return O_;
case 'P':
return P_;
case 'Q':
return Q_;
case 'R':
return R_;
case 'S':
return S_;
case 'T':
return T_;
case 'U':
return U_;
case 'V':
return V_;
case 'W':
return W_;
case 'X':
return X_;
case 'Y':
return Y_;
case 'Z':
return Z_;
case 'a':
return a_;
case 'b':
return b_;
case 'c':
return c_;
case 'd':
return d_;
case 'e':
return e_;
case 'f':
return f_;
case 'g':
return g_;
case 'h':
return h_;
case 'i':
return i_;
case 'j':
return j_;
case 'k':
return k_;
case 'l':
return l_;
case 'm':
return m_;
case 'n':
return n_;
case 'o':
return o_;
case 'p':
return p_;
case 'q':
return q_;
case 'r':
return r_;
case 's':
return s_;
case 't':
return t_;
case 'u':
return u_;
case 'v':
return v_;
case 'w':
return w_;
case 'x':
return x_;
case 'y':
return y_;
case 'z':
return z_;
case '-':
return HYPHEN_;
case '0':
return _0_;
case '1':
return _1_;
case '2':
return _2_;
case '3':
return _3_;
case '4':
return _4_;
case '5':
return _5_;
case '6':
return _6_;
case '7':
return _7_;
case '8':
return _8_;
case '9':
return _9_;
/* This was previously implemented with unicode escape codes, however, that
* seemed to cause compilation issues. Which is strange because others reported
* compilation issues with the actual unicode characters. I'm not sure a good
* universal way to resolve this.
*
* Additionally, the ♂/♀ symbols don't render properly on the flipper. Would
* need to create a custom image/icon somehow, otherwise its nonobvious that
* the traded pokemon would have this symbol in their name.
*/
case '\201':
return MALE_;
case '\200':
return FEMALE_;
default:
return TERM_;
}
}
int pokemon_encoded_to_char(char byte) {
switch(byte) {
case A_:
return 'A';
case B_:
return 'B';
case C_:
return 'C';
case D_:
return 'D';
case E_:
return 'E';
case F_:
return 'F';
case G_:
return 'G';
case H_:
return 'H';
case I_:
return 'I';
case J_:
return 'J';
case K_:
return 'K';
case L_:
return 'L';
case M_:
return 'M';
case N_:
return 'N';
case O_:
return 'O';
case P_:
return 'P';
case Q_:
return 'Q';
case R_:
return 'R';
case S_:
return 'S';
case T_:
return 'T';
case U_:
return 'U';
case V_:
return 'V';
case W_:
return 'W';
case X_:
return 'X';
case Y_:
return 'Y';
case Z_:
return 'Z';
case a_:
return 'a';
case b_:
return 'b';
case c_:
return 'c';
case d_:
return 'd';
case e_:
return 'e';
case f_:
return 'f';
case g_:
return 'g';
case h_:
return 'h';
case i_:
return 'i';
case j_:
return 'j';
case k_:
return 'k';
case l_:
return 'l';
case m_:
return 'm';
case n_:
return 'n';
case o_:
return 'o';
case p_:
return 'p';
case q_:
return 'q';
case r_:
return 'r';
case s_:
return 's';
case t_:
return 't';
case u_:
return 'u';
case v_:
return 'v';
case w_:
return 'w';
case x_:
return 'x';
case y_:
return 'y';
case z_:
return 'z';
case HYPHEN_:
return '-';
case _0_:
return '0';
case _1_:
return '1';
case _2_:
return '2';
case _3_:
return '3';
case _4_:
return '4';
case _5_:
return '5';
case _6_:
return '6';
case _7_:
return '7';
case _8_:
return '8';
case _9_:
return '9';
/* This was previously implemented with unicode escape codes, however, that
* seemed to cause compilation issues. Which is strange because others reported
* compilation issues with the actual unicode characters. I'm not sure a good
* universal way to resolve this.
*
* Additionally, the ♂/♀ symbols don't render properly on the flipper. Would
* need to create a custom image/icon somehow, otherwise its nonobvious that
* the traded pokemon would have this symbol in their name.
*/
case MALE_:
return '\201';
case FEMALE_:
return '\200';
default:
return '\0';
}
}
/* encode n bytes, any currently noninputtable characters are set with TERM_ */
void pokemon_str_to_encoded_array(uint8_t* dest, char* src, size_t n) {
for(; n > 0; n--) {
*dest = pokemon_char_to_encoded(*src);
dest++;
src++;
}
}
/* decode n bytes, any currently noninputtable characters are set with '\0' */
void pokemon_encoded_array_to_str(char* dest, uint8_t* src, size_t n) {
for(; n > 0; n--) {
*dest = pokemon_encoded_to_char(*src);
dest++;
src++;
}
}