Prev: 62DA Up: Map Next: 6329
62DB: Control the sniper
Used by the command list at FD7A. Checks whether conditions are right for the sniper to appear, and if they are, hands over control to the interruptible subcommand routine at 621E.
Input
H 0xE3 (sniper)
62DB LD A,($7FFF) 7FFF holds the y-coordinate of the topmost row of the play area on screen
62DE CP $14 Is the sidewalk on screen at the moment?
62E0 RET NZ Return if not
62E1 LD A,($7FFC) Collect Sam's status flags from 7FFC
62E4 AND $81 Is Sam being carried or falling from a building at the moment?
62E6 RET NZ Return if so
62E7 LD L,$03 Set bit 7 of byte 0x03 of the sniper's buffer, making him move quickly
62E9 SET 7,(HL)
62EB LD L,$0A Decrement and then collect byte 0x0A of the sniper's buffer
62ED DEC (HL)
62EE LD A,(HL)
62EF AND $0F Are any of bits 0-3 set?
62F1 RET NZ Return if so (15 times out of 16)
Now we check how many keys Sam has collected. The exact number in Sam's possession affects the probability that the sniper will appear.
62F2 LD A,($7FEA) Collect the key inventory flags from 7FEA
62F5 LD B,$1F B=0x1F if Sam has no keys or one key, 0x3F if he has two keys, 0x7F if he has three, or 0xFF if he has all four
62F7 ADD A,A
62F8 JR Z,$6300
62FA JR NC,$62F7
62FC RL B
62FE JR $62F7
6300 CALL $F17F Get a random number in A
6303 CP B Is A>=B?
6304 RET NC Return if so
The dice are telling us that the sniper should appear. But can we find a suitable spot for him?
6305 LD DE,$6212 Point DE at the table of potential x-coordinates for the sniper at 6212
6308 LD L,$01 Point HL at byte 0x01 of the sniper's buffer
630A LD B,$07 There are 7 entries in the table
630C LD A,(DE) A=potential x-coordinate for the sniper
630D INC E Point DE at the next potential x-coordinate
630E LD (HL),A Set the sniper's x-coordinate for testing
630F CALL $66DA Would this bring the sniper on screen no less than 8 x-coordinates away from Sam?
6312 JR Z,$6317 Jump if so
6314 DJNZ $630C Otherwise consider the next potential x-coordinate
6316 RET
We have found a suitable place for the sniper to emerge from.
6317 LD L,$11 Byte 0x11 of the sniper's buffer is used to regulate the delay between shots; initialise it to 0
6319 LD (HL),A
631A DEC L L=0x10
631B CALL $F17F Get a random number in A
631E AND $0F Byte 0x10 of the sniper's buffer is used to decide when to duck and when to shoot; initialise it to a number between 0x0A and 0x19
6320 ADD A,$0A
6322 LD (HL),A
6323 LD BC,$621E Copy the address of the interruptible subcommand routine at 621E into bytes 0x0E and 0x0F of the sniper's buffer, and then jump to it
6326 JP $F7AB
Prev: 62DA Up: Map Next: 6329