diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-07-11 18:14:18 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-07-11 18:14:18 -0400 |
commit | ec66a022a8879a5300f2ae64cd86a5d8cfbd1a36 (patch) | |
tree | 06e096126cf673be5cfd9dd1ff164c8d46520de9 /source/main.c | |
parent | 57afb4058710a978bd7b07a368125d04378c62f1 (diff) | |
download | gen3uploader-ec66a022a8879a5300f2ae64cd86a5d8cfbd1a36.tar.gz gen3uploader-ec66a022a8879a5300f2ae64cd86a5d8cfbd1a36.tar.bz2 gen3uploader-ec66a022a8879a5300f2ae64cd86a5d8cfbd1a36.zip |
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.
Diffstat (limited to 'source/main.c')
-rw-r--r-- | source/main.c | 77 |
1 files changed, 53 insertions, 24 deletions
diff --git a/source/main.c b/source/main.c index 79fd2fc..dfcdc3b 100644 --- a/source/main.c +++ b/source/main.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <dirent.h> | 17 | #include <dirent.h> |
18 | #include <fat.h> | 18 | #include <fat.h> |
19 | #include "link.h" | 19 | #include "link.h" |
20 | #include "encoding.h" | ||
20 | 21 | ||
21 | //from my tests 50us seems to be the lowest | 22 | //from my tests 50us seems to be the lowest |
22 | //safe si transfer delay in between calls | 23 | //safe si transfer delay in between calls |
@@ -308,6 +309,21 @@ u32 deriveKeyC(u32 keyCderive, u32 kcrc) { | |||
308 | return keyc; | 309 | return keyc; |
309 | } | 310 | } |
310 | 311 | ||
312 | u32 getMsg() | ||
313 | { | ||
314 | u32 val = 0; | ||
315 | while (val == 0) | ||
316 | { | ||
317 | val = __builtin_bswap32(recv()); | ||
318 | fsleep(1); | ||
319 | } | ||
320 | send(0); | ||
321 | while (recv()!=0) {fsleep(1);}; | ||
322 | send(0); | ||
323 | |||
324 | return val; | ||
325 | } | ||
326 | |||
311 | int main(int argc, char *argv[]) | 327 | int main(int argc, char *argv[]) |
312 | { | 328 | { |
313 | void *xfb = NULL; | 329 | void *xfb = NULL; |
@@ -482,7 +498,7 @@ int main(int argc, char *argv[]) | |||
482 | u32 bootkey = docrc(0xBB,keyc) | 0xbb000000; | 498 | u32 bootkey = docrc(0xBB,keyc) | 0xbb000000; |
483 | printf("BootKey = 0x%08lx\n",bootkey); | 499 | printf("BootKey = 0x%08lx\n",bootkey); |
484 | send(bootkey); | 500 | send(bootkey); |
485 | /* | 501 | /* |
486 | printf("GBA Found! Waiting on BIOS...\n"); | 502 | printf("GBA Found! Waiting on BIOS...\n"); |
487 | 503 | ||
488 | resbuf[2]=0; | 504 | resbuf[2]=0; |
@@ -557,12 +573,12 @@ int main(int argc, char *argv[]) | |||
557 | endproc(); | 573 | endproc(); |
558 | } else if (btns & PAD_BUTTON_A) | 574 | } else if (btns & PAD_BUTTON_A) |
559 | {*/ | 575 | {*/ |
560 | sleep(1); | 576 | sleep(2); |
561 | //recv(); | 577 | //recv(); |
562 | 578 | ||
563 | //if (recv() == 0) //ready | 579 | //if (recv() == 0) //ready |
564 | { | 580 | //{ |
565 | 581 | {{ | |
566 | printf("Waiting for GBA...\n"); | 582 | printf("Waiting for GBA...\n"); |
567 | while (recv() != 0) {fsleep(1);}; | 583 | while (recv() != 0) {fsleep(1);}; |
568 | send(0); | 584 | send(0); |
@@ -604,6 +620,7 @@ int main(int argc, char *argv[]) | |||
604 | 620 | ||
605 | send(0); | 621 | send(0); |
606 | while (recv()!=0) {fsleep(1);}; | 622 | while (recv()!=0) {fsleep(1);}; |
623 | send(0); | ||
607 | //sleep(1); | 624 | //sleep(1); |
608 | 625 | ||
609 | if (gameId == -1) | 626 | if (gameId == -1) |
@@ -644,27 +661,26 @@ int main(int argc, char *argv[]) | |||
644 | 661 | ||
645 | send(0); | 662 | send(0); |
646 | while (recv()!=0) {fsleep(1);}; | 663 | while (recv()!=0) {fsleep(1);}; |
664 | send(0); | ||
647 | //sleep(1); | 665 | //sleep(1); |
648 | /* | 666 | |
649 | // Get trainer name | 667 | // Get trainer name |
650 | u8 trainerName[8]; | 668 | u8 trainerName[8]; |
651 | 669 | ||
652 | u32 tnd = recv(); | 670 | u32 tnd = getMsg(); |
653 | send(0); | 671 | //send(0); |
654 | trainerName[0] = (tnd & 0xFF000000); | 672 | trainerName[0] = (tnd & 0xFF000000) >> 24; |
655 | trainerName[1] = (tnd & 0x00FF0000) >> 8; | 673 | trainerName[1] = (tnd & 0x00FF0000) >> 16; |
656 | trainerName[2] = (tnd & 0x0000FF00) >> 16; | 674 | trainerName[2] = (tnd & 0x0000FF00) >> 8; |
657 | trainerName[3] = (tnd & 0x000000FF) >> 24; | 675 | trainerName[3] = (tnd & 0x000000FF); |
658 | 676 | ||
659 | tnd = recv(); | 677 | tnd = getMsg(); |
660 | send(0); | 678 | //send(0); |
661 | trainerName[4] = (tnd & 0xFF000000); | 679 | trainerName[4] = (tnd & 0xFF000000) >> 24; |
662 | trainerName[5] = (tnd & 0x00FF0000) >> 8; | 680 | trainerName[5] = (tnd & 0x00FF0000) >> 16; |
663 | trainerName[6] = (tnd & 0x0000FF00) >> 16; | 681 | trainerName[6] = (tnd & 0x0000FF00) >> 8; |
664 | trainerName[7] = (tnd & 0x000000FF) >> 24; | 682 | trainerName[7] = (tnd & 0x000000FF); |
665 | 683 | ||
666 | printf("Trainer: %s", (char*) trainerName); | ||
667 | */ | ||
668 | // Get trainer ID | 684 | // Get trainer ID |
669 | u32 trainerId = 0; | 685 | u32 trainerId = 0; |
670 | while (trainerId == 0) | 686 | while (trainerId == 0) |
@@ -674,7 +690,20 @@ int main(int argc, char *argv[]) | |||
674 | } | 690 | } |
675 | send(0); | 691 | send(0); |
676 | while (recv()!=0) {fsleep(1);}; | 692 | while (recv()!=0) {fsleep(1);}; |
693 | send(0); | ||
677 | //sleep(1); | 694 | //sleep(1); |
695 | |||
696 | printf("Trainer: "); | ||
697 | |||
698 | for (int i = 0; i < 8; i++) | ||
699 | { | ||
700 | if (trainerName[i] == 0xFF) | ||
701 | { | ||
702 | break; | ||
703 | } else { | ||
704 | printf("%c", debugGen3Decode(trainerName[i])); | ||
705 | } | ||
706 | } | ||
678 | 707 | ||
679 | printf(" (%ld)\n", trainerId); | 708 | printf(" (%ld)\n", trainerId); |
680 | 709 | ||
@@ -917,9 +946,9 @@ int main(int argc, char *argv[]) | |||
917 | sleep(5); | 946 | sleep(5); |
918 | } | 947 | } |
919 | }*/ | 948 | }*/ |
920 | // } | 949 | } |
921 | // } | 950 | // } |
922 | // } | 951 | // } |
923 | } | 952 | } |
924 | return 0; | 953 | return 0; |
925 | } | 954 | } |