Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/home/map_objects.asm
1270 views
1
; checks if the player's coordinates match an arrow movement tile's coordinates
2
; and if so, decodes the RLE movement data
3
; b = player Y
4
; c = player X
5
DecodeArrowMovementRLE::
6
ld a, [hli]
7
cp $ff
8
ret z ; no match in the list
9
cp b
10
jr nz, .nextArrowMovementTileEntry1
11
ld a, [hli]
12
cp c
13
jr nz, .nextArrowMovementTileEntry2
14
ld a, [hli]
15
ld d, [hl]
16
ld e, a
17
ld hl, wSimulatedJoypadStatesEnd
18
call DecodeRLEList
19
dec a
20
ld [wSimulatedJoypadStatesIndex], a
21
ret
22
.nextArrowMovementTileEntry1
23
inc hl
24
.nextArrowMovementTileEntry2
25
inc hl
26
inc hl
27
jr DecodeArrowMovementRLE
28
29
TextScript_ItemStoragePC::
30
call SaveScreenTilesToBuffer2
31
ld b, BANK(PlayerPC)
32
ld hl, PlayerPC
33
jr BankswitchAndContinue
34
35
TextScript_BillsPC::
36
call SaveScreenTilesToBuffer2
37
ld b, BANK(BillsPC_)
38
ld hl, BillsPC_
39
jr BankswitchAndContinue
40
41
TextScript_GameCornerPrizeMenu::
42
ld b, BANK(CeladonPrizeMenu)
43
ld hl, CeladonPrizeMenu
44
BankswitchAndContinue::
45
call Bankswitch
46
jp HoldTextDisplayOpen ; continue to main text-engine function
47
48
TextScript_PokemonCenterPC::
49
ld b, BANK(ActivatePC)
50
ld hl, ActivatePC
51
jr BankswitchAndContinue
52
53
StartSimulatingJoypadStates::
54
xor a
55
ld [wOverrideSimulatedJoypadStatesMask], a
56
ld [wSpritePlayerStateData2MovementByte1], a
57
ld hl, wStatusFlags5
58
set BIT_SCRIPTED_MOVEMENT_STATE, [hl]
59
ret
60
61
IsItemInBag::
62
; given an item_id in b
63
; set zero flag if item isn't in player's bag
64
; else reset zero flag
65
; related to Pokémon Tower and ghosts
66
predef GetQuantityOfItemInBag
67
ld a, b
68
and a
69
ret
70
71
DisplayPokedex::
72
ld [wPokedexNum], a
73
farjp _DisplayPokedex
74
75
SetSpriteFacingDirectionAndDelay::
76
call SetSpriteFacingDirection
77
ld c, 6
78
jp DelayFrames
79
80
SetSpriteFacingDirection::
81
ld a, SPRITESTATEDATA1_FACINGDIRECTION
82
ldh [hSpriteDataOffset], a
83
call GetPointerWithinSpriteStateData1
84
ldh a, [hSpriteFacingDirection]
85
ld [hl], a
86
ret
87
88
SetSpriteImageIndexAfterSettingFacingDirection::
89
ld de, SPRITESTATEDATA1_IMAGEINDEX - SPRITESTATEDATA1_FACINGDIRECTION
90
add hl, de
91
ld [hl], a
92
ret
93
94
; tests if the player's coordinates are in a specified array
95
; INPUT:
96
; hl = address of array
97
; OUTPUT:
98
; [wCoordIndex] = if there is match, the matching array index
99
; sets carry if the coordinates are in the array, clears carry if not
100
ArePlayerCoordsInArray::
101
ld a, [wYCoord]
102
ld b, a
103
ld a, [wXCoord]
104
ld c, a
105
; fallthrough
106
107
CheckCoords::
108
xor a
109
ld [wCoordIndex], a
110
.loop
111
ld a, [hli]
112
cp $ff ; reached terminator?
113
jr z, .notInArray
114
push hl
115
ld hl, wCoordIndex
116
inc [hl]
117
pop hl
118
.compareYCoord
119
cp b
120
jr z, .compareXCoord
121
inc hl
122
jr .loop
123
.compareXCoord
124
ld a, [hli]
125
cp c
126
jr nz, .loop
127
.inArray
128
scf
129
ret
130
.notInArray
131
and a
132
ret
133
134
; tests if a boulder's coordinates are in a specified array
135
; INPUT:
136
; hl = address of array
137
; [hSpriteIndex] = index of boulder sprite
138
; OUTPUT:
139
; [wCoordIndex] = if there is match, the matching array index
140
; sets carry if the coordinates are in the array, clears carry if not
141
CheckBoulderCoords::
142
push hl
143
ld hl, wSpritePlayerStateData2MapY
144
ldh a, [hSpriteIndex]
145
swap a
146
ld d, $0
147
ld e, a
148
add hl, de
149
ld a, [hli]
150
sub $4 ; because sprite coordinates are offset by 4
151
ld b, a
152
ld a, [hl]
153
sub $4 ; because sprite coordinates are offset by 4
154
ld c, a
155
pop hl
156
jp CheckCoords
157
158
GetPointerWithinSpriteStateData1::
159
ld h, HIGH(wSpriteStateData1)
160
jr _GetPointerWithinSpriteStateData
161
162
GetPointerWithinSpriteStateData2::
163
ld h, HIGH(wSpriteStateData2)
164
165
_GetPointerWithinSpriteStateData:
166
ldh a, [hSpriteDataOffset]
167
ld b, a
168
ldh a, [hSpriteIndex]
169
swap a
170
add b
171
ld l, a
172
ret
173
174
; decodes a $ff-terminated RLEncoded list
175
; each entry is a pair of bytes <byte value> <repetitions>
176
; the final $ff will be replicated in the output list and a contains the number of bytes written
177
; de: input list
178
; hl: output list
179
DecodeRLEList::
180
xor a
181
ld [wRLEByteCount], a ; count written bytes here
182
.listLoop
183
ld a, [de]
184
cp $ff
185
jr z, .endOfList
186
ldh [hRLEByteValue], a ; store byte value to be written
187
inc de
188
ld a, [de]
189
ld b, $0
190
ld c, a ; number of bytes to be written
191
ld a, [wRLEByteCount]
192
add c
193
ld [wRLEByteCount], a ; update total number of written bytes
194
ldh a, [hRLEByteValue]
195
call FillMemory ; write a c-times to output
196
inc de
197
jr .listLoop
198
.endOfList
199
ld a, $ff
200
ld [hl], a ; write final $ff
201
ld a, [wRLEByteCount]
202
inc a ; include sentinel in counting
203
ret
204
205
; sets movement byte 1 for sprite [hSpriteIndex] to $FE and byte 2 to [hSpriteMovementByte2]
206
SetSpriteMovementBytesToFE::
207
push hl
208
call GetSpriteMovementByte1Pointer
209
ld [hl], $fe
210
call GetSpriteMovementByte2Pointer
211
ldh a, [hSpriteMovementByte2]
212
ld [hl], a
213
pop hl
214
ret
215
216
; sets both movement bytes for sprite [hSpriteIndex] to $FF
217
SetSpriteMovementBytesToFF::
218
push hl
219
call GetSpriteMovementByte1Pointer
220
ld [hl], STAY
221
call GetSpriteMovementByte2Pointer
222
ld [hl], NONE
223
pop hl
224
ret
225
226
; returns the sprite movement byte 1 pointer for sprite [hSpriteIndex] in hl
227
GetSpriteMovementByte1Pointer::
228
ld h, HIGH(wSpriteStateData2)
229
ldh a, [hSpriteIndex]
230
swap a
231
add 6
232
ld l, a
233
ret
234
235
; returns the sprite movement byte 2 pointer for sprite [hSpriteIndex] in hl
236
GetSpriteMovementByte2Pointer::
237
push de
238
ld hl, wMapSpriteData
239
ldh a, [hSpriteIndex]
240
dec a
241
add a
242
ld d, 0
243
ld e, a
244
add hl, de
245
pop de
246
ret
247
248