Routines |
Prev: C571 | Up: Map | Next: C5E7 |
Used by the routine at C15A.
|
||||||||
Uses the tunnel room data at 6710 and the connecting door sets at 6790 to work out which room the tunnel that Maroc has just entered leads to.
|
||||||||
C5B5 | LD A,$00 | |||||||
C5B7 | LD ($EC9D),A | Set number of creatures in the room to zero | ||||||
Get length of tunnel
|
||||||||
C5BA | LD A,(HL) | First byte of data = tunnel length | ||||||
C5BB | ADD A,A | Double it... | ||||||
C5BC | LD ($EB7D),A | ...and store | ||||||
The second and third bytes of the set hold the two paired door set numbers (in the table at 6790) 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.
|
||||||||
C5BF | INC HL | Get 2nd byte (connecting door set #1) | ||||||
C5C0 | LD B,(HL) | |||||||
C5C1 | LD A,($EAB4) | Compare with the current door set number that Maroc has just left | ||||||
C5C4 | CP B | |||||||
C5C5 | JR NZ,$C5C8 | |||||||
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
|
||||||||
C5C7 | INC HL | |||||||
HL register pair is now pointing at the correct connecting room door set number (at 6790)
|
||||||||
C5C8 | LD A,(HL) | Get the connecting room set number... | ||||||
C5C9 | LD ($EAB4),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).
|
||||||||
C5CC | LD HL,($DAF5) | Address pointer to connecting door sets (6790) | ||||||
C5CF | LD D,$00 | The offset will be in the DE register paid, so set the high byte (D register) to zero | ||||||
C5D1 | RLA | Set number x 2 | ||||||
C5D2 | RL D | |||||||
C5D4 | RLA | Set number x 4 (as data sets are 4 bytes long) | ||||||
C5D5 | RL D | ...also rotating any carry bits into (D) - the high byte | ||||||
C5D7 | AND $FC | Addresses are a multiple of 4 so we don't need bits 0-1 (values 0-3) | ||||||
C5D9 | LD E,A | DE register pair now contains the offset | ||||||
C5DA | ADD HL,DE | ...and add it to address pointer | ||||||
C5DB | LD ($EAB5),HL | ...and store the address pointer-plus-offset | ||||||
Update the 'entry point' door data in the room connecting data set at 6790:
|
||||||||
C5DE | INC HL | Move address pointer along 2 bytes to byte 3 of the set | ||||||
C5DF | INC HL | |||||||
C5E0 | LD A,($EAF5) | This is the door properties byte indicating the door that Maroc entered the room from (normally will have bit 7 set) | ||||||
C5E3 | LD (HL),A | Store this as the third byte in the room connecting door data set (at 6790). | ||||||
C5E4 | INC HL | Move to the 4th byte of the relevant door set (in the table at 6790) | ||||||
C5E5 | LD (HL),$00 | 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: C571 | Up: Map | Next: C5E7 |