-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.asm
11647 lines (10168 loc) · 172 KB
/
main.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
INCLUDE "includes.asm"
SECTION "bank1", ROMX
PlaceWaitingText:: ; 4000
hlcoord 3, 10
ld b, 1
ld c, 11
ld a, [wBattleMode]
and a
jr z, .notinbattle
call TextBox
jr .proceed
.notinbattle
predef Predef_LinkTextbox
.proceed
hlcoord 4, 11
ld de, .Waiting
call PlaceString
ld c, 50
jp DelayFrames
.Waiting ; 4025
db "Waiting...!@"
LoadPushOAM:: ; 4031
ld c, hPushOAM - $ff00
ld b, PushOAMEnd - PushOAM
ld hl, PushOAM
.loop
ld a, [hli]
ld [$ff00+c], a
inc c
dec b
jr nz, .loop
ret
PushOAM: ; 403f
ld a, Sprites / $100
ld [rDMA], a
ld a, 40
.loop
dec a
jr nz, .loop
ret
PushOAMEnd
INCLUDE "engine/map_objects.asm"
INCLUDE "engine/intro_menu.asm"
Function6454:: ; 6454
call DelayFrame
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
ld a, [hBGMapMode]
push af
xor a
ld [hBGMapMode], a
call .Function6473
pop af
ld [hBGMapMode], a
pop af
ld [hOAMUpdate], a
ld hl, VramState
set 6, [hl]
ret
.Function6473
xor a
ld [hFFC6], a
ld [hBGMapMode], a
ld a, $90
ld [hWY], a
call OverworldTextModeSwitch
ld a, VBGMap1 / $100
call .Function64b9
call Function2e20
callba LoadOW_BGPal7
callba ApplyPals
ld a, $1
ld [hCGBPalUpdate], a
xor a
ld [hBGMapMode], a
ld [hWY], a
callba Function64db ; no need to farcall
ld a, VBGMap0 / $100
call .Function64b9
xor a
ld [wBGMapAnchor], a
ld a, VBGMap0 / $100
ld [wBGMapAnchor + 1], a
xor a
ld [hSCX], a
ld [hSCY], a
call Function5958
ret
.Function64b9: ; 64b9
ld [hBGMapAddress + 1], a
xor a
ld [hBGMapAddress], a
ret
Function64bf:: ; 64bf
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
call .Function64cd
pop af
ld [hOAMUpdate], a
ret
.Function64cd
call LoadFontsExtra
ld a, $90
ld [hWY], a
call Function2e31
call LoadStandardFont
ret
Function64db: ; 64db
ld a, [rSVBK]
push af
ld a, $6
ld [rSVBK], a
ld a, $60
ld hl, wDecompressScratch
ld bc, wBackupAttrMap - wDecompressScratch
call ByteFill
ld a, wDecompressScratch / $100
ld [rHDMA1], a
ld a, wDecompressScratch % $100
ld [rHDMA2], a
ld a, (VBGMap0 % $8000) / $100
ld [rHDMA3], a
ld a, (VBGMap0 % $8000) % $100
ld [rHDMA4], a
ld a, $3f
ld [hDMATransfer], a
call DelayFrame
pop af
ld [rSVBK], a
ret
INCLUDE "engine/learn.asm"
CheckNickErrors:: ; 669f
; error-check monster nick before use
; must be a peace offering to gamesharkers
; input: de = nick location
push bc
push de
ld b, PKMN_NAME_LENGTH
.checkchar
; end of nick?
ld a, [de]
cp "@" ; terminator
jr z, .end
; check if this char is a text command
ld hl, .textcommands
dec hl
.loop
; next entry
inc hl
; reached end of commands table?
ld a, [hl]
cp a, -1
jr z, .done
; is the current char between this value (inclusive)...
ld a, [de]
cp [hl]
inc hl
jr c, .loop
; ...and this one?
cp [hl]
jr nc, .loop
; replace it with a "?"
ld a, "?"
ld [de], a
jr .loop
.done
; next char
inc de
; reached end of nick without finding a terminator?
dec b
jr nz, .checkchar
; change nick to "?@"
pop de
push de
ld a, "?"
ld [de], a
inc de
ld a, "@"
ld [de], a
.end
; if the nick has any errors at this point it's out of our hands
pop de
pop bc
ret
.textcommands ; 66cf
; table defining which characters are actually text commands
; format:
; ≥ <
db "<START>", $04 + 1
db "<PLAY_G>", $18 + 1
db $1d, "%" + 1
db $35, "<GREEN>" + 1
db "<ENEMY>", "<ENEMY>" + 1
db $49, "<TM>" + 1
db "<ROCKET>", "┘" + 1
db -1 ; end
INCLUDE "engine/math.asm"
ItemAttributes: ; 67c1
INCLUDE "items/item_attributes.asm"
INCLUDE "engine/npc_movement.asm"
GetFirstPokemonHappiness: ; 718d
ld hl, PartyMon1Happiness
ld bc, PARTYMON_STRUCT_LENGTH
ld de, PartySpecies
.loop
ld a, [de]
cp EGG
jr nz, .done
inc de
add hl, bc
jr .loop
.done
ld [wd265], a
ld a, [hl]
ld [ScriptVar], a
call GetPokemonName
jp CopyPokemonName_Buffer1_Buffer3
CheckFirstMonIsEgg: ; 71ac
ld a, [PartySpecies]
ld [wd265], a
cp EGG
ld a, $1
jr z, .egg
xor a
.egg
ld [ScriptVar], a
call GetPokemonName
jp CopyPokemonName_Buffer1_Buffer3
ChangeHappiness: ; 71c2
; Perform happiness action c on CurPartyMon
ld a, [CurPartyMon]
inc a
ld e, a
ld d, 0
ld hl, PartySpecies - 1
add hl, de
ld a, [hl]
cp EGG
ret z
push bc
ld hl, PartyMon1Happiness
ld bc, PARTYMON_STRUCT_LENGTH
ld a, [CurPartyMon]
call AddNTimes
pop bc
ld d, h
ld e, l
push de
ld a, [de]
cp 100
ld e, 0
jr c, .ok
inc e
cp 200
jr c, .ok
inc e
.ok
dec c
ld b, 0
ld hl, .Actions
rept 3
add hl, bc
endr
ld d, 0
add hl, de
ld a, [hl]
cp 100
pop de
ld a, [de]
jr nc, .negative
add [hl]
jr nc, .done
ld a, -1
jr .done
.negative
add [hl]
jr c, .done
xor a
.done
ld [de], a
ld a, [wBattleMode]
and a
ret z
ld a, [CurPartyMon]
ld b, a
ld a, [wPartyMenuCursor]
cp b
ret nz
ld a, [de]
ld [BattleMonHappiness], a
ret
.Actions
db +5, +3, +2 ; Gained a level
db +5, +3, +2 ; Vitamin
db +1, +1, +0 ; X Item
db +3, +2, +1 ; Battled a Gym Leader
db +1, +1, +0 ; Learned a move
db -1, -1, -1 ; Lost to an enemy
db -5, -5, -10 ; Fainted due to poison
db -5, -5, -10 ; Lost to a much stronger enemy
db +1, +1, +1 ; Haircut (Y1)
db +3, +3, +1 ; Haircut (Y2)
db +5, +5, +2 ; Haircut (Y3)
db +1, +1, +1 ; Haircut (O1)
db +3, +3, +1 ; Haircut (O2)
db +10, +10, +4 ; Haircut (O3)
db -5, -5, -10 ; Used Heal Powder or Energypowder (bitter)
db -10, -10, -15 ; Used Energy Root (bitter)
db -15, -15, -20 ; Used Revival Herb (bitter)
db +3, +3, +1 ; Grooming
db +10, +6, +4 ; Gained a level in the place where it was caught
StepHappiness:: ; 725a
; Raise the party's happiness by 1 point every other step cycle.
ld hl, wHappinessStepCount
ld a, [hl]
inc a
and 1
ld [hl], a
ret nz
ld de, PartyCount
ld a, [de]
and a
ret z
ld c, a
ld hl, PartyMon1Happiness
.loop
inc de
ld a, [de]
cp EGG
jr z, .next
inc [hl]
jr nz, .next
ld [hl], $ff
.next
push de
ld de, PARTYMON_STRUCT_LENGTH
add hl, de
pop de
dec c
jr nz, .loop
ret
DaycareStep:: ; 7282
ld a, [wDaycareMan]
bit 0, a
jr z, .daycare_lady
ld a, [wBreedMon1Level] ; level
cp 100
jr nc, .daycare_lady
ld hl, wBreedMon1Exp + 2 ; exp
inc [hl]
jr nz, .daycare_lady
dec hl
inc [hl]
jr nz, .daycare_lady
dec hl
inc [hl]
ld a, [hl]
cp 5242880 / $10000
jr c, .daycare_lady
ld a, 5242880 / $10000
ld [hl], a
.daycare_lady
ld a, [wDaycareLady]
bit 0, a
jr z, .check_egg
ld a, [wBreedMon2Level] ; level
cp 100
jr nc, .check_egg
ld hl, wBreedMon2Exp + 2 ; exp
inc [hl]
jr nz, .check_egg
dec hl
inc [hl]
jr nz, .check_egg
dec hl
inc [hl]
ld a, [hl]
cp 5242880 / $10000
jr c, .check_egg
ld a, 5242880 / $10000
ld [hl], a
.check_egg
ld hl, wDaycareMan
bit 5, [hl] ; egg
ret z
ld hl, wStepsToEgg
dec [hl]
ret nz
call Random
ld [hl], a
callab CheckBreedmonCompatibility
ld a, [wd265]
cp 230
ld b, -1 + 32 percent
jr nc, .okay
ld a, [wd265]
cp 170
ld b, 16 percent
jr nc, .okay
ld a, [wd265]
cp 110
ld b, 12 percent
jr nc, .okay
ld b, 4 percent
.okay
call Random
cp b
ret nc
ld hl, wDaycareMan
res 5, [hl]
set 6, [hl]
ret
SpecialGiveShuckle: ; 7305
; Adding to the party.
xor a
ld [MonType], a
; Level 15 Shuckle.
Randomizer_ShuckleSpecies::
ld a, SHUCKLE
ld [CurPartySpecies], a
ld a, 15
ld [CurPartyLevel], a
predef TryAddMonToParty
jr nc, .NotGiven
; Caught data.
ld b, 0
callba SetGiftPartyMonCaughtData
; Holding a Berry.
ld bc, PARTYMON_STRUCT_LENGTH
ld a, [PartyCount]
dec a
push af
push bc
ld hl, PartyMon1Item
call AddNTimes
ld [hl], BERRY
pop bc
pop af
; OT ID.
ld hl, PartyMon1ID
call AddNTimes
ld a, $2
ld [hli], a
ld [hl], $6
; Nickname.
ld a, [PartyCount]
dec a
ld hl, PartyMonNicknames
call SkipNames
ld de, SpecialShuckleNick
call CopyName2
; OT.
ld a, [PartyCount]
dec a
ld hl, PartyMonOT
call SkipNames
ld de, SpecialShuckleOT
call CopyName2
; Engine flag for this event.
ld hl, DailyFlags
set 5, [hl]
; setflag ENGINE_SHUCKLE_GIVEN
ld a, 1
ld [ScriptVar], a
ret
.NotGiven
xor a
ld [ScriptVar], a
ret
SpecialShuckleOT:
db "MANIA@"
SpecialShuckleNick:
db "SHUCKIE@"
SpecialReturnShuckle: ; 737e
callba SelectMonFromParty
jr c, .refused
ld a, [CurPartySpecies]
cp SHUCKLE
jr nz, .DontReturn
ld a, [CurPartyMon]
ld hl, PartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
; OT ID
ld a, [hli]
cp 00518 / $100
jr nz, .DontReturn
ld a, [hl]
cp 00518 % $100
jr nz, .DontReturn
; OT
ld a, [CurPartyMon]
ld hl, PartyMonOT
call SkipNames
ld de, SpecialShuckleOT
.CheckOT
ld a, [de]
cp [hl]
jr nz, .DontReturn
cp "@"
jr z, .done
inc de
inc hl
jr .CheckOT
.done
callba CheckCurPartyMonFainted
jr c, .fainted
ld a, [CurPartyMon]
ld hl, PartyMon1Happiness
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld a, [hl]
cp 150
ld a, $3
jr nc, .HappyToStayWithYou
xor a ; take from pc
ld [wPokemonWithdrawDepositParameter], a
callab RemoveMonFromPartyOrBox
ld a, $2
.HappyToStayWithYou
ld [ScriptVar], a
ret
.refused
ld a, $1
ld [ScriptVar], a
ret
.DontReturn
xor a
ld [ScriptVar], a
ret
.fainted
ld a, $4
ld [ScriptVar], a
ret
Special_BillsGrandfather: ; 73f7
callba SelectMonFromParty
jr c, .cancel
ld a, [CurPartySpecies]
ld [ScriptVar], a
ld [wNamedObjectIndexBuffer], a
call GetPokemonName
jp CopyPokemonName_Buffer1_Buffer3
.cancel
xor a
ld [ScriptVar], a
ret
Special_YoungerHaircutBrother: ; 7413
ld hl, Data_YoungerHaircutBrother
jr MassageOrHaircut
Special_OlderHaircutBrother: ; 7418
ld hl, Data_OlderHaircutBrother
jr MassageOrHaircut
Special_DaisyMassage: ; 741d
ld hl, Data_DaisyMassage
MassageOrHaircut: ; 7420
push hl
callba SelectMonFromParty
pop hl
jr c, .nope
ld a, [CurPartySpecies]
cp EGG
jr z, .egg
push hl
call GetCurNick
call CopyPokemonName_Buffer1_Buffer3
pop hl
call Random
; Bug: Subtracting $ff from $ff fails to set c.
; This can result in overflow into the next data array.
; In the case of getting a massage from Daisy, we bleed
; into CopyPokemonName_Buffer1_Buffer3, which passes
; $d0 to ChangeHappiness and returns $73 to the script.
; The end result is that there is a 0.4% chance your
; Pokemon's happiness will not change at all.
.loop
sub [hl]
jr c, .ok
rept 3
inc hl
endr
jr .loop
.ok
inc hl
ld a, [hli]
ld [ScriptVar], a
ld c, [hl]
call ChangeHappiness
ret
.nope
xor a
ld [ScriptVar], a
ret
.egg
ld a, 1
ld [ScriptVar], a
ret
Data_YoungerHaircutBrother: ; 7459
db $4c, 2, HAPPINESS_YOUNGCUT1 ; 30% chance
db $80, 3, HAPPINESS_YOUNGCUT2 ; 20% chance
db $ff, 4, HAPPINESS_YOUNGCUT3 ; 50% chance
Data_OlderHaircutBrother: ; 7462
db $9a, 2, HAPPINESS_OLDERCUT1 ; 60% chance
db $4c, 3, HAPPINESS_OLDERCUT2 ; 10% chance
db $ff, 4, HAPPINESS_OLDERCUT3 ; 30% chance
Data_DaisyMassage: ; 746b
db $ff, 2, HAPPINESS_MASSAGE ; 99.6% chance
CopyPokemonName_Buffer1_Buffer3: ; 746e
ld hl, StringBuffer1
ld de, StringBuffer3
ld bc, PKMN_NAME_LENGTH
jp CopyBytes
Predef1: ; 747a
; not used
ret
SECTION "bank2", ROMX
BlankScreen: ; 8000
call DisableSpriteUpdates
xor a
ld [hBGMapMode], a
call ClearBGPalettes
call ClearSprites
hlcoord 0, 0
ld bc, TileMapEnd - TileMap
ld a, " "
call ByteFill
hlcoord 0, 0, AttrMap
ld bc, AttrMapEnd - AttrMap
ld a, $7
call ByteFill
call WaitBGMap2
call SetPalettes
ret
SpawnPlayer: ; 8029
ld a, -1
ld [wObjectFollow_Leader], a
ld [wObjectFollow_Follower], a
ld a, $0
ld hl, PlayerObjectTemplate
call CopyPlayerObjectTemplate
ld b, $0
call PlayerSpawn_ConvertCoords
ld a, $0
call GetMapObject
ld hl, MAPOBJECT_COLOR
add hl, bc
ln e, (1 << 3) | PAL_OW_RED, PERSONTYPE_SCRIPT
ld a, [wPlayerSpriteSetupFlags]
bit 2, a
jr nz, .ok
ld a, [PlayerGender]
bit 0, a
jr z, .ok
ln e, (1 << 3) | PAL_OW_BLUE, PERSONTYPE_SCRIPT
.ok
ld [hl], e
ld a, $0
ld [hMapObjectIndexBuffer], a
ld bc, MapObjects
ld a, $0
ld [hObjectStructIndexBuffer], a
ld de, ObjectStructs
call CopyMapObjectToObjectStruct
ld a, PLAYER
ld [wCenteredObject], a
ret
PlayerObjectTemplate: ; 8071
; A dummy map object used to initialize the player object.
; Shorter than the actual amount copied by two bytes.
; Said bytes seem to be unused.
person_event SPRITE_CHRIS, -4, -4, SPRITEMOVEDATA_PLAYER, 15, 15, -1, -1, 0, PERSONTYPE_SCRIPT, 0, 0, -1
CopyDECoordsToMapObject:: ; 807e
push de
ld a, b
call GetMapObject
pop de
ld hl, MAPOBJECT_X_COORD
add hl, bc
ld [hl], d
ld hl, MAPOBJECT_Y_COORD
add hl, bc
ld [hl], e
ret
PlayerSpawn_ConvertCoords: ; 808f
push bc
ld a, [XCoord]
add 4
ld d, a
ld a, [YCoord]
add 4
ld e, a
pop bc
call CopyDECoordsToMapObject
ret
WritePersonXY:: ; 80a1
ld a, b
call CheckObjectVisibility
ret c
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld e, [hl]
ld a, [hMapObjectIndexBuffer]
ld b, a
call CopyDECoordsToMapObject
and a
ret
RefreshPlayerCoords: ; 80b8
ld a, [XCoord]
add 4
ld d, a
ld hl, PlayerStandingMapX
sub [hl]
ld [hl], d
ld hl, MapObjects + MAPOBJECT_X_COORD
ld [hl], d
ld hl, PlayerLastMapX
ld [hl], d
ld d, a
ld a, [YCoord]
add 4
ld e, a
ld hl, PlayerStandingMapY
sub [hl]
ld [hl], e
ld hl, MapObjects + MAPOBJECT_Y_COORD
ld [hl], e
ld hl, PlayerLastMapY
ld [hl], e
ld e, a
ld a, [wObjectFollow_Leader]
cp $0
ret nz ; wtf
ret
CopyObjectStruct:: ; 80e7
call CheckObjectMask
and a
ret nz ; masked
ld hl, ObjectStructs + OBJECT_STRUCT_LENGTH * 1
ld a, 1
ld de, OBJECT_STRUCT_LENGTH
.loop
ld [hObjectStructIndexBuffer], a
ld a, [hl]
and a
jr z, .done
add hl, de
ld a, [hObjectStructIndexBuffer]
inc a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
scf
ret ; overflow
.done
ld d, h
ld e, l
call CopyMapObjectToObjectStruct
ld hl, VramState
bit 7, [hl]
ret z
ld hl, OBJECT_FLAGS2
add hl, de
set 5, [hl]
ret
CopyMapObjectToObjectStruct: ; 8116
call .CopyMapObjectToTempObject
call CopyTempObjectToObjectStruct
ret
.CopyMapObjectToTempObject: ; 811d
ld a, [hObjectStructIndexBuffer]
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
add hl, bc
ld [hl], a
ld a, [hMapObjectIndexBuffer]
ld [wTempObjectCopyMapObjectIndex], a
ld hl, MAPOBJECT_SPRITE
add hl, bc
ld a, [hl]
ld [wTempObjectCopySprite], a
call GetSpriteVTile
ld [wTempObjectCopySpriteVTile], a
ld a, [hl]
call GetSpritePalette
ld [wTempObjectCopyPalette], a
ld hl, MAPOBJECT_COLOR
add hl, bc
ld a, [hl]
and $f0
jr z, .skip_color_override
swap a
and $7 ; OAM_PALETTE
ld [wTempObjectCopyPalette], a
.skip_color_override
ld hl, MAPOBJECT_MOVEMENT
add hl, bc
ld a, [hl]
ld [wTempObjectCopyMovement], a
ld hl, MAPOBJECT_RANGE
add hl, bc
ld a, [hl]
ld [wTempObjectCopyRange], a
ld hl, MAPOBJECT_X_COORD
add hl, bc
ld a, [hl]
ld [wTempObjectCopyX], a
ld hl, MAPOBJECT_Y_COORD
add hl, bc
ld a, [hl]
ld [wTempObjectCopyY], a
ld hl, MAPOBJECT_RADIUS
add hl, bc
ld a, [hl]
ld [wTempObjectCopyRadius], a
ret
InitializeVisibleSprites: ; 8177
ld bc, MapObjects + OBJECT_LENGTH
ld a, 1
.loop
ld [hMapObjectIndexBuffer], a
ld hl, MAPOBJECT_SPRITE
add hl, bc
ld a, [hl]
and a
jr z, .next
ld hl, MAPOBJECT_OBJECT_STRUCT_ID
add hl, bc
ld a, [hl]
cp -1
jr nz, .next
ld a, [XCoord]
ld d, a
ld a, [YCoord]
ld e, a
ld hl, MAPOBJECT_X_COORD
add hl, bc
ld a, [hl]
add 1
sub d
jr c, .next
cp MAPOBJECT_SCREEN_WIDTH
jr nc, .next
ld hl, MAPOBJECT_Y_COORD
add hl, bc
ld a, [hl]
add 1
sub e
jr c, .next
cp MAPOBJECT_SCREEN_HEIGHT
jr nc, .next
push bc
call CopyObjectStruct
pop bc
jp c, .ret
.next
ld hl, OBJECT_LENGTH
add hl, bc
ld b, h
ld c, l
ld a, [hMapObjectIndexBuffer]
inc a
cp NUM_OBJECTS
jr nz, .loop