Prev: AD59 Up: Map Next: AE75
ADBD: Night-time
This drives the searchlights. It is called when day_or_night is non-zero.
Used by the routine at main_loop.
nighttime ADBD LD HL,$81BD Point HL at searchlight_state
ADC0 LD A,(HL) Fetch the state
ADC1 CP $FF Is it in searchlight_STATE_SEARCHING state? ($FF)
ADC3 JP Z,searching If so, jump to searching
ADC6 LD A,($68A0) Fetch the global current room index
ADC9 AND A Are we outdoors?
ADCA JR Z,nighttime_0 If so, jump to searchlight movement code
If the hero goes indoors then the searchlight loses track.
ADCC LD (HL),$FF Set the searchlight state to searchlight_STATE_SEARCHING
ADCE RET Return
The hero is outdoors.
If the searchlight previously caught the hero, then track him.
nighttime_0 ADCF LD A,(HL) Fetch the searchlight state again - it's a counter
ADD0 CP $1F Does it equal searchlight_STATE_CAUGHT? ($1F)
ADD2 JP NZ,nighttime_8 If not, jump to single searchlight code. This will draw the searchlight in the place where the hero was last seen
Caught in searchlight.
ADD5 LD HL,($81BB) Fetch map_position into HL
ADD8 LD A,L Compute map_x as map_position.x + 4
ADD9 ADD A,$04
ADDB LD E,A
ADDC LD D,H map_y is just map_position.y
ADDD LD HL,($AE76) Fetch the searchlight_caught_coord x/y into HL
ADE0 LD A,L Does caught_x equal map_x?
ADE1 CP E
ADE2 JR NZ,nighttime_1 Jump if not
ADE4 LD A,H Does caught_y equal map_y?
ADE5 CP D
ADE6 RET Z If both are equal the highlight doesn't need to move so return
ADE7 JR nighttime_4 (else)
Move searchlight left/right to focus on the hero.
nighttime_1 ADE9 JP NC,nighttime_2 Jump to decrement case if caught_x exceeds map_x
ADEC INC A Increment caught_x
ADED JR nighttime_3 (else)
nighttime_2 ADEF DEC A Decrement caught_x
nighttime_3 ADF0 LD L,A Save to HL
Move searchlight up/down to focus on the hero.
nighttime_4 ADF1 LD A,H Does caught_y equal map_y? (Note: This looks like a duplicated check but isn't - the equivalent above doesn't always execute)
ADF2 CP D
ADF3 JR Z,nighttime_7 Skip movement code if so
ADF5 JP NC,nighttime_5 Jump to decrement case if caught_y exceeds map_y
ADF8 INC A Increment caught_y
ADF9 JR nighttime_6 (else)
nighttime_5 ADFB DEC A Decrement caught_y
nighttime_6 ADFC LD H,A Save to HL
nighttime_7 ADFD LD ($AE76),HL Save HL back to searchlight_caught_coord
When tracking the hero a single searchlight is used.
nighttime_8 AE00 LD DE,($81BB) Fetch map_position into HL
AE04 LD HL,$AE77 Point HL at searchlight_caught_coord plus a byte to compensate for the 'DEC HL' at the jump target
AE07 LD B,$01 1 iteration / 1 searchlight
AE09 PUSH BC Preserve loop counter
AE0A PUSH HL Preserve searchlight movement pointer
AE0B JR nighttime_10 Jump
When not tracking the hero all three searchlights are cycled through.
searching AE0D LD HL,$AD29 Point HL at searchlight_movements[0]
AE10 LD B,$03 3 iterations / 3 searchlights
Start loop
nighttime_9 AE12 PUSH BC Preserve loop counter
AE13 PUSH HL Preserve searchlight movement pointer
AE14 CALL searchlight_movement Decide searchlight movement
AE17 POP HL Restore searchlight movement pointer
AE18 PUSH HL
AE19 CALL searchlight_caught Is the hero caught in the searchlight?
AE1C POP HL Restore searchlight movement pointer
AE1D PUSH HL
AE1E LD DE,($81BB) Point DE at map_position
AE22 LD A,E If map_x + 23 < searchlight.x (off right hand side) goto next
AE23 ADD A,$17
AE25 CP (HL)
AE26 JP C,next_searchlight
AE29 LD A,(HL) If searchlight.x + 16 < map_x (off left hand side) goto next
AE2A ADD A,$10
AE2C CP E
AE2D JP C,next_searchlight
AE30 INC HL Point HL at searchlight.y
AE31 LD A,D If map_y + 16 < searchlight.y (off top side) goto next
AE32 ADD A,$10
AE34 CP (HL)
AE35 JP C,next_searchlight
AE38 LD A,(HL) If searchlight.y + 16 < map_y (off bottom side) goto next
AE39 ADD A,$10
AE3B CP D
AE3C JP C,next_searchlight
nighttime_10 AE3F XOR A Set the clip flag to zero
AE40 EX AF,AF' Bank the clip flag
AE41 DEC HL Point HL at searchlight.x (or caught_coord.x depending on how it was entered)
Calculate the column
AE42 LD B,$00 Clear top part of 'column' skip
AE44 LD A,(HL) Calculate the left side skip = searchlight.x - map_x
AE45 SUB E
AE46 JP NC,nighttime_11 Jump if left hand skip is +ve
AE49 LD B,$FF Invert the top part of 'column'
AE4B EX AF,AF' Bitwise complement the banked clip flag
AE4C CPL
AE4D EX AF,AF'
nighttime_11 AE4E LD C,A Finalise BC as column
Calculate the row
AE4F INC HL Point HL at searchlight.y
AE50 LD A,(HL) Fetch searchlight.y
AE51 LD H,$00 Clear top part of 'row' skip
AE53 SUB D Calculate the top side skip = searchlight.y - map_y
AE54 JP NC,nighttime_12 Jump if top side skip is +ve
AE57 LD H,$FF Invert the top part of 'row'
nighttime_12 AE59 LD L,A Finalise HL as row
HL is row, BC is column
AE5A ADD HL,HL Multiply row by 32
AE5B ADD HL,HL
AE5C ADD HL,HL
AE5D ADD HL,HL
AE5E ADD HL,HL
AE5F ADD HL,BC Add column to it
AE60 LD BC,$5846 Point HL at the address of the top-left game window attribute
AE63 ADD HL,BC Add row+column to base, producing our plot pointer
AE64 EX DE,HL Move it to DE
AE65 EX AF,AF' Unbank the clip flag
AE66 LD ($AE75),A Assign it to searchlight_clip_left
AE69 CALL searchlight_plot Plot the searchlight
next_searchlight AE6C POP HL Restore searchlight_movement pointer
AE6D POP BC Restore loop counter
AE6E LD DE,$0007 Step to the next searchlight_movement
AE71 ADD HL,DE
AE72 DJNZ nighttime_9 ...loop
AE74 RET Return
Prev: AD59 Up: Map Next: AE75