Prev: D94C Up: Map Next: DA4D
DA0A: Maroc's room number has changed - identify new room number
Used by the routine at D94C.
Maroc has left a room - all door, creature and object data from the room he's left has been dealt with in the previous routine.
DA0A LD A,($EAB7) Get room number
DA0D CP $E0 Check if it's a tunnel room (room numbers 224-255)
DA0F JR NC,$DA1D If so, there are no creatures to deal with, so skip the next few instructions
Standard (non-tunnel room). Copy the room's creature data byte (EBB7), calculated in the previous routine, in the relevant room's creature data set at 6790.
DA11 DEC A Offset starts at 0, not 1, so decrement room number
DA12 LD C,A Use room number as an offset in BC register pair
DA13 LD B,$00
DA15 LD HL,($DAF0) Address pointer for the room creature data set at 6B8C
DA18 ADD HL,BC Add offset (with C = room number)
DA19 LD A,($EBB7) Byte indicating which creatures are in the room (that Maroc is leaving)
DA1C LD (HL),A Copy into the room creature data at 6790
Get new room number:
DA1D LD A,($EAB0) Get (new) room number data byte
DA20 CP $FF If byte set to 255 it indicates that the room number needs to be calculated, so will need calculating using the connecting door table at 6790
DA22 JR NZ,$DA31 If already calculated, skip the next few instructions
DA24 LD HL,($EAB5) Address pointer to connecting door data at 6790
DA27 LD A,($EAB7) Get current room number
DA2A CP (HL) The connecting room will either be byte 2 or 3 (1 door, two rooms)
Is the current room equal to byte 2 in the door table?
DA2B JR NZ,$DA2E If not, the new room is byte 2
DA2D INC HL If so, we need byte 3
DA2E LD A,(HL) Get the room byte from the connecting door table
DA2F JR $DA42
If the new room number is already set/calculated, it means it's been changed by some event during the game cycle.
For example, if Maroc:
  • is out of energy (room set to room #1)
  • casts a spell such as SUMMON or WAYSTONE, that teleports him to a new room
If so, set Maroc's position in the new room at the point of the room's left wall-floor connector. See Bugs - Teleport spells
DA31 LD C,A Calculated room number - temp store in C
DA32 LD A,$30 Set Maroc's vertical pixel position in the room to 48 pixels
DA34 LD ($EB74),A
DA37 LD A,$10 Set Maroc's horizontal room position (4-pixel/half-character steps) to 16
DA39 LD ($EB75),A
DA3C LD A,$00
DA3E LD ($EB76),A Set Maroc's room vertical position to 0
DA41 LD A,C Retrieve byte (EAB0) from C register
Maroc's room has now changed, so he's either gone through a door, run out of energy, or has teleported somewhere.
DA42 LD ($EAB7),A Store new room number (e.g. = room #1 when Maroc is out of energy, room #61 for SUMMON)
DA45 LD A,($EAE0) Check Maroc's energy level
DA48 CP $00 Is it zero?
DA4A JP NZ,$C107 If not 0, Maroc hasn't run out of energy, so if he hasn't just gone through a door he's probably cast some sort of teleport spell.
If this is the case, jump out here and initialize the data for his new room.
Otherwise, Maroc is out of energy - continue to the next routine.
Prev: D94C Up: Map Next: DA4D