Prev: 8820 Up: Map Next: 890D
882B: Fire Shot
Used by the routine at FireRandomShot.
Starts a shot (type 1C) from an object, in one of the three shot slots. The kind of shot is chosen by the caller using the value in ScratchValue.
Input
IX Address of the object that fires
Output
IY Address of the shot slot
FireShot 882B PUSH IX Save the address of the object.
882D LD A,$03 Look for a free slot among three slots...
882F LD IX,$99D4 ...starting at the first shot slot.
8833 CALL FindFreeSlot Search for a free slot.
8836 PUSH IX Copy the address of the slot into IY...
8838 POP IY
883A POP IX ...and restore the address of the object.
883C RET NZ Return if there are no free slots.
883D LD A,(IX+$11) Fetch the horizontal screen position of the object.
8840 CP $C0 Return if it is off the right-hand side of the screen...
8842 RET NC
8843 CP $18 ...or off the left-hand side.
8845 RET C
8846 LD A,($5C1C) Fetch the kind of shot from ScratchValue.
8849 LD HL,$89A6 Use the table of shot flags at ShotTables, less one.
884C CALL AddAToHL Add the kind of shot to the address.
884F LD A,(HL) Fetch the flags for this kind of shot.
8850 LD ($5C1D),A Store them in TileNumber.
8853 LD A,(IX+$12) Fetch the vertical screen position of the object.
8856 BIT 7,(HL) Jump to FireShot_CheckHigh if bit 7 of the flags is clear.
8858 JR Z,FireShot_CheckHigh
885A CP $58 Return if the object is too low down the screen for this shot.
885C RET NC
FireShot_CheckHigh 885D BIT 6,(HL) Jump to FireShot_Start if bit 6 of the flags is clear.
885F JR Z,FireShot_Start
8861 CP $50 Return if the object is too high up the screen for this shot.
8863 RET C
FireShot_Start 8864 CALL SwapObjects Swap IX and IY, then copy the position of the object.
8867 CALL FreeObjectSlot Clear the slot of the shot.
886A LD (IX+$00),$1C Make the object a shot.
886E LD (IX+$10),$20 Set the flags of the shot.
8872 LD HL,$89AB Use the table of shot speeds at ShotTables_Speeds.
8875 LD A,($5C1C) Fetch the kind of shot.
8878 ADD A,A Multiply it by four.
8879 ADD A,A
887A CALL AddAToHL Add it to the address.
887D LD A,(HL) Set the horizontal speed of the shot from the table.
887E LD (IX+$07),A
8881 INC HL
8882 LD A,(HL)
8883 LD (IX+$09),A Set the vertical speed of the shot from the table.
8886 INC HL
8887 LD A,(HL)
8888 LD (IX+$13),A Set the first state byte of the shot from the table.
888B INC HL
888C LD A,(HL)
888D LD (IX+$14),A Set the second state byte of the shot from the table.
8890 LD A,($5C1D) Fetch the flags for this kind of shot.
8893 AND %00001111 Keep the colour in the bottom four bits.
8895 LD B,A Copy it into the top four bits...
8896 ADD A,A
8897 ADD A,A
8898 ADD A,A
8899 ADD A,A
889A OR B ...and set the attribute of the shot.
889B LD (IX+$0D),A
889E LD (IX+$15),$38 Set the lifetime of the shot to 38.
88A2 CALL MoveObject Draw the shot.
88A5 PUSH IY Swap IX and IY back again.
88A7 PUSH IX
88A9 POP IY
88AB POP IX
88AD LD A,(IY+$13) Fetch the state of the object that fired the shot.
88B0 AND %00001111 Keep the bottom four bits.
88B2 JP Z,SetFallingSpeed Jump to SetFallingSpeed if it is zero.
88B5 CP $05 Jump to SetRandomSpeed if it is 05.
88B7 JP Z,SetRandomSpeed
88BA CP $06 Jump to SetRandomSpeed if it is 06.
88BC JP Z,SetRandomSpeed
88BF CP $07 Jump to ReverseVerticalSpeed if it is 07.
88C1 JP Z,ReverseVerticalSpeed
88C4 CP $0A Jump to FireShot_State0A if it is 0A.
88C6 JP Z,FireShot_State0A
88C9 LD H,(IX+$07) Fetch the horizontal speed of the shot...
88CC LD L,(IX+$08)
88CF SRA H ...halve it...
88D1 RR L
88D3 LD (IY+$07),H ...and give it to the object that fired.
88D6 LD (IY+$08),L
88D9 LD A,($5C1D) Fetch the flags for this kind of shot.
88DC LD (IY+$09),$05 Set the vertical speed of the object to push it up.
88E0 BIT 7,A Jump to FireShot_Sound if bit 7 of the flags is set.
88E2 JR NZ,FireShot_Sound
88E4 LD (IY+$09),$FB Otherwise set the vertical speed to push it down instead.
This entry point is used by the routines at SetRandomSpeed, SetFallingSpeed and ReverseVerticalSpeed.
FireShot_Sound 88E8 LD A,(IY+$00) Fetch the type of the object.
88EB INC A Increment it.
88EC CALL NZ,PlayNoiseBurst Play a sound if the object is active.
88EF RET Return.
FireShot_State0A 88F0 LD (IY+$07),$06 Set the horizontal speed of the object to six...
88F4 LD (IY+$08),$00 ...and clear its other speeds.
88F8 LD (IY+$09),$00
88FC LD (IY+$0A),$00
8900 LD A,($5C1C) Fetch the kind of shot.
8903 CP $07 Jump to FireShot_Sound if it is 07.
8905 JR Z,FireShot_Sound
8907 LD (IY+$07),$FA Otherwise reverse the horizontal speed.
890B JR FireShot_Sound Jump to FireShot_Sound.
Prev: 8820 Up: Map Next: 890D