2018-06-24 07:09:41 -07:00
|
|
|
_HandlePlayerStep::
|
2015-12-24 19:58:42 -08:00
|
|
|
ld a, [wPlayerStepFlags]
|
|
|
|
and a
|
|
|
|
ret z
|
2019-01-24 18:41:14 -08:00
|
|
|
bit PLAYERSTEP_START_F, a
|
2015-12-24 19:58:42 -08:00
|
|
|
jr nz, .update_overworld_map
|
2019-01-24 18:41:14 -08:00
|
|
|
bit PLAYERSTEP_STOP_F, a
|
2015-12-24 19:58:42 -08:00
|
|
|
jr nz, .update_player_coords
|
2019-01-24 18:41:14 -08:00
|
|
|
bit PLAYERSTEP_CONTINUE_F, a
|
2015-12-24 19:58:42 -08:00
|
|
|
jr nz, .finish
|
|
|
|
ret
|
|
|
|
|
|
|
|
.update_overworld_map
|
|
|
|
ld a, 4
|
|
|
|
ld [wHandlePlayerStep], a
|
|
|
|
call UpdateOverworldMap
|
|
|
|
jr .finish
|
|
|
|
|
|
|
|
.update_player_coords
|
|
|
|
call UpdatePlayerCoords
|
|
|
|
jr .finish
|
|
|
|
|
|
|
|
.finish
|
|
|
|
call HandlePlayerStep
|
|
|
|
ld a, [wPlayerStepVectorX]
|
|
|
|
ld d, a
|
|
|
|
ld a, [wPlayerStepVectorY]
|
|
|
|
ld e, a
|
2016-05-04 19:34:09 -07:00
|
|
|
ld a, [wPlayerBGMapOffsetX]
|
2015-12-24 19:58:42 -08:00
|
|
|
sub d
|
2016-05-04 19:34:09 -07:00
|
|
|
ld [wPlayerBGMapOffsetX], a
|
|
|
|
ld a, [wPlayerBGMapOffsetY]
|
2015-12-24 19:58:42 -08:00
|
|
|
sub e
|
2016-05-04 19:34:09 -07:00
|
|
|
ld [wPlayerBGMapOffsetY], a
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ScrollScreen::
|
2015-12-24 19:58:42 -08:00
|
|
|
ld a, [wPlayerStepVectorX]
|
|
|
|
ld d, a
|
|
|
|
ld a, [wPlayerStepVectorY]
|
|
|
|
ld e, a
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh a, [hSCX]
|
2015-12-24 19:58:42 -08:00
|
|
|
add d
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSCX], a
|
|
|
|
ldh a, [hSCY]
|
2015-12-24 19:58:42 -08:00
|
|
|
add e
|
2018-08-25 11:28:22 -07:00
|
|
|
ldh [hSCY], a
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HandlePlayerStep:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld hl, wHandlePlayerStep
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
dec [hl]
|
|
|
|
ld a, [hl]
|
|
|
|
ld hl, .Jumptable
|
|
|
|
rst JumpTable
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.Jumptable:
|
2015-12-26 18:59:03 -08:00
|
|
|
dw GetMovementPermissions
|
|
|
|
dw BufferScreen
|
|
|
|
dw .mobile
|
|
|
|
dw .fail2
|
2015-12-24 19:58:42 -08:00
|
|
|
; The rest are never used. Ever.
|
2015-12-26 18:59:03 -08:00
|
|
|
dw .fail1
|
|
|
|
dw .fail1
|
|
|
|
dw .fail1
|
|
|
|
dw .fail1
|
|
|
|
dw .fail1
|
|
|
|
dw .fail1
|
|
|
|
dw .fail1
|
2015-12-24 19:58:42 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.fail1
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.mobile
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.fail2
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
UpdatePlayerCoords:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld a, [wPlayerStepDirection]
|
|
|
|
and a
|
|
|
|
jr nz, .check_step_down
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wYCoord
|
2015-12-24 19:58:42 -08:00
|
|
|
inc [hl]
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
|
|
|
ret nz
|
|
|
|
ld hl, wViewMapModeDisplacementY
|
|
|
|
inc [hl]
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.check_step_down
|
|
|
|
cp UP
|
|
|
|
jr nz, .check_step_left
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wYCoord
|
2015-12-24 19:58:42 -08:00
|
|
|
dec [hl]
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
|
|
|
ret nz
|
|
|
|
ld hl, wViewMapModeDisplacementY
|
|
|
|
dec [hl]
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.check_step_left
|
|
|
|
cp LEFT
|
|
|
|
jr nz, .check_step_right
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wXCoord
|
2015-12-24 19:58:42 -08:00
|
|
|
dec [hl]
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
|
|
|
ret nz
|
|
|
|
ld hl, wViewMapModeDisplacementX
|
|
|
|
dec [hl]
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.check_step_right
|
|
|
|
cp RIGHT
|
|
|
|
ret nz
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wXCoord
|
2015-12-24 19:58:42 -08:00
|
|
|
inc [hl]
|
2023-11-05 02:07:32 -08:00
|
|
|
ldh a, [hCurBoardEvent]
|
2023-10-31 12:25:56 -07:00
|
|
|
cp BOARDEVENT_VIEW_MAP_MODE
|
|
|
|
ret nz
|
|
|
|
ld hl, wViewMapModeDisplacementX
|
|
|
|
inc [hl]
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
UpdateOverworldMap:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld a, [wPlayerStepDirection]
|
|
|
|
and a
|
|
|
|
jr z, .step_down
|
|
|
|
cp UP
|
|
|
|
jr z, .step_up
|
|
|
|
cp LEFT
|
|
|
|
jr z, .step_left
|
|
|
|
cp RIGHT
|
|
|
|
jr z, .step_right
|
|
|
|
ret
|
|
|
|
|
|
|
|
.step_down
|
|
|
|
call .ScrollOverworldMapDown
|
2024-02-10 15:16:00 -08:00
|
|
|
call LoadOverworldTilemap
|
2019-06-06 14:59:13 -07:00
|
|
|
call ScrollMapDown
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.step_up
|
|
|
|
call .ScrollOverworldMapUp
|
2024-02-10 15:16:00 -08:00
|
|
|
call LoadOverworldTilemap
|
2019-06-06 14:59:13 -07:00
|
|
|
call ScrollMapUp
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.step_left
|
|
|
|
call .ScrollOverworldMapLeft
|
2024-02-10 15:16:00 -08:00
|
|
|
call LoadOverworldTilemap
|
2019-06-06 14:59:13 -07:00
|
|
|
call ScrollMapLeft
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
|
|
|
.step_right
|
|
|
|
call .ScrollOverworldMapRight
|
2024-02-10 15:16:00 -08:00
|
|
|
call LoadOverworldTilemap
|
2019-06-06 14:59:13 -07:00
|
|
|
call ScrollMapRight
|
2015-12-24 19:58:42 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.ScrollOverworldMapDown:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld a, [wBGMapAnchor]
|
|
|
|
add 2 * BG_MAP_WIDTH
|
|
|
|
ld [wBGMapAnchor], a
|
|
|
|
jr nc, .not_overflowed
|
|
|
|
ld a, [wBGMapAnchor + 1]
|
|
|
|
inc a
|
2018-01-11 09:00:01 -08:00
|
|
|
and %11
|
2017-12-28 04:32:33 -08:00
|
|
|
or HIGH(vBGMap0)
|
2015-12-24 19:58:42 -08:00
|
|
|
ld [wBGMapAnchor + 1], a
|
|
|
|
.not_overflowed
|
2022-09-12 06:15:44 -07:00
|
|
|
ld hl, wPlayerMetatileY
|
2015-12-24 19:58:42 -08:00
|
|
|
inc [hl]
|
|
|
|
ld a, [hl]
|
|
|
|
cp 2 ; was 1
|
|
|
|
jr nz, .done_down
|
|
|
|
ld [hl], 0
|
2019-06-06 14:59:13 -07:00
|
|
|
call .ScrollMapDataDown
|
2015-12-24 19:58:42 -08:00
|
|
|
.done_down
|
|
|
|
ret
|
|
|
|
|
2019-06-06 14:59:13 -07:00
|
|
|
.ScrollMapDataDown:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld hl, wOverworldMapAnchor
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapWidth]
|
2019-06-06 14:59:13 -07:00
|
|
|
add 3 * 2 ; surrounding tiles
|
2015-12-24 19:58:42 -08:00
|
|
|
add [hl]
|
|
|
|
ld [hli], a
|
|
|
|
ret nc
|
|
|
|
inc [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.ScrollOverworldMapUp:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld a, [wBGMapAnchor]
|
|
|
|
sub 2 * BG_MAP_WIDTH
|
|
|
|
ld [wBGMapAnchor], a
|
|
|
|
jr nc, .not_underflowed
|
|
|
|
ld a, [wBGMapAnchor + 1]
|
|
|
|
dec a
|
2018-01-11 09:00:01 -08:00
|
|
|
and %11
|
2017-12-28 04:32:33 -08:00
|
|
|
or HIGH(vBGMap0)
|
2015-12-24 19:58:42 -08:00
|
|
|
ld [wBGMapAnchor + 1], a
|
|
|
|
.not_underflowed
|
2022-09-12 06:15:44 -07:00
|
|
|
ld hl, wPlayerMetatileY
|
2015-12-24 19:58:42 -08:00
|
|
|
dec [hl]
|
|
|
|
ld a, [hl]
|
|
|
|
cp -1 ; was 0
|
|
|
|
jr nz, .done_up
|
|
|
|
ld [hl], $1
|
2019-06-06 14:59:13 -07:00
|
|
|
call .ScrollMapDataUp
|
2015-12-24 19:58:42 -08:00
|
|
|
.done_up
|
|
|
|
ret
|
|
|
|
|
2019-06-06 14:59:13 -07:00
|
|
|
.ScrollMapDataUp:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld hl, wOverworldMapAnchor
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wMapWidth]
|
2019-06-06 14:59:13 -07:00
|
|
|
add 3 * 2 ; surrounding tiles
|
2015-12-24 19:58:42 -08:00
|
|
|
ld b, a
|
|
|
|
ld a, [hl]
|
|
|
|
sub b
|
|
|
|
ld [hli], a
|
|
|
|
ret nc
|
|
|
|
dec [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.ScrollOverworldMapLeft:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld a, [wBGMapAnchor]
|
|
|
|
ld e, a
|
|
|
|
and $e0
|
|
|
|
ld d, a
|
|
|
|
ld a, e
|
|
|
|
sub $2
|
|
|
|
and $1f
|
|
|
|
or d
|
|
|
|
ld [wBGMapAnchor], a
|
2022-09-12 06:15:44 -07:00
|
|
|
ld hl, wPlayerMetatileX
|
2015-12-24 19:58:42 -08:00
|
|
|
dec [hl]
|
|
|
|
ld a, [hl]
|
|
|
|
cp -1
|
|
|
|
jr nz, .done_left
|
|
|
|
ld [hl], 1
|
2019-06-06 14:59:13 -07:00
|
|
|
call .ScrollMapDataLeft
|
2015-12-24 19:58:42 -08:00
|
|
|
.done_left
|
|
|
|
ret
|
|
|
|
|
2019-06-06 14:59:13 -07:00
|
|
|
.ScrollMapDataLeft:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld hl, wOverworldMapAnchor
|
|
|
|
ld a, [hl]
|
|
|
|
sub 1
|
|
|
|
ld [hli], a
|
|
|
|
ret nc
|
|
|
|
dec [hl]
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.ScrollOverworldMapRight:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld a, [wBGMapAnchor]
|
|
|
|
ld e, a
|
|
|
|
and $e0
|
|
|
|
ld d, a
|
|
|
|
ld a, e
|
|
|
|
add $2
|
|
|
|
and $1f
|
|
|
|
or d
|
|
|
|
ld [wBGMapAnchor], a
|
2022-09-12 06:15:44 -07:00
|
|
|
ld hl, wPlayerMetatileX
|
2015-12-24 19:58:42 -08:00
|
|
|
inc [hl]
|
|
|
|
ld a, [hl]
|
|
|
|
cp 2
|
|
|
|
jr nz, .done_right
|
|
|
|
ld [hl], 0
|
2019-06-06 14:59:13 -07:00
|
|
|
call .ScrollMapDataRight
|
2015-12-24 19:58:42 -08:00
|
|
|
.done_right
|
|
|
|
ret
|
|
|
|
|
2019-06-06 14:59:13 -07:00
|
|
|
.ScrollMapDataRight:
|
2015-12-24 19:58:42 -08:00
|
|
|
ld hl, wOverworldMapAnchor
|
|
|
|
ld a, [hl]
|
|
|
|
add 1
|
|
|
|
ld [hli], a
|
|
|
|
ret nc
|
|
|
|
inc [hl]
|
|
|
|
ret
|