![]() |
Routines |
| Prev: 41825 | Up: Map | Next: 42136 |
|
The handler for entity types 110 and 111, 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 9) in a sector that has some energy then the sector is activated, and if it runs into a hazard (a cell of type 1 or 7) then the program is destroyed.
|
||||||||
| MoveProgramPacket | 41836 | CALL GetPosition | Fetch the position of the packet. | |||||
| 41839 | LD A,(IX+0) | Fetch the type of the packet... | ||||||
| 41842 | XOR 1 | ...and switch to the other sprite. | ||||||
| 41844 | LD (IX+0),A | |||||||
| 41847 | LD A,E | Jump if the packet is not at the start of a cell. | ||||||
| 41848 | OR L | |||||||
| 41849 | JR NZ,MoveProgramPacket_UpdateState | |||||||
| 41851 | LD A,(IX+7) | Fetch the direction that the packet is heading in... | ||||||
| 41854 | AND 3 | ...limited to 0-3. | ||||||
| 41856 | CALL ChooseDirection | Choose a direction that is not blocked using ChooseDirection. | ||||||
| 41859 | JR Z,MoveProgramPacket_CheckCell | Jump if there is one. | ||||||
| 41861 | LD (IX+0),56 | Otherwise turn the packet into smoke... | ||||||
| 41865 | JP AddEntity | ...and draw it. | ||||||
| MoveProgramPacket_CheckCell | 41868 | CP 9 | Jump if the packet has reached a receiving terminal (a cell of type 9). | |||||
| 41870 | JR Z,MoveProgramPacket_Terminal | |||||||
| 41872 | AND A | Jump to carry on if the cell is open (type 0). | ||||||
| 41873 | JR Z,MoveProgramPacket_Continue | |||||||
| 41875 | LD B,132 | Use the state that says that the packet has been destroyed... | ||||||
| 41877 | CP 1 | ...and jump to set it if the cell is a hazard of type 1... | ||||||
| 41879 | JR Z,MoveProgramPacket_State | |||||||
| 41881 | CP 7 | ...or of type 7. | ||||||
| 41883 | JR Z,MoveProgramPacket_State | |||||||
| 41885 | CP 15 | Jump to carry on if the cell is type 15. | ||||||
| 41887 | JR Z,MoveProgramPacket_Continue | |||||||
|
The packet has been destroyed or has arrived, and is removed.
|
||||||||
| MoveProgramPacket_Remove | 41889 | XOR A | Remove the packet by setting its type to zero. | |||||
| 41890 | LD (IX+0),A | Store it. | ||||||
| 41893 | RET | Return. | ||||||
|
The terminal has no energy, so the packet turns round.
|
||||||||
| MoveProgramPacket_TurnRound | 41894 | POP HL | Restore the Y position. | |||||
| 41895 | LD A,C | Fetch the direction that the packet is heading in... | ||||||
| 41896 | ADD A,2 | ...and reverse it. | ||||||
| 41898 | AND 3 | |||||||
| 41900 | LD C,A | Keep the reversed direction. | ||||||
| 41901 | JR MoveProgramPacket_Continue | Carry on. | ||||||
| MoveProgramPacket_Terminal | 41903 | PUSH HL | Save the Y position... | |||||
| 41904 | PUSH DE | ...and the X position. | ||||||
| 41905 | CALL FindSector | Find the sector that the terminal is in using FindSector. | ||||||
| 41908 | LD E,D | Use the sector number as an index. | ||||||
| 41909 | LD D,0 | |||||||
| 41911 | LD HL,41825 | Point HL at SectorEnergy. | ||||||
| 41914 | ADD HL,DE | Add the index. | ||||||
| 41915 | POP DE | Restore the X position. | ||||||
| 41916 | LD A,(HL) | Fetch the energy of the sector. | ||||||
| 41917 | AND A | Jump to turn the packet round if the sector has no energy. | ||||||
| 41918 | JR Z,MoveProgramPacket_TurnRound | |||||||
| 41920 | LD HL,(38446) | Fetch the address of the terminal. | ||||||
| 41923 | LD A,(HL) | Fetch its contents. | ||||||
| 41924 | AND 240 | Keep the initial type... | ||||||
| 41926 | OR 14 | ...change the current type to 14, the activated terminal... | ||||||
| 41928 | LD (HL),A | ...and store the new contents. | ||||||
| 41929 | LD B,4 | Set the state of the packet to four... | ||||||
| 41931 | POP HL | ...after restoring the Y position. | ||||||
| MoveProgramPacket_State | 41932 | LD (IX+14),B | Store the state of the packet. | |||||
| MoveProgramPacket_Continue | 41935 | LD A,(IX+7) | Fetch the direction of the packet... | |||||
| 41938 | AND 252 | ...clear the old direction... | ||||||
| 41940 | OR C | ...add the new direction... | ||||||
| 41941 | LD (IX+7),A | ...and store it. | ||||||
| MoveProgramPacket_UpdateState | 41944 | LD A,(IX+14) | Fetch the state of the packet... | |||||
| 41947 | AND 15 | ...limited to the low four bits, and jump to carry on if it is zero. | ||||||
| 41949 | JR Z,MoveProgramPacket_Move | |||||||
| 41951 | DEC A | Count down the state, and jump to store it if it has not reached zero. | ||||||
| 41952 | JR NZ,MoveProgramPacket_StoreCount | |||||||
| 41954 | BIT 7,(IX+14) | Test the flag that says that the packet has been destroyed, and jump if it is not set. | ||||||
| 41958 | JR Z,MoveProgramPacket_Arrived | |||||||
| 41960 | LD DE,3 | Queue message 3, "PROGRAM HAS BEEN"... | ||||||
| 41963 | CALL QueueMessage | ...using QueueMessage. | ||||||
| 41966 | LD DE,4 | Queue message 4, "DESTROYED"... | ||||||
| 41969 | CALL QueueMessage | ...using QueueMessage. | ||||||
| 41972 | LD HL,772 | Start effect 3 (four tones)... | ||||||
| 41975 | LD (38536),HL | ...by storing the length and the effect number for PlaySoundStep. | ||||||
| 41978 | JR MoveProgramPacket_Remove | Remove the packet. | ||||||
|
The packet has arrived at a terminal in a sector that has energy.
|
||||||||
| MoveProgramPacket_Arrived | 41980 | LD DE,8 | Queue message 8, "PROGRAM RECIEVED"... | |||||
| 41983 | CALL QueueMessage | ...using QueueMessage. | ||||||
| 41986 | CALL FindSector | Find the sector that the packet is in using FindSector. | ||||||
| 41989 | LD E,1 | Queue message 1, "SECTOR n"... | ||||||
| 41991 | CALL QueueMessage | ...using QueueMessage. | ||||||
| 41994 | LD HL,38491 | Point HL at SectorFlags. | ||||||
| 41997 | LD E,D | Use the sector number as an index. | ||||||
| 41998 | LD D,0 | |||||||
| 42000 | ADD HL,DE | Add the index. | ||||||
| 42001 | LD (HL),255 | Set the flag that says that the sector has been activated. | ||||||
| 42003 | LD HL,38488 | Point HL at the number of sectors that have been activated. | ||||||
| 42006 | INC (HL) | Add one. | ||||||
| 42007 | LD HL,38526 | Point HL at SectorStates. | ||||||
| 42010 | ADD HL,DE | Add the sector number. | ||||||
| 42011 | LD A,(HL) | Fetch the state of the sector. | ||||||
| 42012 | AND 252 | Change it to activated (bit 1 set and bit 0 clear), clearing the flag that says it is under attack. | ||||||
| 42014 | OR 2 | |||||||
| 42016 | LD (HL),A | Store the new state. | ||||||
| 42017 | LD HL,41825 | Point HL at SectorEnergy. | ||||||
| 42020 | ADD HL,DE | Add the sector number. | ||||||
| 42021 | LD B,(HL) | Use the energy of the sector as a counter... | ||||||
| 42022 | XOR A | ...to count up in decimal. | ||||||
| MoveProgramPacket_CountEnergy | 42023 | ADD A,1 | Add one. | |||||
| 42025 | DAA | Convert it to decimal. | ||||||
| 42026 | DJNZ MoveProgramPacket_CountEnergy | Loop back until the count is the energy. | ||||||
| 42028 | RRCA | Swap the digits. | ||||||
| 42029 | RRCA | |||||||
| 42030 | RRCA | |||||||
| 42031 | RRCA | |||||||
| 42032 | LD C,A | Keep the result. | ||||||
| 42033 | AND 15 | Keep the digit that was the first. | ||||||
| 42035 | LD B,A | |||||||
| 42036 | CALL AddPointsToScore | Add the bonus to the score using AddPointsToScore. | ||||||
| 42039 | CALL DrawSectorMap | Colour the sector map using DrawSectorMap. | ||||||
| 42042 | LD BC,20480 | Add 20480 points... | ||||||
| 42045 | CALL AddPointsToScore | ...to the score using AddPointsToScore. | ||||||
| 42048 | LD HL,519 | Start effect 2 (seven tones)... | ||||||
| 42051 | LD (38536),HL | ...by storing the length and the effect number for PlaySoundStep. | ||||||
| 42054 | JP MoveProgramPacket_Remove | Remove the packet. | ||||||
| MoveProgramPacket_StoreCount | 42057 | LD B,A | Keep the new count. | |||||
| 42058 | LD A,(IX+14) | Fetch the state of the packet... | ||||||
| 42061 | AND 240 | ...keep the bits that are not the count... | ||||||
| 42063 | OR B | ...and combine them with the new count... | ||||||
| 42064 | LD (IX+14),A | ...and store it. | ||||||
|
The packet moves on.
|
||||||||
| MoveProgramPacket_Move | 42067 | LD B,48 | The packet can take up to 48 steps in this frame. | |||||
| 42069 | CALL TryMove | Take a step using TryMove. | ||||||
| 42072 | JR Z,MoveProgramPacket_CheckEntities | Jump if the packet could carry on. | ||||||
| 42074 | CP 1 | Jump to carry on if the cell that blocked the packet is type 1. | ||||||
| 42076 | JR Z,MoveProgramPacket_Restore | |||||||
| 42078 | CP 7 | Jump to carry on if the cell that blocked the packet is type 7. | ||||||
| 42080 | JR Z,MoveProgramPacket_Restore | |||||||
| 42082 | CP 14 | Jump if the cell that blocked the packet is not type 14. | ||||||
| 42084 | JR NZ,MoveProgramPacket_CheckEntities | |||||||
| MoveProgramPacket_Restore | 42086 | LD DE,(38483) | Restore the position that the packet had before the step... | |||||
| 42090 | LD HL,(38485) | ...and the other coordinate. | ||||||
| MoveProgramPacket_CheckEntities | 42093 | CALL CheckEntityOverlap | Check whether any entity is in the way using CheckEntityOverlap. | |||||
| 42096 | JR NC,MoveProgramPacket_Store | Jump if there is none. | ||||||
| 42098 | LD A,(IX+7) | Fetch the direction of the packet... | ||||||
| 42101 | ADD A,2 | ...and reverse it... | ||||||
| 42103 | AND 3 | |||||||
| 42105 | LD C,A | ...and keep it in C. | ||||||
| 42106 | LD A,(IX+7) | Fetch the byte again... | ||||||
| 42109 | AND 252 | ...and combine the other bits of the byte with the new direction... | ||||||
| 42111 | OR C | |||||||
| 42112 | LD (IX+7),A | ...and store it. | ||||||
| MoveProgramPacket_Store | 42115 | CALL SetPosition | Store the position of the packet. | |||||
| 42118 | RES 7,(IX+0) | Do not flip the sprite of the packet... | ||||||
| 42122 | BIT 0,(IX+7) | ...if the lowest bit of the direction is clear... | ||||||
| 42126 | JP Z,AddEntity | ...and draw the packet using AddEntity. | ||||||
| 42129 | SET 7,(IX+0) | Otherwise flip the sprite... | ||||||
| 42133 | JP AddEntity | ...and draw the packet using AddEntity. | ||||||
| Prev: 41825 | Up: Map | Next: 42136 |