mirror of
https://github.com/GearsProgress/Poke_Transporter_GB.git
synced 2026-08-20 07:44:41 -05:00
Adding support for Yellow and fixing other bugs
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include "text_engine.h"
|
||||
#include "global_frame_controller.h"
|
||||
#include "gb_rom_values/eng_gb_rom_values.h"
|
||||
#include "background_engine.h"
|
||||
#include "sprite_data.h"
|
||||
|
||||
#define TIMEOUT 2
|
||||
#define TIMEOUT_ONE_LENGTH 1000000 // Maybe keep a 10:1 ratio between ONE and TWO?
|
||||
@@ -108,17 +110,21 @@ void setup()
|
||||
tte_set_pos(0, 0);
|
||||
tte_write("FEED ME POKEMON, I HUNGER!\n");
|
||||
}
|
||||
set_textbox_large();
|
||||
tte_erase_screen();
|
||||
tte_set_pos(40, 24);
|
||||
tte_write("\n\n\n Connecting to\n GameBoy");
|
||||
}
|
||||
|
||||
byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, Simplified_Pokemon *curr_simple_array)
|
||||
byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, Simplified_Pokemon *curr_simple_array, bool cancel_connection)
|
||||
{
|
||||
// TODO: Change to a switch statement
|
||||
if (state == hs)
|
||||
{
|
||||
mosi_delay = 4;
|
||||
if (curr_gb_rom->generation == 2)
|
||||
{
|
||||
state = ack;
|
||||
// mosi_delay = 1;
|
||||
return 0x00;
|
||||
}
|
||||
if (in == 0x00)
|
||||
@@ -159,8 +165,10 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_
|
||||
if (in == 0x60 || in == 0x61)
|
||||
{
|
||||
tte_erase_screen();
|
||||
tte_write("Connected to Game Boy.");
|
||||
tte_set_pos(40, 24);
|
||||
tte_write("\n\n\nLink was successful!\n\n Waiting for trade");
|
||||
state = pretrade;
|
||||
data_counter = 0;
|
||||
return in;
|
||||
}
|
||||
else if (in == 0x02)
|
||||
@@ -176,23 +184,22 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_
|
||||
|
||||
else if (state == pretrade)
|
||||
{
|
||||
if (in == 0xD0)
|
||||
if (data_counter == 16)
|
||||
{
|
||||
data_counter = 0;
|
||||
state = trade;
|
||||
return 0xD4;
|
||||
}
|
||||
else if (in == 0xD1)
|
||||
{
|
||||
state = trade;
|
||||
return 0xD1;
|
||||
}
|
||||
return in;
|
||||
data_counter++;
|
||||
return 0xD4;
|
||||
}
|
||||
|
||||
else if (state == trade)
|
||||
{
|
||||
if (in == 0xfd)
|
||||
{
|
||||
tte_erase_screen();
|
||||
tte_set_pos(40, 24);
|
||||
tte_write("\n\n\nTransferring data...\n please wait!");
|
||||
mosi_delay = 1;
|
||||
state = party_preamble;
|
||||
}
|
||||
@@ -219,6 +226,10 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_
|
||||
}
|
||||
else if ((curr_gb_rom->method == METHOD_MEW) && (in == 0xFE))
|
||||
{
|
||||
tte_erase_screen();
|
||||
tte_set_pos(40, 24);
|
||||
tte_write("\n\nPlease press A or B\n twice on the other\n GameBoy system");
|
||||
mosi_delay = 3;
|
||||
state = wait_to_resend;
|
||||
}
|
||||
else
|
||||
@@ -253,6 +264,9 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_
|
||||
{
|
||||
if (in != 0xFE)
|
||||
{
|
||||
tte_erase_screen();
|
||||
tte_set_pos(40, 24);
|
||||
tte_write("\n\n\nTransferring data...\n please wait!");
|
||||
state = resend_payload;
|
||||
data_counter = 0x1B4;
|
||||
}
|
||||
@@ -273,7 +287,6 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_
|
||||
else if (state == reboot)
|
||||
{
|
||||
data_counter = 0;
|
||||
mosi_delay = 16;
|
||||
state = remove_array_preamble;
|
||||
return 0xFD;
|
||||
}
|
||||
@@ -283,7 +296,7 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_
|
||||
if (in != 0xFD)
|
||||
{
|
||||
state = send_remove_array;
|
||||
return exchange_remove_array(in, curr_simple_array);
|
||||
return exchange_remove_array(in, curr_simple_array, cancel_connection);
|
||||
}
|
||||
return in;
|
||||
}
|
||||
@@ -295,13 +308,13 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_
|
||||
state = end2;
|
||||
}
|
||||
data_counter++;
|
||||
return exchange_remove_array(in, curr_simple_array);
|
||||
return exchange_remove_array(in, curr_simple_array, cancel_connection);
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, Simplified_Pokemon *curr_simple_array)
|
||||
int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, Simplified_Pokemon *curr_simple_array, bool cancel_connection)
|
||||
{
|
||||
int counter = 0;
|
||||
while (true)
|
||||
@@ -311,6 +324,7 @@ int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, Simpli
|
||||
|
||||
if (DEBUG_MODE)
|
||||
{
|
||||
tte_set_margins(0, 0, H_MAX, V_MAX);
|
||||
print(
|
||||
std::to_string(counter) + ": [" +
|
||||
std::to_string(data_counter) + "][" +
|
||||
@@ -318,15 +332,15 @@ int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, Simpli
|
||||
std::to_string(in_data) + "][" +
|
||||
std::to_string(out_data) + "]\n");
|
||||
}
|
||||
out_data = handleIncomingByte(in_data, box_data_storage, curr_payload, curr_gb_rom, curr_simple_array);
|
||||
out_data = handleIncomingByte(in_data, box_data_storage, curr_payload, curr_gb_rom, curr_simple_array, cancel_connection);
|
||||
|
||||
if (FF_count > 25)
|
||||
if (FF_count > (5 * 60))
|
||||
{
|
||||
// return COND_ERROR_DISCONNECT;
|
||||
return COND_ERROR_DISCONNECT;
|
||||
}
|
||||
if (zero_count > 25)
|
||||
if (zero_count > (5 * 60))
|
||||
{
|
||||
// return COND_ERROR_COM_ENDED;
|
||||
return COND_ERROR_COM_ENDED;
|
||||
}
|
||||
if (connection_state == COLOSSEUM)
|
||||
{
|
||||
@@ -349,16 +363,17 @@ int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, Simpli
|
||||
return COND_ERROR_DISCONNECT;
|
||||
}
|
||||
|
||||
if (state != box_data)
|
||||
{
|
||||
FF_count = (in_data == 0xFF ? FF_count + mosi_delay : 0);
|
||||
zero_count = (in_data == 0x00 ? zero_count + mosi_delay : 0);
|
||||
}
|
||||
|
||||
counter++;
|
||||
for (int i = 0; i < mosi_delay; i++)
|
||||
{
|
||||
global_next_frame();
|
||||
}
|
||||
|
||||
if (counter > (60 * 10))
|
||||
{
|
||||
// return COND_ERROR_TIMEOUT_ONE;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -376,11 +391,11 @@ byte exchange_boxes(byte curr_in, byte *box_data_storage)
|
||||
return curr_in;
|
||||
};
|
||||
|
||||
byte exchange_remove_array(byte curr_in, Simplified_Pokemon *curr_simple_array)
|
||||
byte exchange_remove_array(byte curr_in, Simplified_Pokemon *curr_simple_array, bool cancel_connection)
|
||||
{
|
||||
for (int i = 29; i >= 0; i--)
|
||||
{
|
||||
if (curr_simple_array[i].is_valid && !curr_simple_array[i].is_transferred)
|
||||
if (curr_simple_array[i].is_valid && !curr_simple_array[i].is_transferred && !cancel_connection)
|
||||
{
|
||||
curr_simple_array[i].is_transferred = true;
|
||||
return i;
|
||||
|
||||
Reference in New Issue
Block a user