Prev: EC1C Up: Map Next: ECBD
EC3A: Place Special Object
Used by the routine at Draw_Room.
Puts an extra life or a guardian in the room that Sabreman has just entered, if there is one in it and it has not been collected or destroyed.
The room of Sabreman is looked up in the table of the sixteen extra lives at Extra_Life_Table and then in the table of the guardians at Guardian_Table (the entries are three bytes long: the room x, the room y and a collected flag). A guardian is dealt with by Place_Guardian.
An extra life is made from a copy of the template at Extra_Life_Template in the first of the two special object records at First_Special_Object_Record. Byte 06 of the record holds the number of the entry, counted from the end of the table, which Collect_Extra_Life uses to set the collected flag when the extra life is picked up.
The extra life sits on top of one of the two objects at Object_Record_10 and Object_Record_11, which are the decorations of a special room or the stalactites of a cave: the first is used if the room y is odd, the second if it is even. In a special room the height of the object comes from the table at Decoration_Height_Table.
The loop over the guardians counts eight entries, but the table only has four, so it carries on into the code that follows the table.
Place_Special_Object EC3A LD HL,$EDC4 Point HL at the table of extra lives.
EC3D LD A,($8F1C) Fetch the room x of Sabreman.
EC40 LD E,A Store it in E.
EC41 LD A,($8F1E) Fetch the room y of Sabreman.
EC44 LD D,A Store it in D.
EC45 LD B,$10 Set the number of extra lives to check to 10.
Place_Special_Object_Find_Extra_Life EC47 LD A,(HL) Fetch the room x of the entry.
EC48 INC HL Move on to the room y.
EC49 CP E Jump to Place_Special_Object_Next_Extra_Life if it is not the room x of Sabreman.
EC4A JR NZ,Place_Special_Object_Next_Extra_Life
EC4C LD A,(HL) Fetch the room y of the entry.
EC4D CP D Jump to Place_Special_Object_Extra_Life if it is the room y of Sabreman.
EC4E JR Z,Place_Special_Object_Extra_Life
Place_Special_Object_Next_Extra_Life EC50 INC HL Move on to the next entry.
EC51 INC HL
EC52 DJNZ Place_Special_Object_Find_Extra_Life Loop back until all the extra lives have been checked.
EC54 LD HL,$EDF4 Point HL at Guardian_Table.
EC57 LD B,$08 Set the number of guardians to check to 08.
Place_Special_Object_Find_Guardian EC59 LD A,(HL) Fetch the room x of the entry.
EC5A INC HL Move on to the room y.
EC5B CP E Jump to Place_Special_Object_Next_Guardian if it is not the room x of Sabreman.
EC5C JR NZ,Place_Special_Object_Next_Guardian
EC5E LD A,(HL) Fetch the room y of the entry.
EC5F CP D Jump to Place_Guardian if it is the room y of Sabreman, to place the guardian.
EC60 JP Z,Place_Guardian
Place_Special_Object_Next_Guardian EC63 INC HL Move on to the next entry.
EC64 INC HL
EC65 DJNZ Place_Special_Object_Find_Guardian Loop back until all the entries have been checked.
EC67 RET Return.
Place_Special_Object_Extra_Life EC68 INC HL Move on to the collected flag of the entry.
EC69 LD A,(HL) Fetch the collected flag.
EC6A AND A Return if the extra life has been collected already.
EC6B RET NZ
EC6C LD A,B Fetch the number of the entry, counted from the end of the table.
EC6D PUSH DE Stash the room of Sabreman.
EC6E LD HL,$EDB4 Point HL at Extra_Life_Template.
EC71 LD DE,$8FBA Point DE at First_Special_Object_Record.
EC74 LD BC,$0010 Set the size of a record in BC.
EC77 LDIR Copy the template to the record.
EC79 LD ($8FC0),A Store the number of the entry in byte 06 of the record.
EC7C POP BC Restore the room of Sabreman into BC.
EC7D DI Disable interrupts.
EC7E PUSH IY Save IY.
EC80 LD IY,$8F9A Point IY at the object at Object_Record_10.
EC84 BIT 0,B Jump to Place_Special_Object_Set_Position if the room y is odd.
EC86 JR NZ,Place_Special_Object_Set_Position
EC88 LD IY,$8FAA Point IY at the object at Object_Record_11 instead.
Place_Special_Object_Set_Position EC8C LD DE,$8FBB Point DE at the x position of the special object record.
EC8F LD A,(IY+$01) Fetch the x position of the object.
EC92 ADD A,$08 Add 08.
EC94 LD (DE),A Set the x position of the extra life.
EC95 INC DE Move on to the room x.
EC96 LD A,C Fetch the room x.
EC97 LD (DE),A Set the room x of the extra life.
EC98 INC DE Move on to the y position.
EC99 LD A,B Fetch the room y.
EC9A CP $10 Jump to Place_Special_Object_Set_Top if the room is a cave (the room y is 10 or more).
EC9C JR NC,Place_Special_Object_Set_Top
Place_Special_Object_Set_Height EC9E LD HL,$EBB5 Point HL at Decoration_Height_Table.
ECA1 LD A,(IY+$00) Fetch the type of the decoration.
ECA4 SUB $74 Subtract 74 to make the number of the decoration.
ECA6 ADD A,L Add the number to the address in HL.
ECA7 LD L,A Store the low byte of the address.
ECA8 LD A,H Fetch the high byte of the address.
ECA9 ADC A,$00 Add the carry.
ECAB LD H,A Store the high byte of the address.
ECAC LD A,(HL) Fetch the height of the decoration.
ECAD LD (IY+$0C),A Store it in byte 0C of the object, where the size of the obstacle is kept.
Place_Special_Object_Set_Top ECB0 LD A,(IY+$03) Fetch the y position of the object.
ECB3 SUB (IY+$0C) Subtract its height to get the y position of its top.
ECB6 LD (DE),A Set the y position of the extra life.
ECB7 INC DE Move on to the room y.
ECB8 LD A,B Fetch the room y.
ECB9 LD (DE),A Set the room y of the extra life.
ECBA POP IY Restore IY.
ECBC RET Return.
Prev: EC1C Up: Map Next: ECBD