![]() |
Routines |
| Prev: 9AFA | Up: Map | Next: 9BF3 |
|
Used by the routine at StartRound.
Counts the installed programs (map cells with both their current and initial type equal to 02) in each of the nine sectors. The result is the amount of energy that each sector starts with.
|
||||
| CountSectorPrograms | 9BCE | LD B,$09 | There are nine sectors, which are counted from the last to the first. | |
| CountSectorPrograms_NextSector | 9BD0 | LD A,B | Fetch the sector number... | |
| 9BD1 | DEC A | ...which is one below the counter. | ||
| 9BD2 | LD HL,$A361 | Point HL at SectorEnergy. | ||
| 9BD5 | CALL AddAToHL | Add the sector number, using AddAToHL, to find the entry for this sector. | ||
| 9BD8 | LD (HL),$00 | Start the count for the sector at zero. | ||
| 9BDA | LD A,B | Fetch the sector number again. | ||
| 9BDB | DEC A | The sector number is one below the counter. | ||
| 9BDC | EXX | Switch to the shadow registers, so that the counter in HL' is the address of the entry for this sector. | ||
| 9BDD | ADD A,A | Double the sector number... | ||
| 9BDE | LD E,A | ...to make an index into the table of offsets of the sectors in the map. | ||
| 9BDF | LD D,$00 | Clear the high byte of the index. | ||
| 9BE1 | LD HL,$9C0E | Point HL at SectorOffsets. | ||
| 9BE4 | ADD HL,DE | Add the index. | ||
| 9BE5 | LD E,(HL) | Fetch the low byte of the offset of the sector... | ||
| 9BE6 | INC HL | ...and then the high byte... | ||
| 9BE7 | LD D,(HL) | ...into DE. | ||
| 9BE8 | LD HL,$C515 | Point HL at Map. | ||
| 9BEB | ADD HL,DE | Add the offset to find the first cell of the sector. | ||
| 9BEC | CALL CountSectorPrograms_Sector | Count the programs in the sector using CountSectorPrograms_Sector. | ||
| 9BEF | EXX | Switch back to the main registers. | ||
| 9BF0 | DJNZ CountSectorPrograms_NextSector | Loop back until every sector has been counted. | ||
| 9BF2 | RET | Return. | ||
| Prev: 9AFA | Up: Map | Next: 9BF3 |