pokecrystal-board/engine/events/elevator.asm

216 lines
3.1 KiB
NASM
Raw Normal View History

2018-06-24 07:09:41 -07:00
Elevator::
2015-12-17 14:51:32 -08:00
call .LoadPointer
call .FindCurrentFloor
jr c, .quit
ld [wElevatorOriginFloor], a
call Elevator_AskWhichFloor
jr c, .quit
ld hl, wElevatorOriginFloor
2015-11-11 13:11:08 -08:00
cp [hl]
2015-12-17 14:51:32 -08:00
jr z, .quit
call Elevator_GoToFloor
2015-11-11 13:11:08 -08:00
and a
ret
2015-12-17 14:51:32 -08:00
.quit
2015-11-11 13:11:08 -08:00
scf
ret
2018-06-24 07:09:41 -07:00
.LoadPointer:
2015-11-11 13:11:08 -08:00
ld a, b
2015-12-17 14:51:32 -08:00
ld [wElevatorPointerBank], a
2015-11-11 13:11:08 -08:00
ld a, e
2017-12-09 19:24:43 -08:00
ld [wElevatorPointer], a
2015-11-11 13:11:08 -08:00
ld a, d
2017-12-09 19:24:43 -08:00
ld [wElevatorPointer + 1], a
2015-12-17 14:51:32 -08:00
call .LoadFloors
2015-11-11 13:11:08 -08:00
ret
2018-06-24 07:09:41 -07:00
.LoadFloors:
2018-01-23 14:39:09 -08:00
ld de, wCurElevator
ld bc, wElevatorDataEnd - wElevatorData
2017-12-09 19:24:43 -08:00
ld hl, wElevatorPointer
2015-11-11 13:11:08 -08:00
ld a, [hli]
ld h, [hl]
ld l, a
2015-12-17 14:51:32 -08:00
ld a, [wElevatorPointerBank]
2015-11-11 13:11:08 -08:00
call GetFarByte
inc hl
ld [de], a
inc de
2015-12-17 14:51:32 -08:00
.loop
ld a, [wElevatorPointerBank]
2015-11-11 13:11:08 -08:00
call GetFarByte
ld [de], a
inc de
add hl, bc
2015-12-17 14:51:32 -08:00
cp -1
jr nz, .loop
2015-11-11 13:11:08 -08:00
ret
2018-06-24 07:09:41 -07:00
.FindCurrentFloor:
2017-12-09 19:24:43 -08:00
ld hl, wElevatorPointer
2015-11-11 13:11:08 -08:00
ld a, [hli]
ld h, [hl]
ld l, a
2015-12-17 14:51:32 -08:00
ld a, [wElevatorPointerBank]
2015-11-11 13:11:08 -08:00
call GetFarByte
ld c, a
inc hl
2018-01-23 14:39:09 -08:00
ld a, [wBackupMapGroup]
2015-11-11 13:11:08 -08:00
ld d, a
2018-01-23 14:39:09 -08:00
ld a, [wBackupMapNumber]
2015-11-11 13:11:08 -08:00
ld e, a
2015-12-17 14:51:32 -08:00
ld b, 0
.loop2
ld a, [wElevatorPointerBank]
2015-11-11 13:11:08 -08:00
call GetFarByte
2015-12-17 14:51:32 -08:00
cp -1
jr z, .fail
2015-11-11 13:11:08 -08:00
inc hl
inc hl
2015-12-17 14:51:32 -08:00
ld a, [wElevatorPointerBank]
2015-11-11 13:11:08 -08:00
call GetFarByte
inc hl
cp d
2015-12-17 14:51:32 -08:00
jr nz, .next1
ld a, [wElevatorPointerBank]
2015-11-11 13:11:08 -08:00
call GetFarByte
inc hl
cp e
2015-12-17 14:51:32 -08:00
jr nz, .next2
jr .done
2015-11-11 13:11:08 -08:00
2015-12-17 14:51:32 -08:00
.next1
2015-11-11 13:11:08 -08:00
inc hl
2015-12-17 14:51:32 -08:00
.next2
2015-11-11 13:11:08 -08:00
inc b
2015-12-17 14:51:32 -08:00
jr .loop2
2015-11-11 13:11:08 -08:00
2015-12-17 14:51:32 -08:00
.done
2015-11-11 13:11:08 -08:00
xor a
ld a, b
ret
2015-12-17 14:51:32 -08:00
.fail
2015-11-11 13:11:08 -08:00
scf
ret
2018-06-24 07:09:41 -07:00
Elevator_GoToFloor:
2015-11-11 13:11:08 -08:00
push af
2017-12-09 19:24:43 -08:00
ld hl, wElevatorPointer
2015-11-11 13:11:08 -08:00
ld a, [hli]
ld h, [hl]
ld l, a
inc hl
pop af
ld bc, wElevatorDataEnd - wElevatorData
2015-11-11 13:11:08 -08:00
call AddNTimes
inc hl
2018-01-23 14:39:09 -08:00
ld de, wBackupWarpNumber
2015-12-17 14:51:32 -08:00
ld a, [wElevatorPointerBank]
ld bc, wElevatorDataEnd - wElevatorData - 1
2015-11-11 13:11:08 -08:00
call FarCopyBytes
ret
2018-06-24 07:09:41 -07:00
Elevator_AskWhichFloor:
call LoadStandardMenuHeader
ld hl, AskFloorElevatorText
2015-11-11 13:11:08 -08:00
call PrintText
call Elevator_GetCurrentFloorText
ld hl, Elevator_MenuHeader
call CopyMenuHeader
2015-11-17 12:54:03 -08:00
call InitScrollingMenu
2015-11-11 13:11:08 -08:00
call UpdateSprites
xor a
2015-11-23 13:04:53 -08:00
ld [wMenuScrollPosition], a
2015-12-17 19:31:16 -08:00
call ScrollingMenu
call CloseWindow
2015-12-15 15:59:49 -08:00
ld a, [wMenuJoypad]
2015-12-17 14:51:32 -08:00
cp B_BUTTON
jr z, .cancel
2015-11-11 13:11:08 -08:00
xor a
2015-12-17 14:51:32 -08:00
ld a, [wScrollingMenuCursorPosition]
2015-11-11 13:11:08 -08:00
ret
2015-12-17 14:51:32 -08:00
.cancel
2015-11-11 13:11:08 -08:00
scf
ret
AskFloorElevatorText:
text_far _AskFloorElevatorText
text_end
2015-11-11 13:11:08 -08:00
2018-06-24 07:09:41 -07:00
Elevator_GetCurrentFloorText:
2018-01-23 14:39:09 -08:00
ld hl, wOptions
2015-11-11 13:11:08 -08:00
ld a, [hl]
push af
set NO_TEXT_SCROLL, [hl]
hlcoord 0, 0
ld b, 4
ld c, 8
2019-04-08 05:15:10 -07:00
call Textbox
2015-11-11 13:11:08 -08:00
hlcoord 1, 2
ld de, Elevator_CurrentFloorText
call PlaceString
hlcoord 4, 4
call Elevator_GetCurrentFloorString
pop af
2018-01-23 14:39:09 -08:00
ld [wOptions], a
2015-11-11 13:11:08 -08:00
ret
2018-06-24 07:09:41 -07:00
Elevator_CurrentFloorText:
2015-11-11 13:11:08 -08:00
db "Now on:@"
2018-06-24 07:09:41 -07:00
Elevator_GetCurrentFloorString:
2015-11-11 13:11:08 -08:00
push hl
2015-12-17 14:51:32 -08:00
ld a, [wElevatorOriginFloor]
2015-11-11 13:11:08 -08:00
ld e, a
ld d, 0
2018-01-23 14:39:09 -08:00
ld hl, wCurElevatorFloors
2015-11-11 13:11:08 -08:00
add hl, de
ld a, [hl]
pop de
call GetFloorString
ret
Elevator_MenuHeader:
db MENU_BACKUP_TILES ; flags
menu_coords 12, 1, 18, 9
dw Elevator_MenuData
2015-11-11 13:11:08 -08:00
db 1 ; default option
Elevator_MenuData:
db SCROLLINGMENU_DISPLAY_ARROWS ; flags
2015-11-11 13:11:08 -08:00
db 4, 0 ; rows, columns
db SCROLLINGMENU_ITEMS_NORMAL ; item format
2018-01-23 14:39:09 -08:00
dbw 0, wCurElevator
2018-01-10 22:45:27 -08:00
dba GetElevatorFloorStrings
2015-11-11 13:11:08 -08:00
dba NULL
dba NULL
2018-06-24 07:09:41 -07:00
GetElevatorFloorStrings:
2018-01-23 14:39:09 -08:00
ld a, [wMenuSelection]
2018-06-24 07:09:41 -07:00
GetFloorString:
2015-11-11 13:11:08 -08:00
push de
call FloorToString
ld d, h
ld e, l
pop hl
jp PlaceString
2018-06-24 07:09:41 -07:00
FloorToString:
2015-11-11 13:11:08 -08:00
push de
ld e, a
ld d, 0
2018-01-10 22:45:27 -08:00
ld hl, ElevatorFloorNames
2015-11-11 13:11:08 -08:00
add hl, de
add hl, de
2015-11-11 13:11:08 -08:00
ld a, [hli]
ld h, [hl]
ld l, a
pop de
ret
2018-01-25 19:19:24 -08:00
INCLUDE "data/events/elevator_floors.asm"