Prev: D4FC Up: Map Next: D5FE
D5D4: Re-calculate room event table data sets
Follows setup of foreground scenery objects at D4FC.
The room's 'events-to-check' sets at 7FB3 contain any items in the current room that will need checking for events/collisions - for example if the servant, or a warlock, is present.
  • This routine decrements the first byte of each set at 7FB3
  • For each event item set, this byte will be (pre-decrement) either 1 or 2, as items/events are checked twice (e.g. if they've moved on-screen
  • After decrementing this counter, any sets with this byte value of 0 are removed from the set, and any sets with a byte value of 2 (so 1 after decrementing) are moved up the set (the table is dynamic so will shrink as well as grow)
  • Once all sets have been checked/decremented, a value of 255 is put at the start of the next set to indicate the end of the sets
D5D4 LD HL,($EB6C) Pointer to room item event data sets at 7FB3
D5D7 LD D,H Copy into DE register pair - this is the address pointer ready for a later set to be copied here
D5D8 LD E,L
D5D9 LD A,(HL) Get first byte of event set
D5DA INC HL (and move the pointer along)
This loop DECrements the first byte of each event set by 1:
D5DB CP $FF Have we reached the end of the event sets?
D5DD JR Z,$D5F3 If so, skip out at this point
D5DF DEC A The first byte for these will be 1 or 2
D5E0 JR Z,$D5EC ...So after the DEC, skip the next set of instructions if it was 1, as it'll now be zero no longer needs checking
First byte of set (after the decrement) = 1 - it's still not zero, so we need to keep this set:
D5E2 LD B,$04 Copy the DEC'd byte back into the first byte of the previously stored address
D5E4 LD (DE),A
D5E5 LD A,(HL) ...followed by the rest of the bytes in the set
D5E6 INC DE
D5E7 INC HL
D5E8 DJNZ $D5E4
D5EA JR $D5DB Keep checking sets until all sets dealt with (byte value of 255 found)
First byte of set (after the decrement) = 0 - no need to keep this set, move on to the next:
D5EC INC HL HL is pointing at the second byte of the set, so move it along 3...
D5ED INC HL
D5EE INC HL ...To get to the first byte of the next set
D5EF LD A,(HL)
D5F0 INC HL
D5F1 JR $D5DB ...And repeat the check for the next set.
All event sets now dealt with. Set termination (end-of-data) byte of 255 at the start of what would be the next set.
D5F3 LD (DE),A At this instruction, the A register contains 255 and DE points to the start of the next event data set at D4FC, so this stores a 255 (end-of-data) byte at the start of the next set.
D5F4 EX DE,HL Swap DE (start of data sets) back into HL
D5F5 LD ($EAAD),HL Store pointer to end of event table (byte 1 of new set)
D5F8 LD HL,($EB72) Retrieve address pointer for the end of the room element data sets at 7C00
D5FB LD ($EABE),HL Copy to data buffer
The following routine (D5FE) determines if any creatures should enter Maroc's current room.
Prev: D4FC Up: Map Next: D5FE