Prev: 46769 Up: Map Next: 46841
46777: Handle Block Moving East West
Handles a block that slides to and fro along the X axis. It works in the same way as HandleBlockMovingNorthSouth but with the X coordinate and the speed in X.
Input
IX Address of the block object
HandleBlockMovingEastWest 46777 CALL PlaySoundFromXPosition Play the sound of a block moving along the X axis.
46780 LD HL,265 Set H to the offset of the X coordinate and L to the offset of the speed in X.
This entry point is used by the routine at HandleBlockMovingNorthSouth.
Modify the instructions that fetch the coordinate and store the speed.
HandleMovingBlock 46783 LD A,H Fetch the offset of the coordinate.
46784 LD (46816),A Change the instruction at HandleMovingBlock_Coordinate to use it.
46787 LD A,L Fetch the offset of the speed.
46788 LD (46833),A Change the instruction at HandleMovingBlock_Speed to use it.
46791 CALL SetPixelAdjustments_Block Set the pixel adjustments of a block.
Work out where the block should be: a position from 0 to 15 that goes up and down with the frame counter. The two blocks of a room are half a cycle apart, depending on the address of the object.
46794 PUSH IX Copy IX to BC (using the stack).
46796 POP BC
46797 LD A,C Fetch the low byte of the address of the object.
46798 RRCA Rotate it right.
46799 AND %00010000 Keep the bit which is different for the neighbouring objects.
46801 LD C,A Stash it in C.
46802 LD A,(23458) Fetch the frame counter from FrameCounter.
46805 ADD A,C Add the offset of this block.
46806 BIT 4,A Jump to HandleMovingBlock_Target if bit 4, which is the direction of the wave, is clear.
46808 JR Z,HandleMovingBlock_Target
46810 CPL Invert the value, so that the wave goes down again.
HandleMovingBlock_Target 46811 AND %00001111 Keep the lowest four bits as the position to go to.
46813 LD C,A Stash it in C.
Compare the block with the target. Redraw it if it is already there, otherwise set a speed of 1 towards the target.
HandleMovingBlock_Coordinate 46814 LD A,(IX+1) Fetch the coordinate of the block. This is the instruction that is modified.
46817 ADD A,8 Add 8 to it.
46819 AND %00001111 Keep the position of the block within its 16 steps.
46821 CP C Compare it with the position that it should go to.
46822 JP Z,SetWipeAndDrawFlags Jump to SetWipeAndDrawFlags if it is already there.
46825 LD A,1 Set the speed to 1.
46827 JR C,HandleMovingBlock_Speed Jump to HandleMovingBlock_Speed if the block is below the position that it should go to.
46829 NEG Make the speed negative.
Set that speed, hold the block up, and move it.
HandleMovingBlock_Speed 46831 LD (IX+9),A Set the speed of the block. This is the instruction that is modified.
46834 LD (IX+11),1 Set the speed in Z to 1, so that the block does not fall.
46838 JP MoveAndDrawObject Move the block and flag it to be drawn again.
View the equivalent code in;
Prev: 46769 Up: Map Next: 46841