Prev: E8BE Up: Map Next: E9DF
E8D7: Handle Weapon Pickup
Handler for the object types 68 to 6B the four weapons that Sabreman can pick up (see Sprite_Weapon_1). The weapons are the small object records at Small_Object_Records. Byte 07 of a record holds the flags: bit 0 is set if there is no old image to erase, bit 1 is set while Sabreman carries the weapon and bit 2 is set while the weapon falls.
A weapon that lies on the floor is drawn again and again. When an action key has just been pressed (the flag at New_Action_Key_Press_Flag is FF) and Sabreman is touching it (see Check_Sabreman_Contact), he picks it up: the weapon moves to the x position 88 and the y position 0F which is its place in the panel at the top of the screen, bit 1 of the flags is set, the flag at New_Action_Key_Press_Flag is set to FE to show that the key press has been used, and the type of the weapon is stored in the first of the weapon slots at Weapon_Slots.
Each later key press moves a carried weapon 18 pixels to the right in the panel and stores its type in the weapon slot that goes with the new x position (the x positions A0 and B8 both give the third slot, and none gives the second). A key press when the weapon has reached B8 makes Sabreman drop it. It is put at his position, with bit 1 of the flags reset, bit 2 set and the counter in byte 06 set to 10 and it falls (see Handle_Weapon_Pickup_Fall).
A weapon that is in a different room is dealt with by Handle_Distant_Weapon.
Input
IX Small object record of the weapon
Handle_Weapon_Pickup E8D7 CALL StoreEntity Save the state of the weapon.
E8DA BIT 1,(IX+$07) Jump to Handle_Weapon_Pickup_Carried if Sabreman is carrying the weapon.
E8DE JR NZ,Handle_Weapon_Pickup_Carried
E8E0 LD A,($8F1C) Fetch the room x of Sabreman.
E8E3 CP (IX+$02) Jump to Handle_Distant_Weapon if the weapon is in a different room x.
E8E6 JP NZ,Handle_Distant_Weapon
E8E9 LD A,($8F1E) Fetch the room y of Sabreman.
E8EC CP (IX+$04) Jump to Handle_Distant_Weapon if the weapon is in a different room y.
E8EF JP NZ,Handle_Distant_Weapon
E8F2 BIT 0,(IX+$07) Jump to Update_Object_Sprite_Using_Flags if it has no old image to erase.
E8F6 JP NZ,Update_Object_Sprite_Using_Flags
E8F9 BIT 2,(IX+$07) Jump to Handle_Weapon_Pickup_Fall if the weapon is falling.
E8FD JP NZ,Handle_Weapon_Pickup_Fall
E900 LD A,($8EEA) Fetch the flag for a new action key press.
E903 AND A Jump to Handle_Weapon_Pickup_Draw if no action key has been pressed.
E904 JR Z,Handle_Weapon_Pickup_Draw
E906 INC A Jump to Handle_Weapon_Pickup_Draw if the key press has been used already (the flag is not FF).
E907 JR NZ,Handle_Weapon_Pickup_Draw
E909 CALL Check_Sabreman_Contact Check for contact with Sabreman.
E90C BIT 2,C Jump to Handle_Weapon_Pickup_Draw if Sabreman is not touching the weapon.
E90E JR Z,Handle_Weapon_Pickup_Draw
E910 LD (IX+$01),$88 Set the x position of the weapon to 88.
E914 LD (IX+$03),$0F Set the y position of the weapon to 0F.
E918 SET 1,(IX+$07) Set bit 1 of the flags, as Sabreman carries the weapon.
E91C LD A,$FE Mark the key press as used by writing FE to New_Action_Key_Press_Flag.
E91E LD ($8EEA),A
E921 LD A,(IX+$00) Fetch the type of the weapon.
E924 LD ($8EEB),A Store it in the first weapon slot.
E927 JP Update_Object_Sprite_Using_Flags Jump to Update_Object_Sprite_Using_Flags.
Handle_Weapon_Pickup_Carried E92A RES 0,(IX+$07) Reset bit 0 of the flags.
E92E LD A,($8EEA) Fetch the flag for a new action key press.
E931 AND A Jump to Handle_Weapon_Pickup_Draw if no action key has been pressed.
E932 JR Z,Handle_Weapon_Pickup_Draw
E934 LD A,(IX+$01) Fetch the x position of the weapon.
E937 ADD A,$18 Add 18 to move it to the next place in the panel.
E939 CP $C8 Jump to Handle_Weapon_Pickup_Next_Slot if the result is less than C8.
E93B JR C,Handle_Weapon_Pickup_Next_Slot
E93D LD HL,($8F1B) Fetch the x position and the room x of Sabreman.
E940 LD (IX+$01),L Set the x position of the weapon.
E943 LD (IX+$02),H Set the room x of the weapon.
E946 LD HL,($8F1D) Fetch the y position and the room y of Sabreman.
E949 LD (IX+$03),L Set the y position of the weapon.
E94C LD (IX+$04),H Set the room y of the weapon.
E94F RES 1,(IX+$07) Reset bit 1 of the flags, as the weapon is dropped.
E953 SET 2,(IX+$07) Set bit 2 of the flags, as the weapon falls.
E957 LD (IX+$06),$10 Set the counter in byte 06 to 10.
E95B JP Update_Object_Sprite_Using_Flags Jump to Update_Object_Sprite_Using_Flags.
Handle_Weapon_Pickup_Next_Slot E95E LD (IX+$01),A Set the x position of the weapon.
E961 RRA Shift the x position right four times.
E962 RRA
E963 RRA
E964 RRA
E965 AND %00000011 Keep only the two low bits.
E967 CP $03 Jump to Handle_Weapon_Pickup_Store_Slot unless the result is 03.
E969 JR NZ,Handle_Weapon_Pickup_Store_Slot
E96B DEC A Change 03 to 02.
Handle_Weapon_Pickup_Store_Slot E96C LD E,A Store the weapon slot number in E.
E96D LD D,$00 Clear the high byte of the slot number.
E96F LD HL,$8EEB Point HL at Weapon_Slots.
E972 ADD HL,DE Add the slot number to point at the weapon slot.
E973 LD A,(IX+$00) Fetch the type of the weapon.
E976 LD (HL),A Store it in the weapon slot.
E977 JP Update_Object_Sprite_Using_Flags Jump to Update_Object_Sprite_Using_Flags.
Handle_Weapon_Pickup_Draw E97A CALL PrepDraw2 Prepare the sprite of the weapon.
E97D JP ColourEntity Jump to ColourEntity.
The weapon falls. The counter in byte 06 goes up on every call and one sixteenth of it is added to the y position.
Handle_Weapon_Pickup_Fall E980 LD A,(IX+$06) Fetch the counter.
E983 INC (IX+$06) Add one to the counter.
E986 RRA Divide the old value by sixteen.
E987 RRA
E988 RRA
E989 RRA
E98A AND %00001111 Keep only the low four bits.
E98C ADD A,(IX+$03) Add the y position of the weapon.
E98F LD (IX+$03),A Set the y position of the weapon.
E992 CALL Check_Decoration_Contact Check for contact with the decorations.
E995 BIT 2,C Jump to Handle_Weapon_Pickup_Check_Floor if the weapon is not touching a decoration.
E997 JR Z,Handle_Weapon_Pickup_Check_Floor
E999 LD A,B Copy A0 less the y position of the top of the decoration to A.
E99A NEG Negate it.
E99C ADD A,$A1 Add A1 to get the y position just below the top of the decoration.
E99E LD (IX+$03),A Set the y position of the weapon.
E9A1 RES 2,(IX+$07) Reset bit 2 of the flags, as the weapon has stopped falling.
E9A5 JP Update_Object_Sprite_Using_Flags Jump to Update_Object_Sprite_Using_Flags.
Handle_Weapon_Pickup_Check_Floor E9A8 LD A,(IX+$03) Fetch the y position of the weapon.
E9AB CP $9F Jump to Update_Object_Sprite_Using_Flags if it is less than 9F.
E9AD JP C,Update_Object_Sprite_Using_Flags
E9B0 CALL Read_World_Map Read the world map entry of the room that the weapon is in. The flags of the room are returned in E.
E9B3 BIT 4,E Jump to Handle_Weapon_Pickup_Check_Bottom if the room has no floor.
E9B5 JR Z,Handle_Weapon_Pickup_Check_Bottom
E9B7 LD (IX+$03),$9F Set the y position of the weapon to 9F which is the floor.
E9BB RES 2,(IX+$07) Reset bit 2 of the flags, as the weapon has stopped falling.
E9BF JP Update_Object_Sprite_Using_Flags Jump to Update_Object_Sprite_Using_Flags.
Handle_Weapon_Pickup_Check_Bottom E9C2 LD A,(IX+$03) Fetch the y position of the weapon.
E9C5 CP $BF Jump to Update_Object_Sprite_Using_Flags if it is less than BF.
E9C7 JP C,Update_Object_Sprite_Using_Flags
Handle_Weapon_Pickup_Next_Room E9CA INC (IX+$04) Move the weapon to the room below.
E9CD CALL Read_World_Map Read the world map entry of the room that the weapon is in.
E9D0 BIT 4,E Jump back to Handle_Weapon_Pickup_Next_Room if the room has no floor.
E9D2 JR Z,Handle_Weapon_Pickup_Next_Room
E9D4 LD (IX+$03),$9E Set the y position of the weapon to 9E.
E9D8 LD (IX+$06),$00 Clear the counter in byte 06.
E9DC JP RemoveEntity Erase the sprite of the weapon.
Prev: E8BE Up: Map Next: E9DF