Prev: 42534 Up: Map Next: 42670
42582: Fire Weapon B
Used by the routine at MoveRobotHorizontally.
Fires a pellet, which is the second weapon of the robot. It is cheaper than a spark, as it only costs half a unit of energy.
Input
A Controls that are being pressed
IX Robot
FireWeaponB 42582 RES 3,A Clear the flag that says that the second weapon has been fired...
42584 LD (38437),A ...and store the controls.
42587 LD HL,38560 Point HL at the first of the three entities that are used for shots.
42590 LD DE,16 Each entity is 16 bytes long.
42593 LD BC,128 Set the cost of the shot to 128...
42596 LD (38463),BC ...and store it.
42600 LD BC,816 Use three entities, and use type 48 for the sprite.
42603 LD A,7 Use the lowest three bits of the type of the robot...
42605 LD (42634),A ...to choose the sprite of the shot (this changes the mask used by the instruction at 42633).
This entry point is used by the routine at FireWeaponA.
This entry point finds an entity that is not in use and starts a shot there.
FireWeapon_Find 42608 LD A,(HL) Fetch the type of the entity.
42609 AND A Jump if it is not in use.
42610 JR Z,FireWeapon_Start
42612 ADD HL,DE Move on to the next entity.
42613 DJNZ FireWeapon_Find Loop back until all of them have been tried.
42615 RET Return, as all are in use.
FireWeapon_Start 42616 PUSH HL Save the address of the entity...
42617 PUSH DE ...and the size of an entity.
42618 LD DE,(38463) Fetch the cost of the shot.
42622 CALL UseEnergy Take it off the energy of the battery using UseEnergy.
42625 POP DE Restore the size of an entity...
42626 POP HL ...and the address of the entity.
42627 RET C Return if there was not enough energy.
42628 LD A,(IX+0) Fetch the type of the robot...
42631 RRCA ...divide it by two...
42632 LD B,A ...and keep it in B.
42633 AND 7 Keep the bits that choose the sprite (the mask is changed by the code above, from 7 to 3 for the first weapon)...
42635 OR C ...and use them with the first sprite of the shot...
42636 LD (HL),A ...as the type of the shot.
42637 INC HL Move on to the X fraction of the shot.
42638 LD A,(IX+1) Copy the X fraction of the robot to the shot.
42641 LD (HL),A
42642 INC HL Move on to the X cell of the shot.
42643 LD A,(IX+2) Copy the X cell of the robot to the shot.
42646 LD (HL),A
42647 INC HL Move on to the Y fraction of the shot.
42648 LD A,(IX+3) Copy the Y fraction of the robot to the shot.
42651 LD (HL),A
42652 INC HL Move on to the Y cell of the shot.
42653 LD A,(IX+4) Copy the Y cell of the robot to the shot.
42656 LD (HL),A
42657 INC HL Move on to the byte that holds the direction and the range.
42658 INC HL
42659 INC HL
42660 LD A,B Fetch the type of the robot, divided by two.
42661 RRCA Divide it by two again...
42662 AND 3 ...and keep the direction...
42664 OR 96 ...together with the range of six cells.
42666 LD (HL),A Store them.
42667 JP PlayNoiseSound Jump to PlayNoiseSound.
Prev: 42534 Up: Map Next: 42670