Prev: EEF3 Up: Map Next: EF91
EF35: Update the current position of moving objects
Used by the routines at ED2A, ED8A, F10E, F24B, F277, F309, F334, F37D, F3AB, F409, F49D, F503, F5F1, F674, F6EC, F746, F8B9 and F9F5.
Input
IX pointer to a buffer containing current positions
BC Pointer to a buffer containing bounds
The buffer containing bounds is fixed at:
0 Minimum x co-ordinate
1 Maximum x co-ordinate
2 Minimum y co-ordinate
3 Maximum y co-ordinate
The buffer containing the positions varies over time and contains:
0 Current x co-ordinate
1 Current y co-ordinate
2 Distance to move in x
3 Distance to move in y
The distances to move are stored as a 2s complement value. When an object hits the minimum or maximum value, its distance to move is inverted between positive and negative and it starts travelling back in the other direction.
The function updates IX on each call to point at the next entries beyond the one it was called with, and can be called multiple times or in a loop for each moving object in the room.
EF35 LD E,(IX+$02) Put the distance to move in DE.
EF38 LD D,(IX+$03)
EF3B PUSH BC Store BC and AF.
EF3C PUSH AF
EF3D XOR A Reset flags used in this routine.
EF3E LD ($F673),A
EF41 LD ($F672),A
EF44 LD A,(IX+$00) Get the current x co-ordinate in A.
EF47 ADD A,E Add the distance to move by.
EF48 LD L,A Put this in L.
Check the minimum x co-ordinate.
EF49 LD A,(BC) Get the minimum x co-ordinate.
EF4A INC BC Point BC to the next place in the buffer.
EF4B CP L Is our current x co-ordinate the minimum?
EF4C JR NZ,$EF59 Jump forward if not.
x co-ordinate has reached the minimum or maximum.
EF4E LD A,$01 Flag x boundary reached.
EF50 LD ($F672),A
EF53 LD A,E Flip the distance to change between negative and positive.
EF54 NEG
EF56 LD E,A
EF57 JR $EF5D
Check the maxmimum x co-ordinate.
EF59 LD A,(BC) Get the maxmimum x co-ordinate.
EF5A CP L Is our current x co-ordinate the maximum?
EF5B JR Z,$EF4E Jump back to flip direction if so.
x co-ordinate is in range, check the y co-ordinate.
EF5D INC BC Point BC to the next place in the buffer.
EF5E LD A,(IX+$01) Get the current y co-ordinate in A.
EF61 ADD A,D Add the distance to move by.
EF62 LD H,A Put this in H.
Check the minimum y co-ordinate.
EF63 LD A,(BC) Get the minumum y co-ordinate.
EF64 INC BC Point BC to the next place in the buffer.
EF65 CP H Is our current y co-ordinate the minimum?
EF66 JR NZ,$EF73 Jump forward if not.
y co-ordinate has reached the minimum or maximum.
EF68 LD A,$01
EF6A LD ($F673),A
EF6D LD A,D Flip the distance to change between negative and positive.
EF6E NEG
EF70 LD D,A
EF71 JR $EF77
Check the maximum y co-ordinate.
EF73 LD A,(BC) Get the maximum y co-ordinate.
EF74 CP H Is our current y co-ordinate the maxmimum?
EF75 JR Z,$EF68 Jump back to flip the direction if so.
The positions have all been updated, so write them out.
EF77 LD ($A838),HL Write the position to update that will be used by the next call to the routine at A83D.
EF7A LD (IX+$00),L Write back the positions.
EF7D LD (IX+$01),H
EF80 LD (IX+$02),E Write back the directions.
EF83 LD (IX+$03),D
EF86 POP AF Restore AF and BC.
EF87 POP BC
This entry point is used by the routines at F8B9 and FAF0.
EF88 INC IX Move to the next entry and return.
EF8A INC IX
EF8C INC IX
EF8E INC IX
EF90 RET
Prev: EEF3 Up: Map Next: EF91