Prev: 9D46 Up: Map Next: 9DFE
9DA7: Attack Sector
Used by the routine at MainLoop.
Called every frame. It counts down to the next attack on one of the nine sectors. When the count reaches zero a sector is picked at random. If it still has some energy then it comes under attack, and the messages "SECTOR n" and "UNDER ATTACK" are queued. The attack lasts until the next sector is attacked.
AttackSector 9DA7 LD A,($9646) Fetch the number of frames until the next attack.
9DAA DEC A Count down.
9DAB LD ($9646),A Store it.
9DAE RET NZ Return if it has not reached zero.
9DAF LD A,$50 Set the time until the next attack to 50 frames.
9DB1 LD ($9646),A Store it.
9DB4 LD A,($9617) Fetch the random number.
9DB7 AND $C6 Keep the bits that choose the sector (bits 1 and 2 give the column, bits 6 and 7 the row).
9DB9 LD C,A Keep the sector bits.
9DBA AND $C0 Test the row.
9DBC CP $C0 Jump if it is 03, as there is no such row.
9DBE JR Z,AttackSector_Retry
9DC0 LD A,C Fetch the number again.
9DC1 AND $06 Test the column.
9DC3 CP $06 Jump if it is 03, as there is no such column.
9DC5 JR Z,AttackSector_Retry
9DC7 RRCA Move the column into bits 0 and 1...
9DC8 LD D,A ...and keep it in D.
9DC9 LD A,C Fetch the number again.
9DCA RLCA Move the row into bits 0 and 1...
9DCB RLCA
9DCC AND $03 ...clear the other bits...
9DCE LD E,A ...and keep the row in E.
9DCF RLCA Double the row...
9DD0 ADD A,E ...add the row to make three times the row...
9DD1 ADD A,D ...and add the column to find the sector number.
9DD2 LD E,A Keep the sector number...
9DD3 LD D,$00 ...and clear D.
9DD5 LD HL,$A361 Point HL at SectorEnergy.
9DD8 ADD HL,DE Add the sector number.
9DD9 LD A,(HL) Fetch the energy of the sector.
9DDA AND A Jump if the sector has no energy left, as it cannot be attacked.
9DDB JR Z,AttackSector_NoEnergy
9DDD LD HL,$967E Point HL at SectorStates.
9DE0 ADD HL,DE Add the sector number.
9DE1 SET 2,(HL) Mark the sector as under attack.
9DE3 LD D,E Use the sector number as the argument of the message...
9DE4 LD E,$01 ...for message 01, "SECTOR n".
9DE6 CALL QueueMessage Queue the message using QueueMessage.
9DE9 LD DE,$0006 Queue message 06, "UNDER ATTACK"...
9DEC CALL QueueMessage ...as well.
9DEF JP SetAttackedSector Mark the sector as the one under attack and colour the sector map using SetAttackedSector.
The time until the next attack is shortened if there was no sector that could be attacked.
AttackSector_Retry 9DF2 LD A,$20 Set the time until the next attack to 20 frames.
AttackSector_Store 9DF4 LD ($9646),A Store it.
9DF7 JP SetAttackedSector Mark the sector as the one under attack and colour the sector map using SetAttackedSector.
AttackSector_NoEnergy 9DFA LD A,$01 Set the time until the next attack to one frame.
9DFC JR AttackSector_Store Jump back to store it.
Prev: 9D46 Up: Map Next: 9DFE