Prev: A33B Up: Map Next: A39C
A356: 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
00 The sprite ID, which is 80 plus the type of the object (bits 0-3 of the table entry)
01 The room the player is in
03 The X position
04 The Y position
05 The colour, see ObjectColours
06 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 A356 PUSH HL Stash the address of the table entry on the stack.
A357 LD C,A Stash the table entry in C.
A358 AND %00001111 Keep only the object type (bits 0-3).
A35A ADD A,$80 Add 80 to get the sprite ID.
A35C LD (DE),A Set the sprite ID of the object.
A35D INC DE Move onto the room of the object.
A35E LD A,(IX+$01) Fetch the room of the player.
A361 LD (DE),A Set the room of the object.
A362 INC DE Move onto the X position of the object.
A363 INC DE
Find the positions for the layout of the room.
A364 LD L,A Use the room as the offset into the layout table.
A365 LD H,$00 Clear H.
A367 PUSH DE Stash the pointer to the actor record on the stack.
A368 LD DE,$6066 Point DE at the layout table at Layout.
A36B ADD HL,DE Add the layout table address to get the address of the layout number for the room.
A36C LD L,(HL) Fetch the layout number of the room.
A36D LD H,$00 Clear H.
A36F ADD HL,HL Multiply HL by eight, as there are eight bytes of positions for each layout.
A370 ADD HL,HL
A371 ADD HL,HL
Use bits 6-7 of the table entry to choose one of the four positions.
A372 LD A,C Fetch the table entry.
A373 RLCA Rotate it left three times.
A374 RLCA
A375 RLCA
A376 AND %00000110 Keep only bits 1-2.
A378 LD E,A Stash the position offset in E.
A379 LD D,$00 Clear D.
A37B ADD HL,DE Add the position offset to the layout offset.
A37C LD DE,$DC6C Point DE at the table of object positions at ObjectLocation.
A37F ADD HL,DE Add the table address to get the address of the position.
A380 POP DE Restore the pointer to the actor record from the stack.
A381 LD A,(HL) Fetch the X position.
A382 INC HL Move onto the Y position.
A383 LD (DE),A Set the X position of the object.
A384 INC DE Move onto the Y position of the object.
A385 LD A,(HL) Fetch the Y position.
A386 LD (DE),A Set the Y position of the object.
A387 INC DE Move onto the colour of the object.
Look up the colour for the type of the object.
A388 LD A,C Fetch the table entry.
A389 AND %00001111 Keep only bits 0-3.
A38B LD C,A Stash the object type in C.
A38C LD B,$00 Clear B.
A38E LD HL,$A3A7 Point HL at the table of object colours at ObjectColours.
A391 ADD HL,BC Add the object type to get the address of the colour.
A392 LD A,(HL) Fetch the colour of the object.
A393 LD (DE),A Set the colour of the object.
A394 INC DE Move onto the address of the table entry in the actor record.
A395 POP HL Restore the address of the table entry from the stack.
A396 LD A,L Fetch the low byte of the address of the table entry.
A397 LD (DE),A Store it in the actor record.
A398 INC DE Move onto the high byte.
A399 LD A,H Fetch the high byte of the address of the table entry.
A39A LD (DE),A Store it in the actor record.
A39B RET Return.
Prev: A33B Up: Map Next: A39C