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
|
thumb_func_start Main
Main:
push {r4-r7,lr}
mov r7, r8
push {r7}
movs r0, 0xFF
bl RegisterRamReset
movs r1, 0xA0
lsls r1, 19
ldr r2, =0x00007fff
adds r0, r2, 0
strh r0, [r1]
bl InitGpuRegManager
ldr r1, =0x04000204
ldr r3, =0x00004014
adds r0, r3, 0
strh r0, [r1]
bl InitKeypadData
bl InitIntrHandlers
bl m4aSoundInit
bl EnableVCountIntrAtLine150
bl sub_800E6D0
bl GameFreakRTC_Init
bl CheckForFlashMemory
bl InitVariablesAndSetCopyrightScreenCallback
bl sound_sources_off
bl ClearDma3Requests
bl ResetBgs
bl SetDefaultFontsPointer
ldr r0, =0x02000000
movs r1, 0xE0
lsls r1, 9
bl InitHeap
ldr r0, =0x03002700
movs r4, 0
strb r4, [r0]
ldr r0, =0x03005d88
ldr r0, [r0]
cmp r0, 0x1
beq _08000414
movs r0, 0
bl SetMainCallback2
_08000414:
ldr r2, =0x030022b4
strb r4, [r2]
ldr r1, =0x03000000
movs r3, 0xFC
lsls r3, 4
adds r0, r3, 0
strh r0, [r1]
ldr r7, =0x030022c0
movs r0, 0
mov r8, r0
adds r6, r2, 0
_0800042A:
bl ReadKeypad
ldr r0, =0x03002700
ldrb r0, [r0]
cmp r0, 0
bne _08000454
ldrh r1, [r7, 0x28]
movs r0, 0x1
ands r0, r1
cmp r0, 0
beq _08000454
movs r0, 0xE
ands r0, r1
cmp r0, 0xE
bne _08000454
bl rfu_REQ_stopMode
bl rfu_waitREQComplete
bl Reset
_08000454:
bl sub_8087634
cmp r0, 0x1
bne _0800048C
strb r0, [r6]
bl HandleLinkConnectionAndCallMainCallbacks
movs r0, 0
strb r0, [r6]
b _080004B2
.pool
_0800048C:
ldr r5, =0x030022b4
movs r0, 0
strb r0, [r5]
bl HandleLinkConnectionAndCallMainCallbacks
bl sub_80875C8
adds r4, r0, 0
cmp r4, 0x1
bne _080004B2
movs r0, 0
strh r0, [r7, 0x2E]
bl ClearObjectCopyRequests
strb r4, [r5]
bl HandleLinkConnectionAndCallMainCallbacks
mov r2, r8
strb r2, [r5]
_080004B2:
bl gametime_increment
bl sound_something
bl WaitForVBlankIntr
b _0800042A
.pool
thumb_func_end Main
thumb_func_start HandleLinkConnectionAndCallMainCallbacks
; void HandleLinkConnectionAndCallMainCallbacks()
HandleLinkConnectionAndCallMainCallbacks: ; 80004C4
push {lr}
bl HandleLinkConnection
lsls r0, 24
cmp r0, 0
bne _080004D4
bl CallMainCallbacks
_080004D4:
pop {r0}
bx r0
thumb_func_end HandleLinkConnectionAndCallMainCallbacks
thumb_func_start InitVariablesAndSetCopyrightScreenCallback
; void InitVariablesAndSetCopyrightScreenCallback()
InitVariablesAndSetCopyrightScreenCallback: ; 80004D8
push {lr}
ldr r2, =0x030022c0
movs r0, 0
str r0, [r2, 0x20]
ldr r1, =0x0203cf5c
str r0, [r1]
str r0, [r2, 0x24]
str r0, [r2]
ldr r0, =c2_copyright_1
bl SetMainCallback2
ldr r1, =0x03005d90
ldr r0, =0x02024a54
str r0, [r1]
ldr r1, =0x03005d94
ldr r0, =0x02029808
str r0, [r1]
pop {r0}
bx r0
.pool
thumb_func_end InitVariablesAndSetCopyrightScreenCallback
thumb_func_start CallMainCallbacks
; void CallMainCallbacks()
CallMainCallbacks: ; 800051C
push {r4,lr}
ldr r4, =0x030022c0
ldr r0, [r4]
cmp r0, 0
beq _0800052A
bl _call_via_r0
_0800052A:
ldr r0, [r4, 0x4]
cmp r0, 0
beq _08000534
bl _call_via_r0
_08000534:
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end CallMainCallbacks
thumb_func_start SetMainCallback2
; void SetMainCallback2(void ( *func)())
SetMainCallback2: ; 8000540
ldr r1, =0x030022c0
str r0, [r1, 0x4]
movs r0, 0x87
lsls r0, 3
adds r1, r0
movs r0, 0
strb r0, [r1]
bx lr
.pool
thumb_func_end SetMainCallback2
thumb_func_start StartTimer1
; void StartTimer1()
StartTimer1: ; 8000554
ldr r1, =0x04000106
movs r0, 0x80
strh r0, [r1]
bx lr
.pool
thumb_func_end StartTimer1
thumb_func_start SeedRngAndSetTrainerId
; void SeedRngAndSetTrainerId()
SeedRngAndSetTrainerId: ; 8000560
push {r4,lr}
ldr r0, =0x04000104
ldrh r4, [r0]
adds r0, r4, 0
bl SeedRng
ldr r1, =0x04000106
movs r0, 0
strh r0, [r1]
ldr r0, =0x02020000
strh r4, [r0]
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end SeedRngAndSetTrainerId
thumb_func_start GetTrainerId
; u16 GetTrainerId()
GetTrainerId: ; 8000588
ldr r0, =0x02020000
ldrh r0, [r0]
bx lr
.pool
thumb_func_end GetTrainerId
thumb_func_start EnableVCountIntrAtLine150
; void EnableVCountIntrAtLine150()
EnableVCountIntrAtLine150: ; 8000594
push {lr}
movs r0, 0x4
bl GetGpuReg
movs r1, 0xFF
ands r1, r0
movs r2, 0x96
lsls r2, 8
adds r0, r2, 0
orrs r1, r0
movs r0, 0x20
orrs r1, r0
movs r0, 0x4
bl SetGpuReg
movs r0, 0x4
bl EnableInterrupts
pop {r0}
bx r0
thumb_func_end EnableVCountIntrAtLine150
thumb_func_start InitKeypadData
; void InitKeypadData()
InitKeypadData: ; 80005BC
ldr r1, =0x030026fc
movs r0, 0x5
strh r0, [r1]
ldr r1, =0x030022b0
movs r0, 0x28
strh r0, [r1]
ldr r1, =0x030022c0
movs r0, 0
strh r0, [r1, 0x2C]
strh r0, [r1, 0x2E]
strh r0, [r1, 0x30]
strh r0, [r1, 0x28]
strh r0, [r1, 0x2A]
bx lr
.pool
thumb_func_end InitKeypadData
thumb_func_start ReadKeypad
; void ReadKeypad()
ReadKeypad: ; 80005E4
push {lr}
ldr r0, =0x04000130
ldrh r1, [r0]
ldr r2, =0x000003ff
adds r0, r2, 0
adds r3, r0, 0
eors r3, r1
ldr r1, =0x030022c0
ldrh r2, [r1, 0x28]
adds r0, r3, 0
bics r0, r2
strh r0, [r1, 0x2A]
strh r0, [r1, 0x2E]
strh r0, [r1, 0x30]
adds r2, r1, 0
cmp r3, 0
beq _08000630
ldrh r0, [r2, 0x2C]
cmp r0, r3
bne _08000630
ldrh r0, [r2, 0x32]
subs r0, 0x1
strh r0, [r2, 0x32]
lsls r0, 16
cmp r0, 0
bne _08000636
strh r3, [r2, 0x30]
ldr r0, =0x030026fc
b _08000632
.pool
_08000630:
ldr r0, =0x030022b0
_08000632:
ldrh r0, [r0]
strh r0, [r2, 0x32]
_08000636:
strh r3, [r2, 0x28]
strh r3, [r2, 0x2C]
ldr r0, =0x03005d90
ldr r0, [r0]
ldrb r0, [r0, 0x13]
cmp r0, 0x2
bne _08000668
ldrh r1, [r2, 0x2E]
movs r3, 0x80
lsls r3, 2
adds r0, r3, 0
ands r0, r1
cmp r0, 0
beq _08000658
movs r0, 0x1
orrs r0, r1
strh r0, [r2, 0x2E]
_08000658:
ldrh r1, [r2, 0x2C]
adds r0, r3, 0
ands r0, r1
cmp r0, 0
beq _08000668
movs r0, 0x1
orrs r0, r1
strh r0, [r2, 0x2C]
_08000668:
ldrh r1, [r2, 0x2E]
ldrh r0, [r2, 0x36]
ands r0, r1
cmp r0, 0
beq _08000676
movs r0, 0x1
strh r0, [r2, 0x34]
_08000676:
pop {r0}
bx r0
.pool
thumb_func_end ReadKeypad
thumb_func_start InitIntrHandlers
; void InitIntrHandlers()
InitIntrHandlers: ; 8000684
push {r4,r5,lr}
ldr r5, =InterruptMain
ldr r4, =0x03002750
ldr r3, =gRomInterruptTable
ldr r2, =0x03002710
movs r1, 0xD
_08000690:
ldm r3!, {r0}
stm r2!, {r0}
subs r1, 0x1
cmp r1, 0
bge _08000690
ldr r0, =0x040000d4
str r5, [r0]
str r4, [r0, 0x4]
ldr r1, =0x84000200
str r1, [r0, 0x8]
ldr r0, [r0, 0x8]
ldr r0, =0x03007ffc
str r4, [r0]
movs r0, 0
bl SetVBlankCallback
movs r0, 0
bl SetHBlankCallback
movs r0, 0
bl SetSerialCallback
ldr r1, =0x04000208
movs r0, 0x1
strh r0, [r1]
movs r0, 0x1
bl EnableInterrupts
pop {r4,r5}
pop {r0}
bx r0
.pool
thumb_func_end InitIntrHandlers
thumb_func_start SetVBlankCallback
; void SetVBlankCallback(void ( *func)())
SetVBlankCallback: ; 80006F0
ldr r1, =0x030022c0
str r0, [r1, 0xC]
bx lr
.pool
thumb_func_end SetVBlankCallback
thumb_func_start SetHBlankCallback
; void SetHBlankCallback(void ( *func)())
SetHBlankCallback: ; 80006FC
ldr r1, =0x030022c0
str r0, [r1, 0x10]
bx lr
.pool
thumb_func_end SetHBlankCallback
thumb_func_start SetVCountCallback
; void SetVCountCallback(void ( *func)())
SetVCountCallback: ; 8000708
ldr r1, =0x030022c0
str r0, [r1, 0x14]
bx lr
.pool
thumb_func_end SetVCountCallback
thumb_func_start RestoreSerialTimer3IntrHandlers
; void RestoreSerialTimer3IntrHandlers()
RestoreSerialTimer3IntrHandlers: ; 8000714
ldr r0, =0x03002710
ldr r1, =SerialIntr
str r1, [r0, 0x4]
ldr r1, =Timer3Intr
str r1, [r0, 0x8]
bx lr
.pool
thumb_func_end RestoreSerialTimer3IntrHandlers
thumb_func_start SetSerialCallback
; void SetSerialCallback(void ( *func)())
SetSerialCallback: ; 800072C
ldr r1, =0x030022c0
str r0, [r1, 0x18]
bx lr
.pool
thumb_func_end SetSerialCallback
thumb_func_start VBlankIntr
; void VBlankIntr()
VBlankIntr: ; 8000738
push {r4,lr}
ldr r0, =0x030030fc
ldrb r0, [r0]
cmp r0, 0
beq _0800074C
bl rfu_syncVBlank__
b _08000758
.pool
_0800074C:
ldr r0, =0x03002748
ldrb r0, [r0]
cmp r0, 0
bne _08000758
bl sub_800B9B8
_08000758:
ldr r0, =0x030022c0
ldr r1, [r0, 0x20]
adds r1, 0x1
str r1, [r0, 0x20]
ldr r1, =0x0203cf5c
ldr r1, [r1]
adds r4, r0, 0
cmp r1, 0
beq _08000778
ldr r2, [r1]
movs r0, 0x2
negs r0, r0
cmp r2, r0
bhi _08000778
adds r0, r2, 0x1
str r0, [r1]
_08000778:
ldr r0, [r4, 0xC]
cmp r0, 0
beq _08000782
bl _call_via_r0
_08000782:
ldr r0, [r4, 0x24]
adds r0, 0x1
str r0, [r4, 0x24]
bl CopyBufferedValuesToGpuRegs
bl ProcessDma3Requests
ldr r1, =0x03002f50
ldr r0, =0x03006380
ldrb r0, [r0, 0x4]
strb r0, [r1]
bl m4aSoundMain
bl sub_8033648
ldr r1, =0x00000439
adds r0, r4, r1
ldrb r1, [r0]
movs r0, 0x2
ands r0, r1
cmp r0, 0
beq _080007BA
ldr r0, =0x02022fec
ldr r0, [r0]
ldr r1, =0x013f0102
ands r0, r1
cmp r0, 0
bne _080007BE
_080007BA:
bl GenerateRandomNumber
_080007BE:
bl sub_800E174
ldr r2, =0x03007ff8
ldrh r0, [r2]
movs r1, 0x1
orrs r0, r1
strh r0, [r2]
ldr r0, =0x030022c0
ldrh r2, [r0, 0x1C]
ldrh r3, [r0, 0x1C]
orrs r1, r2
strh r1, [r0, 0x1C]
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end VBlankIntr
thumb_func_start StartFlashMemoryTimer
; void StartFlashMemoryTimer()
StartFlashMemoryTimer: ; 8000800
push {lr}
ldr r1, =0x0300272c
movs r0, 0x2
bl SetFlashTimerIntr
pop {r0}
bx r0
.pool
thumb_func_end StartFlashMemoryTimer
thumb_func_start HBlankIntr
; void HBlankIntr()
HBlankIntr: ; 8000814
push {r4,lr}
ldr r4, =0x030022c0
ldr r0, [r4, 0x10]
cmp r0, 0
beq _08000822
bl _call_via_r0
_08000822:
ldr r2, =0x03007ff8
ldrh r0, [r2]
movs r1, 0x2
orrs r0, r1
strh r0, [r2]
ldrh r0, [r4, 0x1C]
ldrh r2, [r4, 0x1C]
orrs r1, r0
strh r1, [r4, 0x1C]
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end HBlankIntr
thumb_func_start VCountIntr
; void VCountIntr()
VCountIntr: ; 8000844
push {r4,lr}
ldr r4, =0x030022c0
ldr r0, [r4, 0x14]
cmp r0, 0
beq _08000852
bl _call_via_r0
_08000852:
bl SoundVSync_rev01
ldr r2, =0x03007ff8
ldrh r0, [r2]
movs r1, 0x4
orrs r0, r1
strh r0, [r2]
ldrh r0, [r4, 0x1C]
ldrh r2, [r4, 0x1C]
orrs r1, r0
strh r1, [r4, 0x1C]
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end VCountIntr
thumb_func_start SerialIntr
; void SerialIntr()
SerialIntr: ; 8000878
push {r4,lr}
ldr r4, =0x030022c0
ldr r0, [r4, 0x18]
cmp r0, 0
beq _08000886
bl _call_via_r0
_08000886:
ldr r2, =0x03007ff8
ldrh r0, [r2]
movs r1, 0x80
orrs r0, r1
strh r0, [r2]
ldrh r0, [r4, 0x1C]
ldrh r2, [r4, 0x1C]
orrs r1, r0
strh r1, [r4, 0x1C]
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end SerialIntr
thumb_func_start DummyIntrHandler
; void DummyIntrHandler()
DummyIntrHandler: ; 80008A8
bx lr
thumb_func_end DummyIntrHandler
thumb_func_start WaitForVBlankIntr
; void WaitForVBlankIntr()
WaitForVBlankIntr: ; 80008AC
push {lr}
ldr r2, =0x030022c0
ldrh r1, [r2, 0x1C]
ldr r0, =0x0000fffe
ands r0, r1
ldrh r1, [r2, 0x1C]
strh r0, [r2, 0x1C]
ldrh r1, [r2, 0x1C]
movs r0, 0x1
ands r0, r1
cmp r0, 0
bne _080008D0
movs r3, 0x1
_080008C6:
ldrh r1, [r2, 0x1C]
adds r0, r3, 0
ands r0, r1
cmp r0, 0
beq _080008C6
_080008D0:
pop {r0}
bx r0
.pool
thumb_func_end WaitForVBlankIntr
thumb_func_start sub_80008DC
sub_80008DC: ; 80008DC
ldr r1, =0x0203cf5c
str r0, [r1]
bx lr
.pool
thumb_func_end sub_80008DC
thumb_func_start sub_80008E8
sub_80008E8: ; 80008E8
ldr r1, =0x0203cf5c
movs r0, 0
str r0, [r1]
bx lr
.pool
thumb_func_end sub_80008E8
thumb_func_start Reset
; void Reset()
Reset: ; 80008F4
push {r4,lr}
ldr r1, =0x04000208
movs r0, 0
strh r0, [r1]
bl SoundVSyncOff_rev01
bl remove_some_task
ldr r1, =0x040000bc
ldrh r2, [r1, 0xA]
ldr r3, =0x0000c5ff
adds r0, r3, 0
ands r0, r2
strh r0, [r1, 0xA]
ldrh r4, [r1, 0xA]
ldr r2, =0x00007fff
adds r0, r2, 0
ands r0, r4
strh r0, [r1, 0xA]
ldrh r0, [r1, 0xA]
adds r1, 0xC
ldrh r4, [r1, 0xA]
adds r0, r3, 0
ands r0, r4
strh r0, [r1, 0xA]
ldrh r4, [r1, 0xA]
adds r0, r2, 0
ands r0, r4
strh r0, [r1, 0xA]
ldrh r0, [r1, 0xA]
ldr r0, =0x040000d4
ldrh r1, [r0, 0xA]
ands r3, r1
strh r3, [r0, 0xA]
ldrh r1, [r0, 0xA]
ands r2, r1
strh r2, [r0, 0xA]
ldrh r0, [r0, 0xA]
bl RTC_SetReadOnly
movs r0, 0xFF
bl SoftReset
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end Reset
thumb_func_start sub_8000964
sub_8000964: ; 8000964
push {lr}
sub sp, 0x4
mov r1, sp
movs r0, 0
strh r0, [r1]
ldr r1, =0x03007330
ldr r2, =0x01000034
mov r0, sp
bl CpuSet
add sp, 0x4
pop {r0}
bx r0
.pool
thumb_func_end sub_8000964
|