about summary refs log tree commit diff stats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/encoding.c398
-rw-r--r--source/encoding.h7
-rw-r--r--source/link.c17
-rw-r--r--source/main.c51
4 files changed, 413 insertions, 60 deletions
diff --git a/source/encoding.c b/source/encoding.c index 0be1e0b..0a44800 100644 --- a/source/encoding.c +++ b/source/encoding.c
@@ -9,15 +9,397 @@
9 */ 9 */
10#include "encoding.h" 10#include "encoding.h"
11 11
12const char charmap[] = { 12const char* charmap[] = {
13 ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '?', '.', '-', ' ', 13 " ", // space
14 ' ', '\"', '\"', '\'', '\'', '*', '*', ' ', ',', ' ', '/', 'A', 'B', 'C', 'D', 'E', 14 "\xe3\x81\x82", // hiragana letter a
15 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 15 "\xe3\x81\x84", // hiragana letter i
16 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 16 "\xe3\x81\x86", // hiragana letter u
17 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' ' 17 "\xe3\x81\x88", // hiragana letter e
18 "\xe3\x81\x8a", // hiragana letter o
19 "\xe3\x81\x8b", // hiragana letter ka
20 "\xe3\x81\x8d", // hiragana letter ki
21 "\xe3\x81\x8f", // hiragana letter ku
22 "\xe3\x81\x91", // hiragana letter ke
23 "\xe3\x81\x93", // hiragana letter ko
24 "\xe3\x81\x95", // hiragana letter sa
25 "\xe3\x81\x97", // hiragana letter si
26 "\xe3\x81\x99", // hiragana letter su
27 "\xe3\x81\x9b", // hiragana letter se
28 "\xe3\x81\x9d", // hiragana letter so
29 "\xe3\x81\x9f", // hiragana letter ta
30 "\xe3\x81\xa1", // hiragana letter ti
31 "\xe3\x81\xa4", // hiragana letter tu
32 "\xe3\x81\xa6", // hiragana letter te
33 "\xe3\x81\xa8", // hiragana letter to
34 "\xe3\x81\xaa", // hiragana letter na
35 "\xe3\x81\xab", // hiragana letter ni
36 "\xe3\x81\xac", // hiragana letter nu
37 "\xe3\x81\xad", // hiragana letter ne
38 "\xe3\x81\xae", // hiragana letter no
39 "\xe3\x81\xaf", // hiragana letter ha
40 "\xe3\x81\xb2", // hiragana letter hi
41 "\xe3\x81\xb5", // hiragana letter hu
42 "\xe3\x81\xb8", // hiragana letter he
43 "\xe3\x81\xbb", // hiragana letter ho
44 "\xe3\x81\xbe", // hiragana letter ma
45 "\xe3\x81\xbf", // hiragana letter mi
46 "\xe3\x82\x80", // hiragana letter mu
47 "\xe3\x82\x81", // hiragana letter me
48 "\xe3\x82\x82", // hiragana letter mo
49 "\xe3\x82\x84", // hiragana letter ya
50 "\xe3\x82\x86", // hiragana letter yu
51 "\xe3\x82\x88", // hiragana letter yo
52 "\xe3\x82\x89", // hiragana letter ra
53 "\xe3\x82\x8a", // hiragana letter ri
54 "\xe3\x82\x8b", // hiragana letter ru
55 "\xe3\x82\x8c", // hiragana letter re
56 "\xe3\x82\x8d", // hiragana letter ro
57 "\xe3\x82\x8f", // hiragana letter wa
58 "\xe3\x82\x92", // hiragana letter wo
59 "\xe3\x82\x93", // hiragana letter n
60 "\xe3\x81\x81", // hiragana letter small a
61 "\xe3\x81\x83", // hiragana letter small i
62 "\xe3\x81\x85", // hiragana letter small u
63 "\xe3\x81\x87", // hiragana letter small e
64 "\xe3\x81\x89", // hiragana letter small o
65 "\xe3\x82\x83", // hiragana letter small ya
66 "\xe3\x82\x85", // hiragana letter small yu
67 "\xe3\x82\x87", // hiragana letter small yo
68 "\xe3\x81\x8c", // hiragana letter ga
69 "\xe3\x81\x8e", // hiragana letter gi
70 "\xe3\x81\x90", // hiragana letter gu
71 "\xe3\x81\x92", // hiragana letter ge
72 "\xe3\x81\x94", // hiragana letter go
73 "\xe3\x81\x96", // hiragana letter za
74 "\xe3\x81\x98", // hiragana letter zi
75 "\xe3\x81\x9a", // hiragana letter zu
76 "\xe3\x81\x9c", // hiragana letter ze
77 "\xe3\x81\x9e", // hiragana letter zo
78 "\xe3\x81\xa0", // hiragana letter da
79 "\xe3\x81\xa2", // hiragana letter di
80 "\xe3\x81\xa5", // hiragana letter du
81 "\xe3\x81\xa7", // hiragana letter de
82 "\xe3\x81\xa9", // hiragana letter do
83 "\xe3\x81\xb0", // hiragana letter ba
84 "\xe3\x81\xb3", // hiragana letter bi
85 "\xe3\x81\xb6", // hiragana letter bu
86 "\xe3\x81\xb9", // hiragana letter be
87 "\xe3\x81\xbc", // hiragana letter bo
88 "\xe3\x81\xb1", // hiragana letter pa
89 "\xe3\x81\xb4", // hiragana letter pi
90 "\xe3\x81\xb7", // hiragana letter pu
91 "\xe3\x81\xba", // hiragana letter pe
92 "\xe3\x81\xbd", // hiragana letter po
93 "\xe3\x81\xa3", // hiragana letter small tu
94 "\xe3\x82\xa2", // katakana letter a
95 "\xe3\x82\xa4", // katakana letter i
96 "\xe3\x82\xa6", // katakana letter u
97 "\xe3\x82\xa8", // katakana letter e
98 "\xe3\x82\xaa", // katakana letter o
99 "\xe3\x82\xab", // katakana letter ka
100 "\xe3\x82\xad", // katakana letter ki
101 "\xe3\x82\xaf", // katakana letter ku
102 "\xe3\x82\xb1", // katakana letter ke
103 "\xe3\x82\xb3", // katakana letter ko
104 "\xe3\x82\xb5", // katakana letter sa
105 "\xe3\x82\xb7", // katakana letter si
106 "\xe3\x82\xb9", // katakana letter su
107 "\xe3\x82\xbb", // katakana letter se
108 "\xe3\x82\xbd", // katakana letter so
109 "\xe3\x82\xbf", // katakana letter ta
110 "\xe3\x83\x81", // katakana letter ti
111 "\xe3\x83\x84", // katakana letter tu
112 "\xe3\x83\x86", // katakana letter te
113 "\xe3\x83\x88", // katakana letter to
114 "\xe3\x83\x8a", // katakana letter na
115 "\xe3\x83\x8b", // katakana letter ni
116 "\xe3\x83\x8c", // katakana letter nu
117 "\xe3\x83\x8d", // katakana letter ne
118 "\xe3\x83\x8e", // katakana letter no
119 "\xe3\x83\x8f", // katakana letter ha
120 "\xe3\x83\x92", // katakana letter hi
121 "\xe3\x83\x95", // katakana letter hu
122 "\xe3\x83\x98", // katakana letter he
123 "\xe3\x83\x9b", // katakana letter ho
124 "\xe3\x83\x9e", // katakana letter ma
125 "\xe3\x83\x9f", // katakana letter mi
126 "\xe3\x83\xa0", // katakana letter mu
127 "\xe3\x83\xa1", // katakana letter me
128 "\xe3\x83\xa2", // katakana letter mo
129 "\xe3\x83\xa4", // katakana letter ya
130 "\xe3\x83\xa6", // katakana letter yu
131 "\xe3\x83\xa8", // katakana letter yo
132 "\xe3\x83\xa9", // katakana letter ra
133 "\xe3\x83\xaa", // katakana letter ri
134 "\xe3\x83\xab", // katakana letter ru
135 "\xe3\x83\xac", // katakana letter re
136 "\xe3\x83\xad", // katakana letter ro
137 "\xe3\x83\xaf", // katakana letter wa
138 "\xe3\x83\xb2", // katakana letter wo
139 "\xe3\x83\xb3", // katakana letter n
140 "\xe3\x82\xa1", // katakana letter small a
141 "\xe3\x82\xa3", // katakana letter small i
142 "\xe3\x82\xa5", // katakana letter small u
143 "\xe3\x82\xa7", // katakana letter small e
144 "\xe3\x82\xa9", // katakana letter small o
145 "\xe3\x83\xa3", // katakana letter small ya
146 "\xe3\x83\xa5", // katakana letter small yu
147 "\xe3\x83\xa7", // katakana letter small yo
148 "\xe3\x82\xac", // katakana letter ga
149 "\xe3\x82\xae", // katakana letter gi
150 "\xe3\x82\xb0", // katakana letter gu
151 "\xe3\x82\xb2", // katakana letter ge
152 "\xe3\x82\xb4", // katakana letter go
153 "\xe3\x82\xb6", // katakana letter za
154 "\xe3\x82\xb8", // katakana letter zi
155 "\xe3\x82\xba", // katakana letter zu
156 "\xe3\x82\xbc", // katakana letter ze
157 "\xe3\x82\xbe", // katakana letter zo
158 "\xe3\x83\x80", // katakana letter da
159 "\xe3\x83\x82", // katakana letter di
160 "\xe3\x83\x85", // katakana letter du
161 "\xe3\x83\x87", // katakana letter de
162 "\xe3\x83\x89", // katakana letter do
163 "\xe3\x83\x90", // katakana letter ba
164 "\xe3\x83\x93", // katakana letter bi
165 "\xe3\x83\x96", // katakana letter bu
166 "\xe3\x83\x99", // katakana letter be
167 "\xe3\x83\x9c", // katakana letter bo
168 "\xe3\x83\x91", // katakana letter pa
169 "\xe3\x83\x94", // katakana letter pi
170 "\xe3\x83\x97", // katakana letter pu
171 "\xe3\x83\x9a", // katakana letter pe
172 "\xe3\x83\x9d", // katakana letter po
173 "\xe3\x83\x83", // katakana letter small tu
174 "0", // arabic numeral zero
175 "1", // arabic numeral one
176 "2", // arabic numeral two
177 "3", // arabic numeral three
178 "4", // arabic numeral four
179 "5", // arabic numeral five
180 "6", // arabic numeral six
181 "7", // arabic numeral seven
182 "8", // arabic numeral eight
183 "9", // arabic numeral nine
184 0, // exclamation mark [varies]
185 0, // question mark [varies]
186 0, // period [varies]
187 0, // hyphen [varies]
188 "\xe3\x83\xbb", // interpunct
189 "\xe2\x80\xa6", // ellipsis
190 0, // left double quotation mark [varies]
191 0, // right double quotation mark [varies]
192 0, // left single quotation mark [varies]
193 0, // right single quotation mark [varies]
194 "\xe2\x99\x82", // mars astrological sign
195 "\xe2\x99\x80", // venus astrological sign
196 0, // unused
197 ",", // comma
198 0, // unused
199 "/", // forward slash
200 "A", // uppercase latin letter a
201 "B", // uppercase latin letter b
202 "C", // uppercase latin letter c
203 "D", // uppercase latin letter d
204 "E", // uppercase latin letter e
205 "F", // uppercase latin letter f
206 "G", // uppercase latin letter g
207 "H", // uppercase latin letter h
208 "I", // uppercase latin letter i
209 "J", // uppercase latin letter j
210 "K", // uppercase latin letter k
211 "L", // uppercase latin letter l
212 "M", // uppercase latin letter m
213 "N", // uppercase latin letter n
214 "O", // uppercase latin letter o
215 "P", // uppercase latin letter p
216 "Q", // uppercase latin letter q
217 "R", // uppercase latin letter r
218 "S", // uppercase latin letter s
219 "T", // uppercase latin letter t
220 "U", // uppercase latin letter u
221 "V", // uppercase latin letter v
222 "W", // uppercase latin letter w
223 "X", // uppercase latin letter x
224 "Y", // uppercase latin letter y
225 "Z", // uppercase latin letter z
226 "a", // lowercase latin letter a
227 "b", // lowercase latin letter b
228 "c", // lowercase latin letter c
229 "d", // lowercase latin letter d
230 "e", // lowercase latin letter e
231 "f", // lowercase latin letter f
232 "g", // lowercase latin letter g
233 "h", // lowercase latin letter h
234 "i", // lowercase latin letter i
235 "j", // lowercase latin letter j
236 "k", // lowercase latin letter k
237 "l", // lowercase latin letter l
238 "m", // lowercase latin letter m
239 "n", // lowercase latin letter n
240 "o", // lowercase latin letter o
241 "p", // lowercase latin letter p
242 "q", // lowercase latin letter q
243 "r", // lowercase latin letter r
244 "s", // lowercase latin letter s
245 "t", // lowercase latin letter t
246 "u", // lowercase latin letter u
247 "v", // lowercase latin letter v
248 "w", // lowercase latin letter w
249 "x", // lowercase latin letter x
250 "y", // lowercase latin letter y
251 "z", // lowercase latin letter z
252 0, // unused
253 0, // unused
254 "\xc3\x84", // uppercase latin letter a with diaeresis
255 "\xc3\x96", // uppercase latin letter o with diaeresis
256 "\xc3\x9c", // uppercase latin letter u with diaeresis
257 "\xc3\xa4", // lowercase latin letter a with diaeresis
258 "\xc3\xb6", // lowercase latin letter o with diaeresis
259 "\xc3\xbc" // lowercase latin letter u with diaeresis
18}; 260};
19 261
20char debugGen3Decode(u8 val) 262/**
263 * Converts a string encoded with the propietary gen 3 character encoding into
264 * a UTF-8 encoded string. The function will read the input buffer until either
265 * the max length has been reached, or an 0xFF has been found. The output buffer
266 * must be at least one plus three times the max length in size.
267 */
268void decodePokemonCharset(
269 const u8* input,
270 int maxLength,
271 char* output,
272 enum PokemonLanguage language)
21{ 273{
22 return charmap[val - 0xA0]; 274 for (int i=0; i<maxLength; i++)
275 {
276 char cur = *input;
277 input++;
278
279 if (cur == 0xff)
280 {
281 break;
282 }
283
284 const char* next = 0;
285
286 if (cur == 0xab)
287 {
288 // fullwidth exclamation mark
289 if (language == Japanese)
290 {
291 next = "\xef\xbc\x81";
292 }
293 // exclamation mark
294 else {
295 next = "!";
296 }
297 } else if (cur == 0xac)
298 {
299 // fullwidth question mark
300 if (language == Japanese)
301 {
302 next = "\xef\xbc\x9f";
303 }
304 // question mark
305 else {
306 next = "?";
307 }
308 } else if (cur == 0xad)
309 {
310 // ideographic full stop
311 if (language == Japanese)
312 {
313 next = "\xe3\x80\x82";
314 }
315 // period
316 else {
317 next = ".";
318 }
319 } else if (cur == 0xae)
320 {
321 // katakana-hiragana prolonged sound mark
322 if (language == Japanese)
323 {
324 next = "\xe3\x83\xbc";
325 }
326 // hyphen
327 else {
328 next = "-";
329 }
330 } else if (cur == 0xb1)
331 {
332 // left white corner bracket
333 if (language == Japanese)
334 {
335 next = "\xe3\x80\x83";
336 }
337 // double low-9 quotation mark
338 else if (language == German)
339 {
340 next = "\xe2\x80\x9e";
341 }
342 // left double angle quotation mark
343 else if (language == French)
344 {
345 next = "\xc2\xab";
346 }
347 // left double quotation mark
348 else {
349 next = "\xe2\x80\x9c";
350 }
351 } else if (cur == 0xb2)
352 {
353 // right white corner bracket
354 if (language == Japanese)
355 {
356 next = "\xe3\x80\x8f";
357 }
358 // left double quotation mark
359 else if (language == German)
360 {
361 next = "\xe2\x80\x9c";
362 }
363 // right double angle quotation mark
364 else if (language == French)
365 {
366 next = "\xc2\xbb";
367 }
368 // right double quotation mark
369 else {
370 next = "\xe2\x80\x9d";
371 }
372 } else if (cur == 0xb3)
373 {
374 // left corner bracket
375 if (language == Japanese)
376 {
377 next = "\xe3\x80\x8c";
378 }
379 // left single quotation mark
380 else {
381 next = "\xe2\x80\x98";
382 }
383 } else if (cur == 0xb4)
384 {
385 // right corner bracket
386 if (language == Japanese)
387 {
388 next = "\xe3\x80\x8d";
389 }
390 // right single quotation mark
391 else {
392 next = "\xe2\x80\x99";
393 }
394 } else {
395 next = charmap[(int)cur];
396 }
397
398 for (; *next != 0; next++)
399 {
400 *output++ = *next;
401 }
402 }
403
404 *output = 0;
23} 405}
diff --git a/source/encoding.h b/source/encoding.h index 4dc3b1f..0cf6165 100644 --- a/source/encoding.h +++ b/source/encoding.h
@@ -8,7 +8,12 @@
8#define ENCODING_H_95547384 8#define ENCODING_H_95547384
9 9
10#include <gccore.h> 10#include <gccore.h>
11#include "pokemon.h"
11 12
12char debugGen3Decode(u8 val); 13void decodePokemonCharset(
14 const u8* input,
15 int maxLength,
16 char* output,
17 enum PokemonLanguage language);
13 18
14#endif /* end of include guard: ENCODING_H_95547384 */ 19#endif /* end of include guard: ENCODING_H_95547384 */
diff --git a/source/link.c b/source/link.c index 27837f8..c627039 100644 --- a/source/link.c +++ b/source/link.c
@@ -12,7 +12,7 @@
12 12
13//from my tests 50us seems to be the lowest 13//from my tests 50us seems to be the lowest
14//safe si transfer delay in between calls 14//safe si transfer delay in between calls
15#define SI_TRANS_DELAY 50 15#define SI_TRANS_DELAY 500
16 16
17static u8* resbuf; 17static u8* resbuf;
18static u8* cmdbuf; 18static u8* cmdbuf;
@@ -61,7 +61,7 @@ u32 recv()
61 SI_Transfer(1, cmdbuf, 1, resbuf, 5, transcb, SI_TRANS_DELAY); 61 SI_Transfer(1, cmdbuf, 1, resbuf, 5, transcb, SI_TRANS_DELAY);
62 62
63 while (transval == 0); 63 while (transval == 0);
64 printf("%08lx\n", *(vu32*)resbuf); 64 //printf("%08lx\n", *(vu32*)resbuf);
65 return *(vu32*)resbuf; 65 return *(vu32*)resbuf;
66} 66}
67 67
@@ -82,14 +82,7 @@ void send(u32 msg)
82 82
83u32 getMsg() 83u32 getMsg()
84{ 84{
85 u32 val = 0; 85 u32 val = __builtin_bswap32(recv());
86 while (val == 0)
87 {
88 val = __builtin_bswap32(recv());
89 }
90
91 send(0);
92 while (recv()!=0);
93 send(0); 86 send(0);
94 87
95 return val; 88 return val;
@@ -105,10 +98,7 @@ void getMsgArr(u32* arr, int len)
105 98
106void sendMsg(u32 msg) 99void sendMsg(u32 msg)
107{ 100{
108 while (recv()==0);
109 send(msg); 101 send(msg);
110 while (recv()!=0);
111 send(0);
112} 102}
113 103
114void waitForGBA() 104void waitForGBA()
@@ -157,5 +147,4 @@ void waitForGame()
157void waitForAck() 147void waitForAck()
158{ 148{
159 while (recv() != 0) {sleep(1);} 149 while (recv() != 0) {sleep(1);}
160 send(0);
161} 150}
diff --git a/source/main.c b/source/main.c index ceb24d5..1355533 100644 --- a/source/main.c +++ b/source/main.c
@@ -10,6 +10,7 @@
10#include <stdio.h> 10#include <stdio.h>
11#include <stdlib.h> 11#include <stdlib.h>
12#include <unistd.h> 12#include <unistd.h>
13#include <string.h>
13#include "link.h" 14#include "link.h"
14#include "encoding.h" 15#include "encoding.h"
15#include "multiboot.h" 16#include "multiboot.h"
@@ -117,6 +118,7 @@ void* extractor(void* userdata)
117 118
118 printf("\n"); 119 printf("\n");
119 VIDEO_WaitVSync(); 120 VIDEO_WaitVSync();
121 sleep(1);
120 122
121 u32 isValid = getMsg(); 123 u32 isValid = getMsg();
122 if (isValid == -1) 124 if (isValid == -1)
@@ -144,19 +146,13 @@ void* extractor(void* userdata)
144 // Get trainer ID 146 // Get trainer ID
145 u32 trainerId = getMsg(); 147 u32 trainerId = getMsg();
146 148
147 printf("Trainer: "); 149 // Get game language.
150 enum PokemonLanguage gameLanguage = getMsg();
148 151
149 for (int i = 0; i < 8; i++) 152 char d_trainerName[25];
150 { 153 decodePokemonCharset(trainerName, 8, d_trainerName, gameLanguage);
151 if (trainerName[i] == 0xFF)
152 {
153 break;
154 } else {
155 printf("%c", debugGen3Decode(trainerName[i]));
156 }
157 }
158 154
159 printf(" (%ld)\n", trainerId); 155 printf("Trainer: %s (%ld)\n", d_trainerName, trainerId);
160 156
161 // Wait for confirmation. 157 // Wait for confirmation.
162 printf("Press A to import the data from this game.\n"); 158 printf("Press A to import the data from this game.\n");
@@ -219,34 +215,15 @@ void* extractor(void* userdata)
219 215
220 struct PokemonIntermediate* pki = (struct PokemonIntermediate*)(&rawdata); 216 struct PokemonIntermediate* pki = (struct PokemonIntermediate*)(&rawdata);
221 217
222 printf("Species: %d\n", __builtin_bswap16(pki->species)); 218 char d_pokename[31];
223 219 decodePokemonCharset(pki->nickname, 10, d_pokename, pki->language);
224 u8* pokename = pki->nickname;
225 printf("Nickname: ");
226
227 for (int i = 0; i < 10; i++)
228 {
229 if (pokename[i] == 0xFF)
230 {
231 break;
232 } else {
233 printf("%c", debugGen3Decode(pokename[i]));
234 }
235 }
236 220
237 printf("\nOT: "); 221 char d_otName[22];
222 decodePokemonCharset(pki->otName, 7, d_otName, pki->language);
238 223
239 for (int i=0; i<7; i++) 224 printf("Species: %d\n", __builtin_bswap16(pki->species));
240 { 225 printf("Nickname: %s\n", d_pokename);
241 if (pki->otName[i] == 0xFF) 226 printf("OT: %s\n", d_otName);
242 {
243 break;
244 } else {
245 printf("%c", debugGen3Decode(pki->otName[i]));
246 }
247 }
248
249 printf("\n");
250 printf("Level: %d\n", pki->level); 227 printf("Level: %d\n", pki->level);
251 printf("HP: %ld\n", __builtin_bswap32(pki->hp)); 228 printf("HP: %ld\n", __builtin_bswap32(pki->hp));
252 printf("Attack: %ld\n", __builtin_bswap32(pki->attack)); 229 printf("Attack: %ld\n", __builtin_bswap32(pki->attack));