summaryrefslogtreecommitdiff
path: root/engine/events/elevator.asm
blob: 001122fb939a72f080576f58694c99e219d7fdbd (plain)
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
Elevator::
	call .LoadPointer
	call .FindCurrentFloor
	jr c, .quit
	ld [wElevatorOriginFloor], a
	call Elevator_AskWhichFloor
	jr c, .quit
	ld hl, wElevatorOriginFloor
	cp [hl]
	jr z, .quit
	call Elevator_GoToFloor
	and a
	ret

.quit
	scf
	ret

.LoadPointer:
	ld a, b
	ld [wElevatorPointerBank], a
	ld a, e
	ld [wElevatorPointer], a
	ld a, d
	ld [wElevatorPointer + 1], a
	call .LoadFloors
	ret

.LoadFloors:
	ld de, wCurElevatorCount
	ld bc, wElevatorDataEnd - wElevatorData
	ld hl, wElevatorPointer
	ld a, [hli]
	ld h, [hl]
	ld l, a
	ld a, [wElevatorPointerBank]
	call GetFarByte
	inc hl
	ld [de], a
	inc de
	assert wCurElevatorCount + 1 == wCurElevatorFloors
.loop
	ld a, [wElevatorPointerBank]
	call GetFarByte
	ld [de], a
	inc de
	add hl, bc
	cp -1
	jr nz, .loop
	ret

.FindCurrentFloor:
	ld hl, wElevatorPointer
	ld a, [hli]
	ld h, [hl]
	ld l, a
	ld a, [wElevatorPointerBank]
	call GetFarByte
	ld c, a
	inc hl
	ld a, [wBackupMapGroup]
	ld d, a
	ld a, [wBackupMapNumber]
	ld e, a
	ld b, 0
.loop2
	ld a, [wElevatorPointerBank]
	call GetFarByte
	cp -1
	jr z, .fail
	inc hl
	inc hl
	ld a, [wElevatorPointerBank]
	call GetFarByte
	inc hl
	cp d
	jr nz, .next1
	ld a, [wElevatorPointerBank]
	call GetFarByte
	inc hl
	cp e
	jr nz, .next2
	jr .done

.next1
	inc hl
.next2
	inc b
	jr .loop2

.done
	xor a
	ld a, b
	ret

.fail
	scf
	ret

Elevator_GoToFloor:
	push af
	ld hl, wElevatorPointer
	ld a, [hli]
	ld h, [hl]
	ld l, a
	inc hl
	pop af
	ld bc, wElevatorDataEnd - wElevatorData
	call AddNTimes
	inc hl
	ld de, wBackupWarpNumber
	ld a, [wElevatorPointerBank]
	ld bc, wElevatorDataEnd - wElevatorData - 1
	call FarCopyBytes
	ret

Elevator_AskWhichFloor:
	call LoadStandardMenuHeader
	ld hl, AskFloorElevatorText
	call PrintText
	call Elevator_GetCurrentFloorText
	ld hl, Elevator_MenuHeader
	call CopyMenuHeader
	call InitScrollingMenu
	call UpdateSprites
	xor a
	ld [wMenuScrollPosition], a
	call ScrollingMenu
	call CloseWindow
	ld a, [wMenuJoypad]
	cp B_BUTTON
	jr z, .cancel
	xor a
	ld a, [wScrollingMenuCursorPosition]
	ret

.cancel
	scf
	ret

AskFloorElevatorText:
	text_far _AskFloorElevatorText
	text_end

Elevator_GetCurrentFloorText:
	ld hl, wOptions
	ld a, [hl]
	push af
	set NO_TEXT_SCROLL, [hl]
	hlcoord 0, 0
	ld b, 4
	ld c, 8
	call Textbox
	hlcoord 1, 2
	ld de, Elevator_CurrentFloorText
	call PlaceString
	hlcoord 4, 4
	call Elevator_GetCurrentFloorString
	pop af
	ld [wOptions], a
	ret

Elevator_CurrentFloorText:
	db "Now on:@"

Elevator_GetCurrentFloorString:
	push hl
	ld a, [wElevatorOriginFloor]
	ld e, a
	ld d, 0
	ld hl, wCurElevatorFloors
	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
	db 1 ; default option

Elevator_MenuData:
	db SCROLLINGMENU_DISPLAY_ARROWS ; flags
	db 4, 0 ; rows, columns
	db SCROLLINGMENU_ITEMS_NORMAL ; item format
	dbw 0, wCurElevatorCount
	dba GetElevatorFloorStrings
	dba NULL
	dba NULL

GetElevatorFloorStrings:
	ld a, [wMenuSelection]
GetFloorString:
	push de
	call FloorToString
	ld d, h
	ld e, l
	pop hl
	jp PlaceString

FloorToString:
	push de
	ld e, a
	ld d, 0
	ld hl, ElevatorFloorNames
	add hl, de
	add hl, de
	ld a, [hli]
	ld h, [hl]
	ld l, a
	pop de
	ret

INCLUDE "data/events/elevator_floors.asm"