-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroom.asm
494 lines (396 loc) · 7.61 KB
/
room.asm
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
draw_room
call clear_room
SELECT_BANK room_bank_config
call draw_outline
call draw_items
SELECT_BANK room_bank_config
call draw_collectables
call draw_food
SELECT_BANK item_bank_config
call calc_room_dimensions
call copy_room_to_other_screen
SELECT_BANK room_bank_config
call calculate_collision_grid
call update_collision_grid_for_items
call try_teleport_dracula
call replen_food
; Reset data for new room.
xor a
ld (room_changed), a
; Temporarily save current room sprite data
ld hl, sprite1
ld de, temp_sprite_data
ld bc, sprite_end - sprite1
ldir
ld a, (saved_room_number)
ld b, a
ld a, (room_number)
cp b
jr z, has_gone_back
call reset_sprites
jr gb1
has_gone_back
ld hl, old_room_sprites
ld de, sprite1
ld bc, sprite_end - sprite1
ldir
call partial_reset_sprites
gb1
ld hl, temp_sprite_data
ld de, old_room_sprites
ld bc, sprite_end - sprite1
ldir
ld a, (last_room_number)
ld (saved_room_number), a
ngb1
ld a, r
ld (random_seed), a
ld hl, 0
ld (door_to_toggle), hl
call reset_player
call init_boss
call reset_weapon
call reset_food_collected
call set_pens
ld a, (room_number)
cp end_room
ret nz
ld a, game_completed
ld (game_over), a
ret
copy_room_to_other_screen
ld a, (hidden_screen_base_address)
ld h, a
ld l, 0
ld ixh, num_rows
copy_room_loop
push hl
ld a, h
xor 0x40
ld d, a
ld e, l
ld bc, 48
ldir
pop hl
GET_NEXT_SCR_LINE
dec ixh
jr nz, copy_room_loop
ret
draw_outline
ld a, (room_number)
ld bc, room_bank_RoomInfo
ld l, a
ld h, 0
add hl, hl
add hl, bc
ld d, (hl) ; room colour
set 7, (hl)
push hl
cp skeleton_room1
jr z, skeleton_room
cp skeleton_room2
jr z, skeleton_room
cp skeleton_room3
jr z, skeleton_room
cp skeleton_room4
jr nz, not_skeleton_room
skeleton_room
ld d, 0
not_skeleton_room
ld a, d
and 0x03
ld c, a
ld b, 0
ld hl, room_colour_palette
add hl, bc
ld a, (hl)
ld (line_pen_number + 1), a
pop hl
inc hl
ld a, (hl) ; a has room type
ld (room_type), a
ld bc, room_bank_RoomTypes
ld l, a
ld h, 0
add hl, hl
ld d, h
ld e, l
add hl, hl
add hl, de
add hl, bc ; hl now points to room info
ld d, (hl)
inc hl
ld e, (hl)
inc hl ; de now has width / height
ex de, hl
ld (room_size), hl ; save it
ex de, hl
ld e, (hl)
inc hl
ld d, (hl) ; de is vertex data
inc hl
ld c, (hl)
inc hl
ld b, (hl) ; bc is line info
ex de, hl ; hl is now vertex data
ld (point_address), hl
dec bc
ld ixh, b
ld ixl, c ; ix now points to index list - 1
draw1
inc ix
ld a, (ix + 0)
cp 0xff
ret z
draw3
; convert a into a point address stored in bc
call get_point
draw2
inc ix
ld a, (ix + 0)
cp 0xff
jr z, draw1
; convert a into a point stored in de
push bc
call get_point
ld d, b
ld e, c
pop bc
push bc
call plot_line
pop bc
jr draw2
get_point ; IN: A = coord number, out: bc = coord
ld hl, (point_address)
add a
ld c, a
ld b, 0
add hl, bc
ld b, (hl)
inc hl
ld c, (hl)
ret
clear_room
ld a, (hidden_screen_base_address)
clear_room2
ld h, a
ld l, 0
ld b, num_rows
clear1
push bc
push hl
ld bc, 0x2f
ld (hl), 0
ld d, h
ld e, l
inc de
ldir
pop hl
GET_NEXT_SCR_LINE
pop bc
djnz clear1
ret
calc_room_dimensions
ld hl, (room_size)
srl h
ld a, 0x30
sub h
sub 4
ld (min_x), a
ld a, 0x30
add h
sub 4
ld (max_x), a
ld a, 0x60
sub l
sub 9
ld (min_y), a
ld a, 0x60
add l
sub 12
ld (max_y), a
ret
calculate_collision_grid
ld hl, collision_grid
ld de, collision_grid + 1
ld bc, (collision_grid_size * collision_grid_size) - 1
ld (hl), 0xff
ldir
call block_items
call block_room
; call draw_collision_grid
ret
block_room
ld bc, 0 ; set all collision tiles based on min-max x and y
ld hl, collision_grid
set_grid ; b is y, c is x
ld a, (min_y) ; divide by 8
srl a
srl a
srl a
cp b
jr nc, skip_this_element
ld a, (max_y) ; divide by 8
srl a
srl a
srl a
inc a
inc a
cp b
jr c, skip_this_element
ld a, (min_x) ; divide by 4
srl a
srl a
dec a
cp c
jr nc, skip_this_element
ld a, (max_x) ; divide by 4
srl a
srl a
inc a
cp c
jr c, skip_this_element
set_grid_element
ld a, (hl)
call get_type_for_collision_index ; is this element a table or trapdoor?
cp active_door_trapdoor
jr z, skip_this_element
cp item_table
jr nz, clear_the_floor
ld (hl), 0xff
jr skip_this_element
clear_the_floor
ld (hl), 0
skip_this_element
inc hl
inc c
ld a, c
cp collision_grid_size
jr nz, set_grid
ld c, 0
inc b
ld a, b
cp collision_grid_size
jr nz, set_grid
ret
get_type_for_collision_index ; IN: A = door index + 1
push de
push hl
dec a
ld l, a
ld h, 0
add hl, hl
add hl, hl
add hl, hl
ld de, this_rooms_door_list
add hl, de
ld a, (hl)
pop hl
pop de
ret
block_items
ld a, (this_rooms_door_count)
ld b, a
ld ix, this_rooms_door_list
collision_list_loop
ld l, (ix + 2) ; y
srl l
srl l
srl l
ld h, 0
add hl, hl
add hl, hl
add hl, hl
ld d, h
ld e, l ; de = y * 8
add hl, hl
add hl, de ; hl = (y * 16) + (y * 4) = y * 24
ld e, (ix + 1)
srl e
srl e
ld d, 0
add hl, de
ld de, collision_grid
add hl, de ; hl is first char in collision grid for this item
push bc
ld a, (this_rooms_door_count)
sub b
inc a
ld (this_doors_index), a
call block_out_item
pop bc
ld de, 8
add ix, de
djnz collision_list_loop
ret
block_out_item
call is_door_locked_or_closed
ld c, (ix + 6) ; height of item
srl c
srl c
srl c
coll_item_loop2
ld b, (ix + 5)
srl b
ld a, (ix + 0)
cp item_clock
jr nz, not_a_clock
dec b ; adjust width if a clock
not_a_clock
push hl
ld a, (this_doors_index)
coll_item_loop
ld (hl), a
inc hl
djnz coll_item_loop
pop hl
ld de, 24
add hl, de
dec c
jr nz, coll_item_loop2
ret
is_door_locked_or_closed ; IN: ix = item, OUT: a=0xff if so, otherwise a unchanged
ld e, (ix + 3)
ld d, (ix + 4)
ld a, (de)
cp item_table
ret z
inc de
inc de
ld a, (de)
bit 7, a
ret z
ld a, 0xff
ld (this_doors_index), a
ret
point_address
defw 0
room_size
defw 0
min_x
defb 0
max_x
defb 0
min_y
defb 0
max_y
defb 0
this_doors_index
defb 0x00
room_number
defb 0x00
last_room_number
defb 0x00
saved_room_number
defb 0x00
room_changed
defb 0
room_type
defb 0
next_room_number
defb 0
room_colour_palette
defb 0x0c ; 0x02
defb 0xfc ; 0x07
defb 0x3f ; 0x0e
defb 0xcc ; 0x03