mirror of
https://github.com/breadbored/Pokemon-Distribution-ROM.git
synced 2026-03-22 10:14:16 -05:00
Compare commits
No commits in common. "v0.0.1" and "main" have entirely different histories.
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -63,3 +63,5 @@ a.ihx
|
|||
.vscode/settings.json
|
||||
.vscode/c_cpp_properties.json
|
||||
.DS_Store
|
||||
pokedistro.gb
|
||||
pokedistro2.gb
|
||||
|
|
|
|||
3
Makefile
3
Makefile
|
|
@ -1,4 +1,5 @@
|
|||
CC = /opt/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG=1
|
||||
# CC = /opt/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j
|
||||
CC = ~/gbdk-2020/build/gbdk/bin/lcc -Wa-l -Wl-m -Wl-j
|
||||
|
||||
BINS = comm.gb
|
||||
|
||||
|
|
|
|||
181
comm.c
181
comm.c
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
enum connection_state_t connection_state = NOT_CONNECTED;
|
||||
enum trade_state_t trade_state = INIT;
|
||||
uint32_t emu_var = 0x12345678;
|
||||
uint8_t INPUT_BLOCK[418];
|
||||
uint8_t DATA_BLOCK[418];
|
||||
int trade_pokemon = -1;
|
||||
|
|
@ -28,11 +27,11 @@ unsigned char name[11] = {
|
|||
pokechar_e,
|
||||
pokechar_a,
|
||||
pokechar_d,
|
||||
pokechar_B,
|
||||
pokechar_C,
|
||||
pokechar_o,
|
||||
pokechar_r,
|
||||
pokechar_e,
|
||||
pokechar_d,
|
||||
pokechar_e,
|
||||
pokechar_s,
|
||||
pokechar_STOP_BYTE
|
||||
};
|
||||
unsigned char nicknames[11] = {
|
||||
|
|
@ -41,18 +40,18 @@ unsigned char nicknames[11] = {
|
|||
pokechar_E,
|
||||
pokechar_W,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_NULL_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
pokechar_STOP_BYTE,
|
||||
};
|
||||
|
||||
typedef struct TraderPacket {
|
||||
// Name must not exceed 10 characters + 1 STOP_BYTE
|
||||
// Any leftover space after STOP_BYTE must be filled with NULL_BYTE
|
||||
// Any leftover space must be filled with STOP_BYTE
|
||||
unsigned char name[11];
|
||||
struct SelectedPokemon selected_pokemon;
|
||||
struct PartyMember pokemon[6];
|
||||
|
|
@ -76,9 +75,9 @@ void party_member_to_bytes(struct PartyMember *pPartyMember, uint8_t *out) {
|
|||
pPartyMember->move4,
|
||||
(uint8_t) (pPartyMember->original_trainer_id >> 8),
|
||||
(uint8_t) (pPartyMember->original_trainer_id & 0x00FF),
|
||||
(uint8_t) ((pPartyMember->experience & 0x00FF0000) >> 16),
|
||||
(uint8_t) ((pPartyMember->experience & 0x0000FF00) >> 8),
|
||||
(uint8_t) (pPartyMember->experience & 0x000000FF),
|
||||
(uint8_t) (pPartyMember->experience & 0x0000FF00) >> 8,
|
||||
(uint8_t) (pPartyMember->experience & 0x00FF0000) >> 16,
|
||||
(uint8_t) (pPartyMember->HP_ev >> 8),
|
||||
(uint8_t) (pPartyMember->HP_ev & 0x00FF),
|
||||
(uint8_t) (pPartyMember->attack_ev >> 8),
|
||||
|
|
@ -144,12 +143,6 @@ 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++) {
|
||||
|
|
@ -204,65 +197,64 @@ uint8_t handle_byte(uint8_t in, size_t *counter) {
|
|||
switch (connection_state)
|
||||
{
|
||||
case NOT_CONNECTED:
|
||||
// printf("Not connected...\n");
|
||||
if(in == PKMN_MASTER) {
|
||||
out[0] = PKMN_SLAVE;
|
||||
// printf("We are slave\n");
|
||||
}
|
||||
else if(in == PKMN_BLANK) {
|
||||
out[0] = PKMN_BLANK;
|
||||
// printf("Pokemon Blank\n");
|
||||
}
|
||||
else if(in == PKMN_CONNECTED) {
|
||||
out[0] = PKMN_CONNECTED;
|
||||
connection_state = CONNECTED;
|
||||
// printf("We are connected!\n");
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
||||
case CONNECTED:
|
||||
// printf("Connected...\n");
|
||||
if(in == PKMN_CONNECTED) {
|
||||
out[0] = PKMN_CONNECTED;
|
||||
// printf("Confirmed connected.\n");
|
||||
}
|
||||
else if(in == PKMN_TRADE_CENTRE) {
|
||||
connection_state = TRADE_CENTRE;
|
||||
// printf("Trade Center\n");
|
||||
}
|
||||
else if(in == PKMN_COLOSSEUM) {
|
||||
connection_state = COLOSSEUM;
|
||||
// printf("COLOSSEUM\n");
|
||||
}
|
||||
else if(in == PKMN_BREAK_LINK || in == PKMN_MASTER) {
|
||||
connection_state = NOT_CONNECTED;
|
||||
out[0] = PKMN_BREAK_LINK;
|
||||
// printf(in == PKMN_MASTER ? "PKMN_MASTER\n" : "PKMN_BREAK_LINK\n");
|
||||
} else {
|
||||
out[0] = in;
|
||||
// printf("echoing back after connected: %x\n", in);
|
||||
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;
|
||||
}
|
||||
break;
|
||||
|
||||
case TRADE_CENTRE:
|
||||
// printf("Trade Center...\n");
|
||||
if(trade_state == INIT && in == 0x00) {
|
||||
trade_state = READY;
|
||||
out[0] = 0x00;
|
||||
// printf("Init, now ready\n");
|
||||
} else if(trade_state == READY && in == 0xFD) {
|
||||
trade_state = FIRST_DETECTED_WAIT;
|
||||
trade_state = DETECTED;
|
||||
out[0] = 0xFD;
|
||||
// printf("Ready, begin waiting\n");
|
||||
} else if(trade_state == FIRST_DETECTED_WAIT && in != 0xFD) {
|
||||
// random data of slave is ignored.
|
||||
} else if(trade_state == DETECTED && in != 0xFD) {
|
||||
out[0] = in;
|
||||
trade_state = DATA_TX_RANDOM;
|
||||
// printf("Detected, start random data\n");
|
||||
} else if(trade_state == DATA_TX_RANDOM && in == 0xFD) {
|
||||
trade_state = DATA_TX_WAIT;
|
||||
out[0] = 0xFD;
|
||||
// printf("Random data sent, wait\n");
|
||||
(*counter) = 0;
|
||||
} else if (trade_state == DATA_TX_WAIT && in == 0xFD) {
|
||||
out[0] = 0x00;
|
||||
} else if(trade_state == DATA_TX_WAIT && in != 0xFD) {
|
||||
(*counter) = 0;
|
||||
// send first byte
|
||||
|
|
@ -270,7 +262,6 @@ uint8_t handle_byte(uint8_t in, size_t *counter) {
|
|||
INPUT_BLOCK[(*counter)] = in;
|
||||
trade_state = DATA_TX;
|
||||
(*counter)++;
|
||||
// printf("Sending data (not 0xFD)\n");
|
||||
} else if(trade_state == DATA_TX) {
|
||||
out[0] = DATA_BLOCK[(*counter)];
|
||||
INPUT_BLOCK[(*counter)] = in;
|
||||
|
|
@ -278,57 +269,44 @@ uint8_t handle_byte(uint8_t in, size_t *counter) {
|
|||
if((*counter) == 418) {
|
||||
trade_state = DATA_TX_PATCH;
|
||||
}
|
||||
// printf("Sending data\n");
|
||||
} else if(trade_state == DATA_TX_PATCH && in == 0xFD) {
|
||||
(*counter) = 0;
|
||||
out[0] = 0xFD;
|
||||
// printf("Send patch\n");
|
||||
} else if(trade_state == DATA_TX_PATCH && in != 0xFD) {
|
||||
out[0] = in;
|
||||
(*counter)++;
|
||||
if((*counter) == 197) {
|
||||
trade_state = TRADE_WAIT;
|
||||
}
|
||||
// printf("Send patch trade wait\n");
|
||||
} else if(trade_state == TRADE_WAIT && (in & 0x60) == 0x60) {
|
||||
if (in == 0x6f) {
|
||||
trade_state = READY;
|
||||
out[0] = 0x6f;
|
||||
// printf("Master ready\n");
|
||||
} else {
|
||||
out[0] = 0x60; // first pokemon
|
||||
out[0] = 0x60;
|
||||
trade_pokemon = in - 0x60;
|
||||
// printf("Master first pokemon\n");
|
||||
}
|
||||
} else if(trade_state == TRADE_WAIT && in == 0x00) {
|
||||
out[0] = 0;
|
||||
trade_state = TRADE_DONE;
|
||||
// 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("Trade done, wait\n");
|
||||
} else {
|
||||
trade_state = DONE;
|
||||
// printf("Trade done, mark done\n");
|
||||
}
|
||||
} else if(trade_state == DONE && in == 0x00) {
|
||||
out[0] = 0;
|
||||
trade_state = INIT;
|
||||
// printf("Done, reinit\n");
|
||||
} else {
|
||||
out[0] = in;
|
||||
// printf("Echo back\n");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
out[0] = in;
|
||||
// printf("Echo back 2\n");
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +348,7 @@ void main(void)
|
|||
pPartyMember->move2 = PSYWAVE;
|
||||
pPartyMember->move3 = PSYCHIC;
|
||||
pPartyMember->move4 = FLY;
|
||||
pPartyMember->original_trainer_id = 0xFFDE;//0xA455; // In decimal, these are the funny numbers
|
||||
pPartyMember->original_trainer_id = 0xA455; // In decimal, these are the funny numbers
|
||||
|
||||
// - Experience is complicated. You must look up the Pokemon you are trying to trade
|
||||
// in the following table and apply the experience points that match the level.
|
||||
|
|
@ -418,34 +396,41 @@ void main(void)
|
|||
}
|
||||
}
|
||||
|
||||
size_t trade_counter = 0;
|
||||
trader_packet_to_bytes(&traderPacket, DATA_BLOCK);
|
||||
|
||||
puts("Poke Distribution");
|
||||
puts("Copyright 2023");
|
||||
puts("BreadCodes");
|
||||
|
||||
|
||||
int debug_last_byte = 0x00;
|
||||
size_t trade_counter = 0;
|
||||
while(1) {
|
||||
|
||||
receive_byte();
|
||||
while(_io_status == IO_RECEIVING);
|
||||
uint8_t in = _io_in; //SER_REG_DIR;
|
||||
uint8_t in = _io_in;
|
||||
|
||||
_io_out = handle_byte(in, trade_counter);
|
||||
|
||||
__asm
|
||||
LD A,#0x01
|
||||
LD (__io_status),A ; Store status
|
||||
LD A,#0x01
|
||||
LDH (0x02),A ; Use internal clock
|
||||
LD A,(__io_out)
|
||||
LDH (0x01),A ; Send data byte
|
||||
LD A,#0x80
|
||||
LDH (0x02),A ; Use internal clock
|
||||
__endasm;
|
||||
_io_out = handle_byte(in, &trade_counter);
|
||||
|
||||
while(_io_status == IO_SENDING);
|
||||
while((joypad() > 0)); // Pause output to read the screen
|
||||
// No-Op loop to delay the bytes being sent.
|
||||
// We do this because the serial interface halts operations on
|
||||
// the other Gameboy and freezes the game, so we need to give it
|
||||
// time to think.
|
||||
for (int i = 0; i < 500; i++) {
|
||||
__asm
|
||||
NOP
|
||||
__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;
|
||||
|
||||
while(_io_status == IO_RECEIVING || _io_status == IO_SENDING);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
41
gen1.h
41
gen1.h
|
|
@ -195,18 +195,19 @@ enum connection_state_t {
|
|||
enum trade_state_t {
|
||||
INIT = 0x00,
|
||||
READY = 0x01,
|
||||
FIRST_DETECTED_WAIT = 0x02,
|
||||
DETECTED = 0x02,
|
||||
DATA_TX = 0x03,
|
||||
DATA_TX_WAIT = 0x04,
|
||||
DATA_TX_START = 0x05,
|
||||
DATA_TX_RANDOM = 0x06,
|
||||
DATA_TX_PATCH = 0x07,
|
||||
TRADE_WAIT = 0x08,
|
||||
TRADE_DONE = 0x09,
|
||||
DONE = 0x0A
|
||||
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
|
||||
};
|
||||
|
||||
enum GenOneDex {
|
||||
enum gen_one_dex_t {
|
||||
NULL_POKEMON = 0xFF,
|
||||
RHYDON = 0x01,
|
||||
KANGASKHAN = 0x02,
|
||||
|
|
@ -361,7 +362,7 @@ enum GenOneDex {
|
|||
VICTREEBEL = 0xBE,
|
||||
};
|
||||
|
||||
enum PokemonMove {
|
||||
enum poke_move_t {
|
||||
ABSORB = 0x47,
|
||||
ACID = 0x33,
|
||||
ACID_ARMOR = 0x97,
|
||||
|
|
@ -529,7 +530,7 @@ enum PokemonMove {
|
|||
WRAP = 0x23,
|
||||
};
|
||||
|
||||
enum StatusCondition {
|
||||
enum status_condition_t {
|
||||
NONE = 0x00,
|
||||
ASLEEP = 0x04,
|
||||
BURNED = 0x10,
|
||||
|
|
@ -538,7 +539,7 @@ enum StatusCondition {
|
|||
POISONED = 0x08,
|
||||
};
|
||||
|
||||
enum PokemonType {
|
||||
enum poke_type_t {
|
||||
NORMAL = 0x00,
|
||||
FIGHTING = 0x01,
|
||||
FLYING = 0x02,
|
||||
|
|
@ -559,25 +560,25 @@ enum PokemonType {
|
|||
typedef struct SelectedPokemon {
|
||||
// Number of pokemon in the trainer's party
|
||||
uint8_t number;
|
||||
enum GenOneDex pokemon[6];
|
||||
enum gen_one_dex_t 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 GenOneDex pokemon;
|
||||
enum gen_one_dex_t pokemon;
|
||||
uint16_t current_hp;
|
||||
uint16_t max_hp;
|
||||
uint8_t level;
|
||||
enum StatusCondition status;
|
||||
enum PokemonType type1;
|
||||
enum PokemonType type2; // If only one type, copy the first
|
||||
enum status_condition_t status;
|
||||
enum poke_type_t type1;
|
||||
enum poke_type_t 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 PokemonMove move1;
|
||||
enum PokemonMove move2;
|
||||
enum PokemonMove move3;
|
||||
enum PokemonMove move4;
|
||||
enum poke_move_t move1;
|
||||
enum poke_move_t move2;
|
||||
enum poke_move_t move3;
|
||||
enum poke_move_t 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