pokemon_app.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. #include <furi_hal_light.h>
  2. #include <pokemon_icons.h>
  3. #include "views/trade.hpp"
  4. #include "views/select_pokemon.hpp"
  5. #include "pokemon_app.h"
  6. const PokemonTable pokemon_table[] = {
  7. {"Bulbasaur", &I_bulbasaur, 0x99},
  8. {"Ivysaur", &I_ivysaur, 0x09},
  9. {"Venusaur", &I_venusaur, 0x9A},
  10. {"Charmander", &I_charmander, 0xB0},
  11. {"Charmeleon", &I_charmeleon, 0xB2},
  12. {"Charizard", &I_charizard, 0xB4},
  13. {"Squirtle", &I_squirtle, 0xB1},
  14. {"Wartortle", &I_wartortle, 0xB3},
  15. {"Blastoise", &I_blastoise, 0x1C},
  16. {"Caterpie", &I_caterpie, 0x7B},
  17. {"Metapod", &I_metapod, 0x7C},
  18. {"Butterfree", &I_butterfree, 0x7D},
  19. {"Weedle", &I_weedle, 0x70},
  20. {"Kakuna", &I_kakuna, 0x71},
  21. {"Beedrill", &I_beedrill, 0x72},
  22. {"Pidgey", &I_pidgey, 0x24},
  23. {"Pidgeotto", &I_pidgeotto, 0x96},
  24. {"Pidgeot", &I_pidgeot, 0x97},
  25. {"Rattata", &I_rattata, 0xA5},
  26. {"Raticate", &I_raticate, 0xA6},
  27. {"Spearow", &I_spearow, 0x05},
  28. {"Fearow", &I_fearow, 0x23},
  29. {"Ekans", &I_ekans, 0x6C},
  30. {"Arbok", &I_arbok, 0x2D},
  31. {"Pikachu", &I_pikachu, 0x54},
  32. {"Raichu", &I_raichu, 0x55},
  33. {"Sandshrew", &I_sandshrew, 0x60},
  34. {"Sandslash", &I_sandslash, 0x61},
  35. {"Nidoran ♀", &I_nidoranf, 0x0F},
  36. {"Nidorina", &I_nidorina, 0xA8},
  37. {"Nidoqueen", &I_nidoqueen, 0x10},
  38. {"Nidoran ♂", &I_nidoranm, 0x03},
  39. {"Nidorino", &I_nidorino, 0xA7},
  40. {"Nidoking", &I_nidoking, 0x07},
  41. {"Clefairy", &I_clefairy, 0x04},
  42. {"Clefable", &I_clefable, 0x8E},
  43. {"Vulpix", &I_vulpix, 0x52},
  44. {"Ninetales", &I_ninetales, 0x53},
  45. {"Jigglypuff", &I_jigglypuff, 0x64},
  46. {"Wigglytuff", &I_wigglytuff, 0x65},
  47. {"Zubat", &I_zubat, 0x6B},
  48. {"Golbat", &I_golbat, 0x82},
  49. {"Oddish", &I_oddish, 0xB9},
  50. {"Gloom", &I_gloom, 0xBA},
  51. {"Vileplume", &I_vileplume, 0xBB},
  52. {"Paras", &I_paras, 0x6D},
  53. {"Parasect", &I_parasect, 0x2E},
  54. {"Venonat", &I_venonat, 0x41},
  55. {"Venomoth", &I_venomoth, 0x77},
  56. {"Diglett", &I_diglett, 0x3B},
  57. {"Dugtrio", &I_dugtrio, 0x76},
  58. {"Meowth", &I_meowth, 0x4D},
  59. {"Persian", &I_persian, 0x90},
  60. {"Psyduck", &I_psyduck, 0x2F},
  61. {"Golduck", &I_golduck, 0x80},
  62. {"Mankey", &I_mankey, 0x39},
  63. {"Primeape", &I_primeape, 0x75},
  64. {"Growlithe", &I_growlithe, 0x21},
  65. {"Arcanine", &I_arcanine, 0x14},
  66. {"Poliwag", &I_poliwag, 0x47},
  67. {"Poliwhirl", &I_poliwhirl, 0x6E},
  68. {"Poliwrath", &I_poliwrath, 0x6F},
  69. {"Abra", &I_abra, 0x94},
  70. {"Kadabra", &I_kadabra, 0x26},
  71. {"Alakazam", &I_alakazam, 0x95},
  72. {"Machop", &I_machop, 0x6A},
  73. {"Machoke", &I_machoke, 0x29},
  74. {"Machamp", &I_machamp, 0x7E},
  75. {"Bellsprout", &I_bellsprout, 0xBC},
  76. {"Weepinbell", &I_weepinbell, 0xBD},
  77. {"Victreebel", &I_victreebel, 0xBE},
  78. {"Tentacool", &I_tentacool, 0x18},
  79. {"Tentacruel", &I_tentacruel, 0x9B},
  80. {"Geodude", &I_geodude, 0xA9},
  81. {"Graveler", &I_graveler, 0x27},
  82. {"Golem", &I_golem, 0x31},
  83. {"Ponyta", &I_ponyta, 0xA3},
  84. {"Rapidash", &I_rapidash, 0xA4},
  85. {"Slowpoke", &I_slowpoke, 0x25},
  86. {"Slowbro", &I_slowbro, 0x08},
  87. {"Magnemite", &I_magnemite, 0xAD},
  88. {"Magneton", &I_magneton, 0x36},
  89. {"Farfetch'd", &I_farfetchd, 0x40},
  90. {"Doduo", &I_doduo, 0x46},
  91. {"Dodrio", &I_dodrio, 0x74},
  92. {"Seel", &I_seel, 0x3A},
  93. {"Dewgong", &I_dewgong, 0x78},
  94. {"Grimer", &I_grimer, 0x0D},
  95. {"Muk", &I_muk, 0x88},
  96. {"Shellder", &I_shellder, 0x17},
  97. {"Cloyster", &I_cloyster, 0x8B},
  98. {"Gastly", &I_gastly, 0x19},
  99. {"Haunter", &I_haunter, 0x93},
  100. {"Gengar", &I_gengar, 0x0E},
  101. {"Onix", &I_onix, 0x22},
  102. {"Drowzee", &I_drowzee, 0x30},
  103. {"Hypno", &I_hypno, 0x81},
  104. {"Krabby", &I_krabby, 0x4E},
  105. {"Kingler", &I_kingler, 0x8A},
  106. {"Voltorb", &I_voltorb, 0x06},
  107. {"Electrode", &I_electrode, 0x8D},
  108. {"Exeggcute", &I_exeggcute, 0x0C},
  109. {"Exeggutor", &I_exeggutor, 0x0A},
  110. {"Cubone", &I_cubone, 0x11},
  111. {"Marowak", &I_marowak, 0x91},
  112. {"Hitmonlee", &I_hitmonlee, 0x2B},
  113. {"Hitmonchan", &I_hitmonchan, 0x2C},
  114. {"Lickitung", &I_lickitung, 0x0B},
  115. {"Koffing", &I_koffing, 0x37},
  116. {"Weezing", &I_weezing, 0x8F},
  117. {"Rhyhorn", &I_rhyhorn, 0x12},
  118. {"Rhydon", &I_rhydon, 0x01},
  119. {"Chansey", &I_chansey, 0x28},
  120. {"Tangela", &I_tangela, 0x1E},
  121. {"Kangaskhan", &I_kangaskhan, 0x02},
  122. {"Horsea", &I_horsea, 0x5C},
  123. {"Seadra", &I_seadra, 0x5D},
  124. {"Goldeen", &I_goldeen, 0x9D},
  125. {"Seaking", &I_seaking, 0x9E},
  126. {"Staryu", &I_staryu, 0x1B},
  127. {"Starmie", &I_starmie, 0x98},
  128. {"Mr. Mime", &I_mr_mime, 0x2A},
  129. {"Scyther", &I_scyther, 0x1A},
  130. {"Jynx", &I_jynx, 0x48},
  131. {"Electabuzz", &I_electabuzz, 0x35},
  132. {"Magmar", &I_magmar, 0x33},
  133. {"Pinsir", &I_pinsir, 0x1D},
  134. {"Tauros", &I_tauros, 0x3C},
  135. {"Magikarp", &I_magikarp, 0x85},
  136. {"Gyarados", &I_gyarados, 0x16},
  137. {"Lapras", &I_lapras, 0x13},
  138. {"Ditto", &I_ditto, 0x4C},
  139. {"Eevee", &I_eevee, 0x66},
  140. {"Vaporeon", &I_vaporeon, 0x69},
  141. {"Jolteon", &I_jolteon, 0x68},
  142. {"Flareon", &I_flareon, 0x67},
  143. {"Porygon", &I_porygon, 0xAA},
  144. {"Omanyte", &I_omanyte, 0x62},
  145. {"Omastar", &I_omastar, 0x63},
  146. {"Kabuto", &I_kabuto, 0x5A},
  147. {"Kabutops", &I_kabutops, 0x5B},
  148. {"Aerodactyl", &I_aerodactyl, 0xAB},
  149. {"Snorlax", &I_snorlax, 0x84},
  150. {"Articuno", &I_articuno, 0x4A},
  151. {"Zapdos", &I_zapdos, 0x4B},
  152. {"Moltres", &I_moltres, 0x49},
  153. {"Dratini", &I_dratini, 0x58},
  154. {"Dragonair", &I_dragonair, 0x59},
  155. {"Dragonite", &I_dragonite, 0x42},
  156. {"Mewtwo", &I_mewtwo, 0x83},
  157. {"Mew", &I_mew, 0x15},
  158. {},
  159. };
  160. TradeBlock OUTPUT_BLOCK = {
  161. .trainer_name = {F_, l_, i_, p_, p_, e_, r_, TERM_, 0x00, 0x00, 0x00},
  162. .party_cnt = 1,
  163. /* Only the first pokemon is ever used even though there are 7 bytes here.
  164. * If the remaining 6 bytes are _not_ 0xff, then the trade window renders
  165. * garbage for the Flipper's party.
  166. */
  167. .party_members = {0x15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
  168. /* Only the first pokemon is set up, even though there are 6 total party members */
  169. .party =
  170. {
  171. {.species = 0x4a,
  172. .hp = 0x2c01,
  173. .level = 0x4a,
  174. .status_condition = 0x0,
  175. .type = {0x14, 0x08},
  176. .catch_held = 0x1f,
  177. .move = {0x7e, 0x38, 0x09, 0x19},
  178. .orig_trainer = 0xd204,
  179. .exp = {0x3, 0xd, 0x40},
  180. .hp_ev = 0xffff,
  181. .atk_ev = 0xffff,
  182. .def_ev = 0xffff,
  183. .spd_ev = 0xffff,
  184. .special_ev = 0xffff,
  185. .iv = 0xffff,
  186. .move_pp = {0xc0, 0xc0, 0xc0, 0xc0},
  187. .level_again = 0x4a,
  188. .max_hp = 0x2c01,
  189. .atk = 0x9600,
  190. .def = 0x9700,
  191. .spd = 0x9800,
  192. .special = 0x9900},
  193. },
  194. /* Only the first pokemon has an OT name and nickname even though there are 6 members */
  195. /* NOTE: I think this shouldn't exceed 7 chars */
  196. .ot_name =
  197. {
  198. {.str = {F_, l_, i_, p_, p_, e_, r_, TERM_, 0x00, 0x00}},
  199. },
  200. .nickname = {
  201. {.str = {F_, l_, o_, p_, p_, e_, r_, TERM_, 0x00, 0x00}},
  202. }};
  203. uint32_t pokemon_exit_confirm_view(void* context) {
  204. UNUSED(context);
  205. return AppViewExitConfirm;
  206. }
  207. PokemonFap* pokemon_alloc() {
  208. PokemonFap* pokemon_fap = (PokemonFap*)malloc(sizeof(PokemonFap));
  209. // View dispatcher
  210. pokemon_fap->view_dispatcher = view_dispatcher_alloc();
  211. view_dispatcher_enable_queue(pokemon_fap->view_dispatcher);
  212. view_dispatcher_set_event_callback_context(pokemon_fap->view_dispatcher, pokemon_fap);
  213. view_dispatcher_attach_to_gui(
  214. pokemon_fap->view_dispatcher,
  215. (Gui*)furi_record_open(RECORD_GUI),
  216. ViewDispatcherTypeFullscreen);
  217. // Start Index first pokemon
  218. pokemon_fap->curr_pokemon = 0;
  219. // Set up pointer to pokemon table
  220. pokemon_fap->pokemon_table = pokemon_table;
  221. // Set up trade party struct
  222. pokemon_fap->trade_party = &OUTPUT_BLOCK;
  223. // Select Pokemon View
  224. pokemon_fap->select_view = select_pokemon_alloc(pokemon_fap);
  225. view_set_previous_callback(pokemon_fap->select_view, pokemon_exit_confirm_view);
  226. view_dispatcher_add_view(
  227. pokemon_fap->view_dispatcher, AppViewSelectPokemon, pokemon_fap->select_view);
  228. // Trade View
  229. pokemon_fap->trade_view = trade_alloc(pokemon_fap);
  230. view_set_previous_callback(pokemon_fap->trade_view, pokemon_exit_confirm_view);
  231. view_dispatcher_add_view(pokemon_fap->view_dispatcher, AppViewTrade, pokemon_fap->trade_view);
  232. view_dispatcher_switch_to_view(pokemon_fap->view_dispatcher, AppViewSelectPokemon);
  233. return pokemon_fap;
  234. }
  235. void free_app(PokemonFap* pokemon_fap) {
  236. furi_assert(pokemon_fap);
  237. // Free views
  238. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewSelectPokemon);
  239. select_pokemon_free(pokemon_fap);
  240. view_dispatcher_remove_view(pokemon_fap->view_dispatcher, AppViewTrade);
  241. trade_free(pokemon_fap);
  242. // Close records
  243. furi_record_close(RECORD_GUI);
  244. // Free rest
  245. free(pokemon_fap);
  246. pokemon_fap = NULL;
  247. }
  248. extern "C" int32_t pokemon_app(void* p) {
  249. UNUSED(p);
  250. //App* app = (App*)pokemon_alloc();
  251. PokemonFap* pokemon_fap = pokemon_alloc();
  252. furi_hal_light_set(LightRed, 0x00);
  253. furi_hal_light_set(LightGreen, 0x00);
  254. furi_hal_light_set(LightBlue, 0x00);
  255. //switch view and run dispatcher
  256. view_dispatcher_run(pokemon_fap->view_dispatcher);
  257. // Free resources
  258. free_app(pokemon_fap);
  259. return 0;
  260. }