pokecrystal-board/home/movement.asm

194 lines
2.6 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
InitMovementBuffer::
ld [wMovementBufferObject], a
xor a
ld [wMovementBufferCount], a
ld a, $0 ; useless
2017-12-09 16:41:03 -08:00
ld [wUnusedMovementBufferBank], a
2018-01-23 14:39:09 -08:00
ld a, LOW(wMovementBuffer)
2017-12-09 16:41:03 -08:00
ld [wUnusedMovementBufferPointer], a
2018-01-23 14:39:09 -08:00
ld a, HIGH(wMovementBuffer)
2017-12-09 16:41:03 -08:00
ld [wUnusedMovementBufferPointer + 1], a
ret
2018-06-24 07:09:41 -07:00
DecrementMovementBufferCount::
ld a, [wMovementBufferCount]
and a
ret z
dec a
ld [wMovementBufferCount], a
ret
2018-06-24 07:09:41 -07:00
AppendToMovementBuffer::
push hl
push de
ld hl, wMovementBufferCount
ld e, [hl]
inc [hl]
ld d, 0
2018-01-23 14:39:09 -08:00
ld hl, wMovementBuffer
add hl, de
ld [hl], a
pop de
pop hl
ret
2018-06-24 07:09:41 -07:00
AppendToMovementBufferNTimes::
push af
ld a, c
and a
jr nz, .okay
pop af
ret
.okay
pop af
.loop
call AppendToMovementBuffer
dec c
jr nz, .loop
ret
2018-06-24 07:09:41 -07:00
ComputePathToWalkToPlayer::
push af
; compare x coords, load left/right into h, and x distance into d
ld a, b
sub d
ld h, LEFT
jr nc, .got_x_distance
dec a
cpl
ld h, RIGHT
.got_x_distance
ld d, a
; compare y coords, load up/down into l, and y distance into e
ld a, c
sub e
ld l, UP
jr nc, .got_y_distance
dec a
cpl
ld l, DOWN
.got_y_distance
ld e, a
; if the x distance is less than the y distance, swap h and l, and swap d and e
cp d
jr nc, .done
ld a, h
ld h, l
ld l, a
ld a, d
ld d, e
ld e, a
.done
pop af
ld b, a
; Add movement in the longer direction first...
ld a, h
call .GetMovementData
ld c, d
call AppendToMovementBufferNTimes
; ... then add the shorter direction.
ld a, l
call .GetMovementData
ld c, e
call AppendToMovementBufferNTimes
ret
2018-06-24 07:09:41 -07:00
.GetMovementData:
push de
push hl
ld l, b
ld h, 0
add hl, hl
add hl, hl
ld e, a
ld d, 0
add hl, de
ld de, .MovementData
add hl, de
ld a, [hl]
pop hl
pop de
ret
.MovementData:
2016-05-14 10:46:14 -07:00
slow_step DOWN
slow_step UP
slow_step LEFT
slow_step RIGHT
step DOWN
step UP
step LEFT
step RIGHT
big_step DOWN
big_step UP
big_step LEFT
big_step RIGHT
2018-06-24 07:09:41 -07:00
SetMenuAttributes::
push hl
push bc
ld hl, w2DMenuCursorInitY
ld b, $8
2015-11-18 20:16:25 -08:00
.loop
ld a, [de]
inc de
ld [hli], a
dec b
2015-11-18 20:16:25 -08:00
jr nz, .loop
ld a, $1
ld [hli], a
ld [hli], a
xor a
ld [hli], a
ld [hli], a
ld [hli], a
pop bc
pop hl
ret
2018-06-24 07:09:41 -07:00
StaticMenuJoypad::
2017-12-24 09:47:30 -08:00
callfar _StaticMenuJoypad
2015-12-15 15:59:49 -08:00
call GetMenuJoypad
ret
2018-06-24 07:09:41 -07:00
ScrollingMenuJoypad::
2017-12-24 09:47:30 -08:00
callfar _ScrollingMenuJoypad
2015-12-15 15:59:49 -08:00
call GetMenuJoypad
ret
2018-06-24 07:09:41 -07:00
GetMenuJoypad::
push bc
push af
2015-10-16 10:35:43 -07:00
ld a, [hJoyLast]
and D_PAD
ld b, a
ld a, [hJoyPressed]
2015-10-16 10:35:43 -07:00
and BUTTONS
or b
ld b, a
pop af
ld a, b
pop bc
ret
2018-06-24 07:09:41 -07:00
PlaceHollowCursor::
2015-12-15 15:59:49 -08:00
ld hl, wCursorCurrentTile
ld a, [hli]
ld h, [hl]
ld l, a
2015-12-15 15:59:49 -08:00
ld [hl], "▷"
ret
2018-06-24 07:09:41 -07:00
HideCursor::
2015-12-15 15:59:49 -08:00
ld hl, wCursorCurrentTile
ld a, [hli]
ld h, [hl]
ld l, a
2015-12-15 15:59:49 -08:00
ld [hl], " "
ret