Prev: CCD0 Up: Map Next: CE06
CCDE: Make Room Objects
Used by the routine at RetrieveRoom.
Makes the objects of a room from its entry in the room data. The colour of the room is the low three bits of the byte after the length, and the size of the room is the high two bits. The size gives the distance to the walls and the floor level, from the table at RoomSizes. Each type of block is the number of an entry in the table at BlockTypes, which holds the address of a template of one or more objects that already have their coordinates. These are copied into the objects table, along with the number of the room. The types of block end with a FF, or at the end of the entry if there are no more objects. After the FF come the groups of other objects, each with a type in bits 3 to 7 and one less than the number of places in bits 0 to 2, followed by that many positions (see RoomData). Type 00 sets the position offset at PositionOffset, and type 1F switches the table of types from ObjectTypes to SecondObjectTypes. The other types are lists of objects that have a sprite, a size and flags, but no coordinates.
Input
DE Address of the first object to make
HL Address of the length of the entry of the room
IX Address of the player
Set the colour of the room, the size and the floor.
MakeRoomObjects CCDE LD B,(HL) Fetch the length of the entry.
CCDF INC HL Point HL at the colour and size.
CCE0 LD A,(HL) Fetch the colour and size.
CCE1 AND %00000111 Keep the colour.
CCE3 LD ($5B0D),A Store it as the colour of the room at RoomColour.
CCE6 LD ($5B34),HL Store the address of the colour and size at ChamberAddress.
CCE9 PUSH DE Stash the address of the object to make on the stack.
CCEA EX DE,HL Point DE at the colour and size.
CCEB LD A,(DE) Fetch the colour and size.
CCEC INC DE Point DE at the types of block.
CCED RLCA Move the size into the low two bits.
CCEE RLCA
CCEF AND %00000011 Keep it.
CCF1 LD C,A Stash it in C.
CCF2 ADD A,A Multiply it by three.
CCF3 ADD A,C
CCF4 LD HL,$6460 Point HL at RoomSizes.
CCF7 CALL AddAToHL Add the offset to find the size.
CCFA LD A,(HL) Fetch the size of the room in X, and move on.
CCFB INC HL
CCFC LD ($5B0B),A Store it at RoomSize_X.
CCFF LD A,(HL) Fetch the size of the room in Y, and move on.
CD00 INC HL
CD01 LD ($5B0C),A Store it at RoomSize_Y.
CD04 LD A,(HL) Fetch the floor of the room.
CD05 LD ($5B0E),A Store it at FloorHeight.
CD08 DEC B Take two off the length that is left.
CD09 DEC B
CD0A EX DE,HL Point HL at the types of block.
CD0B POP DE Restore the address of the object to make from the stack.
Copy each type of block from BlockTypes.
MakeRoomObjects_Background CD0C LD A,(HL) Fetch the type of block, and move on.
CD0D INC HL
CD0E CP $FF Jump to MakeRoomObjects_Foreground if it is the end of the types.
CD10 JR Z,MakeRoomObjects_Foreground
CD12 PUSH BC Stash the length that is left and the address of the next type on the stack.
CD13 PUSH HL
Look up the list of objects of this type.
CD14 LD L,A Make the type into an offset.
CD15 LD H,$00
CD17 ADD HL,HL Double it.
CD18 LD BC,$7519 Point BC at BlockTypes.
CD1B ADD HL,BC Add the two.
CD1C LD A,(HL) Fetch the address of the list of objects of the block.
CD1D INC HL
CD1E LD H,(HL)
CD1F LD L,A
Copy one block object into the objects table.
MakeRoomObjects_BackgroundCopy CD20 LD BC,$0008 Set the number of bytes to copy to 08.
CD23 LDIR Copy the graphic number, the coordinates, the size and the flags of the object.
CD25 LD A,(IX+$08) Fetch the room number of the player.
CD28 LD (DE),A Set the room number of the object, and move on.
CD29 INC DE
CD2A LD B,$17 Set the number of bytes to 17.
CD2C CALL ClearBytes Clear the rest of the object.
CD2F LD A,(HL) Jump to MakeRoomObjects_BackgroundCopy if the list has not ended.
CD30 AND A
CD31 JR NZ,MakeRoomObjects_BackgroundCopy
CD33 POP HL Restore the address of the next type and the length that is left from the stack.
CD34 POP BC
CD35 DJNZ MakeRoomObjects_Background Jump to MakeRoomObjects_Background until all of the types have been used.
CD37 JP ClearRemainingObjects Jump to ClearRemainingObjects to clear the rest of the objects table.
The other objects. IY points at the object that is being made.
MakeRoomObjects_Foreground CD3A DEC B Take one off the length that is left, for the end of the types.
CD3B PUSH IY Stash IY on the stack.
CD3D PUSH DE Point IY at the object to make (using the stack).
CD3E POP IY
Decode the type and the number of places.
MakeRoomObjects_ForegroundObject CD40 LD A,(HL) Fetch the type and the number of places.
CD41 AND %00000111 Keep the count.
CD43 INC A Add one to get the number of times.
CD44 LD C,A Stash it in C.
CD45 LD A,(HL) Fetch the type and the number of places again, and move on.
CD46 INC HL
CD47 DEC B Take one off the length that is left.
CD48 LD D,(HL) Fetch the first place, and move on.
CD49 INC HL
CD4A PUSH HL Stash the address of the next byte on the stack.
CD4B RRCA Move the type into bits 1 to 5.
CD4C RRCA
CD4D AND %00111110 Keep it, to make it twice the number of the type.
CD4F JP Z,MakeRoomObjects_SetOffset Jump to MakeRoomObjects_SetOffset if the type is 00.
CD52 CP $3E Jump to MakeRoomObjects_SwitchTable if the type is 1F.
CD54 JP Z,MakeRoomObjects_SwitchTable
CD57 LD HL,($5B20) Fetch the address of the object types from ObjectTypeTableAddress.
CD5A CALL AddAToHL Add the offset to find the type.
CD5D LD A,(HL) Fetch the address of the list of objects of the type.
CD5E INC HL
CD5F LD H,(HL)
CD60 LD L,A
MakeRoomObjects_ForegroundPlace CD61 PUSH HL Stash the address of the list of objects on the stack.
Copy the sprite, the size and the flags from the type.
MakeRoomObjects_ForegroundSprite CD62 LD A,(HL) Fetch the sprite number, and move on.
CD63 INC HL
CD64 LD (IY+$00),A Set the sprite number of the object.
CD67 LD A,(HL) Fetch the width, and move on.
CD68 INC HL
CD69 LD (IY+$04),A Set the width of the object.
CD6C LD A,(HL) Fetch the depth, and move on.
CD6D INC HL
CD6E LD (IY+$05),A Set the depth of the object.
CD71 LD A,(HL) Fetch the height, and move on.
CD72 INC HL
CD73 LD (IY+$06),A Set the height of the object.
CD76 LD A,(HL) Fetch the flags, and move on.
CD77 INC HL
CD78 LD (IY+$07),A Set the flags of the object.
CD7B LD A,(IX+$08) Fetch the room number of the player.
CD7E LD (IY+$08),A Set the room number of the object.
The offset at PositionOffset has the half step along the x axis in bit 0, the half step along the y axis in bit 1, and the offset up the z axis in bits 2 to 7. The place has the x position in bits 0 to 2, the y position in bits 3 to 5 and the height in bits 6 and 7. The x position of the object is the x position times 10, plus 08 if the half step is set, plus 48.
CD81 LD A,($5B19) Fetch the position offset from PositionOffset.
CD84 RLCA Move the half step along x into bit 3.
CD85 RLCA
CD86 RLCA
CD87 AND %00001000 Keep it.
CD89 LD E,A Stash it in E.
CD8A LD A,D Fetch the place.
CD8B RLCA Move the x position into bits 4 to 6.
CD8C RLCA
CD8D RLCA
CD8E RLCA
CD8F AND %01110000 Keep it.
CD91 ADD A,E Add the half step.
CD92 ADD A,$48 Add 48.
CD94 LD (IY+$01),A Set the x position of the object.
The y position is worked out in the same way from the y position and the half step along y.
CD97 LD A,($5B19) Fetch the position offset from PositionOffset.
CD9A RLCA Move the half step along y into bit 3.
CD9B RLCA
CD9C AND %00001000 Keep it.
CD9E LD E,A Stash it in E.
CD9F LD A,D Fetch the place.
CDA0 RLCA Move the y position into bits 4 to 6.
CDA1 AND %01110000 Keep it.
CDA3 ADD A,E Add the half step.
CDA4 ADD A,$48 Add 48.
CDA6 LD (IY+$02),A Set the y position of the object.
The z position is the height times 0C, plus the offset up the z axis, plus the floor.
CDA9 LD A,D Fetch the place.
CDAA RLCA Move the height into the low two bits.
CDAB RLCA
CDAC AND %00000011 Keep it.
CDAE ADD A,A Multiply it by four.
CDAF ADD A,A
CDB0 LD E,A Stash it in E.
CDB1 ADD A,A Multiply it by eight.
CDB2 ADD A,E Add the four times to make twelve times.
CDB3 LD E,A Stash it in E.
CDB4 LD A,($5B19) Fetch the position offset from PositionOffset.
CDB7 ADD A,E Add the twelve times.
CDB8 AND %11111100 Clear the two bits of the half steps.
CDBA LD E,A Stash it in E.
CDBB LD A,($5B0E) Fetch the floor of the room from FloorHeight.
CDBE ADD A,E Add it.
CDBF LD (IY+$03),A Set the z position of the object.
Clear the rest of the object.
CDC2 PUSH BC Stash the count on the stack.
CDC3 LD BC,$0009 Set the length of the part of the object that has been made to 09.
CDC6 ADD IY,BC Point IY at the rest of the object.
CDC8 LD B,$17 Set the number of bytes to clear to 17.
MakeRoomObjects_ForegroundClear CDCA LD (IY+$00),$00 Clear a byte.
CDCE INC IY Move on.
CDD0 DJNZ MakeRoomObjects_ForegroundClear Jump to MakeRoomObjects_ForegroundClear until the object is clear.
Move on to the next object of the type, or the next place, or the next group.
CDD2 POP BC Restore the count from the stack.
CDD3 LD A,(HL) Jump to MakeRoomObjects_ForegroundSprite if the type has not ended.
CDD4 AND A
CDD5 JR NZ,MakeRoomObjects_ForegroundSprite
CDD7 POP DE Restore the address of the type and the address of the next byte from the stack.
CDD8 POP HL
CDD9 DEC B Jump to MakeRoomObjects_Finish if the entry has ended.
CDDA JR Z,MakeRoomObjects_Finish
CDDC DEC C Jump to MakeRoomObjects_ForegroundObject if the type has been used the number of times.
CDDD JP Z,MakeRoomObjects_ForegroundObject
CDE0 LD A,(HL) Fetch the next place, and move on.
CDE1 INC HL
CDE2 PUSH HL Stash the address of the next byte on the stack.
CDE3 EX DE,HL Point HL at the list of objects of the type.
CDE4 LD D,A Put the place in D.
CDE5 JP MakeRoomObjects_ForegroundPlace Jump to MakeRoomObjects_ForegroundPlace.
Finish, and clear any objects that were not made.
MakeRoomObjects_Finish CDE8 PUSH IY Point DE at the next object to make (using the stack).
CDEA POP DE
CDEB POP IY Restore IY from the stack.
CDED JP ClearRemainingObjects Jump to ClearRemainingObjects to clear the rest of the objects table.
Type 1F switches to the second table of object types at SecondObjectTypes.
MakeRoomObjects_SwitchTable CDF0 LD HL,($5B20) Fetch the address of the object types from ObjectTypeTableAddress.
CDF3 LD A,$40 Set the offset to 40.
CDF5 CALL AddAToHL Add it to switch to SecondObjectTypes.
CDF8 LD ($5B20),HL Store it at ObjectTypeTableAddress.
Go on to the next group.
MakeRoomObjects_Next CDFB DEC B Take one off the length that is left.
CDFC POP HL Restore the address of the next byte from the stack.
CDFD JP MakeRoomObjects_ForegroundObject Jump to MakeRoomObjects_ForegroundObject.
Type 00 sets the position offset for the groups that follow.
MakeRoomObjects_SetOffset CE00 LD A,D Fetch the place, which is the offset.
CE01 LD ($5B19),A Store it at PositionOffset.
CE04 JR MakeRoomObjects_Next Jump to MakeRoomObjects_Next.
View the equivalent code in;
Prev: CCD0 Up: Map Next: CE06