-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpokemon-rby-trade-translator.ino
1714 lines (1697 loc) · 88.9 KB
/
pokemon-rby-trade-translator.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*DESCRIPTION: A program that communicates with a Gameboy running an English Gen 1 Pokemon Game and another Gameboy running a Japanese Gen 1 Pokemon game, both being connected to the Arduino Pins via the link cable.*/
//Arduino(Master)
//Gameboy A (Slave)(English)
//Gameboy B (Slave)(Japanese)
/*C INCLUDES*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*PIN DEFINITIONS*/
#define DMG_GAMEBOY_A_LINK_CLK 2
#define DMG_GAMEBOY_A_LINK_SIN 3
#define DMG_GAMEBOY_A_LINK_SOUT 4
#define DMG_GAMEBOY_B_LINK_CLK 5
#define DMG_GAMEBOY_B_LINK_SIN 6
#define DMG_GAMEBOY_B_LINK_SOUT 7
//#define START_TRANSMISSION_BUTTON_PIN 8
/*BUFFER DEFINITIONS*/
/*OTHER DEFINITIONS*/
#define STATE_COUNT 26
#define TRAINER_ID_COUNT 4
/*STRUCTS*/
struct LinkState{
//Controls the condition needed for the state to proceed.
//0 = Waiting on Byte, 1 = Waiting For Data Transmission + Data Sync, 2 = Data Translation, 3 = Jump To State, 4 = Delay Transmission
unsigned char stateType = 0;
//The byte that the the state is waiting on.
unsigned char targetByte = 0;
//Whether the target byte consists of a range.
bool targetByteUsesRange = false;
//The inclusive end of the range of the target byte check.
unsigned char targetByteEnd = 0;
//Whether the condition needs to be inverted.
bool inverseCondition = false;
//The occurrences of the byte needed to satify the state.
unsigned char targetByteOccurrenceCount = 1;
//The counter used to keep track of the amount of time the target byte was read while this state is active. One for each gameboy.
unsigned char targetByteOccurrenceCounterA = 1;
unsigned char targetByteOccurrenceCounterB = 1;
//Whether the occurrence counter resets if the condition isn't satisfied.
bool resetOccurrenceCounterUponConflictingByte = false;
//Whether the state responds with a byte whenever it's condition gets satisfied.
bool respondsWithByte = false;
//Whether the state responds with a byte upon transitioning to a different state.
bool respondsWithByteUponTransition = false;
//The byte that will be sent to the gameboys when the state's condition gets satisfied, if applicable.
unsigned char responseByte = 0xFE;
//The amount of response bytes that will be sent to the gameboy.
unsigned char responseByteRepeatCount = 0;
//Whether the state has a byte is sends by default.
bool sendsByteByDefault = true;
//The byte to send by default whenever this state isn't satisfied.
unsigned char defaultResponseByte = 0xFE;
//Whether the default response byte is the last byte that was exchanged.
bool useLastExchangedBytesAsDefaultResponseByte = false;
//Stores the index of the buffer to be used.
//0 = Random Number Block, 1 = Player Party Block, 2 = Patch List Block
signed char bufferIndex = -1;
//Whether the state exchanges bytes. Used for states with the type of 1.
bool exchangesBytes = false;
//Stores the amount of bytes that is expected to be exchanged while the state is active.
unsigned short bufferASize = 0;
unsigned short bufferBSize = 0;
//The state that will be looped back to once this state is made active.
unsigned char jumpStateIndex = 0;
//Whether the state waits for a byte before it can be transitioned out of.
bool canOnlyProceedOnCertainByte = false;
//The byte the state will wait for before the it can be transitioned out of.
unsigned char requiredByteToProceed = 0;
//The amount of time(in ms) transmission will be disabled after this state is transitioned from.
unsigned long transmissionDelayTime = 0;
};
/*DATA*/
//1661 Byte Array of Data containing Encoded English Pokemon Names (11 Bytes Each)
const unsigned char englishPokemonNameData[] PROGMEM = {
0x81, 0x94, 0x8b, 0x81, 0x80, 0x92, 0x80, 0x94, 0x91, 0x50, 0x00, 0x88, 0x95, 0x98, 0x92, 0x80,
0x94, 0x91, 0x50, 0x00, 0x00, 0x00, 0x95, 0x84, 0x8d, 0x94, 0x92, 0x80, 0x94, 0x91, 0x50, 0x00,
0x00, 0x82, 0x87, 0x80, 0x91, 0x8c, 0x80, 0x8d, 0x83, 0x84, 0x91, 0x50, 0x82, 0x87, 0x80, 0x91,
0x8c, 0x84, 0x8b, 0x84, 0x8e, 0x8d, 0x50, 0x82, 0x87, 0x80, 0x91, 0x88, 0x99, 0x80, 0x91, 0x83,
0x50, 0x00, 0x92, 0x90, 0x94, 0x88, 0x91, 0x93, 0x8b, 0x84, 0x50, 0x00, 0x00, 0x96, 0x80, 0x91,
0x93, 0x8e, 0x91, 0x93, 0x8b, 0x84, 0x50, 0x00, 0x81, 0x8b, 0x80, 0x92, 0x93, 0x8e, 0x88, 0x92,
0x84, 0x50, 0x00, 0x82, 0x80, 0x93, 0x84, 0x91, 0x8f, 0x88, 0x84, 0x50, 0x00, 0x00, 0x8c, 0x84,
0x93, 0x80, 0x8f, 0x8e, 0x83, 0x50, 0x00, 0x00, 0x00, 0x81, 0x94, 0x93, 0x93, 0x84, 0x91, 0x85,
0x91, 0x84, 0x84, 0x50, 0x96, 0x84, 0x84, 0x83, 0x8b, 0x84, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8a,
0x80, 0x8a, 0x94, 0x8d, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x81, 0x84, 0x84, 0x83, 0x91, 0x88,
0x8b, 0x8b, 0x50, 0x00, 0x00, 0x8f, 0x88, 0x83, 0x86, 0x84, 0x98, 0x50, 0x00, 0x00, 0x00, 0x00,
0x8f, 0x88, 0x83, 0x86, 0x84, 0x8e, 0x93, 0x93, 0x8e, 0x50, 0x00, 0x8f, 0x88, 0x83, 0x86, 0x84,
0x8e, 0x93, 0x50, 0x00, 0x00, 0x00, 0x91, 0x80, 0x93, 0x93, 0x80, 0x93, 0x80, 0x50, 0x00, 0x00,
0x00, 0x91, 0x80, 0x93, 0x88, 0x82, 0x80, 0x93, 0x84, 0x50, 0x00, 0x00, 0x92, 0x8f, 0x84, 0x80,
0x91, 0x8e, 0x96, 0x50, 0x00, 0x00, 0x00, 0x85, 0x84, 0x80, 0x91, 0x8e, 0x96, 0x50, 0x00, 0x00,
0x00, 0x00, 0x84, 0x8a, 0x80, 0x8d, 0x92, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x91, 0x81,
0x8e, 0x8a, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x88, 0x8a, 0x80, 0x82, 0x87, 0x94, 0x50,
0x00, 0x00, 0x00, 0x91, 0x80, 0x88, 0x82, 0x87, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x92, 0x80,
0x8d, 0x83, 0x92, 0x87, 0x91, 0x84, 0x96, 0x50, 0x00, 0x92, 0x80, 0x8d, 0x83, 0x92, 0x8b, 0x80,
0x92, 0x87, 0x50, 0x00, 0x8d, 0x88, 0x83, 0x8e, 0x91, 0x80, 0x8d, 0x50, 0x00, 0x00, 0x00, 0x8d,
0x88, 0x83, 0x8e, 0x91, 0x88, 0x8d, 0x80, 0x50, 0x00, 0x00, 0x8d, 0x88, 0x83, 0x8e, 0x90, 0x94,
0x84, 0x84, 0x8d, 0x50, 0x00, 0x8d, 0x88, 0x83, 0x8e, 0x91, 0x80, 0x8d, 0x50, 0x00, 0x00, 0x00,
0x8d, 0x88, 0x83, 0x8e, 0x91, 0x88, 0x8d, 0x8e, 0x50, 0x00, 0x00, 0x8d, 0x88, 0x83, 0x8e, 0x8a,
0x88, 0x8d, 0x86, 0x50, 0x00, 0x00, 0x82, 0x8b, 0x84, 0x85, 0x80, 0x88, 0x91, 0x98, 0x50, 0x00,
0x00, 0x82, 0x8b, 0x84, 0x85, 0x80, 0x81, 0x8b, 0x84, 0x50, 0x00, 0x00, 0x95, 0x94, 0x8b, 0x8f,
0x88, 0x97, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x88, 0x8d, 0x84, 0x93, 0x80, 0x8b, 0x84, 0x92,
0x50, 0x00, 0x89, 0x88, 0x86, 0x86, 0x8b, 0x98, 0x8f, 0x94, 0x85, 0x85, 0x50, 0x96, 0x88, 0x86,
0x86, 0x8b, 0x98, 0x93, 0x94, 0x85, 0x85, 0x50, 0x99, 0x94, 0x81, 0x80, 0x93, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x86, 0x8e, 0x8b, 0x81, 0x80, 0x93, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x83,
0x83, 0x88, 0x92, 0x87, 0x50, 0x00, 0x00, 0x00, 0x00, 0x86, 0x8b, 0x8e, 0x8e, 0x8c, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x95, 0x88, 0x8b, 0x84, 0x8f, 0x8b, 0x94, 0x8c, 0x84, 0x50, 0x00, 0x8f,
0x80, 0x91, 0x80, 0x92, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x80, 0x91, 0x80, 0x92, 0x84,
0x82, 0x93, 0x50, 0x00, 0x00, 0x95, 0x84, 0x8d, 0x8e, 0x8d, 0x80, 0x93, 0x50, 0x00, 0x00, 0x00,
0x95, 0x84, 0x8d, 0x8e, 0x8c, 0x8e, 0x93, 0x87, 0x50, 0x00, 0x00, 0x83, 0x88, 0x86, 0x8b, 0x84,
0x93, 0x93, 0x50, 0x00, 0x00, 0x00, 0x83, 0x94, 0x86, 0x93, 0x91, 0x88, 0x8e, 0x50, 0x00, 0x00,
0x00, 0x8c, 0x84, 0x8e, 0x96, 0x93, 0x87, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x84, 0x91, 0x92,
0x88, 0x80, 0x8d, 0x50, 0x00, 0x00, 0x00, 0x8f, 0x92, 0x98, 0x83, 0x94, 0x82, 0x8a, 0x50, 0x00,
0x00, 0x00, 0x86, 0x8e, 0x8b, 0x83, 0x94, 0x82, 0x8a, 0x50, 0x00, 0x00, 0x00, 0x8c, 0x80, 0x8d,
0x8a, 0x84, 0x98, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x91, 0x88, 0x8c, 0x84, 0x80, 0x8f, 0x84,
0x50, 0x00, 0x00, 0x86, 0x91, 0x8e, 0x96, 0x8b, 0x88, 0x93, 0x87, 0x84, 0x50, 0x00, 0x80, 0x91,
0x82, 0x80, 0x8d, 0x88, 0x8d, 0x84, 0x50, 0x00, 0x00, 0x8f, 0x8e, 0x8b, 0x88, 0x96, 0x80, 0x86,
0x50, 0x00, 0x00, 0x00, 0x8f, 0x8e, 0x8b, 0x88, 0x96, 0x87, 0x88, 0x91, 0x8b, 0x50, 0x00, 0x8f,
0x8e, 0x8b, 0x88, 0x96, 0x91, 0x80, 0x93, 0x87, 0x50, 0x00, 0x80, 0x81, 0x91, 0x80, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x80, 0x83, 0x80, 0x81, 0x91, 0x80, 0x50, 0x00, 0x00, 0x00,
0x80, 0x8b, 0x80, 0x8a, 0x80, 0x99, 0x80, 0x8c, 0x50, 0x00, 0x00, 0x8c, 0x80, 0x82, 0x87, 0x8e,
0x8f, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x80, 0x82, 0x87, 0x8e, 0x8a, 0x84, 0x50, 0x00, 0x00,
0x00, 0x8c, 0x80, 0x82, 0x87, 0x80, 0x8c, 0x8f, 0x50, 0x00, 0x00, 0x00, 0x81, 0x84, 0x8b, 0x8b,
0x92, 0x8f, 0x91, 0x8e, 0x94, 0x93, 0x50, 0x96, 0x84, 0x84, 0x8f, 0x88, 0x8d, 0x81, 0x84, 0x8b,
0x8b, 0x50, 0x95, 0x88, 0x82, 0x93, 0x91, 0x84, 0x84, 0x81, 0x84, 0x8b, 0x50, 0x93, 0x84, 0x8d,
0x93, 0x80, 0x82, 0x8e, 0x8e, 0x8b, 0x50, 0x00, 0x93, 0x84, 0x8d, 0x93, 0x80, 0x82, 0x91, 0x94,
0x84, 0x8b, 0x50, 0x86, 0x84, 0x8e, 0x83, 0x94, 0x83, 0x84, 0x50, 0x00, 0x00, 0x00, 0x86, 0x91,
0x80, 0x95, 0x84, 0x8b, 0x84, 0x91, 0x50, 0x00, 0x00, 0x86, 0x8e, 0x8b, 0x84, 0x8c, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x8f, 0x8e, 0x8d, 0x98, 0x93, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x91,
0x80, 0x8f, 0x88, 0x83, 0x80, 0x92, 0x87, 0x50, 0x00, 0x00, 0x92, 0x8b, 0x8e, 0x96, 0x8f, 0x8e,
0x8a, 0x84, 0x50, 0x00, 0x00, 0x92, 0x8b, 0x8e, 0x96, 0x81, 0x91, 0x8e, 0x50, 0x00, 0x00, 0x00,
0x8c, 0x80, 0x86, 0x8d, 0x84, 0x8c, 0x88, 0x93, 0x84, 0x50, 0x00, 0x8c, 0x80, 0x86, 0x8d, 0x84,
0x93, 0x8e, 0x8d, 0x50, 0x00, 0x00, 0x85, 0x80, 0x91, 0x85, 0x84, 0x93, 0x82, 0x87, 0xe0, 0x83,
0x50, 0x83, 0x8e, 0x83, 0x94, 0x8e, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x8e, 0x83, 0x91,
0x88, 0x8e, 0x50, 0x00, 0x00, 0x00, 0x00, 0x92, 0x84, 0x84, 0x8b, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x83, 0x84, 0x96, 0x86, 0x8e, 0x8d, 0x86, 0x50, 0x00, 0x00, 0x00, 0x86, 0x91, 0x88,
0x8c, 0x84, 0x91, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x94, 0x8a, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x92, 0x87, 0x84, 0x8b, 0x8b, 0x83, 0x84, 0x91, 0x50, 0x00, 0x00, 0x82, 0x8b,
0x8e, 0x98, 0x92, 0x93, 0x84, 0x91, 0x50, 0x00, 0x00, 0x86, 0x80, 0x92, 0x93, 0x8b, 0x98, 0x50,
0x00, 0x00, 0x00, 0x00, 0x87, 0x80, 0x94, 0x8d, 0x93, 0x84, 0x91, 0x50, 0x00, 0x00, 0x00, 0x86,
0x84, 0x8d, 0x86, 0x80, 0x91, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x8d, 0x88, 0x97, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x91, 0x8e, 0x96, 0x99, 0x84, 0x84, 0x50, 0x00, 0x00, 0x00,
0x87, 0x98, 0x8f, 0x8d, 0x8e, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x91, 0x80, 0x81, 0x81,
0x98, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x88, 0x8d, 0x86, 0x8b, 0x84, 0x91, 0x50, 0x00, 0x00,
0x00, 0x95, 0x8e, 0x8b, 0x93, 0x8e, 0x91, 0x81, 0x50, 0x00, 0x00, 0x00, 0x84, 0x8b, 0x84, 0x82,
0x93, 0x91, 0x8e, 0x83, 0x84, 0x50, 0x00, 0x84, 0x97, 0x84, 0x86, 0x86, 0x82, 0x94, 0x93, 0x84,
0x50, 0x00, 0x84, 0x97, 0x84, 0x86, 0x86, 0x94, 0x93, 0x8e, 0x91, 0x50, 0x00, 0x82, 0x94, 0x81,
0x8e, 0x8d, 0x84, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x80, 0x91, 0x8e, 0x96, 0x80, 0x8a, 0x50,
0x00, 0x00, 0x00, 0x87, 0x88, 0x93, 0x8c, 0x8e, 0x8d, 0x8b, 0x84, 0x84, 0x50, 0x00, 0x87, 0x88,
0x93, 0x8c, 0x8e, 0x8d, 0x82, 0x87, 0x80, 0x8d, 0x50, 0x8b, 0x88, 0x82, 0x8a, 0x88, 0x93, 0x94,
0x8d, 0x86, 0x50, 0x00, 0x8a, 0x8e, 0x85, 0x85, 0x88, 0x8d, 0x86, 0x50, 0x00, 0x00, 0x00, 0x96,
0x84, 0x84, 0x99, 0x88, 0x8d, 0x86, 0x50, 0x00, 0x00, 0x00, 0x91, 0x87, 0x98, 0x87, 0x8e, 0x91,
0x8d, 0x50, 0x00, 0x00, 0x00, 0x91, 0x87, 0x98, 0x83, 0x8e, 0x8d, 0x50, 0x00, 0x00, 0x00, 0x00,
0x82, 0x87, 0x80, 0x8d, 0x92, 0x84, 0x98, 0x50, 0x00, 0x00, 0x00, 0x93, 0x80, 0x8d, 0x86, 0x84,
0x8b, 0x80, 0x50, 0x00, 0x00, 0x00, 0x8a, 0x80, 0x8d, 0x86, 0x80, 0x92, 0x8a, 0x87, 0x80, 0x8d,
0x50, 0x87, 0x8e, 0x91, 0x92, 0x84, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x92, 0x84, 0x80, 0x83,
0x91, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x86, 0x8e, 0x8b, 0x83, 0x84, 0x84, 0x8d, 0x50, 0x00,
0x00, 0x00, 0x92, 0x84, 0x80, 0x8a, 0x88, 0x8d, 0x86, 0x50, 0x00, 0x00, 0x00, 0x92, 0x93, 0x80,
0x91, 0x98, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x92, 0x93, 0x80, 0x91, 0x8c, 0x88, 0x84, 0x50,
0x00, 0x00, 0x00, 0x8c, 0x91, 0xe8, 0x8c, 0x88, 0x8c, 0x84, 0x50, 0x00, 0x00, 0x00, 0x92, 0x82,
0x98, 0x93, 0x87, 0x84, 0x91, 0x50, 0x00, 0x00, 0x00, 0x89, 0x98, 0x8d, 0x97, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x84, 0x8b, 0x84, 0x82, 0x93, 0x80, 0x81, 0x94, 0x99, 0x99, 0x50, 0x8c,
0x80, 0x86, 0x8c, 0x80, 0x91, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x88, 0x8d, 0x92, 0x88, 0x91,
0x50, 0x00, 0x00, 0x00, 0x00, 0x93, 0x80, 0x94, 0x91, 0x8e, 0x92, 0x50, 0x00, 0x00, 0x00, 0x00,
0x8c, 0x80, 0x86, 0x88, 0x8a, 0x80, 0x91, 0x8f, 0x50, 0x00, 0x00, 0x86, 0x98, 0x80, 0x91, 0x80,
0x83, 0x8e, 0x92, 0x50, 0x00, 0x00, 0x8b, 0x80, 0x8f, 0x91, 0x80, 0x92, 0x50, 0x00, 0x00, 0x00,
0x00, 0x83, 0x88, 0x93, 0x93, 0x8e, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x84, 0x95, 0x84,
0x84, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x80, 0x8f, 0x8e, 0x91, 0x84, 0x8e, 0x8d, 0x50,
0x00, 0x00, 0x89, 0x8e, 0x8b, 0x93, 0x84, 0x8e, 0x8d, 0x50, 0x00, 0x00, 0x00, 0x85, 0x8b, 0x80,
0x91, 0x84, 0x8e, 0x8d, 0x50, 0x00, 0x00, 0x00, 0x8f, 0x8e, 0x91, 0x98, 0x86, 0x8e, 0x8d, 0x50,
0x00, 0x00, 0x00, 0x8e, 0x8c, 0x80, 0x8d, 0x98, 0x93, 0x84, 0x50, 0x00, 0x00, 0x00, 0x8e, 0x8c,
0x80, 0x92, 0x93, 0x80, 0x91, 0x50, 0x00, 0x00, 0x00, 0x8a, 0x80, 0x81, 0x94, 0x93, 0x8e, 0x50,
0x00, 0x00, 0x00, 0x00, 0x8a, 0x80, 0x81, 0x94, 0x93, 0x8e, 0x8f, 0x92, 0x50, 0x00, 0x00, 0x80,
0x84, 0x91, 0x8e, 0x83, 0x80, 0x82, 0x93, 0x98, 0x8b, 0x50, 0x92, 0x8d, 0x8e, 0x91, 0x8b, 0x80,
0x97, 0x50, 0x00, 0x00, 0x00, 0x80, 0x91, 0x93, 0x88, 0x82, 0x94, 0x8d, 0x8e, 0x50, 0x00, 0x00,
0x99, 0x80, 0x8f, 0x83, 0x8e, 0x92, 0x50, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x8e, 0x8b, 0x93, 0x91,
0x84, 0x92, 0x50, 0x00, 0x00, 0x00, 0x83, 0x91, 0x80, 0x93, 0x88, 0x8d, 0x88, 0x50, 0x00, 0x00,
0x00, 0x83, 0x91, 0x80, 0x86, 0x8e, 0x8d, 0x80, 0x88, 0x91, 0x50, 0x00, 0x83, 0x91, 0x80, 0x86,
0x8e, 0x8d, 0x88, 0x93, 0x84, 0x50, 0x00, 0x8c, 0x84, 0x96, 0x93, 0x96, 0x8e, 0x50, 0x00, 0x00,
0x00, 0x00, 0x8c, 0x84, 0x96, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//1661 Byte Array of Data containing Encoded Japanese Pokemon Names (11 Bytes Each, although technically just 6)
const unsigned char japanesePokemonNameData[] PROGMEM = {
0x9b, 0x8b, 0x06, 0x0f, 0x97, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9b, 0x8b, 0x06, 0x8e, 0x82,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9b, 0x8b, 0x06, 0x19, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x9a, 0x93, 0x85, 0x08, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x0a, 0xe3, 0x13,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x0a, 0xe3, 0x13, 0xab, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0d, 0x95, 0x05, 0xa0, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0xa0, 0xe3,
0xa6, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0xa0, 0xac, 0x87, 0x8c, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x86, 0xad, 0x8f, 0x41, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0xa5,
0xab, 0x8d, 0xa6, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x8f, 0x9b, 0xd8, 0xe3, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1a, 0xe3, 0x13, 0xa6, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89,
0x87, 0xe3, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x41, 0x80, 0xe3, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0xac, 0x43, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x41, 0x0b, 0xaf, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x0b, 0xaf, 0xac, 0x93,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0xa5, 0xac, 0x8f, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xa5, 0xac, 0x8f, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x95, 0x8c, 0x0c,
0xa0, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x95, 0x13, 0xd8, 0xa6, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xe3, 0x1c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe3, 0x1c,
0xac, 0x87, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x85, 0x90, 0xae, 0x82, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0xa5, 0x81, 0x90, 0xae, 0x82, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0xab,
0x13, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0xab, 0x13, 0x40, 0xab, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x95, 0x13, 0xa5, 0xab, 0xf5, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95,
0x13, 0xd8, 0xe3, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x13, 0x87, 0x81, 0xab, 0x50,
0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x13, 0xa5, 0xab, 0xef, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x95, 0x13, 0xd8, 0xe3, 0x98, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x13, 0x86, 0xab, 0x07,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xac, 0x41, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x41, 0x87, 0x8b, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0x89, 0xab, 0x50,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xae, 0x82, 0x89, 0xab, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x42, 0xd8, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x87, 0xd8,
0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x19, 0xac, 0x93, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x09, 0xa6, 0x19, 0xac, 0x93, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x0e,
0x98, 0x87, 0x8a, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x8a, 0x81, 0x99, 0x94, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0xa5, 0x9b, 0xa7, 0x8b, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
0xa5, 0x8c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xa5, 0x8d, 0x87, 0x93, 0x50,
0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0xab, 0x40, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xa1, 0xa6, 0x9b, 0xf4, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xb0, 0x07, 0x0f, 0x50,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x07, 0x93, 0xd8, 0x84, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x95, 0xad, 0xe3, 0x8c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0xa6, 0x8b, 0x80,
0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x0f, 0xac, 0x87, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x09, 0xa6, 0x0f, 0xac, 0x87, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0xab, 0x86,
0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x89, 0xd8, 0x0a, 0xa6, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x05, 0xe3, 0x12, 0xb0, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x81,
0xab, 0x12, 0xb0, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0xaf, 0xa8, 0xa1, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x95, 0xaf, 0xa8, 0x0e, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95,
0xaf, 0xa8, 0x1c, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xe3, 0x8b, 0xb0, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa3, 0xab, 0x08, 0xa5, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x9b, 0xe3, 0x12, 0xb0, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa9, 0xab, 0xd8, 0x86, 0xe3,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xe3, 0xd8, 0x86, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x85, 0x81, 0xd8, 0x86, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0x0f, 0x91, 0x1c,
0x9e, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x91, 0x13, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x82, 0x91, 0x1c, 0xac, 0x93, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x98, 0x87,
0xa5, 0x08, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x87, 0x87, 0xa5, 0x08, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x81, 0x8b, 0x91, 0x1b, 0x92, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xa8,
0xe3, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xa8, 0xe3, 0x95, 0xad, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x43, 0x95, 0xe3, 0x8f, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0xad, 0xa8, 0xac, 0x42, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa2, 0x13, 0xab, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xa2, 0x13, 0xa5, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x89, 0x81, 0xa6, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0x80, 0x89, 0x81, 0xa6,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0xa1, 0x97, 0x06, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x13, 0xe3, 0x13, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xe3, 0x13, 0xd8,
0x84, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x82, 0xa9, 0x82, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0b, 0xae, 0x09, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x93, 0x3d,
0x8f, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x93, 0x3d, 0x93, 0xab, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x8b, 0xeb, 0xa6, 0x0f, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xa6,
0x8b, 0xeb, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xe3, 0x8c, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x09, 0xe3, 0x8c, 0x93, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0xab, 0x05, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0xa9, 0xe3, 0x87, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0xd8, 0xe3, 0x42, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x8c, 0xd8, 0xe3, 0x40, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0xa5, 0x1b, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86, 0xab, 0x07, 0xa5, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1a, 0xd8, 0xd8, 0x0f, 0x9d, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d, 0xa6, 0x9d, 0x81,
0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x9d, 0x8f, 0x9d, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x94, 0xac, 0x8b, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0xa5, 0x85,
0xa5, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xa5, 0x05, 0xa5, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x8a, 0xa9, 0x9f, 0xa5, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x1a,
0xa9, 0xa5, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0xa8, 0xd8, 0xab, 0x05, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x13, 0x05, 0xe3, 0x8c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9d,
0x8f, 0x13, 0x05, 0x8c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x81, 0x9c, 0xe3, 0xab, 0x50,
0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x81, 0x13, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xa5, 0xac, 0x86, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa1, 0xab, 0x0b, 0xad, 0xa5,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xa6, 0xe3, 0xa5, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x8f, 0xac, 0x91, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0xe3, 0x13, 0xa5,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x8a, 0x86, 0xab, 0x93, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x0c, 0x9d, 0x84, 0x82, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0x93, 0x12,
0x9d, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x8f, 0xe3, 0x9e, 0xe3, 0x50, 0x00, 0x00,
0x00, 0x00, 0x00, 0x19, 0xd8, 0xa2, 0xe3, 0x13, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x93,
0xa5, 0x81, 0x87, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6, 0xe3, 0x0b, 0xae, 0xa5, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x83, 0xa7, 0x1b, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b,
0xe3, 0x19, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x81, 0xa8, 0x8c, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0xab, 0x8f, 0xa8, 0x8c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x89, 0x81, 0x86, 0xab, 0x07, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xad, 0xa5, 0x13, 0x8c,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x42, 0xa5, 0x8c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xa0, 0x8f, 0xa1, 0xab, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0xe3, 0x1b, 0x81,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0xad, 0xa9, 0xe3, 0x0c, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x8a, 0xab, 0x0f, 0xe3, 0x8c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0xe3, 0x8c,
0x8f, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0xd8, 0x09, 0xab, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x84, 0x9f, 0x94, 0x81, 0x93, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x9f,
0x8c, 0x8f, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x1b, 0x93, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x85, 0x1b, 0x93, 0x42, 0x8c, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42,
0x92, 0xa5, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x1a, 0x09, 0xab, 0x50, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x9b, 0xd8, 0xe3, 0x0a, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x8a, 0xab, 0x0f, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9b, 0xe9, 0x81, 0xa2, 0xe3,
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0x95, 0xd8, 0xae, 0x82, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x99, 0x87, 0xd8, 0xae, 0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x81, 0xd8, 0xae,
0xe3, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0xae, 0x82, 0x91, 0xe3, 0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x9e, 0xae, 0x82, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
//Array to get the Pokedex # from the Species ID. Subtract 1 to get the index number within the array.
signed short speciesIDToPokedexNumberArray[] = { -1,112,115,32,35,21,100,34,80,2,103,108,102,88,94,29,31,104,111,131,59,151,130,90,72,92,123,120,9,127,114,-1,-1,58,95,22,16,79,64,75,113,67,122,106,107,24,47,54,96,76,-1,126,-1,125,82,109,-1,56,86,50,128,-1,-1,-1,83,48,149,-1,-1,-1,84,60,124,146,144,145,132,52,98,-1,-1,-1,37,38,25,26,-1,-1,147,148,140,141,116,117,-1,-1,27,28,138,139,39,40,133,136,135,134,66,41,23,46,61,62,13,14,15,-1,85,57,51,49,87,-1,-1,10,11,12,68,-1,55,97,42,150,143,129,-1,-1,89,-1,99,91,-1,101,36,110,53,105,-1,93,63,65,17,18,121,1,3,73,-1,118,119,-1,-1,-1,-1,77,78,19,20,33,30,74,137,142,-1,81,-1,-1,4,7,5,8,6,-1,-1,-1,-1,43,44,45,69,70,71 };
//Stores the TrainerIDs associated with each Gameboy.
unsigned short gameboyATrainerID = 24879;
unsigned short gameboyBTrainerID = 16987;
//Stores all of the trainer IDs that can participate in the trade.
unsigned short trainerIDList[] = {24879, 16987, 56838, 63599};
//Stores the encoded names that will be used for Pokemon Traded from Gameboy A(ENG) to Gameboy B(JPN).
unsigned char gameboyAToBEncodedTrainerNames[][6] = {
{ 0x9D, 0xAC, 0x87, 0x50, 0x00, 0x00 }, //マック -> MAKKU
{ 0x8A, 0x81, 0x93, 0x50, 0x00, 0x00 }, //サイト -> SAITO
{ 0x93, 0xA7, 0xE3, 0x94, 0xE3, 0x50 }, //トレーナー -> TOREENAA/TRAINER
{ 0x9D, 0xAC, 0x87, 0x50, 0x00, 0x00 } //マック -> MAKKU
};
//Stores the encoded names that will be used for Pokemon Traded from Gameboy B(ENG) to Gameboy A(JPN).
unsigned char gameboyBToAEncodedTrainerNames[][11] = {
{ 0x8C, 0x80, 0x82, 0x8A, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //MACK
{ 0x92, 0x80, 0x88, 0x93, 0x8E, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00 }, //SAITO
{ 0x93, 0x91, 0x80, 0x88, 0x8D, 0x84, 0x91, 0x50, 0x00, 0x00, 0x00 }, //TRAINER
{ 0x8C, 0x80, 0x82, 0x8A, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //MACK
};
//Stores the party data sent from each Gameboy.
unsigned char gameboyAPartyData[7];
unsigned char gameboyBPartyData[7];
unsigned char gameboyAPartyDataPos = 0;
unsigned char gameboyBPartyDataPos = 0;
//Stores the Trainer IDs of the pokemon from each Gameboy.
unsigned char gameboyAPokemonTrainerIDs[12];
unsigned char gameboyBPokemonTrainerIDs[12];
unsigned char gameboyAPokemonTrainerIDPos = 0;
unsigned char gameboyBPokemonTrainerIDPos = 0;
unsigned char gameboyACurrentPokemonTrainerIDIndex = 0;
unsigned char gameboyBCurrentPokemonTrainerIDIndex = 0;
/*GLOBAL VARIABLES*/
//Stores the bytes read from each gameboy.
unsigned char linkIncomingByteA = 0xFE;
unsigned char linkIncomingByteB = 0xFE;
//Stores the bytes that need to be sent to each gameboy.
unsigned char linkOutgoingByteA = 0xFE;
unsigned char lastLinkOutgoingByteA = 0xFE;
unsigned char linkOutgoingByteB = 0xFE;
unsigned char lastLinkOutgoingByteB = 0xFE;
//Stores the last exchanged bytes triggered by a State of Type 1.
unsigned char lastExchangedByteToA = 0x0;
unsigned char lastExchangedByteToB = 0x0;
//Buffers that are used to store translated data to send to the Gameboys.
unsigned char translatedIncomingBufferDataA[32];
unsigned char translatedIncomingBufferDataB[32];
//Stores the amount of translated bytes present within the buffers.
unsigned char translatedIncomingBufferALength = 0;
unsigned char translatedIncomingBufferBLength = 0;
//Stores the position of the byte to send from within the buffer.
unsigned char translatedIncomingBufferAPosition = 0;
unsigned char translatedIncomingBufferBPosition = 0;
//Stores whether a translation exchange point has been reached.
bool translationPointReachedForGameboyA = false;
bool translationPointReachedForGameboyB = false;
//Stores the amount of times to re-transmit a particular byte.
unsigned char linkOutgoingByteARepeatCounter = 0;
unsigned char linkOutgoingByteBRepeatCounter = 0;
//Booleans that control whether transmission with a particular gameboy is allowed or not.
bool enableTransmission = false;
bool enableTransmissionA = true;
bool enableTransmissionB = true;
//A flag used to disable transmission after a clock pulse.
bool disableTransmissionAAfterPulse = false;
bool disableTransmissionBAfterPulse = false;
bool enableTransmissionAAfterPulse = false;
bool enableTransmissionBAfterPulse = false;
//Stores the amount of bytes that was exchanged with the Gameboys.
unsigned short transferredByteCounterA = 0;
unsigned short transferredByteCounterB = 0;
//Whether transmission has been temporarily disabled between a particular Gameboy.
bool transmissionATemporarilyDisabled = false;
bool transmissionBTemporarilyDisabled = false;
//Stores the time when transmission was temporarily disabled and how long it should be disabled.
unsigned long transmissionATemporaryDisabledTime = 0;
unsigned long transmissionBTemporaryDisabledTime = 0;
unsigned long transmissionATemporaryDisableDuration = 0;
unsigned long transmissionBTemporaryDisableDuration = 0;
//Stores all of the states that drive the communication.
LinkState linkStates[STATE_COUNT];
//The index of the active state.
unsigned int activeLinkStateIndexA = 0;
unsigned int activeLinkStateIndexB = 0;
//Used to keep track of the microseconds that have passed.
unsigned long time = 0;
//Obtain the indices of each gameboy.
signed int gameboyATrainerIndex = 0;
signed int gameboyBTrainerIndex = 0;
//Debugging Variables
bool enableDebugOutput = false;
char charBuffer[64];
//Obtains the index of a particular trainer, by ID
signed int getTrainerIndexFromID(unsigned short trainerID){
for(signed int i = 0; i < TRAINER_ID_COUNT; i++){
if(trainerIDList[i] == trainerID){
return i;
}
}
return -1;
}
void setup() {
//Set the serial output speed.
Serial.begin(9600);
//Set the Input and Output pins.
pinMode(DMG_GAMEBOY_A_LINK_CLK, OUTPUT);
pinMode(DMG_GAMEBOY_B_LINK_CLK, OUTPUT);
pinMode(DMG_GAMEBOY_A_LINK_SIN, OUTPUT);
pinMode(DMG_GAMEBOY_B_LINK_SOUT, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(DMG_GAMEBOY_A_LINK_SOUT, INPUT);
pinMode(DMG_GAMEBOY_B_LINK_SIN, INPUT);
pinMode(DMG_GAMEBOY_B_LINK_SIN, INPUT);
//pinMode(START_TRANSMISSION_BUTTON_PIN, INPUT);
//Set the defauly states of the signals.
digitalWrite(DMG_GAMEBOY_A_LINK_CLK, HIGH);
digitalWrite(DMG_GAMEBOY_B_LINK_CLK, HIGH);
digitalWrite(DMG_GAMEBOY_A_LINK_SIN, LOW);
digitalWrite(DMG_GAMEBOY_B_LINK_SOUT, LOW);
/*STATE DATA SETUP*/
//State 0: The state where the Arduino waits for connections from each Gameboy.
linkStates[0].stateType = 0;
linkStates[0].targetByte = 0x60;
linkStates[0].sendsByteByDefault = true;
linkStates[0].defaultResponseByte = 0x1;
//State 1: The state that precedes the menu where the options are displayed. 0x60 is exchanged between the Gameboys and the Arduino.
linkStates[1].stateType = 0;
linkStates[1].targetByte = 0x60;
linkStates[1].respondsWithByte = true;
linkStates[1].responseByte = 0x60;
linkStates[1].sendsByteByDefault = true;
linkStates[1].defaultResponseByte = 0x60;
linkStates[1].transmissionDelayTime = 600;
//State 2: The state where the options are being presented to each gameboy. 0xD4 indicates the intention to enter the Trade Center. Send this to each Gameboy and wait for each Gameboy to send 0xD0. Repeat to make sure the Gameboy gets the byte.
linkStates[2].stateType = 0;
linkStates[2].targetByte = 0xD0;
linkStates[2].respondsWithByte = true;
linkStates[2].responseByte = 0xD4;
linkStates[2].responseByteRepeatCount = 3;
linkStates[2].sendsByteByDefault = false;
linkStates[2].transmissionDelayTime = 600;
//State 3: The state where each Gameboy is in the Trade Center and the Arduino is waiting for the Trade to begin. 0x60 indicates that the trade is beginning.
linkStates[3].stateType = 0;
linkStates[3].targetByte = 0x60;
linkStates[3].respondsWithByte = true;
linkStates[3].responseByte = 0x60;
linkStates[3].responseByteRepeatCount = 5;
linkStates[3].sendsByteByDefault = true;
linkStates[3].defaultResponseByte = 0xFE;
linkStates[3].transmissionDelayTime = 100;
//State 4: The state where the Arduino waits for 16 consecutive Preamble Bytes(0xFD) from each gameboy, and then responds with the Preamble Byte.
linkStates[4].stateType = 0;
linkStates[4].targetByte = 0xFD;
linkStates[4].targetByteOccurrenceCount = 16;
linkStates[4].respondsWithByteUponTransition = true;
linkStates[4].responseByte = 0xFD;
linkStates[4].sendsByteByDefault = false;
linkStates[4].transmissionDelayTime = 50;
//State 5: The state where the Arduino waits for the Preamble Byte(0xFD) from each gameboy, and then responds with the Preamble Byte. Just another countermeasure to make sure the Gameboy gets the byte.
linkStates[5].stateType = 0;
linkStates[5].targetByte = 0xFD;
linkStates[5].respondsWithByte = true;
linkStates[5].responseByte = 0xFD;
linkStates[5].sendsByteByDefault = false;
//State 6: The state where the Arduino waits for the Gameboys to send anything but the Preamble Byte, signaling the start of data.
linkStates[6].stateType = 1;
linkStates[6].exchangesBytes = true;
linkStates[6].targetByte = 0xFD;
linkStates[6].inverseCondition = true;
linkStates[6].sendsByteByDefault = false;
//State 7: The state where the Arduino transmits Random Number data between Gameboy A and Gameboy B.
linkStates[7].stateType = 2;
linkStates[7].bufferIndex = 0;
linkStates[7].bufferASize = 10;//17 if Preamble Bytes were included, but we are skipping over them.
linkStates[7].bufferBSize = 10;//17 if Preamble Bytes were included, but we are skipping over them.
linkStates[7].sendsByteByDefault = false;
//State 4: The state where the Arduino waits for 16 consecutive Preamble Bytes(0xFD) from each gameboy, and then responds with the Preamble Byte.
linkStates[8].stateType = 0;
linkStates[8].targetByte = 0xFD;
linkStates[8].targetByteOccurrenceCount = 16;
linkStates[8].respondsWithByteUponTransition = true;
linkStates[8].responseByte = 0xFD;
linkStates[8].sendsByteByDefault = false;
linkStates[8].transmissionDelayTime = 50;
//State 9: The state where the Arduino waits for the Preamble Byte(0xFD) from each gameboy, and then responds with the Preamble Byte.
linkStates[9].stateType = 0;
linkStates[9].targetByte = 0xFD;
linkStates[9].respondsWithByte = true;
linkStates[9].responseByte = 0xFD;
linkStates[9].sendsByteByDefault = false;
//State 10: The state where the Arduino waits for the Gameboys to send anything but the Preamble Byte, signaling the start of data.
linkStates[10].stateType = 1;
linkStates[10].targetByte = 0xFD;
linkStates[10].inverseCondition = true;
linkStates[10].sendsByteByDefault = false;
//State 11: The state where the Arduino transmits the Trainer Name and Party Pokemon data between Gameboy A and Gameboy B.
linkStates[11].stateType = 2;
linkStates[11].bufferIndex = 1;
linkStates[11].bufferASize = 418; //424 if Preamble Bytes were included, but we are skipping over them.
linkStates[11].bufferBSize = 353; //359 if Preamble Bytes were included, but we are skipping over them.
linkStates[11].sendsByteByDefault = false;
//State 4: The state where the Arduino waits for 16 consecutive Preamble Bytes(0xFD) from each gameboy, and then responds with the Preamble Byte.
linkStates[12].stateType = 0;
linkStates[12].targetByte = 0xFD;
linkStates[12].targetByteOccurrenceCount = 16;
linkStates[12].respondsWithByteUponTransition = true;
linkStates[12].responseByte = 0xFD;
linkStates[12].sendsByteByDefault = false;
linkStates[12].transmissionDelayTime = 50;
//State 13: The state where the Arduino waits for the Preamble Byte(0xFD) from each gameboy, and then responds with the Preamble Byte.
linkStates[13].stateType = 0;
linkStates[13].targetByte = 0xFD;
linkStates[13].respondsWithByte = true;
linkStates[13].responseByte = 0xFD;
linkStates[13].sendsByteByDefault = false;
//State 14: The state where the Arduino waits for the Gameboys to send anything but the Preamble Byte, signaling the start of data.
linkStates[14].stateType = 1;
linkStates[14].exchangesBytes = true;
linkStates[14].targetByte = 0xFD;
linkStates[14].inverseCondition = true;
linkStates[14].sendsByteByDefault = false;
//State 15: The state where the Arduino transmits patch list data between Gameboy A and Gameboy B.
linkStates[15].stateType = 2;
linkStates[15].bufferIndex = 2;
linkStates[15].bufferASize = 197; //200 if Preamble Bytes were included, but we are skipping over them.
linkStates[15].bufferBSize = 197; //200 if Preamble Bytes were included, but we are skipping over them.
linkStates[15].sendsByteByDefault = false;
linkStates[15].transmissionDelayTime = 500;
//State 16: The state where the Arduino waits for the Gameboys to select the pokemon they'd like to trade.
linkStates[16].stateType = 1;
linkStates[16].exchangesBytes = true;
linkStates[16].targetByteUsesRange = true;
linkStates[16].targetByte = 0x60;
linkStates[16].targetByteEnd = 0x65;
linkStates[16].sendsByteByDefault = false;
//State 17: The state where the Arduino waits for the gameboy to send 0x0, following the trade selection.
linkStates[17].stateType = 0;
linkStates[17].targetByte = 0x0;
linkStates[17].sendsByteByDefault = false;
//State 18: The state where the Arduino waits for the Gameboys to send 0x62 to finalize the trade, and it responds back with 0x62.
linkStates[18].stateType = 1;
linkStates[18].exchangesBytes = true;
linkStates[18].targetByte = 0x62;
linkStates[18].sendsByteByDefault = false;
//State 19: The state where the Arduino waits for a while as the trade animation occurs. Just to make the clock stop for a while, as no communication happens during the trade animation.
linkStates[19].stateType = 4;
linkStates[19].transmissionDelayTime = 40000;
linkStates[19].sendsByteByDefault = false;
//State 19: The state where 0x62 is sent to the Gameboys to complete the trade.
linkStates[20].stateType = 0;
linkStates[20].targetByte = 0xFD;
linkStates[20].defaultResponseByte = 0x62;
//State 21: The state where the Arduino waits for the Gameboys to both send the 0xFD, to make sure the gameboys stay sync'd, even in the case of evolution.
linkStates[21].stateType = 1;
linkStates[21].targetByte = 0xFD;
linkStates[21].sendsByteByDefault = false;
//State 22: Jump back to state 4 to re-exchange data with the Gameboys.
linkStates[22].stateType = 3;
linkStates[22].sendsByteByDefault = false;
linkStates[22].jumpStateIndex = 4;
//State 23: The state that gets manually triggered whenever the Gameboy cancels the trade.
linkStates[23].stateType = 0;
linkStates[23].targetByte = 0x0;
linkStates[23].sendsByteByDefault = true;
linkStates[23].defaultResponseByte = 0x6F;
//State 24: The state where the Arduino waits for the Gameboys to send 0x6F, which is what gets sent whenever a player cancels the trade session and starts a new one.
linkStates[24].stateType = 0;
linkStates[24].targetByte = 0x6F;
linkStates[24].respondsWithByte = true;
linkStates[24].responseByte = 0x60;
linkStates[24].responseByteRepeatCount = 5;
linkStates[24].sendsByteByDefault = true;
linkStates[24].defaultResponseByte = 0xFE;
linkStates[24].transmissionDelayTime = 100;
//State 25: Jump back to state 4 to re-exchange data with the Gameboys.
linkStates[25].stateType = 3;
linkStates[25].sendsByteByDefault = false;
linkStates[25].jumpStateIndex = 4;
//Obtain the indices of each gameboy.
gameboyATrainerIndex = getTrainerIndexFromID(gameboyATrainerID);
gameboyBTrainerIndex = getTrainerIndexFromID(gameboyBTrainerID);
//Give the user 15 seconds to make sure their gameboys are connected.
digitalWrite(LED_BUILTIN, LOW);
delay(15000);
digitalWrite(LED_BUILTIN, HIGH);
enableTransmission = true;
}
//Handles the logic associated with states.
void UpdateStates(unsigned int* activeLinkStateIndex){
//Set the output bytes if the active state responds with one by default.
if(linkStates[(*activeLinkStateIndex)].sendsByteByDefault){
if(!linkStates[(*activeLinkStateIndex)].useLastExchangedBytesAsDefaultResponseByte){
//STATE A
if(activeLinkStateIndex == &activeLinkStateIndexA){
linkOutgoingByteA = linkStates[(*activeLinkStateIndex)].defaultResponseByte;
}
//STATE B
else{
linkOutgoingByteB = linkStates[(*activeLinkStateIndex)].defaultResponseByte;
}
}else{
//STATE A
if(activeLinkStateIndex == &activeLinkStateIndexA){
linkOutgoingByteA = lastExchangedByteToA;
}
//STATE B
else{
linkOutgoingByteB = lastExchangedByteToB;
}
}
}
//Proceed if this is a state that waits on a particular byte.
if(linkStates[(*activeLinkStateIndex)].stateType == 0){
//Stores whether a target byte has been received that satisfies the condition.
bool targetByteSatisfiesCondition = false;
//Check to see if the byte received by Gameboy A matches that which is required by the state.
//STATE A
if(activeLinkStateIndex == &activeLinkStateIndexA){
if(linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterA > 0){
if(!linkStates[(*activeLinkStateIndex)].targetByteUsesRange){
if(linkIncomingByteA == linkStates[(*activeLinkStateIndex)].targetByte){
linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterA--;
targetByteSatisfiesCondition = true;
if(linkStates[(*activeLinkStateIndex)].respondsWithByte){
linkOutgoingByteA = linkStates[(*activeLinkStateIndex)].responseByte;
lastLinkOutgoingByteA = linkOutgoingByteA;
linkOutgoingByteARepeatCounter = linkStates[(*activeLinkStateIndex)].responseByteRepeatCount + 1;
}
}
}else{
if(linkIncomingByteA >= linkStates[(*activeLinkStateIndex)].targetByte && linkIncomingByteA <= linkStates[(*activeLinkStateIndex)].targetByteEnd){
linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterA--;
targetByteSatisfiesCondition = true;
if(linkStates[(*activeLinkStateIndex)].respondsWithByte){
linkOutgoingByteA = linkStates[(*activeLinkStateIndex)].responseByte;
lastLinkOutgoingByteA = linkOutgoingByteA;
linkOutgoingByteARepeatCounter = linkStates[(*activeLinkStateIndex)].responseByteRepeatCount + 1;
}
}
}
}
}
//STATE B
else{
//Check to see if the byte received by Gameboy A matches that which is required by the state.
if(linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterB > 0){
if(!linkStates[(*activeLinkStateIndex)].targetByteUsesRange){
if(linkIncomingByteB == linkStates[(*activeLinkStateIndex)].targetByte){
linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterB--;
targetByteSatisfiesCondition = true;
if(linkStates[(*activeLinkStateIndex)].respondsWithByte){
linkOutgoingByteB = linkStates[(*activeLinkStateIndex)].responseByte;
lastLinkOutgoingByteB = linkOutgoingByteB;
linkOutgoingByteBRepeatCounter = linkStates[(*activeLinkStateIndex)].responseByteRepeatCount + 1;
}
}
}else{
if(linkIncomingByteB >= linkStates[(*activeLinkStateIndex)].targetByte && linkIncomingByteB <= linkStates[(*activeLinkStateIndex)].targetByteEnd){
linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterB--;
targetByteSatisfiesCondition = true;
if(linkStates[(*activeLinkStateIndex)].respondsWithByte){
linkOutgoingByteB = linkStates[(*activeLinkStateIndex)].responseByte;
lastLinkOutgoingByteB = linkOutgoingByteB;
linkOutgoingByteBRepeatCounter = linkStates[(*activeLinkStateIndex)].responseByteRepeatCount + 1;
}
}
}
}
}
//Proceed if the counter resets itself upon unsatisfied conditions.
if(linkStates[(*activeLinkStateIndex)].resetOccurrenceCounterUponConflictingByte){
if(!targetByteSatisfiesCondition){
//STATE A
if(activeLinkStateIndex == &activeLinkStateIndexA){
linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterA = linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCount;
}
//STATE B
else{
linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterB = linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCount;
}
}
}
//Check to see if the next state needs to be transitioned to.
bool canProceedToNextState = false;
//STATE A
if(activeLinkStateIndex == &activeLinkStateIndexA){
if(linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterA == 0){
if(!linkStates[(*activeLinkStateIndex)].canOnlyProceedOnCertainByte){
canProceedToNextState = true;
}else{
if(linkIncomingByteA == linkStates[(*activeLinkStateIndex)].requiredByteToProceed){
canProceedToNextState = true;
}
}
}
}
//STATE B
else{
if(linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterB == 0){
if(!linkStates[(*activeLinkStateIndex)].canOnlyProceedOnCertainByte){
canProceedToNextState = true;
}else{
if(linkIncomingByteB == linkStates[(*activeLinkStateIndex)].requiredByteToProceed){
canProceedToNextState = true;
}
}
}
}
//If more bytes need to be sent, remain in this state.
if(activeLinkStateIndex == &activeLinkStateIndexA){
if(linkOutgoingByteARepeatCounter > 0){
canProceedToNextState = false;
}
}else{
if(linkOutgoingByteBRepeatCounter > 0){
canProceedToNextState = false;
}
}
//Proceed to the next state, if applicable.
if(canProceedToNextState){
//If another state exists, proceed.
if((*activeLinkStateIndex) < STATE_COUNT - 1){
//Send the byte whenever the state is transitioning, if applicable.
if(linkStates[(*activeLinkStateIndex)].respondsWithByteUponTransition){
//STATE A
if(activeLinkStateIndex == &activeLinkStateIndexA){
linkOutgoingByteA = linkStates[(*activeLinkStateIndex)].responseByte;
}
//STATE B
else{
linkOutgoingByteB = linkStates[(*activeLinkStateIndex)].responseByte;
}
}
//If the state temporarily disables transmission, apply it.
DelayTransmissionBasedOnActiveState(activeLinkStateIndex);
//Make the next state active.
(*activeLinkStateIndex)++;
//Reset the counters.
ResetStateByteCounters(activeLinkStateIndex);
//Debugging.
OutputStateChangeDebugString(activeLinkStateIndex);
}
}
}
//Proceed if this state waits for the data to start following the transmission of a particular byte.
else if(linkStates[(*activeLinkStateIndex)].stateType == 1){
//Prevent this state from performing any checks if data transmission is temporarily disabled.
if((activeLinkStateIndex == &activeLinkStateIndexA && !transmissionATemporarilyDisabled) || (activeLinkStateIndex == &activeLinkStateIndexB && !transmissionBTemporarilyDisabled)){
//Check for a specific byte or range of bytes. Once they are received, stop transmission with the corresponding gameboy.
bool conditionMet = false;
//STATE A
if(activeLinkStateIndex == &activeLinkStateIndexA){
if(!linkStates[(*activeLinkStateIndex)].targetByteUsesRange){
if(linkIncomingByteA == linkStates[(*activeLinkStateIndex)].targetByte){
conditionMet = true;
}
}else{
if(linkIncomingByteA >= linkStates[(*activeLinkStateIndex)].targetByte && linkIncomingByteA <= linkStates[(*activeLinkStateIndex)].targetByteEnd){
conditionMet = true;
}
}
//Apply the inverse, if applicable.
if(linkStates[(*activeLinkStateIndex)].inverseCondition){
conditionMet = !conditionMet;
}
//Disable the transmission upon the condition being met.
if(conditionMet){
enableTransmissionA = false;
}
}
//STATE B
else{
if(!linkStates[(*activeLinkStateIndex)].targetByteUsesRange){
if(linkIncomingByteB == linkStates[(*activeLinkStateIndex)].targetByte){
conditionMet = true;
}
}else{
if(linkIncomingByteB >= linkStates[(*activeLinkStateIndex)].targetByte && linkIncomingByteB <= linkStates[(*activeLinkStateIndex)].targetByteEnd){
conditionMet = true;
}
}
//Apply the inverse, if applicable.
if(linkStates[(*activeLinkStateIndex)].inverseCondition){
conditionMet = !conditionMet;
}
//Disable the transmission upon the condition being met.
if(conditionMet){
enableTransmissionB = false;
}
}
//Proceed to the next state once all transmissions are disabled.
if(!enableTransmissionA && !enableTransmissionB && !transmissionATemporarilyDisabled && !transmissionBTemporarilyDisabled){
//Only apply this logic when Gameboy B's states are being updated.
if(activeLinkStateIndex == &activeLinkStateIndexB){
if(linkStates[(*activeLinkStateIndex)].exchangesBytes){
//Set the outgoing bytes to exchange the data from each gameboy.
linkOutgoingByteA = linkIncomingByteB;
linkOutgoingByteB = linkIncomingByteA;
}
//Increment both A and B's states.
activeLinkStateIndexA++;
activeLinkStateIndexB++;
if(enableDebugOutput){
if(linkStates[activeLinkStateIndexA].bufferIndex != -1){
Serial.print("Proceeding to Read Buffer ");
Serial.println(linkStates[activeLinkStateIndexA].bufferIndex);
}else{
Serial.print("A and B Proceeding to State ");
Serial.println(activeLinkStateIndexA);
}
}
//Reset the byte counters.
linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterA = linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCount;
linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCounterB = linkStates[(*activeLinkStateIndex)].targetByteOccurrenceCount;
//Re-enable the transmission.
enableTransmissionA = true;
enableTransmissionB = true;
//Reset the byte counter.
transferredByteCounterA = 1;
transferredByteCounterB = 1;
//If this state starts the transmission of Buffer 1, copy the translated trainer names into the buffers to be transmitted.
if(linkStates[activeLinkStateIndexA].bufferIndex == 1){
//JAPANESE TRAINER NAME IN ENGLISH
for(signed int i = 0; i < 11; i++){
translatedIncomingBufferDataA[i] = gameboyBToAEncodedTrainerNames[gameboyBTrainerIndex][i];
}
translatedIncomingBufferALength = 11;
translatedIncomingBufferAPosition = 1;
//Copy the data into each of the buffers and set the variables to continue the transfer.
//ENGLISH TRAINER NAME IN JAPANESE
for(signed int i = 0; i < 6; i++){
translatedIncomingBufferDataB[i] = gameboyAToBEncodedTrainerNames[gameboyATrainerIndex][i];
}
translatedIncomingBufferBLength = 6;
translatedIncomingBufferBPosition = 1;
//Set the outgoing bytes to the first byte of the buffers.
linkOutgoingByteA = translatedIncomingBufferDataA[0];
linkOutgoingByteB = translatedIncomingBufferDataB[0];
//Reset some variables.
gameboyAPokemonTrainerIDPos = 0;
gameboyBPokemonTrainerIDPos = 0;
gameboyACurrentPokemonTrainerIDIndex = 0;
gameboyBCurrentPokemonTrainerIDIndex = 0;
gameboyAPartyDataPos = 0;
gameboyBPartyDataPos = 0;
}
}
}
}
}
//Proceed if this state translates and exchanges data between the Gameboys.
else if(linkStates[(*activeLinkStateIndex)].stateType == 2){
//Skip over the logic of this state if transmission is disabled.
bool skipLogic = false;
if(activeLinkStateIndex == &activeLinkStateIndexA && !enableTransmissionA){
skipLogic = true;
}
else if(activeLinkStateIndex == &activeLinkStateIndexB && !enableTransmissionB){
skipLogic = true;
}
if(!skipLogic){
//Obtain the transferred byte counter associated with this gameboy.
unsigned short* transferredByteCounterPtr = &transferredByteCounterA;
if(activeLinkStateIndex == &activeLinkStateIndexB){
transferredByteCounterPtr = &transferredByteCounterB;
}
//Record party information, if applicable.
if(linkStates[(*activeLinkStateIndex)].bufferIndex == 1){
if(activeLinkStateIndex == &activeLinkStateIndexA){
if(transferredByteCounterA >= 11 && transferredByteCounterA < 18){
if(gameboyAPartyDataPos < 7){
if(enableDebugOutput){
sprintf(charBuffer, "(A) Party Data Index %d: %02X\n", gameboyAPartyDataPos, linkIncomingByteA);
Serial.print(charBuffer);
}
gameboyAPartyData[gameboyAPartyDataPos] = linkIncomingByteA;
gameboyAPartyDataPos++;
}
}
}else{
if(transferredByteCounterB >= 6 && transferredByteCounterB < 13){
if(gameboyBPartyDataPos < 7){
if(enableDebugOutput){
sprintf(charBuffer, "(B) Party Data Index %d: %02X\n", gameboyBPartyDataPos, linkIncomingByteB);
Serial.print(charBuffer);
}
gameboyBPartyData[gameboyBPartyDataPos] = linkIncomingByteB;
gameboyBPartyDataPos++;
}
}
}
}
//Record Trainer ID information if applicable.
if(linkStates[(*activeLinkStateIndex)].bufferIndex == 1){
if(activeLinkStateIndex == &activeLinkStateIndexA){
if(transferredByteCounterA > 18 && transferredByteCounterA < 282){
if(((transferredByteCounterA - 19) % 44) == 12 || ((transferredByteCounterA - 19) % 44) == 13){
gameboyAPokemonTrainerIDs[gameboyAPokemonTrainerIDPos] = linkIncomingByteA;
gameboyAPokemonTrainerIDPos++;
}
}
}else{
if(transferredByteCounterB > 13 && transferredByteCounterB < 277){
if(((transferredByteCounterB - 14) % 44) == 12 || ((transferredByteCounterB - 14) % 44) == 13){
gameboyBPokemonTrainerIDs[gameboyBPokemonTrainerIDPos] = linkIncomingByteB;
gameboyBPokemonTrainerIDPos++;
}
}
}
}
//Handle intercepting the exchanging of bytes at specific offsets within the buffer.
//GAMEBOY A(USA)
if(activeLinkStateIndex == &activeLinkStateIndexA && !translationPointReachedForGameboyA){
//(0x11B, 0x126, 0x131, 0x13C, 0x147, 0x152) (OT Names)
if(transferredByteCounterA == 0x11B || transferredByteCounterA == 0x126 || transferredByteCounterA == 0x131 || transferredByteCounterA == 0x13C || transferredByteCounterA == 0x147 || transferredByteCounterA == 0x152){
//Mark the translation point as having been reached.
translationPointReachedForGameboyA = true;
//Disable transmission.
enableTransmissionA = false;
}
//(0x15D)(Pokemon A Nickname)
else if(transferredByteCounterA == 0x15D){
//Mark the translation point as having been reached.
translationPointReachedForGameboyA = true;
//Disable transmission.
enableTransmissionA = false;
}
//(0x168)(Pokemon B Nickname)
else if(transferredByteCounterA == 0x168){
//Mark the translation point as having been reached.
translationPointReachedForGameboyA = true;
//Disable transmission.
enableTransmissionA = false;
}
//(0x173)(Pokemon C Nickname)
else if(transferredByteCounterA == 0x173){
//Mark the translation point as having been reached.
translationPointReachedForGameboyA = true;
//Disable transmission.
enableTransmissionA = false;
}
//(0x17E)(Pokemon D Nickname)
else if(transferredByteCounterA == 0x17E){
//Mark the translation point as having been reached.
translationPointReachedForGameboyA = true;
//Disable transmission.
enableTransmissionA = false;
}
//(0x189)(Pokemon E Nickname)
else if(transferredByteCounterA == 0x189){
//Mark the translation point as having been reached.
translationPointReachedForGameboyA = true;
//Disable transmission.
enableTransmissionA = false;
}
//(0x194)(Pokemon F Nickname)
else if(transferredByteCounterA == 0x194){
//Mark the translation point as having been reached.
translationPointReachedForGameboyA = true;
//Disable transmission.
enableTransmissionA = false;
}
}
//GAMEBOY B(JPN)
else if(activeLinkStateIndex == &activeLinkStateIndexB && !translationPointReachedForGameboyB){
//(0x116, 0x11C, 0x122, 0x128, 12E, 134) (OT Names)
if(transferredByteCounterB == 0x116 || transferredByteCounterB == 0x11C || transferredByteCounterB == 0x122 || transferredByteCounterB == 0x128 || transferredByteCounterB == 0x12E || transferredByteCounterB == 0x134){
//Mark the translation point as having been reached.
translationPointReachedForGameboyB = true;
//Disable transmission.
enableTransmissionB = false;
}
//(0x13A)(Pokemon A Nickname)
else if(transferredByteCounterB == 0x13A){
//Mark the translation point as having been reached.
translationPointReachedForGameboyB = true;
//Disable transmission.
enableTransmissionB = false;
}
//(0x140)(Pokemon B Nickname)
else if(transferredByteCounterB == 0x140){
//Mark the translation point as having been reached.
translationPointReachedForGameboyB = true;
//Disable transmission.
enableTransmissionB = false;
}
//(0x146)(Pokemon C Nickname)
else if(transferredByteCounterB == 0x146){
//Mark the translation point as having been reached.
translationPointReachedForGameboyB = true;
//Disable transmission.
enableTransmissionB = false;
}
//(0x14C)(Pokemon D Nickname)
else if(transferredByteCounterB == 0x14C){
//Mark the translation point as having been reached.
translationPointReachedForGameboyB = true;
//Disable transmission.
enableTransmissionB = false;
}
//(0x152)(Pokemon E Nickname)