Prev: 9D43 Up: Map Next: 9DA9
9D53: Find Beam Extent
Used by the routine at UpdateBeams.
Works out where a beam is drawn and how long it is. The beam number is held at 5C1E: bit 0 selects the side of the screen on the horizontal axis and bit 1 selects the side on the vertical axis. The screen address that is returned is where the beam starts.
Input
DE Second scroll position (from CE41)
HL First scroll position (from CE45)
IX Address of the beam variables
Output
B Length of the beam in bytes, or zero if there is no beam
C Pattern of each byte, rotated to match the fine scroll
HL Screen address of the start of the beam
FindBeamExtent 9D53 LD B,$00 Start with a length of zero.
9D55 LD A,($5C1E) Fetch the number of the beam.
9D58 BIT 0,A Test bit 0.
9D5A LD A,H Fetch the high byte of the first position.
9D5B JR NZ,FindBeamExtent_Right Jump to FindBeamExtent_Right if bit 0 is set.
9D5D CP $21 Is the position at least 21?
9D5F RET NC Return if so, as there is no beam.
9D60 LD A,$81 Use 81 as the offset.
9D62 JR FindBeamExtent_Y Jump to FindBeamExtent_Y.
FindBeamExtent_Right 9D64 CP $21 Is the position below 21?
9D66 RET C Return if so, as there is no beam.
9D67 LD A,$21 Use 21 as the offset.
FindBeamExtent_Y 9D69 ADD A,D Add the second position to get the vertical pixel position.
9D6A LD D,A Store it in D.
9D6B LD A,($5C1E) Fetch the number of the beam.
9D6E BIT 1,A Jump to FindBeamExtent_Far if bit 1 is set.
9D70 JR NZ,FindBeamExtent_Far
9D72 LD A,$E8 Take the first position from E8...
9D74 SUB L ...to get the length in pixels.
9D75 LD E,$08 The beam starts at the horizontal position 08.
9D77 JR FindBeamExtent_Length Jump to FindBeamExtent_Length.
FindBeamExtent_Far 9D79 LD A,$E8 Add the second position to E8...
9D7B ADD A,E ...to get the horizontal start.
9D7C LD E,A Store it in E.
9D7D LD A,L Fetch the first position.
9D7E SUB $08 Take 08 off to get the length in pixels.
FindBeamExtent_Length 9D80 LD ($BF83),DE Store the start of the beam.
9D84 LD B,A Copy the length in pixels.
9D85 AND %00000111 Keep the bottom three bits.
9D87 JR Z,FindBeamExtent_Bytes Jump to FindBeamExtent_Bytes if the length is a whole number of bytes.
9D89 LD A,B Round the length up...
9D8A ADD A,$08 ...to the next whole byte.
9D8C LD B,A Store it in B.
FindBeamExtent_Bytes 9D8D SRL B Divide the length by eight.
9D8F SRL B
9D91 SRL B
9D93 RET Z Return if the length is zero.
9D94 LD C,(IX+$00) Fetch the pattern of the beams.
9D97 LD A,($CE41) Fetch the fine scroll.
9D9A AND %00000111 Keep the bottom three bits.
9D9C JR Z,FindBeamExtent_Address Jump to FindBeamExtent_Address if there is no fine scroll.
FindBeamExtent_Rotate 9D9E RRC C Rotate the pattern.
9DA0 DEC A Count down.
9DA1 JR NZ,FindBeamExtent_Rotate Loop back to FindBeamExtent_Rotate until the pattern matches the fine scroll.
FindBeamExtent_Address 9DA3 LD HL,($BF83) Fetch the start of the beam.
9DA6 JP GetScreenAddress Jump to GetScreenAddress.
Prev: 9D43 Up: Map Next: 9DA9