| Routines

25539: Check whether Sam has somersaulted onto a banknote

Used by the routine at 25789. Compares Sam's location with those of the two banknotes. If there's a match, and Sam has just finished a somersault, the banknote is added to Sam's cash supply.
Input
HL | 58892 (byte 12 of Sam's buffer)
25539 | BIT 5,(HL) | Byte 12 of Sam's buffer holds the LSB of the current roll/somersault animation phase table entry
25541 | RET Z | Return if Sam was rolling
25542 | LD L,1 | Collect Sam's x- and y-coordinates in E and D
25544 | LD E,(HL)
25545 | INC L
25546 | LD D,(HL)
25547 | LD B,L | B=2 (there are 2 banknotes)
25548 | DEC H | H=228 or 229
25549 | LD A,D | A=Sam's y-coordinate
25550 | CP (HL) | Compare it with the banknote's y-coordinate
25551 | DEC HL | Point HL at byte 1 of the banknote's buffer
25552 | JR NZ,25558 | Jump unless Sam's y-coordinate matches the banknote's
25554 | LD A,E | A=Sam's x-coordinate
25555 | CP (HL) | Has Sam landed on a banknote?
25556 | JR Z,25562 | Jump if so
25558 | INC HL | Point HL at byte 2 of the banknote's buffer
25559 | DJNZ 25548 | Jump back until both banknotes have been checked
25561 | RET |
Sam has landed on something that is using one of the banknote buffers. Here we check that the object looks like a banknote. But this check is redundant, since no object except a banknote or the hook can use buffer 228 or 229, and Sam cannot land on the hook.
25562 | DEC L | L=0
25563 | LD A,(HL) | A=banknote's animatory state
25564 | AND 127 | Discard bit 7
25566 | SUB 62 | Is the banknote's animatory state 62 or 190?
25568 | JR Z,25573 | Jump if so
25570 | SUB 8 | Is the banknote's animatory state 70 or 198?
25572 | RET NZ | Return if not (this never happens)
Sam has landed on something that looks like a banknote.
25573 | LD L,10 | Set byte 10 of the banknote's buffer to 1 to indicate that Sam's just landed on it (see 25420)
25575 | INC (HL)
25576 | CALL 25039 | Add 1, 5, 10 or 20 bucks to Sam's total
Finally we make an appropriate sound effect. Your browser doesn't support HTML5 audio. Here is a link to the audio instead.
25579 | XOR A | Prepare the sound effect parameters: A=0 (initial border colour), D=5 (duration), E=249 (initial pitch)
25580 | LD DE,1529
25583 | INC A | Increment the border colour
25584 | XOR 16 | Flip bit 4 of A
25586 | AND 23 | Retain only bits 0-2 (border colour) and 4 (speaker state)
25588 | OUT (254),A | Change the border colour and speaker state
25590 | LD B,E | Perform the pitch delay
25591 | DJNZ 25591
25593 | DEC E | Decrement the pitch delay
25594 | JR NZ,25583 | Jump back unless it's zero
25596 | DEC D | Decrement the duration counter
25597 | JR NZ,25583 | Jump back unless it's zero
25599 | RET |