Prev: 39674 Up: Map Next: 39923
39886: Count Sector Programs
Used by the routine at StartRound.
Counts the installed programs (map cells with both their current and initial type equal to 2) in each of the nine sectors. The result is the amount of energy that each sector starts with.
CountSectorPrograms 39886 LD B,9 There are nine sectors, which are counted from the last to the first.
CountSectorPrograms_NextSector 39888 LD A,B Fetch the sector number...
39889 DEC A ...which is one below the counter.
39890 LD HL,41825 Point HL at SectorEnergy.
39893 CALL AddAToHL Add the sector number, using AddAToHL, to find the entry for this sector.
39896 LD (HL),0 Start the count for the sector at zero.
39898 LD A,B Fetch the sector number again.
39899 DEC A The sector number is one below the counter.
39900 EXX Switch to the shadow registers, so that the counter in HL' is the address of the entry for this sector.
39901 ADD A,A Double the sector number...
39902 LD E,A ...to make an index into the table of offsets of the sectors in the map.
39903 LD D,0 Clear the high byte of the index.
39905 LD HL,39950 Point HL at SectorOffsets.
39908 ADD HL,DE Add the index.
39909 LD E,(HL) Fetch the low byte of the offset of the sector...
39910 INC HL ...and then the high byte...
39911 LD D,(HL) ...into DE.
39912 LD HL,50453 Point HL at Map.
39915 ADD HL,DE Add the offset to find the first cell of the sector.
39916 CALL CountSectorPrograms_Sector Count the programs in the sector using CountSectorPrograms_Sector.
39919 EXX Switch back to the main registers.
39920 DJNZ CountSectorPrograms_NextSector Loop back until every sector has been counted.
39922 RET Return.
Prev: 39674 Up: Map Next: 39923