Prev: 658F Up: Map Next: 65DB
6592: Check whether Sam has been hit by a bullet
Used by the routine at 65DB. Returns with the carry flag set if Sam has been hit by a bullet.
Input
D Bullet's next screen y-coordinate (1-20)
E Bullet's next screen x-coordinate (0-31)
6592 EXX
6593 XOR A Initialise E' to 0; E' may be updated by the call to E900 below
6594 LD E,A
6595 EXX
6596 PUSH HL
6597 PUSH DE Save the bullet's screen coordinates
6598 LD HL,($7FFE) Collect the x- and y-coordinates of the top-left tile of the play area on screen in L and H
659B ADD HL,DE Add the bullet's screen coordinates
659C EX DE,HL Now DE holds the bullet's play area coordinates
659D LD HL,$E604 Point HL at byte 0x04 of Sam's buffer
65A0 LD A,(HL) A=Sam's z-coordinate
65A1 DEC A Set the zero flag if Sam's indoors
65A2 CALL $E900 Print the play area tile where the bullet will be next (if Sam's not indoors)
65A5 LD A,E A=reference of the sprite tile (of Sam's) that was printed, or 0 if none was printed
65A6 AND A Was a sprite tile printed?
65A7 JR Z,$65D8 Jump if not (Sam was not hit)
65A9 CP $10 Was the sprite tile reference in the range 0x01-0x0F?
65AB JR C,$65B1 Jump if so
65AD CP $1A Was the sprite tile reference in the range 0x10-0x19?
65AF JR C,$65BF Jump if so (Sam was hit by the bullet)
The reference of the sprite tile upon which the bullet impinged was in the range 0x01-0x0F or greater than 0x19. Closer examination is required to determine whether Sam was hit.
65B1 LD HL,$6586 Point HL at the table of sprite tile references at 6586
65B4 LD B,$09 There are 9 sprite tile references in the table
65B6 CP (HL) Compare the reference of the sprite tile that was printed with a reference from the table
65B7 JR Z,$65BF Jump if they match (Sam was hit)
65B9 INC HL Point HL at the next sprite tile reference in the table
65BA DJNZ $65B6 Jump back to compare it with the sprite tile that was printed
65BC AND A Reset the carry flag: Sam was not hit by the bullet
65BD JR $65D8
Sam was hit by the bullet.
65BF CALL $66F0 Make the sound effect of Sam being hit by a bullet
65C2 LD HL,$7FEF 7FEF holds the number of remaining first aid kits
65C5 LD A,(HL) Pick this up in A
65C6 ADD A,A Discard a first aid kit
65C7 LD (HL),A
65C8 JR C,$65D4 Jump if there was a first aid kit left to discard
Sam has already used all his first aid kits. Game over.
65CA LD L,$9E HL=7F9E (bucks)
65CC LD (HL),A Reduce Sam's cash supply to 0
65CD INC L
65CE LD (HL),A
65CF LD A,$63 Message 0x63: 'I HAD TO GO TO HOSPITAL...'
65D1 JP $7AD5 Display the ending cutscene with this message
Sam had a first aid kit left.
65D4 CALL $7417 Display any remaining first aid kits
65D7 SCF Set the carry flag: Sam was hit by the bullet
65D8 POP DE Restore the bullet's screen coordinates to DE
65D9 POP HL
65DA RET
Prev: 658F Up: Map Next: 65DB