From 1d82e3affd42c2336702af4a644baa8eec249ead Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 10 Sep 2017 17:16:52 -0400 Subject: Increased stability and added support for non-English names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GameCube side of the program now can convert from the propietary character set to UTF-8. This is useful for representing names of Pokémon and players in a neutral way. The propietary character set is mostly compatible between the six languages supported by the games (as in, the hiragana and katakana characters unique to Japanese occupy spaces not used by the other languages for names, as do the letters with umlauts unique to German). However, six codepoints differ between the Japanese and non-Japanese character sets, and an additional two differ even amongst the non-Japanese sets. Because of this, the function that converts to UTF-8 takes a language as a parameter, and uses the correct characters for that language. From there, the behavior of this function differs slightly to that of the games. In the non-Japanese games, the Japanese encoding is used if the Pokémon in question originated in a Japanese game, and the non-Japanese encoding (disregarding the regional differences in the two codepoints mentioned earlier) otherwise. In the Japanese games, the Japanese encoding is used regardless of the Pokémon's origin. The decoding function I wrote always uses the character set corresponding to the language of the Pokémon's origin, because that most accurately represents the name given to it, and will not change just because the Pokémon was traded to a different game. The character set used for the name of the player is the one corresponding to the language of the cartridge. Additionally, a number of changes were made to the communication protocol between the GameCube and the GBA that appear to have dramatically increased stability. The most significant of these is likely that the transfer delay was increased tenfold. This causes the multiboot image to take slightly longer to download to the GBA, but the difference is not large enough to outweigh the benefits of the increased stability. --- gba/source/link.c | 15 ++++----------- gba/source/main.c | 17 ++++++++++++++++- gba/source/serialize.c | 12 ++---------- gba/source/serialize.h | 3 +-- 4 files changed, 23 insertions(+), 24 deletions(-) (limited to 'gba') diff --git a/gba/source/link.c b/gba/source/link.c index 26443c8..05e4732 100644 --- a/gba/source/link.c +++ b/gba/source/link.c @@ -12,9 +12,9 @@ void initializeLink() { - REG_HS_CTRL |= JOY_RW; REG_JOYTR = 0; - while ((REG_HS_CTRL & JOY_WRITE) == 0); + REG_HS_CTRL |= JOY_RW; + while ((REG_HS_CTRL & JOY_READ) == 0); REG_HS_CTRL |= JOY_RW; } @@ -22,29 +22,22 @@ void waitForAck() { while ((REG_HS_CTRL & JOY_WRITE) == 0); REG_HS_CTRL |= JOY_RW; - REG_JOYTR = 0; - while ((REG_HS_CTRL & JOY_WRITE) == 0); - REG_HS_CTRL |= JOY_RW; } u32 waitForResponse() { u32 val; - REG_JOYTR = 1; - while ((REG_HS_CTRL & JOY_WRITE) == 0); - val = REG_JOYRE; - REG_HS_CTRL |= JOY_RW; - REG_JOYTR = 0; while ((REG_HS_CTRL & JOY_WRITE) == 0); REG_HS_CTRL |= JOY_RW; + val = REG_JOYRE; return val; } void sendS32(s32 val) { - REG_JOYTR = val; + sendU32(val); } void sendU32(u32 val) diff --git a/gba/source/main.c b/gba/source/main.c index aeb05af..0934e91 100644 --- a/gba/source/main.c +++ b/gba/source/main.c @@ -113,6 +113,21 @@ int main(void) sendU32(trainerIdNum); waitForAck(); + // Send cart language. + u8 cartLang = 0; + switch (*(u8*)(0x80000AF)) + { + case 'J': cartLang = Japanese; break; + case 'E': cartLang = English; break; + case 'F': cartLang = French; break; + case 'I': cartLang = Italian; break; + case 'D': cartLang = German; break; + case 'S': cartLang = Spanish; break; + } + + sendU32(cartLang); + waitForAck(); + // Does the player want to import this game? if (waitForResponse() == 0) { @@ -193,7 +208,7 @@ int main(void) struct PokemonIntermediate pki; - PokemonIntermediateInit(&pki, bpkm, trainerIdNum, secretIdNum, &gameData); + PokemonIntermediateInit(&pki, bpkm, trainerIdNum, secretIdNum); PokemonIntermediateStream(&pki); } } diff --git a/gba/source/serialize.c b/gba/source/serialize.c index 4a80bdf..c5e8570 100644 --- a/gba/source/serialize.c +++ b/gba/source/serialize.c @@ -11,14 +11,6 @@ #include "exptables.h" #include "dexorder.h" -enum Stat { - StatAttack, - StatDefense, - StatSpeed, - StatSpAttack, - StatSpDefense -}; - u32 CalculateStat( u8 base, u32 iv, @@ -50,8 +42,7 @@ void PokemonIntermediateInit( struct PokemonIntermediate* pki, struct BoxPokemon* bpkm, u16 trainerId, - u16 secretId, - const struct GameData* gameData) + u16 secretId) { DecryptBoxPokemon(bpkm); @@ -88,6 +79,7 @@ void PokemonIntermediateInit( pki->metLocation = sub3->metLocation; pki->pokeball = sub3->pokeball; pki->altAbility = sub3->altAbility; + pki->language = bpkm->language & 3; // Derive nature from the personality value. pki->nature = (bpkm->personality % 25); diff --git a/gba/source/serialize.h b/gba/source/serialize.h index 38a4d6b..7fcae0f 100644 --- a/gba/source/serialize.h +++ b/gba/source/serialize.h @@ -17,8 +17,7 @@ void PokemonIntermediateInit( struct PokemonIntermediate* pki, struct BoxPokemon* bpkm, u16 trainerId, - u16 secretId, - const struct GameData* gameData); + u16 secretId); void PokemonIntermediateStream(struct PokemonIntermediate* pki); -- cgit 1.4.1