Prev: D3E2 Up: Map Next: D4F2
D3F0: Make Room Objects
Used by the routine at RetrieveRoom.
Makes the objects of a room from its entry in the table of rooms. The colour of the room is the low three bits of the byte after the length, with bright added, and the size of the room is the high five bits. The size gives the size of the room in X, Y and Z, from the table at RoomSizeTable. Each type of background object is the number of an entry in the table at BackgroundTypeTable, which holds the address of a list of objects that already have their coordinates. Each of these is copied into the objects table, along with the number of the room. The background objects end at a FF, or at the end of the entry if there are no foreground objects. Each group of foreground objects starts with a byte that has the number of a block in bits 3 to 7 and one less than the number of times it is used in bits 0 to 2, followed by that many positions. A block is a list of objects from the table at BlockTypeTable, each with a graphic, a size, flags and an offset, but no coordinates. A position has the X coordinate in bits 0 to 2, the Y coordinate in bits 3 to 5 and the Z coordinate in bits 6 and 7.
Input
DE Address of the first object to make
HL Address of the entry of the room (the byte after the number of the room)
IX Address of the player
Set the colour of the room, the size and the floor.
MakeRoomObjects D3F0 LD B,(HL) Fetch the length of the entry.
D3F1 INC HL Point HL at the colour and size.
D3F2 LD A,(HL) Fetch the colour and size.
D3F3 AND %00000111 Keep the colour.
D3F5 OR %01000000 Make it bright.
D3F7 LD ($5BAD),A Store it as the colour of the room at RoomAttribute.
D3FA PUSH DE Stash the address of the object to make on the stack.
D3FB EX DE,HL Point DE at the colour and size.
D3FC LD A,(DE) Fetch the colour and size.
D3FD INC DE Point DE at the types of background object.
D3FE RRCA Move the size into the low five bits.
D3FF RRCA
D400 RRCA
D401 AND %00011111 Keep it.
D403 LD C,A Stash it in C.
D404 ADD A,A Multiply it by three.
D405 ADD A,C
D406 LD HL,$6248 Point HL at RoomSizeTable.
D409 CALL AddAToHL Add the offset to find the size.
D40C LD A,(HL) Fetch the size of the room in X, and move on.
D40D INC HL
D40E LD ($5BAB),A Store it at RoomSizeX.
D411 LD A,(HL) Fetch the size of the room in Y, and move on.
D412 INC HL
D413 LD ($5BAC),A Store it at RoomSizeY.
D416 LD A,(HL) Fetch the size of the room in Z, which is the floor of the room.
D417 LD ($5BAE),A Store it at FloorHeight.
D41A DEC B Take two off the length that is left.
D41B DEC B
D41C EX DE,HL Point HL at the types of background object.
D41D POP DE Restore the address of the object to make from the stack.
Copy each type of background object from BackgroundTypeTable.
MakeRoomObjects_Background D41E LD A,(HL) Fetch the type of background object, and move on.
D41F INC HL
D420 CP $FF Jump to MakeRoomObjects_Foreground if it is the end of the types.
D422 JR Z,MakeRoomObjects_Foreground
D424 PUSH BC Stash the length that is left and the address of the next type on the stack.
D425 PUSH HL
Look up the list of objects of this type.
D426 LD L,A Make the type into an offset.
D427 LD H,$00
D429 ADD HL,HL Double it.
D42A LD BC,$6CE2 Point BC at BackgroundTypeTable.
D42D ADD HL,BC Add the two.
D42E LD A,(HL) Fetch the address of the list of objects of the background.
D42F INC HL
D430 LD H,(HL)
D431 LD L,A
Copy one background object into the objects table.
MakeRoomObjects_Background_Copy D432 LD BC,$0008 Set the number of bytes to copy to 08.
D435 LDIR Copy the graphic number, the coordinates, the size and the flags of the object.
D437 LD A,(IX+$08) Fetch the room number of the player.
D43A LD (DE),A Set the room number of the object, and move on.
D43B INC DE
D43C LD B,$17 Set the number of bytes to 17.
D43E CALL ClearBytes Clear the rest of the object.
D441 LD A,(HL) Jump to MakeRoomObjects_Background_Copy if the list has not ended.
D442 AND A
D443 JR NZ,MakeRoomObjects_Background_Copy
D445 POP HL Restore the address of the next type and the length that is left from the stack.
D446 POP BC
D447 DJNZ MakeRoomObjects_Background Jump to MakeRoomObjects_Background until all of the types have been used.
D449 JP ClearRemainingObjects Jump to ClearRemainingObjects to clear the rest of the objects table.
The foreground objects. IY points at the object that is being made.
MakeRoomObjects_Foreground D44C DEC B Take one off the length that is left, for the end of the types.
D44D PUSH IY Stash IY on the stack.
D44F PUSH DE Point IY at the object to make (using the stack).
D450 POP IY
Decode the block type and the number of places.
MakeRoomObjects_Block D452 LD A,(HL) Fetch the block and the count.
D453 AND %00000111 Keep the count.
D455 INC A Add one to get the number of times.
D456 LD C,A Stash it in C.
D457 LD A,(HL) Fetch the block and the count again, and move on.
D458 INC HL
D459 DEC B Take one off the length that is left.
D45A LD D,(HL) Fetch the position of the first block, and move on.
D45B INC HL
D45C PUSH HL Stash the address of the next byte on the stack.
D45D RRCA Move the block into bits 1 to 5.
D45E RRCA
D45F AND %00111110 Keep it, to make it twice the number of the block.
D461 LD HL,$6BD1 Point HL at BlockTypeTable.
D464 CALL AddAToHL Add the offset to find the block.
D467 LD A,(HL) Fetch the address of the list of objects of the block.
D468 INC HL
D469 LD H,(HL)
D46A LD L,A
MakeRoomObjects_Block_Object D46B PUSH HL Stash the address of the list of objects on the stack.
Copy the graphic, the size and the flags from the block.
MakeRoomObjects_Object D46C LD A,(HL) Fetch the graphic number, and move on.
D46D INC HL
D46E LD (IY+$00),A Set the graphic number of the object.
D471 LD A,(HL) Fetch the width, and move on.
D472 INC HL
D473 LD (IY+$04),A Set the width of the object.
D476 LD A,(HL) Fetch the depth, and move on.
D477 INC HL
D478 LD (IY+$05),A Set the depth of the object.
D47B LD A,(HL) Fetch the height, and move on.
D47C INC HL
D47D LD (IY+$06),A Set the height of the object.
D480 LD A,(HL) Fetch the flags, and move on.
D481 INC HL
D482 LD (IY+$07),A Set the flags of the object.
D485 LD A,(IX+$08) Fetch the room number of the player.
D488 LD (IY+$08),A Set the room number of the object.
The byte of offsets has the half step in X in bit 0, the half step in Y in bit 1, and the offset in Z in bits 2 to 7. The X coordinate is the X position times 10, plus eight if the half step is set, plus 48.
D48B LD A,(HL) Fetch the offsets.
D48C RLCA Move the half step in X into bit 3.
D48D RLCA
D48E RLCA
D48F AND %00001000 Keep it.
D491 LD E,A Stash it in E.
D492 LD A,D Fetch the position.
D493 RLCA Move the X position into bits 4 to 6.
D494 RLCA
D495 RLCA
D496 RLCA
D497 AND %01110000 Keep it.
D499 ADD A,E Add the half step.
D49A ADD A,$48 Add 48.
D49C LD (IY+$01),A Set the X coordinate of the object.
The Y coordinate is worked out in the same way from the Y position and the half step in Y.
D49F LD A,(HL) Fetch the offsets.
D4A0 RLCA Move the half step in Y into bit 3.
D4A1 RLCA
D4A2 AND %00001000 Keep it.
D4A4 LD E,A Stash it in E.
D4A5 LD A,D Fetch the position.
D4A6 RLCA Move the Y position into bits 4 to 6.
D4A7 AND %01110000 Keep it.
D4A9 ADD A,E Add the half step.
D4AA ADD A,$48 Add 48.
D4AC LD (IY+$02),A Set the Y coordinate of the object.
The Z coordinate is the Z position times 0C, plus the offset in Z, plus the floor of the room.
D4AF LD A,D Fetch the position.
D4B0 RLCA Move the Z position into the low two bits.
D4B1 RLCA
D4B2 AND %00000011 Keep it.
D4B4 ADD A,A Multiply it by four.
D4B5 ADD A,A
D4B6 LD E,A Stash it in E.
D4B7 ADD A,A Multiply it by eight.
D4B8 ADD A,E Add the four times to make twelve times.
D4B9 ADD A,(HL) Add the offsets, which includes the offset in Z.
D4BA INC HL Move on.
D4BB AND %11111100 Clear the two bits of the half steps.
D4BD LD E,A Stash it in E.
D4BE LD A,($5BAE) Fetch the floor of the room from FloorHeight.
D4C1 ADD A,E Add it.
D4C2 LD (IY+$03),A Set the Z coordinate of the object.
Clear the rest of the object.
D4C5 PUSH BC Stash the count on the stack.
D4C6 LD BC,$0009 Set the length of the part of the object that has been made to 09.
D4C9 ADD IY,BC Point IY at the rest of the object.
D4CB LD B,$17 Set the number of bytes to clear to 17.
MakeRoomObjects_Clear D4CD LD (IY+$00),$00 Clear a byte.
D4D1 INC IY Move on.
D4D3 DJNZ MakeRoomObjects_Clear Jump to MakeRoomObjects_Clear until the object is clear.
Move on to the next object of the block, or the next place, or the next group.
D4D5 POP BC Restore the count from the stack.
D4D6 LD A,(HL) Jump to MakeRoomObjects_Object if the block has not ended.
D4D7 AND A
D4D8 JR NZ,MakeRoomObjects_Object
D4DA POP DE Restore the address of the block and the address of the next byte from the stack.
D4DB POP HL
D4DC DEC B Jump to MakeRoomObjects_Finish if the entry has ended.
D4DD JR Z,MakeRoomObjects_Finish
D4DF DEC C Jump to MakeRoomObjects_Block if the block has been used the number of times.
D4E0 JP Z,MakeRoomObjects_Block
D4E3 LD A,(HL) Fetch the position for the next use of the block, and move on.
D4E4 INC HL
D4E5 PUSH HL Stash the address of the next byte on the stack.
D4E6 EX DE,HL Point HL at the list of objects of the block.
D4E7 LD D,A Put the position in D.
D4E8 JR MakeRoomObjects_Block_Object Jump to MakeRoomObjects_Block_Object.
Finish, and clear any objects that were not made.
MakeRoomObjects_Finish D4EA PUSH IY Point DE at the next object to make (using the stack).
D4EC POP DE
D4ED POP IY Restore IY from the stack.
D4EF JP ClearRemainingObjects Jump to ClearRemainingObjects to clear the rest of the objects table.
View the equivalent code in;
Prev: D3E2 Up: Map Next: D4F2