Prev: 64B8 Up: Map Next: 653E
64BD: 'S' pressed - somersault
The address of this routine is found in the table of keypress handling routines at ED00. It is called from the main loop at F02B when 'S' is pressed.
64BD LD HL,$6494 The animation phase table for Sam when somersaulting is at 6494
This entry point is used by the routine at 64B8 with HL=647C.
64C0 PUSH HL Save the address of the animation phase table
64C1 CALL $653E Return to the main loop if Sam cannot roll or somersault from his current location
64C4 LD A,$08 Set bit 3 of Sam's status flags at 7FFC
64C6 LD ($7FFC),A
64C9 POP HL Restore the address of the animation phase table to HL
64CA LD ($E60C),HL Copy the address of the animation phase table into bytes 0x0C and 0x0D of Sam's buffer
This entry point is used by the routine at 74D8 when bit 3 at 7FFC is set (by this routine - see above).
64CD LD HL,$E608 Reset Sam's main action timer (in byte 0x08 of his buffer) to 6
64D0 LD (HL),$06
64D2 CALL $E9C8 Update the SRB for Sam's current animatory state and location
64D5 LD HL,($E60C) Point HL at the first byte of the current entry in the animation phase table
64D8 AND $80 Set the zero flag if Sam is facing left
64DA LD B,A B=0x00 if Sam is facing left, 0x80 if facing right
64DB LD A,(HL) A=first byte of the animation phase table entry
64DC INC HL Point HL at the second byte in the entry
64DD JR Z,$64E0 Jump if Sam is facing left
64DF LD A,(HL) A=second byte of the animation phase table entry
64E0 ADD A,E Add Sam's current x-coordinate
64E1 LD E,A E=Sam's next x-coordinate
64E2 INC HL A=third byte of the animation phase table entry
64E3 LD A,(HL)
64E4 ADD A,D Add Sam's current y-coordinate
64E5 LD D,A D=Sam's next y-coordinate
64E6 INC HL A=fourth byte of the animation phase table entry
64E7 LD A,(HL)
64E8 INC HL Point HL at the first byte of the next entry
64E9 LD ($E60C),HL Store this address in bytes 0x0C and 0x0D of Sam's buffer
64EC RLCA C=Sam's next base animatory state (bit 7 reset)
64ED AND A
64EE RRA
64EF LD C,A
64F0 JR NC,$6515 Jump unless it's time to check whether Sam has landed
It's time to check whether Sam has landed on his feet yet.
64F2 PUSH DE Save Sam's new coordinates briefly
64F3 AND A Is Sam's next animatory state 0x00 or 0x80 (standing upright)?
64F4 JR Z,$64FD Jump if so
64F6 DEC E Subtract 1 from Sam's new x-coordinate
64F7 BIT 7,B Is Sam facing left?
64F9 JR Z,$64FD Jump if so
64FB INC E Add 1 to Sam's new x-coordinate
64FC INC E
64FD CALL $EAFF Has Sam landed on the sidewalk or the road yet?
6500 JR NC,$650A Jump if so
6502 LD A,E A=Sam's adjusted new x-coordinate
6503 POP DE Restore Sam's new x-coordinate to E
6504 INC D Add 1 to Sam's new y-coordinate (move him down a level)
6505 PUSH DE Save Sam's adjusted new coordinates briefly
6506 LD E,A E=Sam's adjusted new x-coordinate
6507 CALL $EAFF Set the carry flag unless Sam has landed on the sidewalk or road
650A POP DE Restore Sam's adjusted new y-coordinate to D, and his new x-coordinate to E
650B JR C,$6514 Jump if Sam has not landed yet
650D LD A,C A=Sam's next base animatory state (bit 7 reset)
650E AND A Is it 0x00 or 0x80 (standing upright)?
650F JR NZ,$6514 Jump if not
6511 LD ($7FFC),A Clear all of Sam's status flags at 7FFC (Sam has landed)
6514 LD A,C A=Sam's next base animatory state (bit 7 reset)
6515 CP $09 Is the new base animatory state < 0x09 (meaning Sam has just started or is just finishing a roll or somersault)?
6517 JR C,$6525 Jump if so
6519 PUSH BC Save Sam's direction indicator and next base animatory state
651A PUSH DE Save Sam's next x- and y-coordinates
651B CP $0F Is the new base animatory state 0x0F (meaning Sam is going to rotate 90 degrees for the first part of the roll or somersault)?
651D CALL Z,$6412 If so, prepare sprite tiles 0xEF-0xF7 for this animatory state
6520 CALL NZ,$6448 Otherwise, rotate sprite tiles 0xEF-0xF7 for animatory state 0x09, 0x1F or 0x0A
6523 POP DE Restore Sam's next x- and y-coordinates to E and D
6524 POP BC Restore Sam's direction indicator and next base animatory state to B and C
6525 LD H,$E6 0xE6=Sam
6527 LD A,B A=Sam's new animatory state
6528 OR C
6529 CALL $E9D5 Update Sam's animatory state and location and update the SRB
652C LD A,($7FFC) Collect Sam's status flags from 7FFC
652F AND A Has Sam landed yet?
6530 RET NZ Return if not
6531 CALL $EC69 Make a sound effect
6534 LD L,$0C Point HL at byte 0x0C of Sam's buffer
6536 CALL $63C3 Check whether Sam has somersaulted onto a banknote
6539 LD H,$E6 0xE6=Sam
653B JP $EC83 Now that Sam has landed, scroll the screen left or right if necessary
Prev: 64B8 Up: Map Next: 653E