mirror of
https://github.com/breadbored/Pokemon-Distribution-ROM.git
synced 2026-03-22 02:04:12 -05:00
Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
2
Makefile
2
Makefile
|
|
@ -1,5 +1,5 @@
|
|||
# CC = /opt/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j
|
||||
CC = ~/gbdk-2020/build/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j
|
||||
CC = /Users/jasoncarpenter/gbdk-2020/build/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j
|
||||
|
||||
BINS = comm.gb
|
||||
|
||||
|
|
|
|||
141
comm.c
141
comm.c
|
|
@ -40,18 +40,18 @@ unsigned char nicknames[11] = {
|
|||
pokechar_E,
|
||||
pokechar_W,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
};
|
||||
|
||||
typedef struct TraderPacket {
|
||||
// Name must not exceed 10 characters + 1 STOP_BYTE
|
||||
// Any leftover space must be filled with STOP_BYTE
|
||||
// Any leftover space after STOP_BYTE must be filled with NULL_BYTE
|
||||
unsigned char name[11];
|
||||
struct SelectedPokemon selected_pokemon;
|
||||
struct PartyMember pokemon[6];
|
||||
|
|
@ -143,6 +143,12 @@ void trader_packet_to_bytes(struct TraderPacket *pTraderPacket, uint8_t *out) {
|
|||
for (size_t i = 0; i < PARTY_SIZE; i++) {
|
||||
uint8_t poke[POKE_SIZE];
|
||||
party_member_to_bytes(&pTraderPacket->pokemon[i], poke);
|
||||
|
||||
// Selected Pokemon Data (for listing and ordering without stats)
|
||||
// if (poke[0] != 0x00) {
|
||||
// pTraderPacket->selected_pokemon.number++;
|
||||
// pTraderPacket->selected_pokemon.pokemon[i] = poke[0];
|
||||
// }
|
||||
|
||||
// Full Party Data (all stats and such)
|
||||
for (size_t j = 0; j < POKE_SIZE; j++) {
|
||||
|
|
@ -197,62 +203,67 @@ uint8_t handle_byte(uint8_t in, size_t *counter) {
|
|||
switch (connection_state)
|
||||
{
|
||||
case NOT_CONNECTED:
|
||||
switch (in)
|
||||
{
|
||||
case PKMN_MASTER:
|
||||
out[0] = PKMN_SLAVE;
|
||||
break;
|
||||
case PKMN_BLANK:
|
||||
out[0] = PKMN_BLANK;
|
||||
break;
|
||||
case PKMN_CONNECTED:
|
||||
connection_state = CONNECTED;
|
||||
out[0] = PKMN_CONNECTED;
|
||||
break;
|
||||
// printf("NC\n");
|
||||
if(in == PKMN_MASTER) {
|
||||
out[0] = PKMN_SLAVE;
|
||||
// printf("SLV\n");
|
||||
}
|
||||
else if(in == PKMN_BLANK) {
|
||||
out[0] = PKMN_BLANK;
|
||||
// printf("BNK\n");
|
||||
}
|
||||
else if(in == PKMN_CONNECTED) {
|
||||
out[0] = PKMN_CONNECTED;
|
||||
connection_state = CONNECTED;
|
||||
// printf("CON\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case CONNECTED:
|
||||
switch (in)
|
||||
{
|
||||
case PKMN_CONNECTED:
|
||||
out[0] = PKMN_CONNECTED;
|
||||
break;
|
||||
case PKMN_TRADE_CENTRE:
|
||||
// No byte known, just move on the next case
|
||||
connection_state = TRADE_CENTRE;
|
||||
break;
|
||||
case PKMN_COLOSSEUM:
|
||||
// No byte known, just move on the next case
|
||||
// This case is not built out and I have no intention to do it
|
||||
connection_state = COLOSSEUM;
|
||||
break;
|
||||
case PKMN_BREAK_LINK:
|
||||
case PKMN_MASTER:
|
||||
connection_state = NOT_CONNECTED;
|
||||
out[0] = PKMN_BREAK_LINK;
|
||||
break;
|
||||
|
||||
default:
|
||||
out[0] = in;
|
||||
break;
|
||||
//printf("Connected...\n");
|
||||
if(in == PKMN_CONNECTED) {
|
||||
out[0] = PKMN_CONNECTED;
|
||||
// printf("CC\n");
|
||||
}
|
||||
else if(in == PKMN_TRADE_CENTRE) {
|
||||
connection_state = TRADE_CENTRE;
|
||||
// printf("TC\n");
|
||||
}
|
||||
else if(in == PKMN_COLOSSEUM) {
|
||||
connection_state = COLOSSEUM;
|
||||
// printf("COL\n");
|
||||
}
|
||||
else if(in == PKMN_BREAK_LINK || in == PKMN_MASTER) {
|
||||
connection_state = NOT_CONNECTED;
|
||||
out[0] = PKMN_BREAK_LINK;
|
||||
// printf(in == PKMN_MASTER ? "PMR\n" : "PBL\n");
|
||||
} else {
|
||||
out[0] = in;
|
||||
// printf("echoing back after connected: %x\n", in);
|
||||
// printf("EC1\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case TRADE_CENTRE:
|
||||
// printf("TCC\n");
|
||||
if(trade_state == INIT && in == 0x00) {
|
||||
trade_state = READY;
|
||||
out[0] = 0x00;
|
||||
// printf("I\n");
|
||||
} else if(trade_state == READY && in == 0xFD) {
|
||||
trade_state = DETECTED;
|
||||
trade_state = FIRST_DETECTED_WAIT;
|
||||
out[0] = 0xFD;
|
||||
} else if(trade_state == DETECTED && in != 0xFD) {
|
||||
// printf("R\n");
|
||||
} else if(trade_state == FIRST_DETECTED_WAIT && in != 0xFD) {
|
||||
// random data of slave is ignored.
|
||||
out[0] = in;
|
||||
trade_state = DATA_TX_RANDOM;
|
||||
// printf("DRD\n");
|
||||
} else if(trade_state == DATA_TX_RANDOM && in == 0xFD) {
|
||||
trade_state = DATA_TX_WAIT;
|
||||
out[0] = 0xFD;
|
||||
(*counter) = 0;
|
||||
// printf("RDS\n");
|
||||
} else if (trade_state == DATA_TX_WAIT && in == 0xFD) {
|
||||
out[0] = 0x00;
|
||||
} else if(trade_state == DATA_TX_WAIT && in != 0xFD) {
|
||||
|
|
@ -262,6 +273,7 @@ uint8_t handle_byte(uint8_t in, size_t *counter) {
|
|||
INPUT_BLOCK[(*counter)] = in;
|
||||
trade_state = DATA_TX;
|
||||
(*counter)++;
|
||||
// printf("SD1\n");
|
||||
} else if(trade_state == DATA_TX) {
|
||||
out[0] = DATA_BLOCK[(*counter)];
|
||||
INPUT_BLOCK[(*counter)] = in;
|
||||
|
|
@ -269,46 +281,63 @@ uint8_t handle_byte(uint8_t in, size_t *counter) {
|
|||
if((*counter) == 418) {
|
||||
trade_state = DATA_TX_PATCH;
|
||||
}
|
||||
// printf("SD2\n");
|
||||
} else if(trade_state == DATA_TX_PATCH && in == 0xFD) {
|
||||
(*counter) = 0;
|
||||
out[0] = 0xFD;
|
||||
// printf("SP\n");
|
||||
} else if(trade_state == DATA_TX_PATCH && in != 0xFD) {
|
||||
out[0] = in;
|
||||
(*counter)++;
|
||||
if((*counter) == 197) {
|
||||
trade_state = TRADE_WAIT;
|
||||
}
|
||||
(*counter) = 0;
|
||||
// printf("SPW\n");
|
||||
} else if(trade_state == TRADE_WAIT && (in & 0x60) == 0x60) {
|
||||
if (in == 0x6f) {
|
||||
trade_state = READY;
|
||||
out[0] = 0x6f;
|
||||
// printf("MR\n");
|
||||
} else {
|
||||
out[0] = 0x60;
|
||||
out[0] = 0x60; // first pokemon
|
||||
trade_pokemon = in - 0x60;
|
||||
// printf("MFP\n");
|
||||
}
|
||||
} else if(trade_state == TRADE_WAIT && in == 0x00) {
|
||||
out[0] = 0;
|
||||
trade_state = TRADE_DONE;
|
||||
// printf("TWD\n");
|
||||
// printf("Sent the Gameboy:\n");
|
||||
// printf("Gameboy Sent:\n");
|
||||
// printf("Trade done\n");
|
||||
} else if(trade_state == TRADE_DONE && (in & 0x60) == 0x60) {
|
||||
out[0] = in;
|
||||
if (in == 0x61) {
|
||||
trade_pokemon = -1;
|
||||
trade_state = TRADE_WAIT;
|
||||
// printf("TDW\n");
|
||||
} else {
|
||||
trade_state = DONE;
|
||||
// printf("TD\n");
|
||||
}
|
||||
} else if(trade_state == DONE && in == 0x00) {
|
||||
out[0] = 0;
|
||||
trade_state = INIT;
|
||||
// printf("DRI\n");
|
||||
} else {
|
||||
out[0] = in;
|
||||
// printf("EC2\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
out[0] = in;
|
||||
// printf("EC3\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// printf(" %x %x\n", in, out[0]);
|
||||
|
||||
return out[0];
|
||||
}
|
||||
|
|
@ -401,6 +430,8 @@ void main(void)
|
|||
puts("Poke Distribution");
|
||||
puts("Copyright 2023");
|
||||
puts("BreadCodes");
|
||||
puts("");
|
||||
puts("Reset: Press Button");
|
||||
|
||||
size_t trade_counter = 0;
|
||||
while(1) {
|
||||
|
|
@ -418,19 +449,13 @@ void main(void)
|
|||
__endasm;
|
||||
}
|
||||
|
||||
// trade_byte_primary();
|
||||
// See https://github.com/gbdk-2020/gbdk-2020/pull/577
|
||||
__asm
|
||||
LD A,#0x02 ; .IO_RECEIVING
|
||||
LD (__io_status),A ; Store status
|
||||
LD A,#0x01
|
||||
LDH (0x02),A ; (.SC) Use external clock
|
||||
LD A,(__io_out)
|
||||
LDH (0x01),A ; (.SB) Send __io_out byte
|
||||
LD A,#0x81
|
||||
LDH (0x02),A ; (.SC) Use external clock
|
||||
__endasm;
|
||||
trade_byte();
|
||||
|
||||
while(_io_status == IO_RECEIVING || _io_status == IO_SENDING);
|
||||
|
||||
if (joypad() > 0) {
|
||||
connection_state = NOT_CONNECTED;
|
||||
trade_state = INIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
42
gen1.h
42
gen1.h
|
|
@ -195,19 +195,19 @@ enum connection_state_t {
|
|||
enum trade_state_t {
|
||||
INIT = 0x00,
|
||||
READY = 0x01,
|
||||
DETECTED = 0x02,
|
||||
FIRST_DETECTED_WAIT = 0x02,
|
||||
DATA_TX = 0x03,
|
||||
DATA_TX_WAIT = 0x04,
|
||||
DATA_TX_WAIT_HOLD = 0x05,
|
||||
DATA_TX_START = 0x06,
|
||||
DATA_TX_RANDOM = 0x07,
|
||||
DATA_TX_PATCH = 0x08,
|
||||
TRADE_WAIT = 0x09,
|
||||
TRADE_DONE = 0x0A,
|
||||
DONE = 0x0B
|
||||
DATA_TX_WAIT_HOLD = 0x0B,
|
||||
DATA_TX_START = 0x05,
|
||||
DATA_TX_RANDOM = 0x06,
|
||||
DATA_TX_PATCH = 0x07,
|
||||
TRADE_WAIT = 0x08,
|
||||
TRADE_DONE = 0x09,
|
||||
DONE = 0x0A
|
||||
};
|
||||
|
||||
enum gen_one_dex_t {
|
||||
enum GenOneDex {
|
||||
NULL_POKEMON = 0xFF,
|
||||
RHYDON = 0x01,
|
||||
KANGASKHAN = 0x02,
|
||||
|
|
@ -362,7 +362,7 @@ enum gen_one_dex_t {
|
|||
VICTREEBEL = 0xBE,
|
||||
};
|
||||
|
||||
enum poke_move_t {
|
||||
enum PokemonMove {
|
||||
ABSORB = 0x47,
|
||||
ACID = 0x33,
|
||||
ACID_ARMOR = 0x97,
|
||||
|
|
@ -530,7 +530,7 @@ enum poke_move_t {
|
|||
WRAP = 0x23,
|
||||
};
|
||||
|
||||
enum status_condition_t {
|
||||
enum StatusCondition {
|
||||
NONE = 0x00,
|
||||
ASLEEP = 0x04,
|
||||
BURNED = 0x10,
|
||||
|
|
@ -539,7 +539,7 @@ enum status_condition_t {
|
|||
POISONED = 0x08,
|
||||
};
|
||||
|
||||
enum poke_type_t {
|
||||
enum PokemonType {
|
||||
NORMAL = 0x00,
|
||||
FIGHTING = 0x01,
|
||||
FLYING = 0x02,
|
||||
|
|
@ -560,25 +560,25 @@ enum poke_type_t {
|
|||
typedef struct SelectedPokemon {
|
||||
// Number of pokemon in the trainer's party
|
||||
uint8_t number;
|
||||
enum gen_one_dex_t pokemon[6];
|
||||
enum GenOneDex pokemon[6];
|
||||
} SelectedPokemon;
|
||||
|
||||
|
||||
// Luckily it follows the save file structure closely enough
|
||||
// https://bulbapedia.bulbagarden.net/wiki/Pok%C3%A9mon_data_structure_(Generation_I)
|
||||
typedef struct PartyMember {
|
||||
enum gen_one_dex_t pokemon;
|
||||
enum GenOneDex pokemon;
|
||||
uint16_t current_hp;
|
||||
uint16_t max_hp;
|
||||
uint8_t level;
|
||||
enum status_condition_t status;
|
||||
enum poke_type_t type1;
|
||||
enum poke_type_t type2; // If only one type, copy the first
|
||||
enum StatusCondition status;
|
||||
enum PokemonType type1;
|
||||
enum PokemonType type2; // If only one type, copy the first
|
||||
uint8_t catch_rate_or_held_item; // R/G/B/Y (catch rate), G/S/C (held item), and Stadium (held item) use this byte differently
|
||||
enum poke_move_t move1;
|
||||
enum poke_move_t move2;
|
||||
enum poke_move_t move3;
|
||||
enum poke_move_t move4;
|
||||
enum PokemonMove move1;
|
||||
enum PokemonMove move2;
|
||||
enum PokemonMove move3;
|
||||
enum PokemonMove move4;
|
||||
uint16_t original_trainer_id; // In decimal, these are the funny numbers
|
||||
|
||||
// - Experience is complicated. You must look up the Pokemon you are trying to trade
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user