![]() |
Routines |
| Prev: 51482 | Up: Map | Next: 51836 |
|
Used by the routine at BuildRoom.
Makes the scenery objects of a room, from the data of the room, which starts at Room_00 and has a record for each of the rooms. A record is the room number, then a length byte (which counts itself and the bytes after it), then a byte holding the ink colour of the room in bits 0-2 and the size of the room in bits 3-7, then the features of the room and then the groups of templates. The size is the index of one of the three 3-byte entries at RoomSizeTable, which hold the distance from the centre of the room to the walls on the x axis and the y axis, and the height of the floor.
The features are pairs of bytes: the number of a feature and a parameter, ended by 255 (or by the end of the data of the room, as 43 of the rooms have no 255). The number is the index into the table of addresses at FeatureTable. A feature is a list of the eight bytes of one or more objects (the type, x, y, z, the sizes along each axis and the flags) that ends with a zero in place of the type of another object. These are the doors and their frames, and the objects that are fixed to the walls. The parameter is stored in the room field of each of the objects in the feature, which makes it the number of the room that a door leads to.
Each group of templates that follows is a byte holding the number of a template in bits 3-7 and, in bits 0-2, one less than the number of cells that follow, and then a byte for each of the cells. A cell holds the x position in bits 0-2 and the y position in bits 3-5 (in steps of 16 from 72), and the height in bits 6-7 (in steps of 12 above the floor). A template is a list of the five bytes of one or more objects (the type, the sizes along each axis and the flags) that ends with a zero in place of the type of another object, and an object is made from it for each of the cells. The template numbers are the indexes into the table of addresses that starts at TemplateTable, which a group with the number 31 moves on by 32 templates, though no room has one. The last group of rooms 13 and 108 is cut short by the end of their data.
The objects are made from the last of the object slots, which is at ObjectsTable_Last, and downwards. The first feature of a room is always a door, with its frame in the last slot and the door in the one before, so that the doors are found by FindDoor in the slots at the top. The player and the creatures have the slots at the start.
|
||||||||
|
Clear the objects and point at the room data.
|
||||||||
| BuildRoomScenery | 51500 | CALL ClearObjects | Call ClearObjects to clear all of the objects except for the player. | |||||
| 51503 | LD HL,27877 | Start with the first of the tables of templates, which is TemplateTable. | ||||||
| 51506 | LD (42810),HL | |||||||
| 51509 | XOR A | Set the offset of the cells to zero. | ||||||
| 51510 | LD (42812),A | |||||||
| 51513 | LD DE,44559 | Take the last of the object slots. | ||||||
| 51516 | LD BC,26989 | Take the end of the room data, which is FeatureTable. | ||||||
| 51519 | LD HL,24080 | Start at the first room record, which is Room_00. | ||||||
|
Find the record for this room.
|
||||||||
| BuildRoomScenery_FindRoomRecord | 51522 | LD A,(HL) | Fetch the number of the room, and move on to the length. | |||||
| 51523 | INC HL | |||||||
| 51524 | CP (IX+8) | Jump to BuildRoomScenery_ReadRoomHeader if it is the room that the player is in. | ||||||
| 51527 | JR Z,BuildRoomScenery_ReadRoomHeader | |||||||
| 51529 | LD A,(HL) | Fetch the length of the record. | ||||||
| 51530 | CALL AddAToHL | Call AddAToHL to move on to the next record. | ||||||
| 51533 | AND A | Compare HL with the end of the room data, which sets the carry flag if it is before it. | ||||||
| 51534 | SBC HL,BC | |||||||
| 51536 | ADD HL,BC | |||||||
| 51537 | JR BuildRoomScenery_FindRoomRecord | Jump to BuildRoomScenery_FindRoomRecord if there are more records. | ||||||
|
Read the colour and size of the room.
|
||||||||
| BuildRoomScenery_ReadRoomHeader | 51539 | LD B,(HL) | Fetch the length of the record into B, and move on to the colour and size of the room. | |||||
| 51540 | INC HL | |||||||
| 51541 | LD A,(HL) | Fetch the colour and size of the room. | ||||||
| 51542 | AND %00000111 | Keep the ink colour. | ||||||
| 51544 | OR %01000000 | Set the bright bit. | ||||||
| 51546 | LD (42808),A | Store it as the colour of the room. | ||||||
| 51549 | PUSH DE | Save the address of the next free object slot. | ||||||
| 51550 | EX DE,HL | Put the address of the room data in DE. | ||||||
| 51551 | LD A,(DE) | Fetch the colour and size again, and move on to the first feature. | ||||||
| 51552 | INC DE | |||||||
| 51553 | RRCA | Move the size of the room to bits 0-4. | ||||||
| 51554 | RRCA | |||||||
| 51555 | RRCA | |||||||
| 51556 | AND %00011111 | Keep it. | ||||||
| 51558 | LD C,A | Put the size in C. | ||||||
| 51559 | ADD A,A | Multiply the size by three. | ||||||
| 51560 | ADD A,C | |||||||
| 51561 | LD HL,24071 | Take the sizes of the rooms, which is RoomSizeTable. | ||||||
| 51564 | CALL AddAToHL | Call AddAToHL to find the entry for the size. | ||||||
| 51567 | LD A,(HL) | Fetch the distance to the walls along x, move on and store it. | ||||||
| 51568 | INC HL | |||||||
| 51569 | LD (42781),A | |||||||
| 51572 | LD A,(HL) | Fetch the distance to the walls along y, move on and store it. | ||||||
| 51573 | INC HL | |||||||
| 51574 | LD (42782),A | |||||||
| 51577 | LD A,(HL) | Fetch the height of the floor and store it. | ||||||
| 51578 | LD (42783),A | |||||||
| 51581 | DEC B | Count the length and the colour and size as read. | ||||||
| 51582 | DEC B | |||||||
| 51583 | EX DE,HL | Put the address of the room data back in HL. | ||||||
| 51584 | POP DE | Get the address of the next free object slot back. | ||||||
|
Make the objects of each feature.
|
||||||||
| BuildRoomScenery_MakeFeature | 51585 | LD A,(HL) | Fetch the number of the feature, and move on to its parameter. | |||||
| 51586 | INC HL | |||||||
| 51587 | CP 255 | Jump to BuildRoomScenery_MakeTemplates if it is the end of the features. | ||||||
| 51589 | JR Z,BuildRoomScenery_MakeTemplates | |||||||
| 51591 | PUSH BC | Save the number of bytes left to read and the address of the parameter. | ||||||
| 51592 | PUSH HL | |||||||
| 51593 | LD L,A | Put the number of the feature in HL. | ||||||
| 51594 | LD H,0 | |||||||
| 51596 | ADD HL,HL | Double it. | ||||||
| 51597 | LD BC,26989 | Take the table of addresses of the features, which is FeatureTable. | ||||||
| 51600 | ADD HL,BC | Add the offset to find the entry for the feature. | ||||||
| 51601 | LD A,(HL) | Fetch the low byte of the address of the feature, and move on. | ||||||
| 51602 | INC HL | |||||||
| 51603 | LD H,(HL) | Fetch the high byte, and make the address of the feature in HL. | ||||||
| 51604 | LD L,A | |||||||
| BuildRoomScenery_MakeFeatureObject | 51605 | LD BC,8 | Set the number of bytes that make an object in a feature, which is eight. | |||||
| 51608 | LDIR | Copy the type, position, sizes and flags into the object slot. | ||||||
| 51610 | EX (SP),HL | Fetch the parameter, leaving the address in the feature on the stack. | ||||||
| 51611 | LD A,(HL) | |||||||
| 51612 | EX (SP),HL | |||||||
| 51613 | LD (DE),A | Store it in the room field of the object, and move on. | ||||||
| 51614 | INC DE | |||||||
| 51615 | LD B,23 | Set the number of bytes to clear, which is the rest of the object. | ||||||
| 51617 | CALL ClearBytes | Call ClearBytes to clear them. | ||||||
| 51620 | PUSH HL | Save the address in the feature. | ||||||
| 51621 | LD HL,65472 | Subtract 32 from DE, by adding 65472... | ||||||
| 51624 | ADD HL,DE | |||||||
| 51625 | EX DE,HL | ...and put it back in DE. | ||||||
| 51626 | POP HL | Get the address in the feature back. | ||||||
| 51627 | LD A,(HL) | Jump to BuildRoomScenery_MakeFeatureObject to make another object if the next type in the feature is not zero. | ||||||
| 51628 | AND A | |||||||
| 51629 | JR NZ,BuildRoomScenery_MakeFeatureObject | |||||||
| 51631 | POP HL | Get the address of the parameter and the number of bytes left to read. | ||||||
| 51632 | POP BC | |||||||
| 51633 | INC HL | Move on to the next feature. | ||||||
| 51634 | DEC B | Count the parameter as read. | ||||||
| 51635 | DJNZ BuildRoomScenery_MakeFeature | Jump to BuildRoomScenery_MakeFeature for the next feature, counting the number as read, while any data is left. | ||||||
| 51637 | RET | Return. | ||||||
|
Make the objects from the templates.
|
||||||||
| BuildRoomScenery_MakeTemplates | 51638 | DEC B | Count the end of the features as read. | |||||
| 51639 | PUSH IY | Save IY. | ||||||
| 51641 | PUSH DE | Move on to the next free object slot (using the stack). | ||||||
| 51642 | POP IY | |||||||
| BuildRoomScenery_MakeTemplateGroup | 51644 | LD A,(HL) | Fetch the byte that holds the template and the number of cells. | |||||
| 51645 | AND %00000111 | Keep the number of cells less one. | ||||||
| 51647 | INC A | Add one. | ||||||
| 51648 | LD C,A | Put the number of cells in C. | ||||||
| 51649 | LD A,(HL) | Fetch the byte again, and move on to the first cell. | ||||||
| 51650 | INC HL | |||||||
| 51651 | DEC B | Count it as read. | ||||||
| 51652 | LD D,(HL) | Fetch the first cell into D, and move on. | ||||||
| 51653 | INC HL | |||||||
| 51654 | PUSH HL | Save the address of the next byte. | ||||||
| 51655 | RRCA | Move the template number to bits 1-5, which doubles it. | ||||||
| 51656 | RRCA | |||||||
| 51657 | AND %00111110 | Keep it. | ||||||
| 51659 | CP 62 | Jump to BuildRoomScenery_SwitchTemplateTable if it is the template number that moves on the table. | ||||||
| 51661 | JP Z,BuildRoomScenery_SwitchTemplateTable | |||||||
| 51664 | LD HL,(42810) | Fetch the address of the table of templates. | ||||||
| 51667 | CALL AddAToHL | Call AddAToHL to find the entry for the template. | ||||||
| 51670 | LD A,(HL) | Fetch the low byte of the address of the template, and move on. | ||||||
| 51671 | INC HL | |||||||
| 51672 | LD H,(HL) | Fetch the high byte, and make the address of the template in HL. | ||||||
| 51673 | LD L,A | |||||||
|
Copy a template object into a cell.
|
||||||||
| BuildRoomScenery_MakeTemplateCell | 51674 | PUSH HL | Save the address of the template. | |||||
| BuildRoomScenery_MakeTemplateObject | 51675 | LD A,(HL) | Copy the type from the template to the object. | |||||
| 51676 | INC HL | |||||||
| 51677 | LD (IY+0),A | |||||||
| 51680 | LD A,(HL) | Copy the half size along x. | ||||||
| 51681 | INC HL | |||||||
| 51682 | LD (IY+4),A | |||||||
| 51685 | LD A,(HL) | Copy the half size along y. | ||||||
| 51686 | INC HL | |||||||
| 51687 | LD (IY+5),A | |||||||
| 51690 | LD A,(HL) | Copy the half size along z. | ||||||
| 51691 | INC HL | |||||||
| 51692 | LD (IY+6),A | |||||||
| 51695 | LD A,(HL) | Copy the flags. | ||||||
| 51696 | INC HL | |||||||
| 51697 | LD (IY+7),A | |||||||
| 51700 | LD A,(IX+8) | Copy the room that the player is in to the room field of the object. | ||||||
| 51703 | LD (IY+8),A | |||||||
| 51706 | LD A,(42812) | Fetch the cell offset. | ||||||
| 51709 | RLCA | Move bit 0 of the offset to bit 3. | ||||||
| 51710 | RLCA | |||||||
| 51711 | RLCA | |||||||
| 51712 | AND %00001000 | Keep it. | ||||||
| 51714 | LD E,A | Put it in E. | ||||||
| 51715 | LD A,D | Fetch the cell. | ||||||
| 51716 | RLCA | Move the x position of the cell to bits 4-6. | ||||||
| 51717 | RLCA | |||||||
| 51718 | RLCA | |||||||
| 51719 | RLCA | |||||||
| 51720 | AND %01110000 | Keep it. | ||||||
| 51722 | ADD A,E | Add bit 3 of the offset. | ||||||
| 51723 | ADD A,72 | Add the start of the cells. | ||||||
| 51725 | LD (IY+1),A | Store it as the x position of the object. | ||||||
| 51728 | LD A,(42812) | Fetch the cell offset. | ||||||
| 51731 | RLCA | Move bit 1 of the offset to bit 3. | ||||||
| 51732 | RLCA | |||||||
| 51733 | AND %00001000 | Keep it. | ||||||
| 51735 | LD E,A | Put it in E. | ||||||
| 51736 | LD A,D | Fetch the cell. | ||||||
| 51737 | RLCA | Move the y position of the cell to bits 4-6. | ||||||
| 51738 | AND %01110000 | Keep it. | ||||||
| 51740 | ADD A,E | Add bit 3 of the offset. | ||||||
| 51741 | ADD A,72 | Add the start of the cells. | ||||||
| 51743 | LD (IY+2),A | Store it as the y position of the object. | ||||||
| 51746 | LD A,D | Fetch the cell. | ||||||
| 51747 | RLCA | Move the height of the cell to bits 0-1. | ||||||
| 51748 | RLCA | |||||||
| 51749 | AND %00000011 | Keep it. | ||||||
| 51751 | ADD A,A | Multiply it by four. | ||||||
| 51752 | ADD A,A | |||||||
| 51753 | LD E,A | Put it in E. | ||||||
| 51754 | ADD A,A | Multiply it by eight. | ||||||
| 51755 | ADD A,E | Add the four times to make it twelve times the height. | ||||||
| 51756 | LD E,A | Put it in E. | ||||||
| 51757 | LD A,(42812) | Fetch the cell offset. | ||||||
| 51760 | ADD A,E | Add the height. | ||||||
| 51761 | AND %11111100 | Keep the multiple of four. | ||||||
| 51763 | LD E,A | Put it in E. | ||||||
| 51764 | LD A,(42783) | Fetch the height of the floor. | ||||||
| 51767 | ADD A,E | Add the height of the cell. | ||||||
| 51768 | LD (IY+3),A | Store it as the z position of the object. | ||||||
| 51771 | PUSH BC | Save the number of bytes left to read and the number of cells. | ||||||
| 51772 | LD BC,9 | Set the offset from the type to the byte after the room field, which is 9. | ||||||
| 51775 | ADD IY,BC | Add it to IY. | ||||||
| 51777 | LD B,23 | Set the number of bytes to clear, which is the rest of the object. | ||||||
| BuildRoomScenery_ClearTemplateObject | 51779 | LD (IY+0),0 | Clear a byte of the object. | |||||
| 51783 | INC IY | Move on to the next byte. | ||||||
| 51785 | DJNZ BuildRoomScenery_ClearTemplateObject | Jump to BuildRoomScenery_ClearTemplateObject until the rest of the object is clear. | ||||||
| 51787 | LD BC,65472 | Subtract 64 from IY, which moves it to the slot below the object. | ||||||
| 51790 | ADD IY,BC | |||||||
| 51792 | POP BC | Get the number of bytes left to read and the number of cells back. | ||||||
| 51793 | LD A,(HL) | Jump to BuildRoomScenery_MakeTemplateObject to make another object if the next type in the template is not zero. | ||||||
| 51794 | AND A | |||||||
| 51795 | JR NZ,BuildRoomScenery_MakeTemplateObject | |||||||
| 51797 | POP DE | Get the address of the template and the address of the next byte of the room data. | ||||||
| 51798 | POP HL | |||||||
| 51799 | DEC B | Count the cell as read, and jump to BuildRoomScenery_FinishRoomScenery if there is no more room data. | ||||||
| 51800 | JR Z,BuildRoomScenery_FinishRoomScenery | |||||||
| 51802 | DEC C | Count the object as made, and jump to BuildRoomScenery_MakeTemplateGroup for the next group if there is no cell left. | ||||||
| 51803 | JP Z,BuildRoomScenery_MakeTemplateGroup | |||||||
| 51806 | LD A,(HL) | Fetch the next cell, and move on. | ||||||
| 51807 | INC HL | |||||||
| 51808 | PUSH HL | Save the address of the next byte. | ||||||
| 51809 | EX DE,HL | Put the address of the template in HL. | ||||||
| 51810 | LD D,A | Put the cell in D. | ||||||
| 51811 | JP BuildRoomScenery_MakeTemplateCell | Jump to BuildRoomScenery_MakeTemplateCell to make the object for it. | ||||||
|
Finish, or switch the template table.
|
||||||||
| BuildRoomScenery_FinishRoomScenery | 51814 | PUSH IY | Put the address of the next free object slot in DE (using the stack). | |||||
| 51816 | POP DE | |||||||
| 51817 | POP IY | Get the original IY back. | ||||||
| 51819 | RET | Return. | ||||||
| BuildRoomScenery_SwitchTemplateTable | 51820 | LD HL,(42810) | Fetch the address of the table of templates. | |||||
| 51823 | LD A,64 | Set the number of bytes to move on, which is 32 templates. | ||||||
| 51825 | CALL AddAToHL | Call AddAToHL to move on. | ||||||
| 51828 | LD (42810),HL | Store it as the table of templates. | ||||||
|
This entry point is used by the routine at SetCellOffset.
|
||||||||
| BuildRoomScenery_NextTemplateGroup | 51831 | DEC B | Count the unused cell as read. | |||||
| 51832 | POP HL | Get the address of the next group back. | ||||||
| 51833 | JP BuildRoomScenery_MakeTemplateGroup | Jump to BuildRoomScenery_MakeTemplateGroup to make the objects for it. | ||||||
|
View the equivalent code in;
|
||||||||
| Prev: 51482 | Up: Map | Next: 51836 |