Prev: AB1F Up: Map Next: ABF5
AB61: Handle Attacking Tool
The handler for the boxing glove, hammer and hook (objects 51 to 53). In the game over scene they take it in turns to beat the robot, once the alarm has finished flashing (see HandleAlarm).
A tool swings towards the robot for six frames, makes a noise, and swings back for six frames. Bit 7 of the state holds the direction and bit 0 is set while it is attacking. The game restarts after 10 attacks, or if a number key is pressed.
Input
IX The address of the object
Start an attack, or keep one going.
HandleAttackingTool AB61 LD HL,$5B41 Point HL at GameOverSceneStage.
AB64 LD A,(HL) Jump to HandleAttackingTool_ColourCells if GameOverSceneStage is zero.
AB65 AND A
AB66 JR Z,HandleAttackingTool_ColourCells
AB68 LD A,$E7 Read from the keyboard;
Port Number Bit
0 1 2 3 4
E7 1 / 0 2 / 9 3 / 8 4 / 7 5 / 6
AB6A CALL ReadKeyboardPort
AB6D JP NZ,RestartGame Jump to RestartGame if a key is pressed.
AB70 BIT 0,(IX+$11) Jump to HandleAttackingTool_Swing if this tool is already attacking.
AB74 JR NZ,HandleAttackingTool_Swing
AB76 BIT 7,(HL) Jump to HandleAttackingTool_ColourCells if another tool is attacking.
AB78 JR NZ,HandleAttackingTool_ColourCells
AB7A LD A,($5B05) Fetch RandomSeed2.
AB7D CPL Invert it.
AB7E AND %00000011 Keep bits 0 and 1.
AB80 JR NZ,HandleAttackingTool_ColourCells Jump to HandleAttackingTool_ColourCells unless both bits were set.
AB82 PUSH HL Call PlayBumpSound, preserving HL.
AB83 CALL PlayBumpSound
AB86 POP HL
AB87 SET 0,(IX+$11) Set bit 0 of the state.
AB8B SET 7,(HL) Set bit 7 of GameOverSceneStage.
AB8D LD (IX+$0F),$06 Write 06 to the frame counter.
The boxing glove and the hook move along the x axis by 08; the hammer moves along the y axis by 04.
HandleAttackingTool_Swing AB91 LD A,(IX+$00) Fetch the sprite number.
AB94 AND %00000001 Keep bit 0.
AB96 JR Z,HandleAttackingTool_MoveAlongY Jump to HandleAttackingTool_MoveAlongY if the tool is the hammer.
AB98 LD A,(IX+$1A) Compare bit 7 of the pixel x with bit 7 of the direction.
AB9B XOR (IX+$11)
AB9E AND %10000000 Keep bit 7.
ABA0 LD A,$08 Set the step to 08.
ABA2 JR Z,HandleAttackingTool_MoveAlongX Jump to HandleAttackingTool_MoveAlongX if the step already points the right way.
ABA4 NEG Make the step negative.
HandleAttackingTool_MoveAlongX ABA6 ADD A,(IX+$1A) Add the step to the pixel x position.
ABA9 LD (IX+$1A),A
HandleAttackingTool_CountFrame ABAC DEC (IX+$0F) Jump to HandleAttackingTool_Redraw if this swing has not finished.
ABAF JR NZ,HandleAttackingTool_Redraw
ABB1 LD (IX+$0F),$06 Write 06 to the frame counter.
ABB5 LD A,(IX+$11) Fetch the state of the tool.
ABB8 XOR %10000000 Flip bit 7.
ABBA LD (IX+$11),A Store the state.
ABBD AND %10000000 Keep bit 7.
ABBF JR Z,HandleAttackingTool_AttackFinished Jump to HandleAttackingTool_AttackFinished if the tool has finished swinging back.
ABC1 CALL PlayRandomNoise Call PlayRandomNoise.
ABC4 JR HandleAttackingTool_Redraw Jump to HandleAttackingTool_Redraw.
The swing back has finished.
HandleAttackingTool_AttackFinished ABC6 RES 0,(IX+$11) Reset bit 0 of the state.
ABCA RES 7,(HL) Reset bit 7 of GameOverSceneStage.
ABCC INC (HL) Increment GameOverSceneStage.
ABCD LD A,(HL) Fetch GameOverSceneStage.
ABCE AND %01111111 Keep bits 0 to 6.
ABD0 CP $10 Jump to HandleAttackingTool_Redraw unless 10 attacks have been made.
ABD2 JR NZ,HandleAttackingTool_Redraw
ABD4 JP RestartGame Jump to RestartGame.
HandleAttackingTool_Redraw ABD7 CALL SetWipeAndDrawFlags Call SetWipeAndDrawFlags.
HandleAttackingTool_ColourCells ABDA JP ColourCells Jump to ColourCells.
Move the hammer along the y axis.
HandleAttackingTool_MoveAlongY ABDD LD A,(IX+$1B) Fetch the pixel y position.
ABE0 ADD A,$20 Add 20.
ABE2 XOR (IX+$11) Compare bit 7 with bit 7 of the direction.
ABE5 AND %10000000 Keep bit 7.
ABE7 LD A,$04 Set the step to 04.
ABE9 JR Z,HandleAttackingTool_AddStepToY Jump to HandleAttackingTool_AddStepToY if the step already points the right way.
ABEB NEG Make the step negative.
HandleAttackingTool_AddStepToY ABED ADD A,(IX+$1B) Add the step to the pixel y position.
ABF0 LD (IX+$1B),A
ABF3 JR HandleAttackingTool_CountFrame Jump to HandleAttackingTool_CountFrame.
Prev: AB1F Up: Map Next: ABF5