Routines
 Prev: 25395 Up: Map Next: 25539
25420: Control a banknote
Used by the command list at 64888. Calculates and sets the banknote's next animatory state and location. If the banknote is far enough off-screen to the left or right, it will be moved to a location just off-screen to the left.
Input
H 228 or 229 (banknote)
25420 LD A,(32745) 32745 holds Sam's object inventory
25423 RLCA Has Sam got the hook (bit 6 set)?
25424 RLCA
25425 JR NC,25434 Jump if not
Sam's got the hook; we bring this banknote out of service so that its character buffer is available for use by the hook when it's thrown. However, the banknote is not removed from view, which is a bug.
25427 CALL 59848 Update the SRB for the banknote's current animatory state and location
25430 CALL 63409 Change the banknote's primary command routine address to 25433 (below)
25433 RET
This entry point is used by the command list at 64886.
25434 LD L,10 Collect byte 10 of the banknote's buffer
25436 LD A,(HL)
25437 AND A Reset the zero flag if Sam has just landed on this banknote
25438 LD (HL),0 Set byte 10 to zero
25440 JR NZ,25461 Jump if Sam has just landed on this banknote
First we check whether the banknote is far off-screen to the left or right.
25442 LD L,1 Point HL at byte 1 of the banknote's buffer
25444 LD A,(32766) A=X (the x-coordinate of the leftmost column of the play area on screen)
25447 SUB 12 Is X=0 or 8?
25449 JR C,25454 Jump if so
25451 CP (HL) Is the banknote's x-coordinate greater than X-12?
25452 JR NC,25461 Jump if not
25456 JR C,25477 Jump if X=0, 8, 208, 216 or 224
25458 CP (HL) Is the banknote's x-coordinate greater than X+48?
25459 JR NC,25477 Jump if not
The banknote is off-screen to the left by at least 12 x-coordinates, or it's off-screen to the right by at least 17 x-coordinates, or it's just been landed on by Sam. Time to reinitialise its animatory state and location.
25461 CALL 59848 Update the SRB for the banknote's current animatory state and location
25464 LD D,34 Initialise the banknote's y-coordinate to 34
25466 LD A,(32766) A=X (the x-coordinate of the leftmost column of the play area on screen)
25469 SUB 11 Is X>8?
25471 JR NC,25474 Jump if so
25473 SBC A,A A=255
25474 LD E,A E=255 (if X<=8) or X-11
25475 JR 25480
The banknote is on-screen or not far off it. Now we calculate the banknote's next animatory state and location.
25477 CALL 59848 Update the SRB for the banknote's current animatory state and location
25480 PUSH AF Save the banknote's current animatory state briefly
25481 CALL 61823 Get a random number in A
25484 LD C,A Copy it to C
25485 AND 136 Keep only bits 3 and 7
25487 ADD A,62 B=62, 70, 190, or 198 (banknote animatory states)
25489 LD B,A
25490 POP AF Restore the banknote's current animatory state to A
25491 CP B Is it equal to B?
25492 JR Z,25480 Jump back to generate another animatory state if so
At this point B holds the banknote's next animatory state. Now we calculate its next location.
25494 LD A,B A=banknote's next animatory state
25495 PUSH AF Save this briefly
25496 CALL 60164 Set the carry flag if the banknote is above the road (as opposed to the sidewalk)
25499 ADC A,45 A=45 if the banknote is above the sidewalk, or 46 if it's above the road
25501 SUB E
25502 SUB D Subtract the banknote's current y-coordinate (32-35); now A=11+G, where G (-1<=G<=3) is the height of the banknote above the ground
25503 LD B,A Multiply this value by 5 and add 1 (A=51, 56, 61, 66, or 71)
25507 INC A
25508 PUSH HL Save the banknote's character number
25509 LD L,A Point HL at the entry in the banknote animation table at 25395 that corresponds to the banknote's height above the ground
25510 LD H,99
25512 LD A,C A=random number generated earlier
25513 LD BC,1283 B=5 (number of bytes in the entry), C=3
25516 CP (HL) Find the first byte in the entry that is greater than A
25517 JR C,25522
25519 INC HL
25520 DJNZ 25516
25522 LD A,B A=0-5
25523 CP C Is A<3?
25524 JR C,25528 Jump if so
25526 INC E Otherwise increment the banknote's x-coordinate
25527 SUB C A=0-2
25528 ADD A,A A=0, 2 or 4
25529 JR Z,25532 Jump if A=0
25531 SUB C A=-1 or 1
25532 ADD A,D Add -1, 0 or 1 to the banknote's current y-coordinate
25533 LD D,A
25534 POP HL Restore the banknote's character number to H
25535 POP AF Restore the banknote's next animatory state to A
25536 JP 59861 Update the banknote's animatory state and location and update the SRB
 Prev: 25395 Up: Map Next: 25539