From ec66a022a8879a5300f2ae64cd86a5d8cfbd1a36 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 11 Jul 2017 18:14:18 -0400 Subject: Things are semi-reliably working now! A good portion of the time, the Wii will display: Pokemon LeafGreen Trainer: Starla (34182) which is the correct data on the cartridge I am testing with. Most of the GBA changes are within comments and are unimportant. I did uncomment the portion where it sends over the trainer's name, and I fixed how it reads the trainer ID from memory. The Wii changes involve properly cooperating in the message sending protocol I'm having the GBA and Wii use. More description regarding protocol: I'm not super familiar with the JOY BUS protocol because it's undocumented, but there seems to be this issue where the Wii reads the same value multiple times from the cable, and since the cable is used to negotiate the multiboot image, I need to make sure that the Wii and GBA are on the same page. Since the last message that the GBA sends is nonzero, I have the GBA image start by sending a zero and waiting for a response, and I have the Wii wait for a zero. The Wii then sends a zero in response to the GBA. From then on, the message sending protocol works like so: Wii: waits for non-zero value GBA: sends non-zero value, waits for any response Wii: reads message, sends 0 response, waits for 0 response GBA: receives response, sends 0 response, waits for any response Wii: reads 0, continues on with program The reason for this is to prevent incorrect communication caused by the Wii reading the same value from the GBA multiple times by essentially delimiting the message. This is currently pretty slow because I have debugging messages and sleeps everywhere. I will clean this code up, but this project is slightly dark magic right now and I wanted to commit something that worked in the slightest. Also added a debug function that transcodes from the proprietary gen 3 encoding to ASCII in the domain of characters that can actually be used in names (except for the 6 special German ones). Thanks to Bulbapedia (https://bulbapedia.bulbagarden.net/wiki/Character_encoding_in_Generation_III) for this. It's used for now to display the Trainer name on the console. It assumes that the cartridge is non-Japanese; this will be addressed. I'm not currently planning on transcoding names before transmitting them, because of the fact that there are characters in the character set that are not present in any other character set, and thus transcoding them spuriously (like PK -> P,K) is a loss of data. However, it is true that no such characters exist in the set of characters that can be used for names (in either the Japanese or non-Japanese encoding), so I may later decide to transcode to Unicode on the Wii before transmitting. --- gba/source/main.c | 64 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 23 deletions(-) (limited to 'gba/source/main.c') diff --git a/gba/source/main.c b/gba/source/main.c index 104866a..94d4c2b 100644 --- a/gba/source/main.c +++ b/gba/source/main.c @@ -96,31 +96,53 @@ int main(void) m3_fill(RGB15(31,31,31)); plot_sqr( 4, 4, RGB15(31, 0, 0) ); // or CLR_RED - + /* //*(vu16 *)(REG_BASE + 0x84) = 0x8f; //REG_IME = 1; // the vblank interrupt must be enabled for VBlankIntrWait() to work // since the default dispatcher handles the bios flags no vblank handler // is required - //irqInit(); - //irqEnable(IRQ_VBLANK); + irqInit(); + irqEnable(IRQ_VBLANK); - //consoleDemoInit(); + consoleDemoInit(); //REG_JOYTR = 0; // ansi escape sequence to set print co-ordinates // /x1b[line;columnH //u32 i; - //iprintf("\x1b[9;2HPokemon Gen III Data Extractor\n"); - //iprintf("\x1b[10;4HPlease look at the TV\n"); + iprintf("\x1b[9;2HPokemon Gen III Data Extractor\n"); + iprintf("\x1b[10;4HPlease look at the TV\n"); // disable this, needs power - //SNDSTAT = 0; - //SNDBIAS = 0; + SNDSTAT = 0; + SNDBIAS = 0; // Set up waitstates for EEPROM access etc. - //REG_WAITCNT = 0x0317; + REG_WAITCNT = 0x0317; + + s32 gamesize = getGameSize(); + u32 savesize = SaveSize(save_data,gamesize); + switch (savesize){ + case 0x200: + GetSave_EEPROM_512B(save_data); + break; + case 0x2000: + GetSave_EEPROM_8KB(save_data); + break; + case 0x8000: + GetSave_SRAM_32KB(save_data); + break; + case 0x10000: + GetSave_FLASH_64KB(save_data); + break; + case 0x20000: + GetSave_FLASH_128KB(save_data); + break; + default: + break; + }*/ //clear out previous messages REG_HS_CTRL |= JOY_RW; @@ -172,10 +194,12 @@ int main(void) plot_sqr( 5, 4, RGB15( 31, 0,31) ); waitForAck(); plot_sqr( 5, 5, RGB15( 16, 16,16) ); + // Get access to save data. pSaveBlock1 SaveBlock1; pSaveBlock2 SaveBlock2; pSaveBlock3 SaveBlock3; + //iprintf("gonna check thing\n"); if (!initSaveData(&SaveBlock1, &SaveBlock2, &SaveBlock3)) { // Unsupported game version. @@ -187,12 +211,13 @@ int main(void) continue; } + //iprintf("success\n"); plot_sqr( 5, 6, RGB15( 0, 31,16) ); sendS32(1); waitForAck(); - /* + // Send trainer name. - u8* trainerName; + u8* trainerName = 0; if (GAME_RS) { @@ -204,14 +229,6 @@ int main(void) { trainerName = SaveBlock2->e.playerName; } - iprintf("%d\n", trainerName[0]); - iprintf("%d\n", trainerName[1]); - iprintf("%d\n", trainerName[2]); - iprintf("%d\n", trainerName[3]); - iprintf("%d\n", trainerName[4]); - iprintf("%d\n", trainerName[5]); - iprintf("%d\n", trainerName[6]); - iprintf("%d\n", trainerName[7]); u32 tn1 = (trainerName[0] << 24) @@ -230,10 +247,10 @@ int main(void) sendU32(tn2); waitForAck(); -*/ + // Send trainer ID. + u8* trainerId = 0; - if (GAME_RS) { trainerId = SaveBlock2->rs.playerTrainerId; @@ -246,9 +263,10 @@ int main(void) } u32 tti = - (trainerId[2] << 8) - | (trainerId[3]); + (trainerId[1] << 8) + | (trainerId[0]); + //iprintf("sending trainer id %ld\n", tti); sendU32(tti); waitForAck(); -- cgit 1.4.1