Prev: C5D3 Up: Map Next: C613
C5E9: Keep Object In Room In X
Used by the routine at BlockMovement.
Brings the speed along x of an object closer to zero until the object stays within the walls of the room. Nothing is done while the object is entering the room, or while it is near an arch, as it can then go out through the wall.
Input
C Speed along x
IX The address of the object
Output
C The new speed along x
Return while entering or near an arch.
KeepObjectInRoomInX C5E9 LD A,(IX+$0C) Fetch the collision flags.
C5EC AND %11110000 Keep only bits 4-7.
C5EE RET NZ Return if the object is entering the room.
C5EF BIT 0,(IX+$07) Return if the object is near an arch.
C5F3 RET NZ
C5F4 LD A,($5B0B) Fetch RoomSize_X.
C5F7 LD B,A Copy it to B.
Slow x until the object stays in the room.
KeepObjectInRoomInX_Test C5F8 LD A,(IX+$01) Fetch the x position of the object.
C5FB ADD A,C Add C.
C5FC SUB $80 Subtract 80.
C5FE JR NC,KeepObjectInRoomInX_Compare Jump to KeepObjectInRoomInX_Compare if carry is not set.
C600 NEG Negate A.
KeepObjectInRoomInX_Compare C602 ADD A,(IX+$04) Add the width of the object.
C605 CP B Return if the object stays in the room.
C606 RET C
C607 SET 0,(IX+$0C) Set bit 0 of the collision flags.
C60B LD A,C Copy C to A.
C60C CALL BringSpeedCloserToZero Call BringSpeedCloserToZero.
C60F LD C,A Copy it to C.
C610 JR NZ,KeepObjectInRoomInX_Test Jump to KeepObjectInRoomInX_Test if it is not zero.
C612 RET Return.
View the equivalent code in;
Prev: C5D3 Up: Map Next: C613