Prev: 41787 Up: Map Next: 41884
41814: Create Object
Used by the routine at SetUpRoomObjects.
Creates an object actor from an entry in the table of room objects (see GenerateRoomObjects). The actor is set up as follows:
Byte Contents
0 The sprite ID, which is 128 plus the type of the object (bits 0-3 of the table entry)
1 The room the player is in
3 The X position
4 The Y position
5 The colour, see ObjectColours
6 The address of the table entry, which CollectPickup clears when the object is collected
Input
A The table entry
DE Address of the actor record
HL Address of the table entry
IX Actor record of the player
CreateObject 41814 PUSH HL Stash the address of the table entry on the stack.
41815 LD C,A Stash the table entry in C.
41816 AND %00001111 Keep only the object type (bits 0-3).
41818 ADD A,128 Add 128 to get the sprite ID.
41820 LD (DE),A Set the sprite ID of the object.
41821 INC DE Move onto the room of the object.
41822 LD A,(IX+1) Fetch the room of the player.
41825 LD (DE),A Set the room of the object.
41826 INC DE Move onto the X position of the object.
41827 INC DE
Find the positions for the layout of the room.
41828 LD L,A Use the room as the offset into the layout table.
41829 LD H,0 Clear H.
41831 PUSH DE Stash the pointer to the actor record on the stack.
41832 LD DE,24678 Point DE at the layout table at Layout.
41835 ADD HL,DE Add the layout table address to get the address of the layout number for the room.
41836 LD L,(HL) Fetch the layout number of the room.
41837 LD H,0 Clear H.
41839 ADD HL,HL Multiply HL by eight, as there are eight bytes of positions for each layout.
41840 ADD HL,HL
41841 ADD HL,HL
Use bits 6-7 of the table entry to choose one of the four positions.
41842 LD A,C Fetch the table entry.
41843 RLCA Rotate it left three times.
41844 RLCA
41845 RLCA
41846 AND %00000110 Keep only bits 1-2.
41848 LD E,A Stash the position offset in E.
41849 LD D,0 Clear D.
41851 ADD HL,DE Add the position offset to the layout offset.
41852 LD DE,56428 Point DE at the table of object positions at ObjectLocation.
41855 ADD HL,DE Add the table address to get the address of the position.
41856 POP DE Restore the pointer to the actor record from the stack.
41857 LD A,(HL) Fetch the X position.
41858 INC HL Move onto the Y position.
41859 LD (DE),A Set the X position of the object.
41860 INC DE Move onto the Y position of the object.
41861 LD A,(HL) Fetch the Y position.
41862 LD (DE),A Set the Y position of the object.
41863 INC DE Move onto the colour of the object.
Look up the colour for the type of the object.
41864 LD A,C Fetch the table entry.
41865 AND %00001111 Keep only bits 0-3.
41867 LD C,A Stash the object type in C.
41868 LD B,0 Clear B.
41870 LD HL,41895 Point HL at the table of object colours at ObjectColours.
41873 ADD HL,BC Add the object type to get the address of the colour.
41874 LD A,(HL) Fetch the colour of the object.
41875 LD (DE),A Set the colour of the object.
41876 INC DE Move onto the address of the table entry in the actor record.
41877 POP HL Restore the address of the table entry from the stack.
41878 LD A,L Fetch the low byte of the address of the table entry.
41879 LD (DE),A Store it in the actor record.
41880 INC DE Move onto the high byte.
41881 LD A,H Fetch the high byte of the address of the table entry.
41882 LD (DE),A Store it in the actor record.
41883 RET Return.
Prev: 41787 Up: Map Next: 41884