Prev: 69C9 Up: Map Next: 6A12
69DC: Set-up doors
This is called by setup_room to setup the interior_doors array. It walks through the doors array, extracting the indices of doors relevant to the current room and stores those indices into interior_doors.
Used by the routine at setup_room only.
Clear the interior_doors[] array with door_NONE ($FF).
setup_doors 69DC LD A,$FF Set A to door_NONE
69DE LD DE,$81D9 Set DE to the final byte of interior_doors[] (byte 4)
69E1 LD B,$04 Set all four bytes to door_NONE
setup_doors_0 69E3 LD (DE),A
69E4 DEC DE
69E5 DJNZ setup_doors_0
Setup to populate interior_doors[].
69E7 INC DE Set DE to the first interior_doors[] byte
69E8 LD A,($68A0) Fetch and shift the global current room index up by two bits, to match door_flags, then store it in B
69EB ADD A,A
69EC ADD A,A
69ED LD B,A
69EE LD C,$00 Initialise the door index
69F0 EXX Switch register banks for the iteration
We're about to walk through doors[] and extract the indices of the doors relevant to the current room.
69F1 LD HL,$78D6 Point HL' to the first byte of doors[]
69F4 LD B,$7C Set B' to the number of entries in doors[] (124)
69F6 LD DE,$0004 Set DE' to the stride of four bytes (each door is a room_and_direction byte followed by a 3-byte position)
Start loop
Save any door index which matches the current room.
setup_doors_1 69F9 LD A,(HL) Fetch door's room_and_direction
69FA EXX Switch registers back to the set used on entry to the routine
69FB AND $FC Clear room_and_direction's direction bits (door_FLAGS_MASK_DIRECTION)
69FD CP B Is it the current room?
69FE JR NZ,setup_doors_2 Jump if not
This is the current room.
6A00 LD A,C Write to DE register C toggled with door_REVERSE
6A01 XOR $80
6A03 LD (DE),A
6A04 INC DE
setup_doors_2 6A05 LD A,C Toggle door_REVERSE in C for the next iteration
6A06 XOR $80
6A08 JP M,setup_doors_3 Jump if (C >= door_REVERSE)
6A0B INC A Increment the door index once every two steps through the array
setup_doors_3 6A0C LD C,A
6A0D EXX Switch registers again
6A0E ADD HL,DE Step HL' to the next door
6A0F DJNZ setup_doors_1 ...loop
6A11 RET Return
Prev: 69C9 Up: Map Next: 6A12