Prev: 39894 Up: Map Next: 40206
39898: Update Beams
Used by the routine at ScrollWorld.
Draws, erases and flickers the horizontal beams that cross the screen from the visible map tiles numbered 166, 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 56465. 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 62954, which are cleared when a planet is completed. What the tile 166 looks like is not yet known.
UpdateBeams 39898 LD A,(23612) Fetch the special sequence flag.
39901 AND A Test it.
39902 RET NZ Return if a special sequence (such as landing) is under way.
39903 LD A,(40239) Fetch the delay left after the ship was last hit.
39906 AND A Test it.
39907 JR Z,UpdateBeams_SetHitBox Jump to UpdateBeams_SetHitBox if the delay is over.
39909 DEC A Decrease the delay.
39910 LD (40239),A Store it.
39913 JR UpdateBeams_Look Jump to UpdateBeams_Look.
Set up the hit box of the ship, which is 40 by 16 pixels at the fixed horizontal position of 100.
UpdateBeams_SetHitBox 39915 LD A,(23608) Fetch the vertical position of the ship.
39918 ADD A,8 Move down by 8 to the top of the hit box.
39920 LD H,A Store it in H.
39921 LD L,100 Set the horizontal position to 100.
39923 LD D,16 Set the height to 16.
39925 LD E,40 Set the width to 40.
39927 LD (43940),HL Store the position of the hit box.
39930 LD (43942),DE Store the size of the hit box.
Look for a map tile numbered 166 around the ship, or a beam that is still being drawn.
UpdateBeams_Look 39934 LD B,4 Set the counter to four.
39936 LD IY,40259 Use the table of beams at BeamTable.
39940 LD HL,56465 Use the four tiles around the ship.
UpdateBeams_LookLoop 39943 LD A,(HL) Fetch a tile.
39944 CP 166 Jump to UpdateBeams_Timer if it is tile 166.
39946 JR Z,UpdateBeams_Timer
39948 INC HL Move on to the next tile.
39949 LD A,(IY+0) Fetch the beam address.
39952 AND A Test it.
39953 JR NZ,UpdateBeams_Timer Jump to UpdateBeams_Timer if a beam is still being drawn.
39955 INC IY Move on to the next beam.
39957 INC IY
39959 INC IY
39961 INC IY
39963 DJNZ UpdateBeams_LookLoop Loop back to UpdateBeams_LookLoop for each of the four.
39965 RET Return if there is nothing to do.
Count down to the next change of the beams.
UpdateBeams_Timer 39966 LD IX,39894 Use the beam variables.
39970 DEC (IX+2) Decrease the timer.
39973 JR NZ,UpdateBeams_Beams Jump to UpdateBeams_Beams unless it has run out.
39975 LD (IX+0),0 Switch the beams off.
39979 LD A,(39883) Fetch a random number.
39982 BIT 0,A Jump to UpdateBeams_Off if the beams stay off.
39984 JR Z,UpdateBeams_Off
Choose the colour and pattern of the new beams.
39986 LD A,(39884) Fetch another random number.
39989 AND %00000111 Keep the bottom three bits for the colour.
39991 JR NZ,UpdateBeams_Colour Jump to UpdateBeams_Colour unless the colour is black.
39993 LD A,5 Use cyan instead.
UpdateBeams_Colour 39995 LD B,A Save the colour.
39996 ADD A,64 Make it bright.
39998 LD (IX+1),A Set the attribute of the beams.
40001 LD A,(39883) Fetch the first random number again.
40004 AND %00000111 Keep the bottom three bits.
40006 XOR B Combine them with the colour.
40007 LD HL,40361 Use the table of patterns.
40010 CALL AddAToHL Add the index.
40013 LD A,(HL) Fetch a pattern.
40014 LD (IX+0),A Set the pattern of the beams.
40017 LD B,31 The beams stay on for up to 32 frames.
40019 JR UpdateBeams_Interval Jump to UpdateBeams_Interval.
UpdateBeams_Off 40021 LD B,15 The beams stay off for up to 16 frames.
Choose how long it is until the next change.
UpdateBeams_Interval 40023 LD A,(39884) Fetch a random number.
40026 CPL Invert it.
40027 AND B Limit it to the range chosen.
40028 INC A Make sure it is at least one.
40029 LD (IX+2),A Set the timer.
Now deal with each beam in turn. The beams are done in the order 0, 2, 1 and then 3.
UpdateBeams_Beams 40032 XOR A Clear A.
40033 LD (39897),A Note that no beam has been drawn yet.
40036 LD IY,40259 Use the table of beams.
UpdateBeams_Next 40040 LD (23582),A Store the number of the beam.
40043 LD A,(IY+0) Fetch the screen address of the beam last drawn.
40046 AND A Test it.
40047 JR Z,UpdateBeams_Erased Jump to UpdateBeams_Erased if there is no beam.
40049 LD L,(IY+0) Fetch the screen address into HL.
40052 LD H,(IY+1)
40055 LD B,(IY+2) Fetch the length of the beam into B.
40058 LD C,(IY+3) Fetch the pattern of the beam into C.
40061 CALL EraseBeam Erase the beam.
UpdateBeams_Erased 40064 LD (IY+0),0 Forget the beam.
40068 LD A,(23582) Fetch the number of the beam.
40071 LD HL,(52823) Fetch the position of the ship on the map.
40074 BIT 0,A Jump to UpdateBeams_Row if bit 0 of the beam number is clear.
40076 JR Z,UpdateBeams_Row
40078 INC H Move to the next row of the map.
UpdateBeams_Row 40079 BIT 1,A Jump to UpdateBeams_Cell if bit 1 of the beam number is clear.
40081 JR Z,UpdateBeams_Cell
40083 INC L Move to the next column of the map.
UpdateBeams_Cell 40084 EX DE,HL Copy the position into DE.
40085 CALL FindCellBit Find the byte and bit that go with the cell.
40088 LD A,B Fetch the bit number...
40089 ADD A,70 ...and add the opcode of BIT 0,(HL) (70).
40091 LD (40095),A Modify the instruction at 40094 to test that bit.
40094 BIT 0,(HL) Jump to UpdateBeams_Advance if the bit of the cell is set.
40096 JR NZ,UpdateBeams_Advance
40098 LD HL,56465 Use the four tiles around the ship.
40101 LD A,(23582) Fetch the number of the beam.
40104 CALL AddAToHL Add it to the address.
40107 LD A,(HL) Fetch the tile.
40108 CP 166 Jump to UpdateBeams_Advance if it is not tile 166.
40110 JR NZ,UpdateBeams_Advance
40112 LD A,(IX+0) Fetch the pattern of the beams.
40115 AND A Test it.
40116 JR Z,UpdateBeams_Advance Jump to UpdateBeams_Advance if the beams are off.
40118 LD HL,(52805) Fetch the first scroll position.
40121 LD DE,(52801) Fetch the second scroll position.
40125 CALL FindBeamExtent Work out the extent of the beam.
40128 LD A,B Fetch its length.
40129 AND A Test it.
40130 JR Z,UpdateBeams_Advance Jump to UpdateBeams_Advance if there is no beam.
40132 CALL DrawBeam Draw the beam.
40135 LD HL,(49027) Fetch the position of the beam.
40138 LD A,(IY+2) Fetch its length.
40141 LD (46629),A Store it as the width of the attributes to colour.
40144 ADD A,A Multiply it by eight to get the length in pixels.
40145 ADD A,A
40146 ADD A,A
40147 LD D,A Store it in D.
40148 LD A,(40239) Fetch the delay left after the last hit.
40151 AND A Test it.
40152 PUSH HL Save the position.
40153 CALL Z,CheckBeamHit Check whether the ship has been hit, if the delay is over.
40156 POP HL Restore the position.
40157 LD A,(IX+1) Fetch the attribute of the beam.
40160 LD (46631),A Store it in the parameters.
40163 LD DE,46629 Use the parameters.
40166 CALL FillAttributes Colour the beam.
40169 OR %00000001 Make A non-zero.
40171 LD (39897),A Note that a beam has been drawn.
UpdateBeams_Advance 40174 INC IY Move on to the next beam.
40176 INC IY
40178 INC IY
40180 INC IY
40182 LD A,(23582) Fetch the number of the beam.
40185 CP 3 Jump to UpdateBeams_Sound if it was the last, beam 3.
40187 JR Z,UpdateBeams_Sound
40189 XOR %00000010 Choose the next beam.
40191 JP NZ,UpdateBeams_Next Jump to UpdateBeams_Next if it is now beam 2 or 3.
40194 INC A Otherwise it is beam 1.
40195 JP UpdateBeams_Next Jump to UpdateBeams_Next.
UpdateBeams_Sound 40198 LD A,(39897) Fetch the flag that says whether a beam was drawn.
40201 AND A Test it.
40202 RET Z Return if not.
40203 JP PlayBeamSound Make the sound of the beams.
Prev: 39894 Up: Map Next: 40206