![]() |
Routines |
| Prev: 52432 | Up: Map | Next: 52742 |
|
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 255, or at the end of the entry if there are no more objects. After the 255 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 0 sets the position offset at PositionOffset, and type 31 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.
|
||||||||||||
|
Set the colour of the room, the size and the floor.
|
||||||||||||
| MakeRoomObjects | 52446 | LD B,(HL) | Fetch the length of the entry. | |||||||||
| 52447 | INC HL | Point HL at the colour and size. | ||||||||||
| 52448 | LD A,(HL) | Fetch the colour and size. | ||||||||||
| 52449 | AND %00000111 | Keep the colour. | ||||||||||
| 52451 | LD (23309),A | Store it as the colour of the room at RoomColour. | ||||||||||
| 52454 | LD (23348),HL | Store the address of the colour and size at ChamberAddress. | ||||||||||
| 52457 | PUSH DE | Stash the address of the object to make on the stack. | ||||||||||
| 52458 | EX DE,HL | Point DE at the colour and size. | ||||||||||
| 52459 | LD A,(DE) | Fetch the colour and size. | ||||||||||
| 52460 | INC DE | Point DE at the types of block. | ||||||||||
| 52461 | RLCA | Move the size into the low two bits. | ||||||||||
| 52462 | RLCA | |||||||||||
| 52463 | AND %00000011 | Keep it. | ||||||||||
| 52465 | LD C,A | Stash it in C. | ||||||||||
| 52466 | ADD A,A | Multiply it by three. | ||||||||||
| 52467 | ADD A,C | |||||||||||
| 52468 | LD HL,25696 | Point HL at RoomSizes. | ||||||||||
| 52471 | CALL AddAToHL | Add the offset to find the size. | ||||||||||
| 52474 | LD A,(HL) | Fetch the size of the room in X, and move on. | ||||||||||
| 52475 | INC HL | |||||||||||
| 52476 | LD (23307),A | Store it at RoomSize_X. | ||||||||||
| 52479 | LD A,(HL) | Fetch the size of the room in Y, and move on. | ||||||||||
| 52480 | INC HL | |||||||||||
| 52481 | LD (23308),A | Store it at RoomSize_Y. | ||||||||||
| 52484 | LD A,(HL) | Fetch the floor of the room. | ||||||||||
| 52485 | LD (23310),A | Store it at FloorHeight. | ||||||||||
| 52488 | DEC B | Take two off the length that is left. | ||||||||||
| 52489 | DEC B | |||||||||||
| 52490 | EX DE,HL | Point HL at the types of block. | ||||||||||
| 52491 | POP DE | Restore the address of the object to make from the stack. | ||||||||||
|
Copy each type of block from BlockTypes.
|
||||||||||||
| MakeRoomObjects_Background | 52492 | LD A,(HL) | Fetch the type of block, and move on. | |||||||||
| 52493 | INC HL | |||||||||||
| 52494 | CP 255 | Jump to MakeRoomObjects_Foreground if it is the end of the types. | ||||||||||
| 52496 | JR Z,MakeRoomObjects_Foreground | |||||||||||
| 52498 | PUSH BC | Stash the length that is left and the address of the next type on the stack. | ||||||||||
| 52499 | PUSH HL | |||||||||||
|
Look up the list of objects of this type.
|
||||||||||||
| 52500 | LD L,A | Make the type into an offset. | ||||||||||
| 52501 | LD H,0 | |||||||||||
| 52503 | ADD HL,HL | Double it. | ||||||||||
| 52504 | LD BC,29977 | Point BC at BlockTypes. | ||||||||||
| 52507 | ADD HL,BC | Add the two. | ||||||||||
| 52508 | LD A,(HL) | Fetch the address of the list of objects of the block. | ||||||||||
| 52509 | INC HL | |||||||||||
| 52510 | LD H,(HL) | |||||||||||
| 52511 | LD L,A | |||||||||||
|
Copy one block object into the objects table.
|
||||||||||||
| MakeRoomObjects_BackgroundCopy | 52512 | LD BC,8 | Set the number of bytes to copy to 8. | |||||||||
| 52515 | LDIR | Copy the graphic number, the coordinates, the size and the flags of the object. | ||||||||||
| 52517 | LD A,(IX+8) | Fetch the room number of the player. | ||||||||||
| 52520 | LD (DE),A | Set the room number of the object, and move on. | ||||||||||
| 52521 | INC DE | |||||||||||
| 52522 | LD B,23 | Set the number of bytes to 23. | ||||||||||
| 52524 | CALL ClearBytes | Clear the rest of the object. | ||||||||||
| 52527 | LD A,(HL) | Jump to MakeRoomObjects_BackgroundCopy if the list has not ended. | ||||||||||
| 52528 | AND A | |||||||||||
| 52529 | JR NZ,MakeRoomObjects_BackgroundCopy | |||||||||||
| 52531 | POP HL | Restore the address of the next type and the length that is left from the stack. | ||||||||||
| 52532 | POP BC | |||||||||||
| 52533 | DJNZ MakeRoomObjects_Background | Jump to MakeRoomObjects_Background until all of the types have been used. | ||||||||||
| 52535 | 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 | 52538 | DEC B | Take one off the length that is left, for the end of the types. | |||||||||
| 52539 | PUSH IY | Stash IY on the stack. | ||||||||||
| 52541 | PUSH DE | Point IY at the object to make (using the stack). | ||||||||||
| 52542 | POP IY | |||||||||||
|
Decode the type and the number of places.
|
||||||||||||
| MakeRoomObjects_ForegroundObject | 52544 | LD A,(HL) | Fetch the type and the number of places. | |||||||||
| 52545 | AND %00000111 | Keep the count. | ||||||||||
| 52547 | INC A | Add one to get the number of times. | ||||||||||
| 52548 | LD C,A | Stash it in C. | ||||||||||
| 52549 | LD A,(HL) | Fetch the type and the number of places again, and move on. | ||||||||||
| 52550 | INC HL | |||||||||||
| 52551 | DEC B | Take one off the length that is left. | ||||||||||
| 52552 | LD D,(HL) | Fetch the first place, and move on. | ||||||||||
| 52553 | INC HL | |||||||||||
| 52554 | PUSH HL | Stash the address of the next byte on the stack. | ||||||||||
| 52555 | RRCA | Move the type into bits 1 to 5. | ||||||||||
| 52556 | RRCA | |||||||||||
| 52557 | AND %00111110 | Keep it, to make it twice the number of the type. | ||||||||||
| 52559 | JP Z,MakeRoomObjects_SetOffset | Jump to MakeRoomObjects_SetOffset if the type is 0. | ||||||||||
| 52562 | CP 62 | Jump to MakeRoomObjects_SwitchTable if the type is 31. | ||||||||||
| 52564 | JP Z,MakeRoomObjects_SwitchTable | |||||||||||
| 52567 | LD HL,(23328) | Fetch the address of the object types from ObjectTypeTableAddress. | ||||||||||
| 52570 | CALL AddAToHL | Add the offset to find the type. | ||||||||||
| 52573 | LD A,(HL) | Fetch the address of the list of objects of the type. | ||||||||||
| 52574 | INC HL | |||||||||||
| 52575 | LD H,(HL) | |||||||||||
| 52576 | LD L,A | |||||||||||
| MakeRoomObjects_ForegroundPlace | 52577 | 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 | 52578 | LD A,(HL) | Fetch the sprite number, and move on. | |||||||||
| 52579 | INC HL | |||||||||||
| 52580 | LD (IY+0),A | Set the sprite number of the object. | ||||||||||
| 52583 | LD A,(HL) | Fetch the width, and move on. | ||||||||||
| 52584 | INC HL | |||||||||||
| 52585 | LD (IY+4),A | Set the width of the object. | ||||||||||
| 52588 | LD A,(HL) | Fetch the depth, and move on. | ||||||||||
| 52589 | INC HL | |||||||||||
| 52590 | LD (IY+5),A | Set the depth of the object. | ||||||||||
| 52593 | LD A,(HL) | Fetch the height, and move on. | ||||||||||
| 52594 | INC HL | |||||||||||
| 52595 | LD (IY+6),A | Set the height of the object. | ||||||||||
| 52598 | LD A,(HL) | Fetch the flags, and move on. | ||||||||||
| 52599 | INC HL | |||||||||||
| 52600 | LD (IY+7),A | Set the flags of the object. | ||||||||||
| 52603 | LD A,(IX+8) | Fetch the room number of the player. | ||||||||||
| 52606 | LD (IY+8),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 16, plus 8 if the half step is set, plus 72.
|
||||||||||||
| 52609 | LD A,(23321) | Fetch the position offset from PositionOffset. | ||||||||||
| 52612 | RLCA | Move the half step along x into bit 3. | ||||||||||
| 52613 | RLCA | |||||||||||
| 52614 | RLCA | |||||||||||
| 52615 | AND %00001000 | Keep it. | ||||||||||
| 52617 | LD E,A | Stash it in E. | ||||||||||
| 52618 | LD A,D | Fetch the place. | ||||||||||
| 52619 | RLCA | Move the x position into bits 4 to 6. | ||||||||||
| 52620 | RLCA | |||||||||||
| 52621 | RLCA | |||||||||||
| 52622 | RLCA | |||||||||||
| 52623 | AND %01110000 | Keep it. | ||||||||||
| 52625 | ADD A,E | Add the half step. | ||||||||||
| 52626 | ADD A,72 | Add 72. | ||||||||||
| 52628 | LD (IY+1),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.
|
||||||||||||
| 52631 | LD A,(23321) | Fetch the position offset from PositionOffset. | ||||||||||
| 52634 | RLCA | Move the half step along y into bit 3. | ||||||||||
| 52635 | RLCA | |||||||||||
| 52636 | AND %00001000 | Keep it. | ||||||||||
| 52638 | LD E,A | Stash it in E. | ||||||||||
| 52639 | LD A,D | Fetch the place. | ||||||||||
| 52640 | RLCA | Move the y position into bits 4 to 6. | ||||||||||
| 52641 | AND %01110000 | Keep it. | ||||||||||
| 52643 | ADD A,E | Add the half step. | ||||||||||
| 52644 | ADD A,72 | Add 72. | ||||||||||
| 52646 | LD (IY+2),A | Set the y position of the object. | ||||||||||
|
The z position is the height times 12, plus the offset up the z axis, plus the floor.
|
||||||||||||
| 52649 | LD A,D | Fetch the place. | ||||||||||
| 52650 | RLCA | Move the height into the low two bits. | ||||||||||
| 52651 | RLCA | |||||||||||
| 52652 | AND %00000011 | Keep it. | ||||||||||
| 52654 | ADD A,A | Multiply it by four. | ||||||||||
| 52655 | ADD A,A | |||||||||||
| 52656 | LD E,A | Stash it in E. | ||||||||||
| 52657 | ADD A,A | Multiply it by eight. | ||||||||||
| 52658 | ADD A,E | Add the four times to make twelve times. | ||||||||||
| 52659 | LD E,A | Stash it in E. | ||||||||||
| 52660 | LD A,(23321) | Fetch the position offset from PositionOffset. | ||||||||||
| 52663 | ADD A,E | Add the twelve times. | ||||||||||
| 52664 | AND %11111100 | Clear the two bits of the half steps. | ||||||||||
| 52666 | LD E,A | Stash it in E. | ||||||||||
| 52667 | LD A,(23310) | Fetch the floor of the room from FloorHeight. | ||||||||||
| 52670 | ADD A,E | Add it. | ||||||||||
| 52671 | LD (IY+3),A | Set the z position of the object. | ||||||||||
|
Clear the rest of the object.
|
||||||||||||
| 52674 | PUSH BC | Stash the count on the stack. | ||||||||||
| 52675 | LD BC,9 | Set the length of the part of the object that has been made to 9. | ||||||||||
| 52678 | ADD IY,BC | Point IY at the rest of the object. | ||||||||||
| 52680 | LD B,23 | Set the number of bytes to clear to 23. | ||||||||||
| MakeRoomObjects_ForegroundClear | 52682 | LD (IY+0),0 | Clear a byte. | |||||||||
| 52686 | INC IY | Move on. | ||||||||||
| 52688 | 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.
|
||||||||||||
| 52690 | POP BC | Restore the count from the stack. | ||||||||||
| 52691 | LD A,(HL) | Jump to MakeRoomObjects_ForegroundSprite if the type has not ended. | ||||||||||
| 52692 | AND A | |||||||||||
| 52693 | JR NZ,MakeRoomObjects_ForegroundSprite | |||||||||||
| 52695 | POP DE | Restore the address of the type and the address of the next byte from the stack. | ||||||||||
| 52696 | POP HL | |||||||||||
| 52697 | DEC B | Jump to MakeRoomObjects_Finish if the entry has ended. | ||||||||||
| 52698 | JR Z,MakeRoomObjects_Finish | |||||||||||
| 52700 | DEC C | Jump to MakeRoomObjects_ForegroundObject if the type has been used the number of times. | ||||||||||
| 52701 | JP Z,MakeRoomObjects_ForegroundObject | |||||||||||
| 52704 | LD A,(HL) | Fetch the next place, and move on. | ||||||||||
| 52705 | INC HL | |||||||||||
| 52706 | PUSH HL | Stash the address of the next byte on the stack. | ||||||||||
| 52707 | EX DE,HL | Point HL at the list of objects of the type. | ||||||||||
| 52708 | LD D,A | Put the place in D. | ||||||||||
| 52709 | JP MakeRoomObjects_ForegroundPlace | Jump to MakeRoomObjects_ForegroundPlace. | ||||||||||
|
Finish, and clear any objects that were not made.
|
||||||||||||
| MakeRoomObjects_Finish | 52712 | PUSH IY | Point DE at the next object to make (using the stack). | |||||||||
| 52714 | POP DE | |||||||||||
| 52715 | POP IY | Restore IY from the stack. | ||||||||||
| 52717 | JP ClearRemainingObjects | Jump to ClearRemainingObjects to clear the rest of the objects table. | ||||||||||
|
Type 31 switches to the second table of object types at SecondObjectTypes.
|
||||||||||||
| MakeRoomObjects_SwitchTable | 52720 | LD HL,(23328) | Fetch the address of the object types from ObjectTypeTableAddress. | |||||||||
| 52723 | LD A,64 | Set the offset to 64. | ||||||||||
| 52725 | CALL AddAToHL | Add it to switch to SecondObjectTypes. | ||||||||||
| 52728 | LD (23328),HL | Store it at ObjectTypeTableAddress. | ||||||||||
|
Go on to the next group.
|
||||||||||||
| MakeRoomObjects_Next | 52731 | DEC B | Take one off the length that is left. | |||||||||
| 52732 | POP HL | Restore the address of the next byte from the stack. | ||||||||||
| 52733 | JP MakeRoomObjects_ForegroundObject | Jump to MakeRoomObjects_ForegroundObject. | ||||||||||
|
Type 0 sets the position offset for the groups that follow.
|
||||||||||||
| MakeRoomObjects_SetOffset | 52736 | LD A,D | Fetch the place, which is the offset. | |||||||||
| 52737 | LD (23321),A | Store it at PositionOffset. | ||||||||||
| 52740 | JR MakeRoomObjects_Next | Jump to MakeRoomObjects_Next. | ||||||||||
|
View the equivalent code in;
|
||||||||||||
| Prev: 52432 | Up: Map | Next: 52742 |