Prev: AD29 Up: Map Next: ADBD
AD59: Searchlight movement
This decides searchlight movement.
Used by the routine at nighttime.
Input
HL Pointer to a searchlight movement data.
searchlight_movement AD59 LD E,(HL) Fetch movement.x
AD5A INC HL Step over
AD5B LD D,(HL) Fetch movement.y
AD5C INC HL Step over
AD5D DEC (HL) Decrement movement.counter
AD5E JP NZ,searchlight_movement_6 Jump if it's non-zero
End of previous sweep: work out the next.
AD61 INC HL Advance to movement.index
AD62 INC HL
AD63 LD A,(HL) Fetch movement.index
AD64 BIT 7,A Is the reverse direction flag set?
AD66 JP Z,searchlight_movement_2 Jump if not
AD69 AND $7F Clear the reverse direction flag
AD6B JP NZ,searchlight_movement_0 Jump if non-zero index
Index is zero.
AD6E RES 7,(HL) Clear direction bit when index hits zero
AD70 JR searchlight_movement_1 (else)
Index is non-zero.
searchlight_movement_0 AD72 DEC (HL) Decrement movement.index
AD73 DEC A Decrement local copy too (sans direction bit)
searchlight_movement_1 AD74 JR searchlight_movement_3 (else)
Not reverse direction.
searchlight_movement_2 AD76 INC A Count up
AD77 LD (HL),A Assign to movement.index
searchlight_movement_3 AD78 INC HL Advance to movement.pointer
AD79 LD C,(HL) Load pointer
AD7A INC HL
AD7B LD B,(HL)
AD7C DEC HL Backtrack to movement.index
AD7D DEC HL
AD7E ADD A,A Index in A doubled and added to pointer
AD7F ADD A,C
AD80 LD C,A
AD81 JR NC,searchlight_movement_4
AD83 INC B
searchlight_movement_4 AD84 LD A,(BC) Fetch movement byte
AD85 CP $FF End of list?
AD87 JP NZ,searchlight_movement_5
AD8A DEC (HL) !overshot? count down counter byte
AD8B SET 7,(HL) !go negative
AD8D DEC BC Pointer -= 2
AD8E DEC BC
AD8F LD A,(BC) Bug: A is loaded but never used again
searchlight_movement_5 AD90 DEC HL HL -= 2
AD91 DEC HL
Copy counter + direction_t.
AD92 LD A,(BC) Copy counter
AD93 LD (HL),A
AD94 INC HL
AD95 INC BC
AD96 LD A,(BC) Copy direction
AD97 LD (HL),A
AD98 RET Return
searchlight_movement_6 AD99 INC HL Advance to direction
AD9A LD A,(HL) Fetch direction
AD9B INC HL
AD9C BIT 7,(HL) !Test sign
AD9E JR Z,searchlight_movement_7 Jump if clear
ADA0 XOR $02 Toggle direction
searchlight_movement_7 ADA2 CP $02 If direction <= direction_TOP_RIGHT, y-- else y++
ADA4 JR NC,searchlight_movement_8
ADA6 DEC D
ADA7 DEC D
searchlight_movement_8 ADA8 INC D
ADA9 AND A If direction is RIGHT, x+=2 else x-=2
ADAA JR Z,searchlight_movement_9
ADAC CP $03
ADAE JR Z,searchlight_movement_9
ADB0 INC E
ADB1 INC E
ADB2 JR searchlight_movement_10
searchlight_movement_9 ADB4 DEC E
ADB5 DEC E
searchlight_movement_10 ADB6 DEC HL Backtrack to (x,y)
ADB7 DEC HL
ADB8 DEC HL
ADB9 LD (HL),D Store y
ADBA DEC HL
ADBB LD (HL),E Store x
ADBC RET Return
Prev: AD29 Up: Map Next: ADBD