forked from pret/pokecrystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.asm
5160 lines (4793 loc) · 60.3 KB
/
mail.asm
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
; A library included as part of the Mobile Adapter GB SDK.
setcharmap ascii
SECTION "Mobile Adapter SDK Mail", ROMX
String_114000:
db "---", 0
String_114004:
db "CGB-AAAA-00", 0, 0
Unknown_114011:
dw String_114033
dw String_11403a
dw String_114043
dw String_11404e
dw String_114053
dw String_114058
dw String_114062
dw String_114074
dw String_11408d
dw String_11409f
dw String_1140b8
dw String_1140e6
dw String_114110
dw String_11413f
dw String_114160
dw String_114160
dw String_114163
String_114033:
db "From: ", 0
String_11403a:
db "Sender: ", 0
String_114043:
db "Reply-To: ", 0
String_11404e:
db "To: ", 0
String_114053:
db "Cc: ", 0
String_114058:
db "Subject: ", 0
String_114062:
db "MIME-Version: 1.0", 0
String_114074:
db "X-Game-title: XXXXXXXXXX", 0
String_11408d:
db "X-Game-code: CGB-", 0
String_11409f:
db "X-GBmail-type: exclusive", 0
String_1140b8:
db "Content-Type: text/plain; charset=iso-2022-jp", 0
String_1140e6:
db "Content-Type: multipart/mixed; boundary=\"", 0
String_114110:
db "Content-Type: Application/Octet-Stream; name=\"", 0
String_11413f:
db "Content-Transfer-Encoding:Base64", 0
String_114160:
db "--", 0
String_114163:
db ".", 0
Jumptable_114165:
dw Stubbed_Function114268
dw Function114269
dw Function11433c
dw Function1143b7
dw Function1144d1
dw Function114b55
dw Function114bbc
dw Function114cd9
dw Function114e62
dw Function1152b8
dw Function1154d4
dw Function1156cc
dw Function1159fb
Unknown_11417f:
dw .From
dw .Sender
dw .ReplyTo
dw .To
dw .CC
dw .Subject
dw .Date
dw .ContentType
dw .MimeVersion
dw .XMailer
dw .XGameTitle
dw .XGameCode
dw .XGBMailType
.From:
db "FROM:", 0
.Sender:
db "SENDER:", 0
.ReplyTo:
db "REPLY-TO:", 0
.To:
db "TO:", 0
.CC:
db "CC:", 0
.Subject:
db "SUBJECT:", 0
.Date:
db "DATE:", 0
.ContentType:
db "CONTENT-TYPE:", 0
.MimeVersion:
db "MIME-VERSION:", 0
.XMailer:
db "X-MAILER:", 0
.XGameTitle:
db "X-GAME-TITLE:", 0
.XGameCode:
db "X-GAME-CODE:", 0
.XGBMailType:
db "X-GBMAIL-TYPE:", 0
String_114218:
db "NAME=", 0
String_11421e:
db "MULTIPART", 0
String_114228:
db "BOUNDARY=", 0
String_114232:
db "=?ISO-2022-JP?B?", 0
Function114243::
ld a, SRAM_ENABLE
ld [MBC3SRamEnable], a
ldh a, [hSRAMBank]
push af ; if [$dc02] == 0, this is popped to pc.
push de
ld a, [$dc02]
add a
ld e, a
ld d, 0
ld hl, Jumptable_114165
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
pop de
jp hl
Function11425c:
ld [$dc02], a
pop af
ldh [hSRAMBank], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ret
Stubbed_Function114268:
ret
Function114269:
ld h, d
ld l, e
xor a
ld [$dc02], a
ld [$dc03], a
ld a, [hli]
ld [$dc00], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ld e, [hl]
inc hl
ld d, [hl]
inc hl
ld c, [hl]
inc hl
ld b, [hl]
.asm_114282
ld a, [de]
and a
jr z, .asm_1142a4
ld h, a
ld a, [$dc03]
and a
jr nz, .asm_114292
ld a, h
cp $80
jr nc, .asm_1142ae
.asm_114292
ld a, h
cp $d
jr z, .asm_1142bb
xor a
ld [$dc02], a
.asm_11429b
inc e
call z, Function114333
dec bc
ld a, b
or c
jr nz, .asm_114282
.asm_1142a4
ld a, [$dc03]
and a
jr nz, .asm_114303
ld b, $80
jr .asm_1142b0
.asm_1142ae
ld b, $81
.asm_1142b0
ld a, [$dc00]
ld c, a
ld a, $1
ld h, d
ld l, e
jp Function11425c
.asm_1142bb
and a
jr z, .asm_1142a4
inc e
call z, Function114333
dec bc
ld a, b
or c
jr z, .asm_1142a4
ld a, [de]
ld h, a
ld a, [$dc03]
and a
jr nz, .asm_1142d4
ld a, h
cp $80
jr nc, .asm_1142ae
.asm_1142d4
ld a, h
cp $a
jr nz, .asm_1142ae
ld a, [$dc03]
and a
jr nz, .asm_11430d
ld a, [$dc02]
and a
jr nz, .asm_114309
ld a, $1
ld [$dc02], a
inc e
call z, Function114333
dec bc
ld a, b
or c
jr z, .asm_1142a4
ld a, [de]
cp $20
jr z, .asm_11429b
cp $9
jr z, .asm_11429b
jr .asm_114282
.asm_1142fe
xor a
ld b, a
jp Function11425c
.asm_114303
xor a
ld b, $1
jp Function11425c
.asm_114309
xor a
ld [$dc02], a
.asm_11430d
ld a, [$dc02]
and a
jr nz, .asm_1142fe
ld a, $1
ld [$dc03], a
inc e
call z, Function114333
dec bc
ld a, b
or c
jr z, .asm_1142a4
ld a, [de]
and a
jp z, .asm_1142a4
cp $2e
jp nz, .asm_114282
ld a, $1
ld [$dc02], a
jp .asm_11429b
Function114333:
push bc
ld bc, $dc00
call Function115d80
pop bc
ret
Function11433c:
push de
ld h, d
ld l, e
ld c, [hl]
inc hl
ld e, [hl]
inc hl
ld d, [hl]
ld b, $b
call Function1143f3
cp $2
jr z, .asm_114358
and a
jr z, .asm_114360
pop hl
.asm_114351
xor a
ld b, $3
jp Function11425c
.asm_114357
pop hl
.asm_114358
pop hl
ld a, $1
ld b, $82
jp Function11425c
.asm_114360
ld a, h
ld [$dc03], a
pop hl
push bc
push de
ld c, [hl]
inc hl
ld e, [hl]
inc hl
ld d, [hl]
inc hl
ld b, $c
call Function1143f3
cp $2
jr z, .asm_114357
and a
jr z, .asm_114381
xor a
ld b, $2
pop hl
pop hl
jp Function11425c
.asm_114381
pop de
pop bc
ld a, [$dc03]
ld [$dc00], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
call Function114c0b
ld hl, String_114004
.asm_114394
ld de, $dc24
.asm_114397
ld a, [hli]
and a
jr z, .asm_1143ad
ld b, a
ld a, [de]
inc de
cp b
jr z, .asm_114397
.asm_1143a1
ld a, [hli]
and a
jr nz, .asm_1143a1
ld a, [hl]
and a
jr nz, .asm_114394
ld b, a
jp Function11425c
.asm_1143ad
ld a, [de]
and a
jr nz, .asm_114351
xor a
ld b, $1
jp Function11425c
Function1143b7:
ld a, [de]
ld b, a
inc de
ld a, [de]
ld c, a
inc de
ld a, [de]
ld h, a
inc de
ld a, [de]
inc de
push de
ld d, a
ld e, h
call Function1143f3
cp $2
jr z, .asm_1143eb
and a
jr nz, .asm_1143ed
ld a, h
pop hl
push af
ld a, [hli]
ld [wCurMapBGEventCount], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ld a, [hli]
ld h, [hl]
ld l, a
pop af
ld [hli], a
ld a, e
ld [hli], a
ld a, d
ld [hli], a
ld a, c
ld [hli], a
ld [hl], b
xor a
jp Function11425c
.asm_1143eb
ld b, $82
.asm_1143ed
ld a, $1
pop hl
jp Function11425c
Function1143f3:
call .asm_114412
and a
jr nz, .asm_11440d
ld a, $4
cp b
jr c, .asm_114407
jr z, .asm_114402
.asm_114400
xor a
ret
.asm_114402
ld a, $0
cp c
jr nc, .asm_114400
.asm_114407
lb bc, $4, $0
ld a, $2
ret
.asm_11440d
ld a, $1
ld b, $84
ret
.asm_114412:
ld a, c
ld [$dc00], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ld hl, Unknown_11417f
ld a, b
add a
ld c, a
ld b, 0
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
ld c, $0
jr .asm_11444a
.asm_11442b
ld a, [de]
and a
jp z, .asm_1144c2
inc e
call z, Function1144c8
cp "\r"
jr nz, .asm_11442b
ld a, [de]
inc e
call z, Function1144c8
cp "\n"
jr nz, .asm_11442b
ld a, [de]
cp "."
jr z, .asm_1144ae
cp "\r"
jr z, .asm_1144b8
.asm_11444a
ld a, [$dc00]
ld [$dc02], a
ld a, [de]
and a
jr z, .asm_1144c2
inc e
call z, Function1144c8
cp "a"
jr c, .asm_114462
cp "z" + 1
jr nc, .asm_114462
sub $20
.asm_114462
ld b, a
ld a, [hl]
and a
jr z, .asm_114476
cp b
jr nz, .asm_11446e
inc c
inc hl
jr .asm_11444a
.asm_11446e
ld a, c
and a
jr z, .asm_11442b
dec c
dec hl
jr .asm_11446e
.asm_114476
ld a, " "
cp b
jr z, .asm_114481
ld a, "\n"
cp b
jr z, .asm_114481
dec de
.asm_114481
ld h, d
ld l, e
ld bc, NULL
.asm_114486
ld a, [de]
and a
jr z, .asm_1144c2
inc bc
inc e
call z, Function1144c8
cp "\r"
jr nz, .asm_114486
ld a, [de]
inc bc
inc e
call z, Function1144c8
cp "\n"
jr nz, .asm_114486
ld a, [de]
cp " "
jr z, .asm_114486
cp "\t"
jr z, .asm_114486
ld d, h
ld e, l
ld a, [$dc02]
ld h, a
xor a
ret
.asm_1144ae
inc e
call z, Function1144c8
ld a, [de]
cp "\r"
jp nz, .asm_11442b
.asm_1144b8
inc e
call z, Function1144c8
ld a, [de]
cp "\n"
jp nz, .asm_11442b
.asm_1144c2
ld a, $0
ld [hl], a
ld a, $1
ret
Function1144c8:
push bc
ld bc, $dc00
call Function115d80
pop bc
ret
Function1144d1:
call Function114561
dec de
dec de
push de
inc de
inc de
inc de
inc hl
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hli], a
inc hl
ld a, [de]
ld [hld], a
dec de
ld a, [de]
ld [hl], a
xor a
ld [wDecoBigDoll], a
ld [$dc17], a
ld a, $2
ld [$dc0e], a
ld hl, $dc03
ld c, [hl]
inc hl
ld e, [hl]
inc hl
ld d, [hl]
call Function114576
cp $2
jr z, .asm_11455b
and a
jr z, .asm_114511
ld a, $1
ld [$dc0d], a
call Function1146fa
and a
jr nz, .asm_11455b
jr .asm_11451c
.asm_114511
call Function1146a4
and a
jr nz, .asm_11455b
ld a, $2
ld [$dc0d], a
.asm_11451c
pop hl
ld a, [hli]
ld [wCurMapBGEventCount], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ld e, [hl]
inc hl
ld d, [hl]
ld a, [$dc0d]
ld [de], a
ld b, $0
ld a, [wDecoBigDoll]
and a
jr z, .asm_114537
ld b, $1
.asm_114537
ld hl, $dc06
ld a, [hl]
ld [wCurMapBGEventCount], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ld hl, $dc09
ld e, [hl]
inc hl
ld d, [hl]
dec de
ld a, d
or e
jr z, .asm_114559
ld hl, wCurMapSceneScriptCount
ld e, [hl]
inc hl
ld d, [hl]
xor a
ld [de], a
jp Function11425c
.asm_114559
ld b, $83
.asm_11455b
pop hl
ld a, $1
jp Function11425c
Function114561:
ld hl, $dc03
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hli], a
inc de
ld a, [de]
ld [hl], a
ret
Function114576:
xor a
ld [wDecoBed], a
ld b, $7
call Function1143f3
cp $2
jr z, .asm_1145b6
and a
jr nz, .asm_1145b4
ld a, h
ld [$dc00], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
push hl
push de
push bc
ld hl, $dc24
call Function115d53
call Function1145c5
pop bc
pop de
pop hl
and a
jr z, .asm_1145bf
ld a, b
and a
jr nz, .asm_1145ba
ld a, h
ld [$dc00], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ld hl, String_114218
call Function114acf
.asm_1145b4
xor a
ret
.asm_1145b6
ld b, $82
jr .asm_1145bc
.asm_1145ba
ld b, $81
.asm_1145bc
ld a, $2
ret
.asm_1145bf
ld a, $1
ld [wDecoBed], a
ret
Function1145c5:
ld hl, $dc24
ld de, String_11421e
ld c, $0
.asm_1145cd
ld a, [hli]
and a
jr z, .asm_1145ef
cp $20
jr z, .asm_1145cd
cp $d
jr z, .asm_1145f8
cp $61
jr c, .asm_1145e3
cp $7b
jr nc, .asm_1145e3
sub $20
.asm_1145e3
ld b, a
ld a, [de]
and a
jr z, .asm_11460e
inc de
cp b
jr z, .asm_1145cd
dec de
jr .asm_1145cd
.asm_1145ef
ld b, $0
jr .asm_1145f5
.asm_1145f3
ld b, $81
.asm_1145f5
ld a, $1
ret
.asm_1145f8
ld a, [hli]
and a
jr z, .asm_1145f3
cp $a
jr nz, .asm_1145f3
ld a, [hli]
and a
jr z, .asm_1145f3
cp $20
jr z, .asm_1145cd
cp $9
jr z, .asm_1145cd
jr .asm_1145f3
.asm_11460e
ld a, c
and a
jr nz, .asm_114619
ld c, $1
ld de, String_114228
jr .asm_1145cd
.asm_114619
dec hl
ld a, [hl]
cp $22
jr nz, .asm_114620
inc hl
.asm_114620
ld de, $ddc8
ld b, $0
ld c, $40
.asm_114627
ld a, [hli]
cp $22
jr z, .asm_114636
cp $d
jr z, .asm_114636
ld [de], a
inc de
inc b
dec c
jr nz, .asm_114627
.asm_114636
ld a, b
ld [wPartyMon5Defense], a
xor a
ret
Function11463c:
ld a, [$dc00]
push af
push de
ld hl, $ddc8
ld a, [wPartyMon5Defense]
ld b, a
.asm_114648
ld a, [de]
ld c, a
ld a, [hli]
cp c
jr nz, .asm_11468a
inc e
call z, Function11469b
dec b
jr nz, .asm_114648
ld a, [de]
cp $2d
jr z, .asm_114673
cp $d
jr nz, .asm_11468a
xor a
ld [wDecoCarpet], a
.asm_114662
inc e
call z, Function11469b
ld a, [de]
cp $a
jr nz, .asm_11468a
inc e
call z, Function11469b
xor a
pop hl
pop hl
ret
.asm_114673
inc e
call z, Function11469b
ld a, [de]
cp $2d
jr nz, .asm_11468a
inc e
call z, Function11469b
ld a, $1
ld [wDecoCarpet], a
ld a, [de]
cp $d
jr z, .asm_114662
.asm_11468a
pop de
pop af
ld [$dc00], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
xor a
ld [wDecoCarpet], a
ld a, $1
ret
Function11469b:
push bc
ld bc, $dc00
call Function115d80
pop bc
ret
Function1146a4:
call Function114867
and a
jr nz, .asm_1146e4
ld hl, $dc03
ld a, [hli]
ld [$dc00], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ld e, [hl]
inc hl
ld d, [hl]
call Function114a18
and a
jr nz, .asm_1146e8
call Function1148c2
and a
jr nz, .asm_1146e4
ld hl, $dc03
ld a, [hli]
ld [$dc00], a
ldh [hSRAMBank], a
ld [MBC3SRamBank], a
ld e, [hl]
inc hl
ld d, [hl]
call Function114a7a
and a
jr nz, .asm_1146e8
.asm_1146da
dec bc
dec bc
call Function1149cc
and a
jr nz, .asm_1146e4
xor a
ret
.asm_1146e4
ld b, $83
jr .asm_1146f7
.asm_1146e8
ld a, [$dc17]
and a
jr z, .asm_1146f5
ld a, $1
ld [wDecoBigDoll], a
jr .asm_1146da
.asm_1146f5
ld b, $81
.asm_1146f7
ld a, $1
ret