![]() |
Routines |
| Prev: 47636 | Up: Map | Next: 47710 |
|
Used by the routines at DrawLevelObjects and TestGroupObjects.
Finds the group of objects at a position of the level, using the level map at the address in LevelHeaderAddress and the table of groups at GroupTable.
|
||||||||||||||||
|
Check that the position is inside the map, and find the cell of the map.
|
||||||||||||||||
| FindGroup | 47638 | LD IY,(23806) | Fetch the address of the header of the level into IY. | |||||||||||||
| 47642 | LD A,L | Copy the horizontal position into A. | ||||||||||||||
| 47643 | SUB 32 | Take away the border of 32 to make it a column of the map. | ||||||||||||||
| 47645 | RET C | Return if the position is left of the map. | ||||||||||||||
| 47646 | LD C,A | Keep the column in C. | ||||||||||||||
| 47647 | CP (IY+5) | Compare the column with the width of the map. | ||||||||||||||
| 47650 | JR NC,SetCarryAndReturn | Return with no group if the position is right of the map. | ||||||||||||||
| 47652 | LD A,H | Copy the vertical position into H. | ||||||||||||||
| 47653 | SUB 32 | Take away the border of 32 to make it a row of the map. | ||||||||||||||
| 47655 | RET C | Return if the position is above the map. | ||||||||||||||
| 47656 | LD B,A | Keep the row in B. | ||||||||||||||
| 47657 | JR Z,FindGroup_Row | Jump to FindGroup_Row if it is the first row. | ||||||||||||||
| 47659 | CP (IY+6) | Compare the row with the height of the map. | ||||||||||||||
| 47662 | JR NC,SetCarryAndReturn | Return with no group if the position is below the map. | ||||||||||||||
|
Find the number of the cell by adding the width of the map once for each row, and then add that number of cells to the start of the map.
|
||||||||||||||||
| 47664 | LD A,C | Start with the column. | ||||||||||||||
| 47665 | LD D,(IY+5) | Fetch the width of the map. | ||||||||||||||
| FindGroup_Loop | 47668 | ADD A,D | Add the width of the map. | |||||||||||||
| 47669 | DJNZ FindGroup_Loop | Decrease the row counter and loop back to FindGroup_Loop until all the rows have been added. | ||||||||||||||
| 47671 | LD C,A | Keep the number of the cell in C. | ||||||||||||||
| FindGroup_Row | 47672 | SLA C | Double it, as there are two bytes for each cell. | |||||||||||||
| 47674 | ADD IY,BC | Add it to the address of the header, to reach the cell. | ||||||||||||||
|
Read the cell. Its first byte is returned as an offset, and its second is the number of the group.
|
||||||||||||||||
| 47676 | LD E,B | Clear E. | ||||||||||||||
| 47677 | LD A,(IY+7) | Fetch the first byte of the cell, which starts 7 bytes after the header. | ||||||||||||||
| 47680 | LD D,A | Keep it in D. | ||||||||||||||
| 47681 | ADD A,2 | Add 2 which sets the carry flag if the byte is 254 or 255. | ||||||||||||||
| 47683 | RET C | Return with no group if the cell has none. | ||||||||||||||
| 47684 | LD C,(IY+8) | Fetch the number of the group from the second byte of the cell. | ||||||||||||||
| 47687 | SLA C | Double it, as the table has two bytes for each group. | ||||||||||||||
| 47689 | LD HL,35761 | Point HL at GroupTable. | ||||||||||||||
| 47692 | ADD HL,BC | Add the offset to find the entry for the group. | ||||||||||||||
| 47693 | LD C,(HL) | Fetch the low byte of the address of the group. | ||||||||||||||
| 47694 | INC HL | Move onto the high byte. | ||||||||||||||
| 47695 | LD B,(HL) | Fetch the high byte of the address of the group. | ||||||||||||||
| 47696 | PUSH BC | Put the address of the group in BC onto the stack... | ||||||||||||||
| 47697 | POP IY | ...and take it off into IY. | ||||||||||||||
| 47699 | SRL D | Multiply the first byte of the cell by 128 by shifting it... | ||||||||||||||
| 47701 | RR E | ...across DE, ready to return it as an offset. | ||||||||||||||
| 47703 | LD A,(IY+0) | Fetch the first byte of the group. | ||||||||||||||
| 47706 | AND A | Test it. | ||||||||||||||
| 47707 | RET NZ | Return with the carry flag reset if the group has objects. | ||||||||||||||
| 47708 | SCF | Set the carry flag as the group is empty. | ||||||||||||||
| 47709 | RET | Return. | ||||||||||||||
| Prev: 47636 | Up: Map | Next: 47710 |