pokemon_char_encode.c 6.1 KB

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