forked from pret/pokered
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathmap_objects.asm
More file actions
234 lines (212 loc) · 4.92 KB
/
map_objects.asm
File metadata and controls
234 lines (212 loc) · 4.92 KB
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
TextScript_ItemStoragePC::
call SaveScreenTilesToBuffer2
ld b, BANK(PlayerPC)
ld hl, PlayerPC
jr bankswitchAndContinue
TextScript_BillsPC::
call SaveScreenTilesToBuffer2
ld b, BANK(BillsPC_)
ld hl, BillsPC_
jr bankswitchAndContinue
TextScript_GameCornerPrizeMenu::
; XXX find a better name for this function
; special_F7
ld b, BANK(CeladonPrizeMenu)
ld hl, CeladonPrizeMenu
bankswitchAndContinue::
rst _Bankswitch
jp HoldTextDisplayOpen ; continue to main text-engine function
TextScript_PokemonCenterPC::
ld b, BANK(ActivatePC)
ld hl, ActivatePC
jr bankswitchAndContinue
StartSimulatingJoypadStates::
xor a
ld [wOverrideSimulatedJoypadStatesMask], a
ld [wSpritePlayerStateData2MovementByte1], a
ld hl, wStatusFlags5
set BIT_SCRIPTED_MOVEMENT_STATE, [hl]
ret
IsItemInBag::
; given an item_id in b
; set zero flag if item isn't in player's bag
; else reset zero flag
; related to Pokémon Tower and ghosts
predef GetQuantityOfItemInBag
ld a, b
and a
ret
DisplayPokedex::
ld [wPokedexNum], a
farjp _DisplayPokedex
SetSpriteFacingDirectionAndDelay::
call SetSpriteFacingDirection
ld c, 6
rst _DelayFrames
ret
SetSpriteFacingDirection::
ld a, SPRITESTATEDATA1_FACINGDIRECTION
ldh [hSpriteDataOffset], a
call GetPointerWithinSpriteStateData1
ldh a, [hSpriteFacingDirection]
ld [hl], a
ret
SetSpriteImageIndexAfterSettingFacingDirection::
ld de, SPRITESTATEDATA1_IMAGEINDEX - SPRITESTATEDATA1_FACINGDIRECTION
add hl, de
ld [hl], a
ret
; tests if the player's coordinates are in a specified array
; INPUT:
; hl = address of array
; OUTPUT:
; [wCoordIndex] = if there is match, the matching array index
; sets carry if the coordinates are in the array, clears carry if not
ArePlayerCoordsInArray::
ld a, [wYCoord]
ld b, a
ld a, [wXCoord]
ld c, a
; fallthrough
CheckCoords::
xor a
ld [wCoordIndex], a
.loop
ld a, [hli]
cp $ff ; reached terminator?
jr z, .notInArray
push hl
ld hl, wCoordIndex
inc [hl]
pop hl
.compareYCoord
cp b
jr z, .compareXCoord
inc hl
jr .loop
.compareXCoord
ld a, [hli]
cp c
jr nz, .loop
.inArray
scf
ret
.notInArray
and a
ret
; tests if a boulder's coordinates are in a specified array
; INPUT:
; hl = address of array
; [hSpriteIndex] = index of boulder sprite
; OUTPUT:
; [wCoordIndex] = if there is match, the matching array index
; sets carry if the coordinates are in the array, clears carry if not
CheckBoulderCoords::
push hl
ld hl, wSpritePlayerStateData2MapY
ldh a, [hSpriteIndex]
swap a
ld d, $0
ld e, a
add hl, de
ld a, [hli]
sub $4 ; because sprite coordinates are offset by 4
ld b, a
ld a, [hl]
sub $4 ; because sprite coordinates are offset by 4
ld c, a
pop hl
jp CheckCoords
GetFromSpriteStateData1::
ld a, c
ld h, HIGH(wSpriteStateData1)
jr _GetPointerWithinSpriteStateData.next
GetPointerWithinSpriteStateData1::
ld h, HIGH(wSpriteStateData1)
jr _GetPointerWithinSpriteStateData
GetFromSpriteStateData2::
ld a, c
ld h, HIGH(wSpriteStateData2)
jr _GetPointerWithinSpriteStateData.next
GetPointerWithinSpriteStateData2::
ld h, HIGH(wSpriteStateData2)
_GetPointerWithinSpriteStateData:
ldh a, [hSpriteDataOffset]
ld b, a
ldh a, [hSpriteIndex]
.next
swap a
add b
ld l, a
ret
; decodes a $ff-terminated RLEncoded list
; each entry is a pair of bytes <byte value> <repetitions>
; the final $ff will be replicated in the output list and a contains the number of bytes written
; de: input list
; hl: output list
DecodeRLEList::
xor a
ld [wRLEByteCount], a ; count written bytes here
.listLoop
ld a, [de]
cp $ff
jr z, .endOfList
ldh [hRLEByteValue], a ; store byte value to be written
inc de
ld a, [de]
ld b, $0
ld c, a ; number of bytes to be written
ld a, [wRLEByteCount]
add c
ld [wRLEByteCount], a ; update total number of written bytes
ldh a, [hRLEByteValue]
call FillMemory ; write a c-times to output
inc de
jr .listLoop
.endOfList
; PureRGBnote: OPTIMIZED
ld [hl], $ff
;ld a, $ff
;ld [hl], a ; write final $ff
ld a, [wRLEByteCount]
inc a ; include sentinel in counting
ret
; sets movement byte 1 for sprite [hSpriteIndex] to $FE and byte 2 to [hSpriteMovementByte2]
SetSpriteMovementBytesToFE::
push hl
call GetSpriteMovementByte1Pointer
ld [hl], $fe
call GetSpriteMovementByte2Pointer
ldh a, [hSpriteMovementByte2]
ld [hl], a
pop hl
ret
; sets both movement bytes for sprite [hSpriteIndex] to $FF
SetSpriteMovementBytesToFF::
push hl
call GetSpriteMovementByte1Pointer
ld [hl], STAY
call GetSpriteMovementByte2Pointer
ld [hl], NONE
pop hl
ret
; returns the sprite movement byte 1 pointer for sprite [hSpriteIndex] in hl
GetSpriteMovementByte1Pointer::
ld h, HIGH(wSpriteStateData2)
ldh a, [hSpriteIndex]
swap a
add 6
ld l, a
ret
; returns the sprite movement byte 2 pointer for sprite [hSpriteIndex] in hl
GetSpriteMovementByte2Pointer::
push de
ld hl, wMapSpriteData
ldh a, [hSpriteIndex]
dec a
add a
ld d, 0
ld e, a
add hl, de
pop de
ret