| Routines

37056: Move the rope and guardians in the current room

Used by the routine at 35245.
37056 | LD IX,33024 | Point IX at the first byte of the first entity buffer at 33024
The entity-moving loop begins here.
37060 | LD A,(IX+0) | Pick up the first byte of the current entity's buffer
37063 | CP 255 | Have we already dealt with every entity?
37065 | RET Z | Return if so
37066 | AND 3 | Keep only bits 0 and 1 (which determine the type of entity)
37068 | JP Z,37302 | Jump to consider the next entity buffer if this one belongs to an arrow or is unused
37071 | CP 1 | Is this a horizontal guardian?
37073 | JP Z,37171 | Jump if so
37076 | CP 2 | Is this a vertical guardian?
37078 | JP Z,37247 | Jump if so
We are dealing with a rope.
37081 | BIT 7,(IX+0) | Is the rope currently swinging right to left?
37085 | JR Z,37119 | Jump if so
The rope is swinging left to right.
37087 | LD A,(IX+1) | Pick up the animation frame index
37090 | BIT 7,A | Is the rope currently swinging away from the centre?
37092 | JR Z,37109 | Jump if so
The rope is swinging left to right, towards the centre (132<=A<=182).
37094 | SUB 2 | Subtract 2 from the animation frame index in A
37096 | CP 148 | Is it still 148 or greater?
37098 | JR NC,37149 | If so, use it as the next animation frame index
37100 | SUB 2 | Subtract 2 from the animation frame index again
37102 | CP 128 | Is it 128 now?
37104 | JR NZ,37149 | If not, use it as the next animation frame index
37106 | XOR A | The rope has reached the centre, so the next animation frame index is 0
37107 | JR 37149 | Jump to set it
The rope is swinging left to right, away from the centre (0<=A<=52).
37109 | ADD A,2 | Add 2 to the animation frame index in A
37111 | CP 18 | Is it now 18 or greater?
37113 | JR NC,37149 | If so, use it as the next animation frame index
37115 | ADD A,2 | Add 2 to the animation frame index again
37117 | JR 37149 | Use this value as the next animation frame index
The rope is swinging right to left.
37119 | LD A,(IX+1) | Pick up the animation frame index
37122 | BIT 7,A | Is the rope currently swinging away from the centre?
37124 | JR NZ,37141 | Jump if so
The rope is swinging right to left, towards the centre (4<=A<=54).
37126 | SUB 2 | Subtract 2 from the animation frame index in A
37128 | CP 20 | Is it still 20 or greater?
37130 | JR NC,37149 | If so, use it as the next animation frame index
37132 | SUB 2 | Subtract 2 from the animation frame index again
37134 | OR A | Is it 0 now?
37135 | JR NZ,37149 | If not, use it as the next animation frame index
37137 | LD A,128 | The rope has reached the centre, so the next animation frame index is 128
37139 | JR 37149 | Jump to set it
The rope is swinging right to left, away from the centre (128<=A<=180).
37141 | ADD A,2 | Add 2 to the animation frame index in A
37143 | CP 146 | Is it now 146 or greater?
37145 | JR NC,37149 | If so, use it as the next animation frame index
37147 | ADD A,2 | Add 2 to the animation frame index again
Now A holds the rope's next animation frame index.
37149 | LD (IX+1),A | Update the animation frame index
37152 | AND 127 | Reset bit 7
37154 | CP (IX+7) | Does A match the eighth byte of the rope's buffer (54)?
37157 | JP NZ,37302 | If not, jump to consider the next entity
37160 | LD A,(IX+0) | Flip bit 7 of the first byte of the rope's buffer: the rope has just changed direction and will now swing back towards the centre
37163 | XOR 128
37165 | LD (IX+0),A
37168 | JP 37302 | Jump to consider the next entity
We are dealing with a horizontal guardian.
37171 | BIT 7,(IX+0) | Is the guardian currently moving left to right?
37175 | JR NZ,37212 | Jump if so
This guardian is moving right to left.
37177 | LD A,(IX+0) | Update the guardian's animation frame (in bits 5 and 6 of the first byte of its buffer)
37180 | SUB 32
37182 | AND 127
37184 | LD (IX+0),A
37187 | CP 96 | Is it time to update the x-coordinate of the guardian sprite?
37189 | JR C,37302 | If not, jump to consider the next entity
37191 | LD A,(IX+2) | Pick up the sprite's current screen x-coordinate (0-31)
37194 | AND 31
37196 | CP (IX+6) | Has the guardian reached the leftmost point of its path?
37199 | JR Z,37206 | Jump if so
37201 | DEC (IX+2) | Decrement the sprite's x-coordinate
37204 | JR 37302 | Jump to consider the next entity
37206 | LD (IX+0),129 | The guardian will now start moving left to right
37210 | JR 37302 | Jump to consider the next entity
This guardian is moving left to right.
37212 | LD A,(IX+0) | Update the guardian's animation frame (in bits 5 and 6 of the first byte of its buffer)
37215 | ADD A,32
37217 | OR 128
37219 | LD (IX+0),A
37222 | CP 160 | Is it time to update the x-coordinate of the guardian sprite?
37224 | JR NC,37302 | If not, jump to consider the next entity
37226 | LD A,(IX+2) | Pick up the sprite's current screen x-coordinate (0-31)
37229 | AND 31
37231 | CP (IX+7) | Has the guardian reached the rightmost point of its path?
37234 | JR Z,37241 | Jump if so
37236 | INC (IX+2) | Increment the sprite's x-coordinate
37239 | JR 37302 | Jump to consider the next entity
37241 | LD (IX+0),97 | The guardian will now start moving right to left
37245 | JR 37302 | Jump to consider the next entity
We are dealing with a vertical guardian.
37247 | LD A,(IX+0) | Flip bit 3 of the first byte of the guardian's buffer (if bit 4 is set, the guardian's animation frame is updated on every pass through this routine; otherwise, it is updated on every second pass when bit 3 is set)
37250 | XOR 8
37252 | LD (IX+0),A
37255 | AND 24 | Are bits 3 and 4 both reset now?
37257 | JR Z,37267 | Jump if so
37259 | LD A,(IX+0) | Update the guardian's animation frame (in bits 5-7 of the first byte of its buffer)
37262 | ADD A,32
37264 | LD (IX+0),A
37267 | LD A,(IX+3) | Update the guardian's y-coordinate
37270 | ADD A,(IX+4)
37273 | LD (IX+3),A
37276 | CP (IX+7) | Has the guardian reached the lowest point of its path (maximum y-coordinate)?
37279 | JR NC,37294 | If so, jump to change its direction of movement
37281 | CP (IX+6) | Compare the new y-coordinate with the minimum value (the highest point of its path)
37284 | JR Z,37288 | If they match, jump to change the guardian's direction of movement
37286 | JR NC,37302 | If the new y-coordinate is above the minimum value, jump to consider the next entity
37288 | LD A,(IX+6) | Make sure that the guardian's y-coordinate is set to its minimum value
37291 | LD (IX+3),A
37294 | LD A,(IX+4) | Negate the y-coordinate increment; this changes the guardian's direction of movement
37297 | NEG
37299 | LD (IX+4),A
The current entity has been dealt with. Time for the next one.
37302 | LD DE,8 | Point IX at the first byte of the next entity's buffer
37305 | ADD IX,DE
37307 | JP 37060 | Jump back to deal with it