![]() |
Routines |
| Prev: 39968 | Up: Map | Next: 40054 |
|
Used by the routines at SendProgramPacket, MoveSpark, MoveDestroyer, FindSectorEnergy, MoveProgramPacket and UseActionKey_Up.
Finds the sector that an entity is in. The nine sectors are numbered from 0 for the top left to 8 for the bottom right.
|
||||||||||||
| FindSector | 40030 | LD A,(IX+2) | Fetch the X cell of the entity. | |||||||||
| 40033 | AND 48 | Keep the sector column, which is a multiple of 16... | ||||||||||
| 40035 | LD E,A | ...in E. | ||||||||||
| 40036 | LD A,(IX+4) | Fetch the Y cell of the entity. | ||||||||||
| 40039 | AND 48 | Keep the sector row... | ||||||||||
| 40041 | XOR 48 | ...and turn it round, as the first row of sectors is at the bottom of the map... | ||||||||||
| 40043 | SUB 16 | ...and make it a multiple of 16 from 0 to 32, from the top. | ||||||||||
| 40045 | LD D,A | Keep the sector row. | ||||||||||
| 40046 | ADD A,E | Add the column. | ||||||||||
| 40047 | RRCA | Halve it... | ||||||||||
| 40048 | ADD A,D | ...and add the row, so that the result is three times the row plus the column, multiplied by 8. | ||||||||||
| 40049 | RRCA | Shift down by three... | ||||||||||
| 40050 | RRCA | |||||||||||
| 40051 | RRCA | |||||||||||
| 40052 | LD D,A | ...to give the sector number. | ||||||||||
| 40053 | RET | Return. | ||||||||||
| Prev: 39968 | Up: Map | Next: 40054 |