![]() |
Routines |
| Prev: 9BD6 | Up: Map | Next: 9D0E |
|
Used by the routine at ScrollWorld.
Draws, erases and flickers the horizontal beams that cross the screen from the visible map tiles numbered A6, and hurts the ship when it touches one. There are up to four beams, one for each of the four tiles around the ship that are held at DC91. The beams are switched on and off at random intervals with a random pattern and colour. A beam is skipped when the bit for its cell of the map is set in the three bytes from F5EA, which are cleared when a planet is completed. What the tile A6 looks like is not yet known.
|
||||
| UpdateBeams | 9BDA | LD A,($5C3C) | Fetch the special sequence flag. | |
| 9BDD | AND A | Test it. | ||
| 9BDE | RET NZ | Return if a special sequence (such as landing) is under way. | ||
| 9BDF | LD A,($9D2F) | Fetch the delay left after the ship was last hit. | ||
| 9BE2 | AND A | Test it. | ||
| 9BE3 | JR Z,UpdateBeams_SetHitBox | Jump to UpdateBeams_SetHitBox if the delay is over. | ||
| 9BE5 | DEC A | Decrease the delay. | ||
| 9BE6 | LD ($9D2F),A | Store it. | ||
| 9BE9 | JR UpdateBeams_Look | Jump to UpdateBeams_Look. | ||
|
Set up the hit box of the ship, which is 28 by 10 pixels at the fixed horizontal position of 64.
|
||||
| UpdateBeams_SetHitBox | 9BEB | LD A,($5C38) | Fetch the vertical position of the ship. | |
| 9BEE | ADD A,$08 | Move down by 08 to the top of the hit box. | ||
| 9BF0 | LD H,A | Store it in H. | ||
| 9BF1 | LD L,$64 | Set the horizontal position to 64. | ||
| 9BF3 | LD D,$10 | Set the height to 10. | ||
| 9BF5 | LD E,$28 | Set the width to 28. | ||
| 9BF7 | LD ($ABA4),HL | Store the position of the hit box. | ||
| 9BFA | LD ($ABA6),DE | Store the size of the hit box. | ||
|
Look for a map tile numbered A6 around the ship, or a beam that is still being drawn.
|
||||
| UpdateBeams_Look | 9BFE | LD B,$04 | Set the counter to four. | |
| 9C00 | LD IY,$9D43 | Use the table of beams at BeamTable. | ||
| 9C04 | LD HL,$DC91 | Use the four tiles around the ship. | ||
| UpdateBeams_LookLoop | 9C07 | LD A,(HL) | Fetch a tile. | |
| 9C08 | CP $A6 | Jump to UpdateBeams_Timer if it is tile A6. | ||
| 9C0A | JR Z,UpdateBeams_Timer | |||
| 9C0C | INC HL | Move on to the next tile. | ||
| 9C0D | LD A,(IY+$00) | Fetch the beam address. | ||
| 9C10 | AND A | Test it. | ||
| 9C11 | JR NZ,UpdateBeams_Timer | Jump to UpdateBeams_Timer if a beam is still being drawn. | ||
| 9C13 | INC IY | Move on to the next beam. | ||
| 9C15 | INC IY | |||
| 9C17 | INC IY | |||
| 9C19 | INC IY | |||
| 9C1B | DJNZ UpdateBeams_LookLoop | Loop back to UpdateBeams_LookLoop for each of the four. | ||
| 9C1D | RET | Return if there is nothing to do. | ||
|
Count down to the next change of the beams.
|
||||
| UpdateBeams_Timer | 9C1E | LD IX,$9BD6 | Use the beam variables. | |
| 9C22 | DEC (IX+$02) | Decrease the timer. | ||
| 9C25 | JR NZ,UpdateBeams_Beams | Jump to UpdateBeams_Beams unless it has run out. | ||
| 9C27 | LD (IX+$00),$00 | Switch the beams off. | ||
| 9C2B | LD A,($9BCB) | Fetch a random number. | ||
| 9C2E | BIT 0,A | Jump to UpdateBeams_Off if the beams stay off. | ||
| 9C30 | JR Z,UpdateBeams_Off | |||
|
Choose the colour and pattern of the new beams.
|
||||
| 9C32 | LD A,($9BCC) | Fetch another random number. | ||
| 9C35 | AND %00000111 | Keep the bottom three bits for the colour. | ||
| 9C37 | JR NZ,UpdateBeams_Colour | Jump to UpdateBeams_Colour unless the colour is black. | ||
| 9C39 | LD A,$05 | Use cyan instead. | ||
| UpdateBeams_Colour | 9C3B | LD B,A | Save the colour. | |
| 9C3C | ADD A,$40 | Make it bright. | ||
| 9C3E | LD (IX+$01),A | Set the attribute of the beams. | ||
| 9C41 | LD A,($9BCB) | Fetch the first random number again. | ||
| 9C44 | AND %00000111 | Keep the bottom three bits. | ||
| 9C46 | XOR B | Combine them with the colour. | ||
| 9C47 | LD HL,$9DA9 | Use the table of patterns. | ||
| 9C4A | CALL AddAToHL | Add the index. | ||
| 9C4D | LD A,(HL) | Fetch a pattern. | ||
| 9C4E | LD (IX+$00),A | Set the pattern of the beams. | ||
| 9C51 | LD B,$1F | The beams stay on for up to 20 frames. | ||
| 9C53 | JR UpdateBeams_Interval | Jump to UpdateBeams_Interval. | ||
| UpdateBeams_Off | 9C55 | LD B,$0F | The beams stay off for up to 10 frames. | |
|
Choose how long it is until the next change.
|
||||
| UpdateBeams_Interval | 9C57 | LD A,($9BCC) | Fetch a random number. | |
| 9C5A | CPL | Invert it. | ||
| 9C5B | AND B | Limit it to the range chosen. | ||
| 9C5C | INC A | Make sure it is at least one. | ||
| 9C5D | LD (IX+$02),A | Set the timer. | ||
|
Now deal with each beam in turn. The beams are done in the order 00, 02, 01 and then 03.
|
||||
| UpdateBeams_Beams | 9C60 | XOR A | Clear A. | |
| 9C61 | LD ($9BD9),A | Note that no beam has been drawn yet. | ||
| 9C64 | LD IY,$9D43 | Use the table of beams. | ||
| UpdateBeams_Next | 9C68 | LD ($5C1E),A | Store the number of the beam. | |
| 9C6B | LD A,(IY+$00) | Fetch the screen address of the beam last drawn. | ||
| 9C6E | AND A | Test it. | ||
| 9C6F | JR Z,UpdateBeams_Erased | Jump to UpdateBeams_Erased if there is no beam. | ||
| 9C71 | LD L,(IY+$00) | Fetch the screen address into HL. | ||
| 9C74 | LD H,(IY+$01) | |||
| 9C77 | LD B,(IY+$02) | Fetch the length of the beam into B. | ||
| 9C7A | LD C,(IY+$03) | Fetch the pattern of the beam into C. | ||
| 9C7D | CALL EraseBeam | Erase the beam. | ||
| UpdateBeams_Erased | 9C80 | LD (IY+$00),$00 | Forget the beam. | |
| 9C84 | LD A,($5C1E) | Fetch the number of the beam. | ||
| 9C87 | LD HL,($CE57) | Fetch the position of the ship on the map. | ||
| 9C8A | BIT 0,A | Jump to UpdateBeams_Row if bit 0 of the beam number is clear. | ||
| 9C8C | JR Z,UpdateBeams_Row | |||
| 9C8E | INC H | Move to the next row of the map. | ||
| UpdateBeams_Row | 9C8F | BIT 1,A | Jump to UpdateBeams_Cell if bit 1 of the beam number is clear. | |
| 9C91 | JR Z,UpdateBeams_Cell | |||
| 9C93 | INC L | Move to the next column of the map. | ||
| UpdateBeams_Cell | 9C94 | EX DE,HL | Copy the position into DE. | |
| 9C95 | CALL FindCellBit | Find the byte and bit that go with the cell. | ||
| 9C98 | LD A,B | Fetch the bit number... | ||
| 9C99 | ADD A,$46 | ...and add the opcode of BIT 0,(HL) (46). | ||
| 9C9B | LD ($9C9F),A | Modify the instruction at 9C9E to test that bit. | ||
| 9C9E | BIT 0,(HL) | Jump to UpdateBeams_Advance if the bit of the cell is set. | ||
| 9CA0 | JR NZ,UpdateBeams_Advance | |||
| 9CA2 | LD HL,$DC91 | Use the four tiles around the ship. | ||
| 9CA5 | LD A,($5C1E) | Fetch the number of the beam. | ||
| 9CA8 | CALL AddAToHL | Add it to the address. | ||
| 9CAB | LD A,(HL) | Fetch the tile. | ||
| 9CAC | CP $A6 | Jump to UpdateBeams_Advance if it is not tile A6. | ||
| 9CAE | JR NZ,UpdateBeams_Advance | |||
| 9CB0 | LD A,(IX+$00) | Fetch the pattern of the beams. | ||
| 9CB3 | AND A | Test it. | ||
| 9CB4 | JR Z,UpdateBeams_Advance | Jump to UpdateBeams_Advance if the beams are off. | ||
| 9CB6 | LD HL,($CE45) | Fetch the first scroll position. | ||
| 9CB9 | LD DE,($CE41) | Fetch the second scroll position. | ||
| 9CBD | CALL FindBeamExtent | Work out the extent of the beam. | ||
| 9CC0 | LD A,B | Fetch its length. | ||
| 9CC1 | AND A | Test it. | ||
| 9CC2 | JR Z,UpdateBeams_Advance | Jump to UpdateBeams_Advance if there is no beam. | ||
| 9CC4 | CALL DrawBeam | Draw the beam. | ||
| 9CC7 | LD HL,($BF83) | Fetch the position of the beam. | ||
| 9CCA | LD A,(IY+$02) | Fetch its length. | ||
| 9CCD | LD ($B625),A | Store it as the width of the attributes to colour. | ||
| 9CD0 | ADD A,A | Multiply it by eight to get the length in pixels. | ||
| 9CD1 | ADD A,A | |||
| 9CD2 | ADD A,A | |||
| 9CD3 | LD D,A | Store it in D. | ||
| 9CD4 | LD A,($9D2F) | Fetch the delay left after the last hit. | ||
| 9CD7 | AND A | Test it. | ||
| 9CD8 | PUSH HL | Save the position. | ||
| 9CD9 | CALL Z,CheckBeamHit | Check whether the ship has been hit, if the delay is over. | ||
| 9CDC | POP HL | Restore the position. | ||
| 9CDD | LD A,(IX+$01) | Fetch the attribute of the beam. | ||
| 9CE0 | LD ($B627),A | Store it in the parameters. | ||
| 9CE3 | LD DE,$B625 | Use the parameters. | ||
| 9CE6 | CALL FillAttributes | Colour the beam. | ||
| 9CE9 | OR %00000001 | Make A non-zero. | ||
| 9CEB | LD ($9BD9),A | Note that a beam has been drawn. | ||
| UpdateBeams_Advance | 9CEE | INC IY | Move on to the next beam. | |
| 9CF0 | INC IY | |||
| 9CF2 | INC IY | |||
| 9CF4 | INC IY | |||
| 9CF6 | LD A,($5C1E) | Fetch the number of the beam. | ||
| 9CF9 | CP $03 | Jump to UpdateBeams_Sound if it was the last, beam 03. | ||
| 9CFB | JR Z,UpdateBeams_Sound | |||
| 9CFD | XOR %00000010 | Choose the next beam. | ||
| 9CFF | JP NZ,UpdateBeams_Next | Jump to UpdateBeams_Next if it is now beam 02 or 03. | ||
| 9D02 | INC A | Otherwise it is beam 01. | ||
| 9D03 | JP UpdateBeams_Next | Jump to UpdateBeams_Next. | ||
| UpdateBeams_Sound | 9D06 | LD A,($9BD9) | Fetch the flag that says whether a beam was drawn. | |
| 9D09 | AND A | Test it. | ||
| 9D0A | RET Z | Return if not. | ||
| 9D0B | JP PlayBeamSound | Make the sound of the beams. | ||
| Prev: 9BD6 | Up: Map | Next: 9D0E |