From 301ccf602b14a65fec33ab419898d53c7dbe7792 Mon Sep 17 00:00:00 2001 From: Remnants of Forgotten Disney Date: Sun, 7 Apr 2024 16:46:39 -0500 Subject: [PATCH] Finalizing Red/Blue Payload --- graphics/button_cancel_left.grit | 3 + graphics/button_cancel_left.png | Bin 0 -> 258 bytes graphics/button_confirm_left.grit | 3 + graphics/button_confirm_left.png | Bin 0 -> 267 bytes include/box_menu.h | 1 + include/button_handler.h | 1 - include/debug_mode.h | 4 +- include/gameboy_colour.h | 8 +-- include/payloads/eng_payloads.h | 98 ++++++++++++++++++++------ include/pokemon.h | 1 + include/script_array.h | 8 +-- include/sprite_data.h | 6 ++ source/box_menu.cpp | 110 ++++++++++++++++++++++++------ source/button_handler.cpp | 2 - source/gameboy_colour.cpp | 71 ++++++++++++++++--- source/pokemon.cpp | 2 +- source/pokemon_party.cpp | 4 +- source/script_array.cpp | 34 ++++----- source/sprite_data.cpp | 14 +++- 19 files changed, 279 insertions(+), 91 deletions(-) create mode 100644 graphics/button_cancel_left.grit create mode 100644 graphics/button_cancel_left.png create mode 100644 graphics/button_confirm_left.grit create mode 100644 graphics/button_confirm_left.png diff --git a/graphics/button_cancel_left.grit b/graphics/button_cancel_left.grit new file mode 100644 index 0000000..aa1971c --- /dev/null +++ b/graphics/button_cancel_left.grit @@ -0,0 +1,3 @@ +# +# Button : 4bpp, not compressed. Pallet 2, copy from 32 to 48. +-gB4 -ps32 -pe48 \ No newline at end of file diff --git a/graphics/button_cancel_left.png b/graphics/button_cancel_left.png new file mode 100644 index 0000000000000000000000000000000000000000..424258dc2cb549e88b776a8c7c528985a92f5691 GIT binary patch literal 258 zcmeAS@N?(olHy`uVBq!ia0vp^4nVBH!VDw>HYaZfQU(D&A+AS{9yPQy{PF+C|NsAi zVg$iG``lKbBF2&+zhDN3XE)M-oCZ%9$B>FSS0`WOJ)pqh@{(hY@C!EI@AucTe>=R4 zZPt&=^JZz-Ir4O^$-W$*RMjG+S^a2XielF`50($o4l})Td9PWf*B#*aA?JG}p?LFM zhIoeX_pjLlZdTl3Y@5N5cjV4t(dmoNy}z)_yC?F-k88pDjF~4>L+AeM-tp?|(d*Gy YIUC$l1j;tMX@Fes>FVdQ&MBb@0J?Eo3;+NC literal 0 HcmV?d00001 diff --git a/graphics/button_confirm_left.grit b/graphics/button_confirm_left.grit new file mode 100644 index 0000000..aa1971c --- /dev/null +++ b/graphics/button_confirm_left.grit @@ -0,0 +1,3 @@ +# +# Button : 4bpp, not compressed. Pallet 2, copy from 32 to 48. +-gB4 -ps32 -pe48 \ No newline at end of file diff --git a/graphics/button_confirm_left.png b/graphics/button_confirm_left.png new file mode 100644 index 0000000000000000000000000000000000000000..04bb9c322850b4e8402296a45b3f38d77cfe048a GIT binary patch literal 267 zcmeAS@N?(olHy`uVBq!ia0vp^4nVBH!VDw>HYaZfQU(D&A+AS{9yPQy{PF+C|NsAi zVg$iG``lKbBF2&+zhDN3XE)M-oK8;{$B>FSS0@MZH7Ibjz2tbn`GIZi@B3@zSFPOY zI9va#y~YD`fp(YAQ5GVC`3pNv%}UXT>^x*D#PE~zz>AiphlEPhxa4>L=F{Lg%H?A- zpOt4_6@%Co20!)#CQPqXWj+W+k@`!^SZX; 0)) + if (curr_button == 0) { - x--; - update_pos = true; + if (key_hit(KEY_LEFT) && (x > 0)) + { + x--; + update_pos = true; + } + else if (key_hit(KEY_RIGHT) && (x < 9)) + { + x++; + update_pos = true; + } + else if (key_hit(KEY_UP) && y > 0) + { + y--; + update_pos = true; + } + else if (key_hit(KEY_DOWN) && (y < 2)) + { + y++; + update_pos = true; + } + else if (key_hit(KEY_DOWN) && (y == 2)) + { + obj_hide(box_select); + if (x < 5) + { + cancel_button.set_highlight(true); + curr_button = CANCEL_BUTTON; + } + else + { + confirm_button.set_highlight(true); + curr_button = CONFIRM_BUTTON; + } + } } - else if (key_hit(KEY_RIGHT) && (x < 9)) + else { - x++; - update_pos = true; - } - else if (key_hit(KEY_UP) && y > 0) - { - y--; - update_pos = true; - } - else if (key_hit(KEY_DOWN) && (y < 2)) - { - y++; - update_pos = true; + if (key_hit(KEY_LEFT) && (curr_button == CONFIRM_BUTTON)) + { + curr_button = CANCEL_BUTTON; + cancel_button.set_highlight(true); + confirm_button.set_highlight(false); + x -= 5; + } + else if (key_hit(KEY_RIGHT) && (curr_button == CANCEL_BUTTON)) + { + curr_button = CONFIRM_BUTTON; + cancel_button.set_highlight(false); + confirm_button.set_highlight(true); + x += 5; + } + else if (key_hit(KEY_UP)) + { + curr_button = 0; + cancel_button.set_highlight(false); + confirm_button.set_highlight(false); + obj_unhide(box_select, 0); + update_pos = true; + } + else if (key_hit(KEY_A)) + { + cancel_button.hide(); + confirm_button.hide(); + for (int i = 0; i < 30; i++) + { + obj_hide(party_sprites[i]); + } + tte_erase_screen(); + obj_unhide(prof, 0); + REG_BG2VOFS = BG2VOF_SMALL_TEXTBOX; + return curr_button; + } } if (update_pos) { @@ -49,14 +119,14 @@ int Box_Menu::box_main(Pokemon_Party party_data) tte_erase_rect(40, 72, 220, 88); if (party_data.get_simple_pkmn(index).is_valid) { - char nickname[10] = {'t', 'e', 's', 't', 'i', 'n', 'g'}; + char nickname[10] = {}; for (int i = 0; i < 10; i++) { nickname[i] = gen_3_Intern_char_array[party_data.get_simple_pkmn(index).nickname[i]]; } tte_set_pos(40, 72); tte_write(nickname); - tte_set_pos(56, 80); + tte_set_pos(48, 80); tte_write(NAMES[party_data.get_simple_pkmn(index).dex_number].data()); tte_set_pos(146, 80); tte_write("Lv: "); diff --git a/source/button_handler.cpp b/source/button_handler.cpp index e8b2474..7ec6f34 100644 --- a/source/button_handler.cpp +++ b/source/button_handler.cpp @@ -1,7 +1,5 @@ #include "button_handler.h" -Button::Button() {} - Button::Button(OBJ_ATTR *L, OBJ_ATTR *R, int nLeft_button_width) { button_L = L; diff --git a/source/gameboy_colour.cpp b/source/gameboy_colour.cpp index a1119e2..9af0df3 100644 --- a/source/gameboy_colour.cpp +++ b/source/gameboy_colour.cpp @@ -27,7 +27,11 @@ #define trade_data 7 #define box_preamble 8 #define box_data 9 -#define end 10 +#define end1 10 +#define reboot 11 +#define remove_array_preamble 12 +#define send_remove_array 13 +#define end2 14 const int MODE = 1; // mode=0 will transfer pokemon data from pokemon.h // mode=1 will copy pokemon party data being received @@ -104,8 +108,9 @@ void setup() } } -byte handleIncomingByte(byte in, byte *box_data_storage, PAYLOAD *curr_payload) +byte handleIncomingByte(byte in, byte *box_data_storage, PAYLOAD *curr_payload, Simplified_Pokemon *curr_simple_array) { + // TODO: Change to a switch statement if (state == hs) { if (in == 0x00) @@ -141,6 +146,7 @@ byte handleIncomingByte(byte in, byte *box_data_storage, PAYLOAD *curr_payload) { if (in == 0xfd) { + mosi_delay = 1; state = party_preamble; } return in; @@ -171,7 +177,6 @@ byte handleIncomingByte(byte in, byte *box_data_storage, PAYLOAD *curr_payload) { state = box_data; data_counter = 0; - mosi_delay = 1; return exchange_boxes(in, box_data_storage); } return in; @@ -181,15 +186,43 @@ byte handleIncomingByte(byte in, byte *box_data_storage, PAYLOAD *curr_payload) { if (data_counter >= BOX_DATA_ARRAY_SIZE) { - state = end; + state = end1; } return exchange_boxes(in, box_data_storage); } + else if (state == reboot) + { + data_counter = 0; + mosi_delay = 16; + state = remove_array_preamble; + return 0xFD; + } + + else if (state == remove_array_preamble) + { + if (in != 0xFD) + { + state = send_remove_array; + return exchange_remove_array(in, curr_simple_array); + } + return in; + } + + else if (state == send_remove_array) + { + if (data_counter >= 39) + { + state = end2; + } + data_counter++; + return exchange_remove_array(in, curr_simple_array); + } + return in; } -int loop(byte *box_data_storage, PAYLOAD *curr_payload) +int loop(byte *box_data_storage, PAYLOAD *curr_payload, Simplified_Pokemon *curr_simple_array) { int counter = 0; while (true) @@ -206,7 +239,7 @@ int loop(byte *box_data_storage, PAYLOAD *curr_payload) std::to_string(in_data) + "][" + std::to_string(out_data) + "]\n"); } - out_data = handleIncomingByte(in_data, box_data_storage, curr_payload); + out_data = handleIncomingByte(in_data, box_data_storage, curr_payload, curr_simple_array); if (FF_count > 25) { @@ -221,12 +254,19 @@ int loop(byte *box_data_storage, PAYLOAD *curr_payload) return COND_ERROR_COLOSSEUM; } - if (state == end) + if (state == end1) + { + state = reboot; + return 0; + } + + if (state == end2) { return 0; } - if (DEBUG_MODE && key_hit(KEY_SELECT)){ + if (DEBUG_MODE && key_hit(KEY_SELECT)) + { return COND_ERROR_DISCONNECT; } @@ -255,4 +295,17 @@ byte exchange_boxes(byte curr_in, byte *box_data_storage) box_data_storage[data_counter] = curr_in; data_counter += 1; return curr_in; -}; \ No newline at end of file +}; + +byte exchange_remove_array(byte curr_in, Simplified_Pokemon *curr_simple_array) +{ + for (int i = 29; i >= 0; i--) + { + if (curr_simple_array[i].is_valid && !curr_simple_array[i].is_transferred) + { + curr_simple_array[i].is_transferred = true; + return i; + } + } + return 0xFF; +} \ No newline at end of file diff --git a/source/pokemon.cpp b/source/pokemon.cpp index 0e51587..7deda79 100644 --- a/source/pokemon.cpp +++ b/source/pokemon.cpp @@ -655,7 +655,6 @@ bool Pokemon::get_is_new() Simplified_Pokemon Pokemon::get_simple_pkmn() { - // Simplified_Pokemon curr_pkmn; curr_pkmn.dex_number = get_dex_number(); curr_pkmn.met_level = met_level; @@ -664,5 +663,6 @@ Simplified_Pokemon Pokemon::get_simple_pkmn() curr_pkmn.nickname[i] = nickname[i]; } curr_pkmn.is_valid = get_validity(); + curr_pkmn.is_transferred = false; return curr_pkmn; } \ No newline at end of file diff --git a/source/pokemon_party.cpp b/source/pokemon_party.cpp index 6583b2d..05c55c3 100644 --- a/source/pokemon_party.cpp +++ b/source/pokemon_party.cpp @@ -97,12 +97,12 @@ void Pokemon_Party::start_link() else { setup(); - last_error = loop(&box_data_array[0], &curr_payload); + last_error = loop(&box_data_array[0], &curr_payload, simple_pkmn_array); } } void Pokemon_Party::continue_link(){ - last_error = loop(&box_data_array[0], &curr_payload); + last_error = loop(&box_data_array[0], &curr_payload, simple_pkmn_array); } int Pokemon_Party::get_last_error() diff --git a/source/script_array.cpp b/source/script_array.cpp index 924f3a3..e8ba486 100644 --- a/source/script_array.cpp +++ b/source/script_array.cpp @@ -44,7 +44,7 @@ void populate_dialogue() dialogue[DIA_WHAT_GAME] = "And which Game Boy Pok@mon\ngame are you transferring\nfrom?"; dialogue[DIA_WHAT_LANG] = "What language is the Game\nBoy Pok@mon game that you're\ntransferring from?"; dialogue[DIA_NO_PAYLOAD] = "I'm sorry, but that version\nin that language is not\ncurrently supported."; - dialogue[DIA_IN_BOX] = "Great! Let's take a look at\nthe Pok@mon that will be\ntransfered.|Please remember, once a\nPok@mon is transfered, it\nCANNOT be returned to the\nGame Boy Game Pak.|Select transfer once you're\nready, or select cancel if\nyou want to keep the Pok@mon\non your Game Boy Game Pak."; + dialogue[DIA_IN_BOX] = "Great! Let's take a look at\nthe Pok@mon that will be\ntransfered.|Please remember, once a\nPok@mon is transfered, it\nCANNOT be returned to the\nGame Boy Game Pak.|Select confirm once you're\nready, or select cancel if\nyou want to keep the Pok@mon\non your Game Boy Game Pak."; dialogue[DIA_ERROR_COLOSSEUM] = "It looks like you went to\nthe colosseum instead of the\ntrading room!|Let's try that again!"; dialogue[DIA_ERROR_COM_ENDED] = "Communication with the other\ndevice was terminated.|Let's try that again!"; @@ -98,10 +98,9 @@ void populate_script() script[DIA_ERROR_DISCONNECT] = script_obj(dialogue[DIA_ERROR_DISCONNECT], DIA_START); // Pause the transfer and show the user their box data - script[DIA_IN_BOX] = script_obj(dialogue[DIA_IN_BOX], CMD_SHOW_LARGE_TEXTBOX); - script[CMD_SHOW_LARGE_TEXTBOX] = script_obj(CMD_SHOW_LARGE_TEXTBOX, CMD_BOX_MENU); - script[CMD_BOX_MENU] = script_obj(CMD_BOX_MENU, CMD_HIDE_LARGE_TEXTBOX); - script[CMD_HIDE_LARGE_TEXTBOX] = script_obj(CMD_HIDE_LARGE_TEXTBOX, DIA_LETS_START); + script[DIA_IN_BOX] = script_obj(dialogue[DIA_IN_BOX], CMD_BOX_MENU); + script[CMD_BOX_MENU] = script_obj(CMD_BOX_MENU, CMD_CONTINUE_LINK); + script[CMD_CONTINUE_LINK] = script_obj(CMD_CONTINUE_LINK, CMD_IMPORT_POKEMON); // Complete the transfer and give messages based on the transfered Pokemon script[CMD_IMPORT_POKEMON] = script_obj(CMD_IMPORT_POKEMON, DIA_TRANS_GOOD, DIA_NO_VALID_PKMN); @@ -210,9 +209,6 @@ bool run_conditional(int index) return true; case CMD_IMPORT_POKEMON: - // party_data.set_lang(ENG_ID); - // party_data.set_game(RED_ID); - // REMOVE ME ^ return inject_mystery(party_data); case CMD_BACK_TO_MENU: @@ -268,7 +264,10 @@ bool run_conditional(int index) for (int i = 0; i < 48; i++) { obj_set_pos(prof, (prof->attr1 & ATTR1_X_MASK) - 2, prof->attr0 & ATTR0_Y_MASK); - global_next_frame(); + if (!DEBUG_MODE) + { + global_next_frame(); + } } return true; @@ -276,22 +275,13 @@ bool run_conditional(int index) for (int i = 0; i < 48; i++) { obj_set_pos(prof, (prof->attr1 & ATTR1_X_MASK) + 2, prof->attr0 & ATTR0_Y_MASK); - global_next_frame(); + if (!DEBUG_MODE) + { + global_next_frame(); + } } return true; - case CMD_SHOW_LARGE_TEXTBOX: - tte_erase_screen(); - obj_hide(prof); - REG_BG2VOFS = BG2VOF_LARGE_TEXTBOX; - return true; - - case CMD_HIDE_LARGE_TEXTBOX: - tte_erase_screen(); - obj_unhide(prof, 0); - REG_BG2VOFS = BG2VOF_SMALL_TEXTBOX; - return true; - case CMD_CONTINUE_LINK: party_data.continue_link(); return true; diff --git a/source/sprite_data.cpp b/source/sprite_data.cpp index 58b8671..3ed2e70 100644 --- a/source/sprite_data.cpp +++ b/source/sprite_data.cpp @@ -132,6 +132,11 @@ OBJ_ATTR *party_sprites[30] = { &obj_buffer[num_sprites++], &obj_buffer[num_sprites++], &obj_buffer[num_sprites++], &obj_buffer[num_sprites++], &obj_buffer[num_sprites++], }; +OBJ_ATTR *button_cancel_left = &obj_buffer[num_sprites++]; +OBJ_ATTR *button_cancel_right = &obj_buffer[num_sprites++]; +OBJ_ATTR *button_confirm_left = &obj_buffer[num_sprites++]; +OBJ_ATTR *button_confirm_right = &obj_buffer[num_sprites++]; + u32 global_tile_id_end = 0; void load_eternal_sprites() @@ -199,13 +204,16 @@ void load_temp_box_sprites(Pokemon_Party party_data){ u32 curr_tile_id = global_tile_id_end; for (int i = 0; i < 30; i++){ if (party_data.get_simple_pkmn(i).is_valid){ - load_sprite(party_sprites[i], &duel_frame_menu_spritesTiles[(MENU_SPRITES[party_data.get_simple_pkmn(i).dex_number] - 1) * 32], 256, curr_tile_id, MENU_SPRITE_PAL, ATTR0_SQUARE, ATTR1_SIZE_16x16, 2); + load_sprite(party_sprites[i], &duel_frame_menu_spritesTiles[(MENU_SPRITES[party_data.get_simple_pkmn(i).dex_number] - 1) * 32], 256, curr_tile_id, MENU_SPRITE_PAL, ATTR0_SQUARE, ATTR1_SIZE_16x16, 1); obj_set_pos(party_sprites[i], (16 * (i % 10)) + 40, (16 * (i / 10)) + 24); - obj_unhide(party_sprites[i], 0); } curr_tile_id += 4; } - load_sprite(box_select, box_selectTiles, box_selectTilesLen, curr_tile_id, BTN_PAL, ATTR0_SQUARE, ATTR1_SIZE_16x16, 1); + load_sprite(box_select, box_selectTiles, box_selectTilesLen, curr_tile_id, BTN_PAL, ATTR0_SQUARE, ATTR1_SIZE_16x16, 0); + load_sprite(button_cancel_left, button_cancel_leftTiles, button_cancel_leftTilesLen, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1); + load_sprite(button_cancel_right, button_game_select_edgeTiles, button_game_select_edgeTilesLen, curr_tile_id, BTN_PAL, ATTR0_TALL, ATTR1_SIZE_8x32, 1); + load_sprite(button_confirm_left, button_confirm_leftTiles, button_confirm_leftTilesLen, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1); + load_sprite(button_confirm_right, button_game_select_edgeTiles, button_game_select_edgeTilesLen, curr_tile_id, BTN_PAL, ATTR0_TALL, ATTR1_SIZE_8x32, 1); } void load_sprite(OBJ_ATTR *sprite, const unsigned int objTiles[], int objTilesLen,