Prev: 40259 Up: Map Next: 40361
40275: 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 23582: 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 52801)
HL First scroll position (from 52805)
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 40275 LD B,0 Start with a length of zero.
40277 LD A,(23582) Fetch the number of the beam.
40280 BIT 0,A Test bit 0.
40282 LD A,H Fetch the high byte of the first position.
40283 JR NZ,FindBeamExtent_Right Jump to FindBeamExtent_Right if bit 0 is set.
40285 CP 33 Is the position at least 33?
40287 RET NC Return if so, as there is no beam.
40288 LD A,129 Use 129 as the offset.
40290 JR FindBeamExtent_Y Jump to FindBeamExtent_Y.
FindBeamExtent_Right 40292 CP 33 Is the position below 33?
40294 RET C Return if so, as there is no beam.
40295 LD A,33 Use 33 as the offset.
FindBeamExtent_Y 40297 ADD A,D Add the second position to get the vertical pixel position.
40298 LD D,A Store it in D.
40299 LD A,(23582) Fetch the number of the beam.
40302 BIT 1,A Jump to FindBeamExtent_Far if bit 1 is set.
40304 JR NZ,FindBeamExtent_Far
40306 LD A,232 Take the first position from 232...
40308 SUB L ...to get the length in pixels.
40309 LD E,8 The beam starts at the horizontal position 8.
40311 JR FindBeamExtent_Length Jump to FindBeamExtent_Length.
FindBeamExtent_Far 40313 LD A,232 Add the second position to 232...
40315 ADD A,E ...to get the horizontal start.
40316 LD E,A Store it in E.
40317 LD A,L Fetch the first position.
40318 SUB 8 Take 8 off to get the length in pixels.
FindBeamExtent_Length 40320 LD (49027),DE Store the start of the beam.
40324 LD B,A Copy the length in pixels.
40325 AND %00000111 Keep the bottom three bits.
40327 JR Z,FindBeamExtent_Bytes Jump to FindBeamExtent_Bytes if the length is a whole number of bytes.
40329 LD A,B Round the length up...
40330 ADD A,8 ...to the next whole byte.
40332 LD B,A Store it in B.
FindBeamExtent_Bytes 40333 SRL B Divide the length by eight.
40335 SRL B
40337 SRL B
40339 RET Z Return if the length is zero.
40340 LD C,(IX+0) Fetch the pattern of the beams.
40343 LD A,(52801) Fetch the fine scroll.
40346 AND %00000111 Keep the bottom three bits.
40348 JR Z,FindBeamExtent_Address Jump to FindBeamExtent_Address if there is no fine scroll.
FindBeamExtent_Rotate 40350 RRC C Rotate the pattern.
40352 DEC A Count down.
40353 JR NZ,FindBeamExtent_Rotate Loop back to FindBeamExtent_Rotate until the pattern matches the fine scroll.
FindBeamExtent_Address 40355 LD HL,(49027) Fetch the start of the beam.
40358 JP GetScreenAddress Jump to GetScreenAddress.
Prev: 40259 Up: Map Next: 40361