diff --git a/include/gameboy_colour.h b/include/gameboy_colour.h index f238f88..f6a8ac5 100644 --- a/include/gameboy_colour.h +++ b/include/gameboy_colour.h @@ -27,8 +27,8 @@ void setup(); byte handleIncomingByte(byte in); -bool transferBit(byte *party_data); -byte *loop(byte *party_data); +int transferBit(byte *party_data); +int loop(byte *party_data); std::string outHexStr(vu8 inputNum); void updateFrames(); diff --git a/include/pokemon_party.h b/include/pokemon_party.h new file mode 100644 index 0000000..8449115 --- /dev/null +++ b/include/pokemon_party.h @@ -0,0 +1,17 @@ +#ifndef POKEMON_PARTY_H +#define POKEMON_PARTY_H + +#include +#include "pokemon.h" + +class Pokemon_Party{ + public: + Pokemon_Party(); + int start_link(); + + private: + Pokemon party[6]; + byte party_data[444]; +}; + +#endif \ No newline at end of file diff --git a/include/script_array.h b/include/script_array.h index b9d3e1d..2f0d4bb 100644 --- a/include/script_array.h +++ b/include/script_array.h @@ -2,7 +2,10 @@ #define SCRIPT_ARRAY_H #include "script_obj.h" +#include "pokemon_party.h" -extern script_obj script[6]; +extern script_obj script[11]; + +void add_script_party_var(Pokemon_Party var); #endif \ No newline at end of file diff --git a/include/script_obj.h b/include/script_obj.h index e06b42a..9f54a5c 100644 --- a/include/script_obj.h +++ b/include/script_obj.h @@ -2,20 +2,29 @@ #define SCRIPT_OBJ_H #include +#include "pokemon_party.h" + +#define CHECK_GAME 1 +#define START_LINK 2 + +#define ERROR_TIMEOUT 10 +#define ERROR_DISCONNECT 11 +#define ERROR_COM_ENDED 12 class script_obj { public: script_obj(); script_obj(std::string nText, int nNext_index); + script_obj(std::string nText, int nNext_index, int nCond_index); script_obj(std::string nText, int nNext_index, int nCond_index, int nFalse_index); + void link_party_var(Pokemon_Party *var); std::string get_text(); int get_true_index(); int get_false_index(); int get_cond_id(); int get_next_obj_id(); - int get_out_code(); private: std::string text; @@ -23,7 +32,7 @@ private: int conditional_index; int next_false_index; bool run_conditional(int index); - int out_code; + Pokemon_Party *party_data; //ME }; #endif \ No newline at end of file diff --git a/include/text_engine.h b/include/text_engine.h index eb3ea55..661c91b 100644 --- a/include/text_engine.h +++ b/include/text_engine.h @@ -10,11 +10,12 @@ class text_engine { public: text_engine(); - int next_frame(); + void next_frame(); private: script_obj curr_line; int frame_count; + Pokemon_Party *party_data; void set_next_line(std::string next); }; diff --git a/source/gameboy_colour.cpp b/source/gameboy_colour.cpp index f14e0b8..9ab6531 100644 --- a/source/gameboy_colour.cpp +++ b/source/gameboy_colour.cpp @@ -4,70 +4,101 @@ #include "pokemon_trade.h" #include "output.h" #include "LinkGPIO.h" +#include "script_obj.h" +#define BYTE_INCOMPLETE 0 +#define BYTE_COMPLETE 1 +#define TIMEOUT 2 +#define TIMEOUT_LENGTH 1000000 const int MODE = 1; // mode=0 will transfer pokemon data from pokemon.h // mode=1 will copy pokemon party data being received -LinkGPIO* linkGPIO = new LinkGPIO(); +LinkGPIO *linkGPIO = new LinkGPIO(); -uint8_t shift = 0; -uint8_t in_data = 0; -uint8_t out_data = 0; -uint frame = 0; +uint8_t shift; +uint8_t in_data; +uint8_t out_data; +uint frame; -bool SC_state = 0; +bool SC_state; -connection_state_t connection_state = PRE_CONNECT_ONE; -trade_centre_state_gen_II_t trade_centre_state_gen_II = INIT; -int counter = 0; +connection_state_t connection_state; +trade_centre_state_gen_II_t trade_centre_state_gen_II; +int counter; -int gen = 0; +int gen; -int trade_pokemon = -1; +int trade_pokemon; unsigned long last_bit; +int FF_count; +int zero_count; + char hexArr[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; char output[2]; -std::string outHexStr(vu8 inputNum){ +std::string outHexStr(vu8 inputNum) +{ std::string out = "XX"; - out[0] = (inputNum) & 0xF; - out[1] = (inputNum>>4) & 0xF; - return out; + out[0] = (inputNum)&0xF; + out[1] = (inputNum >> 4) & 0xF; + return out; } std::string out_array[10]; -void print(std::string str){ - for (int i = 10; i > 0; i--){ +void print(std::string str) +{ + for (int i = 10; i > 0; i--) + { out_array[i] = out_array[i - 1]; } out_array[0] = std::to_string(frame) + ": " + str + "\n"; - tte_erase_screen(); - tte_set_pos(0, 0); - for (int j = 0; j < 10; j++){ + tte_erase_screen(); + tte_set_pos(0, 0); + for (int j = 0; j < 10; j++) + { tte_write(out_array[j].c_str()); } } -void updateFrames(){ - if (((connection_state > 1) && (frame - last_bit >= ((trade_centre_state_gen_II >= WAITING_TO_SEND_DATA) ? 10 : 1000))) /*|| connection_state == PRE_CONNECTED*/) - { - SC_state = !SC_state; - linkGPIO->writePin(LinkGPIO::Pin::SC, SC_state); - //print(SC_state ? "True" : "False"); - last_bit = frame; - } +void updateFrames() +{ + if (((connection_state > 1) && (frame - last_bit >= ((trade_centre_state_gen_II >= WAITING_TO_SEND_DATA) ? 10 : 1000))) /*|| connection_state == PRE_CONNECTED*/) + { + SC_state = !SC_state; + linkGPIO->writePin(LinkGPIO::Pin::SC, SC_state); + // print(SC_state ? "True" : "False"); + last_bit = frame; + } frame++; } void setup() { + shift = 0; + in_data = 0; + out_data = 0; + frame = 0; + + SC_state = 0; + + connection_state = PRE_CONNECT_ONE; + trade_centre_state_gen_II = INIT; + counter = 0; + + gen = 0; + + trade_pokemon = -1; + + FF_count = 0; + zero_count = 0; + // pinMode(SCLK_, INPUT); // pinMode(MISO_, INPUT); // pinMode(MOSI_, OUTPUT); @@ -94,36 +125,53 @@ void setup() // digitalWrite(MOSI_, LOW); linkGPIO->writePin(LinkGPIO::Pin::SO, 0); out_data <<= 1; - } - byte handleIncomingByte(byte in) { byte send = 0x00; - - switch (connection_state) - { - case PRE_CONNECT_ONE: - if (in == PKMN_MASTER){ - connection_state = PRE_CONNECT_TWO; + + if (trade_centre_state_gen_II < WAITING_TO_SEND_DATA) + { + switch (in) + { + case 0x00: + FF_count = 0; + zero_count++; + break; + + case 0xFF: + zero_count = 0; + FF_count++; + break; + } } + + switch (connection_state) + { + case PRE_CONNECT_ONE: + if (in == PKMN_MASTER) + { + connection_state = PRE_CONNECT_TWO; + } send = PKMN_MASTER; - break; + break; case PRE_CONNECT_TWO: - if (in == PKMN_MASTER){ - connection_state = NOT_CONNECTED; - linkGPIO->setMode(LinkGPIO::Pin::SC, LinkGPIO::Direction::OUTPUT); - shift = shift + 1; - } + if (in == PKMN_MASTER) + { + connection_state = NOT_CONNECTED; + linkGPIO->setMode(LinkGPIO::Pin::SC, LinkGPIO::Direction::OUTPUT); + shift = shift + 1; + } send = PKMN_MASTER; - break; + break; case NOT_CONNECTED: if (in == PKMN_SLAVE) send = PKMN_MASTER; - else if (in == PKMN_BLANK){ + else if (in == PKMN_BLANK) + { send = PKMN_BLANK; } else if (in == PKMN_CONNECTED_I) @@ -292,31 +340,39 @@ byte handleIncomingByte(byte in) return send; } -bool transferBit(byte *party_data) -{ - bool flag = false; - in_data |= (linkGPIO->readPin(LinkGPIO::Pin::SI)) << (7 - shift); /*digitalRead(MISO_)*/ +int transferBit(byte *party_data) +{ + int timeout = 0; + int flag = BYTE_INCOMPLETE; + in_data |= (linkGPIO->readPin(LinkGPIO::Pin::SI)) << (7 - shift); /*digitalRead(MISO_)*/ if (++shift > 7) { shift = 0; - out_data = handleIncomingByte(in_data); //in_data + out_data = handleIncomingByte(in_data); // in_data print( - std::to_string(trade_centre_state_gen_II) + " " + - std::to_string(connection_state) + " " + - std::to_string(in_data) + " " + - std::to_string(out_data) + "\n"); - if (trade_centre_state_gen_II == SENDING_DATA){ + std::to_string(trade_centre_state_gen_II) + " " + + std::to_string(connection_state) + " " + + std::to_string(in_data) + " " + + std::to_string(out_data) + "\n"); + if (trade_centre_state_gen_II == SENDING_DATA) + { party_data[0] = in_data; - flag = true; + flag = BYTE_COMPLETE; } - in_data = 0; - + in_data = 0; } - while (!((connection_state >= 2) ? SC_state : linkGPIO->readPin(LinkGPIO::Pin::SC))){ + while (!((connection_state >= 2) ? SC_state : linkGPIO->readPin(LinkGPIO::Pin::SC))) + { updateFrames(); + timeout++; + if (timeout > TIMEOUT_LENGTH) + { + timeout = 0; + return TIMEOUT; + } } // no activity when clock is low //!digitalRead(SCLK_) - //digitalWrite(MOSI_, out_data & 0x80 ? HIGH : LOW); + // digitalWrite(MOSI_, out_data & 0x80 ? HIGH : LOW); linkGPIO->writePin(LinkGPIO::Pin::SO, (out_data >> 7)); out_data <<= 1; @@ -324,9 +380,11 @@ bool transferBit(byte *party_data) return flag; } -byte *loop(byte *party_data) +int loop(byte *party_data) { + byte small_array[12]; int counter = 0; + int transfer_state = BYTE_INCOMPLETE; while (true) { last_bit = frame; @@ -334,15 +392,31 @@ byte *loop(byte *party_data) { updateFrames(); } - //updateFrames(); - if (transferBit(&party_data[counter])){ + // updateFrames(); + + transfer_state = transferBit(&party_data[counter]); + + if (transfer_state == BYTE_COMPLETE) + { counter++; } + else if ( + transfer_state == TIMEOUT || FF_count > 25 || zero_count > 25) + { + return ERROR_TIMEOUT; + } + if (FF_count > 25) + { + return ERROR_DISCONNECT; + } + if (zero_count > 25) + { + return ERROR_COM_ENDED; + } - if (trade_centre_state_gen_II == SENDING_PATCH_DATA){ - return &party_data[0]; + if (trade_centre_state_gen_II == SENDING_PATCH_DATA) + { + return 0; } } } - - diff --git a/source/main.cpp b/source/main.cpp index e5b7798..08887a9 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -12,6 +12,8 @@ #include "random.h" #include "text_engine.h" #include "background_engine.h" +#include "pokemon_party.h" +#include "script_array.h" /*TODO: -------- @@ -20,6 +22,8 @@ ACCURACY: LINK CABLE: - Prevent trading through time capsule +- Prevent going to the battle area +- Implement gen 1 lol CONVERSION: - Fix fateful encounter so Mew and Celebi work @@ -55,7 +59,7 @@ OBJ_AFFINE *obj_aff_buffer = (OBJ_AFFINE *)obj_buffer; // byte party_data[441] = {0x8A, 0x91, 0x88, 0x92, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x6, 0x9B, 0x9B, 0x9B, 0x9B, 0x9B, 0x9B, 0xFF, 0x25, 0xDA, 155, 0x0, 0x21, 0x2B, 0x0, 0x0, 0x25, 0xDA, 0x0, 0x0, 0x87, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x72, 0x21, 0x23, 0x1E, 0x0, 0x0, 0x46, 0x0, 0x85, 0x81, 0x5, 0x0, 0x0, 0x0, 0x13, 0x0, 0x13, 0x0, 0x0A, 0x0, 0x9, 0x0, 0x0B, 0x0, 0x0B, 0x0, 0x0A, 0x9B, 0x0, 0x21, 0x2B, 0x0, 0x0, 0x25, 0xDA, 0x0, 0x0, 0x87, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x72, 0x21, 0x23, 0x1E, 0x0, 0x0, 0x46, 0x0, 0x85, 0x81, 0x5, 0x0, 0x0, 0x0, 0x13, 0x0, 0x13, 0x0, 0x0A, 0x0, 0x9, 0x0, 0x0B, 0x0, 0x0B, 0x0, 0x0A, 0x9B, 0x0, 0x21, 0x2B, 0x0, 0x0, 0x25, 0xDA, 0x0, 0x0, 0x87, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x72, 0x21, 0x23, 0x1E, 0x0, 0x0, 0x46, 0x0, 0x85, 0x81, 0x5, 0x0, 0x0, 0x0, 0x13, 0x0, 0x13, 0x0, 0x0A, 0x0, 0x9, 0x0, 0x0B, 0x0, 0x0B, 0x0, 0x0A, 0x9B, 0x0, 0x21, 0x2B, 0x0, 0x0, 0x25, 0xDA, 0x0, 0x0, 0x87, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x72, 0x21, 0x23, 0x1E, 0x0, 0x0, 0x46, 0x0, 0x85, 0x81, 0x5, 0x0, 0x0, 0x0, 0x13, 0x0, 0x13, 0x0, 0x0A, 0x0, 0x9, 0x0, 0x0B, 0x0, 0x0B, 0x0, 0x0A, 0x9B, 0x0, 0x21, 0x2B, 0x0, 0x0, 0x25, 0xDA, 0x0, 0x0, 0x87, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x72, 0x21, 0x23, 0x1E, 0x0, 0x0, 0x46, 0x0, 0x85, 0x81, 0x5, 0x0, 0x0, 0x0, 0x13, 0x0, 0x13, 0x0, 0x0A, 0x0, 0x9, 0x0, 0x0B, 0x0, 0x0B, 0x0, 0x0A, 0x9B, 0x0, 0x21, 0x2B, 0x0, 0x0, 0x25, 0xDA, 0x0, 0x0, 0x87, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x72, 0x21, 0x23, 0x1E, 0x0, 0x0, 0x46, 0x0, 0x85, 0x81, 0x5, 0x0, 0x0, 0x0, 0x13, 0x0, 0x13, 0x0, 0x0A, 0x0, 0x9, 0x0, 0x0B, 0x0, 0x0B, 0x0, 0x0A, 0x8A, 0x91, 0x88, 0x92, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x91, 0x88, 0x92, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x91, 0x88, 0x92, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x91, 0x88, 0x92, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x91, 0x88, 0x92, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x91, 0x88, 0x92, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x82, 0x98, 0x8D, 0x83, 0x80, 0x90, 0x94, 0x88, 0x8B, 0x50, 0x50, 0x82, 0x98, 0x8D, 0x83, 0x80, 0x90, 0x94, 0x88, 0x8B, 0x50, 0x50, 0x82, 0x98, 0x8D, 0x83, 0x80, 0x90, 0x94, 0x88, 0x8B, 0x50, 0x50, 0x82, 0x98, 0x8D, 0x83, 0x80, 0x90, 0x94, 0x88, 0x8B, 0x50, 0x50, 0x82, 0x98, 0x8D, 0x83, 0x80, 0x90, 0x94, 0x88, 0x8B, 0x50, 0x50, 0x82, 0x98, 0x8D, 0x83, 0x80, 0x90, 0x94, 0x88, 0x8B, 0x50, 0x50}; -byte party_data[444] = { +/*byte party_data[444] = { 0x8A, 0x91, 0x88, 0x92, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x06, 0x9B, 0x13, 0xA1, 0xA1, 0xA1, 0xA1, 0xFF, 0x25, 0xDA, 0x8B, 0x00, 0x37, 0x35, 0x21, 0x2B, 0x25, 0xDA, 0x00, 0x00, 0xA7, 0x00, 0x46, 0x00, 0x5C, 0x00, 0x44, 0x00, 0x28, 0x00, 0x46, 0xFA, 0xAA, 0x1F, 0x1E, 0x00, 0x00, 0x45, 0x00, 0x85, 0x81, 0x05, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x13, 0x00, 0x0A, 0x00, 0x09, 0x00, 0x0B, 0x00, 0x0B, 0x00, 0x0A, @@ -80,11 +84,12 @@ byte party_data[444] = { 0xE3, 0xE6, 0xE7, 0xF3, 0xF2, 0xF4, 0x7F, 0x50, 0x50, 0x50, 0x50, 0x00, 0x00, 0x00}; - +*/ Poke_Random poke_rand(0x12162001); +Pokemon_Party party = Pokemon_Party(); text_engine main_text = text_engine(); -Pokemon party[6] = {}; +//Pokemon party[6] = {}; vu8 pkmn[480] = { 0x5C, 0xF2, 0x9B, 0x70, 0x9B, 0x2A, 0x81, 0xE4, 0xBB, 0xC6, 0xBC, 0xBF, 0xCC, 0xCE, 0xFF, 0x00, @@ -143,18 +148,17 @@ void load_sprite(void) oam_copy(oam_mem, obj_buffer, 1); // Update first OAM object } -void load_pokemon(byte *party_array, int gen) +/*void load_pokemon(byte *party_array, int gen) { int party_size = party_array[11]; for (int i = 0; i < party_size; i++) { - party[i].load_data(2, i, &party_array[0]); + party[i].convert_from_gen(2, i, &party_array[0]); poke_rand.next_frame(); party[i].convert_to_gen_three(poke_rand.get_rand()); } } - -static bool DEBUG_MODE = false; +*/ int main(void) { @@ -171,111 +175,102 @@ int main(void) initalize_memory_locations(); back_main(); + //add_script_party_var(party); // load_sprite(); - if (!DEBUG_MODE) + // MAIN LOOP + while (1) { - // MAIN LOOP - while (1) - { - key_poll(); - poke_rand.next_frame(); - back_frame(); - int out_code = main_text.next_frame(); + key_poll(); + poke_rand.next_frame(); + back_frame(); + main_text.next_frame(); - switch (out_code) - { - case 1: - setup(); - loop(&party_data[0]); - break; - - default: - break; - } - } - } - else - { - bool print = false; - char str[128] = {'\0'}; - int arr = 0; - int frame = 0; - while (1) - { - u16 keys = ~REG_KEYS & KEY_ANY; - poke_rand.next_frame(); - vid_vsync(); - key_poll(); - if (key_released(KEY_UP)) - { - arr++; - if (arr == 14) - { - arr = 0; - } - } - if (key_released(KEY_DOWN)) - { - arr--; - if (arr == -1) - { - arr = 13; - } - } - if (key_released(KEY_A)) - { - load_pokemon(&party_data[0], 2); - insert_pokemon(&party[0], 6); - print = true; - } - - if (key_released(KEY_START)) - { - setup(); - loop(&party_data[0]); - } - - tte_erase_screen(); - - tte_set_pos(0, 0); - printValueAt(memory_section_array[arr] + 0xFF4); - - tte_set_pos(0, 10); - sprintf(str, "[%c-%X] R:%X", mem_name, arr, poke_rand.get_rand()); - tte_write(str); - - tte_set_pos(0, 20); - sprintf(str, "%X %X %X %X %X %X %X %X", party_data[0], party_data[1], party_data[2], party_data[3], party_data[4], party_data[5], party_data[6], party_data[7]); - tte_write(str); - if (print) - { - tte_set_pos(0, 30); - tte_write("Pokemon Injected!"); - tte_set_pos(0, 40); - for (int i = 0; i < 80; i++) - { - tte_write(intToHex(party[0].get_gen_3_data(i)).c_str()); - tte_write(" "); - } - tte_set_pos(0, 120); - for (int i = 0; i < 49; i++) - { - tte_write(intToHex(party[0].get_unencrypted_data(i)).c_str()); - tte_write(" "); - } - } - - tte_set_pos(0, 30); - - frame++; - VBlankIntrWait(); - } } } +/* +{ + bool print = false; + char str[128] = {'\0'}; + int arr = 0; + int frame = 0; + while (1) + { + u16 keys = ~REG_KEYS & KEY_ANY; + poke_rand.next_frame(); + + vid_vsync(); + key_poll(); + if (key_released(KEY_UP)) + { + arr++; + if (arr == 14) + { + arr = 0; + } + } + if (key_released(KEY_DOWN)) + { + arr--; + if (arr == -1) + { + arr = 13; + } + } + if (key_released(KEY_A)) + { + load_pokemon(&party_data[0], 2); + insert_pokemon(&party[0], 6); + print = true; + } + + if (key_released(KEY_START)) + { + setup(); + loop(&party_data[0]); + } + + tte_erase_screen(); + + tte_set_pos(0, 0); + printValueAt(memory_section_array[arr] + 0xFF4); + + tte_set_pos(0, 10); + sprintf(str, "[%c-%X] R:%X", mem_name, arr, poke_rand.get_rand()); + tte_write(str); + + tte_set_pos(0, 20); + sprintf(str, "%X %X %X %X %X %X %X %X", party_data[0], party_data[1], party_data[2], party_data[3], party_data[4], party_data[5], party_data[6], party_data[7]); + tte_write(str); + if (print) + { + tte_set_pos(0, 30); + tte_write("Pokemon Injected!"); + tte_set_pos(0, 40); + for (int i = 0; i < 80; i++) + { + tte_write(intToHex(party[0].get_gen_3_data(i)).c_str()); + tte_write(" "); + } + tte_set_pos(0, 120); + for (int i = 0; i < 49; i++) + { + tte_write(intToHex(party[0].get_unencrypted_data(i)).c_str()); + tte_write(" "); + } + } + + tte_set_pos(0, 30); + + frame++; + VBlankIntrWait(); + } +} +} +*/ /*Credits: https://github.com/laqieer/libsavgba https://github.com/rodri042/gba-link-connection diff --git a/source/pokemon_party.cpp b/source/pokemon_party.cpp new file mode 100644 index 0000000..ae0df35 --- /dev/null +++ b/source/pokemon_party.cpp @@ -0,0 +1,9 @@ +#include "gameboy_colour.h" +#include "pokemon_party.h" + +Pokemon_Party::Pokemon_Party(){}; +int Pokemon_Party::start_link() +{ + setup(); + loop(&party_data[0]); +} diff --git a/source/script_array.cpp b/source/script_array.cpp index ab09d0f..5326df3 100644 --- a/source/script_array.cpp +++ b/source/script_array.cpp @@ -1,16 +1,28 @@ #include "script_array.h" #include "script_obj.h" +#include "pokemon_party.h" #include - -script_obj script[6] = +script_obj script[11] = { - script_obj("", 2, 1, 1), // 0 + script_obj("", 2, CHECK_GAME, 1), // 0 script_obj("Game not detected. Please turn off your system and upload the program again.", 2), // 1 script_obj("Welcome to Pokemon Mirror!", 3), // 2 - script_obj("Please connect your GBA to a GB in the trading room, and press A", 4, 2, 5), // 3 - script_obj("Connection successful! Transfering in Pokemon now", 6), // 4 - script_obj("Connection not found, please try again.", 3), // 5 + script_obj("Please connect your GBA to a GB in the trading room, and press A", 4, START_LINK), // 3 + script_obj("", 6, ERROR_COM_ENDED, 5), // 4 + script_obj("Error: Communication ended.", 3), // 5 + script_obj("", 8, ERROR_DISCONNECT, 7), // 6 + script_obj("Error: Cable disconnected.", 3), // 7 + script_obj("", 10, ERROR_TIMEOUT, 9), // 8 + script_obj("Error: Timed out.", 3), // 9 + script_obj("Connection successful! Transfering in Pokemon now", 5), // 10 }; +void add_script_party_var(Pokemon_Party *var){ + for (int i = 0; i < 11; i++){ + script[i].link_party_var(var); + } +} + + diff --git a/source/script_obj.cpp b/source/script_obj.cpp index 8ee250d..abfc176 100644 --- a/source/script_obj.cpp +++ b/source/script_obj.cpp @@ -3,6 +3,7 @@ #include "script_obj.h" #include "gba_flash.h" #include "pokemon.h" +#include "pokemon_party.h" script_obj::script_obj() { @@ -10,7 +11,6 @@ script_obj::script_obj() next_index = 0; conditional_index = 0; next_false_index = 0; - out_code = 0; } script_obj::script_obj(std::string nText, int nNext_index) @@ -19,15 +19,26 @@ script_obj::script_obj(std::string nText, int nNext_index) next_index = nNext_index; conditional_index = 0; next_false_index = 0; - out_code = 0; } + +script_obj::script_obj(std::string nText, int nNext_index, int nCond_index) +{ + text = nText; + next_index = nNext_index; + conditional_index = nCond_index; + next_false_index = nNext_index; +} + script_obj::script_obj(std::string nText, int nNext_index, int nCond_index, int nFalse_index) { text = nText; next_index = nNext_index; conditional_index = nCond_index; next_false_index = nFalse_index; - out_code = 0; +} + +void script_obj::link_party_var(Pokemon_Party *var){ + party_data = var; } std::string script_obj::get_text() @@ -50,12 +61,6 @@ int script_obj::get_cond_id() return conditional_index; } -int script_obj::get_out_code(){ - int temp = out_code; - out_code = 0; - return temp; -} - int script_obj::get_next_obj_id() { if (conditional_index == 0) @@ -77,7 +82,7 @@ bool script_obj::run_conditional(int index) // Here is most of the logic that drives what lines show up where. It's probably not the best way to code it, but it works switch (index) { - case 1: + case CHECK_GAME: { u32 game_code = (*(vu32 *)(0x80000AC)) & 0xFFFFFF; return (game_code == 0x565841 || // Ruby @@ -87,9 +92,14 @@ bool script_obj::run_conditional(int index) game_code == 0x455042 // Emerald ); } - case 2: - out_code = 1; + case START_LINK: + party_data->start_link(); return true; + + //case : + default: + tte_set_pos(0, 0); + tte_write("ERROR! No conditional found."); + return false; } - return false; } diff --git a/source/text_engine.cpp b/source/text_engine.cpp index 9ecb837..c207fba 100644 --- a/source/text_engine.cpp +++ b/source/text_engine.cpp @@ -12,6 +12,7 @@ const int TOP = 122; const int BOTTOM = V_MAX; uint char_count = 0; +Pokemon_Party party_data; text_engine::text_engine() { @@ -25,10 +26,9 @@ text_engine::text_engine() frame_count = 0; } -int text_engine::next_frame() +void text_engine::next_frame() { tte_set_pos(LEFT, TOP); - int out_code = 0; if (char_count < curr_line.get_text().length()) { if (frame_count % 2 == 0 || key_held(KEY_B)) @@ -42,14 +42,10 @@ int text_engine::next_frame() { if (key_hit(KEY_A) || frame_count <= 1) { - int new_index = curr_line.get_next_obj_id(); - out_code = curr_line.get_out_code(); - curr_line = script[new_index]; + curr_line = script[curr_line.get_next_obj_id()]; char_count = 0; } } frame_count++; - - return out_code; }