Prev: 44863 Up: Map Next: 45141
44921: Handle Valve
The handler for a valve lying about in a room (objects 96 to 99). If the room has a socket of the same shape the valve moves towards it one step at a time along the x and y axes, and is pulled down by gravity. When it sits on the socket it is placed: the object number goes up by four (100 to 103), the screen colours cycle sixteen times with a sparkle, the chamber ink is set to white, and one is added to ChambersActivated. If that makes 36 the game is completed.
A valve which is not on its way to a socket is just moved with gravity, and stopped and redrawn if it has been dropped.
Input
IX The address of the object
Look for a matching socket.
HandleValve 44921 CALL SetPixelAdjustments_Valve Call SetPixelAdjustments_Valve.
44924 LD HL,1136 Set HL to 1136.
44927 CALL FindObject Call FindObject.
44930 JR NC,HandleValve_Fall Jump to HandleValve_Fall if there is no socket.
44932 LD A,(IY+0) Fetch the sprite number of the socket.
44935 AND %00000011 Keep bits 0 and 1.
44937 LD C,A Keep it in C.
44938 LD A,(IX+0) Fetch the object number of the valve.
44941 AND %00000011 Keep bits 0 and 1.
44943 CP C Jump to HandleValve_Fall if the shapes are different.
44944 JR NZ,HandleValve_Fall
Set the speed towards the socket.
44946 LD A,(IX+1) Subtract the socket x from the valve x.
44949 SUB (IY+1)
44952 JR Z,HandleValve_SetSpeedX Jump to HandleValve_SetSpeedX if they are the same.
44954 LD A,1 Set the speed to 1.
44956 JP M,HandleValve_SetSpeedX Jump to HandleValve_SetSpeedX if the valve is west of the socket.
44959 NEG Make the speed negative.
HandleValve_SetSpeedX 44961 LD (IX+9),A Set the speed along the x axis.
44964 LD A,(IX+2) Subtract the socket y from the valve y.
44967 SUB (IY+2)
44970 JR Z,HandleValve_SetSpeedY Jump to HandleValve_SetSpeedY if they are the same.
44972 LD A,1 Set the speed to 1.
44974 JP M,HandleValve_SetSpeedY Jump to HandleValve_SetSpeedY if the valve is south of the socket.
44977 NEG Make the speed negative.
HandleValve_SetSpeedY 44979 LD (IX+10),A Set the speed along the y axis.
Place the valve if it is on the socket.
44982 LD A,(IX+1) Compare the x positions.
44985 CP (IY+1)
44988 JR NZ,HandleValve_Fall Jump to HandleValve_Fall if they differ.
44990 LD A,(IX+2) Compare the y positions.
44993 CP (IY+2)
44996 JR NZ,HandleValve_Fall Jump to HandleValve_Fall if they differ.
44998 LD A,(IY+3) Fetch the height of the socket.
45001 ADD A,12 Add 12.
45003 CP (IX+3) Compare it with the height of the valve.
45006 JR Z,HandleValve_Arrived Jump to HandleValve_Arrived if the valve is on the socket.
Move the valve if it is not placed yet.
HandleValve_Fall 45008 CALL ApplyGravityAndMove Call ApplyGravityAndMove.
45011 BIT 0,(IX+13) Jump to HandleValve_Dropped if the valve has been dropped.
45015 JR NZ,HandleValve_Dropped
45017 CALL TestObjectMoving Return if the valve is not moving.
45020 RET Z
HandleValve_Dropped 45021 RES 0,(IX+13) Reset bit 0 of the state.
45025 CALL ClearSpeed Call ClearSpeed.
45028 JP PlaySoundAndRedraw Jump to PlaySoundAndRedraw.
Place the valve on the socket.
HandleValve_Arrived 45031 LD A,(IX+0) Fetch the object number of the valve.
45034 XOR (IY+0) Combine it with that of the socket.
45037 AND %00000011 Keep bits 0 and 1.
45039 JR Z,HandleValve_PlaceValve Jump to HandleValve_PlaceValve if the shapes are the same.
45041 LD (IX+0),64 Write 64 as the sprite number.
45045 JP SetWipeAndDrawFlags Jump to SetWipeAndDrawFlags.
HandleValve_PlaceValve 45048 LD A,(IX+0) Fetch the object number of the valve.
45051 OR %00000100 Set bit 2.
45053 LD (IX+0),A Store the object number.
45056 CALL PlaySoundAndRedraw Call PlaySoundAndRedraw.
45059 LD D,16 Set a counter of 16.
Cycle the screen colours.
HandleValve_CycleColours 45061 LD HL,22528 Point HL at 22528 (in the attribute buffer).
45064 LD BC,768 Set BC to 768.
HandleValve_CycleAttribute 45067 LD A,(HL) Fetch an attribute.
45068 AND %11111000 Keep bits 3 to 7.
45070 LD E,A Keep it in E.
45071 LD A,(HL) Fetch the attribute and add one.
45072 INC A
45073 AND %00000111 Keep bits 0 to 2.
45075 OR E Combine it with the rest of the attribute.
45076 LD (HL),A Store the new attribute.
45077 INC HL Move on to the next attribute.
45078 DEC BC Count down the attributes.
45079 LD A,B Jump to HandleValve_CycleAttribute until all of them have been changed.
45080 OR C
45081 JR NZ,HandleValve_CycleAttribute
45083 CALL PlaySparkleSound Call PlaySparkleSound.
45086 LD BC,512 Set BC to 512.
HandleValve_Delay 45089 DEC BC Jump to HandleValve_Delay until the delay is done.
45090 LD A,B
45091 OR C
45092 JR NZ,HandleValve_Delay
45094 DEC D Jump to HandleValve_CycleColours until all of the colours have been cycled.
45095 JR NZ,HandleValve_CycleColours
45097 LD HL,(23348) Fetch ChamberAddress.
45100 LD A,(HL) Fetch the colour of the room.
45101 OR %00000111 Set bits 0 to 2.
45103 LD (HL),A Store the colour of the chamber.
45104 AND %00000111 Keep bits 0 to 2.
45106 LD (23309),A Set RoomColour.
45109 CALL UpdatePanel Call UpdatePanel.
45112 LD HL,23360 Point HL at ChambersActivated.
45115 LD A,(HL) Add one to ChambersActivated.
45116 ADD A,1
45118 DAA
45119 LD (HL),A
45120 CP 36 Jump to HandleValve_Finish unless it is 36.
45122 JR NZ,HandleValve_Finish
45124 LD A,1 Write 1 to GameCompletedFlag.
45126 LD (23331),A
45129 JP GameOver Jump to GameOver.
HandleValve_Finish 45132 CALL PrintActivatedChambers Call PrintActivatedChambers.
45135 LD BC,6176 Set the pixel position to 32, 24.
45138 JP CopyAreaToScreen Jump to CopyAreaToScreen.
Prev: 44863 Up: Map Next: 45141