pokemon_char_encode.c 6.1 KB

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