Prev: B4CD Up: Map Next: B57A
B4D1: Throw Weapon
Throws a weapon that Sabreman is carrying. Nothing happens if bit 0 of the redraw flags of Sabreman is set or if he is not carrying a weapon (one of the types 68 to 6B in the three slots from Weapon_Slots).
One weapon at a time is thrown unless the counter in Fire_Key_Flag allows another: the counter is reset while both weapon records are empty, and while a weapon is in flight it goes up each time this routine is called, so a weapon is thrown only when its low three bits are zero.
The weapon record is a free one of the two records at Object_Records and Second_Weapon_Record. The type, the position and the attribute are copied from Sabreman. The type of the weapon is then changed to the type of the projectile for the weapon that was carried (from the table at Weapon_Projectile_Types), plus one if it is thrown to the left. The weapon starts 08 pixels to the side of Sabreman and 08 pixels higher, with an x velocity between 40 and 7F and an upward y velocity that comes from the frame counter. Bit 2 of the type of Sabreman, less one (or less two if his type is 15 or more), tells which way he is facing (set for the right). The weapon is not thrown if there is no room to its left.
Input
IX Object record of Sabreman
Throw_Weapon B4D1 LD A,($8F29) Fetch the redraw flags of Sabreman.
B4D4 AND %00000001 Keep only bit 0.
B4D6 RET NZ Return if Sabreman has only just appeared in the room (bit 0 is set).
B4D7 LD HL,$8EEB Point HL at the first of the three slots that hold the items that Sabreman carries.
B4DA LD B,$03 Set a counter in B for the three slots.
Throw_Weapon_Find_Weapon B4DC LD A,(HL) Fetch the type of the item.
B4DD AND %11111100 Reset the two low bits.
B4DF CP $68 Jump to Throw_Weapon_Found if the item is a weapon.
B4E1 JR Z,Throw_Weapon_Found
B4E3 INC HL Move on to the next slot.
B4E4 DJNZ Throw_Weapon_Find_Weapon Decrease the slot counter and loop back for the next slot.
B4E6 RET Return, as Sabreman has no weapon.
Throw_Weapon_Found B4E7 LD C,(HL) Fetch the type of the weapon into C.
B4E8 LD A,($8EFA) Fetch the type of the first weapon record into B.
B4EB LD B,A
B4EC LD A,($8F0A) Combine it with the type of the second weapon record, and jump to Throw_Weapon_Store_Counter if both of the records are empty.
B4EF OR B
B4F0 JR Z,Throw_Weapon_Store_Counter
B4F2 LD A,($AAAB) Fetch the fire key flag.
B4F5 INC A Increase it.
Throw_Weapon_Store_Counter B4F6 LD ($AAAB),A Store the counter.
B4F9 AND %00000111 Keep only the low three bits.
B4FB RET NZ Return unless they are zero (a weapon can only be thrown on one pass in eight).
B4FC LD DE,$8EFA Point DE at Object_Records.
B4FF LD A,(DE) Fetch its type.
B500 AND A Jump to Throw_Weapon_Copy_Position if the record is empty.
B501 JR Z,Throw_Weapon_Copy_Position
B503 LD DE,$8F0A Point DE at Second_Weapon_Record.
B506 LD A,(DE) Fetch its type.
B507 AND A Return if the record is in use too.
B508 RET NZ
Throw_Weapon_Copy_Position B509 LD HL,$8F1A Point HL at the record of Sabreman.
B50C PUSH BC Stash the type of the weapon.
B50D LD BC,$0006 Set the number of bytes to copy to 06.
B510 PUSH DE Stash the address of the weapon record.
B511 LDIR Copy the type, the position and the attribute of Sabreman to the weapon record.
B513 POP HL Restore the address of the weapon record to HL.
B514 POP BC Restore the type of the weapon to C.
B515 LD A,($5C78) Fetch the low byte of the frame counter.
B518 LD B,A Store it in B.
B519 LD A,($8ED6) Fetch the tick counter.
B51C ADD A,B Add the low byte of the frame counter.
B51D AND %01111111 Keep only the low seven bits.
B51F OR %01000000 Set bit 6.
B521 LD B,A Store the result in B, to use as the x velocity of the weapon.
B522 LD A,C Fetch the type of the weapon.
B523 AND %00000011 Keep only the two low bits.
B525 LD DE,$B753 Point DE at Weapon_Projectile_Types.
B528 ADD A,E Add the weapon number to the address.
B529 LD E,A
B52A LD A,D
B52B ADC A,$00
B52D LD D,A
B52E LD A,(DE) Fetch the type of the projectile into C.
B52F LD C,A
B530 LD A,(IX+$00) Fetch the type of Sabreman.
B533 CP $15 Jump to Adjust_Throw_Facing if the type is 15 or more.
B535 JR NC,Adjust_Throw_Facing
B537 DEC A Subtract one from the type.
This entry point is used by the routine at Adjust_Throw_Facing.
Throw_Weapon_Test_Facing B538 INC HL Move to the x position in the weapon record.
B539 LD DE,$0003 Set DE to 03.
B53C AND %00000100 Test which way Sabreman is facing (bit 2 of the type that was worked out).
B53E LD A,(HL) Fetch the x position.
B53F JR Z,Throw_Weapon_Face_Left Jump to Throw_Weapon_Face_Left if Sabreman is facing left.
B541 ADD A,$08 Add 08 to start the weapon on his right.
B543 JR Throw_Weapon_Store_Position Jump to Throw_Weapon_Store_Position.
Throw_Weapon_Face_Left B545 SUB $08 Jump to Throw_Weapon_Cancel if the x position would be below zero.
B547 JR C,Throw_Weapon_Cancel
B549 PUSH AF Invert the x velocity in B, so that it is negative.
B54A LD A,B
B54B CPL
B54C LD B,A
B54D POP AF
B54E INC C Use the next projectile type, for a weapon that travels to the left.
Throw_Weapon_Store_Position B54F LD (HL),A Store the x position.
B550 DEC HL Move back to the type.
B551 LD (HL),C Store the type of the projectile.
B552 INC HL Move to the y position.
B553 INC HL
B554 INC HL
B555 LD A,(HL) Fetch the y position.
B556 SUB $08 Subtract 08.
B558 LD (HL),A Store the y position.
B559 ADD HL,DE Move to byte 06 of the record.
B55A LD (HL),$00 Clear byte 06 of the record.
B55C INC HL Move to the x velocity.
B55D INC HL
B55E LD (HL),B Store the x velocity.
B55F INC HL Move to the y velocity.
B560 LD A,($5C78) Fetch the low byte of the frame counter.
B563 RLA Multiply it by four.
B564 RLA
B565 AND %01111111 Keep only the low seven bits.
B567 NEG Negate it, to make an upward velocity.
B569 LD (HL),A Store the y velocity.
B56A LD A,($8F25) Fetch the contact flags of Sabreman.
B56D INC HL Move to the contact flags.
B56E INC HL
B56F LD (HL),A Store the contact flags.
B570 LD E,$04 Set E to 04.
B572 ADD HL,DE Move to the redraw flags.
B573 LD (HL),$01 Set bit 0 of the redraw flags, so that the weapon is drawn without being erased first.
B575 RET Return.
Throw_Weapon_Cancel B576 DEC HL Move back to the type.
B577 LD (HL),$00 Empty the weapon record.
B579 RET Return.
Prev: B4CD Up: Map Next: B57A