Prev: 50545 Up: Map Next: 50663
50613: Tunnel room - identify the connecting door set
Used by the routine at 49498.
Input
HL Address pointing to the current tunnel data bank at 26384
Uses the tunnel room data at 26384 and the connecting door sets at 26512 to work out which room the tunnel that Maroc has just entered leads to.
50613 LD A,0
50615 LD (60573),A Set number of creatures in the room to zero
Get length of tunnel
50618 LD A,(HL) First byte of data = tunnel length
50619 ADD A,A Double it...
50620 LD (60285),A ...and store
The second and third bytes of the set hold the two paired door set numbers (in the table at 26512) that connects each end of this tunnel. One of them will be the room Maroc has left, and the other the room he's headed to.
The next instructions identify which direction way Maroc is going - i.e. whether to pick out the second or third byte of the set.
50623 INC HL Get 2nd byte (connecting door set #1)
50624 LD B,(HL)
50625 LD A,(60084) Compare with the current door set number that Maroc has just left
50628 CP B
50629 JR NZ,50632
If the second byte is the same as the current one, we need to grab the third byte, rather than the second, so advance the pointer along
50631 INC HL
HL register pair is now pointing at the correct connecting room door set number (at 26512)
50632 LD A,(HL) Get the connecting room set number...
50633 LD (60084),A ...and store as the connecting door set number (destination)
The next instructions use the door set number to set the address pointer to the right connecting door set, by multiplying it by 4 (as each set contains 4 bytes of data).
50636 LD HL,(56053) Address pointer to connecting door sets (26512)
50639 LD D,0 The offset will be in the DE register paid, so set the high byte (D register) to zero
50641 RLA Set number x 2
50642 RL D
50644 RLA Set number x 4 (as data sets are 4 bytes long)
50645 RL D ...also rotating any carry bits into (D) - the high byte
50647 AND 252 Addresses are a multiple of 4 so we don't need bits 0-1 (values 0-3)
50649 LD E,A DE register pair now contains the offset
50650 ADD HL,DE ...and add it to address pointer
50651 LD (60085),HL ...and store the address pointer-plus-offset
Update the 'entry point' door data in the room connecting data set at 26512:
50654 INC HL Move address pointer along 2 bytes to byte 3 of the set
50655 INC HL
50656 LD A,(60149) This is the door properties byte indicating the door that Maroc entered the room from (normally will have bit 7 set)
50659 LD (HL),A Store this as the third byte in the room connecting door data set (at 26512).
50660 INC HL Move to the 4th byte of the relevant door set (in the table at 26512)
50661 LD (HL),0 Set this byte to 0.
This is the 'event check' value. Setting it to 0 effectively means that the door is subsequently only interactable by Maroc bumping into it, or another creature entering the room.
It's not completely clear why this needs changing.
It may possibly be a remnant from some earlier code which dealt with the doors in a different way.
Prev: 50545 Up: Map Next: 50663