Prev: C89F Up: Map Next: C95F
C8DC: Determine if creatures will enter the current room
Used by the routine at C89F.
Creatures will follow Maroc into a room after a short delay. Maroc can:
  • Lose his pursuers if he exits the room before they appear
  • Move away so the door is off-screen. Creatures won't enter the room off-screen, though they may appear once the door is back in view.
Creatures may also wander in from other adjacent rooms. The frequency of this happening is much lower - there's a longer timer counter for this event.
This is the first routine run when handling DOOR items (item number 2), in the room item check at C89F.
C8DC LD A,($EB4E) Get item properties byte (for the door)
C8DF LD C,A
C8E0 AND $01 Bit 1 indicates if the item is on-screen (0 = no, 1 = yes)
C8E2 JP Z,$D27D If the door isn't on-screen, nothing more to do or check in this routine
C8E5 LD A,C If the bit is set, the door is on-screen. Retrieve item properties byte
C8E6 AND $F0 Filter out bits 0-3
C8E8 CP $00 If any of bits 4-7 are set, there's already something already happening with this door that needs dealing with
C8EA JP Z,$C8FA No bits set - skip next few checks
C8ED CP $20
C8EF JP Z,$CA8E Bit 5 (32) set = Maroc or a creature has touched a door, so it needs to be opened/closed
C8F2 CP $40 Bit 6 (64) set = means the door is currently opening or closing
C8F4 JP Z,$CAB4
C8F7 JP $CAF9 Bit 7 (128) set = Maroc has just gone through this doorway
Creatures will follow Maroc into other rooms. After Maroc enters a room, a check is made every 16 game cycles to see if there are any creatures in the connecting room.
This gives Maroc a short time to quickly move room again before the creature enters. Doing so lets him successfully escape his pursuers.
C8FA LD A,($EAAA) Game cycle counter/timer
C8FD AND $0F Check bits 0-3 (values = 0-15)
C8FF JP NZ,$C99B If anything other than 0, skip this check
Every 16 frames/game cycles:
C902 LD A,($EB46) Door being checked - 0 = Back wall, 1 = Right wall, 2 = Left wall
C905 LD C,A
C906 LD A,($EAB4) Connecting door (in table at 6790) that Maroc entered the current room from
C909 CP C
C90A JR Z,$C925 If Maroc entered through this door, check if there were any creatures in his previous room
Maroc didn't enter through this door. However, there's still a chance that any creatures in the adjacent connected room may wander in.
A random number is generated and compared against the delay counter at EBB5. There will be a much greater delay before this event occurs (a monster wandering in, rather than pursuing).
Additionally, creatures will not wander into the room if there is already another creature in the room.
C90C CALL $DB06 Generate pseudo-random number
C90F AND $7F Filter out bit 7 (just keep random values 0-127)
C911 LD C,A
C912 LD A,($EBB5) Timer indicating how long before a creature is likely to wander in from an adjacent room
C915 DEC A Decrement the counter
C916 LD ($EBB5),A ...re-store it...
C919 CP C Compare it with the randomly generated value
C91A JP NC,$C99B If timer is (still) >= than the random value, a creature won't wander into the room
C91D LD A,($EBB7) Timer is less than the random value. Get the number of creatures currently in the room
C920 CP $00
C922 JP NZ,$C99B If there are ANY creatures already in the room, don't let any more enter
First, check if we've reached the maximum creatures-per-room (3)
C925 LD A,($EBB6) Get number of creatures currently in room
C928 CP $03
C92A JR NC,$C99B If there are already 3, skip the whole check as there can't be any more
Use the connecting door table at 6790 to check which rooms are adjacent to this one
C92C LD HL,($EB44) Address pointer to connecting door table at 6790
C92F LD C,(HL) First byte in set contains the room number for this door
C930 LD A,($EAB7) Current room number
C933 CP C Is it the same as the first byte of the connecting door set?
C934 JR NZ,$C93D
C936 INC HL If so, the door is in this room - move to next byte
C937 LD C,(HL) This byte holds the connecting room for this door
C938 LD A,$DF
C93A CP C
C93B JR C,$C99B If the connecting room is >=224, the door leads to a tunnel. Nothing can enter from that direction so skip out of the routine
Check for any creature data in the adjacent room
C93D DEC C C register will be part of an offset (BC register pair) to add to an address pointer for the room creature table at 6B8C. Room numbers start at 1, but it needs to start at 0 for the offset, so reduce the value by 1
C93E LD B,$00 Reset B register (ready for offset to be added)
C940 LD HL,($DAF0) Address pointer at start of room creature data at 6B8C
C943 ADD HL,BC Add the offset to get to the right creature data in this adjacent room
C944 LD A,(HL) Get the room creature data (all stored in 1 single byte)
C945 LD C,A
C946 CP $00
C948 JR Z,$C99B If there are no creatures in this room, there aren't any creatures who might come through this door
There IS a creature (or creatures) in the adjacent room that this door connects to:
C94A LD A,($EB4E) Get door properties byte
C94D LD D,A Temp store in D register
C94E AND $F0 Clear bits 0-3
C950 CP $00 Any of bits 4-7 set?
This check has already been made at C8E6, so the jump in the next instruction shouldn't be triggered.
C952 JR NZ,$C99B If so, jump out of routine here
C954 LD A,D Retrieve door properties byte
C955 AND $08 Check bit 3 - if set, indicates door is open, otherwise closed
C957 JR NZ,$C95F If door is open, skip ahead to the next routine
C959 LD A,D Retrieve door properties byte
C95A ADD A,$40 A creature is entering the room and the door is closed.
Open the door by setting bit 6 (if set this indicates the door is now opening/closing)
C95C LD ($EB4E),A ...and re-store
The next routine determines the type of creature that will enter the room.
Prev: C89F Up: Map Next: C95F