Prev: AF3F Up: Map Next: AFDA
AF56: Set Up Room Objects
Used by the routine at Draw_Room.
Sets up the objects of a room that is in the lower part of the map (the room y is 10 or more) when the room is drawn.
The two decoration records that start at Object_Record_10 are emptied. The two before them are emptied too, unless they hold a bubble. What happens next depends on the first byte of the world map entry of the room (see Draw_Ceiling).
A room with both a ceiling and a floor gets a plant and a rock. Their x positions come from the table at Room_Object_X_Positions, and the rock is one of the four templates at Rock_Templates.
A room with no floor gets the objects that are set up by Set_Up_Stalactites. A room with a floor but no ceiling gets the two objects of type 54 that start at Spikes_Templates.
Set_Up_Room_Objects AF56 CALL Read_World_Map Read the world map entry of the room. The flags of the room are returned in E.
AF59 XOR A Clear the type of the first room object record (Object_Record_10).
AF5A LD ($8F9A),A
AF5D LD ($8FAA),A Clear the type of the second room object record (Object_Record_11).
AF60 LD A,($8F7A) Fetch the type of the record at Object_Record_8.
AF63 AND %11111100 Ignore the low two bits.
AF65 CP $58 Jump to Set_Up_Room_Objects_Next_Record if the record holds a bubble (58 to 5B).
AF67 JR Z,Set_Up_Room_Objects_Next_Record
AF69 XOR A Write 00 to the type of the record at Object_Record_8.
AF6A LD ($8F7A),A
Set_Up_Room_Objects_Next_Record AF6D LD A,($8F8A) Fetch the type of the record at Object_Record_9.
AF70 AND %11111100 Ignore the low two bits.
AF72 CP $58 Jump to Set_Up_Room_Objects_Test_Flags if the record holds a bubble.
AF74 JR Z,Set_Up_Room_Objects_Test_Flags
AF76 XOR A Write 00 to the type of the record at Object_Record_9.
AF77 LD ($8F8A),A
Set_Up_Room_Objects_Test_Flags AF7A LD A,E Copy the flags of the room to A.
AF7B AND %00010001 Keep only the ceiling bit (bit 0) and the floor bit (bit 4).
AF7D CP $11 Jump to Set_Up_Room_Objects_Test_Floor if the room does not have both.
AF7F JR NZ,Set_Up_Room_Objects_Test_Floor
Put a plant and a rock in the room. The x positions come from the table at Room_Object_X_Positions, starting at an offset that is the sum of the room coordinates, modulo 10.
AF81 LD A,($8F1C) Fetch the room x of Sabreman.
AF84 LD L,A Copy it to L.
AF85 LD A,($8F1E) Fetch the room y of Sabreman.
AF88 ADD A,L Add the room x.
AF89 LD H,$00 Clear the high byte of the offset.
AF8B AND %00001111 Keep only the low four bits.
AF8D LD L,A Store the offset in L.
AF8E LD DE,$B757 Point at the table of x positions (Room_Object_X_Positions).
AF91 ADD HL,DE Add the offset.
AF92 EX DE,HL Move the table address to DE.
AF93 LD HL,$8F7B Point at the x position of the record (Object_Record_8_X_Position).
AF96 LD A,(DE) Fetch the x position of the plant from the table.
AF97 LD (HL),A Store it in the record.
AF98 INC DE Move on to the x position of the rock.
AF99 LD HL,$8F7D Point at the y position of the record (Object_Record_8_Y_Position).
AF9C LD (HL),$9F Set the y position to 9F which is the floor.
AF9E LD HL,$8F7A Point at the type of the record (Object_Record_8).
AFA1 LD (HL),$1C Set the type to 1C (a plant).
AFA3 LD HL,$8F89 Point at the redraw flags of the record (Object_Record_8_Redraw_Flags).
AFA6 LD (HL),$01 Set the redraw flags to 01 so that the plant is drawn without being erased.
AFA8 PUSH DE Stash the table address on the stack.
AFA9 LD DE,$B76B Point at the templates of the rocks (Rock_Templates).
AFAC LD A,($8F1C) Fetch the room x of Sabreman.
AFAF LD C,A Copy it to C.
AFB0 RLA Multiply it by sixteen (rotate left four times).
AFB1 RLA
AFB2 RLA
AFB3 RLA
AFB4 AND %00110000 Keep only bits 4 and 5, which pick one of the four templates.
AFB6 LD L,A Store the offset of the template in L.
AFB7 LD H,$00 Clear the high byte of the offset.
AFB9 ADD HL,DE Add the address of the first template.
AFBA LD DE,$8F9A DE=Object_Record_10 (the first decoration record that is for a room object).
AFBD LD A,C Copy the room x to A (this is not used).
AFBE LD BC,$0010 Set the size of a record to 10.
AFC1 LDIR Copy the template into the record.
AFC3 POP DE Restore the table address from the stack.
AFC4 LD A,(DE) Fetch the x position of the rock from the table.
AFC5 LD ($8F9B),A Store it in the record.
AFC8 RET Return.
Set_Up_Room_Objects_Test_Floor AFC9 BIT 4,E Jump to Set_Up_Stalactites if the room has no floor.
AFCB JP Z,Set_Up_Stalactites
The room has a floor but no ceiling.
AFCE LD HL,$B7AB HL=Spikes_Templates (the templates of the two objects of type 54).
AFD1 LD DE,$8F9A DE=Object_Record_10 (the first decoration record that is for a room object).
AFD4 LD BC,$0020 Set the size of two records to 20.
AFD7 LDIR Copy the templates into the two records.
AFD9 RET Return.
Prev: AF3F Up: Map Next: AFDA