diff options
-rw-r--r-- | gba/source/link.c | 22 | ||||
-rw-r--r-- | gba/source/link.h | 2 | ||||
-rw-r--r-- | gba/source/main.c | 57 | ||||
-rw-r--r-- | source/main.c | 55 |
4 files changed, 135 insertions, 1 deletions
diff --git a/gba/source/link.c b/gba/source/link.c index acadf3b..26443c8 100644 --- a/gba/source/link.c +++ b/gba/source/link.c | |||
@@ -27,6 +27,21 @@ void waitForAck() | |||
27 | REG_HS_CTRL |= JOY_RW; | 27 | REG_HS_CTRL |= JOY_RW; |
28 | } | 28 | } |
29 | 29 | ||
30 | u32 waitForResponse() | ||
31 | { | ||
32 | u32 val; | ||
33 | |||
34 | REG_JOYTR = 1; | ||
35 | while ((REG_HS_CTRL & JOY_WRITE) == 0); | ||
36 | val = REG_JOYRE; | ||
37 | REG_HS_CTRL |= JOY_RW; | ||
38 | REG_JOYTR = 0; | ||
39 | while ((REG_HS_CTRL & JOY_WRITE) == 0); | ||
40 | REG_HS_CTRL |= JOY_RW; | ||
41 | |||
42 | return val; | ||
43 | } | ||
44 | |||
30 | void sendS32(s32 val) | 45 | void sendS32(s32 val) |
31 | { | 46 | { |
32 | REG_JOYTR = val; | 47 | REG_JOYTR = val; |
@@ -36,3 +51,10 @@ void sendU32(u32 val) | |||
36 | { | 51 | { |
37 | REG_JOYTR = val; | 52 | REG_JOYTR = val; |
38 | } | 53 | } |
54 | |||
55 | void directSendU32(u32 val) | ||
56 | { | ||
57 | REG_JOYTR = val; | ||
58 | while ((REG_HS_CTRL & JOY_READ) == 0); | ||
59 | REG_HS_CTRL |= JOY_RW; | ||
60 | } | ||
diff --git a/gba/source/link.h b/gba/source/link.h index 08fd998..38d1c39 100644 --- a/gba/source/link.h +++ b/gba/source/link.h | |||
@@ -11,7 +11,9 @@ | |||
11 | 11 | ||
12 | void initializeLink(); | 12 | void initializeLink(); |
13 | void waitForAck(); | 13 | void waitForAck(); |
14 | u32 waitForResponse(); | ||
14 | void sendS32(s32 val); | 15 | void sendS32(s32 val); |
15 | void sendU32(u32 val); | 16 | void sendU32(u32 val); |
17 | void directSendU32(u32 val); | ||
16 | 18 | ||
17 | #endif | 19 | #endif |
diff --git a/gba/source/main.c b/gba/source/main.c index 6207685..14d2f1d 100644 --- a/gba/source/main.c +++ b/gba/source/main.c | |||
@@ -10,6 +10,10 @@ | |||
10 | 10 | ||
11 | int main(void) | 11 | int main(void) |
12 | { | 12 | { |
13 | // This possibly increases stability, I don't rightly know, this is all black | ||
14 | // magic, will test more later. | ||
15 | REG_IME = 0; | ||
16 | |||
13 | initializeLink(); | 17 | initializeLink(); |
14 | 18 | ||
15 | // Identify the host game. | 19 | // Identify the host game. |
@@ -105,4 +109,57 @@ int main(void) | |||
105 | 109 | ||
106 | sendU32(tti); | 110 | sendU32(tti); |
107 | waitForAck(); | 111 | waitForAck(); |
112 | |||
113 | // Does the player want to import this game? | ||
114 | if (waitForResponse() == 0) | ||
115 | { | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | // Send Pokédex data | ||
120 | u8* pokedexSeen = 0; | ||
121 | if (GAME_RS) | ||
122 | { | ||
123 | pokedexSeen = SaveBlock2->rs.pokedex.seen; | ||
124 | } else if (GAME_FRLG) | ||
125 | { | ||
126 | pokedexSeen = SaveBlock2->frlg.pokedex.seen; | ||
127 | } else if (GAME_EM) | ||
128 | { | ||
129 | pokedexSeen = SaveBlock2->e.pokedex.seen; | ||
130 | } | ||
131 | |||
132 | for (int i=0; i<13; i++) | ||
133 | { | ||
134 | u32 psi = | ||
135 | (pokedexSeen[i*4]) | ||
136 | | (pokedexSeen[i*4+1] << 8) | ||
137 | | (pokedexSeen[i*4+2] << 16) | ||
138 | | (pokedexSeen[i*4+3] << 24); | ||
139 | |||
140 | directSendU32(psi); | ||
141 | } | ||
142 | |||
143 | u8* pokedexCaught = 0; | ||
144 | if (GAME_RS) | ||
145 | { | ||
146 | pokedexCaught = SaveBlock2->rs.pokedex.owned; | ||
147 | } else if (GAME_FRLG) | ||
148 | { | ||
149 | pokedexCaught = SaveBlock2->frlg.pokedex.owned; | ||
150 | } else if (GAME_EM) | ||
151 | { | ||
152 | pokedexCaught = SaveBlock2->e.pokedex.owned; | ||
153 | } | ||
154 | |||
155 | for (int i=0; i<13; i++) | ||
156 | { | ||
157 | u32 psi = | ||
158 | (pokedexCaught[i*4]) | ||
159 | | (pokedexCaught[i*4+1] << 8) | ||
160 | | (pokedexCaught[i*4+2] << 16) | ||
161 | | (pokedexCaught[i*4+3] << 24); | ||
162 | |||
163 | directSendU32(psi); | ||
164 | } | ||
108 | } | 165 | } |
diff --git a/source/main.c b/source/main.c index 128feb9..dd252b5 100644 --- a/source/main.c +++ b/source/main.c | |||
@@ -240,12 +240,29 @@ u32 getMsg() | |||
240 | } | 240 | } |
241 | 241 | ||
242 | send(0); | 242 | send(0); |
243 | while (recv()!=0) {sleep(1);}; | 243 | while (recv()!=0) {sleep(1);} |
244 | send(0); | 244 | send(0); |
245 | 245 | ||
246 | return val; | 246 | return val; |
247 | } | 247 | } |
248 | 248 | ||
249 | void getMsgArr(u32* arr, int len) | ||
250 | { | ||
251 | for (int i=0; i<len; i++) | ||
252 | { | ||
253 | *(vu32*)(arr+i) = __builtin_bswap32(recv()); | ||
254 | usleep(500000); | ||
255 | } | ||
256 | } | ||
257 | |||
258 | void sendMsg(u32 msg) | ||
259 | { | ||
260 | while (recv()==0) {sleep(1);} | ||
261 | send(msg); | ||
262 | while (recv()!=0) {sleep(1);} | ||
263 | send(0); | ||
264 | } | ||
265 | |||
249 | int main(int argc, char *argv[]) | 266 | int main(int argc, char *argv[]) |
250 | { | 267 | { |
251 | void *xfb = NULL; | 268 | void *xfb = NULL; |
@@ -520,8 +537,44 @@ int main(int argc, char *argv[]) | |||
520 | 537 | ||
521 | if (waitForButtons(PAD_BUTTON_A | PAD_BUTTON_B) & PAD_BUTTON_B) | 538 | if (waitForButtons(PAD_BUTTON_A | PAD_BUTTON_B) & PAD_BUTTON_B) |
522 | { | 539 | { |
540 | printf("Cancelling...\n"); | ||
541 | VIDEO_WaitVSync(); | ||
542 | |||
543 | sendMsg(0); | ||
544 | |||
523 | continue; | 545 | continue; |
524 | } | 546 | } |
547 | |||
548 | printf("Importing...\n"); | ||
549 | VIDEO_WaitVSync(); | ||
550 | |||
551 | sendMsg(1); | ||
552 | |||
553 | // Get Pokédex data | ||
554 | u32 pokedexSeen[13]; | ||
555 | u32 pokedexCaught[13]; | ||
556 | |||
557 | getMsgArr(pokedexSeen, 13); | ||
558 | getMsgArr(pokedexCaught, 13); | ||
559 | int numCaught = 0; | ||
560 | int numSeen = 0; | ||
561 | for (int i=0; i<(13*32); i++) | ||
562 | { | ||
563 | if (pokedexCaught[i >> 5] >> (i & 31) & 1) | ||
564 | { | ||
565 | //printf("Caught #%d\n", i); | ||
566 | numCaught++; | ||
567 | numSeen++; | ||
568 | } else if (pokedexSeen[i >> 5] >> (i & 31) & 1) | ||
569 | { | ||
570 | //printf("Saw #%d\n", i); | ||
571 | numSeen++; | ||
572 | } | ||
573 | } | ||
574 | |||
575 | printf("Caught: %d\nSeen: %d\n", numCaught, numSeen); | ||
576 | |||
577 | waitForButtons(PAD_BUTTON_START); | ||
525 | } | 578 | } |
526 | } | 579 | } |
527 | 580 | ||