Prev: 6333 Up: Map Next: 63C3
634C: Control a banknote
Used by the command list at FD78. 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 0xE4 or 0xE5 (banknote)
634C LD A,($7FE9) 7FE9 holds Sam's object inventory
634F RLCA Has Sam got the hook (bit 6 set)?
6350 RLCA
6351 JR NC,$635A 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.
6353 CALL $E9C8 Update the SRB for the banknote's current animatory state and location
6356 CALL $F7B1 Change the banknote's primary command routine address to 6359 (below)
6359 RET
This entry point is used by the command list at FD76.
635A LD L,$0A Collect byte 0x0A of the banknote's buffer
635C LD A,(HL)
635D AND A Reset the zero flag if Sam has just landed on this banknote
635E LD (HL),$00 Set byte 0x0A to zero
6360 JR NZ,$6375 Jump if Sam has just landed on this banknote
First we check whether the banknote is far off-screen to the left or right.
6362 LD L,$01 Point HL at byte 0x01 of the banknote's buffer
6364 LD A,($7FFE) A=X (the x-coordinate of the leftmost column of the play area on screen)
6367 SUB $0C Is X=0 or 8?
6369 JR C,$636E Jump if so
636B CP (HL) Is the banknote's x-coordinate greater than X-12?
636C JR NC,$6375 Jump if not
636E ADD A,$3C A=X+48
6370 JR C,$6385 Jump if X=0, 8, 208, 216 or 224
6372 CP (HL) Is the banknote's x-coordinate greater than X+48?
6373 JR NC,$6385 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.
6375 CALL $E9C8 Update the SRB for the banknote's current animatory state and location
6378 LD D,$22 Initialise the banknote's y-coordinate to 34
637A LD A,($7FFE) A=X (the x-coordinate of the leftmost column of the play area on screen)
637D SUB $0B Is X>8?
637F JR NC,$6382 Jump if so
6381 SBC A,A A=0xFF
6382 LD E,A E=0xFF (if X<=8) or X-11
6383 JR $6388
The banknote is on-screen or not far off it. Now we calculate the banknote's next animatory state and location.
6385 CALL $E9C8 Update the SRB for the banknote's current animatory state and location
6388 PUSH AF Save the banknote's current animatory state briefly
6389 CALL $F17F Get a random number in A
638C LD C,A Copy it to C
638D AND $88 Keep only bits 3 and 7
638F ADD A,$3E B=0x3E, 0x46, 0xBE, or 0xC6 (banknote animatory states)
6391 LD B,A
6392 POP AF Restore the banknote's current animatory state to A
6393 CP B Is it equal to B?
6394 JR Z,$6388 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.
6396 LD A,B A=banknote's next animatory state
6397 PUSH AF Save this briefly
6398 CALL $EB04 Set the carry flag if the banknote is above the road (as opposed to the sidewalk)
639B ADC A,$2D A=45 if the banknote is above the sidewalk, or 46 if it's above the road
639D SUB E
639E 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
639F LD B,A Multiply this value by 5 and add 1 (A=51, 56, 61, 66, or 71)
63A0 ADD A,A
63A1 ADD A,A
63A2 ADD A,B
63A3 INC A
63A4 PUSH HL Save the banknote's character number
63A5 LD L,A Point HL at the entry in the banknote animation table at 6333 that corresponds to the banknote's height above the ground
63A6 LD H,$63
63A8 LD A,C A=random number generated earlier
63A9 LD BC,$0503 B=5 (number of bytes in the entry), C=3
63AC CP (HL) Find the first byte in the entry that is greater than A
63AD JR C,$63B2
63AF INC HL
63B0 DJNZ $63AC
63B2 LD A,B A=0-5
63B3 CP C Is A<3?
63B4 JR C,$63B8 Jump if so
63B6 INC E Otherwise increment the banknote's x-coordinate
63B7 SUB C A=0-2
63B8 ADD A,A A=0, 2 or 4
63B9 JR Z,$63BC Jump if A=0
63BB SUB C A=-1 or 1
63BC ADD A,D Add -1, 0 or 1 to the banknote's current y-coordinate
63BD LD D,A
63BE POP HL Restore the banknote's character number to H
63BF POP AF Restore the banknote's next animatory state to A
63C0 JP $E9D5 Update the banknote's animatory state and location and update the SRB
Prev: 6333 Up: Map Next: 63C3