Prev: A361 Up: Map Next: A498
A36C: Move Program Packet
The handler for entity types 6E and 6F, which is the program packet that is sent from a transmitter to a sector. It follows the open cells of the map. If it reaches a receiving terminal (a cell of type 09) in a sector that has some energy then the sector is activated, and if it runs into a hazard (a cell of type 01 or 07) then the program is destroyed.
Input
IX Entity
MoveProgramPacket A36C CALL GetPosition Fetch the position of the packet.
A36F LD A,(IX+$00) Fetch the type of the packet...
A372 XOR $01 ...and switch to the other sprite.
A374 LD (IX+$00),A
A377 LD A,E Jump if the packet is not at the start of a cell.
A378 OR L
A379 JR NZ,MoveProgramPacket_UpdateState
A37B LD A,(IX+$07) Fetch the direction that the packet is heading in...
A37E AND $03 ...limited to 00-03.
A380 CALL ChooseDirection Choose a direction that is not blocked using ChooseDirection.
A383 JR Z,MoveProgramPacket_CheckCell Jump if there is one.
A385 LD (IX+$00),$38 Otherwise turn the packet into smoke...
A389 JP AddEntity ...and draw it.
MoveProgramPacket_CheckCell A38C CP $09 Jump if the packet has reached a receiving terminal (a cell of type 09).
A38E JR Z,MoveProgramPacket_Terminal
A390 AND A Jump to carry on if the cell is open (type 00).
A391 JR Z,MoveProgramPacket_Continue
A393 LD B,$84 Use the state that says that the packet has been destroyed...
A395 CP $01 ...and jump to set it if the cell is a hazard of type 01...
A397 JR Z,MoveProgramPacket_State
A399 CP $07 ...or of type 07.
A39B JR Z,MoveProgramPacket_State
A39D CP $0F Jump to carry on if the cell is type 0F.
A39F JR Z,MoveProgramPacket_Continue
The packet has been destroyed or has arrived, and is removed.
MoveProgramPacket_Remove A3A1 XOR A Remove the packet by setting its type to zero.
A3A2 LD (IX+$00),A Store it.
A3A5 RET Return.
The terminal has no energy, so the packet turns round.
MoveProgramPacket_TurnRound A3A6 POP HL Restore the Y position.
A3A7 LD A,C Fetch the direction that the packet is heading in...
A3A8 ADD A,$02 ...and reverse it.
A3AA AND $03
A3AC LD C,A Keep the reversed direction.
A3AD JR MoveProgramPacket_Continue Carry on.
MoveProgramPacket_Terminal A3AF PUSH HL Save the Y position...
A3B0 PUSH DE ...and the X position.
A3B1 CALL FindSector Find the sector that the terminal is in using FindSector.
A3B4 LD E,D Use the sector number as an index.
A3B5 LD D,$00
A3B7 LD HL,$A361 Point HL at SectorEnergy.
A3BA ADD HL,DE Add the index.
A3BB POP DE Restore the X position.
A3BC LD A,(HL) Fetch the energy of the sector.
A3BD AND A Jump to turn the packet round if the sector has no energy.
A3BE JR Z,MoveProgramPacket_TurnRound
A3C0 LD HL,($962E) Fetch the address of the terminal.
A3C3 LD A,(HL) Fetch its contents.
A3C4 AND $F0 Keep the initial type...
A3C6 OR $0E ...change the current type to 0E, the activated terminal...
A3C8 LD (HL),A ...and store the new contents.
A3C9 LD B,$04 Set the state of the packet to four...
A3CB POP HL ...after restoring the Y position.
MoveProgramPacket_State A3CC LD (IX+$0E),B Store the state of the packet.
MoveProgramPacket_Continue A3CF LD A,(IX+$07) Fetch the direction of the packet...
A3D2 AND $FC ...clear the old direction...
A3D4 OR C ...add the new direction...
A3D5 LD (IX+$07),A ...and store it.
MoveProgramPacket_UpdateState A3D8 LD A,(IX+$0E) Fetch the state of the packet...
A3DB AND $0F ...limited to the low four bits, and jump to carry on if it is zero.
A3DD JR Z,MoveProgramPacket_Move
A3DF DEC A Count down the state, and jump to store it if it has not reached zero.
A3E0 JR NZ,MoveProgramPacket_StoreCount
A3E2 BIT 7,(IX+$0E) Test the flag that says that the packet has been destroyed, and jump if it is not set.
A3E6 JR Z,MoveProgramPacket_Arrived
A3E8 LD DE,$0003 Queue message 03, "PROGRAM HAS BEEN"...
A3EB CALL QueueMessage ...using QueueMessage.
A3EE LD DE,$0004 Queue message 04, "DESTROYED"...
A3F1 CALL QueueMessage ...using QueueMessage.
A3F4 LD HL,$0304 Start effect 03 (four tones)...
A3F7 LD ($9688),HL ...by storing the length and the effect number for PlaySoundStep.
A3FA JR MoveProgramPacket_Remove Remove the packet.
The packet has arrived at a terminal in a sector that has energy.
MoveProgramPacket_Arrived A3FC LD DE,$0008 Queue message 08, "PROGRAM RECIEVED"...
A3FF CALL QueueMessage ...using QueueMessage.
A402 CALL FindSector Find the sector that the packet is in using FindSector.
A405 LD E,$01 Queue message 01, "SECTOR n"...
A407 CALL QueueMessage ...using QueueMessage.
A40A LD HL,$965B Point HL at SectorFlags.
A40D LD E,D Use the sector number as an index.
A40E LD D,$00
A410 ADD HL,DE Add the index.
A411 LD (HL),$FF Set the flag that says that the sector has been activated.
A413 LD HL,$9658 Point HL at the number of sectors that have been activated.
A416 INC (HL) Add one.
A417 LD HL,$967E Point HL at SectorStates.
A41A ADD HL,DE Add the sector number.
A41B LD A,(HL) Fetch the state of the sector.
A41C AND $FC Change it to activated (bit 1 set and bit 0 clear), clearing the flag that says it is under attack.
A41E OR $02
A420 LD (HL),A Store the new state.
A421 LD HL,$A361 Point HL at SectorEnergy.
A424 ADD HL,DE Add the sector number.
A425 LD B,(HL) Use the energy of the sector as a counter...
A426 XOR A ...to count up in decimal.
MoveProgramPacket_CountEnergy A427 ADD A,$01 Add one.
A429 DAA Convert it to decimal.
A42A DJNZ MoveProgramPacket_CountEnergy Loop back until the count is the energy.
A42C RRCA Swap the digits.
A42D RRCA
A42E RRCA
A42F RRCA
A430 LD C,A Keep the result.
A431 AND $0F Keep the digit that was the first.
A433 LD B,A
A434 CALL AddPointsToScore Add the bonus to the score using AddPointsToScore.
A437 CALL DrawSectorMap Colour the sector map using DrawSectorMap.
A43A LD BC,$5000 Add 5000 points...
A43D CALL AddPointsToScore ...to the score using AddPointsToScore.
A440 LD HL,$0207 Start effect 02 (seven tones)...
A443 LD ($9688),HL ...by storing the length and the effect number for PlaySoundStep.
A446 JP MoveProgramPacket_Remove Remove the packet.
MoveProgramPacket_StoreCount A449 LD B,A Keep the new count.
A44A LD A,(IX+$0E) Fetch the state of the packet...
A44D AND $F0 ...keep the bits that are not the count...
A44F OR B ...and combine them with the new count...
A450 LD (IX+$0E),A ...and store it.
The packet moves on.
MoveProgramPacket_Move A453 LD B,$30 The packet can take up to 30 steps in this frame.
A455 CALL TryMove Take a step using TryMove.
A458 JR Z,MoveProgramPacket_CheckEntities Jump if the packet could carry on.
A45A CP $01 Jump to carry on if the cell that blocked the packet is type 01.
A45C JR Z,MoveProgramPacket_Restore
A45E CP $07 Jump to carry on if the cell that blocked the packet is type 07.
A460 JR Z,MoveProgramPacket_Restore
A462 CP $0E Jump if the cell that blocked the packet is not type 0E.
A464 JR NZ,MoveProgramPacket_CheckEntities
MoveProgramPacket_Restore A466 LD DE,($9653) Restore the position that the packet had before the step...
A46A LD HL,($9655) ...and the other coordinate.
MoveProgramPacket_CheckEntities A46D CALL CheckEntityOverlap Check whether any entity is in the way using CheckEntityOverlap.
A470 JR NC,MoveProgramPacket_Store Jump if there is none.
A472 LD A,(IX+$07) Fetch the direction of the packet...
A475 ADD A,$02 ...and reverse it...
A477 AND $03
A479 LD C,A ...and keep it in C.
A47A LD A,(IX+$07) Fetch the byte again...
A47D AND $FC ...and combine the other bits of the byte with the new direction...
A47F OR C
A480 LD (IX+$07),A ...and store it.
MoveProgramPacket_Store A483 CALL SetPosition Store the position of the packet.
A486 RES 7,(IX+$00) Do not flip the sprite of the packet...
A48A BIT 0,(IX+$07) ...if the lowest bit of the direction is clear...
A48E JP Z,AddEntity ...and draw the packet using AddEntity.
A491 SET 7,(IX+$00) Otherwise flip the sprite...
A495 JP AddEntity ...and draw the packet using AddEntity.
Prev: A361 Up: Map Next: A498