mirror of
https://github.com/GearsProgress/Poke_Transporter_GB.git
synced 2026-09-09 01:25:35 -05:00
Speeding things up!
This commit is contained in:
@@ -68,9 +68,9 @@ void print(const char *format, ...)
|
||||
}
|
||||
}
|
||||
|
||||
void setup(const u16 *debug_charset)
|
||||
void setup(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_rom, PokeBox *box, const u16 *debug_charset, bool cancel_connection)
|
||||
{
|
||||
REG_TM3D = -0x4000;
|
||||
REG_TM3D = -0x4000 / 60;
|
||||
REG_TM3CNT = TM_FREQ_1024 | TM_ENABLE;
|
||||
irq_enable(II_TIMER3);
|
||||
|
||||
@@ -78,6 +78,12 @@ void setup(const u16 *debug_charset)
|
||||
linkSPI->setWaitModeActive(false);
|
||||
|
||||
currLinkState = new LinkState;
|
||||
currLinkState->box_data_storage = box_data_storage;
|
||||
currLinkState->curr_payload = curr_payload;
|
||||
currLinkState->curr_gb_rom = curr_rom;
|
||||
currLinkState->box = box;
|
||||
currLinkState->debug_charset = debug_charset;
|
||||
currLinkState->cancel_connection = cancel_connection;
|
||||
|
||||
{
|
||||
u8 general_text_table_buffer[2048];
|
||||
@@ -87,6 +93,8 @@ void setup(const u16 *debug_charset)
|
||||
ptgb_write_textbox(general_text.get_text_entry(GENERAL_connecting), true, false,
|
||||
GENERAL_INDEX, GENERAL_connecting, false);
|
||||
}
|
||||
|
||||
create_textbox(0, 0, 125, 128, false);
|
||||
}
|
||||
|
||||
byte handleIncomingByte()
|
||||
@@ -100,7 +108,7 @@ byte handleIncomingByte()
|
||||
currLinkState->conState = ACK;
|
||||
return 0x00;
|
||||
}
|
||||
if (currLinkState->in == 0x00)
|
||||
if (currLinkState->in_data == 0x00)
|
||||
{
|
||||
currLinkState->conState = ACK;
|
||||
return 0x01;
|
||||
@@ -110,7 +118,7 @@ byte handleIncomingByte()
|
||||
case ACK:
|
||||
if (currLinkState->curr_gb_rom->generation == 2)
|
||||
{
|
||||
if (currLinkState->in == 0x61)
|
||||
if (currLinkState->in_data == 0x61)
|
||||
{
|
||||
currLinkState->conState = MENU;
|
||||
return 0x61;
|
||||
@@ -119,12 +127,12 @@ byte handleIncomingByte()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currLinkState->in == 0x00)
|
||||
if (currLinkState->in_data == 0x00)
|
||||
{
|
||||
currLinkState->conState = MENU;
|
||||
return 0x00;
|
||||
}
|
||||
else if (currLinkState->in == 0x02)
|
||||
else if (currLinkState->in_data == 0x02)
|
||||
{
|
||||
currLinkState->conState = HS;
|
||||
return 0x02;
|
||||
@@ -133,7 +141,7 @@ byte handleIncomingByte()
|
||||
break;
|
||||
|
||||
case MENU:
|
||||
if (currLinkState->in == 0x60 || currLinkState->in == 0x61)
|
||||
if (currLinkState->in_data == 0x60 || currLinkState->in_data == 0x61)
|
||||
{
|
||||
{
|
||||
u8 general_text_table_buffer[2048];
|
||||
@@ -146,27 +154,27 @@ byte handleIncomingByte()
|
||||
|
||||
link_animation_state(STATE_NO_ANIM);
|
||||
currLinkState->conState = PRETRADE;
|
||||
currLinkState->data_counter = 0;
|
||||
return currLinkState->in;
|
||||
currLinkState->section_data_counter = 0;
|
||||
return currLinkState->in_data;
|
||||
}
|
||||
else if (currLinkState->in == 0x02)
|
||||
else if (currLinkState->in_data == 0x02)
|
||||
{
|
||||
currLinkState->conState = HS;
|
||||
return 0x02;
|
||||
}
|
||||
else
|
||||
{
|
||||
return currLinkState->in;
|
||||
return currLinkState->in_data;
|
||||
}
|
||||
break;
|
||||
|
||||
case PRETRADE:
|
||||
if (currLinkState->data_counter == 16)
|
||||
if (currLinkState->section_data_counter == 16)
|
||||
{
|
||||
currLinkState->data_counter = 0;
|
||||
currLinkState->section_data_counter = 0;
|
||||
currLinkState->conState = TRADE;
|
||||
}
|
||||
currLinkState->data_counter++;
|
||||
currLinkState->section_data_counter++;
|
||||
if (currLinkState->curr_gb_rom->generation == 2)
|
||||
{
|
||||
return 0x61;
|
||||
@@ -181,7 +189,7 @@ byte handleIncomingByte()
|
||||
}
|
||||
break;
|
||||
case TRADE:
|
||||
if (currLinkState->in == 0xfd)
|
||||
if (currLinkState->in_data == 0xfd)
|
||||
{
|
||||
{
|
||||
u8 general_text_table_buffer[2048];
|
||||
@@ -193,23 +201,24 @@ byte handleIncomingByte()
|
||||
}
|
||||
|
||||
link_animation_state(STATE_TRANSFER);
|
||||
currLinkState->mosi_delay = 1;
|
||||
//currLinkState->mosi_delay = 1;
|
||||
REG_TM3D = -0x0040;
|
||||
currLinkState->conState = PARTY_PREAMBLE;
|
||||
}
|
||||
return currLinkState->in;
|
||||
return currLinkState->in_data;
|
||||
break;
|
||||
case PARTY_PREAMBLE:
|
||||
if (currLinkState->in != 0xfd)
|
||||
if (currLinkState->in_data != 0xfd)
|
||||
{
|
||||
currLinkState->conState = TRADE_DATA;
|
||||
return exchange_parties(currLinkState->in, currLinkState->curr_payload);
|
||||
return exchange_parties(currLinkState->in_data, currLinkState->curr_payload);
|
||||
}
|
||||
return currLinkState->in;
|
||||
return currLinkState->in_data;
|
||||
break;
|
||||
case TRADE_DATA:
|
||||
if (currLinkState->data_counter >= currLinkState->curr_gb_rom->payload_size)
|
||||
if (currLinkState->section_data_counter >= currLinkState->curr_gb_rom->payload_size)
|
||||
{
|
||||
if (currLinkState->in == 0xFD)
|
||||
if (currLinkState->in_data == 0xFD)
|
||||
{
|
||||
currLinkState->conState = BOX_PREAMBLE;
|
||||
currLinkState->init_packet = true;
|
||||
@@ -219,55 +228,55 @@ byte handleIncomingByte()
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
return exchange_parties(currLinkState->in, currLinkState->curr_payload);
|
||||
return exchange_parties(currLinkState->in_data, currLinkState->curr_payload);
|
||||
break;
|
||||
case BOX_PREAMBLE:
|
||||
if (currLinkState->in != 0xFD)
|
||||
if (currLinkState->in_data != 0xFD)
|
||||
{
|
||||
currLinkState->conState = BOX_DATA;
|
||||
return exchange_boxes(currLinkState->in, currLinkState->box_data_storage, currLinkState->curr_gb_rom, currLinkState->debug_charset);
|
||||
return exchange_boxes(currLinkState->in_data, currLinkState->box_data_storage, currLinkState->curr_gb_rom, currLinkState->debug_charset);
|
||||
}
|
||||
return currLinkState->in;
|
||||
return currLinkState->in_data;
|
||||
break;
|
||||
case BOX_DATA:
|
||||
return exchange_boxes(currLinkState->in, currLinkState->box_data_storage, currLinkState->curr_gb_rom, currLinkState->debug_charset);
|
||||
return exchange_boxes(currLinkState->in_data, currLinkState->box_data_storage, currLinkState->curr_gb_rom, currLinkState->debug_charset);
|
||||
break;
|
||||
case REBOOT:
|
||||
currLinkState->data_counter = 0;
|
||||
currLinkState->section_data_counter = 0;
|
||||
currLinkState->conState = REMOVE_ARRAY_PREAMBLE;
|
||||
return 0xFD;
|
||||
break;
|
||||
|
||||
case REMOVE_ARRAY_PREAMBLE:
|
||||
if (currLinkState->in != 0xFD)
|
||||
if (currLinkState->in_data != 0xFD)
|
||||
{
|
||||
currLinkState->conState = SEND_REMOVE_ARRAY;
|
||||
return exchange_remove_array(currLinkState->in, currLinkState->box, currLinkState->cancel_connection);
|
||||
return exchange_remove_array(currLinkState->in_data, currLinkState->box, currLinkState->cancel_connection);
|
||||
}
|
||||
return currLinkState->in;
|
||||
return currLinkState->in_data;
|
||||
break;
|
||||
|
||||
case SEND_REMOVE_ARRAY:
|
||||
if (currLinkState->data_counter >= 29) // This assumes the preamble does not count towards the number of bytes sent over the cable
|
||||
if (currLinkState->section_data_counter >= 29) // This assumes the preamble does not count towards the number of bytes sent over the cable
|
||||
{
|
||||
currLinkState->conState = END2;
|
||||
}
|
||||
currLinkState->data_counter++;
|
||||
return exchange_remove_array(currLinkState->in, currLinkState->box, currLinkState->cancel_connection);
|
||||
currLinkState->section_data_counter++;
|
||||
return exchange_remove_array(currLinkState->in_data, currLinkState->box, currLinkState->cancel_connection);
|
||||
break;
|
||||
|
||||
default:
|
||||
return currLinkState->in;
|
||||
return currLinkState->in_data;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0; // This should never hit but the compiler likes this being here
|
||||
}
|
||||
|
||||
/*
|
||||
int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, PokeBox *box, const u16 *debug_charset, bool cancel_connection)
|
||||
{
|
||||
#define LINE_WIDTH 21
|
||||
#define NUM_LINES 8
|
||||
#define NUM_LINES 2
|
||||
int counter = 0;
|
||||
char stuff[NUM_LINES][LINE_WIDTH];
|
||||
|
||||
@@ -381,16 +390,56 @@ int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, PokeBo
|
||||
}
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
#define LINE_WIDTH 21
|
||||
#define NUM_LINES 8
|
||||
char stuff[NUM_LINES][LINE_WIDTH];
|
||||
char line[LINE_WIDTH] = "OUT";
|
||||
ConnectionState prevConState;
|
||||
|
||||
void handshake()
|
||||
{
|
||||
prevConState = currLinkState->conState; // The con state can change in handleIncomingByte - we want to display what it was before running that function
|
||||
currLinkState->in_data = linkSPI->transfer(currLinkState->out_data);
|
||||
currLinkState->out_data = handleIncomingByte();
|
||||
|
||||
if (g_debug_options.print_link_data && !key_held(KEY_DOWN))
|
||||
{
|
||||
n2hexstr(&line[0], currLinkState->global_data_counter & 0xFFFFFF, 6);
|
||||
line[6] = ':';
|
||||
n2hexstr(&line[7], currLinkState->section_data_counter & 0xFFFF, 4);
|
||||
line[11] = '|';
|
||||
n2hexstr(&line[12], prevConState & 0xFF, 2);
|
||||
line[14] = '|';
|
||||
n2hexstr(&line[15], currLinkState->in_data & 0xFF, 2);
|
||||
line[17] = '|';
|
||||
n2hexstr(&line[18], currLinkState->out_data & 0xFF, 2);
|
||||
line[20] = '\0';
|
||||
scroll_text(true, tte_get_context(), false, 8, 8, 127, 135);
|
||||
ptgb_write_debug(currLinkState->debug_charset, line, true);
|
||||
}
|
||||
else if (g_debug_options.write_cable_data_to_save)
|
||||
{
|
||||
global_memory_buffer[link_cable_array_index] = currLinkState->in_data;
|
||||
link_cable_array_index++;
|
||||
global_memory_buffer[link_cable_array_index] = currLinkState->out_data;
|
||||
link_cable_array_index++;
|
||||
if (link_cable_array_index >= 0x1000)
|
||||
{
|
||||
copy_ram_to_save(&global_memory_buffer[0], 0x1000 * link_cable_memory_section_index, 0x1000);
|
||||
link_cable_memory_section_index++;
|
||||
link_cable_array_index = link_cable_array_index % 0x1000;
|
||||
}
|
||||
}
|
||||
|
||||
currLinkState->global_data_counter++;
|
||||
}
|
||||
|
||||
byte exchange_parties(byte curr_in, byte *curr_payload)
|
||||
{
|
||||
int ret = curr_payload[currLinkState->data_counter];
|
||||
currLinkState->data_counter += 1;
|
||||
int ret = curr_payload[currLinkState->section_data_counter];
|
||||
currLinkState->section_data_counter += 1;
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user