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
|
_AdvancePlayerSprite::
ld a, [wSpritePlayerStateData1YStepVector]
ld b, a
ld a, [wSpritePlayerStateData1XStepVector]
ld c, a
ld hl, wWalkCounter ; walking animation counter
dec [hl]
jr nz, .afterUpdateMapCoords
; if it's the end of the animation, update the player's map coordinates
ld hl, wPikachuOverworldStateFlags
res 5, [hl]
ld a, [wYCoord]
add b
ld [wYCoord], a
ld a, [wXCoord]
add c
ld [wXCoord], a
.afterUpdateMapCoords
ld a, [wWalkCounter] ; walking animation counter
cp $07
jp nz, .scrollBackgroundAndSprites
; if this is the first iteration of the animation
ld a, c
cp $01
jr nz, .checkIfMovingWest
; moving east
ld a, [wMapViewVRAMPointer]
ld e, a
and $e0
ld d, a
ld a, e
add $02
and $1f
or d
ld [wMapViewVRAMPointer], a
jr .adjustXCoordWithinBlock
.checkIfMovingWest
cp $ff
jr nz, .checkIfMovingSouth
; moving west
ld a, [wMapViewVRAMPointer]
ld e, a
and $e0
ld d, a
ld a, e
sub $02
and $1f
or d
ld [wMapViewVRAMPointer], a
jr .adjustXCoordWithinBlock
.checkIfMovingSouth
ld a, b
cp $01
jr nz, .checkIfMovingNorth
; moving south
ld a, [wMapViewVRAMPointer]
add $40
ld [wMapViewVRAMPointer], a
jr nc, .adjustXCoordWithinBlock
ld a, [wMapViewVRAMPointer + 1]
inc a
and $03
or $98
ld [wMapViewVRAMPointer + 1], a
jr .adjustXCoordWithinBlock
.checkIfMovingNorth
cp $ff
jr nz, .adjustXCoordWithinBlock
; moving north
ld a, [wMapViewVRAMPointer]
sub $40
ld [wMapViewVRAMPointer], a
jr nc, .adjustXCoordWithinBlock
ld a, [wMapViewVRAMPointer + 1]
dec a
and $03
or $98
ld [wMapViewVRAMPointer + 1], a
.adjustXCoordWithinBlock
ld a, c
and a
jr z, .pointlessJump ; mistake?
.pointlessJump
ld hl, wXBlockCoord
ld a, [hl]
add c
ld [hl], a
cp $02
jr nz, .checkForMoveToWestBlock
; moved into the tile block to the east
xor a
ld [hl], a
ld hl, wXOffsetSinceLastSpecialWarp
inc [hl]
ld de, wCurrentTileBlockMapViewPointer
call MoveTileBlockMapPointerEast
jr .updateMapView
.checkForMoveToWestBlock
cp $ff
jr nz, .adjustYCoordWithinBlock
; moved into the tile block to the west
ld a, $01
ld [hl], a
ld hl, wXOffsetSinceLastSpecialWarp
dec [hl]
ld de, wCurrentTileBlockMapViewPointer
call MoveTileBlockMapPointerWest
jr .updateMapView
.adjustYCoordWithinBlock
ld hl, wYBlockCoord
ld a, [hl]
add b
ld [hl], a
cp $02
jr nz, .checkForMoveToNorthBlock
; moved into the tile block to the south
xor a
ld [hl], a
ld hl, wYOffsetSinceLastSpecialWarp
inc [hl]
ld de, wCurrentTileBlockMapViewPointer
ld a, [wCurMapWidth]
call MoveTileBlockMapPointerSouth
jr .updateMapView
.checkForMoveToNorthBlock
cp $ff
jr nz, .updateMapView
; moved into the tile block to the north
ld a, $01
ld [hl], a
ld hl, wYOffsetSinceLastSpecialWarp
dec [hl]
ld de, wCurrentTileBlockMapViewPointer
ld a, [wCurMapWidth]
call MoveTileBlockMapPointerNorth
.updateMapView
call LoadCurrentMapView
ld a, [wSpritePlayerStateData1YStepVector]
cp $01
jr nz, .checkIfMovingNorth2
; if moving south
call ScheduleSouthRowRedraw
jr .scrollBackgroundAndSprites
.checkIfMovingNorth2
cp $ff
jr nz, .checkIfMovingEast2
; if moving north
call ScheduleNorthRowRedraw
jr .scrollBackgroundAndSprites
.checkIfMovingEast2
ld a, [wSpritePlayerStateData1XStepVector]
cp $01
jr nz, .checkIfMovingWest2
; if moving east
call ScheduleEastColumnRedraw
jr .scrollBackgroundAndSprites
.checkIfMovingWest2
cp $ff
jr nz, .scrollBackgroundAndSprites
; if moving west
call ScheduleWestColumnRedraw
.scrollBackgroundAndSprites
ld a, [wSpritePlayerStateData1YStepVector]
add a
ld b, a
ld a, [wSpritePlayerStateData1XStepVector]
add a
ld c, a
; shift all the sprites in the direction opposite of the player's motion
; so that the player appears to move relative to them
ld hl, wSprite01StateData1YPixels
ld e, 15
.spriteShiftLoop
ld a, [hl]
sub b
ld [hli], a
inc l
ld a, [hl]
sub c
ld [hl], a
ld a, $0e
add l
ld l, a
dec e
jr nz, .spriteShiftLoop
.done
ldh a, [hSCY]
add b
ldh [hSCY], a ; update background scroll Y
ldh a, [hSCX]
add c
ldh [hSCX], a ; update background scroll X
ret
; the following four functions are used to move the pointer to the upper left
; corner of the tile block map in the direction of motion
MoveTileBlockMapPointerEast::
ld a, [de]
add $01
ld [de], a
ret nc
inc de
ld a, [de]
inc a
ld [de], a
ret
MoveTileBlockMapPointerWest::
ld a, [de]
sub $01
ld [de], a
ret nc
inc de
ld a, [de]
dec a
ld [de], a
ret
MoveTileBlockMapPointerSouth::
add MAP_BORDER * 2
ld b, a
ld a, [de]
add b
ld [de], a
ret nc
inc de
ld a, [de]
inc a
ld [de], a
ret
MoveTileBlockMapPointerNorth::
add MAP_BORDER * 2
ld b, a
ld a, [de]
sub b
ld [de], a
ret nc
inc de
ld a, [de]
dec a
ld [de], a
ret
|