-
Notifications
You must be signed in to change notification settings - Fork 12
/
table_functions.asm
111 lines (101 loc) · 3.93 KB
/
table_functions.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
INCLUDE "engine/16/macros.asm"
ForceGarbageCollection::
push bc
ldh a, [rSVBK]
push af
ld a, BANK("16-bit WRAM tables")
ldh [rSVBK], a
call PokemonTableGarbageCollection
call MoveTableGarbageCollection
pop af
ldh [rSVBK], a
pop bc
ret
; Note: ID = 8-bit ID used in memory, etc.; index = true 16-bit index into tables
_GetPokemonIndexFromID::
___conversion_table_load wPokemonIndexTable, MON_TABLE
_GetPokemonIDFromIndex::
___conversion_table_store wPokemonIndexTable, MON_TABLE
; fallthrough - as required by the macro
PokemonTableGarbageCollection:
; must preserve de and rSVBK
push de
ldh a, [rSVBK]
push af
___conversion_bitmap_initialize wPokemonIndexTable, MON_TABLE, .set_bit
ld a, 1
ldh [rSVBK], a
___conversion_bitmap_check_structs wPartyMons, PARTYMON_STRUCT_LENGTH, PARTY_LENGTH, .set_bit
___conversion_bitmap_check_structs wBreedMon1Species, wBreedMon2 - wBreedMon1Species, 2, .set_bit
ld a, [wEggMonSpecies]
call .set_bit
; may or may not be valid, but marking them in use is free
___conversion_bitmap_check_structs wOTPartyMons, PARTYMON_STRUCT_LENGTH, PARTY_LENGTH, .set_bit
___conversion_bitmap_check_structs wRoamMon1, wRoamMon2 - wRoamMon1, 3, .set_bit
___conversion_bitmap_check_structs wBugContestFirstPlaceMon, wBugContestSecondPlaceMon - wBugContestFirstPlaceMon, 3, .set_bit
___conversion_bitmap_check_values .set_bit, wBufferMonSpecies, wTempMonSpecies, wContestMonSpecies, \
wBattleMonSpecies, wEnemyMonSpecies, wOddEggSpecies, wBaseSpecies
pop af
ldh [rSVBK], a
ldh a, [hSRAMBank]
push af
ld a, BANK(sBox)
call OpenSRAM
___conversion_bitmap_check_structs sBoxMons, BOXMON_STRUCT_LENGTH, MONS_PER_BOX, .set_bit
pop af
call OpenSRAM ;will close SRAM if hSRAMBank was -1
___conversion_bitmap_free_unused wPokemonIndexTable, MON_TABLE
pop de
ret
.set_bit
___conversion_bitmap_set MON_TABLE
_LockPokemonID::
___conversion_table_lock_ID wPokemonIndexTable, MON_TABLE
_GetMoveIndexFromID::
___conversion_table_load wMoveIndexTable, MOVE_TABLE
_GetMoveIDFromIndex::
___conversion_table_store wMoveIndexTable, MOVE_TABLE
; fallthrough
MoveTableGarbageCollection:
; must preserve de and rSVBK
push de
ldh a, [rSVBK]
push af
ld a, 1
ldh [rSVBK], a
FOR ___move, NUM_MOVES
___conversion_bitmap_check_structs wPartyMon1Moves + ___move, PARTYMON_STRUCT_LENGTH, PARTY_LENGTH, .set_bit
___conversion_bitmap_check_structs wBreedMon1Moves + ___move, wBreedMon2 - wBreedMon1, 2, .set_bit
ld a, [wEggMonMoves + ___move]
call .set_bit
; may or may not be valid
___conversion_bitmap_check_structs wOTPartyMon1Moves + ___move, PARTYMON_STRUCT_LENGTH, PARTY_LENGTH, .set_bit
___conversion_bitmap_check_values .set_bit, wBufferMonMoves + ___move, wTempMonMoves + ___move, wContestMonMoves + ___move, \
wBattleMonMoves + ___move, wEnemyMonMoves + ___move, wWildMonMoves + ___move, \
wPlayerUsedMoves + ___move
endr
ld a, [wNamedObjectType] ;or any of its aliases...
call .set_bit
; only valid sometimes
___conversion_bitmap_check_values .set_bit, wCurPlayerMove, wCurEnemyMove, wDisabledMove, wEnemyDisabledMove, wUnusedPlayerLockedMove, \
wLastPlayerMove, wLastEnemyMove, wLastPlayerCounterMove, wLastEnemyCounterMove, \
wPlayerTrappingMove, wEnemyTrappingMove, wPlayerMoveStructAnimation, wEnemyMoveStructAnimation, \
wPutativeTMHMMove
pop af
ldh [rSVBK], a
ldh a, [hSRAMBank]
push af
ld a, BANK(sBox)
call OpenSRAM
FOR ___move, NUM_MOVES
___conversion_bitmap_check_structs sBoxMon1Moves + ___move, BOXMON_STRUCT_LENGTH, MONS_PER_BOX, .set_bit
endr
pop af
call OpenSRAM
___conversion_bitmap_free_unused wMoveIndexTable, MOVE_TABLE
pop de
ret
.set_bit
___conversion_bitmap_set MOVE_TABLE
_LockMoveID::
___conversion_table_lock_ID wMoveIndexTable, MOVE_TABLE