2018-06-24 07:09:41 -07:00
|
|
|
InitMovementBuffer::
|
2017-12-24 10:46:34 -08:00
|
|
|
ld [wMovementBufferObject], a
|
2013-11-26 03:44:05 -08:00
|
|
|
xor a
|
2015-11-09 20:01:45 -08:00
|
|
|
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
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
DecrementMovementBufferCount::
|
2015-11-09 20:01:45 -08:00
|
|
|
ld a, [wMovementBufferCount]
|
2013-11-26 03:44:05 -08:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
dec a
|
2015-11-09 20:01:45 -08:00
|
|
|
ld [wMovementBufferCount], a
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
AppendToMovementBuffer::
|
2013-11-26 03:44:05 -08:00
|
|
|
push hl
|
|
|
|
push de
|
2015-11-09 20:01:45 -08:00
|
|
|
ld hl, wMovementBufferCount
|
2013-11-26 03:44:05 -08:00
|
|
|
ld e, [hl]
|
|
|
|
inc [hl]
|
|
|
|
ld d, 0
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wMovementBuffer
|
2013-11-26 03:44:05 -08:00
|
|
|
add hl, de
|
|
|
|
ld [hl], a
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
AppendToMovementBufferNTimes::
|
2013-11-26 03:44:05 -08:00
|
|
|
push af
|
|
|
|
ld a, c
|
|
|
|
and a
|
2015-11-09 20:01:45 -08:00
|
|
|
jr nz, .okay
|
2013-11-26 03:44:05 -08:00
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
2015-11-09 20:01:45 -08:00
|
|
|
.okay
|
2013-11-26 03:44:05 -08:00
|
|
|
pop af
|
2015-11-09 20:01:45 -08:00
|
|
|
.loop
|
|
|
|
call AppendToMovementBuffer
|
2013-11-26 03:44:05 -08:00
|
|
|
dec c
|
2015-11-09 20:01:45 -08:00
|
|
|
jr nz, .loop
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
ComputePathToWalkToPlayer::
|
2013-11-26 03:44:05 -08:00
|
|
|
push af
|
2015-11-09 20:01:45 -08:00
|
|
|
; compare x coords, load left/right into h, and x distance into d
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, b
|
|
|
|
sub d
|
2015-11-09 20:01:45 -08:00
|
|
|
ld h, LEFT
|
|
|
|
jr nc, .got_x_distance
|
2013-11-26 03:44:05 -08:00
|
|
|
dec a
|
|
|
|
cpl
|
2015-11-09 20:01:45 -08:00
|
|
|
ld h, RIGHT
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2015-11-09 20:01:45 -08:00
|
|
|
.got_x_distance
|
2013-11-26 03:44:05 -08:00
|
|
|
ld d, a
|
2015-11-09 20:01:45 -08:00
|
|
|
; compare y coords, load up/down into l, and y distance into e
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, c
|
|
|
|
sub e
|
2015-11-09 20:01:45 -08:00
|
|
|
ld l, UP
|
|
|
|
jr nc, .got_y_distance
|
2013-11-26 03:44:05 -08:00
|
|
|
dec a
|
|
|
|
cpl
|
2015-11-09 20:01:45 -08:00
|
|
|
ld l, DOWN
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2015-11-09 20:01:45 -08:00
|
|
|
.got_y_distance
|
2013-11-26 03:44:05 -08:00
|
|
|
ld e, a
|
2015-11-09 20:01:45 -08:00
|
|
|
; if the x distance is less than the y distance, swap h and l, and swap d and e
|
2013-11-26 03:44:05 -08:00
|
|
|
cp d
|
2015-11-09 20:01:45 -08:00
|
|
|
jr nc, .done
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, h
|
|
|
|
ld h, l
|
|
|
|
ld l, a
|
|
|
|
ld a, d
|
|
|
|
ld d, e
|
|
|
|
ld e, a
|
|
|
|
|
2015-11-09 20:01:45 -08:00
|
|
|
.done
|
2013-11-26 03:44:05 -08:00
|
|
|
pop af
|
|
|
|
ld b, a
|
2015-11-09 20:01:45 -08:00
|
|
|
; Add movement in the longer direction first...
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, h
|
2015-11-09 20:01:45 -08:00
|
|
|
call .GetMovementData
|
2013-11-26 03:44:05 -08:00
|
|
|
ld c, d
|
2015-11-09 20:01:45 -08:00
|
|
|
call AppendToMovementBufferNTimes
|
|
|
|
; ... then add the shorter direction.
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, l
|
2015-11-09 20:01:45 -08:00
|
|
|
call .GetMovementData
|
2013-11-26 03:44:05 -08:00
|
|
|
ld c, e
|
2015-11-09 20:01:45 -08:00
|
|
|
call AppendToMovementBufferNTimes
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.GetMovementData:
|
2013-11-26 03:44:05 -08:00
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
ld l, b
|
|
|
|
ld h, 0
|
|
|
|
add hl, hl
|
2016-05-04 08:46:23 -07:00
|
|
|
add hl, hl
|
2013-11-26 03:44:05 -08:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
|
|
|
add hl, de
|
2015-11-09 20:01:45 -08:00
|
|
|
ld de, .MovementData
|
2013-11-26 03:44:05 -08:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2016-04-10 11:42:14 -07:00
|
|
|
.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
|
2013-11-26 03:44:05 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
SetMenuAttributes::
|
2013-11-26 03:44:05 -08:00
|
|
|
push hl
|
|
|
|
push bc
|
2015-12-17 10:49:26 -08:00
|
|
|
ld hl, w2DMenuCursorInitY
|
2013-11-26 03:44:05 -08:00
|
|
|
ld b, $8
|
2015-11-18 20:16:25 -08:00
|
|
|
.loop
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, [de]
|
|
|
|
inc de
|
|
|
|
ld [hli], a
|
|
|
|
dec b
|
2015-11-18 20:16:25 -08:00
|
|
|
jr nz, .loop
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, $1
|
|
|
|
ld [hli], a
|
2016-05-04 08:46:23 -07:00
|
|
|
ld [hli], a
|
2013-11-26 03:44:05 -08:00
|
|
|
xor a
|
|
|
|
ld [hli], a
|
2016-05-10 09:31:49 -07:00
|
|
|
ld [hli], a
|
|
|
|
ld [hli], a
|
2013-11-26 03:44:05 -08:00
|
|
|
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
|
2013-11-26 03:44:05 -08:00
|
|
|
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
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
GetMenuJoypad::
|
2013-11-26 03:44:05 -08:00
|
|
|
push bc
|
|
|
|
push af
|
2015-10-16 10:35:43 -07:00
|
|
|
ld a, [hJoyLast]
|
|
|
|
and D_PAD
|
2013-11-26 03:44:05 -08:00
|
|
|
ld b, a
|
|
|
|
ld a, [hJoyPressed]
|
2015-10-16 10:35:43 -07:00
|
|
|
and BUTTONS
|
2013-11-26 03:44:05 -08:00
|
|
|
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
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [hl], "▷"
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
HideCursor::
|
2015-12-15 15:59:49 -08:00
|
|
|
ld hl, wCursorCurrentTile
|
2013-11-26 03:44:05 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a
|
2015-12-15 15:59:49 -08:00
|
|
|
ld [hl], " "
|
2013-11-26 03:44:05 -08:00
|
|
|
ret
|
|
|
|
|