Prev: 39886 Up: Map Next: 39950
39923: Count Programs In Sector
Used by the routine at CountSectorPrograms.
Counts the installed programs in a sector of 16 by 16 cells and adds each one to the energy of the sector.
Input
HL Address of the first cell of the sector in the map
HL' Address of the energy of the sector
CountSectorPrograms_Sector 39923 LD DE,64 Each row of the map is 64 bytes long.
39926 LD C,16 There are 16 rows in the sector.
CountSectorPrograms_Row 39928 LD B,16 There are 16 cells in each row.
39930 PUSH HL Save the address of the start of the row.
CountSectorPrograms_Cell 39931 LD A,(HL) Fetch the cell.
39932 CP 34 Jump if it is an installed program, which is a cell with a current and an initial type of 2.
39934 JR Z,CountSectorPrograms_Installed
CountSectorPrograms_Next 39936 INC HL Move on to the next cell.
39937 DJNZ CountSectorPrograms_Cell Loop back until the whole row has been checked.
39939 POP HL Restore the address of the start of the row.
39940 ADD HL,DE Move down to the next row of the map.
39941 DEC C Count down the rows.
39942 JR NZ,CountSectorPrograms_Row Loop back until the whole sector has been checked.
39944 RET Return.
CountSectorPrograms_Installed 39945 EXX Switch to the shadow registers.
39946 INC (HL) Add one to the energy of the sector.
39947 EXX Switch back to the main registers.
39948 JR CountSectorPrograms_Next Jump back to carry on with the row.
Prev: 39886 Up: Map Next: 39950